Factor out folder shortcut action handing into its own class.

This is similar to the tag action manager. Less stuff in kmmainwidget
is always good.

svn path=/trunk/KDE/kdepim/kmail/; revision=1111090
wilder-work
Thomas McGuire 16 years ago
parent 8811d48b28
commit 9b9d4cb251
  1. 1
      CMakeLists.txt
  2. 6
      foldercollection.cpp
  3. 91
      foldershortcutactionmanager.cpp
  4. 71
      foldershortcutactionmanager.h
  5. 3
      kmail_part.cpp
  6. 58
      kmmainwidget.cpp
  7. 22
      kmmainwidget.h

@ -148,6 +148,7 @@ set(kmailprivate_LIB_SRCS
searchdescriptionattribute.cpp
tag.cpp
tagactionmanager.cpp
foldershortcutactionmanager.cpp
)
soprano_add_ontology(kmailprivate_LIB_SRCS

@ -31,6 +31,7 @@
#include "kmcommands.h"
#include "expirejob.h"
#include "compactionjob.h"
#include "foldershortcutactionmanager.h"
#include <QMutex>
#include <QMutexLocker>
@ -249,8 +250,9 @@ void FolderCollection::setShortcut( const KShortcut &sc, KMMainWidget *main )
{
if ( mShortcut != sc ) {
mShortcut = sc;
if( main)
main->shortcutChanged( mCollection );
if ( main) {
main->folderShortcutActionManager()->shortcutChanged( mCollection );
}
}
}

@ -0,0 +1,91 @@
/* Copyright 2010 Thomas McGuire <mcguire@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; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "foldershortcutactionmanager.h"
#include "foldercollection.h"
#include "kmcommands.h"
#include "kmkernel.h"
#include "kmmainwidget.h"
#include <Akonadi/ChangeRecorder>
#include <Akonadi/EntityDisplayAttribute>
#include <KAction>
#include <KActionCollection>
using namespace KMail;
FolderShortcutActionManager::FolderShortcutActionManager( KMMainWidget *parent,
KActionCollection *actionCollection )
: QObject( parent ),
mActionCollection( actionCollection ),
mParent( parent )
{
connect( KMKernel::self()->monitor(), SIGNAL( collectionRemoved( const Akonadi::Collection & ) ),
this, SLOT( slotCollectionRemoved( const Akonadi::Collection& ) ) );
}
void FolderShortcutActionManager::createActions()
{
QList<Akonadi::Collection> folders = kmkernel->allFoldersCollection();
for ( int i = 0 ; i < folders.size(); ++i ) {
Akonadi::Collection col = folders.at( i );
shortcutChanged( col );
}
}
void FolderShortcutActionManager::slotCollectionRemoved( const Akonadi::Collection &col )
{
delete mFolderShortcutCommands.take( col.id() );
}
void FolderShortcutActionManager::shortcutChanged( const Akonadi::Collection &col )
{
// remove the old one, no autodelete in Qt4
slotCollectionRemoved( col );
QSharedPointer<FolderCollection> folderCollection( FolderCollection::forCollection( col ) );
if ( folderCollection->shortcut().isEmpty() )
return;
FolderShortcutCommand *command = new FolderShortcutCommand( mParent, col );
mFolderShortcutCommands.insert( col.id(), command );
KIcon icon( "folder" );
if ( col.hasAttribute<Akonadi::EntityDisplayAttribute>() &&
!col.attribute<Akonadi::EntityDisplayAttribute>()->iconName().isEmpty() ) {
icon = KIcon( col.attribute<Akonadi::EntityDisplayAttribute>()->iconName() );
}
const QString actionLabel = i18n( "Folder Shortcut %1", col.name() );
QString actionName = i18n( "Folder Shortcut %1", folderCollection->idString() );
actionName.replace( ' ', '_' );
KAction *action = mActionCollection->addAction( actionName );
// The folder shortcut is set in the folder shortcut dialog.
// The shortcut set in the shortcut dialog would not be saved back to
// the folder settings correctly.
action->setShortcutConfigurable( false );
action->setText( actionLabel );
action->setShortcuts( folderCollection->shortcut() );
action->setIcon( icon );
connect( action, SIGNAL( triggered( bool ) ), command, SLOT( start() ) );
command->setAction( action ); // will be deleted along with the command
}
#include "foldershortcutactionmanager.moc"

@ -0,0 +1,71 @@
/* Copyright 2010 Thomas McGuire <mcguire@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; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef FOLDERSHORTCUTACTIONMANAGER_H
#define FOLDERSHORTCUTACTIONMANAGER_H
#include "kmail_export.h"
#include <Akonadi/Entity>
#include <QMap>
#include <QObject>
namespace Akonadi {
class Collection;
}
class FolderShortcutCommand;
class KActionCollection;
class KMMainWidget;
namespace KMail {
class KMAIL_EXPORT FolderShortcutActionManager : public QObject
{
Q_OBJECT
public:
FolderShortcutActionManager( KMMainWidget *parent, KActionCollection *actionCollection );
void createActions();
public slots:
/**
* Updates the shortcut action for this collection. Call this when a shortcut was
* added, removed or changed.
*/
void shortcutChanged( const Akonadi::Collection &collection );
private slots:
/**
* Removes the shortcut actions associated with a folder.
*/
void slotCollectionRemoved( const Akonadi::Collection &collection );
private:
QMap< Akonadi::Entity::Id, FolderShortcutCommand* > mFolderShortcutCommands;
KActionCollection *mActionCollection;
KMMainWidget *mParent;
};
}
#endif

