|
|
|
|
@ -54,10 +54,10 @@ typedef boost::shared_ptr<KMime::Message> MessagePtr; |
|
|
|
|
#include <klocale.h> |
|
|
|
|
|
|
|
|
|
KMSearchMessageModel::KMSearchMessageModel( QObject *parent ) |
|
|
|
|
: Akonadi::MessageModel( parent ) |
|
|
|
|
: Akonadi::MessageModel( parent ) |
|
|
|
|
{ |
|
|
|
|
fetchScope().fetchPayloadPart( Akonadi::MessagePart::Envelope ); |
|
|
|
|
fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::All ); |
|
|
|
|
fetchScope().fetchPayloadPart( Akonadi::MessagePart::Envelope ); |
|
|
|
|
fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::All ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
KMSearchMessageModel::~KMSearchMessageModel( ) |
|
|
|
|
@ -66,158 +66,158 @@ KMSearchMessageModel::~KMSearchMessageModel( ) |
|
|
|
|
|
|
|
|
|
QString toolTip( const Akonadi::Item& item ) |
|
|
|
|
{ |
|
|
|
|
MessagePtr msg = item.payload<MessagePtr>(); |
|
|
|
|
|
|
|
|
|
QColor bckColor = QApplication::palette().color( QPalette::ToolTipBase ); |
|
|
|
|
QColor txtColor = QApplication::palette().color( QPalette::ToolTipText ); |
|
|
|
|
|
|
|
|
|
const QString bckColorName = bckColor.name(); |
|
|
|
|
const QString txtColorName = txtColor.name(); |
|
|
|
|
const bool textIsLeftToRight = ( QApplication::layoutDirection() == Qt::LeftToRight ); |
|
|
|
|
const QString textDirection = textIsLeftToRight ? QLatin1String( "left" ) : QLatin1String( "right" ); |
|
|
|
|
|
|
|
|
|
QString tip = QString::fromLatin1( |
|
|
|
|
"<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">" |
|
|
|
|
); |
|
|
|
|
tip += QString::fromLatin1( |
|
|
|
|
"<tr>" \
|
|
|
|
|
"<td bgcolor=\"%1\" align=\"%4\" valign=\"middle\">" \
|
|
|
|
|
"<div style=\"color: %2; font-weight: bold;\">" \
|
|
|
|
|
"%3" \
|
|
|
|
|
"</div>" \
|
|
|
|
|
"</td>" \
|
|
|
|
|
"</tr>" |
|
|
|
|
).arg( txtColorName ).arg( bckColorName ).arg( Qt::escape( msg->subject()->asUnicodeString() ) ).arg( textDirection ); |
|
|
|
|
|
|
|
|
|
tip += QString::fromLatin1( |
|
|
|
|
"<tr>" \
|
|
|
|
|
"<td align=\"center\" valign=\"middle\">" \
|
|
|
|
|
"<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">" |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const QString htmlCodeForStandardRow = QString::fromLatin1( |
|
|
|
|
"<tr>" \
|
|
|
|
|
"<td align=\"right\" valign=\"top\" width=\"45\">" \
|
|
|
|
|
"<div style=\"font-weight: bold;\"><nobr>" \
|
|
|
|
|
"%1:" \
|
|
|
|
|
"</nobr></div>" \
|
|
|
|
|
"</td>" \
|
|
|
|
|
"<td align=\"left\" valign=\"top\">" \
|
|
|
|
|
"%2" \
|
|
|
|
|
"</td>" \
|
|
|
|
|
"</tr>" ); |
|
|
|
|
|
|
|
|
|
QString content = MessageList::Util::contentSummary( item.url() ); |
|
|
|
|
|
|
|
|
|
if ( textIsLeftToRight ) { |
|
|
|
|
tip += htmlCodeForStandardRow.arg( i18n( "From" ) ).arg( MessageCore::StringUtil::stripEmailAddr( msg->from()->asUnicodeString() ) ); |
|
|
|
|
tip += htmlCodeForStandardRow.arg( i18nc( "Receiver of the email", "To" ) ).arg( MessageCore::StringUtil::stripEmailAddr( msg->to()->asUnicodeString() ) ); |
|
|
|
|
tip += htmlCodeForStandardRow.arg( i18n( "Date" ) ).arg( KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate ) ); |
|
|
|
|
if ( !content.isEmpty() ) { |
|
|
|
|
tip += htmlCodeForStandardRow.arg( i18n( "Preview" ) ).arg( content.replace( QLatin1Char( '\n' ), QLatin1String( "<br>" ) ) ); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
tip += htmlCodeForStandardRow.arg( MessageCore::StringUtil::stripEmailAddr( msg->from()->asUnicodeString() ) ).arg( i18n( "From" ) ); |
|
|
|
|
tip += htmlCodeForStandardRow.arg( MessageCore::StringUtil::stripEmailAddr( msg->to()->asUnicodeString() ) ).arg( i18nc( "Receiver of the email", "To" ) ); |
|
|
|
|
tip += htmlCodeForStandardRow.arg( KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate ) ).arg( i18n( "Date" ) ); |
|
|
|
|
if ( !content.isEmpty() ) { |
|
|
|
|
tip += htmlCodeForStandardRow.arg( content.replace( QLatin1Char( '\n' ), QLatin1String( "<br>" ) ) ).arg( i18n( "Preview" ) ); |
|
|
|
|
MessagePtr msg = item.payload<MessagePtr>(); |
|
|
|
|
|
|
|
|
|
QColor bckColor = QApplication::palette().color( QPalette::ToolTipBase ); |
|
|
|
|
QColor txtColor = QApplication::palette().color( QPalette::ToolTipText ); |
|
|
|
|
|
|
|
|
|
const QString bckColorName = bckColor.name(); |
|
|
|
|
const QString txtColorName = txtColor.name(); |
|
|
|
|
const bool textIsLeftToRight = ( QApplication::layoutDirection() == Qt::LeftToRight ); |
|
|
|
|
const QString textDirection = textIsLeftToRight ? QLatin1String( "left" ) : QLatin1String( "right" ); |
|
|
|
|
|
|
|
|
|
QString tip = QString::fromLatin1( |
|
|
|
|
"<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">" |
|
|
|
|
); |
|
|
|
|
tip += QString::fromLatin1( |
|
|
|
|
"<tr>" \
|
|
|
|
|
"<td bgcolor=\"%1\" align=\"%4\" valign=\"middle\">" \
|
|
|
|
|
"<div style=\"color: %2; font-weight: bold;\">" \
|
|
|
|
|
"%3" \
|
|
|
|
|
"</div>" \
|
|
|
|
|
"</td>" \
|
|
|
|
|
"</tr>" |
|
|
|
|
).arg( txtColorName ).arg( bckColorName ).arg( Qt::escape( msg->subject()->asUnicodeString() ) ).arg( textDirection ); |
|
|
|
|
|
|
|
|
|
tip += QString::fromLatin1( |
|
|
|
|
"<tr>" \
|
|
|
|
|
"<td align=\"center\" valign=\"middle\">" \
|
|
|
|
|
"<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">" |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const QString htmlCodeForStandardRow = QString::fromLatin1( |
|
|
|
|
"<tr>" \
|
|
|
|
|
"<td align=\"right\" valign=\"top\" width=\"45\">" \
|
|
|
|
|
"<div style=\"font-weight: bold;\"><nobr>" \
|
|
|
|
|
"%1:" \
|
|
|
|
|
"</nobr></div>" \
|
|
|
|
|
"</td>" \
|
|
|
|
|
"<td align=\"left\" valign=\"top\">" \
|
|
|
|
|
"%2" \
|
|
|
|
|
"</td>" \
|
|
|
|
|
"</tr>" ); |
|
|
|
|
|
|
|
|
|
QString content = MessageList::Util::contentSummary( item.url() ); |
|
|
|
|
|
|
|
|
|
if ( textIsLeftToRight ) { |
|
|
|
|
tip += htmlCodeForStandardRow.arg( i18n( "From" ) ).arg( MessageCore::StringUtil::stripEmailAddr( msg->from()->asUnicodeString() ) ); |
|
|
|
|
tip += htmlCodeForStandardRow.arg( i18nc( "Receiver of the email", "To" ) ).arg( MessageCore::StringUtil::stripEmailAddr( msg->to()->asUnicodeString() ) ); |
|
|
|
|
tip += htmlCodeForStandardRow.arg( i18n( "Date" ) ).arg( KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate ) ); |
|
|
|
|
if ( !content.isEmpty() ) { |
|
|
|
|
tip += htmlCodeForStandardRow.arg( i18n( "Preview" ) ).arg( content.replace( QLatin1Char( '\n' ), QLatin1String( "<br>" ) ) ); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
tip += htmlCodeForStandardRow.arg( MessageCore::StringUtil::stripEmailAddr( msg->from()->asUnicodeString() ) ).arg( i18n( "From" ) ); |
|
|
|
|
tip += htmlCodeForStandardRow.arg( MessageCore::StringUtil::stripEmailAddr( msg->to()->asUnicodeString() ) ).arg( i18nc( "Receiver of the email", "To" ) ); |
|
|
|
|
tip += htmlCodeForStandardRow.arg( KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate ) ).arg( i18n( "Date" ) ); |
|
|
|
|
if ( !content.isEmpty() ) { |
|
|
|
|
tip += htmlCodeForStandardRow.arg( content.replace( QLatin1Char( '\n' ), QLatin1String( "<br>" ) ) ).arg( i18n( "Preview" ) ); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
tip += QString::fromLatin1( |
|
|
|
|
"</table" \
|
|
|
|
|
"</td>" \
|
|
|
|
|
"</tr>" |
|
|
|
|
); |
|
|
|
|
return tip; |
|
|
|
|
tip += QString::fromLatin1( |
|
|
|
|
"</table" \
|
|
|
|
|
"</td>" \
|
|
|
|
|
"</tr>" |
|
|
|
|
); |
|
|
|
|
return tip; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int KMSearchMessageModel::columnCount( const QModelIndex & parent ) const |
|
|
|
|
{ |
|
|
|
|
if ( collection().isValid() |
|
|
|
|
&& !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") ) |
|
|
|
|
&& collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) ) |
|
|
|
|
return 1; |
|
|
|
|
if ( collection().isValid() |
|
|
|
|
&& !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") ) |
|
|
|
|
&& collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) ) |
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
|
if ( !parent.isValid() ) |
|
|
|
|
return 8; // keep in sync with the column type enum
|
|
|
|
|
if ( !parent.isValid() ) |
|
|
|
|
return 8; // keep in sync with the column type enum
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QVariant KMSearchMessageModel::data( const QModelIndex & index, int role ) const |
|
|
|
|
{ |
|
|
|
|
if ( !index.isValid() ) |
|
|
|
|
return QVariant(); |
|
|
|
|
if ( index.row() >= rowCount() ) |
|
|
|
|
return QVariant(); |
|
|
|
|
|
|
|
|
|
if ( !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") ) ) { |
|
|
|
|
if ( role == Qt::DisplayRole ) |
|
|
|
|
return i18nc( "@label", "This model can only handle email folders. The current collection holds mimetypes: %1", |
|
|
|
|
collection().contentMimeTypes().join( QLatin1String(",") ) ); |
|
|
|
|
else |
|
|
|
|
return QVariant(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Akonadi::Item item = itemForIndex( index ); |
|
|
|
|
if ( !item.hasPayload<MessagePtr>() ) |
|
|
|
|
return QVariant(); |
|
|
|
|
MessagePtr msg = item.payload<MessagePtr>(); |
|
|
|
|
if ( role == Qt::DisplayRole ) { |
|
|
|
|
switch ( index.column() ) { |
|
|
|
|
case Collection: |
|
|
|
|
if ( item.storageCollectionId() >= 0 ) { |
|
|
|
|
return MailCommon::Util::fullCollectionPath( Akonadi::Collection( item.storageCollectionId() ) ); |
|
|
|
|
} |
|
|
|
|
return MailCommon::Util::fullCollectionPath(item.parentCollection()); |
|
|
|
|
case Subject: |
|
|
|
|
return msg->subject()->asUnicodeString(); |
|
|
|
|
case Sender: |
|
|
|
|
return msg->from()->asUnicodeString(); |
|
|
|
|
case Receiver: |
|
|
|
|
return msg->to()->asUnicodeString(); |
|
|
|
|
case Date: |
|
|
|
|
return KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate ); |
|
|
|
|
case Size: |
|
|
|
|
if ( item.size() == 0 ) |
|
|
|
|
return i18nc( "@label No size available", "-" ); |
|
|
|
|
else |
|
|
|
|
return KGlobal::locale()->formatByteSize( item.size() ); |
|
|
|
|
case SizeNotLocalized: |
|
|
|
|
return item.size(); |
|
|
|
|
case DateNotTranslated: |
|
|
|
|
return msg->date()->dateTime().dateTime(); |
|
|
|
|
default: |
|
|
|
|
if ( !index.isValid() ) |
|
|
|
|
return QVariant(); |
|
|
|
|
if ( index.row() >= rowCount() ) |
|
|
|
|
return QVariant(); |
|
|
|
|
|
|
|
|
|
if ( !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") ) ) { |
|
|
|
|
if ( role == Qt::DisplayRole ) |
|
|
|
|
return i18nc( "@label", "This model can only handle email folders. The current collection holds mimetypes: %1", |
|
|
|
|
collection().contentMimeTypes().join( QLatin1String(",") ) ); |
|
|
|
|
else |
|
|
|
|
return QVariant(); |
|
|
|
|
} |
|
|
|
|
} else if ( role == Qt::EditRole ) { |
|
|
|
|
switch ( index.column() ) { |
|
|
|
|
case Collection: |
|
|
|
|
if ( item.storageCollectionId() >= 0 ) { |
|
|
|
|
return MailCommon::Util::fullCollectionPath( Akonadi::Collection( item.storageCollectionId() ) ); |
|
|
|
|
} |
|
|
|
|
return MailCommon::Util::fullCollectionPath(item.parentCollection()); |
|
|
|
|
case Subject: |
|
|
|
|
return msg->subject()->asUnicodeString(); |
|
|
|
|
case Sender: |
|
|
|
|
return msg->from()->asUnicodeString(); |
|
|
|
|
case Receiver: |
|
|
|
|
return msg->to()->asUnicodeString(); |
|
|
|
|
case Date: |
|
|
|
|
return msg->date()->dateTime().dateTime(); |
|
|
|
|
case SizeNotLocalized: |
|
|
|
|
case Size: |
|
|
|
|
return item.size(); |
|
|
|
|
case DateNotTranslated: |
|
|
|
|
return msg->date()->dateTime().dateTime(); |
|
|
|
|
default: |
|
|
|
|
|
|
|
|
|
Akonadi::Item item = itemForIndex( index ); |
|
|
|
|
if ( !item.hasPayload<MessagePtr>() ) |
|
|
|
|
return QVariant(); |
|
|
|
|
MessagePtr msg = item.payload<MessagePtr>(); |
|
|
|
|
if ( role == Qt::DisplayRole ) { |
|
|
|
|
switch ( index.column() ) { |
|
|
|
|
case Collection: |
|
|
|
|
if ( item.storageCollectionId() >= 0 ) { |
|
|
|
|
return MailCommon::Util::fullCollectionPath( Akonadi::Collection( item.storageCollectionId() ) ); |
|
|
|
|
} |
|
|
|
|
return MailCommon::Util::fullCollectionPath(item.parentCollection()); |
|
|
|
|
case Subject: |
|
|
|
|
return msg->subject()->asUnicodeString(); |
|
|
|
|
case Sender: |
|
|
|
|
return msg->from()->asUnicodeString(); |
|
|
|
|
case Receiver: |
|
|
|
|
return msg->to()->asUnicodeString(); |
|
|
|
|
case Date: |
|
|
|
|
return KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate ); |
|
|
|
|
case Size: |
|
|
|
|
if ( item.size() == 0 ) |
|
|
|
|
return i18nc( "@label No size available", "-" ); |
|
|
|
|
else |
|
|
|
|
return KGlobal::locale()->formatByteSize( item.size() ); |
|
|
|
|
case SizeNotLocalized: |
|
|
|
|
return item.size(); |
|
|
|
|
case DateNotTranslated: |
|
|
|
|
return msg->date()->dateTime().dateTime(); |
|
|
|
|
default: |
|
|
|
|
return QVariant(); |
|
|
|
|
} |
|
|
|
|
} else if ( role == Qt::EditRole ) { |
|
|
|
|
switch ( index.column() ) { |
|
|
|
|
case Collection: |
|
|
|
|
if ( item.storageCollectionId() >= 0 ) { |
|
|
|
|
return MailCommon::Util::fullCollectionPath( Akonadi::Collection( item.storageCollectionId() ) ); |
|
|
|
|
} |
|
|
|
|
return MailCommon::Util::fullCollectionPath(item.parentCollection()); |
|
|
|
|
case Subject: |
|
|
|
|
return msg->subject()->asUnicodeString(); |
|
|
|
|
case Sender: |
|
|
|
|
return msg->from()->asUnicodeString(); |
|
|
|
|
case Receiver: |
|
|
|
|
return msg->to()->asUnicodeString(); |
|
|
|
|
case Date: |
|
|
|
|
return msg->date()->dateTime().dateTime(); |
|
|
|
|
case SizeNotLocalized: |
|
|
|
|
case Size: |
|
|
|
|
return item.size(); |
|
|
|
|
case DateNotTranslated: |
|
|
|
|
return msg->date()->dateTime().dateTime(); |
|
|
|
|
default: |
|
|
|
|
return QVariant(); |
|
|
|
|
} |
|
|
|
|
} else if( role == Qt::ToolTipRole ) { |
|
|
|
|
return toolTip( item ); |
|
|
|
|
} |
|
|
|
|
} else if( role == Qt::ToolTipRole ) { |
|
|
|
|
return toolTip( item ); |
|
|
|
|
} |
|
|
|
|
return ItemModel::data( index, role ); |
|
|
|
|
return ItemModel::data( index, role ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -225,20 +225,20 @@ QVariant KMSearchMessageModel::data( const QModelIndex & index, int role ) const |
|
|
|
|
QVariant KMSearchMessageModel::headerData( int section, Qt::Orientation orientation, int role ) const |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
if ( collection().isValid() |
|
|
|
|
&& !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") ) |
|
|
|
|
&& collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) ) |
|
|
|
|
return QVariant(); |
|
|
|
|
|
|
|
|
|
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) { |
|
|
|
|
switch ( section ) { |
|
|
|
|
case Collection: |
|
|
|
|
return i18nc( "@title:column, folder (e.g. email)", "Folder" ); |
|
|
|
|
default: |
|
|
|
|
return Akonadi::MessageModel::headerData( ( section-1 ), orientation, role ); |
|
|
|
|
if ( collection().isValid() |
|
|
|
|
&& !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") ) |
|
|
|
|
&& collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) ) |
|
|
|
|
return QVariant(); |
|
|
|
|
|
|
|
|
|
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) { |
|
|
|
|
switch ( section ) { |
|
|
|
|
case Collection: |
|
|
|
|
return i18nc( "@title:column, folder (e.g. email)", "Folder" ); |
|
|
|
|
default: |
|
|
|
|
return Akonadi::MessageModel::headerData( ( section-1 ), orientation, role ); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return Akonadi::MessageModel::headerData( ( section-1 ), orientation, role ); |
|
|
|
|
return Akonadi::MessageModel::headerData( ( section-1 ), orientation, role ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#include "kmsearchmessagemodel.moc" |
|
|
|
|
|