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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
entitylistview.cpp
1 /*
2  Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3  Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
4  Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "entitylistview.h"
23 
24 #include "dragdropmanager_p.h"
25 #include "favoritecollectionsmodel.h"
26 
27 #include <QtCore/QDebug>
28 #include <QtCore/QTimer>
29 #include <QApplication>
30 #include <QDragMoveEvent>
31 #include <QHeaderView>
32 #include <QMenu>
33 
34 #include <KAction>
35 #include <KLocalizedString>
36 #include <KMessageBox>
37 #include <KUrl>
38 #include <KXMLGUIFactory>
39 
40 #include <kdebug.h>
41 #include <kxmlguiclient.h>
42 
43 #include <akonadi/collection.h>
44 #include <akonadi/control.h>
45 #include <akonadi/item.h>
46 #include <akonadi/entitytreemodel.h>
47 
48 #include <progressspinnerdelegate_p.h>
49 
50 using namespace Akonadi;
51 
55 class EntityListView::Private
56 {
57 public:
58  Private( EntityListView *parent )
59  : mParent( parent )
60 #ifndef QT_NO_DRAGANDDROP
61  , mDragDropManager( new DragDropManager( mParent ) )
62 #endif
63  , mXmlGuiClient( 0 )
64  {
65  }
66 
67  void init();
68  void itemClicked( const QModelIndex& );
69  void itemDoubleClicked( const QModelIndex& );
70  void itemCurrentChanged( const QModelIndex& );
71 
72  EntityListView *mParent;
73  DragDropManager *mDragDropManager;
74  KXMLGUIClient *mXmlGuiClient;
75 };
76 
77 void EntityListView::Private::init()
78 {
79  mParent->setEditTriggers( QAbstractItemView::EditKeyPressed );
80  mParent->setAcceptDrops( true );
81 #ifndef QT_NO_DRAGANDDROP
82  mParent->setDropIndicatorShown( true );
83  mParent->setDragDropMode( DragDrop );
84  mParent->setDragEnabled( true );
85 #endif
86  mParent->connect( mParent, SIGNAL(clicked(QModelIndex)),
87  mParent, SLOT(itemClicked(QModelIndex)) );
88  mParent->connect( mParent, SIGNAL(doubleClicked(QModelIndex)),
89  mParent, SLOT(itemDoubleClicked(QModelIndex)) );
90 
91  DelegateAnimator *animator = new DelegateAnimator( mParent );
92  ProgressSpinnerDelegate *customDelegate = new ProgressSpinnerDelegate( animator, mParent );
93  mParent->setItemDelegate( customDelegate );
94 
95  Control::widgetNeedsAkonadi( mParent );
96 }
97 
98 void EntityListView::Private::itemClicked( const QModelIndex &index )
99 {
100  if ( !index.isValid() ) {
101  return;
102  }
103 
104  const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
105  if ( collection.isValid() ) {
106  emit mParent->clicked( collection );
107  } else {
108  const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
109  if ( item.isValid() ) {
110  emit mParent->clicked( item );
111  }
112  }
113 }
114 
115 void EntityListView::Private::itemDoubleClicked( const QModelIndex &index )
116 {
117  if ( !index.isValid() ) {
118  return;
119  }
120 
121  const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
122  if ( collection.isValid() ) {
123  emit mParent->doubleClicked( collection );
124  } else {
125  const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
126  if ( item.isValid() ) {
127  emit mParent->doubleClicked( item );
128  }
129  }
130 }
131 
132 void EntityListView::Private::itemCurrentChanged( const QModelIndex &index )
133 {
134  if ( !index.isValid() ) {
135  return;
136  }
137 
138  const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
139  if ( collection.isValid() ) {
140  emit mParent->currentChanged( collection );
141  } else {
142  const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
143  if ( item.isValid() ) {
144  emit mParent->currentChanged( item );
145  }
146  }
147 }
148 
149 EntityListView::EntityListView( QWidget * parent )
150  : QListView( parent ),
151  d( new Private( this ) )
152 {
153  setSelectionMode( QAbstractItemView::SingleSelection );
154  d->init();
155 }
156 
157 EntityListView::EntityListView( KXMLGUIClient *xmlGuiClient, QWidget * parent )
158  : QListView( parent ),
159  d( new Private( this ) )
160 {
161  d->mXmlGuiClient = xmlGuiClient;
162  d->init();
163 }
164 
165 EntityListView::~EntityListView()
166 {
167  delete d->mDragDropManager;
168  delete d;
169 }
170 
171 void EntityListView::setModel( QAbstractItemModel * model )
172 {
173  if ( selectionModel() ) {
174  disconnect( selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
175  this, SLOT(itemCurrentChanged(QModelIndex)) );
176  }
177 
178  QListView::setModel( model );
179 
180  connect( selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
181  SLOT(itemCurrentChanged(QModelIndex)) );
182 }
183 
184 #ifndef QT_NO_DRAGANDDROP
185 void EntityListView::dragMoveEvent( QDragMoveEvent * event )
186 {
187  if ( d->mDragDropManager->dropAllowed( event ) ||
188  qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) ) {
189  // All urls are supported. process the event.
190  QListView::dragMoveEvent( event );
191  return;
192  }
193 
194  event->setDropAction( Qt::IgnoreAction );
195 }
196 
197 void EntityListView::dropEvent( QDropEvent * event )
198 {
199  bool menuCanceled = false;
200  if ( d->mDragDropManager->processDropEvent( event, menuCanceled ) &&
201  !menuCanceled ) {
202  if ( menuCanceled ) {
203  return;
204  }
205  QListView::dropEvent( event );
206  } else if ( qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) &&
207  !menuCanceled ) {
208  QListView::dropEvent( event );
209  }
210 }
211 #endif
212 
213 #ifndef QT_NO_CONTEXTMENU
214 void EntityListView::contextMenuEvent( QContextMenuEvent * event )
215 {
216  if ( !d->mXmlGuiClient ) {
217  return;
218  }
219 
220  const QModelIndex index = indexAt( event->pos() );
221 
222  QMenu *popup = 0;
223 
224  // check if the index under the cursor is a collection or item
225  const Collection collection = model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
226  if ( collection.isValid() ) {
227  popup = static_cast<QMenu*>( d->mXmlGuiClient->factory()->container(
228  QLatin1String( "akonadi_favoriteview_contextmenu" ), d->mXmlGuiClient ) );
229  } else {
230  popup = static_cast<QMenu*>( d->mXmlGuiClient->factory()->container(
231  QLatin1String( "akonadi_favoriteview_emptyselection_contextmenu" ), d->mXmlGuiClient ) );
232  }
233 
234  if ( popup ) {
235  popup->exec( event->globalPos() );
236  }
237 }
238 #endif
239 
240 void EntityListView::setXmlGuiClient( KXMLGUIClient *xmlGuiClient )
241 {
242  d->mXmlGuiClient = xmlGuiClient;
243 }
244 
245 KXMLGUIClient *EntityListView::xmlGuiClient() const
246 {
247  return d->mXmlGuiClient;
248 }
249 
250 #ifndef QT_NO_DRAGANDDROP
251 void EntityListView::startDrag( Qt::DropActions supportedActions )
252 {
253  d->mDragDropManager->startDrag( supportedActions );
254 }
255 #endif
256 
257 void EntityListView::setDropActionMenuEnabled( bool enabled )
258 {
259 #ifndef QT_NO_DRAGANDDROP
260  d->mDragDropManager->setShowDropActionMenu( enabled );
261 #endif
262 }
263 
264 bool EntityListView::isDropActionMenuEnabled() const
265 {
266 #ifndef QT_NO_DRAGANDDROP
267  return d->mDragDropManager->showDropActionMenu();
268 #else
269  return false;
270 #endif
271 }
272 
273 #include "moc_entitylistview.cpp"
Akonadi::EntityListView::setModel
virtual void setModel(QAbstractItemModel *model)
Definition: entitylistview.cpp:171
Akonadi::EntityListView::xmlGuiClient
KXMLGUIClient * xmlGuiClient() const
Return the XML GUI client which the view is used in.
Definition: entitylistview.cpp:245
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::EntityListView::currentChanged
void currentChanged(const Akonadi::Collection &collection)
This signal is emitted whenever the current collection in the view has changed.
Akonadi::EntityListView::setDropActionMenuEnabled
void setDropActionMenuEnabled(bool enabled)
Sets whether the drop action menu is enabled and will be shown on drop operation. ...
Definition: entitylistview.cpp:257
Akonadi::EntityListView::setXmlGuiClient
void setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
Sets the XML GUI client which the view is used in.
Definition: entitylistview.cpp:240
Akonadi::EntityListView::EntityListView
EntityListView(QWidget *parent=0)
Creates a new favorite collections view.
Definition: entitylistview.cpp:149
Akonadi::EntityListView::isDropActionMenuEnabled
bool isDropActionMenuEnabled() const
Returns whether the drop action menu is enabled and will be shown on drop operation.
Definition: entitylistview.cpp:264
Akonadi::Control::widgetNeedsAkonadi
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
Definition: control.cpp:265
Akonadi::EntityTreeModel::CollectionRole
The collection.
Definition: entitytreemodel.h:335
Akonadi::EntityListView
A view to show an item/collection list provided by an EntityTreeModel.
Definition: entitylistview.h:75
Akonadi::EntityListView::~EntityListView
virtual ~EntityListView()
Destroys the favorite collections view.
Definition: entitylistview.cpp:165
Akonadi::EntityTreeModel::ItemRole
The Item.
Definition: entitytreemodel.h:331
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi::FavoriteCollectionsModel
A model that lists a set of favorite collections.
Definition: favoritecollectionsmodel.h:65
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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