From 28f9db58a544bec34a47a6a273162bf1f7739724 Mon Sep 17 00:00:00 2001 From: Andras Mantia Date: Wed, 22 Sep 2010 18:14:02 +0000 Subject: [PATCH] Reorganization: reduce dependency of folder* classes on the km* classes, so they could be shared later with mobile. svn path=/trunk/KDE/kdepim/kmail/; revision=1178322 --- foldercollectionmonitor.cpp | 6 ++-- foldercollectionmonitor.h | 2 +- foldershortcutactionmanager.cpp | 52 ++++++++++++++++++++++++++------- foldershortcutactionmanager.h | 39 +++++++++++++++++++++---- kmcommands.cpp | 23 --------------- kmcommands.h | 21 ------------- kmkernel.cpp | 8 ++--- kmmainwidget.cpp | 6 ++-- kmmainwidget.h | 3 +- searchwindow.cpp | 2 +- 10 files changed, 90 insertions(+), 72 deletions(-) diff --git a/foldercollectionmonitor.cpp b/foldercollectionmonitor.cpp index 18fb2caf2..b844f6aa2 100644 --- a/foldercollectionmonitor.cpp +++ b/foldercollectionmonitor.cpp @@ -17,7 +17,6 @@ */ #include "foldercollectionmonitor.h" -#include "kmkernel.h" #include "util.h" #include "foldercollection.h" @@ -60,9 +59,10 @@ Akonadi::ChangeRecorder *FolderCollectionMonitor::monitor() const return mMonitor; } -void FolderCollectionMonitor::expireAllFolders(bool immediate ) +void FolderCollectionMonitor::expireAllFolders(bool immediate, QAbstractItemModel* collectionModel ) { - expireAllCollection( KMKernel::self()->entityTreeModel(), immediate ); + if ( collectionModel ) + expireAllCollection( collectionModel, immediate ); } void FolderCollectionMonitor::expireAllCollection( const QAbstractItemModel *model, bool immediate, const QModelIndex& parentIndex ) diff --git a/foldercollectionmonitor.h b/foldercollectionmonitor.h index 414bfd8a4..161caa467 100644 --- a/foldercollectionmonitor.h +++ b/foldercollectionmonitor.h @@ -39,7 +39,7 @@ public: ~FolderCollectionMonitor(); Akonadi::ChangeRecorder * monitor() const; - void expireAllFolders(bool immediate ); + void expireAllFolders( bool immediate, QAbstractItemModel* collectionModel ); void expunge( const Akonadi::Collection& ); private slots: void slotExpungeJob( KJob *job ); diff --git a/foldershortcutactionmanager.cpp b/foldershortcutactionmanager.cpp index c40b2dd1c..3dab66fb2 100644 --- a/foldershortcutactionmanager.cpp +++ b/foldershortcutactionmanager.cpp @@ -19,25 +19,57 @@ #include "foldershortcutactionmanager.h" #include "foldercollection.h" -#include "kmcommands.h" -#include "kmkernel.h" -#include "kmmainwidget.h" #include #include -#include #include +#include + +#include #include #include +#include using namespace KMail; -FolderShortcutActionManager::FolderShortcutActionManager( KMMainWidget *parent, - KActionCollection *actionCollection ) + +FolderShortcutCommand::FolderShortcutCommand( QWidget *mainwidget, + const Akonadi::Collection&col ) + : QObject( mainwidget ), mMainWidget( mainwidget ), mCollectionFolder( col ), mAction( 0 ) +{ + connect( this, SIGNAL(selectCollectionFolder(Akonadi::Collection)), mMainWidget, SLOT(slotSelectCollectionFolder(Akonadi::Collection))); +} + + +FolderShortcutCommand::~FolderShortcutCommand() +{ + if ( mAction && mAction->parentWidget() ) + mAction->parentWidget()->removeAction( mAction ); + delete mAction; +} + +void FolderShortcutCommand::start() +{ + emit selectCollectionFolder( mCollectionFolder ); +} + +void FolderShortcutCommand::setAction( QAction* action ) +{ + mAction = action; +} + + +FolderShortcutActionManager::FolderShortcutActionManager( QWidget *parent, + KActionCollection *actionCollection, + Akonadi::EntityMimeTypeFilterModel *collectionModel, + Akonadi::ChangeRecorder *folderCollectionMonitor + ) : QObject( parent ), mActionCollection( actionCollection ), - mParent( parent ) + mParent( parent ), + mCollectionModel( collectionModel ), + mFolderCollectionMonitor( folderCollectionMonitor ) { } @@ -46,10 +78,10 @@ void FolderShortcutActionManager::createActions() // When this function is called, the ETM has not finished loading yet. Therefore, when new // rows are inserted in the ETM, see if we have new collections that we can assign shortcuts // to. - const QAbstractItemModel *model = KMKernel::self()->collectionModel(); + const QAbstractItemModel *model = mCollectionModel; connect( model, SIGNAL( rowsInserted( const QModelIndex &, int, int ) ), this, SLOT( slotRowsInserted( const QModelIndex &, int, int ) ), Qt::UniqueConnection ); - connect( KMKernel::self()->monitor(), SIGNAL( collectionRemoved( const Akonadi::Collection & ) ), + connect( mFolderCollectionMonitor, SIGNAL( collectionRemoved( const Akonadi::Collection & ) ), this, SLOT( slotCollectionRemoved( const Akonadi::Collection& ) ), Qt::UniqueConnection ); if ( model->rowCount() > 0 ) @@ -63,7 +95,7 @@ void FolderShortcutActionManager::slotRowsInserted( const QModelIndex &parent, i void FolderShortcutActionManager::updateShortcutsForIndex( const QModelIndex &parent, int start, int end ) { - QAbstractItemModel *model = KMKernel::self()->collectionModel(); + QAbstractItemModel *model = mCollectionModel; for ( int i = start; i <= end; i++ ) { const QModelIndex child = model->index( i, 0, parent ); Akonadi::Collection collection = diff --git a/foldershortcutactionmanager.h b/foldershortcutactionmanager.h index 96fdcc22c..039aa25fa 100644 --- a/foldershortcutactionmanager.h +++ b/foldershortcutactionmanager.h @@ -22,28 +22,54 @@ #include "kmail_export.h" #include +#include #include #include #include namespace Akonadi { - class Collection; + class ChangeRecorder; + class EntityMimeTypeFilterModel; } -class FolderShortcutCommand; +class QAction; + class KActionCollection; -class KMMainWidget; namespace KMail { + class FolderShortcutCommand : public QObject + { + Q_OBJECT + + public: + FolderShortcutCommand( QWidget* mainwidget, const Akonadi::Collection & col ); + ~FolderShortcutCommand(); + + public slots: + void start(); + /** Assign a KAction to the command which is used to trigger it. This + * action will be deleted along with the command, so you don't need to + * keep track of it separately. */ + void setAction( QAction* ); + + signals: + void selectCollectionFolder( const Akonadi::Collection & col ); + + private: + QWidget *mMainWidget; + Akonadi::Collection mCollectionFolder; + QAction *mAction; + }; + class KMAIL_EXPORT FolderShortcutActionManager : public QObject { Q_OBJECT public: - FolderShortcutActionManager( KMMainWidget *parent, KActionCollection *actionCollection ); + FolderShortcutActionManager( QWidget *parent, KActionCollection *actionCollection, Akonadi::EntityMimeTypeFilterModel *collectionModel, Akonadi::ChangeRecorder *folderCollectionMonitor ); void createActions(); public slots: @@ -68,8 +94,11 @@ namespace KMail { void updateShortcutsForIndex( const QModelIndex &parent, int start, int end ); QMap< Akonadi::Entity::Id, FolderShortcutCommand* > mFolderShortcutCommands; KActionCollection *mActionCollection; - KMMainWidget *mParent; + QWidget *mParent; + Akonadi::EntityMimeTypeFilterModel *mCollectionModel; + Akonadi::ChangeRecorder *mFolderCollectionMonitor; }; + } #endif diff --git a/kmcommands.cpp b/kmcommands.cpp index 56e9cb1e9..9e701b2e3 100644 --- a/kmcommands.cpp +++ b/kmcommands.cpp @@ -1671,29 +1671,6 @@ void KMMetaFilterActionCommand::start() filterCommand->start(); } -FolderShortcutCommand::FolderShortcutCommand( KMMainWidget *mainwidget, - const Akonadi::Collection&col ) - : QObject( mainwidget ), mMainWidget( mainwidget ), mCollectionFolder( col ), mAction( 0 ) -{ -} - - -FolderShortcutCommand::~FolderShortcutCommand() -{ - if ( mAction && mAction->parentWidget() ) - mAction->parentWidget()->removeAction( mAction ); - delete mAction; -} - -void FolderShortcutCommand::start() -{ - mMainWidget->selectCollectionFolder( mCollectionFolder ); -} - -void FolderShortcutCommand::setAction( QAction* action ) -{ - mAction = action; -} KMMailingListFilterCommand::KMMailingListFilterCommand( QWidget *parent, const Akonadi::Item &msg ) diff --git a/kmcommands.h b/kmcommands.h index 25a393f9a..1da7a5213 100644 --- a/kmcommands.h +++ b/kmcommands.h @@ -593,27 +593,6 @@ private: KMMainWidget *mMainWidget; }; -class KMAIL_EXPORT FolderShortcutCommand : public QObject -{ - Q_OBJECT - -public: - FolderShortcutCommand( KMMainWidget* mainwidget, const Akonadi::Collection & col ); - ~FolderShortcutCommand(); - -public slots: - void start(); - /** Assign a KActio to the command which is used to trigger it. This - * action will be deleted along with the command, so you don't need to - * keep track of it separately. */ - void setAction( QAction* ); - -private: - KMMainWidget *mMainWidget; - Akonadi::Collection mCollectionFolder; - QAction *mAction; -}; - class KMAIL_EXPORT KMMailingListFilterCommand : public KMCommand { diff --git a/kmkernel.cpp b/kmkernel.cpp index 629f99816..eab9eeb7d 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -1641,7 +1641,7 @@ void KMKernel::selectCollectionFromId( const Akonadi::Collection::Id id) Akonadi::Collection colFolder = collectionFromId( id ); if( colFolder.isValid() ) - widget->selectCollectionFolder( colFolder ); + widget->slotSelectCollectionFolder( colFolder ); } void KMKernel::selectFolder( const QString &folder ) @@ -1654,7 +1654,7 @@ void KMKernel::selectFolder( const QString &folder ) Akonadi::Collection colFolder = collectionFromId( folder ); if( colFolder.isValid() ) - widget->selectCollectionFolder( colFolder ); + widget->slotSelectCollectionFolder( colFolder ); } KMMainWidget *KMKernel::getKMMainWidget() @@ -1677,7 +1677,7 @@ void KMKernel::slotRunBackgroundTasks() // called regularly by timer // a stable kmail release goes out with a nasty bug in CompactionJob... KConfigGroup generalGroup( config(), "General" ); if ( generalGroup.readEntry( "auto-expiring", true ) ) { - mFolderCollectionMonitor->expireAllFolders( false /*scheduled, not immediate*/ ); + mFolderCollectionMonitor->expireAllFolders( false /*scheduled, not immediate*/, entityTreeModel() ); } #ifdef DEBUG_SCHEDULER // for debugging, see jobscheduler.h @@ -1711,7 +1711,7 @@ Akonadi::Collection::List KMKernel::allFolders() const void KMKernel::expireAllFoldersNow() // called by the GUI { - mFolderCollectionMonitor->expireAllFolders( true /*immediate*/ ); + mFolderCollectionMonitor->expireAllFolders( true /*immediate*/, entityTreeModel() ); } diff --git a/kmmainwidget.cpp b/kmmainwidget.cpp index 86d3e53fe..31b94b8ba 100644 --- a/kmmainwidget.cpp +++ b/kmmainwidget.cpp @@ -2171,12 +2171,12 @@ void KMMainWidget::slotJumpToFolder() if ( selectFromAllFoldersDialog()->exec() && selectFromAllFoldersDialog() ) { Akonadi::Collection collection = selectFromAllFoldersDialog()->selectedCollection(); if ( collection.isValid() ) { - selectCollectionFolder( collection ); + slotSelectCollectionFolder( collection ); } } } -void KMMainWidget::selectCollectionFolder( const Akonadi::Collection & col ) +void KMMainWidget::slotSelectCollectionFolder( const Akonadi::Collection & col ) { if ( mFolderTreeWidget ) { mFolderTreeWidget->selectCollectionFolder( col ); @@ -3439,7 +3439,7 @@ void KMMainWidget::setupActions() updateFolderMenu(); mTagActionManager = new KMail::TagActionManager( this, actionCollection(), mMsgActions, mGUIClient ); - mFolderShortcutActionManager = new KMail::FolderShortcutActionManager( this, actionCollection() ); + mFolderShortcutActionManager = new KMail::FolderShortcutActionManager( this, actionCollection(), KMKernel::self()->collectionModel(), KMKernel::self()->monitor() ); } diff --git a/kmmainwidget.h b/kmmainwidget.h index 77af5ba50..b71991f7e 100644 --- a/kmmainwidget.h +++ b/kmmainwidget.h @@ -171,7 +171,6 @@ class KMAIL_EXPORT KMMainWidget : public QWidget QLabel* vacationScriptIndicator() const; void updateVacationScriptStatus() { updateVacationScriptStatus( mVacationIndicatorActive ); } - void selectCollectionFolder( const Akonadi::Collection & col ); FolderTreeView *folderTreeView() const { return mFolderTreeWidget->folderTreeView(); @@ -280,6 +279,8 @@ class KMAIL_EXPORT KMMainWidget : public QWidget void slotCollectionProperties(); + void slotSelectCollectionFolder( const Akonadi::Collection & col ); + signals: void messagesTransfered( bool ); void captionChangeRequest( const QString &caption ); diff --git a/searchwindow.cpp b/searchwindow.cpp index 4376a00f4..caabf23dc 100644 --- a/searchwindow.cpp +++ b/searchwindow.cpp @@ -656,7 +656,7 @@ void SearchWindow::openSearchFolder() { Q_ASSERT( mFolder.isValid() ); renameSearchFolder(); - mKMMainWidget->selectCollectionFolder( mFolder ); + mKMMainWidget->slotSelectCollectionFolder( mFolder ); slotClose(); }