@ -48,6 +48,7 @@
#include "folderselectiontreeview.h"
#include "foldertreeview.h"
#include "tagactionmanager.h"
#include "foldershortcutactionmanager.h"
#include <QLayout>
#include <kglobal.h>
@ -180,7 +181,7 @@ void KMailPart::guiActivateEvent(KParts::GUIActivateEvent *e)
KParts::ReadOnlyPart::guiActivateEvent(e);
mainWidget->initializeFilterActions();
mainWidget->tagActionManager()->createActions();
mainWidget->initializeFolderShortcutActions();
mainWidget->folderShortcutActionManager()->createActions();
mainWidget->updateVactionScriptStatus();
}

@ -57,6 +57,7 @@
#include "globalsettings.h"
#include "foldertreeview.h"
#include "tagactionmanager.h"
#include "foldershortcutactionmanager.h"
#if !defined(NDEBUG)
#include "sievedebugdialog.h"
using KMail::SieveDebugDialog;
@ -848,8 +849,8 @@ void KMMainWidget::createWidgets()
opt |= FolderSelectionTreeView::UseLineEditForFiltering;
mCollectionFolderView = new FolderSelectionTreeView( this, mGUIClient, opt );
connect( mCollectionFolderView->folderTreeView(), SIGNAL( currentChanged( const Akonadi::Collection &) ), this, SLOT( slotFolderChanged( const Akonadi::Collection& ) ) );
connect( KMKernel::self()->monitor(), SIGNAL( collectionRemoved( const Akonadi::Collection &) ), this, SLOT( slotCollectionRemoved( const Akonadi::Collection& ) ) );
connect( mCollectionFolderView->folderTreeView(), SIGNAL( currentChanged( const Akonadi::Collection & ) ),
this, SLOT( slotFolderChanged( const Akonadi::Collection& ) ) );
mCollectionFolderView->setSelectionMode( QAbstractItemView::ExtendedSelection );
const KConfigGroup cfg( KMKernel::config(), "CollectionFolderView" );
@ -3488,6 +3489,7 @@ void KMMainWidget::setupActions()
updateFolderMenu();
mTagActionManager = new KMail::TagActionManager( this, actionCollection(), mMsgActions,
mGUIClient );
mFolderShortcutActionManager = new KMail::FolderShortcutActionManager( this, actionCollection() );
}
//-----------------------------------------------------------------------------
@ -3834,7 +3836,7 @@ void KMMainWidget::slotShowStartupFolder()
// the main window or Kontact calls createGUI().
// This function however is called with a single shot timer.
initializeFilterActions();
initializeFolderShortcutActions();
mFolderShortcutActionManager->createActions();
mTagActionManager->createActions();
messageActions()->setupForwardingActionsList( mGUIClient );
@ -3964,16 +3966,6 @@ void KMMainWidget::clearFilterActions()
mFilterCommands.clear();
}
//-----------------------------------------------------------------------------
void KMMainWidget::initializeFolderShortcutActions()
{
QList<Akonadi::Collection> folders = kmkernel->allFoldersCollection();
for ( int i = 0 ; i < folders.size(); ++i ) {
Akonadi::Collection col = folders.at( i );
shortcutChanged( col );
}
}
//-----------------------------------------------------------------------------
void KMMainWidget::initializeFilterActions()
{
@ -4032,11 +4024,6 @@ void KMMainWidget::initializeFilterActions()
updateMessageActions();
}
void KMMainWidget::slotCollectionRemoved( const Akonadi::Collection& col)
{
delete mFolderShortcutCommands.take( col.id() );
}
//-----------------------------------------------------------------------------
void KMMainWidget::initializeIMAPActions( bool setState /* false the first time, true later on */ )
{
@ -4071,41 +4058,6 @@ QList<QAction*> KMMainWidget::actionList()
return actionCollection()->actions();
}
void KMMainWidget::shortcutChanged( const Akonadi::Collection & col )
{
// remove the old one, no autodelete in Qt4
slotCollectionRemoved( col );
QSharedPointer<FolderCollection> fd( FolderCollection::forCollection( col ) );
if ( fd->shortcut().isEmpty() )
return;
FolderShortcutCommand *c = new FolderShortcutCommand( this, col );
mFolderShortcutCommands.insert( col.id(), c );
QString actionlabel = i18n( "Folder Shortcut %1", col.name() );
QString actionname = i18n( "Folder Shortcut %1", fd->idString() );
QString normalizedName = actionname.replace(' ', '_');
KAction *action = actionCollection()->addAction( normalizedName );
// The folder shortcut is set in the folder shortcut dialog.
// The shortcut set in the shortcut dialog would not be saved back to
// the folder settings correctly.
action->setShortcutConfigurable( false );
#ifdef OLD_FOLDERVIEW
mMainFolderView->addAction( action ); // <-- FIXME: why this is added to the folder view ?
#endif
action->setText( actionlabel );
connect( action, SIGNAL( triggered(bool) ), c, SLOT( start() ) );
action->setShortcuts( fd->shortcut() );
KIcon icon( "folder" );
if ( col.hasAttribute<Akonadi::EntityDisplayAttribute>() &&
!col.attribute<Akonadi::EntityDisplayAttribute>()->iconName().isEmpty() ) {
icon = KIcon( col.attribute<Akonadi::EntityDisplayAttribute>()->iconName() );
}
action->setIcon( icon );
c->setAction( action ); // will be deleted along with the command
}
//-----------------------------------------------------------------------------
QString KMMainWidget::findCurrentImapPath()
{

@ -61,7 +61,6 @@ class KActionMenu;
class KToggleAction;
class FolderTreeView;
class KMMetaFilterActionCommand;
class FolderShortcutCommand;
class KMSystemTray;
class CustomTemplatesMenu;
@ -80,6 +79,7 @@ namespace KMail {
class FavoriteFolderView;
class StatusBarLabel;
class TagActionManager;
class FolderShortcutActionManager;
}
class FolderSelectionTreeView;
@ -184,11 +184,13 @@ class KMAIL_EXPORT KMMainWidget : public QWidget
/** Returns the XML GUI client. */
KXMLGUIClient* guiClient() const { return mGUIClient; }
KMail::TagActionManager *tagActionManager() const { return mTagActionManager; }
/** Add, remove or adjust the folder's shortcut. */
void shortcutChanged( const Akonadi::Collection & );
KMail::TagActionManager *tagActionManager() const {
return mTagActionManager;
}
KMail::FolderShortcutActionManager *folderShortcutActionManager() const {
return mFolderShortcutActionManager;
}
public slots:
// Moving messages around
@ -261,9 +263,6 @@ class KMAIL_EXPORT KMMainWidget : public QWidget
/** Create IMAP-account-related actions if applicable */
void initializeIMAPActions() { initializeIMAPActions( true ); }
/** Create actions for the folder shortcuts. */
void initializeFolderShortcutActions();
/** Trigger the dialog for editing out-of-office scripts. */
void slotEditVacation();
@ -441,11 +440,6 @@ class KMAIL_EXPORT KMMainWidget : public QWidget
void slotConfigChanged();
/**
Remove the shortcut actions associated with a folder.
*/
void slotCollectionRemoved( const Akonadi::Collection& );
/** Show a splash screen for the longer-lasting operation */
void slotShowBusySplash();
@ -617,9 +611,9 @@ private:
QList<QAction*> mFilterMenuActions;
QList<QAction*> mFilterTBarActions;
QList<KMMetaFilterActionCommand*> mFilterCommands;
QHash<Akonadi::Entity::Id,FolderShortcutCommand*> mFolderShortcutCommands;
KMail::TagActionManager *mTagActionManager;
KMail::FolderShortcutActionManager *mFolderShortcutActionManager;
KMSystemTray *mSystemTray;
KSharedConfig::Ptr mConfig;
KXMLGUIClient *mGUIClient;

Loading…
Cancel
Save