diff --git a/akonadi/contact/contactstreemodel.cpp b/akonadi/contact/contactstreemodel.cpp index 84ec0fb97..388ef418d 100644 --- a/akonadi/contact/contactstreemodel.cpp +++ b/akonadi/contact/contactstreemodel.cpp @@ -1,282 +1,282 @@ /* This file is part of Akonadi Contact. Copyright (c) 2009 Stephen Kelly Copyright (c) 2009 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "contactstreemodel.h" #include #include #include #include #include #include using namespace Akonadi; class ContactsTreeModel::Private { public: Private() : mColumns( ContactsTreeModel::Columns() << ContactsTreeModel::FullName ), mIconSize( KIconLoader::global()->currentSize( KIconLoader::Small ) ) { } Columns mColumns; const int mIconSize; }; ContactsTreeModel::ContactsTreeModel( ChangeRecorder *monitor, QObject *parent ) : EntityTreeModel( monitor, parent ), d( new Private ) { } ContactsTreeModel::~ContactsTreeModel() { delete d; } void ContactsTreeModel::setColumns( const Columns &columns ) { emit layoutAboutToBeChanged(); d->mColumns = columns; emit layoutChanged(); } ContactsTreeModel::Columns ContactsTreeModel::columns() const { return d->mColumns; } QVariant ContactsTreeModel::entityData( const Item &item, int column, int role ) const { if ( item.mimeType() == KABC::Addressee::mimeType() ) { if ( !item.hasPayload() ) { // Pass modeltest if ( role == Qt::DisplayRole ) return item.remoteId(); return QVariant(); } const KABC::Addressee contact = item.payload(); if ( role == Qt::DecorationRole ) { if ( column == 0 ) { const KABC::Picture picture = contact.photo(); if ( picture.isIntern() ) { return picture.data().scaled( QSize( d->mIconSize, d->mIconSize ), Qt::KeepAspectRatio ); } else { return KIcon( QLatin1String( "user-identity" ) ); } } return QVariant(); } else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) { switch ( d->mColumns.at( column ) ) { case FullName: return contact.realName(); break; case FamilyName: return contact.familyName(); break; case GivenName: return contact.givenName(); break; case Birthday: if ( contact.birthday().isValid() ) - return KGlobal::locale()->formatDate( contact.birthday().date() ); + return KGlobal::locale()->formatDate( contact.birthday().date(), KLocale::ShortDate ); break; case HomeAddress: { const KABC::Address address = contact.address( KABC::Address::Home ); if ( !address.isEmpty() ) return address.formattedAddress(); } break; case BusinessAddress: { const KABC::Address address = contact.address( KABC::Address::Work ); if ( !address.isEmpty() ) return address.formattedAddress(); } break; case PhoneNumbers: { QStringList values; const KABC::PhoneNumber::List numbers = contact.phoneNumbers(); foreach ( const KABC::PhoneNumber &number, numbers ) values += number.number(); return values.join( QLatin1String( "\n" ) ); } break; case PreferredEmail: return contact.preferredEmail(); break; case AllEmails: return contact.emails().join( QLatin1String( "\n" ) ); break; case Organization: return contact.organization(); break; case Role: return contact.role(); break; case Homepage: return contact.url().url(); break; case Note: return contact.note(); break; } } else if ( role == DateRole ) { if ( d->mColumns.at( column ) == Birthday ) return contact.birthday(); else return QDate(); } } else if ( item.mimeType() == KABC::ContactGroup::mimeType() ) { if ( !item.hasPayload() ) { // Pass modeltest if ( role == Qt::DisplayRole ) return item.remoteId(); return QVariant(); } if ( role == Qt::DecorationRole ) { if ( column == 0 ) return KIcon( QLatin1String( "x-mail-distribution-list" ) ); else return QVariant(); } else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) { switch ( d->mColumns.at( column ) ) { case FullName: { const KABC::ContactGroup group = item.payload(); return group.name(); } break; default: return QVariant(); break; } } } return EntityTreeModel::entityData( item, column, role ); } QVariant ContactsTreeModel::entityData( const Collection &collection, int column, int role ) const { if ( role == Qt::DisplayRole ) { switch ( column ) { case 0: return EntityTreeModel::entityData( collection, column, role ); default: return QString(); // pass model test } } return EntityTreeModel::entityData( collection, column, role ); } int ContactsTreeModel::entityColumnCount( HeaderGroup headerGroup ) const { if ( headerGroup == EntityTreeModel::CollectionTreeHeaders ) { return 1; } else if ( headerGroup == EntityTreeModel::ItemListHeaders ) { return d->mColumns.count(); } else { return EntityTreeModel::entityColumnCount( headerGroup ); } } QVariant ContactsTreeModel::entityHeaderData( int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup ) const { if ( role == Qt::DisplayRole ) { if ( orientation == Qt::Horizontal ) { if ( headerGroup == EntityTreeModel::CollectionTreeHeaders ) { if ( section >= 1 ) return QVariant(); switch ( section ) { case 0: return i18nc( "@title:column address books overview", "Address Books" ); break; } } else if ( headerGroup == EntityTreeModel::ItemListHeaders ) { if ( section < 0 || section >= d->mColumns.count() ) return QVariant(); switch ( d->mColumns.at( section ) ) { case FullName: return i18nc( "@title:column name of a person", "Name" ); break; case FamilyName: return i18nc( "@title:column family name of a person", "Family Name" ); break; case GivenName: return i18nc( "@title:column given name of a person", "Given Name" ); break; case Birthday: return KABC::Addressee::birthdayLabel(); break; case HomeAddress: return i18nc( "@title:column home address of a person", "Home" ); break; case BusinessAddress: return i18nc( "@title:column work address of a person", "Work" ); break; case PhoneNumbers: return i18nc( "@title:column phone numbers of a person", "Phone Numbers" ); break; case PreferredEmail: return i18nc( "@title:column the preferred email addresses of a person", "Preferred EMail" ); break; case AllEmails: return i18nc( "@title:column all email addresses of a person", "All EMails" ); break; case Organization: return KABC::Addressee::organizationLabel(); break; case Role: return KABC::Addressee::roleLabel(); break; case Homepage: return KABC::Addressee::urlLabel(); break; case Note: return KABC::Addressee::noteLabel(); break; } } } } return EntityTreeModel::entityHeaderData( section, orientation, role, headerGroup ); } #include "contactstreemodel.moc" diff --git a/akonadi/contact/standardcontactformatter.cpp b/akonadi/contact/standardcontactformatter.cpp index f3d13ed67..7b21faf83 100644 --- a/akonadi/contact/standardcontactformatter.cpp +++ b/akonadi/contact/standardcontactformatter.cpp @@ -1,275 +1,275 @@ /* This file is part of Akonadi Contact. Copyright (c) 2010 Tobias Koenig 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "standardcontactformatter.h" #include #include #include #include #include #include #include using namespace Akonadi; StandardContactFormatter::StandardContactFormatter() : d( 0 ) { } StandardContactFormatter::~StandardContactFormatter() { } QString StandardContactFormatter::toHtml( HtmlForm form ) const { KABC::Addressee rawContact; const Akonadi::Item localItem = item(); if ( localItem.isValid() && localItem.hasPayload() ) rawContact = localItem.payload(); else rawContact = contact(); if ( rawContact.isEmpty() ) return QString(); // We'll be building a table to display the vCard in. // Each row of the table will be built using this string for its HTML. QString rowFmtStr = QString::fromLatin1( "" "%1\n" "%2\n" "\n" ); // Build the table's rows here QString dynamicPart; // Birthday const QDate date = rawContact.birthday().date(); const int years = (date.daysTo( QDate::currentDate() ) / 365); if ( date.isValid() ) dynamicPart += rowFmtStr .arg( KABC::Addressee::birthdayLabel() ) - .arg( KGlobal::locale()->formatDate( date, KLocale::ShortDate ) + + .arg( KGlobal::locale()->formatDate( date ) + QLatin1String( "  " ) + i18np( "(One year old)", "(%1 years old)", years ) ); // Phone Numbers int counter = 0; foreach ( const KABC::PhoneNumber &number, rawContact.phoneNumbers() ) { const QString url = QString::fromLatin1( "%2" ).arg( counter ).arg( number.number() ); counter++; dynamicPart += rowFmtStr .arg( number.typeLabel().replace( QLatin1String( " " ), QLatin1String( " " ) ) ) .arg( url ); } // EMails foreach ( const QString &email, rawContact.emails() ) { QString type = i18nc( "a contact's email address", "Email" ); const QString fullEmail = QString::fromLatin1( KUrl::toPercentEncoding( rawContact.fullEmail( email ) ) ); dynamicPart += rowFmtStr.arg( type ) .arg( QString::fromLatin1( "%2" ) .arg( fullEmail, email ) ); } // Homepage if ( rawContact.url().isValid() ) { QString url = rawContact.url().url(); if ( !url.startsWith( QLatin1String( "http://" ) ) && !url.startsWith( QLatin1String( "https://" ) ) ) url = QLatin1String( "http://" ) + url; url = KStringHandler::tagUrls( url ); dynamicPart += rowFmtStr.arg( i18n( "Homepage" ) ).arg( url ); } // Blog Feed const QString blog = rawContact.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "BlogFeed" ) ); if ( !blog.isEmpty() ) dynamicPart += rowFmtStr.arg( i18n( "Blog Feed" ) ).arg( KStringHandler::tagUrls( blog ) ); // Addresses counter = 0; foreach ( const KABC::Address &address, rawContact.addresses() ) { QString formattedAddress; if ( address.label().isEmpty() ) { formattedAddress = address.formattedAddress().trimmed(); } else { formattedAddress = address.label(); } formattedAddress = formattedAddress.replace( QLatin1Char( '\n' ), QLatin1String( "
" ) ); const QString url = QString::fromLatin1( "%2" ).arg( counter).arg( formattedAddress ); counter++; dynamicPart += rowFmtStr .arg( KABC::Address::typeLabel( address.type() ) ) .arg( url ); } // Note QString notes; if ( !rawContact.note().isEmpty() ) notes = rowFmtStr.arg( i18n( "Notes" ) ).arg( rawContact.note().replace( QLatin1Char( '\n' ), QLatin1String( "
" ) ) ) ; // Custom Data QString customData; static QMap titleMap; if ( titleMap.isEmpty() ) { titleMap.insert( QLatin1String( "Department" ), i18n( "Department" ) ); titleMap.insert( QLatin1String( "Profession" ), i18n( "Profession" ) ); titleMap.insert( QLatin1String( "AssistantsName" ), i18n( "Assistant's Name" ) ); titleMap.insert( QLatin1String( "ManagersName" ), i18n( "Manager's Name" ) ); titleMap.insert( QLatin1String( "SpousesName" ), i18nc( "Wife/Husband/...", "Partner's Name" ) ); titleMap.insert( QLatin1String( "Office" ), i18n( "Office" ) ); titleMap.insert( QLatin1String( "IMAddress" ), i18n( "IM Address" ) ); titleMap.insert( QLatin1String( "Anniversary" ), i18n( "Anniversary" ) ); titleMap.insert( QLatin1String( "AddressBook" ), i18n( "Address Book" ) ); } static QSet blacklistedKeys; if ( blacklistedKeys.isEmpty() ) { blacklistedKeys.insert( QLatin1String( "CRYPTOPROTOPREF" ) ); blacklistedKeys.insert( QLatin1String( "OPENPGPFP" ) ); blacklistedKeys.insert( QLatin1String( "SMIMEFP" ) ); blacklistedKeys.insert( QLatin1String( "CRYPTOSIGNPREF" ) ); blacklistedKeys.insert( QLatin1String( "CRYPTOENCRYPTPREF" ) ); } if ( !rawContact.customs().empty() ) { const QStringList customs = rawContact.customs(); foreach ( QString custom, customs ) { //krazy:exclude=foreach if ( custom.startsWith( QLatin1String( "KADDRESSBOOK-" ) ) ) { custom.remove( QLatin1String( "KADDRESSBOOK-X-" ) ); custom.remove( QLatin1String( "KADDRESSBOOK-" ) ); int pos = custom.indexOf( QLatin1Char( ':' ) ); QString key = custom.left( pos ); QString value = custom.mid( pos + 1 ); // convert anniversary correctly if ( key == QLatin1String( "Anniversary" ) ) { const QDateTime dateTime = QDateTime::fromString( value, Qt::ISODate ); value = KGlobal::locale()->formatDate( dateTime.date(), KLocale::ShortDate ); } // blog is handled separated if ( key == QLatin1String( "BlogFeed" ) ) continue; if ( blacklistedKeys.contains( key ) ) continue; // check whether we have a mapping for the title const QMap::ConstIterator keyIt = titleMap.constFind( key ); if ( keyIt != titleMap.constEnd() ) { key = keyIt.value(); } else { // check whether it is a custom local field foreach ( const QVariantMap &description, customFieldDescriptions() ) { if ( description.value( QLatin1String( "key" ) ).toString() == key ) { key = description.value( QLatin1String( "title" ) ).toString(); if ( description.value( QLatin1String( "type" ) ) == QLatin1String( "boolean" ) ) { if ( value == QLatin1String( "true" ) ) value = i18nc( "Boolean value", "yes" ); else value = i18nc( "Boolean value", "no" ); } else if ( description.value( QLatin1String( "type" ) ) == QLatin1String( "date" ) ) { const QDate date = QDate::fromString( value, Qt::ISODate ); value = KGlobal::locale()->formatDate( date, KLocale::ShortDate ); } else if ( description.value( QLatin1String( "type" ) ) == QLatin1String( "time" ) ) { const QTime time = QTime::fromString( value, Qt::ISODate ); value = KGlobal::locale()->formatTime( time ); } else if ( description.value( QLatin1String( "type" ) ) == QLatin1String( "datetime" ) ) { const QDateTime dateTime = QDateTime::fromString( value, Qt::ISODate ); value = KGlobal::locale()->formatDateTime( dateTime, KLocale::ShortDate ); } break; } } } customData += rowFmtStr.arg( key ).arg( value ) ; } } } // Assemble all parts QString role = rawContact.title(); if ( role.isEmpty() ) role = rawContact.role(); if ( role.isEmpty() ) role = rawContact.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Profession" ) ); QString strAddr = QString::fromLatin1( "
" "" "" "" "" // name "" "" "" // role "" "" "" // organization "") .arg( QLatin1String( "contact_photo" ) ) .arg( rawContact.realName() ) .arg( role ) .arg( rawContact.organization() ); strAddr.append( dynamicPart ); strAddr.append( notes ); strAddr.append( customData ); strAddr.append( QString::fromLatin1( "
" "" // image "%2
%3
%4
\n" ) ); if ( form == EmbeddableForm ) return strAddr; const QString document = QString::fromLatin1( "" "" " " "" "" // text and background color "%3" // contact part "" "" ) .arg( KColorScheme( QPalette::Active, KColorScheme::View ).foreground().color().name() ) .arg( KColorScheme( QPalette::Active, KColorScheme::View ).background().color().name() ) .arg( strAddr ); return document; }