abeditor.cpp

来自「Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3」· C++ 代码 · 共 2,205 行 · 第 1/5 页

CPP
2,205
字号
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#ifdef QTOPIA_DATA_LINKING#include <qtopia/qdl.h>#endif#include "abeditor.h"#include "addresspicker.h"#ifdef QTOPIA_PHONE#include "emaildialogphone.h"#else#include "emaildlgimpl.h"#endif#include "imagesourcedialog.h"#include "addressbook.h" // for AB_PDA#include <qtopia/vscrollview.h>#include <qtopia/categories.h> // needed to get correct WIN32 exports for QValueList<int>#include <qtopia/categoryselect.h>#include <qtopia/qpeapplication.h>#include <qtopia/qpedialog.h>#include <qtopia/datetimeedit.h>#include <qtopia/global.h>#include <qtopia/resource.h>#include <qtopia/image.h>#ifndef QTOPIA_DESKTOP#include <qtopia/imageselector.h>#endif#ifdef QTOPIA_PHONE#include <qtopia/pim/private/abtable_p.h>#endif#ifdef QTOPIA_PHONE#include <qtopia/contextmenu.h>#include <qtopia/fileselector.h>#endif#include <qlistbox.h>#include <qpainter.h>#include <qtextstream.h>#include <qcombobox.h>#include <qcheckbox.h>#include <qlabel.h>#include <qradiobutton.h>#include <qstyle.h>#include <qaction.h>#include <qlayout.h>#include <qlineedit.h>#include <qmultilineedit.h>#include <qscrollview.h>#include <qtoolbutton.h>#include <qpushbutton.h>#include <qmainwindow.h>#include <qvbox.h>#include <qtabwidget.h>#include <qregexp.h>#include <qwhatsthis.h>#include <qmessagebox.h>#include <qdialog.h>#include <qlist.h>#include <qcstring.h>#include <qstring.h>#include <qwidgetstack.h>#include <qbuttongroup.h>#include <qcolor.h>#include <qfile.h>#include <qfileinfo.h>#include <qwmatrix.h>#include <qdir.h>#ifdef QTOPIA_DESKTOP#include <qinputdialog.h>#include <qfiledialog.h>#endif#ifdef QTOPIA_DESKTOP#include <qtextedit.h>#endif#include <stdio.h>#ifndef QTOPIA_DESKTOP#include <qtopia/iconselect.h>#else#include <qtopia/pixmapdisplay.h>#endif#include <time.h>//make name prefixes globally available and translatableconst QString gNamePrefixStr = QObject::tr( "Mr;Mrs;Ms;Miss;Dr;Prof;" );const QString gNameSuffixStr = QObject::tr( "Jr;Sr;I;II;III;IV;V" );// helper functions, convert our comma delimited list to proper// file format...void parseEmailFrom( const QString &txt, QString &strDefaultEmail,		     QStringList &strAll );// helper convert from file format to comma delimited...void parseEmailTo( const QString &strDefaultEmail,		   const QStringList &emails, QString &strBack );#ifdef QTOPIA_PHONE// helper to add "Store on SIM" to a ContextMenu.QAction *addStoreOnSim(ContextMenu *menu, QObject *parent, const char *slot){    QAction *a = new QAction(qApp->translate("ABEditor", "Store on SIM"),		    QString::null, 0,		    parent, 0 );    a->setToggleAction( TRUE );    QObject::connect( a, SIGNAL(toggled(bool)), parent, slot );    menu->insertSeparator(0);    menu->insertAction(a, 0);    return a;}#endifFileAsCombo::FileAsCombo( QWidget *parent )    : QComboBox( FALSE, parent, "fileAsCombo" ){    setEditable( FALSE );    // the default template is filled with whatever is available and forms a valid name if other templates don't yield any options    // in other words, the default template always yields an option if the user has input any name data    mDefaultTemplate = tr("%prefix %firstname %nickname %middlename %lastname %suffix %firstpro %lastpro",                            "Defines the default name format for a contact's File As.");     mTemplates = QStringList::split( ";",				     tr(					"%firstname %lastname;"					"%lastname, %firstname;"					"%firstname;"					"%lastname;"					"%firstname %middlename %lastname;"					"%prefix %firstname %lastname %suffix;"					"%prefix %firstname %lastname;"					"%prefix %lastname %suffix;"					"%prefix %firstname %suffix;"					"%firstname %lastname %suffix;"					"%prefix %firstname;"					"%prefix %lastname;"					"%firstname %suffix;"					"%lastname %suffix;"					"%middlename;"					"%firstname %nickname %lastname;"					"%nickname %lastname;"					"%nickname;",					"Defines locale-specific name formats for a contact's File As. Different formats are separated by ';'"                                        " Provide new sequences if it is necessary for the localisation otherwise don't provide a translation at all."				       )				   );    mTemplateVars["%prefix"] =     mTemplateVars["%suffix"] =     mTemplateVars["%firstname"] =     mTemplateVars["%middlename"] =     mTemplateVars["%lastname"] =     mTemplateVars["%nickname"] =     mTemplateVars["%firstpro"] =     mTemplateVars["%lastpro"] = QString::null;    connect( this, SIGNAL(activated(int)), this, SLOT(customFileAs(int)) );    update();}void FileAsCombo::setSelected( const QString &fileAs ){    if( fileAs == QString::null )	setCurrentItem( 0 );    else    {	for( int i = 1 ; i < (count()-1) ; ++i )	{	    if( text( i ) == fileAs )	    {		setCurrentItem( i );		return;	    }	}	// item not available - custom. add it	insertItem( fileAs, 1 );	setCurrentItem( 1 );	mCustomEntries.prepend( fileAs );    }}QString FileAsCombo::selected() const{    if( currentItem() == 0 || currentItem() == (count()-1) )	return QString::null;    else	return currentText();}void FileAsCombo::customFileAs( int idx ){    if( idx == (count()-1) )    {#ifdef QTOPIA_DESKTOP        bool ok = FALSE;        QString text = QInputDialog::getText( tr("Add Custom File As"), QString::null, QLineEdit::Normal, QString::null, &ok, this );        if( ok && !text.isEmpty() )            setSelected( text );        else            setSelected( QString::null ); #else	QDialog *dlg = new QDialog( this, "customFileAs", TRUE );	dlg->setCaption( tr("Add Custom File As") );	QVBoxLayout *l = new QVBoxLayout( dlg );	l->setAutoAdd( TRUE );	QLineEdit *le = new QLineEdit( dlg );	le->setFocus();	dlg->setMaximumHeight( le->height() );	if( QPEApplication::execDialog( dlg ) == QDialog::Accepted && !le->text().isEmpty() )	    setSelected( le->text() );	else 	    setSelected( QString::null );	delete dlg;#endif    }}QString FileAsCombo::fillTemplate( const QString &t, bool allowEmpty ){    QString cur = t;    QMap<QString,QString>::ConstIterator jit;    for( jit = mTemplateVars.begin() ; jit != mTemplateVars.end() ; ++jit )    {	int f;	while( (f = cur.find( jit.key() )) != -1 )	{	    if( jit.data().simplifyWhiteSpace().isEmpty() && !allowEmpty )	    {		//template is empty if some data for a variable is this template is empty		return QString::null;	    }	    else	    {		cur.replace( f, jit.key().length(), jit.data() );	    }	}    }    return cur.simplifyWhiteSpace();}void FileAsCombo::update(){    int current = currentItem();    clear();    QStringList options;    options += tr( "(default)" );     options += mCustomEntries;    for( QStringList::ConstIterator iit = mTemplates.begin() ; iit != mTemplates.end() ; ++iit )    {	QString cur = fillTemplate( *iit );	if( !cur.isEmpty() && !options.contains( cur ) )	    options += cur;    }    if( !options.count() ) // no options, put together a default if possible    {	QString def = fillTemplate( mDefaultTemplate, TRUE );	if( def.length() )	    options += def;    }    options += tr("...");    insertStringList( options );    setCurrentItem( current );}void FileAsCombo::setPrefix( const QString &prefix ){    mTemplateVars["%prefix"] = prefix;    update();}void FileAsCombo::setSuffix( const QString &suffix ){    mTemplateVars["%suffix"] = suffix;    update();}void FileAsCombo::setFirstName( const QString &firstName ){    mTemplateVars["%firstname"] = firstName;    update();}void FileAsCombo::setMiddleName( const QString &middleName ){    mTemplateVars["%middlename"] = middleName;    update();}void FileAsCombo::setLastName( const QString &lastName ){    mTemplateVars["%lastname"] = lastName;    update();}void FileAsCombo::setNickName( const QString &nickName ){    mTemplateVars["%nickname"] = nickName;    update();}void FileAsCombo::setFirstNamePro( const QString &firstNamePro ){    mTemplateVars["%firstpro"] = firstNamePro;    update();}void FileAsCombo::setLastNamePro( const QString &lastNamePro ){    mTemplateVars["%lastpro"] = lastNamePro;    update();}//-----------------------------------------------------------------------PhoneFieldType::PhoneFieldType(){}PhoneFieldType::PhoneFieldType( const QString& type_id, const QString &str ){    id = type_id;    pixmap = Resource::loadPixmap(id);    name = str;}PhoneFieldType::PhoneFieldType( const PhoneFieldType &other ){    *this = other;}PhoneFieldType &PhoneFieldType::operator=( const PhoneFieldType &other ){    id = other.id;    pixmap = other.pixmap;    name = other.name;    return *this;}bool  PhoneFieldType::operator==( const PhoneFieldType &other ) const{    return id == other.id;}bool PhoneFieldType::operator!=( const PhoneFieldType &other ) const{    return !(*this == other);}PhoneFieldManager::PhoneFieldManager( QWidget *parent, QGridLayout *layout, int rc )    : QObject( parent, "phoneFieldManager" ), parLayout(layout), rowCount(rc){    mEmitFieldChanged = TRUE;}PhoneFieldManager::~PhoneFieldManager(){    phoneFields.setAutoDelete( TRUE );    phoneFields.clear();  }#ifdef QTOPIA_PHONEvoid PhoneFieldManager::setFieldOnSim( const PhoneFieldType &type, bool onSim ){    QListIterator<PhoneField> it(phoneFields);    for( ; *it ; ++it )    {	if( (*it)->type() == type )	{	    if( (*it)->onSim() != onSim )	    {		(*it)->setOnSim( onSim );	    }	    else	    {		break;	    }	}    }}bool PhoneFieldManager::fieldOnSim( const PhoneFieldType &type ) const{    QListIterator<PhoneField> it(phoneFields);    for( ; *it ; ++it )    {	if( (*it)->type() == type )	{	    return (*it)->onSim();	}    }    return FALSE;}#endifbool PhoneFieldManager::isFull() const{    bool full = FALSE;    if ( phoneFields.count() && (phoneFields.count() >= mTypes.count()) ) {	// if there are no blank fields, we're full	full = TRUE;	QListIterator<PhoneField> it(phoneFields);

⌨️ 快捷键说明

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