📄 addressbook.cpp
字号:
){#ifdef QTOPIA_PHONE sel_href = l; //link isn't null and isn't a qdl link actionSpeedDial->setEnabled( !l.isNull() && !l.startsWith("qdl:") ); if( l.startsWith("dialer:") && mGotSimEntries ) { actionOnSim->setEnabled( TRUE ); QString number = l.mid( 7 ); if( number.startsWith( "phoneType:" ) ) { number = number.mid( 10 ); int f = number.find(":"); if( f != -1 ) { int phoneType = number.left( f ).toInt(); PimContact ent = mView->entry(); if( ent.customField("SIM_CONTACT").isEmpty() ) { //not a sim contact.. merge available phonebook data with the contact. QMap<QString,PimContact *> simData = abList->existingContactSimData(); if( simData.contains( ent.fileAs().lower() ) ) AbUtil::mergeSimContact( ent, *simData[ent.fileAs().lower()] ); } mToggleInternal = TRUE; actionOnSim->setOn( ent.customField( AbUtil::simKeyForPhoneType( phoneType ) ).length() ); mToggleInternal = FALSE; } } } else { actionOnSim->setEnabled( FALSE ); }#endif}void AddressbookWindow::storeOnSim( bool #ifdef QTOPIA_PHONE b #endif ){#ifdef QTOPIA_PHONE if( mToggleInternal ) //action was just toggled internally return; if( sel_href.isNull() ) return; if( sel_href.startsWith("dialer:") ) { QString number = sel_href.mid( 7 ); if( number.startsWith( "phoneType:" ) ) { number = number.mid( 10 ); int f = number.find(":"); if( f != -1 ) { int phoneType = number.left( f ).toInt(); number = number.mid( f+1 ); PimContact ent = mView->entry(); //toggle the sim key for this number bool isSimContact = !ent.customField("SIM_CONTACT").isEmpty(); if( !isSimContact ) { //not a sim contact.. merge available phonebook data with the contact. QMap<QString,PimContact *> simData = abList->existingContactSimData(); if( simData.contains( ent.fileAs().lower() ) ) AbUtil::mergeSimContact( ent, *simData[ent.fileAs().lower()] ); } QString k = AbUtil::simKeyForPhoneType( phoneType ); if( !b ) ent.removeCustomField( k ); else ent.setCustomField( k, "1" ); bool closeView = FALSE; if( isSimContact && AbUtil::numbersForSimCount( ent ) == 0 ) { //sim contact and all numbers have been removed int r = QMessageBox::warning( this, tr("Remove SIM Contact"), tr("<qt>Removing '%1' will remove the contact '%2' from the SIM entirely. " "Are you sure you want to do this?</qt>").arg(number).arg(ent.fileAs()), QMessageBox::Yes, QMessageBox::No | QMessageBox::Default ); if( r == QMessageBox::No ) { setHighlightedLink( sel_href ); // reset back to on return; } else { // contact we're viewing will be deleted, so close the view closeView = TRUE; } } AbUtil::syncContactWithSim( ent, mPhoneBookEntries, mPhoneLine->phoneBook() ); if( closeView ) viewClosed(); } } }#endif}void AddressbookWindow::addToSpeedDial(){#ifdef QTOPIA_PHONE if ( !sel_href.isNull() ) { PimContact ent = abList->currentEntry(); ServiceRequest req; QString pm; mView->decodeHref(sel_href,&req,&pm); SpeedDial::addWithDialog(ent.fileAs(), "addressbook/"+pm, req, this); }#endif}void AddressbookWindow::slotListDelete(){ if ( checkSyncing() ) return; if ( FALSE ) {#ifndef QTOPIA_PHONE QValueList<QUuid> t = abList->selectedContacts(); if ( !t.count() ) return; QString str; if ( t.count() > 1 ) { str = QString("<qt>Are you sure you want to delete the %1 selected contacts?</qt>").arg( t.count() ); } else { // some duplicated code, but selected/current logic might change, so I'll leave it as it is PimContact tmpEntry = abList->currentEntry(); QString strName = tmpEntry.fileAs(); if ( strName.isEmpty() ) { strName = tmpEntry.company(); if ( strName.isEmpty() ) strName = tr("No Name"); } str = QString("<qt>Are you sure you want to delete: <b>%1</b> ?</qt>").arg( strName ); } switch( QMessageBox::warning( this, tr("Contacts"), tr(str), tr("Yes"), tr("No"), 0, 0, 1 ) ) { case 0: { deleteContacts(t); updateIcons(); slotListView(); } break; case 1: break; }#endif } else { PimContact tmpEntry = abList->currentEntry(); // get a name, do the best we can... QString strName = tmpEntry.fileAs(); if ( strName.isEmpty() ) { strName = tmpEntry.company(); if ( strName.isEmpty() ) strName = tr("No Name"); } if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), strName ) ) { PimContact curEntry = abList->currentEntry();#ifdef QTOPIA_PHONE if( AbUtil::hasNumbersForSim( curEntry ) ) { for( int i = 0 ; i < AbUtil::numPhoneFields ; ++i ) curEntry.setCustomField( AbUtil::simKeyForPhoneType( AbUtil::phoneFields[i] ), QString::null ); } AbUtil::syncContactWithSim( curEntry, mPhoneBookEntries, mPhoneLine->phoneBook() ); if( curEntry.customField( "SIM_CONTACT" ).isEmpty() ) //real contact#endif contacts.removeContact( curEntry ); abList->reload(); if( centralWidget() == mView ) viewClosed(); else slotListView(); } }}void AddressbookWindow::deleteContacts(QValueList<QUuid> &t){ for (QValueList<QUuid>::ConstIterator it = t.begin(); it != t.end(); ++it) { PrContact t; t.setUid( *it ); contacts.removeContact(t); } abList->reload();}void AddressbookWindow::slotViewBack(){ slotListView();}void AddressbookWindow::slotViewEdit(){ if( !checkSyncing()) { editEntry( abList->currentEntry() ); }}void AddressbookWindow::beamContacts(const QString& description, const QValueList<PimContact>& list){ PimContact::writeVCard( beamfile, list ); beamVCard( beamfile.local8Bit(), description );}void AddressbookWindow::beamVCard( const QCString &filename, const QString &description ){ unlink( filename.data() ); // delete if exists Ir *ir = new Ir( this ); connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); ir->send( filename.data(), description, "text/x-vCard" );#ifdef DEBUG if ( !Ir::supported() ) { QMessageBox::information( this, "Beam", tr("<qt>vCard stored in %1</qt>").arg(filename.data()) ); }#endif}void AddressbookWindow::beamDone( Ir *ir ){ delete ir; ::unlink( beamfile.local8Bit().data() );}/*static void parseName( const QString& name, QString *first, QString *middle, QString * last ){ int comma = name.find ( "," ); QString rest; if ( comma > 0 ) { *last = name.left( comma ); comma++; while ( comma < int(name.length()) && name[comma] == ' ' ) comma++; rest = name.mid( comma ); } else { int space = name.findRev( ' ' ); *last = name.mid( space+1 ); rest = name.left( space ); } int space = rest.find( ' ' ); if ( space <= 0 ) { *first = rest; } else { *first = rest.left( space ); *middle = rest.mid( space+1 ); }}*//* Show item defined by uid, then close once user goes back.*/void AddressbookWindow::showJustItem(const QUuid& uid){ if( isHidden() ) // only close after view if hidden on first activation { mCloseAfterView = TRUE; }#ifdef QTOPIA_PHONE abList->setKeyChars( "" );//make the whole list visible#endif mResetKeyChars = FALSE; abList->setCurrentEntry( uid ); slotDetailView(); updateIcons();}void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data){ if (msg == "editPersonal()") { QPEApplication::setKeepRunning(); editPersonal(); } else if (msg == "editPersonalAndClose()") { QPEApplication::setKeepRunning(); editPersonal(); close(); } else if ( msg == "receiveData(QString,QString)" ) { QDataStream stream(data,IO_ReadOnly); QString f,t; stream >> f >> t; if ( t.lower() == "text/x-vcard" ) receiveFile(f); QFile::remove(f); } else if ( msg == "addContact(PimContact)" ) { QDataStream stream(data,IO_ReadOnly); PimContact c; stream >> c; NameLearner learner(c); contacts.addContact( c ); abList->reload(); } else if ( msg == "removeContact(PimContact)" ) { QDataStream stream(data,IO_ReadOnly); PimContact c; stream >> c; contacts.removeContact( c ); abList->reload(); } else if ( msg == "updateContact(PimContact)" ) { QDataStream stream(data,IO_ReadOnly); PimContact c; stream >> c; NameLearner learner(c); contacts.updateContact( c ); abList->reload(); } else if ( msg == "addAndEditContact(PimContact)" ) { QPEApplication::setKeepRunning(); QDataStream stream(data,IO_ReadOnly); PimContact c; stream >> c; abView()->init( c ); newEntry( c ); } else if ( msg == "showContact(QUuid)" ) { QPEApplication::setKeepRunning(); QUuid uid; QDataStream stream(data, IO_ReadOnly); stream >> uid; showJustItem(uid);#ifdef Q_WS_QWS } else if ( msg == "beamBusinessCard()" ) { if (contacts.hasPersonal()) { QString description; ::unlink( beamfile.local8Bit().data() ); // delete if exists PimContact c((const PimContact &)contacts.personal()); PimContact::writeVCard( beamfile, c ); description = c.fileAs(); Ir *ir = new Ir( this ); connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); ir->send( beamfile, description, "text/x-vCard" ); } else { QMessageBox::warning( this, tr("Contacts"), "<qt>"+tr("No business card set.")+"</qt>"); }#endif }#ifdef QTOPIA_PHONE else if( msg == "smsBusinessCard()") { if( abList->numRows() == 0 || !contacts.hasPersonal()) { QMessageBox::warning( this, tr("Contacts"), "<qt>"+tr("No business card set.")+"</qt"); } else { //QPEApplication::setKeepRunning(); smsBusinessCard(); } }#endif else if( msg == "addPhoneNumberToContact(QString)" ) { QDataStream stream( data, IO_ReadOnly ); QString phoneNumber; stream >> phoneNumber; ContactSelector *s = new ContactSelector( TRUE, &contacts, this ); if(#ifndef QTOPIA_DESKTOP QPEApplication::execDialog( s ) #else s->exec()#endif && s->selectedType() != ContactSelector::NoSelection ) { PimContact cnt; bool isNew = FALSE; if( s->selectedType() == ContactSelector::SelectedContacts ) { QValueList<PimContact> selCnts = s->selected(); if( selCnts.count() <= 0) qDebug("BUG - Selected contacts is 0 but we have a selection"); cnt = selCnts.first(); } else if( s->selectedType() == ContactSelector::SelectedNew ) { isNew = TRUE; } //get the user to choose the type of the number PhoneTypeSelector *pts = new PhoneTypeSelector( cnt, phoneNumber, this ); if(#ifndef QTOPIA_DESKTOP QPEApplication::execDialog( pts ) #else pts->exec()#endif && pts->selected() != -1 ) { int f = pts->selected(); cnt.setField( f, phoneNumber ); if( isNew ) { abView()->init( cnt ); newEntry( cnt ); } else { contacts.updateContact( cnt ); abList->reload(); } } } }#ifdef QTOPIA_DATA_LINKING else if( msg == "QDLRequestLink(QString,QString)" ) { QDataStream stream( data, IO_ReadOnly ); QString clientID, hint; stream >> clientID >> hint; QDLHeartBeat hb( clientID ); ContactSelector *s = new ContactSelector( FALSE, &contacts, ( isVisible() ? this : 0 ), "selector", TRUE ); // No tr#ifndef QTOPIA_DESKTOP if( QPEApplication::execDialog( s ) == QDialog::Accepted )#else if( s->exec() == QDialog::Accepted )#endif {#ifndef QT_NO_QCOP QCopEnvelope e( QDL::CLIENT_CHANNEL, "QDLProvideLink(QString,int,...)" ); e << clientID; QValueList<PimContact> contacts = s->selected(); e << contacts.count(); QValueList<PimContact>::Iterator it; for( it = contacts.begin() ; it != contacts.end() ; ++it ) { QByteArray dataRef; QDataStream refStream( dataRef, IO_WriteOnly ); refStream << (*it).uid().toString(); e << QDLLink( "addressbook", dataRef, (*it).fileAs(), "addressbook/AddressBook" ); }#endif } delete s; } else if( msg == "QDLActivateLink(QByteArray)" ) { QPEApplication::setKeepRunning(); QDataStream stream( data, IO_ReadOnly ); QByteArray dataRef; stream >> dataRef; QDataStream refStream( dataRef, IO_ReadOnly ); QString uidStr; refStream >> uidStr; QUuid uid( uidStr ); showJustItem(uid); }#endif else if( msg == "setContactImage(QImage)" ) { QDataStream stream( data, IO_ReadOnly ); QImage img; stream >> img; ContactSelector *s = new ContactSelector( FALSE, &contacts, this ); s->table->setSelectionMode( AbTable::Single ); if(#ifndef QTOPIA_DESKTOP QPEApplication::execDialog( s ) #else s->exec()#endif && s->selectedType() == ContactSelector::SelectedContacts ) { PimContact cnt = s->selected().first(); QString baseDirStr = Global::applicationFileName( "addressbook", "contactimages/" ); QString pFileName; //remove an old contact image if present pFileName = cnt.customField( "photofile" ); if( !pFileName.isEmpty() ) { QFile oldPhoto( baseDirStr+pFileName ); oldPhoto.remove(); } //create new image QPixmap np; np.convertFromImage( img ); pFileName = AbEditor::createContactImage( np ); if( pFileName.isEmpty() ) qWarning("Unable to save photo file for contact %s", cnt.fileAs().latin1()); cnt.setCustomField( "photofile", pFileName ); contacts.updateContact( cnt ); abList->reload(); } } else if( msg == "beamVCard(QCString,QString,QCString,QString)" ) { QPEApplication::setKeepRunning(); QCString rc, vc; QString id, description; QDataStream stream( data, IO_ReadOnly ); stream >> rc >> id >> vc >> description; beamVCard( vc, description ); }}void AddressbookWindow::slotPersonalView(){ if (showingPersonal) { // we just turned it off setCaption( tr("Contacts") ); updateIcons(); slotListView(); showingPersonal = FALSE; return; } setCaption( tr("Contacts - My Personal Details") ); PimContact me((const PimContact &)contacts.personal()); abList->setCurrentEntry( me.uid() ); viewOpened( me ); abView()->init( me ); abView()->sync(); listView->hide(); setCentralWidget( abView() ); mView->show(); mView->setFocus(); updateIcons();}// hacky static boolstatic bool newPersonal = FALSE;void AddressbookWindow::editPersonal()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -