• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
foldershortcutactionmanager.cpp
Go to the documentation of this file.
1 /* Copyright 2010 Thomas McGuire <mcguire@kde.org>
2 
3  This program is free software; you can redistribute it and/or
4  modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation; either version 2 of
6  the License or (at your option) version 3 or any later version
7  accepted by the membership of KDE e.V. (or its successor approved
8  by the membership of KDE e.V.), which shall act as a proxy
9  defined in Section 14 of version 3 of the license.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "foldershortcutactionmanager.h"
20 
21 #include "foldercollection.h"
22 #include "kernel/mailkernel.h"
23 
24 #include <Akonadi/ChangeRecorder>
25 #include <Akonadi/EntityDisplayAttribute>
26 #include <Akonadi/EntityTreeModel>
27 #include <Akonadi/EntityMimeTypeFilterModel>
28 
29 #include <KAction>
30 #include <KActionCollection>
31 #include <KLocale>
32 
33 using namespace KMail;
34 using namespace MailCommon;
35 
36 
37 FolderShortcutCommand::FolderShortcutCommand( QWidget *mainwidget,
38  const Akonadi::Collection&col )
39  : QObject( mainwidget ),
40  mCollectionFolder( col ),
41  mMainWidget( mainwidget ),
42  mAction( 0 )
43 {
44  connect( this, SIGNAL(selectCollectionFolder(Akonadi::Collection)), mMainWidget, SLOT(slotSelectCollectionFolder(Akonadi::Collection)));
45 }
46 
47 
48 FolderShortcutCommand::~FolderShortcutCommand()
49 {
50  if ( mAction && mAction->parentWidget() )
51  mAction->parentWidget()->removeAction( mAction );
52  delete mAction;
53 }
54 
55 void FolderShortcutCommand::start()
56 {
57  emit selectCollectionFolder( mCollectionFolder );
58 }
59 
60 void FolderShortcutCommand::setAction( QAction* action )
61 {
62  mAction = action;
63 }
64 
65 
66 FolderShortcutActionManager::FolderShortcutActionManager( QWidget *parent,
67  KActionCollection *actionCollection
68  )
69  : QObject( parent ),
70  mActionCollection( actionCollection ),
71  mParent( parent )
72 {
73 }
74 
75 void FolderShortcutActionManager::createActions()
76 {
77  // When this function is called, the ETM has not finished loading yet. Therefore, when new
78  // rows are inserted in the ETM, see if we have new collections that we can assign shortcuts
79  // to.
80  const QAbstractItemModel *model = KernelIf->collectionModel();
81  connect( model, SIGNAL(rowsInserted(QModelIndex,int,int)),
82  this, SLOT(slotRowsInserted(QModelIndex,int,int)), Qt::UniqueConnection );
83  connect( KernelIf->folderCollectionMonitor(), SIGNAL(collectionRemoved(Akonadi::Collection)),
84  this, SLOT(slotCollectionRemoved(Akonadi::Collection)), Qt::UniqueConnection );
85 
86  if ( model->rowCount() > 0 ) {
87  updateShortcutsForIndex( QModelIndex(), 0, model->rowCount() - 1 );
88  }
89 }
90 
91 void FolderShortcutActionManager::slotRowsInserted( const QModelIndex &parent, int start, int end )
92 {
93  updateShortcutsForIndex( parent, start, end );
94 }
95 
96 void FolderShortcutActionManager::updateShortcutsForIndex( const QModelIndex &parent,
97  int start, int end )
98 {
99  QAbstractItemModel *model = KernelIf->collectionModel();
100  for ( int i = start; i <= end; ++i) {
101  if ( model->hasIndex( i, 0, parent ) ) {
102  const QModelIndex child = model->index( i, 0, parent );
103  Akonadi::Collection collection =
104  model->data( child, Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
105  if ( collection.isValid() ) {
106  shortcutChanged( collection );
107  }
108  if ( model->rowCount( child ) > 0 ) {
109  updateShortcutsForIndex( child, 0, model->rowCount( child ) - 1 );
110  }
111  }
112  }
113 }
114 
115 void FolderShortcutActionManager::slotCollectionRemoved( const Akonadi::Collection &col )
116 {
117  delete mFolderShortcutCommands.take( col.id() );
118 }
119 
120 void FolderShortcutActionManager::shortcutChanged( const Akonadi::Collection &col )
121 {
122  // remove the old one, no autodelete in Qt4
123  slotCollectionRemoved( col );
124  const QSharedPointer<FolderCollection> folderCollection( FolderCollection::forCollection( col, false ) );
125  const KShortcut shortcut( folderCollection->shortcut() );
126  if ( shortcut.isEmpty() )
127  return;
128 
129  FolderShortcutCommand *command = new FolderShortcutCommand( mParent, col );
130  mFolderShortcutCommands.insert( col.id(), command );
131 
132  KIcon icon( QLatin1String("folder") );
133  if ( col.hasAttribute<Akonadi::EntityDisplayAttribute>() &&
134  !col.attribute<Akonadi::EntityDisplayAttribute>()->iconName().isEmpty() ) {
135  icon = KIcon( col.attribute<Akonadi::EntityDisplayAttribute>()->iconName() );
136  }
137 
138  const QString actionLabel = i18n( "Folder Shortcut %1", col.name() );
139  QString actionName = i18n( "Folder Shortcut %1", QString::number( col.id() ) );
140  actionName.replace( QLatin1Char(' '), QLatin1Char('_') );
141  KAction *action = mActionCollection->addAction( actionName );
142  // The folder shortcut is set in the folder shortcut dialog.
143  // The shortcut set in the shortcut dialog would not be saved back to
144  // the folder settings correctly.
145  action->setShortcutConfigurable( false );
146  action->setText( actionLabel );
147  action->setShortcuts( shortcut );
148  action->setIcon( icon );
149 
150  connect( action, SIGNAL(triggered(bool)), command, SLOT(start()) );
151  command->setAction( action ); // will be deleted along with the command
152 }
153 
154 #include "foldershortcutactionmanager.moc"
QSharedPointer
Definition: collectionmailinglistpage.h:34
KMail::FolderShortcutCommand::selectCollectionFolder
void selectCollectionFolder(const Akonadi::Collection &col)
QWidget
QObject
KMail::FolderShortcutCommand::~FolderShortcutCommand
~FolderShortcutCommand()
Definition: foldershortcutactionmanager.cpp:48
KMail::FolderShortcutActionManager::shortcutChanged
void shortcutChanged(const Akonadi::Collection &collection)
Updates the shortcut action for this collection.
Definition: foldershortcutactionmanager.cpp:120
KMail::FolderShortcutCommand::start
void start()
Definition: foldershortcutactionmanager.cpp:55
foldershortcutactionmanager.h
KMail::FolderShortcutCommand
Definition: foldershortcutactionmanager.h:37
KMail::FolderShortcutActionManager::createActions
void createActions()
Definition: foldershortcutactionmanager.cpp:75
KMail::FolderShortcutActionManager::FolderShortcutActionManager
FolderShortcutActionManager(QWidget *parent, KActionCollection *actionCollection)
Definition: foldershortcutactionmanager.cpp:66
KMail::FolderShortcutCommand::setAction
void setAction(QAction *)
Assign a KAction to the command which is used to trigger it.
Definition: foldershortcutactionmanager.cpp:60
KMail::FolderShortcutCommand::FolderShortcutCommand
FolderShortcutCommand(QWidget *mainwidget, const Akonadi::Collection &col)
Definition: foldershortcutactionmanager.cpp:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal