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

📄 addressbook.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
#ifdef QTOPIA_PHONEbool AddressbookWindow::eventFilter( QObject *o, QEvent *e ){    if( Global::mousePreferred() ) {	if( o == mFindLE && e->type() == QEvent::KeyPress )	{	    QKeyEvent *ke = (QKeyEvent *)e;	    switch( ke->key() )	    {		case Key_Select:		case Key_Left:		case Key_Right:		case Key_Up:		case Key_Down:		{		    QPEApplication::postEvent( abList, 		    new QKeyEvent( QEvent::KeyPress, ke->key(), 0xffff, 0xffff ) );		    return TRUE;		}	    }	}    }    return FALSE;}#endifvoid AddressbookWindow::sendContact(){    PimContact curEntry;    if( !abList->hasCurrentEntry() )	return;    curEntry = abList->currentEntry();    QString fileAs = curEntry.fileAs().simplifyWhiteSpace();    QValueList<PimContact> l; l.append(curEntry);    sendContacts(fileAs,l);}void AddressbookWindow::sendContactCat(){    QString lbl = categoryLabel(contacts.filter());    sendContacts(tr("%1 contacts","eg. business").arg(lbl), abList->all());}void AddressbookWindow::sendContacts(const QString& description, const QValueList<PimContact>& list){#ifndef QTOPIA_DESKTOP    QString filename;    for( int i = 0 ; i < (int)description.length() ; ++i )	if( description[i].isLetterOrNumber() || description[i] == '-' )	    filename += description[i];	else if( description[i].isSpace() )	    filename += '-';    if( filename.isEmpty() )	filename = "contact";    filename = QString("%1%2-vcard.vcf").arg(Global::tempDir()).arg( filename );    PimContact::writeVCard( filename.utf8(), list );    mSendService->send( filename.utf8(), description );#endif}void AddressbookWindow::setSimFieldLimits( PhoneLine::QueryType #ifdef QTOPIA_PHONE	type#endif	, const QString &#ifdef QTOPIA_PHONE	value#endif	){#ifdef QTOPIA_PHONE    if( type == PhoneLine::SimFieldLimits )	AbUtil::setSimFieldLimits( value );#endif}void AddressbookWindow::phonebookChanged( const PhoneLine&,	const QString& store, const QValueList<PhoneBookEntry>& list ){#ifdef QTOPIA_PHONE    qDebug("phoneBookChanged, num entries =%d", list.count());    //TODO : check what kind of store this is for?    if( !mGotSimEntries )	mPhoneLine->query( PhoneLine::SimFieldLimits ); // first time we've got entries, now find out what the limits are    if( abEditor )	abEditor->setHaveSim( TRUE );    mGotSimEntries = TRUE;    mPhoneBookEntries = list;    abList->setSimContacts( AbUtil::phoneBookToContacts( list ) );    if( mSimIndicator )	mSimIndicator->hide();#else    Q_CONST_UNUSED(list);#endif    Q_CONST_UNUSED(store);}void AddressbookWindow::keyPressEvent(QKeyEvent *e){#ifdef QTOPIA_PHONE    if ( (e->key() == Key_Back || e->key() == Key_No)) {	e->accept();	if( centralWidget() == listView )	{	    allowCloseEvent = TRUE;	    close();	}	else	{	    // slotListView();	    viewClosed(); 	}    }    else#endif	QMainWindow::keyPressEvent(e);}void AddressbookWindow::showEvent( QShowEvent *e ){    QMainWindow::showEvent( e );#ifdef QTOPIA_PHONE    if( !mGotSimEntries )    {	if( !mSimIndicator )	{	    mSimIndicator = new QLabel( tr("Loading SIM..."), listView );	    mSimIndicator->setAlignment( Qt::AlignCenter );	}	mSimIndicator->show();    }    if( Global::mousePreferred() )	mFindLE->setFocus();#endif}void AddressbookWindow::setDocument( const QString &filename ){    receiveFile(filename);}LoadIndicator::LoadIndicator( QWidget *parent, const char *name, WFlags fl )    : QLabel( parent, name, fl ){    setAlignment( AlignCenter );    setFrameStyle( QFrame::Sunken | QFrame::StyledPanel );}void LoadIndicator::center(){    QWidget *w = parentWidget();    if( !w )	w = qApp->desktop();    QPoint pp = w->mapToGlobal( QPoint(0,0) );     QSize s = sizeHint() * 2;    s.setWidth( QMIN(s.width(), w->width()) );    pp = QPoint( pp.x() + w->width()/2 - s.width()/2,		pp.y() + w->height()/ 2 - s.height()/2 );    setGeometry( QRect(pp, s) );}void LoadIndicator::bottom(){    adjustSize();    QWidget *w = parentWidget();    if( !w )	w = qApp->desktop();    setGeometry( 0, w->frameGeometry().bottom()-height(), w->width(), height() );}void LoadIndicator::showEvent( QShowEvent *e ){    QLabel::showEvent( e );}void LoadIndicator::paintEvent( QPaintEvent *e ){    QPainter p( this );    p.fillRect( 0, 0, width(), height(), colorGroup().background() );    p.end();    QLabel::paintEvent( e );}void AddressbookWindow::receiveFile( const QString &filename ){    QString targetFile = filename;    if ( filename.right(8) == ".desktop" ) {	DocLnk lnk(filename);	if ( !lnk.isValid() || lnk.type().lower() != "text/x-vcard" )	    return;	targetFile = lnk.file();    } else if ( targetFile.right(4) != ".vcf" ) {	return;    }    QWidget *mbParent = isVisible() ? this : 0;    LoadIndicator *li = new LoadIndicator( 0 );    li->setText( tr("Reading VCards..") );    li->center();    li->show();    li->repaint();    QValueList<PimContact> cl = PimContact::readVCard( targetFile );    delete li;    if ( cl.count() == 0 ) {	QMessageBox::warning(mbParent, tr("Could not read VCard document"),	    tr("<qt>The VCard document did not contain any valid VCards</qt>") );	return;    }    QValueList<PimContact> newContacts, oldContacts;    for( QValueList<PimContact>::Iterator it = cl.begin(); it != cl.end(); ++it ) {	    if ( contacts.contains(*it) ) {		oldContacts.append( (*it) );	    } else newContacts.append( (*it) );    }    if ( newContacts.count() > 0 ) {	QString list = "";	uint count = 0;	for ( QValueList<PimContact>::Iterator it = newContacts.begin(); it != newContacts.end(); ++it) {	    if ( count < 3 ) {		list += (*it).fileAs() + "\n";	    } else if ( count == 3 ) {		list += "...\n";	    }	    count++;	}	QString msg = tr("<qt>%1 new VCard(s) for %2<br>Do you want to add them to your addressbook?</qt>").arg( newContacts.count() ).arg(list);	if ( QMessageBox::information(mbParent, tr("New contact(s)"), msg, QMessageBox::Ok, QMessageBox::Cancel) ==	    QMessageBox::Ok )	{	    NameLearner namelearner;	    for ( QValueList<PimContact>::Iterator it = newContacts.begin(); it != newContacts.end(); ++it) 	    {		//if we have a photo for this contact, save it to disk		PimContact &curCon = *it;		QString encDataStr( curCon.customField( "phototmp" ) );		if( !encDataStr.isEmpty() )		{		    QByteArray encData;		    encData.duplicate( encDataStr.latin1(), encDataStr.length() );		    QByteArray decData( Global::decodeBase64( encData ) );		    QPixmap np( decData );		    if( !np.isNull() )		    {			QString fn( AbEditor::createContactImage( np ) );			if( fn.isNull() )			    qWarning(QString("AddressBook::receiveFile - Unable to save photo for contact %1").arg(curCon.fileAs()));			else			    curCon.setCustomField( "photofile", fn );		    }		    curCon.removeCustomField( "phototmp" );		}		namelearner.learn(*it);		contacts.addContact( *it );	    }	    abList->reload();	}    } else if ( oldContacts.count() > 0 ) {	QString list = "";	uint count = 0;	for ( QValueList<PimContact>::Iterator it = oldContacts.begin(); it != oldContacts.end(); ++it) {	    if ( count < 3 ) {		list += (*it).fileAs() + "\n";	    } else if ( count == 3 ) {		list += "...\n";	    }	    count++;	}	QString msg = tr("<qt>%1 old VCard(s) for %2<br>The document only contained VCards already in your addressbook</qt>").arg( oldContacts.count() ).arg(list);	QMessageBox::information(mbParent, tr("Contact(s) already registered"), msg, QMessageBox::Ok);    }}void AddressbookWindow::flush(){    contacts.saveData();    syncing = TRUE;}void AddressbookWindow::reload(){    syncing = FALSE;#ifndef QTOPIA_PHONE    QArray<int> vl( 0 );    catSelect->setCategories( vl, "Address Book", // No tr()	tr("Address Book") );    catSelect->setAllCategories( TRUE );#endif    //Force a reload here    abList->reload();    if ( centralWidget() == mView )    {#ifdef QTOPIA_DATA_LINKING    //just refresh the view	mView->init( abList->currentEntry() );	mView->sync();#else	slotDetailView();#endif    }    updateIcons();}void AddressbookWindow::resizeEvent( QResizeEvent *e ){    QMainWindow::resizeEvent( e );    // we receive a resize event from qtable in the middle of the constrution, since    // QTable::columnwidth does qApp->processEvents.  Ignore this event as it causes    // all sorts of init problems for us    if ( !constructorDone )	return;    if ( centralWidget() == listView  )    {	slotListView();    }    else if ( centralWidget() == mView )	showView();}AddressbookWindow::~AddressbookWindow(){    if( contacts.accessMode() != ContactIO::ReadOnly )	if( !contacts.saveData() )	    QMessageBox::information( this, tr( "Contacts" ),		    tr("<qt>Device full.  Some changes may not be saved.</qt>"));    writeConfig();    delete abEditor;#ifdef QTOPIA_PHONE    delete mPhoneLine;#endif}voidAddressbookWindow::readConfig(void){    Config  config("Contacts");    config.setGroup("default");#ifndef QTOPIA_PHONE    catSelect->setCurrentCategory(config.readNumEntry("Category", -2));#endif}voidAddressbookWindow::writeConfig(void){    Config  config("Contacts");    config.setGroup("default");#ifndef QTOPIA_PHONE    config.writeEntry("Category", catSelect->currentCategory());#endif}void AddressbookWindow::updateIcons(){    bool details = centralWidget() == mView;    actionSettings->setEnabled(!details);    #ifdef AB_PDA    actionBack->setEnabled( details );#endif    if ( abList->hasCurrentEntry() ) {	PimContact ce = abList->currentEntry();#ifdef QTOPIA_PHONE	actionSpeedDial->setEnabled( details && (!sel_href.isNull() && !sel_href.startsWith("qdl:")) );	actionOnSim->setEnabled(details && sel_href.startsWith("dialer:") && mGotSimEntries);	const bool enable_item_actions = details;#else	const bool enable_item_actions = TRUE;#endif	actionTrash->setEnabled(enable_item_actions);	actionEdit->setEnabled(enable_item_actions);	if (actionFind)	    actionFind->setEnabled(TRUE);	if ( abList->selectedContacts().count() == 1 ) {	    if (actionSetPersonal)		actionSetPersonal->setEnabled(enable_item_actions);	} else {	    if (actionSetPersonal)		actionSetPersonal->setEnabled(FALSE);	}#ifndef QTOPIA_DESKTOP	if (actionSend) {#ifdef QTOPIA_PHONE	    actionSend->setEnabled(details);#else	    actionSend->setEnabled(TRUE);#endif	    actionSendCat->setEnabled(!details);	}#endif#ifdef QTOPIA_PHONE	ContextBar::setLabel( abList, Qt::Key_Select, ContextBar::View);#endif    } else {#ifdef QTOPIA_PHONE	actionSpeedDial->setEnabled(FALSE);	actionOnSim->setEnabled( FALSE );#endif	actionEdit->setEnabled(FALSE);	actionTrash->setEnabled(FALSE);	// If find is open, need to close it first.	if (actionFind && actionFind->isOn())	    actionFind->setOn(FALSE);	if (actionFind)	    actionFind->setEnabled(FALSE);	if (actionSetPersonal)	    actionSetPersonal->setEnabled(FALSE);#ifndef QTOPIA_DESKTOP	if (actionSend) {	    actionSend->setEnabled(FALSE);	    actionSendCat->setEnabled(FALSE);	}#endif#ifdef QTOPIA_PHONE        ContextBar::setLabel( abList, Qt::Key_Select, "new", QString::null );#endif    }    if (actionPersonal)	actionPersonal->setEnabled( contacts.hasPersonal() );}void AddressbookWindow::showView(){    listView->hide();    setCentralWidget( abView() );    mView->show();    mView->setFocus();#ifdef QTOPIA_PHONE    if( !Global::mousePreferred() )	mView->setModalEditing( TRUE );#endif    updateIcons();    setCaption( tr("Contact Details") );#ifdef QTOPIA_PHONE    actionNew->setEnabled(FALSE);    actionCategory->setEnabled(FALSE);#endif}bool AddressbookWindow::checkSyncing(){    if (syncing) {	if ( QMessageBox::warning(this, tr("Contacts"),			     tr("<qt>Can not edit data, currently syncing</qt>"),			    QMessageBox::Ok, QMessageBox::Abort ) == QMessageBox::Abort )	{	    // Okay, if you say so (eg. Qtopia Desktop may have crashed)....	    syncing = FALSE;	} else	    return TRUE;    }    return FALSE;}void AddressbookWindow::slotListNew(){    PimContact cnt;    if( !checkSyncing() ) {	abView()->init( cnt );	newEntry( cnt );    }}void AddressbookWindow::selectClicked(){    if( abList->numRows() == 0 )    {	slotListNew();    }    else    {	slotDetailView();    }}void AddressbookWindow::slotDetailView(){    if ( abList->hasCurrentEntry() ) {	if (actionFind && actionFind->isOn())	    actionFind->setOn(FALSE);	PimContact curEntry = abList->currentEntry();	viewOpened( curEntry );	setHighlightedLink( QString::null );	abView()->init( curEntry );	mView->sync();	showView();	mResetKeyChars = TRUE;    }}void AddressbookWindow::slotListView(){#ifdef QTOPIA_PHONE    PimContact currentContact = abList->currentEntry();    if( mResetKeyChars )    {	//previous view was something else	mResetKeyChars = FALSE;	abList->setKeyChars( "" );    }#endif    if ( !abList->isVisible() ) {	abView()->hide();	setCentralWidget( listView );	listView->show();#ifdef QTOPIA_PHONE	if( Global::mousePreferred() )	    mFindLE->setFocus();	else	    abList->setFocus();#endif#ifdef QTOPIA_PHONE	//sim contacts don't have uids, so set it by its fileas	if( !currentContact.customField("SIM_CONTACT").isEmpty() )	    abList->setCurrentSimEntry( currentContact.fileAs() );	else	    abList->setCurrentEntry( currentContact.uid() );#endif	setCaption( tr("Contacts") );    }    updateIcons();#ifdef QTOPIA_PHONE    actionNew->setEnabled(TRUE);    actionCategory->setEnabled(TRUE);#endif}void AddressbookWindow::setHighlightedLink(const QString& #ifdef QTOPIA_PHONE	l#endif

⌨️ 快捷键说明

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