From kde-commits Thu Sep 30 22:48:26 2010 From: Allen Winter Date: Thu, 30 Sep 2010 22:48:26 +0000 To: kde-commits Subject: KDE/kdepimlibs/kcalutils Message-Id: <20100930224826.A15B4AC891 () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=128588693428331 SVN commit 1181407 by winterz: port forward the following: SVN commit 1180979 by winterz: in the displayView, show a small participation status icon to the left of each attendee (and the organizer also gets a little icon of their own). now, the user can see at-a-glance who is attending their shindig. still need to do something similar for tooltips. kolab/issue4483 SVN commit 1181033 by winterz: add attendee status icon and text to the attendee list in the tooltips. kolab/issue4483 SVN commit 1181040 by winterz: refactor: make a new static method attendeeStatusIconPath for use in a few places. SVN commit 1181067 by winterz: refactor: new searchName() and searchNameAndUid() methods for searching the user's addressbook for a person's name and/or Uid from their email, as needed. constify a bunch too. kolab/issue4483 SVN commit 1181071 by winterz: refactor: new htmlAddMailtoLink() for creating a mailto: html link kolab/issue4483 SVN commit 1181075 by winterz: refactor: new htmlAddUidLink() for creating a uid: html link kolab/issue4483 M +194 -77 incidenceformatter.cpp --- trunk/KDE/kdepimlibs/kcalutils/incidenceformatter.cpp #1181406:1181407 @@ -78,6 +78,38 @@ return tmpStr; } +static QString htmlAddMailtoLink( const QString &email, const QString &name ) +{ + QString str; + + if ( !email.isEmpty() ) { + Person person( name, email ); + KUrl mailto; + mailto.setProtocol( "mailto" ); + mailto.setPath( person.fullName() ); + const QString iconPath = + KIconLoader::global()->iconPath( "mail-message-new", KIconLoader::Small ); + str = htmlAddLink( mailto.url(), "" ); + } + return str; +} + +static QString htmlAddUidLink( const QString &email, const QString &name, const QString &uid ) +{ + QString str; + + if ( !uid.isEmpty() ) { + // There is a UID, so make a link to the addressbook + if ( name.isEmpty() ) { + // Use the email address for text + str += htmlAddLink( "uid:" + uid, email ); + } else { + str += htmlAddLink( "uid:" + uid, name ); + } + } + return str; +} + static QString htmlAddTag( const QString &tag, const QString &text ) { int numLineBreaks = text.count( "\n" ); @@ -102,6 +134,27 @@ return tmpStr; } +static QPair searchNameAndUid( const QString &email, const QString &name, + const QString &uid ) +{ + // Yes, this is a silly method now, but it's predecessor was quite useful in e35. + // For now, please keep this sillyness until e35 is frozen to ease forward porting. + // -Allen + QPairs; + s.first = name; + s.second = uid; + if ( !email.isEmpty() && ( name.isEmpty() || uid.isEmpty() ) ) { + s.second.clear(); + } + return s; +} + +static QString searchName( const QString &email, const QString &name ) +{ + const QString printName = name.isEmpty() ? email : name; + return printName; +} + static bool iamAttendee( Attendee::Ptr attendee ) { // Check if I'm this attendee @@ -180,6 +233,37 @@ } return name; } + +static QString attendeeStatusIconPath( Attendee::PartStat status ) +{ + QString iconPath; + switch ( status ) { + case Attendee::Accepted: + iconPath = KIconLoader::global()->iconPath( "dialog-ok-apply", KIconLoader::Small ); + break; + case Attendee::Declined: + iconPath = KIconLoader::global()->iconPath( "dialog-cancel", KIconLoader::Small ); + break; + case Attendee::NeedsAction: + iconPath = KIconLoader::global()->iconPath( "help-about", KIconLoader::Small ); + break; + case Attendee::InProcess: + iconPath = KIconLoader::global()->iconPath( "help-about", KIconLoader::Small ); + break; + case Attendee::Tentative: + iconPath = KIconLoader::global()->iconPath( "dialog-ok", KIconLoader::Small ); + break; + case Attendee::Delegated: + iconPath = KIconLoader::global()->iconPath( "mail-forward", KIconLoader::Small ); + break; + case Attendee::Completed: + iconPath = KIconLoader::global()->iconPath( "mail-mark-read", KIconLoader::Small ); + default: + break; + } + return iconPath; +} + //@endcond /******************************************************************* @@ -188,39 +272,65 @@ //@cond PRIVATE static QString displayViewLinkPerson( const QString &email, const QString &name, - QString uid, const QString &iconPath ) + const QString &uid, Attendee::PartStat status ) { - // Make the search, if there is an email address to search on, - // and either name or uid is missing - if ( !email.isEmpty() && ( name.isEmpty() || uid.isEmpty() ) ) { - uid.clear(); + // Search for new print name or uid, if needed. + QPair s = searchNameAndUid( email, name, uid ); + const QString printName = s.first; + const QString printUid = s.second; + + // Get the icon corresponding to the attendee participation status. + const QString iconPath = attendeeStatusIconPath( status ); + + QString personString; + if ( !iconPath.isEmpty() ) { + personString += "" + " "; } - // Show the attendee - QString tmpString; - if ( !uid.isEmpty() ) { - // There is a UID, so make a link to the addressbook - if ( name.isEmpty() ) { - // Use the email address for text - tmpString += htmlAddLink( "uid:" + uid, email ); + // Make the uid link + if ( !printUid.isEmpty() ) { + personString += htmlAddUidLink( email, printName, printUid ); } else { - tmpString += htmlAddLink( "uid:" + uid, name ); + // No UID, just show some text + personString += ( printName.isEmpty() ? email : printName ); } + + // Make the mailto link + if ( !email.isEmpty() ) { + personString += " " + htmlAddMailtoLink( email, printName ); + } + + return personString; +} + +static QString displayViewFormatOrganizer( const QString &email, const QString &name ) +{ + // Search for new print name or uid, if needed. + QPair s = searchNameAndUid( email, name, QString() ); + const QString printName = s.first; + const QString printUid = s.second; + + // Get the icon for organizer + const QString iconPath = + KIconLoader::global()->iconPath( "meeting-organizer", KIconLoader::Small ); + + QString personString; + personString += "" + " "; + + // Make the uid link + if ( !printUid.isEmpty() ) { + personString += htmlAddUidLink( email, printName, printUid ); } else { // No UID, just show some text - tmpString += ( name.isEmpty() ? email : name ); + personString += ( printName.isEmpty() ? email : printName ); } // Make the mailto link - if ( !email.isEmpty() && !iconPath.isNull() ) { - KUrl mailto; - mailto.setProtocol( "mailto" ); - mailto.setPath( email ); - tmpString += htmlAddLink( mailto.url(), - "" ); + if ( !email.isEmpty() ) { + personString += " " + htmlAddMailtoLink( email, printName ); } - return tmpString; + return personString; } static QString displayViewFormatAttendeeRoleList( Incidence::Ptr incidence, Attendee::Role role ) @@ -228,8 +338,6 @@ QString tmpStr; Attendee::List::ConstIterator it; Attendee::List attendees = incidence->attendees(); - KIconLoader *iconLoader = KIconLoader::global(); - const QString iconPath = iconLoader->iconPath( "mail-message-new", KIconLoader::Small ); for ( it = attendees.constBegin(); it != attendees.constEnd(); ++it ) { Attendee::Ptr a = *it; @@ -241,7 +349,7 @@ // skip attendee that is also the organizer continue; } - tmpStr += displayViewLinkPerson( a->email(), a->name(), a->uid(), iconPath ); + tmpStr += displayViewLinkPerson( a->email(), a->name(), a->uid(), a->status() ); if ( !a->delegator().isEmpty() ) { tmpStr += i18n( " (delegated by %1)", a->delegator() ); } @@ -260,9 +368,6 @@ { QString tmpStr, str; - KIconLoader *iconLoader = KIconLoader::global(); - const QString iconPath = iconLoader->iconPath( "mail-message-new", KIconLoader::Small ); - // Add organizer link int attendeeCount = incidence->attendees().count(); if ( attendeeCount > 1 || @@ -271,9 +376,8 @@ tmpStr += ""; tmpStr += "" + i18n( "Organizer:" ) + ""; tmpStr += "" + - displayViewLinkPerson( incidence->organizer()->email(), - incidence->organizer()->name(), - QString(), iconPath ) + + displayViewFormatOrganizer( incidence->organizer()->email(), + incidence->organizer()->name() ) + ""; tmpStr += ""; } @@ -373,10 +477,8 @@ QString name_1 = event->customProperty( "KABC", "NAME-1" ); QString email_1= event->customProperty( "KABC", "EMAIL-1" ); - KIconLoader *iconLoader = KIconLoader::global(); - const QString iconPath = iconLoader->iconPath( "mail-message-new", KIconLoader::Small ); - //TODO: add a birthday cake icon - QString tmpStr = displayViewLinkPerson( email_1, name_1, uid_1, iconPath ); + //TODO: add a birthday cake icon. Make a displayViewLinkBirthdayPerson(email,name,uid) + QString tmpStr = displayViewLinkPerson( email_1, name_1, uid_1, Attendee::None ); return tmpStr; } @@ -1245,44 +1347,30 @@ return ret; } -static QString invitationPerson( const QString &email, QString name, QString uid ) +static QString invitationPerson( const QString &email, const QString &name, const QString &uid ) { - // Make the search, if there is an email address to search on, - // and either name or uid is missing - if ( !email.isEmpty() && ( name.isEmpty() || uid.isEmpty() ) ) { - uid.clear(); - } + QPair s = searchNameAndUid( email, name, uid ); + const QString printName = s.first; + const QString printUid = s.second; - // Show the attendee - QString tmpString; - if ( !uid.isEmpty() ) { - // There is a UID, so make a link to the addressbook - if ( name.isEmpty() ) { - // Use the email address for text - tmpString += htmlAddLink( "uid:" + uid, email ); + QString personString; + + // Make the uid link + if ( !printUid.isEmpty() ) { + personString += htmlAddUidLink( email, printName, printUid ); } else { - tmpString += htmlAddLink( "uid:" + uid, name ); - } - } else { // No UID, just show some text - tmpString += ( name.isEmpty() ? email : name ); + personString += ( printName.isEmpty() ? email : printName ); } - tmpString += '\n'; + personString += '\n'; // Make the mailto link if ( !email.isEmpty() ) { - Person person( name, email ); - KUrl mailto; - mailto.setProtocol( "mailto" ); - mailto.setPath( person.fullName() ); - const QString iconPath = - KIconLoader::global()->iconPath( "mail-message-new", KIconLoader::Small ); - tmpString += htmlAddLink( mailto.url(), - "" ); + personString += " " + htmlAddMailtoLink( email, printName ); } - tmpString += '\n'; + personString += '\n'; - return tmpString; + return personString; } static QString invitationDetailsIncidence( const Incidence::Ptr &incidence, bool noHtmlMode ) @@ -3197,17 +3285,46 @@ return !mResult.isEmpty(); } -static QString tooltipPerson( const QString &email, QString name ) +static QString tooltipPerson( const QString &email, const QString &name, Attendee::PartStat status ) { - return name.isEmpty() ? email : name; + // Search for a new print name, if needed. + const QString printName = searchName( email, name ); + + // Get the icon corresponding to the attendee participation status. + const QString iconPath = attendeeStatusIconPath( status ); + + // Make the return string. + QString personString; + if ( !iconPath.isEmpty() ) { + personString += "" + " "; } + personString += i18nc( "attendee name (attendee status)", "%1 (%2)", + printName.isEmpty() ? email : printName, + Stringify::attendeeStatus( status ) ); + return personString; +} +static QString tooltipFormatOrganizer( const QString &email, const QString &name ) +{ + // Search for a new print name, if needed + const QString printName = searchName( email, name ); + + // Get the icon for organizer + const QString iconPath = + KIconLoader::global()->iconPath( "meeting-organizer", KIconLoader::Small ); + + // Make the return string. + QString personString; + personString += "" + " "; + personString += ( printName.isEmpty() ? email : printName ); + return personString; +} + static QString tooltipFormatAttendeeRoleList( const Incidence::Ptr &incidence, Attendee::Role role ) { int maxNumAtts = 8; // maximum number of people to print per attendee role - QString sep = i18nc( "separator for lists of people names", ", " ); - int sepLen = sep.length(); + const QString etc = i18nc( "elipsis", "..." ); int i = 0; QString tmpStr; @@ -3225,21 +3342,21 @@ continue; } if ( i == maxNumAtts ) { - tmpStr += i18nc( "elipsis", "..." ); + tmpStr += "  " + etc; break; } - tmpStr += tooltipPerson( a->email(), a->name() ); + tmpStr += "  " + tooltipPerson( a->email(), a->name(), a->status() ); if ( !a->delegator().isEmpty() ) { tmpStr += i18n( " (delegated by %1)", a->delegator() ); } if ( !a->delegate().isEmpty() ) { tmpStr += i18n( " (delegated to %1)", a->delegate() ); } - tmpStr += sep; + tmpStr += "
"; i++; } - if ( tmpStr.endsWith( sep ) ) { - tmpStr.truncate( tmpStr.length() - sepLen ); + if ( tmpStr.endsWith( QLatin1String( "
" ) ) ) { + tmpStr.chop( 4 ); } return tmpStr; } @@ -3253,36 +3370,36 @@ if ( attendeeCount > 1 || ( attendeeCount == 1 && incidence->organizer()->email() != incidence->attendees().first()->email() ) ) { - tmpStr += "" + i18n( "Organizer:" ) + "" + " "; - tmpStr += tooltipPerson( incidence->organizer()->email(), + tmpStr += "" + i18n( "Organizer:" ) + "" + "
"; + tmpStr += "  " + tooltipFormatOrganizer( incidence->organizer()->email(), incidence->organizer()->name() ); } // Add "chair" str = tooltipFormatAttendeeRoleList( incidence, Attendee::Chair ); if ( !str.isEmpty() ) { - tmpStr += "
" + i18n( "Chair:" ) + "" + " "; + tmpStr += "
" + i18n( "Chair:" ) + "" + "
"; tmpStr += str; } // Add required participants str = tooltipFormatAttendeeRoleList( incidence, Attendee::ReqParticipant ); if ( !str.isEmpty() ) { - tmpStr += "
" + i18n( "Required Participants:" ) + "" + " "; + tmpStr += "
" + i18n( "Required Participants:" ) + "" + "
"; tmpStr += str; } // Add optional participants str = tooltipFormatAttendeeRoleList( incidence, Attendee::OptParticipant ); if ( !str.isEmpty() ) { - tmpStr += "
" + i18n( "Optional Participants:" ) + "" + " "; + tmpStr += "
" + i18n( "Optional Participants:" ) + "" + "
"; tmpStr += str; } // Add observers str = tooltipFormatAttendeeRoleList( incidence, Attendee::NonParticipant ); if ( !str.isEmpty() ) { - tmpStr += "
" + i18n( "Observers:" ) + "" + " "; + tmpStr += "
" + i18n( "Observers:" ) + "" + "
"; tmpStr += str; }