[Kde-pim] [kdepim] /: Make mailfilter's dummykernel less dummy, and also provide a Settings interface to it.

Andras Mantia amantia at kde.org
Sat Dec 3 22:19:49 GMT 2011


Git commit 9a714df01c97f9922cdd0248756b3a052a055893 by Andras Mantia.
Committed on 03/12/2011 at 23:17.
Pushed by amantia into branch 'master'.

Make mailfilter's dummykernel less dummy, and also provide a Settings interface to it.
This properly fixes 286762 (the previous fix just postponed the crash to a later stage).
Remove MailCommon::Kernel::settingsAreRegistered, as it doesn't make sense to have it (SettingsIf is mandatory).

BUG: 286762
CCMAIL: kde-pim at kde.org

M  +3    -6    mailcommon/foldertreewidget.cpp
M  +0    -4    mailcommon/mailkernel.h
M  +58   -4    mailfilteragent/dummykernel.cpp
M  +21   -1    mailfilteragent/dummykernel.h
M  +1    -0    mailfilteragent/mailfilteragent.cpp

http://commits.kde.org/kdepim/9a714df01c97f9922cdd0248756b3a052a055893

diff --git a/mailcommon/foldertreewidget.cpp b/mailcommon/foldertreewidget.cpp
index b26cf21..30f1bd4 100644
--- a/mailcommon/foldertreewidget.cpp
+++ b/mailcommon/foldertreewidget.cpp
@@ -281,9 +281,8 @@ void FolderTreeWidget::readConfig()
   const int checkedFolderToolTipsPolicy = mainFolderView.readEntry( "ToolTipDisplayPolicy", 0 );
   changeToolTipsPolicyConfig( ( ToolTipDisplayPolicy )checkedFolderToolTipsPolicy );
 
-  if ( MailCommon::Kernel::self()->settingsAreRegistered() ) {
-    d->folderTreeView->setDropActionMenuEnabled( SettingsIf->showPopupAfterDnD() );
-  }
+  d->folderTreeView->setDropActionMenuEnabled( SettingsIf->showPopupAfterDnD() );
+
   readQuotaConfig();
 }
 
@@ -324,9 +323,7 @@ void FolderTreeWidget::readQuotaConfig()
   if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
     KConfigGroup readerConfig( KernelIf->config(), "Reader" );
     quotaColor = readerConfig.readEntry( "CloseToQuotaColor", quotaColor  );
-    if ( MailCommon::Kernel::self()->settingsAreRegistered() ) {
-      threshold = SettingsIf->closeToQuotaThreshold();
-    }
+    threshold = SettingsIf->closeToQuotaThreshold();
   }
   quotaWarningParameters( quotaColor, threshold );
 }
diff --git a/mailcommon/mailkernel.h b/mailcommon/mailkernel.h
index a9043b7..b89c7c9 100644
--- a/mailcommon/mailkernel.h
+++ b/mailcommon/mailkernel.h
@@ -73,10 +73,6 @@ public:
     mSettingsIf = settingsIf;
   }
 
-  bool settingsAreRegistered() const {
-    return mSettingsIf != 0;
-  }
-
   ISettings *settingsIf() const {
     Q_ASSERT( mSettingsIf );
     return mSettingsIf;
diff --git a/mailfilteragent/dummykernel.cpp b/mailfilteragent/dummykernel.cpp
index 8ad1f82..cc74aba 100644
--- a/mailfilteragent/dummykernel.cpp
+++ b/mailfilteragent/dummykernel.cpp
@@ -3,12 +3,31 @@
 #include <kglobal.h>
 #include <kpimidentities/identitymanager.h>
 #include <messagecomposer/akonadisender.h>
+#include <mailcommon/foldercollectionmonitor.h>
+#include <akonadi/session.h>
+#include <akonadi/entitytreemodel.h>
+#include <akonadi/entitymimetypefiltermodel.h>
+#include <akonadi/changerecorder.h>
 
 DummyKernel::DummyKernel( QObject *parent )
   : QObject( parent )
 {
   mMessageSender = new AkonadiSender( this );
   mIdentityManager = new KPIMIdentities::IdentityManager( false, this );
+  mFolderCollectionMonitor = new MailCommon::FolderCollectionMonitor( this );
+
+  Akonadi::Session *session = new Akonadi::Session( "MailFilter Kernel ETM", this );
+  folderCollectionMonitor()->setSession( session );
+  mEntityTreeModel = new Akonadi::EntityTreeModel( folderCollectionMonitor(), this );
+  mEntityTreeModel->setIncludeUnsubscribed( false );
+  mEntityTreeModel->setItemPopulationStrategy( Akonadi::EntityTreeModel::LazyPopulation );
+
+  mCollectionModel = new Akonadi::EntityMimeTypeFilterModel( this );
+  mCollectionModel->setSourceModel( mEntityTreeModel );
+  mCollectionModel->addMimeTypeInclusionFilter( Akonadi::Collection::mimeType() );
+  mCollectionModel->setHeaderGroup( Akonadi::EntityTreeModel::CollectionTreeHeaders );
+  mCollectionModel->setDynamicSortFilter( true );
+  mCollectionModel->setSortCaseSensitivity( Qt::CaseInsensitive );
 }
 
 KPIMIdentities::IdentityManager *DummyKernel::identityManager()
@@ -23,8 +42,7 @@ MessageSender *DummyKernel::msgSender()
 
 Akonadi::EntityMimeTypeFilterModel *DummyKernel::collectionModel() const
 {
-  Q_ASSERT( false );
-  return 0;
+  return mCollectionModel;
 }
 
 KSharedConfig::Ptr DummyKernel::config()
@@ -45,11 +63,47 @@ MailCommon::JobScheduler* DummyKernel::jobScheduler() const
 
 Akonadi::ChangeRecorder *DummyKernel::folderCollectionMonitor() const
 {
-  Q_ASSERT( false );
-  return 0;
+  return mFolderCollectionMonitor->monitor();
 }
 
 void DummyKernel::updateSystemTray()
 {
   Q_ASSERT( false );
 }
+
+bool DummyKernel::showPopupAfterDnD()
+{
+  return false;
+}
+
+qreal DummyKernel::closeToQuotaThreshold()
+{
+  return 80;
+}
+
+QStringList DummyKernel::customTemplates()
+{
+  Q_ASSERT( false );
+  return QStringList();
+}
+
+bool DummyKernel::excludeImportantMailFromExpiry()
+{
+  Q_ASSERT( false );
+  return true;
+}
+
+Akonadi::Entity::Id DummyKernel::lastSelectedFolder()
+{
+  Q_ASSERT( false );
+  return Akonadi::Entity::Id();
+}
+
+void DummyKernel::setLastSelectedFolder(const Akonadi::Entity::Id& col)
+{
+  Q_UNUSED(col);
+}
+
+
+
+
diff --git a/mailfilteragent/dummykernel.h b/mailfilteragent/dummykernel.h
index 6c4d12f..7b1df17 100644
--- a/mailfilteragent/dummykernel.h
+++ b/mailfilteragent/dummykernel.h
@@ -3,7 +3,16 @@
 
 #include <mailcommon/mailinterfaces.h>
 
-class DummyKernel : public QObject, public MailCommon::IKernel
+namespace Akonadi {
+class EntityTreeModel;
+class EntityMimeTypeFilterModel;
+}
+
+namespace MailCommon {
+class FolderCollectionMonitor;
+}
+
+class DummyKernel : public QObject, public MailCommon::IKernel, public MailCommon::ISettings
 {
   public:
     DummyKernel( QObject *parent = 0 );
@@ -18,9 +27,20 @@ class DummyKernel : public QObject, public MailCommon::IKernel
     virtual Akonadi::ChangeRecorder *folderCollectionMonitor() const;
     virtual void updateSystemTray();
 
+    virtual qreal closeToQuotaThreshold();
+    virtual bool excludeImportantMailFromExpiry();
+    virtual QStringList customTemplates();
+    virtual Akonadi::Entity::Id lastSelectedFolder();
+    virtual void setLastSelectedFolder(const Akonadi::Entity::Id& col);
+    virtual bool showPopupAfterDnD();
+    
+
   private:
     KPIMIdentities::IdentityManager *mIdentityManager;
     MessageSender *mMessageSender;
+    MailCommon::FolderCollectionMonitor *mFolderCollectionMonitor;
+    Akonadi::EntityTreeModel *mEntityTreeModel;
+    Akonadi::EntityMimeTypeFilterModel *mCollectionModel;
 };
 
 #endif
diff --git a/mailfilteragent/mailfilteragent.cpp b/mailfilteragent/mailfilteragent.cpp
index 2f2654e..ec561da 100644
--- a/mailfilteragent/mailfilteragent.cpp
+++ b/mailfilteragent/mailfilteragent.cpp
@@ -53,6 +53,7 @@ MailFilterAgent::MailFilterAgent( const QString &id )
 {
   DummyKernel *kernel = new DummyKernel( this );
   CommonKernel->registerKernelIf( kernel ); //register KernelIf early, it is used by the Filter classes
+  CommonKernel->registerSettingsIf( kernel ); //SettingsIf is used in FolderTreeWidget
 
   m_filterManager = new FilterManager( this );
 
_______________________________________________
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