⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressbook.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{    if (contacts.hasPersonal()) {	PrContact me(contacts.personal());	abView()->init( me );	newPersonal = FALSE;	editEntry( me );    } else {	newPersonal = TRUE;	newEntry();    }    newPersonal = FALSE;}void AddressbookWindow::markCurrentAsPersonal(){    if ( !abList->hasCurrentEntry() ) {	qWarning("ab::markCurrentAsPersonal called with no selection");	return;    }    if ( abList->selectedContacts().count() == 1 ) {	PimContact c = abList->currentEntry();	if (QMessageBox::information(this, tr("Contacts"),		tr("<qt>Set \"%1\" as your Business Card?</qt>").arg( c.fileAs() ),		tr("Yes"), tr("No"), 0, 0, 1) == 0) {	    contacts.setAsPersonal(c.uid());        abList->reload();	    updateIcons();	}    }}void AddressbookWindow::viewNext(){#ifndef QTOPIA_PHONE    if ( abList->hasCurrentEntry() ) {	int cr = abList->currentRow();	if ( ++cr < abList->numRows() ) {	    abList->setCurrentCell( cr, 0 );	    abView()->init( abList->currentEntry() );	    mView->sync();	}    }#endif}void AddressbookWindow::viewPrevious(){#ifndef QTOPIA_PHONE    if ( abList->hasCurrentEntry() ) {	int cr = abList->currentRow();	if ( --cr >= 0 ) {	    abList->setCurrentCell( cr, 0 );	    abView()->init( abList->currentEntry() );	    mView->sync();	}    }#endif}void AddressbookWindow::newEntry(){    newEntry( PimContact() );}void AddressbookWindow::newEntry( const PimContact &cnt ){    PimContact entry = cnt;    AbEditor *ed = editor();#ifndef QTOPIA_PHONE    QArray<int> cats(1);    cats[0] = catSelect->currentCategory();    entry.setCategories( cats );#else    if( contacts.filter() != -1 && contacts.filter() != -2 )    {	QArray<int> cats(1);	cats[0] = contacts.filter();	entry.setCategories( cats );    }#endif    ed->setEntry( entry, TRUE );#ifdef QTOPIA_PHONE    ed->setHaveSim( mGotSimEntries );#endif    if ( QPEApplication::execDialog(ed) == QDialog::Accepted )     {	setFocus();	PimContact newEntry = ed->entry();#ifdef QTOPIA_PHONE	AbUtil::syncContactWithSim( newEntry, mPhoneBookEntries, mPhoneLine->phoneBook() );	//don't store sim keys in the database	for( int i = 0 ; i < AbUtil::numPhoneFields ; ++i )	    newEntry.setCustomField( AbUtil::simKeyForPhoneType( AbUtil::phoneFields[i] ),							    QString::null ); #endif	NameLearner learner(newEntry);	QUuid ui = contacts.addContact( newEntry );	if (newPersonal)	    contacts.setAsPersonal(ui);#ifdef QTOPIA_PHONE	abList->setKeyChars("");#endif	abList->reload();	updateIcons();	abList->setCurrentEntry(ui);    }}AbEditor *AddressbookWindow::editor(){    if( !abEditor )	abEditor = new AbEditor( isVisible() ? this : 0, "edit" );    return abEditor;}void AddressbookWindow::editEntry( const PimContact &cnt ){    PimContact entry = cnt;    AbEditor *ed = editor();#ifdef QTOPIA_PHONE    QMap<QString,PimContact *> simData = abList->existingContactSimData();    QString entryFileAs = entry.fileAs().lower();    if( simData.contains( entryFileAs ) )	AbUtil::mergeSimContact( entry, *simData[entryFileAs] );#endif    ed->setNameFocus();    ed->setEntry( entry );#ifdef QTOPIA_PHONE    ed->setHaveSim( mGotSimEntries );    bool isSimContact = !entry.customField( "SIM_CONTACT" ).isEmpty();    bool simContactRemoved = FALSE;#endif    if ( QPEApplication::execDialog(ed) )     {	setFocus();	PimContact editedEntry( ed->entry() );	QUuid entryUid = editedEntry.uid();	if( !AbUtil::compareContacts( entry, editedEntry ) || ed->imageModified() ) 	{// only do update operations if the data has actually changed	    QPixmap *cached = QPixmapCache::find( "pimcontact" + entryUid.toString() + "-cfl" );	    if( ed->imageModified() && cached )	    {		//update the contact field list image cache		QString photoFile( editedEntry.customField( "photofile" ) );		QPixmap p;		if( !photoFile.isEmpty() )		{		    QString baseDirStr = Global::applicationFileName( "addressbook", "contactimages/" );		    QString pFileName( baseDirStr + photoFile  );		    p.convertFromImage(Image::loadPortrait(pFileName, AbUtil::ImageWidth, AbUtil::ImageHeight));		}		QPixmapCache::insert( "pimcontact" + entryUid.toString() + "-cfl", p );	    }#ifdef QTOPIA_PHONE	    //if the name has changed, remove all numbers under the old name from the sim	    if( entry.fileAs().lower() != editedEntry.fileAs().lower() )	    {		PimContact tmp;		tmp.setFileAs( entry.fileAs() );		AbUtil::syncContactWithSim( tmp, mPhoneBookEntries, mPhoneLine->phoneBook() );	    }	    AbUtil::syncContactWithSim( editedEntry, mPhoneBookEntries, mPhoneLine->phoneBook() );#endif#ifdef QTOPIA_PHONE	    bool hasNumbersForSim = AbUtil::hasNumbersForSim( editedEntry );	    // don't store sim keys in the database	    AbUtil::unmergeSimContact( editedEntry );	    if( isSimContact )	    {		//sim contact		bool hasNonSimFields = ed->hasNonSimFields();		if( !hasNumbersForSim && !hasNonSimFields )		{		    //no fields for sim and no other data, so the contact won't be around on the next reload		    simContactRemoved = TRUE;		}		else if( hasNonSimFields )		{		    //has non sim related data, so add it as a real contact		    editedEntry.setCustomField( "SIM_CONTACT", QString::null );		    NameLearner learner(editedEntry);		    entryUid = contacts.addContact( editedEntry );		    isSimContact = FALSE;		}	    }	    else	    {#endif		//regular contact, just update		NameLearner learner(editedEntry);		contacts.updateContact( editedEntry );#ifdef QTOPIA_PHONE	    }#endif	    abList->reload();#ifdef QTOPIA_PHONE	    //reset the current entry to the entry just edited	    if( isSimContact && !simContactRemoved ) // sim contact, not removed		abList->setCurrentSimEntry( editedEntry.fileAs() );	    else if( isSimContact && simContactRemoved )		; // sim contact removed - nothing to set	    else if( !entryUid.isNull() )#endif	    {		// not a sim contact, set current normally		abList->setCurrentEntry( entryUid );	    }#ifdef QTOPIA_PHONE	    if( (isSimContact && simContactRemoved) )		viewClosed(); // can't go back to viewing a removed sim contact	    else	    {#endif		if( centralWidget() == mView )		{		    // don't call slotDetailView because with QDL that would push the same		    // entry onto the view stack again. just refresh		    mView->init( editedEntry );		    mView->sync();		}#ifdef QTOPIA_PHONE	    }#endif	}    }}void AddressbookWindow::closeEvent( QCloseEvent *e ){    //don't ignore a closeEvent - trap closing before we get to this point on QTOPIA_PHONE#ifdef QTOPIA_PHONE	if( mSimIndicator )	    mSimIndicator->hide();#endif#ifdef QTOPIA_DATA_LINKING#ifndef AB_PDA	if( !allowCloseEvent )	{	    e->ignore();	    return;	}#endif#endif	slotListView();	QMainWindow::closeEvent( e );}AbLabel *AddressbookWindow::abView(){    if ( !mView ) {      mView = new AbLabel( this );      connect( mView, SIGNAL(externalLinkActivated()), this, SLOT(close()) );      connect( mView, SIGNAL(highlighted(const QString&)),	this, SLOT(setHighlightedLink(const QString&)) );      mView->setMargin(0);      setHighlightedLink(QString::null);      mView->init( PimContact()  );      //connect( mView, SIGNAL(okPressed()), this, SLOT( viewClosed() ) );      //connect( mView, SIGNAL(previous()), this, SLOT( viewPrevious() ) );      //connect( mView, SIGNAL(next()), this, SLOT( viewNext() ) );#ifdef QTOPIA_PHONE      if( Global::mousePreferred() ) 	  mView->setFocusPolicy( NoFocus );#endif    }    return mView;}void AddressbookWindow::viewOpened( const PimContact &entry ){#ifdef QTOPIA_DATA_LINKING	PimContact last;	if( !mContactViewStack.count() || 		(((last=mContactViewStack.last()).customField("SIM_CONTACT").isEmpty() 		     &&  mContactViewStack.last().uid() != entry.uid() )) ||		(last.customField("SIM_CONTACT").length() && !AbUtil::compareContacts(last, entry)) )// compare data of sim contacts	    mContactViewStack.append( entry );#endif}void AddressbookWindow::viewClosed(){#ifdef QTOPIA_DATA_LINKING    if( mContactViewStack.count() )    {	QValueList<PimContact>::Iterator it = mContactViewStack.fromLast();	mContactViewStack.remove( it );	if( !mContactViewStack.count() )	{	    if( mCloseAfterView )	    {		allowCloseEvent = TRUE;                mCloseAfterView = FALSE;                slotListView();		close();		mCloseAfterView = FALSE;	    }	    else	{		allowCloseEvent = FALSE;		slotListView();	}	}	else	{	    allowCloseEvent = FALSE;	    PimContact prevContact = mContactViewStack.last();	    abList->setCurrentEntry( prevContact.uid() );	    slotDetailView();	}    }    else #endif    if( mCloseAfterView )    {        mCloseAfterView = FALSE;	allowCloseEvent = TRUE;        slotListView();	close();    }    else    {	allowCloseEvent = FALSE;	slotListView();    }}void AddressbookWindow::slotFind(bool s){#ifndef QTOPIA_PHONE    if ( !searchBar ) {	// Search bar	searchBar = new QPEToolBar(this);	addToolBar( searchBar, "", QMainWindow::Top, TRUE );	searchBar->setHorizontalStretchable( TRUE );	searchEdit = new QLineEdit( searchBar, "searchEdit" );	QPEApplication::setInputMethodHint(searchEdit,"addressbook-names");	searchBar->setStretchableWidget( searchEdit );	connect( searchEdit, SIGNAL(textChanged(const QString&)),		this, SLOT(search(const QString &)) );    }    if ( s ) {	if ( centralWidget() == abView() )	    slotListView();	searchBar->show();	searchEdit->setFocus();	abList->setKeyChars( searchEdit->text() );    } else {	searchBar->hide();	if ( abList->numSelections() )	    abList->clearSelection();	bool hasCurrentEntry = abList->hasCurrentEntry();	QUuid uid;	if( hasCurrentEntry )	    uid = abList->currentEntry().uid();	abList->setKeyChars(""); // destroys current	abList->setFocus();	if( hasCurrentEntry )	    abList->setCurrentEntry( uid );    }#else    Q_UNUSED(s);#endif}void AddressbookWindow::search( const QString &k ){#ifndef QTOPIA_DESKTOP    abList->setKeyChars( k );#endif}void AddressbookWindow::slotSetCategory( int c ){    //abList->setPaintingEnabled( false );    contacts.setFilter( c );    abList->reload();    //abList->setPaintingEnabled( true );#ifndef QTOPIA_DESKTOP#ifndef QTOPIA_PHONE    setCaption( tr("Contacts") + " - " + categoryLabel( c ) );#else    if (c == -2) {	if ( actionSendCat )	    actionSendCat->setText(tr("Send All..."));	categoryLbl->hide();    } else {	QString lbl = categoryLabel(c);	if ( actionSendCat )	    actionSendCat->setText(tr("Send %1...").arg(lbl));	categoryLbl->setText(tr("Category: %1").arg(lbl));	categoryLbl->show();    }#endif#endif}// Loop through and validate the categories.  If any records' category list was// modified we need to updatevoid AddressbookWindow::catChanged(){    Categories c;    c.load( categoryFileName() );    QArray<int> cats = c.ids("Address Book", c.labels("Address Book", TRUE) ); // No tr    bool changed = FALSE;    QListIterator<PrContact> it(contacts.contacts());    for(; it.current(); ++it)     {	PimContact t( *(*it) );	if ( t.pruneDeadCategories( cats ) ) 	{	    contacts.updateContact( t );	    changed = TRUE;	}    }        if ( changed )	abList->reload();}QString AddressbookWindow::categoryLabel( int id ){    // This is called seldom, so calling a load in here    // should be fine.    cats.load( categoryFileName() );    if ( id == -1 )	return tr( "Unfiled" );    else if ( id == -2 )	return tr( "All" );        QArray<int> ids( 1 );    ids[0] = id;    return cats.displaySingle( "Address Book", // No tr()		    ids, Categories::ShowFirst );}/* simply disabled for now although this might be usefulvoid AddressbookWindow::contactFilterSelected( int idx ){    int cid = contactMap[idx];    abList->setPreferredField( cid );    qDebug("reloading with preferred");    abList->reload();}*/void AddressbookWindow::selectAll(){//    abList->selectAll();//    updateIcons();}void AddressbookWindow::configure(){    AbSettings settings(this, "", TRUE);#ifndef QTOPIA_PHONE    settings.setCurrentFields( abList->fields() );#endif    if ( QPEApplication::execDialog(&settings) == QDialog::Accepted ) {#ifndef QTOPIA_PHONE	abList->setFields( settings.fields() );	abList->reload();#else	settings.saveFormat();	// Could try to preserve special-cased fileAs items,	// but the semantics for those needs to be defined.	// Could ask the user, but it's not the common case.	bool changed = FALSE;	extern void qpe_setNameFormatCache(bool);	qpe_setNameFormatCache(TRUE);	QListIterator<PrContact> it(contacts.contacts());	for(; it.current(); ++it)	{	    PimContact t( *(*it) );	    QString fn = t.fullName();	    if ( fn != t.fileAs() ) {		t.setFileAs(fn);		contacts.updateContact( t );		changed = TRUE;	    }	}	qpe_setNameFormatCache(FALSE);	if ( changed )	    abList->reload();#endif    }}void AddressbookWindow::selectCategory(){#ifdef QTOPIA_PHONE    // always recreate so it gets refreshed properly    categoryDlg = new CategorySelectDialog("Address Book", this, 0, TRUE);    categoryDlg->setAllCategories(TRUE);    connect(categoryDlg, SIGNAL(selected(int)), this, SLOT(slotSetCategory(int)));    QPEApplication::execDialog(categoryDlg);    delete categoryDlg;    categoryDlg = 0;#endif}#ifdef QTOPIA_PHONEvoid AddressbookWindow::smsBusinessCard(){    bool srvExists = FALSE; // check for SMS service    Config srv(Service::config("Email"),Config::File);    srvExists = srv.isValid();    if ( !abList->hasCurrentEntry() || !srvExists) // nothing selected or srv not avail    {	    close();	    return;    }        QString description;    ::unlink( beamfile.local8Bit().data() ); // delete if exists    // 160 chars limitation for a sms    // business numbers and home mobile will be transmitted    PimContact my((const PimContact &)contacts.personal());    PimContact bCard;    bCard.setFirstName(my.firstName());    bCard.setLastName(my.lastName());	    bCard.setBusinessPhone(my.businessPhone());    bCard.setBusinessFax(my.businessFax());    bCard.setBusinessMobile(my.businessMobile());    bCard.setHomeMobile(my.homeMobile());    PimContact::writeVCard( beamfile, bCard);        ServiceRequest service("Email", "writeSms(QString,QString,QCString)");    service<< QString::null;    service<< QString::null;    service<< QCString(beamfile);    service.send();    close();}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -