author | zautrix <zautrix> | 2004-09-13 21:35:12 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-13 21:35:12 (UTC) |
commit | bd6b4acb39498ffea3beea7d9b5f7620b60c14db (patch) (side-by-side diff) | |
tree | e2d7425b7bb49fbcb7acb5ced497ac1fed06dfaf | |
parent | 06eabf6e82c0390699d11fd12580d91261829431 (diff) | |
download | kdepimpi-bd6b4acb39498ffea3beea7d9b5f7620b60c14db.zip kdepimpi-bd6b4acb39498ffea3beea7d9b5f7620b60c14db.tar.gz kdepimpi-bd6b4acb39498ffea3beea7d9b5f7620b60c14db.tar.bz2 |
Many bugfixes
-rw-r--r-- | kabc/addressee.cpp | 62 | ||||
-rw-r--r-- | kaddressbook/addresseeeditorwidget.cpp | 56 | ||||
-rw-r--r-- | kaddressbook/mainembedded.cpp | 15 | ||||
-rw-r--r-- | kaddressbook/nameeditdialog.cpp | 7 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/genericwrapper.cpp | 2 | ||||
-rw-r--r-- | korganizer/calendarview.cpp | 8 | ||||
-rw-r--r-- | libkdepim/addresseeview.cpp | 10 | ||||
-rw-r--r-- | libkdepim/kdateedit.cpp | 17 | ||||
-rw-r--r-- | libkdepim/kdateedit.h | 3 | ||||
-rw-r--r-- | microkde/kdeui/kaction.cpp | 44 |
10 files changed, 144 insertions, 80 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 6b282e2..4cdd5e5 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -420,797 +420,801 @@ QString Addressee::businessAddressPostalCodeLabel() return i18n("Business Address Postal Code"); } QString Addressee::businessAddressCountryLabel() { return i18n("Business Address Country"); } QString Addressee::businessAddressLabelLabel() { return i18n("Business Address Label"); } QString Addressee::homePhoneLabel() { return i18n("Home Phone"); } QString Addressee::businessPhoneLabel() { return i18n("Business Phone"); } QString Addressee::mobilePhoneLabel() { return i18n("Mobile Phone"); } QString Addressee::homeFaxLabel() { return i18n("Home Fax"); } QString Addressee::businessFaxLabel() { return i18n("Business Fax"); } QString Addressee::carPhoneLabel() { return i18n("Car Phone"); } QString Addressee::isdnLabel() { return i18n("ISDN"); } QString Addressee::pagerLabel() { return i18n("Pager"); } QString Addressee::sipLabel() { return i18n("SIP"); } QString Addressee::emailLabel() { return i18n("Email Address"); } void Addressee::setMailer( const QString &mailer ) { if ( mailer == mData->mailer ) return; detach(); mData->empty = false; mData->mailer = mailer; } QString Addressee::mailer() const { return mData->mailer; } QString Addressee::mailerLabel() { return i18n("Mail Client"); } void Addressee::setTimeZone( const TimeZone &timeZone ) { if ( timeZone == mData->timeZone ) return; detach(); mData->empty = false; mData->timeZone = timeZone; } TimeZone Addressee::timeZone() const { return mData->timeZone; } QString Addressee::timeZoneLabel() { return i18n("Time Zone"); } void Addressee::setGeo( const Geo &geo ) { if ( geo == mData->geo ) return; detach(); mData->empty = false; mData->geo = geo; } Geo Addressee::geo() const { return mData->geo; } QString Addressee::geoLabel() { return i18n("Geographic Position"); } void Addressee::setTitle( const QString &title ) { if ( title == mData->title ) return; detach(); mData->empty = false; mData->title = title; } QString Addressee::title() const { return mData->title; } QString Addressee::titleLabel() { return i18n("Title"); } void Addressee::setRole( const QString &role ) { if ( role == mData->role ) return; detach(); mData->empty = false; mData->role = role; } QString Addressee::role() const { return mData->role; } QString Addressee::roleLabel() { return i18n("Role"); } void Addressee::setOrganization( const QString &organization ) { if ( organization == mData->organization ) return; detach(); mData->empty = false; mData->organization = organization; } QString Addressee::organization() const { return mData->organization; } QString Addressee::organizationLabel() { return i18n("Organization"); } void Addressee::setNote( const QString ¬e ) { if ( note == mData->note ) return; detach(); mData->empty = false; mData->note = note; } QString Addressee::note() const { return mData->note; } QString Addressee::noteLabel() { return i18n("Note"); } void Addressee::setProductId( const QString &productId ) { if ( productId == mData->productId ) return; detach(); mData->empty = false; mData->productId = productId; } QString Addressee::productId() const { return mData->productId; } QString Addressee::productIdLabel() { return i18n("Product Identifier"); } void Addressee::setRevision( const QDateTime &revision ) { if ( revision == mData->revision ) return; detach(); mData->empty = false; mData->revision = revision; } QDateTime Addressee::revision() const { return mData->revision; } QString Addressee::revisionLabel() { return i18n("Revision Date"); } void Addressee::setSortString( const QString &sortString ) { if ( sortString == mData->sortString ) return; detach(); mData->empty = false; mData->sortString = sortString; } QString Addressee::sortString() const { return mData->sortString; } QString Addressee::sortStringLabel() { return i18n("Sort String"); } void Addressee::setUrl( const KURL &url ) { if ( url == mData->url ) return; detach(); mData->empty = false; mData->url = url; } KURL Addressee::url() const { return mData->url; } QString Addressee::urlLabel() { return i18n("URL"); } void Addressee::setSecrecy( const Secrecy &secrecy ) { if ( secrecy == mData->secrecy ) return; detach(); mData->empty = false; mData->secrecy = secrecy; } Secrecy Addressee::secrecy() const { return mData->secrecy; } QString Addressee::secrecyLabel() { return i18n("Security Class"); } void Addressee::setLogo( const Picture &logo ) { if ( logo == mData->logo ) return; detach(); mData->empty = false; mData->logo = logo; } Picture Addressee::logo() const { return mData->logo; } QString Addressee::logoLabel() { return i18n("Logo"); } void Addressee::setPhoto( const Picture &photo ) { if ( photo == mData->photo ) return; detach(); mData->empty = false; mData->photo = photo; } Picture Addressee::photo() const { return mData->photo; } QString Addressee::photoLabel() { return i18n("Photo"); } void Addressee::setSound( const Sound &sound ) { if ( sound == mData->sound ) return; detach(); mData->empty = false; mData->sound = sound; } Sound Addressee::sound() const { return mData->sound; } QString Addressee::soundLabel() { return i18n("Sound"); } void Addressee::setAgent( const Agent &agent ) { if ( agent == mData->agent ) return; detach(); mData->empty = false; mData->agent = agent; } Agent Addressee::agent() const { return mData->agent; } QString Addressee::agentLabel() { return i18n("Agent"); } void Addressee::setNameFromString( const QString &str ) { setFormattedName( str ); setName( str ); - QStringList titles; - titles += i18n( "Dr." ); - titles += i18n( "Miss" ); - titles += i18n( "Mr." ); - titles += i18n( "Mrs." ); - titles += i18n( "Ms." ); - titles += i18n( "Prof." ); - - QStringList suffixes; - suffixes += i18n( "I" ); - suffixes += i18n( "II" ); - suffixes += i18n( "III" ); - suffixes += i18n( "Jr." ); - suffixes += i18n( "Sr." ); - - QStringList prefixes; - prefixes += "van"; - prefixes += "von"; - prefixes += "de"; - -//US KConfig config( "kabcrc" ); - KConfig config( locateLocal( "config", "kabcrc") ); - config.setGroup( "General" ); - titles += config.readListEntry( "Prefixes" ); - titles.remove( "" ); - prefixes += config.readListEntry( "Inclusions" ); - prefixes.remove( "" ); - suffixes += config.readListEntry( "Suffixes" ); - suffixes.remove( "" ); + static bool first = true; + static QStringList titles; + static QStringList suffixes; + static QStringList prefixes; + + if ( first ) { + first = false; + titles += i18n( "Dr." ); + titles += i18n( "Miss" ); + titles += i18n( "Mr." ); + titles += i18n( "Mrs." ); + titles += i18n( "Ms." ); + titles += i18n( "Prof." ); + + suffixes += i18n( "I" ); + suffixes += i18n( "II" ); + suffixes += i18n( "III" ); + suffixes += i18n( "Jr." ); + suffixes += i18n( "Sr." ); + + prefixes += "van"; + prefixes += "von"; + prefixes += "de"; + + KConfig config( locateLocal( "config", "kabcrc") ); + config.setGroup( "General" ); + titles += config.readListEntry( "Prefixes" ); + titles.remove( "" ); + prefixes += config.readListEntry( "Inclusions" ); + prefixes.remove( "" ); + suffixes += config.readListEntry( "Suffixes" ); + suffixes.remove( "" ); + } // clear all name parts setPrefix( "" ); setGivenName( "" ); setAdditionalName( "" ); setFamilyName( "" ); setSuffix( "" ); if ( str.isEmpty() ) return; int i = str.find(','); if( i < 0 ) { QStringList parts = QStringList::split( " ", str ); int leftOffset = 0; int rightOffset = parts.count() - 1; QString suffix; while ( rightOffset >= 0 ) { if ( suffixes.contains( parts[ rightOffset ] ) ) { suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); rightOffset--; } else break; } setSuffix( suffix ); if ( rightOffset < 0 ) return; if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); rightOffset--; } else setFamilyName( parts[ rightOffset ] ); QString prefix; while ( leftOffset < rightOffset ) { if ( titles.contains( parts[ leftOffset ] ) ) { prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); leftOffset++; } else break; } setPrefix( prefix ); if ( leftOffset < rightOffset ) { setGivenName( parts[ leftOffset ] ); leftOffset++; } QString additionalName; while ( leftOffset < rightOffset ) { additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); leftOffset++; } setAdditionalName( additionalName ); } else { QString part1 = str.left( i ); QString part2 = str.mid( i + 1 ); QStringList parts = QStringList::split( " ", part1 ); int leftOffset = 0; int rightOffset = parts.count() - 1; QString suffix; while ( rightOffset >= 0 ) { if ( suffixes.contains( parts[ rightOffset ] ) ) { suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); rightOffset--; } else break; } setSuffix( suffix ); if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); rightOffset--; } else setFamilyName( parts[ rightOffset ] ); QString prefix; while ( leftOffset < rightOffset ) { if ( titles.contains( parts[ leftOffset ] ) ) { prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); leftOffset++; } else break; } parts = QStringList::split( " ", part2 ); leftOffset = 0; rightOffset = parts.count(); while ( leftOffset < rightOffset ) { if ( titles.contains( parts[ leftOffset ] ) ) { prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); leftOffset++; } else break; } setPrefix( prefix ); if ( leftOffset < rightOffset ) { setGivenName( parts[ leftOffset ] ); leftOffset++; } QString additionalName; while ( leftOffset < rightOffset ) { additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); leftOffset++; } setAdditionalName( additionalName ); } } QString Addressee::realName() const { if ( !formattedName().isEmpty() ) return formattedName(); QString n = assembledName(); if ( n.isEmpty() ) n = name(); return n; } QString Addressee::assembledName() const { QString name = prefix() + " " + givenName() + " " + additionalName() + " " + familyName() + " " + suffix(); return name.simplifyWhiteSpace(); } QString Addressee::fullEmail( const QString &email ) const { QString e; if ( email.isNull() ) { e = preferredEmail(); } else { e = email; } if ( e.isEmpty() ) return QString::null; QString text; if ( realName().isEmpty() ) text = e; else text = assembledName() + " <" + e + ">"; return text; } void Addressee::insertEmail( const QString &email, bool preferred ) { detach(); QStringList::Iterator it = mData->emails.find( email ); if ( it != mData->emails.end() ) { if ( !preferred || it == mData->emails.begin() ) return; mData->emails.remove( it ); mData->emails.prepend( email ); } else { if ( preferred ) { mData->emails.prepend( email ); } else { mData->emails.append( email ); } } } void Addressee::removeEmail( const QString &email ) { detach(); QStringList::Iterator it = mData->emails.find( email ); if ( it == mData->emails.end() ) return; mData->emails.remove( it ); } QString Addressee::preferredEmail() const { if ( mData->emails.count() == 0 ) return QString::null; else return mData->emails.first(); } QStringList Addressee::emails() const { return mData->emails; } void Addressee::setEmails( const QStringList& emails ) { detach(); mData->emails = emails; } void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) { detach(); mData->empty = false; PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == phoneNumber.id() ) { *it = phoneNumber; return; } } mData->phoneNumbers.append( phoneNumber ); } void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) { detach(); PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == phoneNumber.id() ) { mData->phoneNumbers.remove( it ); return; } } } PhoneNumber Addressee::phoneNumber( int type ) const { PhoneNumber phoneNumber( "", type ); PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( matchBinaryPattern( (*it).type(), type ) ) { if ( (*it).type() & PhoneNumber::Pref ) return (*it); else if ( phoneNumber.number().isEmpty() ) phoneNumber = (*it); } } return phoneNumber; } PhoneNumber::List Addressee::phoneNumbers() const { return mData->phoneNumbers; } PhoneNumber::List Addressee::phoneNumbers( int type ) const { PhoneNumber::List list; PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( matchBinaryPattern( (*it).type(), type ) ) { list.append( *it ); } } return list; } PhoneNumber Addressee::findPhoneNumber( const QString &id ) const { PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == id ) { return *it; } } return PhoneNumber(); } void Addressee::insertKey( const Key &key ) { detach(); mData->empty = false; Key::List::Iterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).id() == key.id() ) { *it = key; return; } } mData->keys.append( key ); } void Addressee::removeKey( const Key &key ) { detach(); Key::List::Iterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).id() == key.id() ) { mData->keys.remove( key ); return; } } } Key Addressee::key( int type, QString customTypeString ) const { Key::List::ConstIterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).type() == type ) { if ( type == Key::Custom ) { if ( customTypeString.isEmpty() ) { return *it; } else { if ( (*it).customTypeString() == customTypeString ) return (*it); } } else { return *it; } } } return Key( QString(), type ); } void Addressee::setKeys( const Key::List& list ) { detach(); mData->keys = list; } Key::List Addressee::keys() const { return mData->keys; } Key::List Addressee::keys( int type, QString customTypeString ) const { Key::List list; Key::List::ConstIterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).type() == type ) { if ( type == Key::Custom ) { if ( customTypeString.isEmpty() ) { list.append(*it); } else { if ( (*it).customTypeString() == customTypeString ) list.append(*it); } } else { list.append(*it); } } } return list; } Key Addressee::findKey( const QString &id ) const { Key::List::ConstIterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).id() == id ) { return *it; } } return Key(); } QString Addressee::asString() const { return "Smith, agent Smith..."; } void Addressee::dump() const { return; kdDebug(5700) << "Addressee {" << endl; kdDebug(5700) << " Uid: '" << uid() << "'" << endl; kdDebug(5700) << " Name: '" << name() << "'" << endl; kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; diff --git a/kaddressbook/addresseeeditorwidget.cpp b/kaddressbook/addresseeeditorwidget.cpp index 3cfc1f2..826c69b 100644 --- a/kaddressbook/addresseeeditorwidget.cpp +++ b/kaddressbook/addresseeeditorwidget.cpp @@ -1,1280 +1,1306 @@ /* This file is part of KAddressBook. Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 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. 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qcheckbox.h> #include <qhbox.h> #include <qlabel.h> #include <qlayout.h> #include <qlistbox.h> #include <qpushbutton.h> #include <qtabwidget.h> #ifndef KAB_EMBEDDED #include <qtextedit.h> #include <kaccelmanager.h> #include "keywidget.h" #include "soundwidget.h" #else //KAB_EMBEDDED #include <qmultilineedit.h> #endif //KAB_EMBEDDED #include "keywidget.h" #include "geowidget.h" #include "imagewidget.h" #include "nameeditdialog.h" #include "phoneeditwidget.h" #include "secrecywidget.h" #include <qtoolbutton.h> #include <qtooltip.h> #include <kapplication.h> #include <kconfig.h> #include <kcombobox.h> #include <kdebug.h> #include <kdialogbase.h> #include <kglobal.h> #include <kiconloader.h> #include <klineedit.h> #include <klocale.h> #include <kmessagebox.h> #include <kseparator.h> #include <ksqueezedtextlabel.h> #include <libkdepim/categoryeditdialog.h> #include <libkdepim/categoryselectdialog.h> #include <libkdepim/kdateedit.h> #include "addresseditwidget.h" #include "emaileditwidget.h" #include "kabcore.h" #include "kabprefs.h" #include "addresseeeditorwidget.h" AddresseeEditorWidget::AddresseeEditorWidget( KABCore *core, bool isExtension, QWidget *parent, const char *name ) : ExtensionWidget( core, parent, name ), mIsExtension( isExtension ), mBlockSignals( false ) { mAConfig = AddresseeConfig::instance(); - kdDebug(5720) << "AddresseeEditorWidget()" << endl; mFormattedNameType = NameEditDialog::CustomName; initGUI(); mCategoryDialog = 0; mCategoryEditDialog = 0; // Load the empty addressee as defaults load(); mDirty = false; } AddresseeEditorWidget::~AddresseeEditorWidget() { kdDebug(5720) << "~AddresseeEditorWidget()" << endl; } void AddresseeEditorWidget::contactsSelectionChanged() { KABC::Addressee::List list = selectedContacts(); mAddressee = list[ 0 ]; load(); } void AddresseeEditorWidget::setAddressee( const KABC::Addressee &addr ) { mAddressee = addr; load(); } const KABC::Addressee &AddresseeEditorWidget::addressee() { return mAddressee; } void AddresseeEditorWidget::textChanged( const QString& ) { emitModified(); } void AddresseeEditorWidget::initGUI() { QVBoxLayout *layout = new QVBoxLayout( this ); mTabWidget = new QTabWidget( this ); layout->addWidget( mTabWidget ); setupTab1(); setupTab1_1(); setupTab2(); setupTab2_1(); setupTab3(); setupTab3_1(); mNameEdit->setFocus(); connect( mTabWidget, SIGNAL( currentChanged(QWidget*) ), SLOT( pageChanged(QWidget*) ) ); } void AddresseeEditorWidget::setupTab1() { // This is the General tab QWidget *tab1 = new QWidget( mTabWidget ); //US QGridLayout *layout = new QGridLayout( tab1, 11, 7 ); QGridLayout *layout = new QGridLayout( tab1, 7, 1 ); layout->setMargin( KDialogBase::marginHintSmall() ); layout->setSpacing( KDialogBase::spacingHintSmall() ); QLabel *label; KSeparator* bar; QPushButton *button; ////////////////////////////////// // Upper left group (person info) // Person icon /* LR label = new QLabel( tab1 ); //US ambiguous call. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) ); layout->addMultiCellWidget( label, 0, 1, 0, 0 ); */ // First name button = new QPushButton( i18n( "Name..." ), tab1 ); //US QToolTip::add( button, i18n( "Edit the contact's name" ) ); mNameEdit = new KLineEdit( tab1, "mNameEdit" ); connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( nameTextChanged( const QString& ) ) ); connect( button, SIGNAL( clicked() ), SLOT( nameButtonClicked() ) ); mNameLabel = new KSqueezedTextLabel( tab1 ); mNameLabel->hide(); layout->addWidget( button, 0, 0 ); layout->addWidget( mNameEdit, 0, 1 ); layout->addWidget( mNameLabel, 0, 1 ); label = new QLabel( i18n( "Role:" ), tab1 ); mRoleEdit = new KLineEdit( tab1 ); connect( mRoleEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mRoleEdit ); layout->addWidget( label, 1, 0 ); layout->addWidget( mRoleEdit, 1, 1 ); // Organization label = new QLabel( i18n( "Organization:" ), tab1 ); mOrgEdit = new KLineEdit( tab1 ); label->setBuddy( mOrgEdit ); connect( mOrgEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); layout->addWidget( label, 2, 0 ); layout->addWidget( mOrgEdit, 2, 1 ); // File as (formatted name) label = new QLabel( i18n( "Formatted name:" ), tab1 ); mFormattedNameLabel = new KSqueezedTextLabel( tab1 ); layout->addWidget( label, 3, 0 ); layout->addWidget( mFormattedNameLabel, 3, 1 ); /* LR // Left hand separator. This separator doesn't go all the way // across so the dialog still flows from top to bottom bar = new KSeparator( KSeparator::HLine, tab1 ); layout->addMultiCellWidget( bar, 4, 4, 0, 2 ); */ ////////////////////////////////////// /* LR // Phone numbers (upper right) label = new QLabel( tab1 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); //US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); layout->addMultiCellWidget( label, 5, 6, 0, 0 ); */ mPhoneEditWidget = new PhoneEditWidget( tab1 ); connect( mPhoneEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) ); //US layout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 ); int iii; #ifndef DESKTOP_VERSION iii = 7; #else iii = 8; #endif layout->addMultiCellWidget( mPhoneEditWidget, 4, iii, 0, 1 ); ++iii; /* LR bar = new KSeparator( KSeparator::HLine, tab1 ); //US layout->addMultiCellWidget( bar, 4, 4, 3, 6 ); layout->addMultiCellWidget( bar, 9, 9, 0, 2 ); */ /*US ////////////////////////////////////// // Addresses (lower left) label = new QLabel( tab1 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop, 0 ) ); layout->addMultiCellWidget( label, 5, 6, 0, 0 ); mAddressEditWidget = new AddressEditWidget( tab1 ); connect( mAddressEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) ); layout->addMultiCellWidget( mAddressEditWidget, 5, 9, 1, 2 ); ////////////////////////////////////// // Email / Web (lower right) label = new QLabel( tab1 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop, 0) ); layout->addMultiCellWidget( label, 5, 6, 3, 3 ); mEmailWidget = new EmailEditWidget( tab1 ); connect( mEmailWidget, SIGNAL( modified() ), SLOT( emitModified() ) ); layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 ); // add the separator bar = new KSeparator( KSeparator::HLine, tab1 ); layout->addMultiCellWidget( bar, 7, 7, 3, 6 ); label = new QLabel( tab1 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop, 0) ); layout->addMultiCellWidget( label, 8, 9, 3, 3 ); label = new QLabel( i18n( "URL:" ), tab1 ); mURLEdit = new KLineEdit( tab1 ); connect( mURLEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mURLEdit ); layout->addWidget( label, 8, 4 ); layout->addMultiCellWidget( mURLEdit, 8, 8, 5, 6 ); label = new QLabel( i18n( "&IM address:" ), tab1 ); mIMAddressEdit = new KLineEdit( tab1 ); connect( mIMAddressEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mIMAddressEdit ); layout->addWidget( label, 9, 4 ); layout->addMultiCellWidget( mIMAddressEdit, 9, 9, 5, 6 ); layout->addColSpacing( 6, 50 ); bar = new KSeparator( KSeparator::HLine, tab1 ); layout->addMultiCellWidget( bar, 10, 10, 0, 6 ); */ /////////////////////////////////////// QHBox *categoryBox = new QHBox( tab1 ); categoryBox->setSpacing( KDialogBase::spacingHint() ); categoryBox->setMargin( KDialogBase::marginHintSmall() ); // Categories button = new QPushButton( i18n( "Categories" ), categoryBox ); connect( button, SIGNAL( clicked() ), SLOT( categoryButtonClicked() ) ); mCategoryEdit = new KLineEdit( categoryBox ); mCategoryEdit->setReadOnly( true ); connect( mCategoryEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); mSecrecyWidget = new SecrecyWidget( categoryBox ); connect( mSecrecyWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); //US layout->addMultiCellWidget( categoryBox, 11, 11, 0, 6 ); layout->addMultiCellWidget( categoryBox, iii, iii, 0, 1 ); // Build the layout and add to the tab widget layout->activate(); // required mTabWidget->addTab( tab1, i18n( "&General" ) ); } void AddresseeEditorWidget::setupTab1_1() { // This is the Address tab QWidget *tab1_1 = new QWidget( mTabWidget ); //US QGridLayout *layout = new QGridLayout( tab1_1, 11, 7 ); QGridLayout *layout = new QGridLayout( tab1_1, 7, 2 ); layout->setMargin( KDialogBase::marginHintSmall() ); layout->setSpacing( KDialogBase::spacingHintSmall() ); QLabel *label; KSeparator* bar; QPushButton *button; /*US ////////////////////////////////// // Upper left group (person info) // Person icon label = new QLabel( tab1 ); //US ambiguous call. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) ); layout->addMultiCellWidget( label, 0, 1, 0, 0 ); // First name button = new QPushButton( i18n( "Name..." ), tab1 ); QToolTip::add( button, i18n( "Edit the contact's name" ) ); mNameEdit = new KLineEdit( tab1, "mNameEdit" ); connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( nameTextChanged( const QString& ) ) ); connect( button, SIGNAL( clicked() ), SLOT( nameButtonClicked() ) ); #ifndef KAB_EMBEDDED mNameLabel = new KSqueezedTextLabel( tab1 ); mNameLabel->hide(); #else //KAB_EMBEDDED qDebug("AddresseeEditorWidget::setupTab1 has to be changed"); #endif //KAB_EMBEDDED layout->addWidget( button, 0, 1 ); layout->addWidget( mNameEdit, 0, 2 ); #ifndef KAB_EMBEDDED layout->addWidget( mNameLabel, 0, 2 ); #else //KAB_EMBEDDED qDebug("AddresseeEditorWidget::setupTab1 has to be changed"); #endif //KAB_EMBEDDED label = new QLabel( i18n( "Role:" ), tab1 ); mRoleEdit = new KLineEdit( tab1 ); connect( mRoleEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mRoleEdit ); layout->addWidget( label, 1, 1 ); layout->addWidget( mRoleEdit, 1, 2 ); // Organization label = new QLabel( i18n( "Organization:" ), tab1 ); mOrgEdit = new KLineEdit( tab1 ); label->setBuddy( mOrgEdit ); connect( mOrgEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); layout->addWidget( label, 2, 1 ); layout->addWidget( mOrgEdit, 2, 2 ); // File as (formatted name) label = new QLabel( i18n( "Formatted name:" ), tab1 ); #ifndef KAB_EMBEDDED mFormattedNameLabel = new KSqueezedTextLabel( tab1 ); #else //KAB_EMBEDDED qDebug("AddresseeEditorWidget::setupTab1 has to be changed"); #endif //KAB_EMBEDDED layout->addWidget( label, 3, 1 ); #ifndef KAB_EMBEDDED layout->addWidget( mFormattedNameLabel, 3, 2 ); #else //KAB_EMBEDDED qDebug("AddresseeEditorWidget::setupTab1 has to be changed"); #endif //KAB_EMBEDDED // Left hand separator. This separator doesn't go all the way // across so the dialog still flows from top to bottom bar = new KSeparator( KSeparator::HLine, tab1 ); layout->addMultiCellWidget( bar, 4, 4, 0, 2 ); ////////////////////////////////////// // Phone numbers (upper right) label = new QLabel( tab1 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); layout->addMultiCellWidget( label, 0, 1, 3, 3 ); mPhoneEditWidget = new PhoneEditWidget( tab1 ); connect( mPhoneEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) ); layout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 ); bar = new KSeparator( KSeparator::HLine, tab1 ); layout->addMultiCellWidget( bar, 4, 4, 3, 6 ); */ ////////////////////////////////////// // Addresses (lower left) /* LR label = new QLabel( tab1_1 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop, 0 ) ); //US layout->addMultiCellWidget( label, 5, 6, 0, 0 ); layout->addMultiCellWidget( label, 0, 1, 0, 0 ); */ mAddressEditWidget = new AddressEditWidget( tab1_1 ); connect( mAddressEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) ); //US layout->addMultiCellWidget( mAddressEditWidget, 5, 9, 1, 2 ); layout->addMultiCellWidget( mAddressEditWidget, 0, 4, 0, 1 ); //US /* LR bar = new KSeparator( KSeparator::HLine, tab1_1 ); layout->addMultiCellWidget( bar, 5, 5, 0, 3 ); */ ////////////////////////////////////// // Email / Web (lower right) /* LR label = new QLabel( tab1_1 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop, 0) ); //US layout->addMultiCellWidget( label, 5, 6, 3, 3 ); layout->addMultiCellWidget( label, 6, 7, 0, 0 ); */ mEmailWidget = new EmailEditWidget( tab1_1 ); connect( mEmailWidget, SIGNAL( modified() ), SLOT( emitModified() ) ); //US layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 ); layout->addMultiCellWidget( mEmailWidget, 5, 6, 0, 1 ); /* LR // add the separator bar = new KSeparator( KSeparator::HLine, tab1_1 ); //US layout->addMultiCellWidget( bar, 7, 7, 3, 6 ); layout->addMultiCellWidget( bar, 8, 8, 0, 3 ); label = new QLabel( tab1_1 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop, 0) ); //US layout->addMultiCellWidget( label, 8, 9, 3, 3 ); layout->addMultiCellWidget( label, 9, 10, 0, 0 ); */ label = new QLabel( i18n( "URL:" ), tab1_1 ); mURLEdit = new KLineEdit( tab1_1 ); connect( mURLEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mURLEdit ); //US layout->addWidget( label, 8, 4 ); layout->addWidget( label, 7,0 ); //US layout->addMultiCellWidget( mURLEdit, 8, 8, 5, 6 ); layout->addWidget( mURLEdit, 7, 1); label = new QLabel( i18n( "&IM address:" ), tab1_1 ); mIMAddressEdit = new KLineEdit( tab1_1 ); connect( mIMAddressEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mIMAddressEdit ); //US layout->addWidget( label, 9, 4 ); layout->addWidget( label, 8, 0 ); //US layout->addMultiCellWidget( mIMAddressEdit, 9, 9, 5, 6 ); layout->addWidget( mIMAddressEdit, 8,1 ); //US layout->addColSpacing( 6, 50 ); //US bar = new KSeparator( KSeparator::HLine, tab1_1 ); //US layout->addMultiCellWidget( bar, 10, 10, 0, 6 ); /*US /////////////////////////////////////// QHBox *categoryBox = new QHBox( tab1 ); categoryBox->setSpacing( KDialogBase::spacingHintSmall() ); // Categories button = new QPushButton( i18n( "Categories" ), categoryBox ); connect( button, SIGNAL( clicked() ), SLOT( categoryButtonClicked() ) ); mCategoryEdit = new KLineEdit( categoryBox ); mCategoryEdit->setReadOnly( true ); connect( mCategoryEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); mSecrecyWidget = new SecrecyWidget( categoryBox ); connect( mSecrecyWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addMultiCellWidget( categoryBox, 11, 11, 0, 6 ); */ // Build the layout and add to the tab widget layout->activate(); // required mTabWidget->addTab( tab1_1, i18n( "&Address" ) ); } void AddresseeEditorWidget::setupTab2() { // This is the Details tab QWidget *tab2 = new QWidget( mTabWidget ); QGridLayout *layout = new QGridLayout( tab2, 8, 3 ); layout->setMargin( KDialogBase::marginHintSmall() ); layout->setSpacing( KDialogBase::spacingHintSmall() ); QLabel *label; KSeparator* bar; /////////////////////// // Office info // Department label = new QLabel( tab2 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop, 0 ) ); layout->addMultiCellWidget( label, 0, 1, 0, 0 ); label = new QLabel( i18n( "Department:" ), tab2 ); layout->addWidget( label, 0, 1 ); mDepartmentEdit = new KLineEdit( tab2 ); connect( mDepartmentEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mDepartmentEdit ); layout->addWidget( mDepartmentEdit, 0, 2 ); label = new QLabel( i18n( "Office:" ), tab2 ); layout->addWidget( label, 1, 1 ); mOfficeEdit = new KLineEdit( tab2 ); connect( mOfficeEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mOfficeEdit ); layout->addWidget( mOfficeEdit, 1, 2 ); label = new QLabel( i18n( "Profession:" ), tab2 ); layout->addWidget( label, 2, 1 ); mProfessionEdit = new KLineEdit( tab2 ); connect( mProfessionEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mProfessionEdit ); layout->addWidget( mProfessionEdit, 2, 2 ); label = new QLabel( i18n( "Manager\'s name:" ), tab2 ); //US layout->addWidget( label, 0, 3 ); layout->addWidget( label, 3, 1 ); mManagerEdit = new KLineEdit( tab2 ); connect( mManagerEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mManagerEdit ); //US layout->addMultiCellWidget( mManagerEdit, 0, 0, 4, 5 ); layout->addWidget( mManagerEdit, 3, 2 ); label = new QLabel( i18n( "Assistant's name:" ), tab2 ); //US layout->addWidget( label, 1, 3 ); layout->addWidget( label, 4, 1 ); mAssistantEdit = new KLineEdit( tab2 ); connect( mAssistantEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mAssistantEdit ); //US layout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 ); layout->addWidget( mAssistantEdit, 4, 2 ); bar = new KSeparator( KSeparator::HLine, tab2 ); //US layout->addMultiCellWidget( bar, 3, 3, 0, 5 ); layout->addMultiCellWidget( bar, 5, 5, 0, 2 ); ///////////////////////////////////////////////// // Personal info label = new QLabel( tab2 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) ); //US layout->addMultiCellWidget( label, 4, 5, 0, 0 ); layout->addMultiCellWidget( label, 6, 7, 0, 0 ); label = new QLabel( i18n( "Nick name:" ), tab2 ); //US layout->addWidget( label, 4, 1 ); layout->addWidget( label, 6, 1 ); mNicknameEdit = new KLineEdit( tab2 ); connect( mNicknameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mNicknameEdit ); //US layout->addWidget( mNicknameEdit, 4, 2 ); layout->addWidget( mNicknameEdit, 6, 2 ); label = new QLabel( i18n( "Spouse's name:" ), tab2 ); //US layout->addWidget( label, 5, 1 ); layout->addWidget( label, 7, 1 ); mSpouseEdit = new KLineEdit( tab2 ); connect( mSpouseEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mSpouseEdit ); //US layout->addWidget( mSpouseEdit, 5, 2 ); layout->addWidget( mSpouseEdit, 7, 2 ); label = new QLabel( i18n( "Birthday:" ), tab2 ); //US layout->addWidget( label, 4, 3 ); layout->addWidget( label, 8, 1 ); mBirthdayPicker = new KDateEdit( tab2 ); + mBirthdayPicker->toggleDateFormat(); mBirthdayPicker->setHandleInvalid( true ); connect( mBirthdayPicker, SIGNAL( dateChanged( QDate ) ), SLOT( dateChanged( QDate ) ) ); #ifndef KAB_EMBEDDED //US invalid dates are handdled by the KDateEdit widget itself connect( mBirthdayPicker, SIGNAL( invalidDateEntered() ), SLOT( invalidDate() ) ); connect( mBirthdayPicker, SIGNAL( textChanged( const QString& ) ), SLOT( emitModified() ) ); #endif //KAB_EMBEDDED label->setBuddy( mBirthdayPicker ); //US layout->addWidget( mBirthdayPicker, 4, 4 ); layout->addWidget( mBirthdayPicker, 8, 2 ); label = new QLabel( i18n( "Anniversary:" ), tab2 ); //US layout->addWidget( label, 5, 3 ); layout->addWidget( label, 9, 1 ); mAnniversaryPicker = new KDateEdit( tab2 ); mAnniversaryPicker->setHandleInvalid( true ); connect( mAnniversaryPicker, SIGNAL( dateChanged( QDate ) ), SLOT( dateChanged( QDate ) ) ); #ifndef KAB_EMBEDDED //US invalid dates are handled by the KDateEdit widget itself connect( mAnniversaryPicker, SIGNAL( invalidDateEntered() ), SLOT( invalidDate() ) ); connect( mAnniversaryPicker, SIGNAL( textChanged( const QString& ) ), SLOT( emitModified() ) ); #endif //KAB_EMBEDDED label->setBuddy( mAnniversaryPicker ); //US layout->addWidget( mAnniversaryPicker, 5, 4 ); layout->addWidget( mAnniversaryPicker, 9, 2 ); /*US bar = new KSeparator( KSeparator::HLine, tab2 ); layout->addMultiCellWidget( bar, 6, 6, 0, 5 ); ////////////////////////////////////// // Notes label = new QLabel( i18n( "Note:" ), tab2 ); label->setAlignment( Qt::AlignTop | Qt::AlignLeft ); layout->addWidget( label, 7, 0 ); #ifndef KAB_EMBEDDED mNoteEdit = new QTextEdit( tab2 ); mNoteEdit->setWordWrap( QTextEdit::WidgetWidth ); mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() ); #else //KAB_EMBEDDED mNoteEdit = new QMultiLineEdit( tab2 ); //US mNoteEdit->setWordWrap( QTextEdit::WidgetWidth ); //US mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() ); qDebug("AddresseeEditorWidget::setupTab2 has to be changed"); #endif //KAB_EMBEDDED connect( mNoteEdit, SIGNAL( textChanged() ), SLOT( emitModified() ) ); label->setBuddy( mNoteEdit ); layout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 ); */ // Build the layout and add to the tab widget layout->activate(); // required mTabWidget->addTab( tab2, i18n( "&Details" ) ); } void AddresseeEditorWidget::setupTab2_1() { // This is the Details tab QWidget *tab2_2 = new QWidget( mTabWidget ); QGridLayout *layout = new QGridLayout( tab2_2, 1, 2 ); layout->setMargin( KDialogBase::marginHintSmall() ); layout->setSpacing( KDialogBase::spacingHintSmall() ); QLabel *label; KSeparator* bar; /*US /////////////////////// // Office info // Department label = new QLabel( tab2 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop, 0 ) ); layout->addMultiCellWidget( label, 0, 1, 0, 0 ); label = new QLabel( i18n( "Department:" ), tab2 ); layout->addWidget( label, 0, 1 ); mDepartmentEdit = new KLineEdit( tab2 ); connect( mDepartmentEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mDepartmentEdit ); layout->addWidget( mDepartmentEdit, 0, 2 ); label = new QLabel( i18n( "Office:" ), tab2 ); layout->addWidget( label, 1, 1 ); mOfficeEdit = new KLineEdit( tab2 ); connect( mOfficeEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mOfficeEdit ); layout->addWidget( mOfficeEdit, 1, 2 ); label = new QLabel( i18n( "Profession:" ), tab2 ); layout->addWidget( label, 2, 1 ); mProfessionEdit = new KLineEdit( tab2 ); connect( mProfessionEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mProfessionEdit ); layout->addWidget( mProfessionEdit, 2, 2 ); label = new QLabel( i18n( "Manager\'s name:" ), tab2 ); layout->addWidget( label, 0, 3 ); mManagerEdit = new KLineEdit( tab2 ); connect( mManagerEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mManagerEdit ); layout->addMultiCellWidget( mManagerEdit, 0, 0, 4, 5 ); label = new QLabel( i18n( "Assistant's name:" ), tab2 ); layout->addWidget( label, 1, 3 ); mAssistantEdit = new KLineEdit( tab2 ); connect( mAssistantEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mAssistantEdit ); layout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 ); bar = new KSeparator( KSeparator::HLine, tab2 ); layout->addMultiCellWidget( bar, 3, 3, 0, 5 ); ///////////////////////////////////////////////// // Personal info label = new QLabel( tab2 ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) ); layout->addMultiCellWidget( label, 4, 5, 0, 0 ); label = new QLabel( i18n( "Nick name:" ), tab2 ); layout->addWidget( label, 4, 1 ); mNicknameEdit = new KLineEdit( tab2 ); connect( mNicknameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mNicknameEdit ); layout->addWidget( mNicknameEdit, 4, 2 ); label = new QLabel( i18n( "Spouse's name:" ), tab2 ); layout->addWidget( label, 5, 1 ); mSpouseEdit = new KLineEdit( tab2 ); connect( mSpouseEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) ); label->setBuddy( mSpouseEdit ); layout->addWidget( mSpouseEdit, 5, 2 ); label = new QLabel( i18n( "Birthday:" ), tab2 ); layout->addWidget( label, 4, 3 ); mBirthdayPicker = new KDateEdit( tab2 ); mBirthdayPicker->setHandleInvalid( true ); connect( mBirthdayPicker, SIGNAL( dateChanged( QDate ) ), SLOT( dateChanged( QDate ) ) ); connect( mBirthdayPicker, SIGNAL( invalidDateEntered() ), SLOT( invalidDate() ) ); connect( mBirthdayPicker, SIGNAL( textChanged( const QString& ) ), SLOT( emitModified() ) ); label->setBuddy( mBirthdayPicker ); layout->addWidget( mBirthdayPicker, 4, 4 ); label = new QLabel( i18n( "Anniversary:" ), tab2 ); layout->addWidget( label, 5, 3 ); mAnniversaryPicker = new KDateEdit( tab2 ); mAnniversaryPicker->setHandleInvalid( true ); connect( mAnniversaryPicker, SIGNAL( dateChanged( QDate ) ), SLOT( dateChanged( QDate ) ) ); connect( mAnniversaryPicker, SIGNAL( invalidDateEntered() ), SLOT( invalidDate() ) ); connect( mAnniversaryPicker, SIGNAL( textChanged( const QString& ) ), SLOT( emitModified() ) ); label->setBuddy( mAnniversaryPicker ); layout->addWidget( mAnniversaryPicker, 5, 4 ); bar = new KSeparator( KSeparator::HLine, tab2 ); layout->addMultiCellWidget( bar, 6, 6, 0, 5 ); */ ////////////////////////////////////// // Notes label = new QLabel( i18n( "Note:" ), tab2_2 ); label->setAlignment( Qt::AlignTop | Qt::AlignLeft ); //US layout->addWidget( label, 7, 0 ); layout->addWidget( label, 0, 0 ); #ifndef KAB_EMBEDDED mNoteEdit = new QTextEdit( tab2_2 ); mNoteEdit->setWordWrap( QTextEdit::WidgetWidth ); mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() ); #else //KAB_EMBEDDED mNoteEdit = new QMultiLineEdit( tab2_2 ); mNoteEdit->setWordWrap( QMultiLineEdit::WidgetWidth ); mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() ); #endif //KAB_EMBEDDED connect( mNoteEdit, SIGNAL( textChanged() ), SLOT( emitModified() ) ); label->setBuddy( mNoteEdit ); //US layout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 ); layout->addWidget( mNoteEdit, 1, 0); // Build the layout and add to the tab widget layout->activate(); // required mTabWidget->addTab( tab2_2, i18n( "&Notes" ) ); } void AddresseeEditorWidget::setupTab3() { // This is the Misc tab QWidget *tab3 = new QWidget( mTabWidget ); QGridLayout *layout = new QGridLayout( tab3, 1, 1 ); layout->setMargin( KDialogBase::marginHintSmall() ); layout->setSpacing( KDialogBase::spacingHintSmall() ); //US layout->setColStretch( 2, 1 ); ////////////////////////////////////// // Geo mGeoWidget = new GeoWidget( tab3 ); // mGeoWidget->setMinimumSize( mGeoWidget->sizeHint() ); connect( mGeoWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mGeoWidget, 0, 0 ); /*US ////////////////////////////////////// // Sound #ifndef KAB_EMBEDDED mSoundWidget = new SoundWidget( tab3 ); mSoundWidget->setMinimumSize( mSoundWidget->sizeHint() ); connect( mSoundWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mSoundWidget, 0, 1, Qt::AlignTop ); #else //KAB_EMBEDDED qDebug("AddresseeEditorWidget::setupTab2 sound part is not supported = has to be changed"); #endif //KAB_EMBEDDED ////////////////////////////////////// // Images mImageWidget = new ImageWidget( tab3 ); mImageWidget->setMinimumSize( mImageWidget->sizeHint() ); connect( mImageWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mImageWidget, 1, 0, Qt::AlignTop ); */ //US /* KSeparator* bar = new KSeparator( KSeparator::HLine, tab3 ); layout->addMultiCellWidget( bar, 1, 1, 0, 0 ); */ ////////////////////////////////////// // Keys mKeyWidget = new KeyWidget( tab3 ); //mKeyWidget->setMinimumSize( mKeyWidget->sizeHint() ); connect( mKeyWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); //US layout->addWidget( mKeyWidget, 1, 1, Qt::AlignTop ); layout->addWidget( mKeyWidget, 1, 0 ); mTabWidget->addTab( tab3, i18n( "&Misc" ) ); } void AddresseeEditorWidget::setupTab3_1() { // This is the Misc tab QWidget *tab3 = new QWidget( mTabWidget ); //US QGridLayout *layout = new QGridLayout( tab3, 2, 3 ); QGridLayout *layout = new QGridLayout( tab3, 1, 1 ); layout->setMargin( KDialogBase::marginHint() ); layout->setSpacing( KDialogBase::spacingHint() ); //US layout->setColStretch( 2, 1 ); /*US ////////////////////////////////////// // Geo mGeoWidget = new GeoWidget( tab3 ); mGeoWidget->setMinimumSize( mGeoWidget->sizeHint() ); connect( mGeoWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mGeoWidget, 0, 0, Qt::AlignTop ); */ ////////////////////////////////////// // Sound #ifndef KAB_EMBEDDED mSoundWidget = new SoundWidget( tab3 ); mSoundWidget->setMinimumSize( mSoundWidget->sizeHint() ); connect( mSoundWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mSoundWidget, 0, 1, Qt::AlignTop ); #else //KAB_EMBEDDED //US qDebug("AddresseeEditorWidget::setupTab2 sound part is not supported = has to be changed"); #endif //KAB_EMBEDDED ////////////////////////////////////// // Images mImageWidget = new ImageWidget( tab3 ); mImageWidget->setMinimumSize( mImageWidget->sizeHint() ); connect( mImageWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mImageWidget, 0, 0, Qt::AlignTop ); /*US ////////////////////////////////////// // Keys mKeyWidget = new KeyWidget( tab3 ); mKeyWidget->setMinimumSize( mKeyWidget->sizeHint() ); connect( mKeyWidget, SIGNAL( changed() ), SLOT( emitModified() ) ); layout->addWidget( mKeyWidget, 1, 1, Qt::AlignTop ); */ mTabWidget->addTab( tab3, i18n( "&Images" ) ); } void AddresseeEditorWidget::load() { - kdDebug(5720) << "AddresseeEditorWidget::load()" << endl; // Block signals in case anything tries to emit modified // CS: This doesn't seem to work. bool block = signalsBlocked(); blockSignals( true ); mBlockSignals = true; // used for internal signal blocking mNameEdit->setText( mAddressee.assembledName() ); if ( mAddressee.formattedName().isEmpty() ) { //US KConfig config( "kaddressbookrc" ); KConfig config( locateLocal("config", "kaddressbookrc") ); config.setGroup( "General" ); mFormattedNameType = config.readNumEntry( "FormattedNameType", 1 ); mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) ); } else { if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::SimpleName ) ) mFormattedNameType = NameEditDialog::SimpleName; else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::FullName ) ) mFormattedNameType = NameEditDialog::FullName; else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseName ) ) mFormattedNameType = NameEditDialog::ReverseName; else mFormattedNameType = NameEditDialog::CustomName; } mFormattedNameLabel->setText( mAddressee.formattedName() ); mRoleEdit->setText( mAddressee.role() ); mOrgEdit->setText( mAddressee.organization() ); //US mURLEdit->setURL( mAddressee.url().url() ); mURLEdit->setText( mAddressee.url().prettyURL() ); //US?? mURLEdit->home( false ); // mNoteEdit->setText( mAddressee.note() ); mNoteEdit->setText( mAddressee.note() ); mEmailWidget->setEmails( mAddressee.emails() ); mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() ); mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() ); mBirthdayPicker->setDate( mAddressee.birthday().date() ); //US mAnniversaryPicker->setDate( QDate::fromString( mAddressee.custom( //US "KADDRESSBOOK", "X-Anniversary" ), Qt::ISODate) ); QDate dt = KGlobal::locale()->readDate( mAddressee.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate mAnniversaryPicker->setDate( dt ); mNicknameEdit->setText( mAddressee.nickName() ); mCategoryEdit->setText( mAddressee.categories().join( "," ) ); mGeoWidget->setGeo( mAddressee.geo() ); mImageWidget->setPhoto( mAddressee.photo() ); mImageWidget->setLogo( mAddressee.logo() ); mKeyWidget->setKeys( mAddressee.keys() ); mSecrecyWidget->setSecrecy( mAddressee.secrecy() ); #ifndef KAB_EMBEDDED mSoundWidget->setSound( mAddressee.sound() ); #else //KAB_EMBEDDED //US qDebug("AddresseeEditorWidget::load has to be changed 2"); #endif //KAB_EMBEDDED // Load customs mIMAddressEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-IMAddress" ) ); mSpouseEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ) ); mManagerEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-ManagersName" ) ); mAssistantEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-AssistantsName" ) ); mDepartmentEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Department" ) ); mOfficeEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Office" ) ); mProfessionEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Profession" ) ); blockSignals( block ); mBlockSignals = false; mDirty = false; } void AddresseeEditorWidget::save() { - if ( !mDirty ) return; + if ( !dirty() ) { + return; + } mAddressee.setRole( mRoleEdit->text() ); mAddressee.setOrganization( mOrgEdit->text() ); mAddressee.setUrl( KURL( mURLEdit->text() ) ); mAddressee.setNote( mNoteEdit->text() ); - if ( mBirthdayPicker->inputIsValid() ) - mAddressee.setBirthday( QDateTime( mBirthdayPicker->date() ) ); - else + if ( mBirthdayPicker->inputIsValid() ) { + QDate da = mBirthdayPicker->date(); + if ( da > QDate::currentDate() ) + da.setYMD(da.year()-100, da.month(), da.day() ); + mAddressee.setBirthday( QDateTime( da ) ); + qDebug("bday %s ",da.toString().latin1()); + } + else { mAddressee.setBirthday( QDateTime() ); - + mBirthdayPicker->clear(); + } mAddressee.setNickName( mNicknameEdit->text() ); mAddressee.setCategories( QStringList::split( ",", mCategoryEdit->text() ) ); mAddressee.setGeo( mGeoWidget->geo() ); mAddressee.setPhoto( mImageWidget->photo() ); mAddressee.setLogo( mImageWidget->logo() ); mAddressee.setKeys( mKeyWidget->keys() ); #ifndef KAB_EMBEDDED mAddressee.setSound( mSoundWidget->sound() ); #else //KAB_EMBEDDED //US qDebug("AddresseeEditorWidget::save sound not supported"); #endif //KAB_EMBEDDED mAddressee.setSecrecy( mSecrecyWidget->secrecy() ); // save custom fields mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMAddressEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-Department", mDepartmentEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() ); mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() ); if ( mAnniversaryPicker->inputIsValid() ) { - -//US mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", -//US mAnniversaryPicker->date().toString( Qt::ISODate ) ); QString dt = KGlobal::locale()->formatDate(mAnniversaryPicker->date(), true, KLocale::ISODate); mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); } - else + else { mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" ); + mAnniversaryPicker->clear(); + } // Save the email addresses QStringList emails = mAddressee.emails(); QStringList::Iterator iter; for ( iter = emails.begin(); iter != emails.end(); ++iter ) mAddressee.removeEmail( *iter ); emails = mEmailWidget->emails(); bool first = true; for ( iter = emails.begin(); iter != emails.end(); ++iter ) { mAddressee.insertEmail( *iter, first ); first = false; } // Save the phone numbers KABC::PhoneNumber::List phoneNumbers; KABC::PhoneNumber::List::Iterator phoneIter; phoneNumbers = mAddressee.phoneNumbers(); for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end(); ++phoneIter ) mAddressee.removePhoneNumber( *phoneIter ); phoneNumbers = mPhoneEditWidget->phoneNumbers(); for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end(); ++phoneIter ) mAddressee.insertPhoneNumber( *phoneIter ); // Save the addresses KABC::Address::List addresses; KABC::Address::List::Iterator addressIter; addresses = mAddressee.addresses(); for ( addressIter = addresses.begin(); addressIter != addresses.end(); ++addressIter ) mAddressee.removeAddress( *addressIter ); addresses = mAddressEditWidget->addresses(); for ( addressIter = addresses.begin(); addressIter != addresses.end(); ++addressIter ) mAddressee.insertAddress( *addressIter ); mDirty = false; } bool AddresseeEditorWidget::dirty() { + + if ( ! mDirty ) { + if ( mBirthdayPicker->inputIsValid() ) { + QDate da = mBirthdayPicker->date(); + if ( !(da == mAddressee.birthday().date())) + mDirty = true; + } + else { + mBirthdayPicker->clear(); + } + if ( mAnniversaryPicker->inputIsValid() ) { + QDate da = mAnniversaryPicker->date(); + if ( da != KGlobal::locale()->readDate( mAddressee.custom("KADDRESSBOOK", "X-Anniversary" ), + "%Y-%m-%d")) + mDirty = true; + } + else { + mAnniversaryPicker->clear(); + } + } return mDirty; } void AddresseeEditorWidget::nameTextChanged( const QString &text ) { // use the addressee class to parse the name for us mAConfig->setUid( mAddressee.uid() ); if ( mAConfig->automaticNameParsing() ) { if ( !mAddressee.formattedName().isEmpty() ) { - QString fn = mAddressee.formattedName(); - mAddressee.setNameFromString( text ); - mAddressee.setFormattedName( fn ); + QString fn = mAddressee.formattedName(); + mAddressee.setNameFromString( text ); + mAddressee.setFormattedName( fn ); } else { // use extra addressee to avoid a formatted name assignment Addressee addr; addr.setNameFromString( text ); mAddressee.setPrefix( addr.prefix() ); mAddressee.setGivenName( addr.givenName() ); mAddressee.setAdditionalName( addr.additionalName() ); mAddressee.setFamilyName( addr.familyName() ); mAddressee.setSuffix( addr.suffix() ); } } nameBoxChanged(); emitModified(); } void AddresseeEditorWidget::nameBoxChanged() { KABC::Addressee addr; mAConfig->setUid( mAddressee.uid() ); if ( mAConfig->automaticNameParsing() ) { addr.setNameFromString( mNameEdit->text() ); mNameLabel->hide(); mNameEdit->show(); } else { addr = mAddressee; mNameEdit->hide(); mNameLabel->setText( mNameEdit->text() ); mNameLabel->show(); } if ( mFormattedNameType != NameEditDialog::CustomName ) { mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) ); mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) ); } } void AddresseeEditorWidget::nameButtonClicked() { // show the name dialog. NameEditDialog dialog( mAddressee, mFormattedNameType, this ); - if ( dialog.exec() ) { + if ( KApplication::execDialog( &dialog) ) { if ( dialog.changed() ) { mAddressee.setFamilyName( dialog.familyName() ); mAddressee.setGivenName( dialog.givenName() ); mAddressee.setPrefix( dialog.prefix() ); mAddressee.setSuffix( dialog.suffix() ); mAddressee.setAdditionalName( dialog.additionalName() ); mFormattedNameType = dialog.formattedNameType(); if ( mFormattedNameType == NameEditDialog::CustomName ) { mFormattedNameLabel->setText( dialog.customFormattedName() ); mAddressee.setFormattedName( dialog.customFormattedName() ); } // Update the name edit. bool block = mNameEdit->signalsBlocked(); mNameEdit->blockSignals( true ); mNameEdit->setText( mAddressee.assembledName() ); mNameEdit->blockSignals( block ); // Update the combo box. nameBoxChanged(); emitModified(); } } } void AddresseeEditorWidget::categoryButtonClicked() { // Show the category dialog if ( mCategoryDialog == 0 ) { mCategoryDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this ); connect( mCategoryDialog, SIGNAL( categoriesSelected( const QStringList& ) ), SLOT(categoriesSelected( const QStringList& ) ) ); connect( mCategoryDialog, SIGNAL( editCategories() ), SLOT( editCategories() ) ); } mCategoryDialog->setCategories(); mCategoryDialog->setSelected( QStringList::split( ",", mCategoryEdit->text() ) ); mCategoryDialog->show(); mCategoryDialog->raise(); } void AddresseeEditorWidget::categoriesSelected( const QStringList &list ) { mCategoryEdit->setText( list.join( "," ) ); } void AddresseeEditorWidget::editCategories() { if ( mCategoryEditDialog == 0 ) { mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this ); connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ), SLOT( categoryButtonClicked() ) ); } mCategoryEditDialog->show(); mCategoryEditDialog->raise(); } void AddresseeEditorWidget::emitModified() { mDirty = true; KABC::Addressee::List list; if ( mIsExtension && !mBlockSignals ) { save(); list.append( mAddressee ); } emit modified( list ); } void AddresseeEditorWidget::dateChanged( QDate ) { emitModified(); } //US invalid dates are handdled by the KDateEdit widget itself void AddresseeEditorWidget::invalidDate() { KMessageBox::sorry( this, i18n( "You must specify a valid date" ) ); } void AddresseeEditorWidget::pageChanged( QWidget *wdg ) { #ifndef KAB_EMBEDDED if ( wdg ) KAcceleratorManager::manage( wdg ); #else //KAB_EMBEDDED //US #endif //KAB_EMBEDDED } QString AddresseeEditorWidget::title() const { return i18n( "Contact Editor" ); } QString AddresseeEditorWidget::identifier() const { return i18n( "contact_editor" ); } #ifndef KAB_EMBEDDED #include "addresseeeditorwidget.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/mainembedded.cpp b/kaddressbook/mainembedded.cpp index d781f67..4230c07 100644 --- a/kaddressbook/mainembedded.cpp +++ b/kaddressbook/mainembedded.cpp @@ -1,207 +1,222 @@ #ifndef DESKTOP_VERSION #include <qpe/qpeapplication.h> #include <stdlib.h> #else #include <qapplication.h> #include <qwindowsstyle.h> #include <qplatinumstyle.h> #include <qmainwindow.h> #endif #include <kstandarddirs.h> #include <kglobal.h> #include <stdio.h> #include <qdir.h> #include "kaddressbookmain.h" #include "externalapphandler.h" int main( int argc, char **argv ) { #ifndef DESKTOP_VERSION QPEApplication a( argc, argv ); a.setKeepRunning (); #else QApplication a( argc, argv ); QApplication::setStyle( new QPlatinumStyle ()); QString hdir = QDir::homeDirPath(); // there is a bug when creating dirs for WIN 98 // it is difficult to fix, because we have no WIN 98 runnung // such that we try it to create the dirs at startup here if ( hdir == "C:\\" ) { // win 98 or ME QDir app_dir; if ( !app_dir.exists("C:\\kdepim") ) app_dir.mkdir ("C:\\kdepim"); if ( !app_dir.exists("C:\\kdepim\\apps") ) app_dir.mkdir ("C:\\kdepim\\apps"); if ( !app_dir.exists("C:\\kdepim\\config") ) app_dir.mkdir ("C:\\kdepim\\config"); if ( !app_dir.exists("C:\\kdepim\\apps\\kaddressbook") ) app_dir.mkdir ("C:\\kdepim\\apps\\kaddressbook"); } #endif bool exitHelp = false; if ( argc > 1 ) { QString command = argv[1]; if ( command == "-help" ){ printf("KA/E command line commands:\n"); printf(" no command: Start KA/E in usual way\n"); printf(" -help: This output\n"); printf(" KA/E is exiting now. Bye!\n"); exitHelp = true; } } if ( ! exitHelp ) { KGlobal::setAppName( "kaddressbook" ); #ifndef DESKTOP_VERSION if ( QApplication::desktop()->width() > 320 ) KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons22/"); else KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons16/"); #else QString fileName ; fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/icons22/"; KGlobal::iconLoader()->setIconPath(QDir::convertSeparators(fileName)); QApplication::addLibraryPath ( qApp->applicationDirPath () ); #endif KStandardDirs::setAppDir( QDir::convertSeparators(locateLocal("data", "kaddressbook"))); KAddressBookMain m ; //US MainWindow m; QObject::connect(&a, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & ))); + { + KConfig kon ( locateLocal( "config", "korganizerrc" ) ); + kon.setGroup("Locale"); + KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)kon.readNumEntry( "PreferredDate",0) ); + QString dummy = kon.readEntry( "UserDateFormatShort","%aK %d.%m.%y" );// kon.readEntry( ""); + KGlobal::locale()->setHore24Format( !kon.readBoolEntry( "PreferredTime",0 ) ); + KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); + dummy = kon.readEntry( "UserDateFormatLong","%A %d %b %y" ); + KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); + kon.setGroup("Time & Date"); + KGlobal::locale()->setDaylightSaving( kon.readBoolEntry( "UseDaylightsaving", true ), + kon.readNumEntry( "DaylightsavingStart", 90), + kon.readNumEntry( "DaylightsavingEnd",304) ); + KGlobal::locale()->setTimezone( kon.readEntry( "TimeZoneName" ," 00:00 Europe/London(UTC)") ); + } #ifndef DESKTOP_VERSION a.showMainWidget( &m ); #else a.setMainWidget( &m ); m.resize (640, 480 ); m.show(); #endif a.exec(); } qDebug("KA: Bye! "); } /* #include <stdlib.h> #include <qstring.h> #include <kabc/stdaddressbook.h> #include <kaboutdata.h> #include <kcmdlineargs.h> #include <kcrash.h> #include <kdebug.h> #include <klocale.h> #include <kstartupinfo.h> #include <kuniqueapplication.h> #include <kwin.h> #include "kaddressbookmain.h" #include "kabcore.h" extern "C" { void crashHandler( int ) { KABC::StdAddressBook::handleCrash(); ::exit( 0 ); } } class KAddressBookApp : public KUniqueApplication { public: KAddressBookApp() : mMainWin( 0 ) {} ~KAddressBookApp() {} int newInstance(); private: KAddressBookMain *mMainWin; }; int KAddressBookApp::newInstance() { if ( isRestored() ) { // There can only be one main window if ( KMainWindow::canBeRestored( 1 ) ) { mMainWin = new KAddressBookMain; mMainWin->show(); mMainWin->restore( 1 ); } } else { KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); QCString addrStr = args->getOption( "addr" ); QCString uidStr = args->getOption( "uid" ); QString addr; QString uid; if ( !addrStr.isEmpty() ) addr = QString::fromLocal8Bit( addrStr ); if ( !uidStr.isEmpty() ) uid = QString::fromLocal8Bit( uidStr ); if ( args->isSet( "editor-only" ) ) { if ( !mMainWin ) mMainWin = new KAddressBookMain; KStartupInfo::appStarted(); mMainWin->hide(); } else { if ( mMainWin ) { mMainWin->show(); KWin::setActiveWindow( mMainWin->winId() ); } else { mMainWin = new KAddressBookMain; mMainWin->show(); } } // Can not see why anyone would pass both a uid and an email address, so I'll leave it that two contact editors will show if they do if ( !addr.isEmpty() ) mMainWin->addEmail( addr ); if ( !uid.isEmpty() ) mMainWin->showContactEditor( uid ); if ( args->isSet( "new-contact" ) ) { mMainWin->newContact(); } } KCrash::setEmergencySaveFunction( crashHandler ); return 0; } // the dummy argument is required, because KMail apparently sends an empty // argument. static KCmdLineOptions kmoptions[] = { { "a", 0 , 0 }, { "addr <email>", I18N_NOOP( "Shows contact editor with given email address" ), 0 }, { "uid <uid>", I18N_NOOP( "Shows contact editor with given uid" ), 0 }, { "editor-only", I18N_NOOP( "Launches in editor only mode" ), 0 }, { "new-contact", I18N_NOOP( "Launches editor for the new contact" ), 0 }, { "+[argument]", I18N_NOOP( "dummy argument" ), 0}, { 0, 0, 0} }; int main( int argc, char *argv[] ) { KLocale::setMainCatalogue( "kaddressbook" ); KCmdLineArgs::init( argc, argv, KABCore::createAboutData() ); KCmdLineArgs::addCmdLineOptions( kmoptions ); KUniqueApplication::addCmdLineOptions(); if ( !KAddressBookApp::start() ) exit( 0 ); KAddressBookApp app; KGlobal::locale()->insertCatalogue( "libkdepim" ); return app.exec(); } */ diff --git a/kaddressbook/nameeditdialog.cpp b/kaddressbook/nameeditdialog.cpp index fb7eb22..8213c2b 100644 --- a/kaddressbook/nameeditdialog.cpp +++ b/kaddressbook/nameeditdialog.cpp @@ -1,296 +1,293 @@ /* This file is part of KAddressBook. Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 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. 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qlayout.h> #include <qlabel.h> #include <qlistbox.h> #include <qlistview.h> #include <qtooltip.h> #include <qpushbutton.h> #include <qcheckbox.h> #include <qstring.h> #ifndef KAB_EMBEDDED #include <kaccelmanager.h> #else //KAB_EMBEDDED #include <kstandarddirs.h> #endif //KAB_EMBEDDED #include <kapplication.h> #include <kbuttonbox.h> #include <kconfig.h> #include <klineedit.h> #include <klistview.h> #include <kcombobox.h> #include <klocale.h> #include <kglobal.h> #include <kdebug.h> #include <kiconloader.h> #include <kmessagebox.h> #include "nameeditdialog.h" NameEditDialog::NameEditDialog( const KABC::Addressee &addr, int type, QWidget *parent, const char *name ) : KDialogBase( Plain, i18n( "Edit Contact Name" ), Help | Ok | Cancel, Ok, parent, name, true ) { QWidget *page = plainPage(); QGridLayout *layout = new QGridLayout( page, 5, 3 ); layout->setSpacing( spacingHint() ); layout->addColSpacing( 2, 100 ); QLabel *label; label = new QLabel( i18n( "Honorific prefixes:" ), page ); layout->addWidget( label, 0, 0 ); mPrefixCombo = new KComboBox( page ); mPrefixCombo->setDuplicatesEnabled( false ); mPrefixCombo->setEditable( true ); label->setBuddy( mPrefixCombo ); layout->addMultiCellWidget( mPrefixCombo, 0, 0, 1, 2 ); label = new QLabel( i18n( "Given name:" ), page ); layout->addWidget( label, 1, 0 ); mGivenNameEdit = new KLineEdit( page ); label->setBuddy( mGivenNameEdit ); layout->addMultiCellWidget( mGivenNameEdit, 1, 1, 1, 2 ); label = new QLabel( i18n( "Additional names:" ), page ); layout->addWidget( label, 2, 0 ); mAdditionalNameEdit = new KLineEdit( page ); label->setBuddy( mAdditionalNameEdit ); layout->addMultiCellWidget( mAdditionalNameEdit, 2, 2, 1, 2 ); label = new QLabel( i18n( "Family names:" ), page ); layout->addWidget( label, 3, 0 ); mFamilyNameEdit = new KLineEdit( page ); label->setBuddy( mFamilyNameEdit ); layout->addMultiCellWidget( mFamilyNameEdit, 3, 3, 1, 2 ); label = new QLabel( i18n( "Honorific suffixes:" ), page ); layout->addWidget( label, 4, 0 ); mSuffixCombo = new KComboBox( page ); mSuffixCombo->setDuplicatesEnabled( false ); mSuffixCombo->setEditable( true ); label->setBuddy( mSuffixCombo ); layout->addMultiCellWidget( mSuffixCombo, 4, 4, 1, 2 ); mFormattedNameCombo = new KComboBox( page ); mFormattedNameCombo->setMaximumWidth(100); layout->addMultiCellWidget( mFormattedNameCombo, 5, 5, 0, 0 ); connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( typeChanged( int ) ) ); mFormattedNameEdit = new KLineEdit( page ); mFormattedNameEdit->setEnabled( type == CustomName ); layout->addMultiCellWidget( mFormattedNameEdit, 5, 5, 1, 2 ); mParseBox = new QCheckBox( i18n( "Parse name automatically" ), page ); connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( parseBoxChanged(bool) ) ); connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( modified() ) ); - layout->addMultiCellWidget( mParseBox, 6, 6, 0, 1 ); + layout->addMultiCellWidget( mParseBox, 6, 6, 0, 2 ); // Fill in the values mFamilyNameEdit->setText( addr.familyName() ); mGivenNameEdit->setText( addr.givenName() ); mAdditionalNameEdit->setText( addr.additionalName() ); mFormattedNameEdit->setText( addr.formattedName() ); // Prefix and suffix combos //US KConfig config( "kabcrc" ); KConfig config( locateLocal("config", "kabcrc") ); config.setGroup( "General" ); QStringList sTitle; sTitle += i18n( "Dr." ); sTitle += i18n( "Miss" ); sTitle += i18n( "Mr." ); sTitle += i18n( "Mrs." ); sTitle += i18n( "Ms." ); sTitle += i18n( "Prof." ); sTitle += config.readListEntry( "Prefixes" ); sTitle.sort(); QStringList sSuffix; sSuffix += i18n( "I" ); sSuffix += i18n( "II" ); sSuffix += i18n( "III" ); sSuffix += i18n( "Jr." ); sSuffix += i18n( "Sr." ); sSuffix += config.readListEntry( "Suffixes" ); sSuffix.sort(); mPrefixCombo->insertStringList( sTitle ); mSuffixCombo->insertStringList( sSuffix ); #ifndef KAB_EMBEDDED mPrefixCombo->setCurrentText( addr.prefix() ); mSuffixCombo->setCurrentText( addr.suffix() ); #else //KAB_EMBEDDED mPrefixCombo->setEditText( addr.prefix() ); mSuffixCombo->setEditText( addr.suffix() ); #endif //KAB_EMBEDDED AddresseeConfig::instance()->setUid( addr.uid() ); mParseBox->setChecked( AddresseeConfig::instance()->automaticNameParsing() ); #ifndef KAB_EMBEDDED KAcceleratorManager::manage( this ); #endif //KAB_EMBEDDED connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) ); connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) ); connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) ); connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) ); connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) ); connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( modified() ) ); connect( mFormattedNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); updateTypeCombo(); mFormattedNameCombo->setCurrentItem( type ); -#ifdef KAB_EMBEDDED - resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300)); -#endif //KAB_EMBEDDED - + mChanged = false; } NameEditDialog::~NameEditDialog() { } QString NameEditDialog::familyName() const { return mFamilyNameEdit->text(); } QString NameEditDialog::givenName() const { return mGivenNameEdit->text(); } QString NameEditDialog::prefix() const { return mPrefixCombo->currentText(); } QString NameEditDialog::suffix() const { return mSuffixCombo->currentText(); } QString NameEditDialog::additionalName() const { return mAdditionalNameEdit->text(); } QString NameEditDialog::customFormattedName() const { return mFormattedNameEdit->text(); } int NameEditDialog::formattedNameType() const { return mFormattedNameCombo->currentItem(); } bool NameEditDialog::changed() const { return mChanged; } QString NameEditDialog::formattedName( const KABC::Addressee &addr, int type ) { switch ( type ) { case SimpleName: return addr.givenName() + " " + addr.familyName(); break; case FullName: return addr.prefix() + " " + addr.givenName() + " " + addr.additionalName() + " " + addr.familyName() + " " + addr.suffix(); break; case ReverseName: return addr.familyName() + ", " + addr.givenName(); break; default: return ""; break; } } void NameEditDialog::parseBoxChanged( bool value ) { //AddresseeConfig::instance()->setUid( addr.uid() ); AddresseeConfig::instance()->setAutomaticNameParsing( value ); } void NameEditDialog::typeChanged( int pos ) { mFormattedNameEdit->setEnabled( pos == 0 ); } void NameEditDialog::modified() { mChanged = true; } void NameEditDialog::updateTypeCombo() { KABC::Addressee addr; addr.setPrefix( mPrefixCombo->currentText() ); addr.setGivenName( mGivenNameEdit->text() ); addr.setAdditionalName( mAdditionalNameEdit->text() ); addr.setFamilyName( mFamilyNameEdit->text() ); addr.setSuffix( mSuffixCombo->currentText() ); int pos = mFormattedNameCombo->currentItem(); mFormattedNameCombo->clear(); mFormattedNameCombo->insertItem( i18n( "Custom" ) ); mFormattedNameCombo->insertItem( formattedName( addr, SimpleName ) ); mFormattedNameCombo->insertItem( formattedName( addr, FullName ) ); mFormattedNameCombo->insertItem( formattedName( addr, ReverseName ) ); mFormattedNameCombo->setCurrentItem( pos ); } void NameEditDialog::slotHelp() { #ifndef KAB_EMBEDDED kapp->invokeHelp( "managing-contacts-automatic-nameparsing" ); #else //KAB_EMBEDDED qDebug("NameEditDialog::slotHelp Help is not supported yet"); #endif //KAB_EMBEDDED } #ifndef KAB_EMBEDDED #include "nameeditdialog.moc" #endif //KAB_EMBEDDED diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp index ed591fc..c3a1627 100644 --- a/kmicromail/libmailwrapper/genericwrapper.cpp +++ b/kmicromail/libmailwrapper/genericwrapper.cpp @@ -1,423 +1,425 @@ // CHANGED 2004-09-31 Lutz Rogowski #include "genericwrapper.h" #include <libetpan/libetpan.h> #include "mailtypes.h" #include <kconfig.h> #include <kglobal.h> #include <kstandarddirs.h> using namespace Opie::Core; Genericwrapper::Genericwrapper() : AbstractMail() { bodyCache.clear(); m_storage = 0; m_folder = 0; } Genericwrapper::~Genericwrapper() { if (m_folder) { mailfolder_free(m_folder); } if (m_storage) { mailstorage_free(m_storage); } cleanMimeCache(); } QString Genericwrapper::parseDateTime( mailimf_date_time *date ) { static bool init = false ; if ( ! init ) { KConfig kon ( locateLocal( "config", "korganizerrc" ) ); kon.setGroup("Locale"); KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)kon.readNumEntry( "PreferredDate",0) ); QString dummy = kon.readEntry( "UserDateFormatShort","%aK %d.%m.%y" );// kon.readEntry( ""); KGlobal::locale()->setHore24Format( !kon.readBoolEntry( "PreferredTime",0 ) ); KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); + dummy = kon.readEntry( "UserDateFormatLong","%A %d %b %y" ); + KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); kon.setGroup("Time & Date"); KGlobal::locale()->setDaylightSaving( kon.readBoolEntry( "UseDaylightsaving", true ), kon.readNumEntry( "DaylightsavingStart", 90), kon.readNumEntry( "DaylightsavingEnd",304) ); KGlobal::locale()->setTimezone( kon.readEntry( "TimeZoneName" ," 00:00 Europe/London(UTC)") ); init = true; } QDate da (date->dt_year,date->dt_month, date->dt_day ); QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); QDateTime dt ( da ,ti ); int off = KGlobal::locale()->localTimeOffset( dt ); //dt = dt.addSecs( off*60 ); QString ret; if ( da == QDate::currentDate () ) ret = KGlobal::locale()->formatTime( ti,true); else { ret = KGlobal::locale()->formatDateTime( dt,true,true); } #if 0 if ( off < 0 ) ret += " -"; else ret += " +"; ret += QString::number( off / 60 ); ret += "h"; #endif #if 0 char tmp[23]; // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); return QString( tmp ); #endif return ret; } void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) { if (!mime) { return; } mailmime_field*field = 0; mailmime_single_fields fields; memset(&fields, 0, sizeof(struct mailmime_single_fields)); if (mime->mm_mime_fields != NULL) { mailmime_single_fields_init(&fields, mime->mm_mime_fields, mime->mm_content_type); } mailmime_content*type = fields.fld_content; clistcell*current; if (!type) { target->setType("text"); target->setSubtype("plain"); } else { target->setSubtype(type->ct_subtype); switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { case MAILMIME_DISCRETE_TYPE_TEXT: target->setType("text"); break; case MAILMIME_DISCRETE_TYPE_IMAGE: target->setType("image"); break; case MAILMIME_DISCRETE_TYPE_AUDIO: target->setType("audio"); break; case MAILMIME_DISCRETE_TYPE_VIDEO: target->setType("video"); break; case MAILMIME_DISCRETE_TYPE_APPLICATION: target->setType("application"); break; case MAILMIME_DISCRETE_TYPE_EXTENSION: default: if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); } break; } if (type->ct_parameters) { fillParameters(target,type->ct_parameters); } } if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { field = (mailmime_field*)current->data; switch(field->fld_type) { case MAILMIME_FIELD_TRANSFER_ENCODING: target->setEncoding(getencoding(field->fld_data.fld_encoding)); break; case MAILMIME_FIELD_ID: target->setIdentifier(field->fld_data.fld_id); break; case MAILMIME_FIELD_DESCRIPTION: target->setDescription(field->fld_data.fld_description); break; default: break; } } } } void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) { if (!parameters) {return;} clistcell*current=0; mailmime_parameter*param; for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { param = (mailmime_parameter*)current->data; if (param) { target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); } } } QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) { QString enc="7bit"; if (!aEnc) return enc; switch(aEnc->enc_type) { case MAILMIME_MECHANISM_7BIT: enc = "7bit"; break; case MAILMIME_MECHANISM_8BIT: enc = "8bit"; break; case MAILMIME_MECHANISM_BINARY: enc = "binary"; break; case MAILMIME_MECHANISM_QUOTED_PRINTABLE: enc = "quoted-printable"; break; case MAILMIME_MECHANISM_BASE64: enc = "base64"; break; case MAILMIME_MECHANISM_TOKEN: default: if (aEnc->enc_token) { enc = QString(aEnc->enc_token); } break; } return enc; } void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) { if (current_rec >= 10) { ; // odebug << "too deep recursion!" << oendl; } if (!message || !mime) { return; } int r; char*data = 0; size_t len; clistiter * cur = 0; QString b; RecPartP part = new RecPart(); switch (mime->mm_type) { case MAILMIME_SINGLE: { QValueList<int>countlist = recList; countlist.append(current_count); r = mailmessage_fetch_section(message,mime,&data,&len); part->setSize(len); part->setPositionlist(countlist); b = gen_attachment_id(); part->setIdentifier(b); fillSingleBody(part,message,mime); if (part->Type()=="text" && target->Bodytext().isNull()) { encodedString*rs = new encodedString(); rs->setContent(data,len); encodedString*res = decode_String(rs,part->Encoding()); if (countlist.count()>2) { bodyCache[b]=rs; target->addPart(part); } else { delete rs; } b = QString(res->Content()); delete res; target->setBodytext(b); target->setDescription(part); } else { bodyCache[b]=new encodedString(data,len); target->addPart(part); } } break; case MAILMIME_MULTIPLE: { unsigned int ccount = 1; mailmime*cbody=0; QValueList<int>countlist = recList; for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { cbody = (mailmime*)clist_content(cur); if (cbody->mm_type==MAILMIME_MULTIPLE) { RecPartP targetPart = new RecPart(); targetPart->setType("multipart"); countlist.append(current_count); targetPart->setPositionlist(countlist); target->addPart(targetPart); } traverseBody(target,message, cbody,countlist,current_rec+1,ccount); if (cbody->mm_type==MAILMIME_MULTIPLE) { countlist = recList; } ++ccount; } } break; case MAILMIME_MESSAGE: { QValueList<int>countlist = recList; countlist.append(current_count); /* the own header is always at recursion 0 - we don't need that */ if (current_rec > 0) { part->setPositionlist(countlist); r = mailmessage_fetch_section(message,mime,&data,&len); part->setSize(len); part->setPositionlist(countlist); b = gen_attachment_id(); part->setIdentifier(b); part->setType("message"); part->setSubtype("rfc822"); bodyCache[b]=new encodedString(data,len); target->addPart(part); } if (mime->mm_data.mm_message.mm_msg_mime != NULL) { traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); } } break; } } RecBodyP Genericwrapper::parseMail( mailmessage * msg ) { int err = MAILIMF_NO_ERROR; mailmime_single_fields fields; /* is bound to msg and will be freed there */ mailmime * mime=0; RecBodyP body = new RecBody(); memset(&fields, 0, sizeof(struct mailmime_single_fields)); err = mailmessage_get_bodystructure(msg,&mime); QValueList<int>recList; traverseBody(body,msg,mime,recList); return body; } QString Genericwrapper::parseAddressList( mailimf_address_list *list ) { QString result( "" ); bool first = true; if (list == 0) return result; for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { mailimf_address *addr = (mailimf_address *) current->data; if ( !first ) { result.append( "," ); } else { first = false; } switch ( addr->ad_type ) { case MAILIMF_ADDRESS_MAILBOX: result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); break; case MAILIMF_ADDRESS_GROUP: result.append( parseGroup( addr->ad_data.ad_group ) ); break; default: ; // odebug << "Generic: unkown mailimf address type" << oendl; break; } } return result; } QString Genericwrapper::parseGroup( mailimf_group *group ) { QString result( "" ); result.append( group->grp_display_name ); result.append( ": " ); if ( group->grp_mb_list != NULL ) { result.append( parseMailboxList( group->grp_mb_list ) ); } result.append( ";" ); return result; } QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) { QString result( "" ); if ( box->mb_display_name == NULL ) { result.append( box->mb_addr_spec ); } else { result.append( convert_String(box->mb_display_name).latin1() ); result.append( " <" ); result.append( box->mb_addr_spec ); result.append( ">" ); } return result; } QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) { QString result( "" ); bool first = true; for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { mailimf_mailbox *box = (mailimf_mailbox *) current->data; if ( !first ) { result.append( "," ); } else { first = false; } result.append( parseMailbox( box ) ); } return result; } encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) { QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); if (it==bodyCache.end()) return new encodedString(); encodedString*t = decode_String(it.data(),part->Encoding()); return t; } encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) { QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); if (it==bodyCache.end()) return new encodedString(); encodedString*t = it.data(); return t; } QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) { encodedString*t = fetchDecodedPart(mail,part); QString text=t->Content(); delete t; return text; } void Genericwrapper::cleanMimeCache() { QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); for (;it!=bodyCache.end();++it) { encodedString*t = it.data(); //it.setValue(0); if (t) delete t; } bodyCache.clear(); ; // odebug << "Genericwrapper: cache cleaned" << oendl; } QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) { QStringList res; if (!in_replies || !in_replies->mid_list) return res; diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index d5d31e2..258bd43 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -879,771 +879,773 @@ void CalendarView::setupExternSyncProfiles() Event* lse; mExternLastSyncEvent.clear(); int i; for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); if ( lse ) mExternLastSyncEvent.append( lse ); else qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); } } // we check, if the to delete event has a id for a profile // if yes, we set this id in the profile to delete void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) { if ( lastSync.count() == 0 ) { //qDebug(" lastSync.count() == 0"); return; } if ( toDelete->type() == "Journal" ) return; Event* eve = lastSync.first(); while ( eve ) { QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name if ( !id.isEmpty() ) { QString des = eve->description(); QString pref = "e"; if ( toDelete->type() == "Todo" ) pref = "t"; des += pref+ id + ","; eve->setReadOnly( false ); eve->setDescription( des ); //qDebug("setdes %s ", des.latin1()); eve->setReadOnly( true ); } eve = lastSync.next(); } } void CalendarView::checkExternalId( Incidence * inc ) { QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; checkExternSyncEvent( lastSync, inc ); } bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) { bool syncOK = true; int addedEvent = 0; int addedEventR = 0; int deletedEventR = 0; int deletedEventL = 0; int changedLocal = 0; int changedRemote = 0; //QPtrList<Event> el = local->rawEvents(); Event* eventR; QString uid; int take; Event* eventL; Event* eventRSync; Event* eventLSync; QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); bool fullDateRange = false; local->resetTempSyncStat(); mLastCalendarSync = QDateTime::currentDateTime(); QDateTime modifiedCalendar = mLastCalendarSync;; eventLSync = getLastSyncEvent(); eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); if ( eventR ) { eventRSync = (Event*) eventR->clone(); remote->deleteEvent(eventR ); } else { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { eventRSync = (Event*)eventLSync->clone(); } else { fullDateRange = true; eventRSync = new Event(); eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); eventRSync->setDtStart( mLastCalendarSync ); eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); eventRSync->setCategories( i18n("SyncEvent") ); } } if ( eventLSync->dtStart() == mLastCalendarSync ) fullDateRange = true; if ( ! fullDateRange ) { if ( eventLSync->dtStart() != eventRSync->dtStart() ) { // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); fullDateRange = true; } } if ( fullDateRange ) mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); else mLastCalendarSync = eventLSync->dtStart(); // for resyncing if own file has changed if ( mCurrentSyncDevice == "deleteaftersync" ) { mLastCalendarSync = loadedFileVersion; qDebug("setting mLastCalendarSync "); } //qDebug("*************************** "); qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); QPtrList<Incidence> er = remote->rawIncidences(); Incidence* inR = er.first(); Incidence* inL; QProgressBar bar( er.count(),0 ); bar.setCaption (i18n("Syncing - close to abort!") ); int w = 300; if ( QApplication::desktop()->width() < 320 ) w = 220; int h = bar.sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); bar.show(); int modulo = (er.count()/10)+1; int incCounter = 0; while ( inR ) { if ( ! bar.isVisible() ) return false; if ( incCounter % modulo == 0 ) bar.setProgress( incCounter ); ++incCounter; uid = inR->uid(); bool skipIncidence = false; if ( uid.left(15) == QString("last-syncEvent-") ) skipIncidence = true; qApp->processEvents(); if ( !skipIncidence ) { inL = local->incidence( uid ); if ( inL ) { // maybe conflict - same uid in both calendars int maxrev = inL->revision(); if ( maxrev < inR->revision() ) maxrev = inR->revision(); if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { //qDebug("take %d %s ", take, inL->summary().latin1()); if ( take == 3 ) return false; if ( take == 1 ) {// take local inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); remote->deleteIncidence( inR ); if ( inL->revision() < maxrev ) inL->setRevision( maxrev ); remote->addIncidence( inL->clone() ); ++changedRemote; } else { if ( inR->revision() < maxrev ) inR->setRevision( maxrev ); local->deleteIncidence( inL ); local->addIncidence( inR->clone() ); ++changedLocal; } } } else { // no conflict if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { QString des = eventLSync->description(); QString pref = "e"; if ( inR->type() == "Todo" ) pref = "t"; if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); //remote->deleteIncidence( inR ); ++deletedEventR; } else { inR->setLastModified( modifiedCalendar ); local->addIncidence( inR->clone() ); ++addedEvent; } } else { if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { inR->setLastModified( modifiedCalendar ); local->addIncidence( inR->clone() ); ++addedEvent; } else { checkExternSyncEvent(eventRSyncSharp, inR); remote->deleteIncidence( inR ); ++deletedEventR; } } } } inR = er.next(); } QPtrList<Incidence> el = local->rawIncidences(); inL = el.first(); modulo = (el.count()/10)+1; bar.setCaption (i18n("Add / remove events") ); bar.setTotalSteps ( el.count() ) ; bar.show(); incCounter = 0; while ( inL ) { qApp->processEvents(); if ( ! bar.isVisible() ) return false; if ( incCounter % modulo == 0 ) bar.setProgress( incCounter ); ++incCounter; uid = inL->uid(); bool skipIncidence = false; if ( uid.left(15) == QString("last-syncEvent-") ) skipIncidence = true; if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) skipIncidence = true; if ( !skipIncidence ) { inR = remote->incidence( uid ); if ( ! inR ) { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { local->deleteIncidence( inL ); ++deletedEventL; } else { if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { inL->removeID(mCurrentSyncDevice ); ++addedEventR; inL->setLastModified( modifiedCalendar ); remote->addIncidence( inL->clone() ); } } } else { if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { checkExternSyncEvent(eventLSyncSharp, inL); local->deleteIncidence( inL ); ++deletedEventL; } else { if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { ++addedEventR; inL->setLastModified( modifiedCalendar ); remote->addIncidence( inL->clone() ); } } } } } inL = el.next(); } int delFut = 0; if ( KOPrefs::instance()->mWriteBackInFuture ) { er = remote->rawIncidences(); inR = er.first(); QDateTime dt; QDateTime cur = QDateTime::currentDateTime(); QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); while ( inR ) { if ( inR->type() == "Todo" ) { Todo * t = (Todo*)inR; if ( t->hasDueDate() ) dt = t->dtDue(); else dt = cur.addSecs( 62 ); } else if (inR->type() == "Event" ) { bool ok; dt = inR->getNextOccurence( cur, &ok ); if ( !ok ) dt = cur.addSecs( -62 ); } else dt = inR->dtStart(); if ( dt < cur || dt > end ) { remote->deleteIncidence( inR ); ++delFut; } inR = er.next(); } } bar.hide(); mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); eventLSync->setReadOnly( false ); eventLSync->setDtStart( mLastCalendarSync ); eventRSync->setDtStart( mLastCalendarSync ); eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); eventLSync->setReadOnly( true ); if ( mGlobalSyncMode == SYNC_MODE_NORMAL) remote->addEvent( eventRSync ); QString mes; mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); QString delmess; if ( delFut ) { delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); mes += delmess; } if ( KOPrefs::instance()->mShowSyncSummary ) { KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); } qDebug( mes ); mCalendar->checkAlarmForIncidence( 0, true ); return syncOK; } void CalendarView::setSyncDevice( QString s ) { mCurrentSyncDevice= s; } void CalendarView::setSyncName( QString s ) { mCurrentSyncName= s; } bool CalendarView::syncCalendar(QString filename, int mode) { mGlobalSyncMode = SYNC_MODE_NORMAL; CalendarLocal* calendar = new CalendarLocal(); calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); FileStorage* storage = new FileStorage( calendar ); bool syncOK = false; storage->setFileName( filename ); // qDebug("loading ... "); if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { getEventViewerDialog()->setSyncMode( true ); syncOK = synchronizeCalendar( mCalendar, calendar, mode ); getEventViewerDialog()->setSyncMode( false ); if ( syncOK ) { if ( KOPrefs::instance()->mWriteBackFile ) { storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); storage->save(); } } setModified( true ); } delete storage; delete calendar; if ( syncOK ) updateView(); return syncOK; } void CalendarView::syncPhone() { syncExternal( 1 ); } void CalendarView::syncExternal( int mode ) { mGlobalSyncMode = SYNC_MODE_EXTERNAL; //mCurrentSyncDevice = "sharp-DTM"; if ( KOPrefs::instance()->mAskForPreferences ) edit_sync_options(); qApp->processEvents(); CalendarLocal* calendar = new CalendarLocal(); calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); bool syncOK = false; bool loadSuccess = false; PhoneFormat* phoneFormat = 0; #ifndef DESKTOP_VERSION SharpFormat* sharpFormat = 0; if ( mode == 0 ) { // sharp sharpFormat = new SharpFormat () ; loadSuccess = sharpFormat->load( calendar, mCalendar ); } else #endif if ( mode == 1 ) { // phone phoneFormat = new PhoneFormat (mCurrentSyncDevice, KOPrefs::instance()->mPhoneDevice, KOPrefs::instance()->mPhoneConnection, KOPrefs::instance()->mPhoneModel); loadSuccess = phoneFormat->load( calendar,mCalendar); } else return; if ( loadSuccess ) { getEventViewerDialog()->setSyncMode( true ); syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); getEventViewerDialog()->setSyncMode( false ); qApp->processEvents(); if ( syncOK ) { if ( KOPrefs::instance()->mWriteBackFile ) { QPtrList<Incidence> iL = mCalendar->rawIncidences(); Incidence* inc = iL.first(); - while ( inc ) { - inc->removeID(mCurrentSyncDevice); - inc = iL.next(); + if ( phoneFormat ) { + while ( inc ) { + inc->removeID(mCurrentSyncDevice); + inc = iL.next(); + } } #ifndef DESKTOP_VERSION if ( sharpFormat ) sharpFormat->save(calendar); #endif if ( phoneFormat ) phoneFormat->save(calendar); iL = calendar->rawIncidences(); inc = iL.first(); Incidence* loc; while ( inc ) { if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { loc = mCalendar->incidence(inc->uid() ); if ( loc ) { loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); } } inc = iL.next(); } Incidence* lse = getLastSyncEvent(); if ( lse ) { lse->setReadOnly( false ); lse->setDescription( "" ); lse->setReadOnly( true ); } } } setModified( true ); } else { QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), question, i18n("Ok")) ; } delete calendar; updateView(); return ;//syncOK; } void CalendarView::syncSharp() { syncExternal( 0 ); } #include <kabc/stdaddressbook.h> bool CalendarView::importBday() { KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); KABC::AddressBook::Iterator it; int count = 0; for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { ++count; } QProgressBar bar(count,0 ); int w = 300; if ( QApplication::desktop()->width() < 320 ) w = 220; int h = bar.sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); bar.show(); bar.setCaption (i18n("Reading addressbook - close to abort!") ); qApp->processEvents(); count = 0; int addCount = 0; KCal::Attendee* a = 0; for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { if ( ! bar.isVisible() ) return false; bar.setProgress( count++ ); qApp->processEvents(); //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); if ( (*it).birthday().date().isValid() ){ a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) ++addCount; } QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); if ( anni.isValid() ){ a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) ++addCount; } } updateView(); topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); return true; } bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) { //qDebug("addAnni "); Event * ev = new Event(); if ( a ) { ev->addAttendee( a ); } QString kind; if ( birthday ) kind = i18n( "Birthday" ); else kind = i18n( "Anniversary" ); ev->setSummary( name + " - " + kind ); ev->setOrganizer( "nobody@nowhere" ); ev->setCategories( kind ); ev->setDtStart( QDateTime(date) ); ev->setDtEnd( QDateTime(date) ); ev->setFloats( true ); Recurrence * rec = ev->recurrence(); rec->setYearly(Recurrence::rYearlyMonth,1,-1); rec->addYearlyNum( date.month() ); if ( !mCalendar->addAnniversaryNoDup( ev ) ) { delete ev; return false; } return true; } bool CalendarView::importQtopia( const QString &categories, const QString &datebook, const QString &todolist ) { QtopiaFormat qtopiaFormat; qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); updateView(); return true; #if 0 mGlobalSyncMode = SYNC_MODE_QTOPIA; mCurrentSyncDevice = "qtopia-XML"; if ( KOPrefs::instance()->mAskForPreferences ) edit_sync_options(); qApp->processEvents(); CalendarLocal* calendar = new CalendarLocal(); calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); bool syncOK = false; QtopiaFormat qtopiaFormat; qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); bool loadOk = true; if ( !categories.isEmpty() ) loadOk = qtopiaFormat.load( calendar, categories ); if ( loadOk && !datebook.isEmpty() ) loadOk = qtopiaFormat.load( calendar, datebook ); if ( loadOk && !todolist.isEmpty() ) loadOk = qtopiaFormat.load( calendar, todolist ); if ( loadOk ) { getEventViewerDialog()->setSyncMode( true ); syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); getEventViewerDialog()->setSyncMode( false ); qApp->processEvents(); if ( syncOK ) { if ( KOPrefs::instance()->mWriteBackFile ) { // write back XML file } setModified( true ); } } else { QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), question, i18n("Ok")) ; } delete calendar; updateView(); return syncOK; #endif } void CalendarView::setSyncEventsReadOnly() { Event * ev; QPtrList<Event> eL = mCalendar->rawEvents(); ev = eL.first(); while ( ev ) { if ( ev->uid().left(15) == QString("last-syncEvent-") ) ev->setReadOnly( true ); ev = eL.next(); } } bool CalendarView::openCalendar(QString filename, bool merge) { if (filename.isEmpty()) { return false; } if (!QFile::exists(filename)) { KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); return false; } globalFlagBlockAgenda = 1; if (!merge) mCalendar->close(); mStorage->setFileName( filename ); if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) { if ( merge ) ;//setModified( true ); else { //setModified( true ); mViewManager->setDocumentId( filename ); mDialogManager->setDocumentId( filename ); mTodoList->setDocumentId( filename ); } globalFlagBlockAgenda = 2; // if ( getLastSyncEvent() ) // getLastSyncEvent()->setReadOnly( true ); mCalendar->reInitAlarmSettings(); setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); if ( filename != MainWindow::defaultFileName() ) saveCalendar( MainWindow::defaultFileName() ); loadedFileVersion = QDateTime::currentDateTime(); return true; } else { // while failing to load, the calendar object could // have become partially populated. Clear it out. if ( !merge ) mCalendar->close(); KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); globalFlagBlockAgenda = 2; updateView(); } return false; } void CalendarView::setLoadedFileVersion(QDateTime dt) { loadedFileVersion = dt; } bool CalendarView::checkFileChanged(QString fn) { QFileInfo finf ( fn ); if ( !finf.exists() ) return true; QDateTime dt = finf.lastModified (); if ( dt <= loadedFileVersion ) return false; return true; } bool CalendarView::checkFileVersion(QString fn) { QFileInfo finf ( fn ); if ( !finf.exists() ) return true; QDateTime dt = finf.lastModified (); //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); //qDebug("file on disk version %s",dt.toString().latin1()); if ( dt <= loadedFileVersion ) return true; int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) , i18n("KO/Pi Warning"),i18n("Overwrite"), i18n("Sync+save")); if ( km == KMessageBox::Cancel ) return false; if ( km == KMessageBox::Yes ) return true; setSyncDevice("deleteaftersync" ); KOPrefs::instance()->mAskForPreferences = true; KOPrefs::instance()->mSyncAlgoPrefs = 3; KOPrefs::instance()->mWriteBackFile = false; KOPrefs::instance()->mWriteBackExistingOnly = false; KOPrefs::instance()->mShowSyncSummary = false; syncCalendar( fn, 3 ); Event * e = getLastSyncEvent(); mCalendar->deleteEvent ( e ); updateView(); return true; } bool CalendarView::saveCalendar( QString filename ) { // Store back all unsaved data into calendar object // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); if ( mViewManager->currentView() ) mViewManager->currentView()->flushView(); //mStorage->setFileName( filename ); mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); mStorage->setFileName( filename ); bool success; success = mStorage->save(); if ( !success ) { return false; } return true; } void CalendarView::closeCalendar() { // child windows no longer valid emit closingDown(); mCalendar->close(); setModified(false); updateView(); } void CalendarView::archiveCalendar() { mDialogManager->showArchiveDialog(); } void CalendarView::readSettings() { // mViewManager->showAgendaView(); QString str; //qDebug("CalendarView::readSettings() "); // read settings from the KConfig, supplying reasonable // defaults where none are to be found KConfig *config = KOGlobals::config(); #ifndef KORG_NOSPLITTER config->setGroup("KOrganizer Geometry"); QValueList<int> sizes = config->readIntListEntry("Separator1"); if (sizes.count() != 2) { sizes << mDateNavigator->minimumSizeHint().width(); sizes << 300; } mPanner->setSizes(sizes); sizes = config->readIntListEntry("Separator2"); if ( ( mResourceView && sizes.count() == 4 ) || ( !mResourceView && sizes.count() == 3 ) ) { mLeftSplitter->setSizes(sizes); } #endif globalFlagBlockAgenda = 1; mViewManager->showAgendaView(); //mViewManager->readSettings( config ); mTodoList->restoreLayout(config,QString("Todo Layout")); readFilterSettings(config); config->setGroup( "Views" ); int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); if ( dateCount == 5 ) mNavigator->selectWorkWeek(); else if ( dateCount == 7 ) mNavigator->selectWeek(); else mNavigator->selectDates( dateCount ); // mViewManager->readSettings( config ); updateConfig(); globalFlagBlockAgenda = 2; mViewManager->readSettings( config ); #ifdef DESKTOP_VERSION config->setGroup("WidgetLayout"); QStringList list; list = config->readListEntry("MainLayout"); int x,y,w,h; if ( ! list.isEmpty() ) { x = list[0].toInt(); y = list[1].toInt(); w = list[2].toInt(); h = list[3].toInt(); topLevelWidget()->setGeometry(x,y,w,h); } else { topLevelWidget()->setGeometry( 40 ,40 , 640, 440); } list = config->readListEntry("EditEventLayout"); if ( ! list.isEmpty() ) { x = list[0].toInt(); y = list[1].toInt(); diff --git a/libkdepim/addresseeview.cpp b/libkdepim/addresseeview.cpp index d710541..5c69010 100644 --- a/libkdepim/addresseeview.cpp +++ b/libkdepim/addresseeview.cpp @@ -1,389 +1,395 @@ /* This file is part of libkdepim. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <kabc/address.h> #include <kabc/addressee.h> #include <kabc/phonenumber.h> #include <kglobal.h> //US#include <kglobalsettings.h> #include <kiconloader.h> #include <klocale.h> //US #include <kstringhandler.h> #include <qscrollview.h> #include <qregexp.h> #include <qfile.h> #include <qapplication.h> #include "externalapphandler.h" #include "addresseeview.h" //US #ifndef DESKTOP_VERSION //US #include <qtopia/qcopenvelope_qws.h> //US #include <qpe/qpeapplication.h> //US #endif //US static int kphoneInstalled = 0; using namespace KPIM; AddresseeView::AddresseeView( QWidget *parent, const char *name ) //US : KTextBrowser( parent, name ) : QTextBrowser( parent, name ) { //US setWrapPolicy( QTextEdit::AtWordBoundary ); setLinkUnderline( false ); // setVScrollBarMode( QScrollView::AlwaysOff ); //setHScrollBarMode( QScrollView::AlwaysOff ); //US QStyleSheet *sheet = styleSheet(); //US QStyleSheetItem *link = sheet->item( "a" ); //US link->setColor( KGlobalSettings::linkColor() ); } void AddresseeView::setSource(const QString& n) { - qDebug("********AddresseeView::setSource %s", n.latin1()); + //qDebug("********AddresseeView::setSource %s", n.latin1()); if ( n.left( 6 ) == "mailto" ) ExternalAppHandler::instance()->mailToOneContact( n.mid(7) ); else if ( n.left( 7 ) == "phoneto" ) ExternalAppHandler::instance()->callByPhone( n.mid(8) ); else if ( n.left( 5 ) == "faxto" ) ExternalAppHandler::instance()->callByFax( n.mid(6) ); else if ( n.left( 5 ) == "smsto" ) ExternalAppHandler::instance()->callBySMS( n.mid(6) ); else if ( n.left( 7 ) == "pagerto" ) ExternalAppHandler::instance()->callByPager( n.mid(8) ); } void AddresseeView::setAddressee( const KABC::Addressee& addr ) { ExternalAppHandler* eah = ExternalAppHandler::instance(); bool kemailAvail = eah->isEmailAppAvailable(); bool kphoneAvail = eah->isPhoneAppAvailable(); bool kfaxAvail = eah->isFaxAppAvailable(); bool ksmsAvail = eah->isSMSAppAvailable(); bool kpagerAvail = eah->isPagerAppAvailable(); mAddressee = addr; // clear view setText( QString::null ); if ( mAddressee.isEmpty() ) return; QString name = ( mAddressee.assembledName().isEmpty() ? mAddressee.formattedName() : mAddressee.assembledName() ); QString dynamicPart; QStringList emails = mAddressee.emails(); QStringList::ConstIterator emailIt; QString type = i18n( "Email" ); emailIt = emails.begin(); if ( emailIt != emails.end() ) { if ( kemailAvail ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) .arg( type ) .arg( name ) .arg( *emailIt ) .arg( *emailIt ); ++emailIt; } else { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( type ) .arg( *emailIt ); ++emailIt; } } - + if ( mAddressee.birthday().date().isValid() ) { + dynamicPart += QString( + "<tr><td align=\"right\"><b>%1</b></td>" + "<td align=\"left\">%2</td></tr>" ) + .arg( i18n ("Birthday") ) + .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) ); + } KABC::PhoneNumber::List phones = mAddressee.phoneNumbers(); KABC::PhoneNumber::List::ConstIterator phoneIt; QString extension; int phonetype; QString sms; for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { phonetype = (*phoneIt).type(); if (ksmsAvail && ( ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) || ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell) ) ) { sms = QString("<a href=\"smsto:%1 \">(sms)</a>" ) .arg( (*phoneIt).number() ); } else sms = ""; extension = QString::null; if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) { if (kfaxAvail) extension = "faxto:"; } else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) { if (kpagerAvail) extension = "pagerto:"; } else if (kphoneAvail) { extension = "phoneto:"; } else extension = QString::null; if ( !extension.isEmpty() ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" ) .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) .arg( extension ) .arg( (*phoneIt).number() ) .arg( (*phoneIt).number() ) .arg( sms ); } else { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2 %3</td></tr>" ) .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) .arg( (*phoneIt).number() ) .arg( sms ); } } for ( ; emailIt != emails.end(); ++emailIt ) { if ( kemailAvail ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) .arg( type ) .arg( name ) .arg( *emailIt ) .arg( *emailIt ); } else { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( type ) .arg( *emailIt ); } } if ( !mAddressee.url().url().isEmpty() ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( i18n( "Homepage" ) ) //US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) ); .arg( mAddressee.url().url() ); //qDebug("AddresseeView::setAddressee has to be verified."); } KABC::Address::List addresses = mAddressee.addresses(); KABC::Address::List::ConstIterator addrIt; for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { if ( true /*(*addrIt).label().isEmpty()*/ ) { QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace(); //US formattedAddress = formattedAddress.replace( '\n', "<br>" ); //qDebug("adresss %s ",formattedAddress.latin1() ); formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" ); //qDebug("AddresseeView::setAddressee has to be verified."); dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) .arg( formattedAddress ); } else { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) //US .arg( (*addrIt).label().replace( '\n', "<br>" ) ); .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ ); } } QString notes; if ( !mAddressee.note().isEmpty() ) { notes = QString( "<tr>" "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label "<td align=\"left\">%2</td>" // note "</tr>" ).arg( i18n( "Notes" ) ) //US .arg( mAddressee.note().replace( '\n', "<br>" ) ); .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) ); //qDebug("AddresseeView::setAddressee has to be verified."); } QString aRole = ""; QString aOrga = ""; if ( true /*!mAddressee.role().isEmpty()*/ ) { aRole = "<tr>" "<td align=\"left\">" + mAddressee.role() + "</td>" "</tr>"; } if ( true /*!mAddressee.organization().isEmpty()*/ ) { aOrga = "<tr>" "<td align=\"left\">" + mAddressee.organization() + "</td>" ; "</tr>"; } mText = ""; QString picString = ""; KABC::Picture picture = mAddressee.photo(); bool picAvailintern = false; bool picAvailUrl = false; if (! picture.undefined() ) { picAvailintern = (picture.isIntern() && !picture.data().isNull()); picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() ); } if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) { if ( picAvailintern ) { QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() ); } else { if ( picAvailUrl ) { QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() )); } else { QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) ); } } picString = "<img src=\"myimage\" width=\"50\" height=\"70\">"; mText = QString::fromLatin1( "<html>" "<body text=\"%1\" bgcolor=\"%2\">" // text and background color "<table>" "<tr>" "<td rowspan=\"3\" align=\"right\" valign=\"top\">" "%3" "</td>" "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name "</tr>" "%5" // role "%6" // organization "<td colspan=\"2\"> </td>" "%7" // dynamic part "%8" // notes "</table>" "</body>" "</html>") //US .arg( /*KGlobalSettings::textColor().name()*/ "black" ) //US .arg( /*KGlobalSettings::baseColor().name()*/ "white" ) .arg( picString ) .arg( name ) .arg( aRole ) .arg( aOrga ) .arg( dynamicPart ) .arg( notes ); } else { // no picture! mText = "<table width=\"100%\">\n"; //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; #ifdef DESKTOP_VERSION mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>"; #else mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>"; #endif #ifdef DESKTOP_VERSION mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>"; #else mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>"; #endif mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; mText += "<table><td colspan=\"2\"> </td>"; /* mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>" "<td align=\"left\"><b>%2</b></td></tr>" ) .arg( i18n(" ") ) .arg( name ); */ if ( ! mAddressee.role().isEmpty() ) mText += QString("<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( i18n(" ") ) .arg( mAddressee.role()); if ( ! mAddressee.organization().isEmpty() ) mText += QString("<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( i18n(" ") ) .arg( mAddressee.organization()); mText += dynamicPart; mText += notes; mText += "</table>"; } // at last display it... setText( mText ); } KABC::Addressee AddresseeView::addressee() const { return mAddressee; } void AddresseeView::addTag(const QString & tag,const QString & text) { if ( text.isEmpty() ) return; int number=text.contains("\n"); QString str = "<" + tag + ">"; QString tmpText=text; QString tmpStr=str; if(number !=-1) { if (number > 0) { int pos=0; QString tmp; for(int i=0;i<=number;i++) { pos=tmpText.find("\n"); tmp=tmpText.left(pos); tmpText=tmpText.right(tmpText.length()-pos-1); tmpStr+=tmp+"<br>"; } } else tmpStr += tmpText; tmpStr+="</" + tag + ">"; mText.append(tmpStr); } else { str += text + "</" + tag + ">"; mText.append(str); } } diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp index 5fb948a..c4c0081 100644 --- a/libkdepim/kdateedit.cpp +++ b/libkdepim/kdateedit.cpp @@ -1,486 +1,497 @@ /* This file is part of libkdepim. Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 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. 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qapplication.h> #include <qevent.h> #include <qlineedit.h> #include <qpixmap.h> #include <qpushbutton.h> #include <kdatepicker.h> #include <kdebug.h> #include <kglobal.h> #include <kiconloader.h> #include <klocale.h> #include <kmessagebox.h> #include <knotifyclient.h> #include <qpalette.h> #include "kdateedit.h" //#include "kdateedit.moc" KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) : QHBox(parent, name) { dateFormShort = true; withoutDp = withoutDP; mDateEdit = new QLineEdit(this); mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); setFocusProxy(mDateEdit); mDateEdit->installEventFilter(this); // Highlight Background and Textcolor QPalette palette = QWidget::palette(); unsigned char red, green, blue; red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); mDateEdit->setPalette( palette ); if ( withoutDP ) { mDateFrame = 0; mDateButton = 0; mDatePicker = 0; } else { QPixmap pixmap = SmallIcon("smallcal"); mDateButton = new QPushButton(this); mDateButton->setPixmap(pixmap); mDateFrame = new QVBox(0,0,WType_Popup); // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); mDateFrame->setLineWidth(3); mDateFrame->hide(); mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); //mDateFrame->resize( 400, 300 ); } connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); connect(mDateEdit,SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &))); // Create the keyword list. This will be used to match against when the user // enters information. mKeywordMap[i18n("tomorrow")] = 1; mKeywordMap[i18n("today")] = 0; mKeywordMap[i18n("yesterday")] = -1; /* * This loop uses some math tricks to figure out the offset in days * to the next date the given day of the week occurs. There * are two cases, that the new day is >= the current day, which means * the new day has not occured yet or that the new day < the current day, * which means the new day is already passed (so we need to find the * day in the next week). */ QString dayName; int currentDay = QDate::currentDate().dayOfWeek(); for (int i = 1; i <= 7; ++i) { dayName = KGlobal::locale()->weekDayName(i).lower(); if (i >= currentDay) mKeywordMap[dayName] = i - currentDay; else mKeywordMap[dayName] = 7 - currentDay + i; } mTextChanged = false; mHandleInvalid = false; QWidget::setTabOrder( mDateEdit, mDateButton ); } KDateEdit::~KDateEdit() { delete mDateFrame; } - +void KDateEdit::clear() +{ + bool b = mDateEdit->signalsBlocked(); + mDateEdit->blockSignals(true); + mDateEdit->setText(""); + mDateEdit->blockSignals(b); +} void KDateEdit::setDate(QDate newDate) { if (!newDate.isValid() && !mHandleInvalid) return; if ( readDate() == newDate ) return; QString dateString = ""; if(newDate.isValid()) dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); mTextChanged = false; // We do not want to generate a signal here, since we explicity setting // the date bool b = mDateEdit->signalsBlocked(); mDateEdit->blockSignals(true); mDateEdit->setText(dateString); mDateEdit->blockSignals(b); } void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) { QString dateForm = dateFormShort ? KGlobal::locale()->dateFormatShort() : KGlobal::locale()->dateFormat(); int begin = dateForm.find("%"); int space = 0; int allStrLength = 0; int strLength = 0; int repeat = 0; // witch? Day, Month or Year switch? while(1){ switch ( dateForm.at(begin + 1).latin1() ) { case 'd':// 16 (month day) strLength = 2; //Ok break; case 'm':// 01 (month) strLength = 2; //Ok break; case 'a':// Mon (Weekday) strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); break; case 'A':// Monday (Weekday) strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); break; case 'b':// Jan (monthName) strLength = KGlobal::locale()->monthName(date.month(), true).length(); break; case 'B':// January (monthName) strLength = KGlobal::locale()->monthName(date.month(), false).length(); break; case 'y':// 04 (year short) strLength = 2; //Ok break; case 'Y':// 2004 (year) strLength = 4; //Ok break; default: break; } space = begin - (repeat++ * 2); // all select? then dayswitch if( (mDateEdit->text().length() == mDateEdit->markedText().length() ) && ( (dateForm.at(begin + 1).latin1() == 'd') || (dateForm.at(begin + 1).latin1() == 'a') || (dateForm.at(begin + 1).latin1() == 'A') ) ) { break; } // mDateEdit-StringPos == CursorPosition(cpos) then break and set date if( ( (space + allStrLength) <= *cpos && *cpos <= (space + allStrLength + strLength) ) || *cpos < begin ) { break; } allStrLength += strLength; begin = dateForm.find("%", begin +1); } // set date switch ( dateForm.at(begin + 1).latin1() ) { case 'd': case 'a': case 'A': if(key == Key_Up) { setDate( date.addDays( 1 ) ); } else if(key == Key_Down) { setDate( date.addDays( -1 ) ); } maxDay = readDate().day(); break; case 'm': case 'b': case 'B': if(key == Key_Up) { int year = ((date.month()+1)>12)?date.year()+1:date.year(); int month = ((date.month()+1)>12)?1:date.month()+1; int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; setDate( QDate( year, month, day ) ); } else if(key == Key_Down) { int year = ((date.month()-1)<1)?date.year()-1:date.year(); int month = ((date.month()-1)<1)?12:date.month()-1; int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; setDate( QDate( year, month, day ) ); } break; case 'y': case 'Y': if(key == Key_Up) { setDate( QDate( date.year() + 1, date.month() , date.day()) ); } else if(key == Key_Down) { setDate( QDate( date.year() - 1, date.month() , date.day()) ); } break; /* default: if(key == Key_Up) { setDate( date.addDays( 1 ) ); } else if(key == Key_Down) { setDate( date.addDays( -1 ) ); } break;*/ } date = readDate(); begin = dateForm.find("%"); int allSelectStrLength = 0; int selectStrLength = 0; // set selection do new date an set cursor at end of selection for(int i = 0; i < repeat; i++){ switch ( dateForm.at(begin + 1).latin1() ) { case 'd':// 16 (month day) selectStrLength = 2; //Ok break; case 'm':// 01 (month) selectStrLength = 2; //Ok break; case 'a':// Mon (Weekday short) selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); break; case 'A':// Monday (Weekday) selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); break; case 'b':// Jan (monthName short) selectStrLength = KGlobal::locale()->monthName(date.month(), true).length(); break; case 'B':// January (monthName) selectStrLength = KGlobal::locale()->monthName(date.month(), false).length(); break; case 'y':// 04 (year short) selectStrLength = 2; //Ok break; case 'Y':// 2004 (year) selectStrLength = 4; //Ok break; default: break; } space = begin - (i * 2); allSelectStrLength += selectStrLength; begin = dateForm.find("%", begin +1); } // set selection from begin of date setSelect( space + allSelectStrLength - selectStrLength , selectStrLength); *cpos = space + allSelectStrLength; emit(dateChanged(date)); return; } void KDateEdit::setHandleInvalid(bool handleInvalid) { mHandleInvalid = handleInvalid; } void KDateEdit::setEnabled(bool on) { mDateEdit->setEnabled(on); mDateButton->setEnabled(on); } QDate KDateEdit::date() const { QDate date = readDate(); if (date.isValid() || mHandleInvalid) { return date; } else { KNotifyClient::beep(); return QDate::currentDate(); } } void KDateEdit::keyPressEvent(QKeyEvent *e) { QDate date = readDate(); int cpos = mDateEdit->cursorPosition(); switch(e->key()) { case Key_Escape: mDateEdit->deselect(); case Key_Tab: QHBox::keyPressEvent(e); break; case Key_Up: // when date invalid then set to currend and return if(!date.isValid()) { date = QDate::currentDate(); setDate(date); mDateEdit->setCursorPosition(cpos); emit(dateChanged(date)); QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); KMessageBox::information( 0, text ); return; } setDate(date, &cpos, Key_Up, dateFormShort); break; case Key_Down: // when date invalid then set to current and return if(!date.isValid()) { date = QDate::currentDate(); setDate(date); mDateEdit->setCursorPosition(cpos); emit(dateChanged(date)); QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); KMessageBox::information( 0, text ); return; } setDate(date, &cpos, Key_Down, dateFormShort); break; default: QHBox::keyPressEvent(e); break; } // switch mDateEdit->setCursorPosition(cpos); } void KDateEdit::setSelect( int from, int to ) { // return; mDateEdit->setSelection( from , to ); } void KDateEdit::toggleDatePicker() { if( mDateFrame->isVisible() ) { mDateFrame->hide(); } else { QPoint tmpPoint = mapToGlobal(mDateButton->geometry().bottomRight()); QSize datepickersize = mDatePicker->sizeHint(); if ( tmpPoint.x() < 7+datepickersize.width() ) tmpPoint.setX( 7+datepickersize.width() ); int h = QApplication::desktop()->height(); if ( tmpPoint.y() + datepickersize.height() > h ) tmpPoint.setY( h - datepickersize.height() ); mDateFrame->setGeometry(tmpPoint.x()-datepickersize.width()-7, tmpPoint.y(), datepickersize.width()+2*mDateFrame->lineWidth(), datepickersize.height()+2*mDateFrame->lineWidth()); QDate date = readDate(); if(date.isValid()) { mDatePicker->setDate(date); } else { mDatePicker->setDate(QDate::currentDate()); } mDateFrame->show(); } } void KDateEdit::lineEnterPressed() { QDate date = readDate(); if(date.isValid()) { // Update the edit. This is needed if the user has entered a // word rather than the actual date. setDate(date); emit(dateChanged(date)); emit returnPressed(); } else { if ( withoutDp ) { KNotifyClient::beep(); } else { if ( !mDateEdit->text().isEmpty() ) { mTextChanged = false; QString text = i18n( "You entered an invalid date!\n Will use current date instead." ); if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) { setDate( QDate::currentDate() ); emit dateChanged( QDate::currentDate() ); } } } } } bool KDateEdit::inputIsValid() { return readDate().isValid(); } QDate KDateEdit::readDate() const { QString text = mDateEdit->text(); QDate date; if (mKeywordMap.contains(text.lower())) { date = QDate::currentDate().addDays(mKeywordMap[text.lower()]); } else { date = KGlobal::locale()->readDate(text); } return date; } bool KDateEdit::eventFilter(QObject *, QEvent *e) { // We only process the focus out event if the text has changed // since we got focus if ((e->type() == QEvent::FocusOut) && mTextChanged) { lineEnterPressed(); mTextChanged = false; } // switch dateFormShort by double klick with mouse else if (e->type() == QEvent::MouseButtonDblClick) { - dateFormShort = dateFormShort?false:true; - mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort)); + toggleDateFormat(); } else if (e->type() == QEvent::FocusIn) { maxDay = readDate().day(); } return false; } +void KDateEdit::toggleDateFormat() +{ + dateFormShort = ! dateFormShort; + mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort)); + +} void KDateEdit::textChanged(const QString &) { if(mHandleInvalid && mDateEdit->text().stripWhiteSpace().isEmpty()) { QDate date; //invalid date emit(dateChanged(date)); } else { mTextChanged = true; } maxDay = readDate().day(); } diff --git a/libkdepim/kdateedit.h b/libkdepim/kdateedit.h index 742d843..cf3b90a 100644 --- a/libkdepim/kdateedit.h +++ b/libkdepim/kdateedit.h @@ -1,140 +1,141 @@ /* This file is part of libkdepim. Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 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. 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KDATEEDIT_H #define KDATEEDIT_H #include <qhbox.h> #include <qvbox.h> #include <qdatetime.h> #include <qmap.h> class QLineEdit; class QPushButton; class QObject; class QEvent; class KDatePicker; class KDateValidator; /** * A date editing widget that consists of a line edit followed by * a small push button. The line edit contains the date in text form, * and the push button will display a 'popup' style date picker. * * This widget also supports advanced features like allowing the user * to type in the day name to get the date. The following keywords * are supported (in the native language): tomorrow, yesturday, today, * monday, tuesday, wednesday, thursday, friday, saturday, sunday. * * @author Cornelius Schumacher <schumacher@kde.org> * @author Mike Pilone <mpilone@slac.com> */ class KDateEdit : public QHBox { Q_OBJECT public: KDateEdit(QWidget *parent=0, const char *name=0, bool withoutDP = false ); virtual ~KDateEdit(); /** @return True if the date in the text edit is valid, * false otherwise. This will not modify the display of the date, * but only check for validity. */ bool inputIsValid(); /** @return The date entered. This will not * modify the display of the date, but only return it. */ QDate date() const; /** @param handleInvalid If true the date edit accepts invalid dates * and displays them as the empty ("") string. It also returns an invalid date. * If false (default) invalid dates are not accepted and instead the date * of today will be returned. */ void setHandleInvalid(bool handleInvalid); /** Checks for a focus out event. The display of the date is updated * to display the proper date when the focus leaves. */ virtual bool eventFilter(QObject *o, QEvent *e); - + void toggleDateFormat(); + void clear(); signals: /** This signal is emitted whenever the user modifies the date. This * may not get emitted until the user presses enter in the line edit or * focus leaves the widget (ie: the user confirms their selection). */ void dateChanged(QDate); void returnPressed(); public slots: /** Sets the date. * * @param date The new date to display. This date must be valid or * it will not be displayed. */ void setDate(QDate date); // set Date with key_up key_down to relation of cursor Position // and set selection from begin to end of single date void setDate(QDate, int *cpos, const int, const bool); /** Sets the date edit to be enabled or disabled (grayed out) * * @param on Enabled if true, disabled if false */ void setEnabled(bool on); protected slots: void toggleDatePicker(); void lineEnterPressed(); void textChanged(const QString &); private: /** Reads the text from the line edit. If the text is a keyword, the * word will be translated to a date. If the text is not a keyword, the * text will be interpreted as a date. */ QDate readDate() const; /** Maps the text that the user can enter to the offset in days from * today. For example, the text 'tomorrow' is mapped to +1. */ QMap<QString, int> mKeywordMap; bool mTextChanged; bool mHandleInvalid; QPushButton *mDateButton; QLineEdit *mDateEdit; KDatePicker *mDatePicker; QVBox *mDateFrame; int maxDay; bool withoutDp; protected: virtual void keyPressEvent(QKeyEvent *qke); void setSelect ( int, int ); bool dateFormShort; char lengthMonthName; }; #endif diff --git a/microkde/kdeui/kaction.cpp b/microkde/kdeui/kaction.cpp index 77d36a5..d38a6d5 100644 --- a/microkde/kdeui/kaction.cpp +++ b/microkde/kdeui/kaction.cpp @@ -1,1215 +1,1215 @@ /* This file is part of the KDE libraries Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org> (C) 1999 Simon Hausmann <hausmann@kde.org> (C) 2000 Nicolas Hadacek <haadcek@kde.org> (C) 2000 Kurt Granroth <granroth@kde.org> (C) 2000 Michael Koch <koch@kde.org> (C) 2001 Holger Freyther <freyther@kde.org> (C) 2002 Ellis Whitehead <ellis@kde.org> (C) 2002 Joseph Wenninger <jowenn@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "kaction.h" #include <assert.h> #include <qtooltip.h> //US#include <qwhatsthis.h> //US#include <kaccel.h> //US#include <kaccelbase.h> #include <kapplication.h> #include <kdebug.h> #include <kguiitem.h> //US#include <kmainwindow.h> //US#include <kmenubar.h> //US#include <kpopupmenu.h> #include <ktoolbar.h> #include <ktoolbarbutton.h> //US added this includefiles #include <qmenubar.h> #include <qtoolbar.h> #include <qpopupmenu.h> #include <qiconset.h> /** * How it works. * KActionCollection is an organizing container for KActions. * KActionCollection keeps track of the information necessary to handle * configuration and shortcuts. * * Focus Widget pointer: * This is the widget which is the focus for action shortcuts. * It is set either by passing a QWidget* to the KActionCollection constructor * or by calling setWidget() if the widget wasn't known when the object was * initially constructed (as in KXMLGUIClient and KParts::PartBase) * * Shortcuts: * An action's shortcut will not not be connected unless a focus widget has * been specified in KActionCollection. * * XML Filename: * This is used to save user-modified settings back to the *ui.rc file. * It is set by KXMLGUIFactory. */ int KAction::getToolButtonID() { static int toolbutton_no = -2; return toolbutton_no--; } //--------------------------------------------------------------------- // KAction::KActionPrivate //--------------------------------------------------------------------- class KAction::KActionPrivate : public KGuiItem { public: KActionPrivate() : KGuiItem() { m_kaccel = 0; m_configurable = true; } KAccel *m_kaccel; QValueList<KAccel*> m_kaccelList; QString m_groupText; QString m_group; KShortcut m_cut; KShortcut m_cutDefault; bool m_configurable; struct Container { Container() { m_container = 0; m_representative = 0; m_id = 0; } Container( const Container& s ) { m_container = s.m_container; m_id = s.m_id; m_representative = s.m_representative; } QWidget* m_container; int m_id; QWidget* m_representative; }; QValueList<Container> m_containers; }; //--------------------------------------------------------------------- // KAction //--------------------------------------------------------------------- KAction::KAction( const QString& text, const KShortcut& cut, const QObject* receiver, const char* slot, KActionCollection* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, receiver, slot ); } KAction::KAction( const QString& text, const QString& sIconName, const KShortcut& cut, const QObject* receiver, const char* slot, KActionCollection* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, receiver, slot ); d->setIconName( sIconName ); } KAction::KAction( const QString& text, const QIconSet& pix, const KShortcut& cut, const QObject* receiver, const char* slot, KActionCollection* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, receiver, slot ); d->setIconSet( pix ); } KAction::KAction( const KGuiItem& item, const KShortcut& cut, const QObject* receiver, const char* slot, KActionCollection* parent, const char* name ) : QObject( parent, name ) { initPrivate( item.text(), cut, receiver, slot ); if( item.hasIconSet() ) setIcon( item.iconName() ); setToolTip( item.toolTip() ); setWhatsThis( item.whatsThis() ); } // KDE 4: remove KAction::KAction( const QString& text, const KShortcut& cut, QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, 0, 0 ); } KAction::KAction( const QString& text, const KShortcut& cut, const QObject* receiver, const char* slot, QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, receiver, slot ); } KAction::KAction( const QString& text, const QIconSet& pix, const KShortcut& cut, QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, 0, 0 ); setIconSet( pix ); } KAction::KAction( const QString& text, const QString& pix, const KShortcut& cut, QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, 0, 0 ); d->setIconName( pix ); } KAction::KAction( const QString& text, const QIconSet& pix, const KShortcut& cut, const QObject* receiver, const char* slot, QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, receiver, slot ); setIconSet( pix ); } KAction::KAction( const QString& text, const QString& pix, const KShortcut& cut, const QObject* receiver, const char* slot, QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, receiver, slot ); d->setIconName(pix); } KAction::KAction( QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( QString::null, KShortcut(), 0, 0 ); } // KDE 4: remove end KAction::~KAction() { - kdDebug(129) << "KAction::~KAction( this = \"" << name() << "\" )" << endl; // -- ellis #ifndef KDE_NO_COMPAT if (d->m_kaccel) unplugAccel(); #endif // If actionCollection hasn't already been destructed, if ( m_parentCollection ) { m_parentCollection->take( this ); for( uint i = 0; i < d->m_kaccelList.count(); i++ ) //US d->m_kaccelList[i]->remove( name() ); qDebug("KAction::KAction~ ...1 has top be fixed"); } // Do not call unplugAll from here, as tempting as it sounds. // KAction is designed around the idea that you need to plug // _and_ to unplug it "manually". Unplugging leads to an important // slowdown when e.g. closing the window, in which case we simply // want to destroy everything asap, not to remove actions one by one // from the GUI. delete d; d = 0; } void KAction::initPrivate( const QString& text, const KShortcut& cut, const QObject* receiver, const char* slot ) { d = new KActionPrivate; d->m_cutDefault = cut; //US m_parentCollection = dynamic_cast<KActionCollection *>( parent() ); m_parentCollection = (KActionCollection *)( parent() ); kdDebug(129) << "KAction::initPrivate(): this = " << this << " name = \"" << name() << "\" cut = " << cut.toStringInternal() << " m_parentCollection = " << m_parentCollection << endl; if ( m_parentCollection ) m_parentCollection->insert( this ); if ( receiver && slot ) connect( this, SIGNAL( activated() ), receiver, slot ); if( !cut.isNull() && qstrcmp( name(), "unnamed" ) == 0 ) kdWarning(129) << "KAction::initPrivate(): trying to assign a shortcut (" << cut.toStringInternal() << ") to an unnamed action." << endl; d->setText( text ); initShortcut( cut ); } bool KAction::isPlugged() const { return (containerCount() > 0) || d->m_kaccel; } bool KAction::isPlugged( const QWidget *container ) const { return findContainer( container ) > -1; } bool KAction::isPlugged( const QWidget *container, int id ) const { int i = findContainer( container ); return ( i > -1 && itemId( i ) == id ); } bool KAction::isPlugged( const QWidget *container, const QWidget *_representative ) const { int i = findContainer( container ); return ( i > -1 && representative( i ) == _representative ); } /* Three actionCollection conditions: 1) Scope is known on creation and KAccel object is created (e.g. KMainWindow) 2) Scope is unknown and no KAccel object is available (e.g. KXMLGUIClient) a) addClient() will be called on object b) we just want to add the actions to another KXMLGUIClient object The question is how to do we incorporate #2b into the XMLGUI framework? We have a KCommandHistory object with undo and redo actions in a passed actionCollection We have a KoDoc object which holds a KCommandHistory object and the actionCollection We have two KoView objects which both point to the same KoDoc object Undo and Redo should be available in both KoView objects, and calling the undo->setEnabled() should affect both KoViews When addClient is called, it needs to be able to find the undo and redo actions When it calls plug() on them, they need to be inserted into the KAccel object of the appropriate KoView In this case, the actionCollection belongs to KoDoc and we need to let it know that its shortcuts have the same scope as the KoView actionCollection KXMLGUIClient::addSubActionCollection Document: create document actions View create view actions add document actionCollection as sub-collection A parentCollection is created Scenario 1: parentCollection has a focus widget set (e.g. via KMainWindow) A KAccel object is created in the parentCollection A KAction is created with parent=parentCollection The shortcut is inserted into this actionCollection Scenario 1a: xml isn't used done Scenario 1b: KXMLGUIBuilder::addClient() called setWidget is called -- ignore shortcuts are set Scenario 2: parentCollection has no focus widget (e.g., KParts) A KAction is created with parent=parentCollection Scenario 2a: xml isn't used no shortcuts Scenario 2b: KXMLGUIBuilder::addClient() called setWidget is called shortcuts are inserted into current KAccel shortcuts are set in all other KAccels, if the action is present in the other KAccels */ /* shortcut may be set: - on construction - on plug - on reading XML - on plugAccel (deprecated) On Construction: [via initShortcut()] insert into KAccel of m_parentCollection, if kaccel() && isAutoConnectShortcuts() exists On Plug: [via plug() -> plugShortcut()] insert into KAccel of m_parentCollection, if exists and not already inserted into On Read XML: [via setShortcut()] set in all current KAccels insert into KAccel of m_parentCollection, if exists and not already inserted into */ KAccel* KAction::kaccelCurrent() { if( m_parentCollection && m_parentCollection->builderKAccel() ) return m_parentCollection->builderKAccel(); else if( m_parentCollection && m_parentCollection->kaccel() ) return m_parentCollection->kaccel(); else return 0L; } // Only to be called from initPrivate() bool KAction::initShortcut( const KShortcut& cut ) { d->m_cut = cut; // Only insert action into KAccel if it has a valid name, if( qstrcmp( name(), "unnamed" ) != 0 && m_parentCollection && m_parentCollection->isAutoConnectShortcuts() && m_parentCollection->kaccel() ) { insertKAccel( m_parentCollection->kaccel() ); return true; } return false; } // Only to be called from plug() void KAction::plugShortcut() { KAccel* kaccel = kaccelCurrent(); //kdDebug(129) << "KAction::plugShortcut(): this = " << this << " kaccel() = " << (m_parentCollection ? m_parentCollection->kaccel() : 0) << endl; if( kaccel && qstrcmp( name(), "unnamed" ) != 0 ) { // Check if already plugged into current KAccel object for( uint i = 0; i < d->m_kaccelList.count(); i++ ) { if( d->m_kaccelList[i] == kaccel ) return; } insertKAccel( kaccel ); } } bool KAction::setShortcut( const KShortcut& cut ) { qDebug("KAction::setShortcut~ ...1 has top be fixed"); /*US bool bChanged = (d->m_cut != cut); d->m_cut = cut; KAccel* kaccel = kaccelCurrent(); bool bInsertRequired = true; // Apply new shortcut to all existing KAccel objects for( uint i = 0; i < d->m_kaccelList.count(); i++ ) { // Check whether shortcut has already been plugged into // the current kaccel object. if( d->m_kaccelList[i] == kaccel ) bInsertRequired = false; if( bChanged ) updateKAccelShortcut( d->m_kaccelList[i] ); } // Only insert action into KAccel if it has a valid name, if( kaccel && bInsertRequired && qstrcmp( name(), "unnamed" ) ) insertKAccel( kaccel ); if( bChanged ) { // KDE 4: remove if ( d->m_kaccel ) d->m_kaccel->setShortcut( name(), cut ); // KDE 4: remove end int len = containerCount(); for( int i = 0; i < len; ++i ) updateShortcut( i ); } */ return true; } bool KAction::updateKAccelShortcut( KAccel* kaccel ) { - qDebug("KAction::updateKAccelShortcut~ ...1 has top be fixed"); + //qDebug("KAction::updateKAccelShortcut~ ...1 has top be fixed"); + // Check if action is permitted /*US if (kapp && !kapp->authorizeKAction(name())) return false; bool b = true; if ( !kaccel->actions().actionPtr( name() ) ) { if(!d->m_cut.isNull() ) { kdDebug(129) << "Inserting " << name() << ", " << d->text() << ", " << d->plainText() << endl; b = kaccel->insert( name(), d->plainText(), QString::null, d->m_cut, this, SLOT(slotActivated()), isShortcutConfigurable(), isEnabled() ); } } else b = kaccel->setShortcut( name(), d->m_cut ); return b; */ return true; } void KAction::insertKAccel( KAccel* kaccel ) { - qDebug("KAction::updateKAccelShortcut~ ...1 has top be fixed"); + //qDebug("KAction::updateKAccelShortcut~ ...1 has top be fixed"); + /*US //kdDebug(129) << "KAction::insertKAccel( " << kaccel << " ): this = " << this << endl; if ( !kaccel->actions().actionPtr( name() ) ) { if( updateKAccelShortcut( kaccel ) ) { d->m_kaccelList.append( kaccel ); connect( kaccel, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) ); } } else kdWarning(129) << "KAction::insertKAccel( kaccel = " << kaccel << " ): KAccel object already contains an action name \"" << name() << "\"" << endl; // -- ellis */ } void KAction::removeKAccel( KAccel* kaccel ) { - qDebug("KAction::removeKAccel~ ...1 has top be fixed"); + // qDebug("KAction::removeKAccel~ ...1 has top be fixed"); + /*US //kdDebug(129) << "KAction::removeKAccel( " << i << " ): this = " << this << endl; for( uint i = 0; i < d->m_kaccelList.count(); i++ ) { if( d->m_kaccelList[i] == kaccel ) { kaccel->remove( name() ); d->m_kaccelList.remove( d->m_kaccelList.at( i ) ); disconnect( kaccel, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) ); break; } } */ } // KDE 4: remove void KAction::setAccel( int keyQt ) { setShortcut( KShortcut(keyQt) ); } // KDE 4: remove end void KAction::updateShortcut( int i ) { int id = itemId( i ); QWidget* w = container( i ); if ( w->inherits( "QPopupMenu" ) ) { QPopupMenu* menu = static_cast<QPopupMenu*>(w); updateShortcut( menu, id ); } else if ( w->inherits( "QMenuBar" ) ) //US static_cast<QMenuBar*>(w)->setAccel( d->m_cut.keyCodeQt(), id ); //US (QMenuBar*)(w)->setAccel( d->m_cut.keyCodeQt(), id ); - qDebug("KAction::updateShortcut( int i ) ...1 has top be fixed"); + + ; //qDebug("KAction::updateShortcut( int i ) ...1 has top be fixed"); } void KAction::updateShortcut( QPopupMenu* menu, int id ) { /*US //kdDebug(129) << "KAction::updateShortcut(): this = " << this << " d->m_kaccelList.count() = " << d->m_kaccelList.count() << endl; // If the action has a KAccel object, // show the string representation of its shortcut. if ( d->m_kaccel || d->m_kaccelList.count() ) { QString s = menu->text( id ); int i = s.find( '\t' ); if ( i >= 0 ) s.replace( i+1, s.length()-i, d->m_cut.seq(0).toString() ); else s += "\t" + d->m_cut.seq(0).toString(); menu->changeItem( id, s ); } // Otherwise insert the shortcut itself into the popup menu. else { // This is a fall-hack in case the KAction is missing a proper parent collection. // It should be removed eventually. --ellis menu->setAccel( d->m_cut.keyCodeQt(), id ); kdWarning(129) << "KAction::updateShortcut(): name = \"" << name() << "\", cut = " << d->m_cut.toStringInternal() << "; No KAccel, probably missing a parent collection." << endl; } */ - qDebug("KAction::updateShortcut( QPopupMenu* menu, int id ) ...1 has top be fixed"); + + +//qDebug("KAction::updateShortcut( QPopupMenu* menu, int id ) ...1 has top be fixed"); } const KShortcut& KAction::shortcut() const { return d->m_cut; } const KShortcut& KAction::shortcutDefault() const { return d->m_cutDefault; } QString KAction::shortcutText() const { return d->m_cut.toStringInternal(); } void KAction::setShortcutText( const QString& s ) { setShortcut( KShortcut(s) ); } int KAction::accel() const { - qDebug("KAction::accel() ...1 has top be fixed"); + // qDebug("KAction::accel() ...1 has top be fixed"); //US return d->m_cut.keyCodeQt(); return 0; } void KAction::setGroup( const QString& grp ) { d->m_group = grp; int len = containerCount(); for( int i = 0; i < len; ++i ) updateGroup( i ); } void KAction::updateGroup( int ) { // DO SOMETHING } QString KAction::group() const { return d->m_group; } bool KAction::isEnabled() const { return d->isEnabled(); } bool KAction::isShortcutConfigurable() const { return d->m_configurable; } void KAction::setToolTip( const QString& tt ) { - qDebug("KAction::setToolTip ...1 has top be fixed"); + //qDebug("KAction::setToolTip ...1 has top be fixed"); d->setToolTip( tt ); int len = containerCount(); for( int i = 0; i < len; ++i ) updateToolTip( i ); } void KAction::updateToolTip( int i ) { - qDebug("KAction::updateToolTip ...1 has top be fixed"); + //qDebug("KAction::updateToolTip ...1 has top be fixed"); QWidget *w = container( i ); if ( w->inherits( "KToolBar" ) ) QToolTip::add( static_cast<KToolBar*>(w)->getWidget( itemId( i ) ), d->toolTip() ); else if ( w->inherits( "QToolBar" ) ) QToolTip::add( static_cast<KToolBar*>(w)->getWidget( itemId( i ) ), d->toolTip() ); } QString KAction::toolTip() const { return d->toolTip(); } int KAction::plug( QWidget *w, int index ) { //kdDebug(129) << "KAction::plug( " << w << ", " << index << " )" << endl; if (w == 0) { kdWarning(129) << "KAction::plug called with 0 argument\n"; return -1; } -#ifndef NDEBUG - KAccel* kaccel = kaccelCurrent(); - // If there is a shortcut, but no KAccel available - if( !d->m_cut.isNull() && kaccel == 0 ) { - kdWarning(129) << "KAction::plug(): has no KAccel object; this = " << this << " name = " << name() << " parentCollection = " << m_parentCollection << endl; // ellis -//US kdDebug(129) << kdBacktrace() << endl; - } -#endif + // Check if action is permitted //US if (kapp && !kapp->authorizeKAction(name())) //US return -1; plugShortcut(); if ( w->inherits("QPopupMenu") ) { QPopupMenu* menu = static_cast<QPopupMenu*>( w ); int id; // Don't insert shortcut into menu if it's already in a KAccel object. //qDebug("KAction::plug warning: real shortcuts not available yet. "); //US int keyQt = (d->m_kaccelList.count() || d->m_kaccel) ? 0 : d->m_cut.keyCodeQt(); int keyQt = 0; if ( d->hasIcon() ) { /*US KInstance *instance; if ( m_parentCollection ) instance = m_parentCollection->instance(); else instance = KGlobal::instance(); */ id = menu->insertItem( d->iconSet( KIcon::Small, 0/*US , instance */), d->text(), this,//dsweet SLOT( slotActivated() ), keyQt, -1, index ); } else id = menu->insertItem( d->text(), this, SLOT( slotActivated() ), //dsweet keyQt, -1, index ); // If the shortcut is already in a KAccel object, then // we need to set the menu item's shortcut text. /*US if ( d->m_kaccelList.count() || d->m_kaccel ) updateShortcut( menu, id ); */ // call setItemEnabled only if the item really should be disabled, // because that method is slow and the item is per default enabled if ( !d->isEnabled() ) menu->setItemEnabled( id, false ); if ( !d->whatsThis().isEmpty() ) menu->setWhatsThis( id, whatsThisWithIcon() ); addContainer( menu, id ); connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); if ( m_parentCollection ) m_parentCollection->connectHighlight( menu, this ); return d->m_containers.count() - 1; } else if ( w->inherits( "KToolBar" ) ) { KToolBar *bar = static_cast<KToolBar *>( w ); int id_ = getToolButtonID(); /*US KInstance *instance; if ( m_parentCollection ) instance = m_parentCollection->instance(); else instance = KGlobal::instance(); */ if ( icon().isEmpty() && !iconSet().pixmap().isNull() ) // old code using QIconSet directly { bar->insertButton( iconSet().pixmap(), id_, SIGNAL( clicked() ), this, SLOT( slotActivated() ), d->isEnabled(), d->plainText(), index ); } else { QString icon = d->iconName(); if ( icon.isEmpty() ) icon = "unknown"; bar->insertButton( icon, id_, SIGNAL( clicked() ), this, SLOT( slotActivated() ), d->isEnabled(), d->plainText(), index/*US, instance*/ ); } bar->getButton( id_ )->setName( QCString("toolbutton_")+name() ); //US if ( !d->whatsThis().isEmpty() ) //US QWhatsThis::add( bar->getButton(id_), whatsThisWithIcon() ); if ( !d->toolTip().isEmpty() ) QToolTip::add( bar->getButton(id_), d->toolTip() ); addContainer( bar, id_ ); connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); if ( m_parentCollection ) m_parentCollection->connectHighlight( bar, this ); return containerCount() - 1; } return -1; } void KAction::unplug( QWidget *w ) { int i = findContainer( w ); if ( i == -1 ) return; int id = itemId( i ); if ( w->inherits( "QPopupMenu" ) ) { QPopupMenu *menu = static_cast<QPopupMenu *>( w ); menu->removeItem( id ); } else if ( w->inherits( "KToolBar" ) ) { KToolBar *bar = static_cast<KToolBar *>( w ); bar->removeItemDelayed( id ); } else if ( w->inherits( "QMenuBar" ) ) { QMenuBar *bar = static_cast<QMenuBar *>( w ); bar->removeItem( id ); } removeContainer( i ); if ( m_parentCollection ) m_parentCollection->disconnectHighlight( w, this ); } void KAction::plugAccel(KAccel *kacc, bool configurable) { - qDebug("KAction::plugAccel ...1 has top be fixed"); + // qDebug("KAction::plugAccel ...1 has top be fixed"); + /*US kdWarning(129) << "KAction::plugAccel(): call to deprecated action." << endl; kdDebug(129) << kdBacktrace() << endl; //kdDebug(129) << "KAction::plugAccel( kacc = " << kacc << " ): name \"" << name() << "\"" << endl; if ( d->m_kaccel ) unplugAccel(); // If the parent collection's accel ptr isn't set yet //if ( m_parentCollection && !m_parentCollection->accel() ) // m_parentCollection->setAccel( kacc ); // We can only plug this action into the given KAccel object // if it does not already contain an action with the same name. if ( !kacc->actions().actionPtr(name()) ) { d->m_kaccel = kacc; d->m_kaccel->insert(name(), d->plainText(), QString::null, KShortcut(d->m_cut), this, SLOT(slotActivated()), configurable, isEnabled()); connect(d->m_kaccel, SIGNAL(destroyed()), this, SLOT(slotDestroyed())); //connect(d->m_kaccel, SIGNAL(keycodeChanged()), this, SLOT(slotKeycodeChanged())); } else kdWarning(129) << "KAction::plugAccel( kacc = " << kacc << " ): KAccel object already contains an action name \"" << name() << "\"" << endl; // -- ellis */ } void KAction::unplugAccel() { - qDebug("KAction::unplugAccel ...1 has top be fixed"); + // qDebug("KAction::unplugAccel ...1 has top be fixed"); /*US //kdDebug(129) << "KAction::unplugAccel() " << this << " " << name() << endl; if ( d->m_kaccel ) { d->m_kaccel->remove(name()); d->m_kaccel = 0; } */ } void KAction::plugMainWindowAccel( QWidget *w ) { - qDebug("KAction::plugMainWindowAccel ...1 has top be fixed"); + // qDebug("KAction::plugMainWindowAccel ...1 has top be fixed"); + /*US // Note: topLevelWidget() stops too early, we can't use it. QWidget * tl = w; QWidget * n; while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store tl = n; KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow if (mw) plugAccel( mw->accel() ); else kdDebug(129) << "KAction::plugMainWindowAccel: Toplevel widget isn't a KMainWindow, can't plug accel. " << tl << endl; */ } void KAction::setEnabled(bool enable) { //kdDebug(129) << "KAction::setEnabled( " << enable << " ): this = " << this << " d->m_kaccelList.count() = " << d->m_kaccelList.count() << endl; if ( enable == d->isEnabled() ) return; // KDE 4: remove //US if (d->m_kaccel) //US d->m_kaccel->setEnabled(name(), enable); // KDE 4: remove end //US for ( uint i = 0; i < d->m_kaccelList.count(); i++ ) //US d->m_kaccelList[i]->setEnabled( name(), enable ); d->setEnabled( enable ); int len = containerCount(); for( int i = 0; i < len; ++i ) updateEnabled( i ); emit enabled( d->isEnabled() ); } void KAction::updateEnabled( int i ) { QWidget *w = container( i ); if ( w->inherits("QPopupMenu") ) static_cast<QPopupMenu*>(w)->setItemEnabled( itemId( i ), d->isEnabled() ); else if ( w->inherits("QMenuBar") ) static_cast<QMenuBar*>(w)->setItemEnabled( itemId( i ), d->isEnabled() ); else if ( w->inherits( "KToolBar" ) ) { static_cast<KToolBar*>(w)->setItemEnabled( itemId( i ), d->isEnabled() ); } } void KAction::setShortcutConfigurable( bool b ) { d->m_configurable = b; } void KAction::setText( const QString& text ) { /*US // KDE 4: remove if (d->m_kaccel) { KAccelAction* pAction = d->m_kaccel->actions().actionPtr(name()); if (pAction) pAction->setLabel( text ); } // KDE 4: remove end for( uint i = 0; i < d->m_kaccelList.count(); i++ ) { KAccelAction* pAction = d->m_kaccelList[i]->actions().actionPtr(name()); if (pAction) pAction->setLabel( text ); } */ d->setText( text ); int len = containerCount(); for( int i = 0; i < len; ++i ) updateText( i ); } void KAction::updateText( int i ) { QWidget *w = container( i ); if ( w->inherits( "QPopupMenu" ) ) { int id = itemId( i ); static_cast<QPopupMenu*>(w)->changeItem( id, d->text() ); updateShortcut( static_cast<QPopupMenu*>(w), id ); } else if ( w->inherits( "QMenuBar" ) ) static_cast<QMenuBar*>(w)->changeItem( itemId( i ), d->text() ); else if ( w->inherits( "KToolBar" ) ) { - qDebug("KAction::updateText ...3 has top be fixed"); + //qDebug("KAction::updateText ...3 has top be fixed"); QWidget *button = static_cast<KToolBar *>(w)->getWidget( itemId( i ) ); if ( button->inherits( "KToolBarButton" ) ) static_cast<KToolBarButton *>(button)->setText( d->plainText() ); } } QString KAction::text() const { return d->text(); } QString KAction::plainText() const { return d->plainText( ); } void KAction::setIcon( const QString &icon ) { d->setIconName( icon ); // now handle any toolbars int len = containerCount(); for ( int i = 0; i < len; ++i ) updateIcon( i ); } void KAction::updateIcon( int id ) { QWidget* w = container( id ); if ( w->inherits( "QPopupMenu" ) ) { int itemId_ = itemId( id ); static_cast<QPopupMenu*>(w)->changeItem( itemId_, d->iconSet( KIcon::Small ), d->text() ); updateShortcut( static_cast<QPopupMenu*>(w), itemId_ ); } else if ( w->inherits( "QMenuBar" ) ) static_cast<QMenuBar*>(w)->changeItem( itemId( id ), d->iconSet( KIcon::Small ), d->text() ); else if ( w->inherits( "KToolBar" ) ) static_cast<KToolBar *>(w)->setButtonIcon( itemId( id ), d->iconName() ); else if ( w->inherits( "QToolBar" ) ) { qDebug("KAction::updateIcon has top be fixed"); //US static_cast<QToolBar *>(w)->setButtonIcon( itemId( id ), d->iconName() ); } } QString KAction::icon() const { return d->iconName( ); } void KAction::setIconSet( const QIconSet &iconset ) { d->setIconSet( iconset ); int len = containerCount(); for( int i = 0; i < len; ++i ) updateIconSet( i ); } void KAction::updateIconSet( int id ) { QWidget *w = container( id ); if ( w->inherits( "QPopupMenu" ) ) { int itemId_ = itemId( id ); static_cast<QPopupMenu*>(w)->changeItem( itemId_, d->iconSet(), d->text() ); updateShortcut( static_cast<QPopupMenu*>(w), itemId_ ); } else if ( w->inherits( "QMenuBar" ) ) static_cast<QMenuBar*>(w)->changeItem( itemId( id ), d->iconSet(), d->text() ); else if ( w->inherits( "KToolBar" ) ) { if ( icon().isEmpty() && d->hasIconSet() ) // only if there is no named icon ( scales better ) static_cast<KToolBar *>(w)->setButtonIconSet( itemId( id ), d->iconSet() ); else static_cast<KToolBar *>(w)->setButtonIconSet( itemId( id ), d->iconSet( KIcon::Small ) ); } } QIconSet KAction::iconSet( KIcon::Group group, int size ) const { return d->iconSet( group, size ); } bool KAction::hasIcon() const { return d->hasIcon(); } void KAction::setWhatsThis( const QString& text ) { d->setWhatsThis( text ); int len = containerCount(); for( int i = 0; i < len; ++i ) updateWhatsThis( i ); } void KAction::updateWhatsThis( int i ) { qDebug("KAction::updateWhatsThis ...1 has top be fixed"); QPopupMenu* pm = popupMenu( i ); if ( pm ) { pm->setWhatsThis( itemId( i ), d->whatsThis() ); return; } KToolBar *tb = toolBar( i ); if ( tb ) { QWidget *w = tb->getButton( itemId( i ) ); //US QWhatsThis::remove( w ); //US QWhatsThis::add( w, d->whatsThis() ); return; } } QString KAction::whatsThis() const { return d->whatsThis(); } QString KAction::whatsThisWithIcon() const { QString text = whatsThis(); if (!d->iconName().isEmpty()) return QString::fromLatin1("<img source=\"small|%1\"> %2").arg(d->iconName() ).arg(text); return text; } QWidget* KAction::container( int index ) const { assert( index < containerCount() ); return d->m_containers[ index ].m_container; } KToolBar* KAction::toolBar( int index ) const { //US return dynamic_cast<KToolBar *>( d->m_containers[ index ].m_container ); return (KToolBar *)( d->m_containers[ index ].m_container ); } QPopupMenu* KAction::popupMenu( int index ) const { //US return dynamic_cast<QPopupMenu *>( d->m_containers[ index ].m_container ); return (QPopupMenu *)( d->m_containers[ index ].m_container ); } QWidget* KAction::representative( int index ) const { return d->m_containers[ index ].m_representative; } int KAction::itemId( int index ) const { return d->m_containers[ index ].m_id; } int KAction::containerCount() const { return d->m_containers.count(); } uint KAction::kaccelCount() const { return d->m_kaccelList.count(); } void KAction::addContainer( QWidget* c, int id ) { KActionPrivate::Container p; p.m_container = c; p.m_id = id; d->m_containers.append( p ); } void KAction::addContainer( QWidget* c, QWidget* w ) { KActionPrivate::Container p; p.m_container = c; p.m_representative = w; d->m_containers.append( p ); } void KAction::activate() { slotActivated(); } void KAction::slotActivated() { emit activated(); } void KAction::slotDestroyed() { - kdDebug(129) << "KAction::slotDestroyed(): this = " << this << ", name = \"" << name() << "\", sender = " << sender() << endl; + const QObject* o = sender(); /* // KDE 4: remove if ( o == d->m_kaccel ) { d->m_kaccel = 0; return; } // KDE 4: remove end for( uint i = 0; i < d->m_kaccelList.count(); i++ ) { if ( o == d->m_kaccelList[i] ) { disconnect( d->m_kaccelList[i], SIGNAL(destroyed()), this, SLOT(slotDestroyed()) ); d->m_kaccelList.remove( d->m_kaccelList.at( i ) ); return; } } */ int i; do { i = findContainer( static_cast<const QWidget*>( o ) ); if ( i != -1 ) removeContainer( i ); } while ( i != -1 ); } int KAction::findContainer( const QWidget* widget ) const { int pos = 0; QValueList<KActionPrivate::Container>::ConstIterator it = d->m_containers.begin(); while( it != d->m_containers.end() ) { if ( (*it).m_representative == widget || (*it).m_container == widget ) return pos; ++it; ++pos; } return -1; } void KAction::removeContainer( int index ) { int i = 0; QValueList<KActionPrivate::Container>::Iterator it = d->m_containers.begin(); while( it != d->m_containers.end() ) { if ( i == index ) { d->m_containers.remove( it ); return; } ++it; ++i; } } // FIXME: Remove this (ellis) void KAction::slotKeycodeChanged() { qDebug("KAction::slotKeycodeChanged() ...44 has top be fixed"); /*US kdDebug(129) << "KAction::slotKeycodeChanged()" << endl; // -- ellis KAccelAction* pAction = d->m_kaccel->actions().actionPtr(name()); if( pAction ) setShortcut(pAction->shortcut()); */ } KActionCollection *KAction::parentCollection() const { return m_parentCollection; } void KAction::unplugAll() { while ( containerCount() != 0 ) unplug( container( 0 ) ); } void KAction::virtual_hook( int, void* ) { /*BASE::virtual_hook( id, data );*/ } /* vim: et sw=2 ts=2 */ //US #include "kaction.moc" |