[Kde-pim] Fwd: [kdepim] kmail: Add new model to show folder where message was found, now that we can't specify in which folder search.
laurent Montel
montel at kde.org
Wed Aug 3 10:22:35 BST 2011
Hi,
i want to backport to 4.7 branch
It's necessary to add a new string for show folder where we found mail
for the moment we can't know it.
It's very important and I think that we can't wait kde-4.8
Can I backport it ?
Thanks
regards
---------- Message transmit ----------
Sujet : [kdepim] kmail: Add new model to show folder where message was found,
now that we can't specify in which folder search.
Date : Wednesday 3 August 2011, 11:10:54
De : Montel Laurent <montel at kde.org>
À : kde-commits at kde.org
Git commit dbe8076be5ebda4f4fd1866ed54f243d2912839b by Montel Laurent.
Committed on 03/08/2011 at 11:09.
Pushed by mlaurent into branch 'master'.
Add new model to show folder where message was found, now that we can't
specify in which folder search.
M +25 -13 kmail/searchwindow.cpp
A +56 -0 kmail/kmsearchmessagemodel.h [License: GPL (v2) (+Qt
exception)]
M +8 -0 kmail/kmail.kcfg.cmake
A +147 -0 kmail/kmsearchmessagemodel.cpp [License: GPL (v2) (+Qt
exception)]
M +2 -1 kmail/searchwindow.h
M +1 -0 kmail/CMakeLists.txt
http://commits.kde.org/kdepim/dbe8076be5ebda4f4fd1866ed54f243d2912839b
diff --git a/kmail/CMakeLists.txt b/kmail/CMakeLists.txt
index 33f9c13..98ccb17 100644
--- a/kmail/CMakeLists.txt
+++ b/kmail/CMakeLists.txt
@@ -110,6 +110,7 @@ if (NOT WINCE AND KDEPIM_BUILD_DESKTOP)
addressvalidationjob.cpp
identitypage.cpp
newidentitydialog.cpp
+ kmsearchmessagemodel.cpp
)
soprano_add_ontology(kmailprivate_LIB_SRCS
diff --git a/kmail/kmail.kcfg.cmake b/kmail/kmail.kcfg.cmake
index 0d1f504..90c116b 100644
--- a/kmail/kmail.kcfg.cmake
+++ b/kmail/kmail.kcfg.cmake
@@ -481,6 +481,10 @@
<!-- Search Dialog settings -->
<group name="SearchDialog">
+ <entry name="CollectionWidth" type="Int">
+ <label>Specifies the width of the collection field in the Search Window
dialog (for internal use only)</label>
+ <default>150</default>
+ </entry>
<entry name="SubjectWidth" type="Int">
<label>Specifies the width of the subject field in the Search Window
dialog (for internal use only)</label>
<default>150</default>
@@ -489,6 +493,10 @@
<label>Specifies the width of the sender field in the Search Window dialog
(for internal use only)</label>
<default>120</default>
</entry>
+ <entry name="ReceiverWidth" type="Int">
+ <label>Specifies the width of the receiver field in the Search Window
dialog (for internal use only)</label>
+ <default>120</default>
+ </entry>
<entry name="DateWidth" type="Int">
<label>Specifies the width of the date field in the Search Window dialog
(for internal use only)</label>
<default>120</default>
diff --git a/kmail/kmsearchmessagemodel.cpp b/kmail/kmsearchmessagemodel.cpp
new file mode 100644
index 0000000..3cb23ae
--- /dev/null
+++ b/kmail/kmsearchmessagemodel.cpp
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2011 Montel Laurent <montel at 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; version 2 of the License
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of this program with any edition of
+ * the Qt library by Trolltech AS, Norway (or with modified versions
+ * of Qt that use the same license as Qt), and distribute linked
+ * combinations including the two. You must obey the GNU General
+ * Public License in all respects for all of the code used other than
+ * Qt. If you modify this file, you may extend this exception to
+ * your version of the file, but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from
+ * your version.
+ */
+#include "kmsearchmessagemodel.h"
+#include "mailcommon/mailutil.h"
+#include <akonadi/itemfetchscope.h>
+#include <akonadi/monitor.h>
+#include <akonadi/session.h>
+
+#include <akonadi/kmime/messageparts.h>
+#include <kmime/kmime_message.h>
+#include <boost/shared_ptr.hpp>
+typedef boost::shared_ptr<KMime::Message> MessagePtr;
+
+#include <kdebug.h>
+#include <kglobal.h>
+#include <klocale.h>
+
+KMSearchMessageModel::KMSearchMessageModel( QObject *parent ) :
+ Akonadi::MessageModel( parent )
+{
+ fetchScope().fetchPayloadPart( Akonadi::MessagePart::Envelope );
+ fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::All );
+}
+
+KMSearchMessageModel::~KMSearchMessageModel( )
+{
+}
+
+
+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 ( !parent.isValid() )
+ return 6; // keep in sync with the column type enum
+
+ 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:
+ 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() );
+ default:
+ return QVariant();
+ }
+ } else if ( role == Qt::EditRole ) {
+ switch ( index.column() ) {
+ case Collection:
+ 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 Size:
+ return item.size();
+ default:
+ return QVariant();
+ }
+ }
+ return ItemModel::data( index, role );
+}
+
+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 );
+ }
+ }
+ return Akonadi::MessageModel::headerData( ( section-1 ), orientation, role
);
+}
+
+#include "kmsearchmessagemodel.moc"
diff --git a/kmail/kmsearchmessagemodel.h b/kmail/kmsearchmessagemodel.h
new file mode 100644
index 0000000..c7fc1b5
--- /dev/null
+++ b/kmail/kmsearchmessagemodel.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011 Montel Laurent <montel at 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; version 2 of the License
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of this program with any edition of
+ * the Qt library by Trolltech AS, Norway (or with modified versions
+ * of Qt that use the same license as Qt), and distribute linked
+ * combinations including the two. You must obey the GNU General
+ * Public License in all respects for all of the code used other than
+ * Qt. If you modify this file, you may extend this exception to
+ * your version of the file, but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from
+ * your version.
+ */
+#ifndef KMSEARCHMESSAGEMODEL_H
+#define KMSEARCHMESSAGEMODEL_H
+
+#include <akonadi/kmime/messagemodel.h>
+
+class KMSearchMessageModel : public Akonadi::MessageModel
+{
+ Q_OBJECT
+
+ public:
+ enum Column {
+ Collection,
+ Subject,
+ Sender,
+ Receiver,
+ Date,
+ Size
+ };
+ explicit KMSearchMessageModel( QObject* parent = 0 );
+ virtual ~KMSearchMessageModel();
+
+ virtual int columnCount( const QModelIndex & parent = QModelIndex() )
const;
+ virtual QVariant data( const QModelIndex & index, int role =
Qt::DisplayRole ) const;
+
+ virtual QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const;
+
+};
+
+#endif
diff --git a/kmail/searchwindow.cpp b/kmail/searchwindow.cpp
index 7dd004b..b31d4d2 100644
--- a/kmail/searchwindow.cpp
+++ b/kmail/searchwindow.cpp
@@ -30,6 +30,7 @@
#include "regexplineedit.h"
#include "searchdescriptionattribute.h"
#include "foldertreeview.h"
+#include "kmsearchmessagemodel.h"
#include <Akonadi/AttributeFactory>
#include <Akonadi/CollectionModifyJob>
#include <Akonadi/CollectionStatisticsJob>
@@ -39,7 +40,7 @@
#include <akonadi/persistentsearchattribute.h>
#include <Akonadi/SearchCreateJob>
#include <akonadi/standardactionmanager.h>
-
+#include <Akonadi/EntityMimeTypeFilterModel>
#include <KActionMenu>
#include <KConfigGroup>
#include <KDebug>
@@ -226,9 +227,10 @@ SearchWindow::SearchWindow( KMMainWidget *widget, const
Akonadi::Collection &col
mFolder = collection;
mSearchFolderEdt->setText( collection.name() );
Q_ASSERT ( !mResultModel );
- mResultModel = new Akonadi::MessageModel( this );
+ mResultModel = new KMSearchMessageModel( this );
mResultModel->setCollection( mFolder );
mLbxMatches->setModel( mResultModel );
+
mAkonadiStandardAction = new Akonadi::StandardMailActionManager(
actionCollection(), this );
mAkonadiStandardAction->setItemSelectionModel( mLbxMatches-
>selectionModel() );
mAkonadiStandardAction->setCollectionSelectionModel( mKMMainWidget-
>folderTreeView()->selectionModel() );
@@ -361,16 +363,22 @@ SearchWindow::~SearchWindow()
{
if ( mResultModel ) {
if ( mLbxMatches->columnWidth( 0 ) > 0 ) {
- GlobalSettings::self()->setSubjectWidth( mLbxMatches->columnWidth( 0 )
);
+ GlobalSettings::self()->setCollectionWidth( mLbxMatches->columnWidth( 0
) );
}
if ( mLbxMatches->columnWidth( 1 ) > 0 ) {
- GlobalSettings::self()->setSenderWidth( mLbxMatches->columnWidth( 1 )
);
+ GlobalSettings::self()->setSubjectWidth( mLbxMatches->columnWidth( 1 )
);
}
if ( mLbxMatches->columnWidth( 2 ) > 0 ) {
- GlobalSettings::self()->setDateWidth( mLbxMatches->columnWidth( 2 ) );
+ GlobalSettings::self()->setSenderWidth( mLbxMatches->columnWidth( 2 )
);
}
if ( mLbxMatches->columnWidth( 3 ) > 0 ) {
- GlobalSettings::self()->setFolderWidth( mLbxMatches->columnWidth( 3 )
);
+ GlobalSettings::self()->setReceiverWidth( mLbxMatches->columnWidth( 3 )
);
+ }
+ if ( mLbxMatches->columnWidth( 4 ) > 0 ) {
+ GlobalSettings::self()->setDateWidth( mLbxMatches->columnWidth( 4 ) );
+ }
+ if ( mLbxMatches->columnWidth( 5 ) > 0 ) {
+ GlobalSettings::self()->setFolderWidth( mLbxMatches->columnWidth( 5 )
);
}
GlobalSettings::self()->setSearchWidgetWidth( width() );
GlobalSettings::self()->setSearchWidgetHeight( height() );
@@ -504,7 +512,7 @@ void SearchWindow::slotSearch()
const QString queryLanguage = "SPARQL";
#endif
- kDebug() << query;
+ qDebug() << query;
if ( !mFolder.isValid() ) {
// FIXME if another app created a virtual 'Last Search' folder without
// out custom attributes it will result in problems
@@ -561,15 +569,19 @@ void SearchWindow::searchDone( KJob* job )
mSearchJob = 0;
if ( !mResultModel ) {
- mResultModel = new Akonadi::MessageModel( this );
+ mResultModel = new KMSearchMessageModel( this );
mResultModel->setCollection( mFolder );
mLbxMatches->setModel( mResultModel );
- mLbxMatches->setColumnWidth( 0, GlobalSettings::self()-
>subjectWidth() );
- mLbxMatches->setColumnWidth( 1, GlobalSettings::self()->senderWidth()
);
- mLbxMatches->setColumnWidth( 2, GlobalSettings::self()->dateWidth()
);
- mLbxMatches->setColumnWidth( 3, GlobalSettings::self()->folderWidth()
);
- mLbxMatches->setColumnWidth( 4, 0 );
+ mLbxMatches->setColumnWidth( 0, GlobalSettings::self()-
>collectionWidth() );
+ mLbxMatches->setColumnWidth( 1, GlobalSettings::self()-
>subjectWidth() );
+ mLbxMatches->setColumnWidth( 2, GlobalSettings::self()->senderWidth()
);
+ mLbxMatches->setColumnWidth( 3, GlobalSettings::self()-
>receiverWidth() );
+ mLbxMatches->setColumnWidth( 4, GlobalSettings::self()->dateWidth()
);
+ mLbxMatches->setColumnWidth( 5, GlobalSettings::self()->folderWidth()
);
+ mLbxMatches->setColumnWidth( 6, 0 );
+
+
mLbxMatches->header()->setSortIndicator( 2, Qt::DescendingOrder );
mLbxMatches->header()->setStretchLastSection( false );
mLbxMatches->header()->setResizeMode( 3, QHeaderView::Stretch );
diff --git a/kmail/searchwindow.h b/kmail/searchwindow.h
index 83f21c7..b1e5636 100644
--- a/kmail/searchwindow.h
+++ b/kmail/searchwindow.h
@@ -41,6 +41,7 @@ class KJob;
class KLineEdit;
class KMMainWidget;
class KStatusBar;
+class KMSearchMessageModel;
namespace Akonadi {
class EntityTreeView;
@@ -172,7 +173,7 @@ class SearchWindow: public KDialog, virtual public
KXMLGUIClient
QRadioButton *mChkbxSpecificFolders;
MailCommon::FolderRequester *mCbxFolders;
QCheckBox *mChkSubFolders;
- Akonadi::ItemModel *mResultModel;
+ KMSearchMessageModel *mResultModel;
Akonadi::EntityTreeView *mLbxMatches;
QLabel *mSearchFolderLbl;
KLineEdit *mSearchFolderEdt;
-----------------------------------------
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/
More information about the kde-pim
mailing list