📄 addressbook.cpp
字号:
setCaption( tr("Contacts") ); setViewOptions(TRUE); } }void AddressbookWindow::slotListDelete(){ if ( checkSyncing() ) return; if ( abList->selectionMode() == AbTable::Extended ) { 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.fullName(); 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; } } else { PimContact tmpEntry = abList->currentEntry(); // get a name, do the best we can... QString strName = tmpEntry.fullName(); if ( strName.isEmpty() ) { strName = tmpEntry.company(); if ( strName.isEmpty() ) strName = tr("No Name"); } if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), strName ) ) { contacts.removeContact( abList->currentEntry() ); abList->reload(); 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()) { if ( !bAbEditFirstTime ) abEditor->setEntry( abList->currentEntry() ); editEntry( EditEntry ); }}void AddressbookWindow::slotViewDuplicate(void){ if( !checkSyncing()) { duplicateEntry(); }}void AddressbookWindow::writeMail(){ PimContact c = abList->currentEntry(); QString name = c.fileAs(); QString email = c.defaultEmail();#ifndef QT_NO_COP QCopEnvelope e(Service::channel("Email"), "writeMail(QString,QString)"); e << name << email;#endif}static const char * beamfile = "/tmp/obex/contact.vcf";void AddressbookWindow::slotBeam(){ QString filename, description; unlink( beamfile ); // delete if exists if ( !abList->hasCurrentEntry() ) { qWarning("ab::slotBeam called with nothing to beam"); return; }#ifndef Q_OS_WIN32 mkdir("/tmp/obex/", 0755);#else QDir d; d.mkdir("/tmp/obex");#endif filename = beamfile; if ( abList->selectionMode() == AbTable::Extended && abList->selectedContacts().count() > 0 ) { PimContact::writeVCard( beamfile, abList->selected() ); uint count = abList->selectedContacts().count(); if ( count > 1 ) description = QString("the %1 selected contacts").arg( abList->selectedContacts().count() ); else description = abList->currentEntry().fullName(); } else { PimContact c = abList->currentEntry(); PimContact::writeVCard( beamfile, c ); description = c.fullName(); } Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); ir->send( filename, description, "text/x-vCard" );}void AddressbookWindow::beamDone( Ir *ir ){ delete ir; unlink( beamfile );}/*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 ); }}*/void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data){ if (msg == "editPersonal()") { editPersonal(); } else if (msg == "editPersonalAndClose()") { 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; 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; contacts.updateContact( c ); abList->reload(); } else if ( msg == "addAndEditContact(PimContact)" ) { QDataStream stream(data,IO_ReadOnly); PimContact c; stream >> c; if ( bAbEditFirstTime ) { abEditor = new AbEditor( this ); abEditor->setEntry( c ); bAbEditFirstTime = FALSE; } else { abEditor->setEntry( c ); } abView()->init( c ); editEntry( NewEntry ); } else if ( msg == "showContact(QUuid)" ) { QUuid u; QDataStream stream(data, IO_ReadOnly); stream >> u; abList->setCurrentEntry(u); slotListView();#ifdef Q_WS_QWS } else if ( msg == "beamBusinessCard()" ) { if (contacts.hasPersonal()) { QString filename, description; unlink( beamfile ); // delete if exists#ifndef Q_OS_WIN32 mkdir("/tmp/obex/", 0755);#else QDir d; d.mkdir("/tmp/obex");#endif filename = beamfile; PimContact c((const PimContact &)contacts.personal()); PimContact::writeVCard( beamfile, c ); description = c.fullName(); Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); ir->send( filename, description, "text/x-vCard" ); }#endif }}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() ); abView()->init( me ); abView()->sync(); listView->hide(); setCentralWidget( abView() ); mView->show(); mView->setFocus(); actionList->setOn( FALSE ); actionDetails->setOn( TRUE );}// hacky static boolstatic bool newPersonal = FALSE;void AddressbookWindow::editPersonal(){ if (contacts.hasPersonal()) { PrContact me(contacts.personal()); if ( bAbEditFirstTime ) { abEditor = new AbEditor( isVisible() ? this : 0 ); bAbEditFirstTime = FALSE; } abEditor->setEntry( me ); abView()->init( me ); newPersonal = FALSE; editEntry( EditEntry ); } else { newPersonal = TRUE; editEntry( 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::warning(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(){ if ( abList->hasCurrentEntry() ) { int cr = abList->currentRow(); if ( ++cr < abList->numRows() ) { abList->setCurrentCell( cr, 0 ); abView()->init( abList->currentEntry() ); mView->sync(); } }}void AddressbookWindow::viewPrevious(){ if ( abList->hasCurrentEntry() ) { int cr = abList->currentRow(); if ( --cr >= 0 ) { abList->setCurrentCell( cr, 0 ); abView()->init( abList->currentEntry() ); mView->sync(); } }}void AddressbookWindow::editEntry( EntryMode entryMode ){ PimContact entry; if ( bAbEditFirstTime ) { abEditor = new AbEditor( isVisible() ? this : 0 ); if ( entryMode == NewEntry ) { QArray<int> cats(1); cats[0] = catSelect->currentCategory(); entry.setCategories( cats ); } abEditor->setEntry( entry ); bAbEditFirstTime = FALSE; if ( entryMode == EditEntry ) abEditor->setEntry( abList->currentEntry() ); } // fix the foxus... abEditor->setNameFocus(); if ( QPEApplication::execDialog(abEditor) ) { setFocus(); if ( entryMode == NewEntry ) { PimContact insertEntry = abEditor->entry(); QUuid ui = contacts.addContact( insertEntry ); if (newPersonal) contacts.setAsPersonal(ui); abList->reload(); updateIcons(); abList->setCurrentEntry(ui); } else { PimContact replaceEntry = abEditor->entry(); contacts.updateContact( replaceEntry ); abList->reload(); abList->setCurrentEntry(replaceEntry.uid()); } } if ( centralWidget() == abView() ) slotDetailView();}void AddressbookWindow::duplicateEntry(void){ PimContact duplicate; if (abList->hasCurrentEntry()) { duplicate = abList->currentEntry(); duplicate.setLastName(tr("%1 (duplicate)","Noun"). arg(duplicate.lastName())); duplicate.setFileAs(); contacts.addContact( duplicate ); abList->reload(); slotListView(); }}void AddressbookWindow::closeEvent( QCloseEvent *e ){ // in case we are showing details, close that view slotListView(); e->accept();}AbLabel *AddressbookWindow::abView(){ if ( !mView ) { mView = new AbLabel( this ); mView->init( PimContact() ); connect( mView, SIGNAL(okPressed()), this, SLOT( slotListView() ) ); connect( mView, SIGNAL(previous()), this, SLOT( viewPrevious() ) ); connect( mView, SIGNAL(next()), this, SLOT( viewNext() ) ); } return mView;}void AddressbookWindow::slotFind(bool s){ if ( !searchBar ) { // Search bar searchBar = new QPEToolBar(this); addToolBar( searchBar, "", QMainWindow::Top, TRUE ); searchBar->setHorizontalStretchable( TRUE ); searchEdit = new QLineEdit( searchBar, "searchEdit" ); searchBar->setStretchableWidget( searchEdit ); connect( searchEdit, SIGNAL(textChanged(const QString &)), this, SLOT(search()) ); connect( searchEdit, SIGNAL(returnPressed()), this, SLOT(search()) ); QAction *a = new QAction( tr( "Find Next" ), Resource::loadIconSet( "next" ), QString::null, 0, this, 0 ); connect( a, SIGNAL(activated()), this, SLOT(search()) ); a->setWhatsThis( tr("Find the next occurrence of the search text.") ); a->addTo( searchBar ); } if ( s ) { if ( centralWidget() == abView() ) slotListView(); searchBar->show(); searchEdit->setFocus(); } else { searchBar->hide(); if ( abList->numSelections() ) abList->clearSelection(); abList->clearFindRow(); }}void AddressbookWindow::search(){ abList->findNext( searchEdit->text(), contacts.filter() );}void AddressbookWindow::findWrapped(){ Global::statusMessage( tr("Find: reached end") );}void AddressbookWindow::findNotFound(){ Global::statusMessage( tr("Find: not found") );}void AddressbookWindow::findFound(){ Global::statusMessage( "" );}void AddressbookWindow::slotSetCategory( int c ){ //abList->setPaintingEnabled( false ); contacts.setFilter( c ); abList->reload(); //abList->setPaintingEnabled( true ); setCaption( tr("Contacts") + " - " + categoryLabel( c ) );}// Loop through and validate the categories. If any records' category list was// modified we need to updatevoid AddressbookWindow::catChanged(){ QListIterator<PrContact> it(contacts.contacts() ); Categories c; c.load( categoryFileName() ); QArray<int> cats = c.ids("Address Book", c.labels("Address Book", TRUE) ); // No tr bool changed = FALSE; 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" ); return cats.label( "Address Book", // No tr() id );}void AddressbookWindow::contactFilterSelected( int idx ){ int cid = contactMap[idx]; abList->setPreferredField( cid ); abList->reload();}void AddressbookWindow::selectAll(){ abList->selectAll(); updateIcons();}void AddressbookWindow::configure(){ AbSettings settings(this, "", TRUE); settings.setCurrentFields( abList->fields() ); if ( QPEApplication::execDialog(&settings) == QDialog::Accepted ) { abList->setFields( settings.fields() ); abList->reload(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -