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

korganizer

  • sources
  • kde-4.12
  • kdepim
  • korganizer
akonadicollectionview.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6  Copyright (C) 2009 Sebastian Sauer <sebsauer@kdab.net>
7  Copyright (C) 2010 Laurent Montel <montel@kde.org>
8  Copyright (C) 2012 Sérgio Martins <iamsergio@gmail.com>
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License along
21  with this program; if not, write to the Free Software Foundation, Inc.,
22  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 
24  As a special exception, permission is given to link this program
25  with any edition of Qt, and distribute the resulting executable,
26  without including the source code for Qt in the source distribution.
27 */
28 
29 #include "akonadicollectionview.h"
30 #include "kocore.h"
31 #include "kohelper.h"
32 #include "koprefs.h"
33 #include "koglobals.h"
34 
35 #include <calendarsupport/kcalprefs.h>
36 #include <calendarsupport/utils.h>
37 
38 #include <Akonadi/AgentFilterProxyModel>
39 #include <Akonadi/AgentInstanceCreateJob>
40 #include <Akonadi/AgentManager>
41 #include <Akonadi/AgentTypeDialog>
42 #include <Akonadi/CollectionDeleteJob>
43 #include <Akonadi/CollectionFilterProxyModel>
44 #include <Akonadi/EntityDisplayAttribute>
45 #include <Akonadi/EntityTreeView>
46 #include <Akonadi/EntityTreeModel>
47 #include <Akonadi/ETMViewStateSaver>
48 #include <Akonadi/Calendar/StandardCalendarActionManager>
49 
50 #include <KAction>
51 #include <KActionCollection>
52 #include <KCheckableProxyModel>
53 #include <KColorDialog>
54 #include <KMessageBox>
55 #include <KRecursiveFilterProxyModel>
56 
57 #include <QHeaderView>
58 #include <QPainter>
59 #include <QStyledItemDelegate>
60 #include <QVBoxLayout>
61 
62 AkonadiCollectionViewFactory::AkonadiCollectionViewFactory( CalendarView *view )
63  : mView( view ), mAkonadiCollectionView( 0 )
64 {
65 }
66 
67 namespace {
68 
69 static bool hasCompatibleMimeTypes( const Akonadi::Collection &collection )
70 {
71  static QStringList goodMimeTypes;
72 
73  if ( goodMimeTypes.isEmpty() ) {
74  goodMimeTypes << QLatin1String( "text/calendar" )
75  << KCalCore::Event::eventMimeType()
76  << KCalCore::Todo::todoMimeType()
77  << KCalCore::Journal::journalMimeType();
78  }
79 
80  for ( int i=0; i<goodMimeTypes.count(); ++i ) {
81  if ( collection.contentMimeTypes().contains( goodMimeTypes.at( i ) ) ) {
82  return true;
83  }
84  }
85 
86  return false;
87 }
88 
89 class ColorDelegate : public QStyledItemDelegate
90 {
91  public:
92  explicit ColorDelegate( QObject * parent = 0 ) : QStyledItemDelegate( parent )
93  {
94  }
95 
96  void paint ( QPainter *painter, const QStyleOptionViewItem &option,
97  const QModelIndex &index ) const
98  {
99  QStyledItemDelegate::paint( painter, option, index );
100  QStyleOptionViewItemV4 v4 = option;
101  initStyleOption( &v4, index );
102  if ( v4.checkState == Qt::Checked ) {
103  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
104  QColor color = KOHelper::resourceColor( collection );
105  if ( color.isValid() ) {
106  QRect r = v4.rect;
107  const int h = r.height() - 4;
108  r.adjust( r.width() - h - 2, 2, - 2, -2 );
109  painter->save();
110  painter->setRenderHint( QPainter::Antialiasing );
111  QPen pen = painter->pen();
112  pen.setColor( color );
113  QPainterPath path;
114  path.addRoundedRect( r, 5, 5 );
115  color.setAlpha( 200 );
116  painter->fillPath( path, color );
117  painter->strokePath( path, pen );
118  painter->restore();
119  }
120  }
121  }
122 };
123 
124 class ColorProxyModel : public QSortFilterProxyModel
125 {
126  public:
127  explicit ColorProxyModel( QObject *parent=0 )
128  : QSortFilterProxyModel( parent ), mInitDefaultCalendar( false )
129  {
130  }
131 
132  /* reimp */
133  QVariant data( const QModelIndex &index, int role ) const
134  {
135  if ( !index.isValid() ) {
136  return QVariant();
137  }
138  if ( role == Qt::DecorationRole ) {
139  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
140 
141  if ( hasCompatibleMimeTypes( collection ) ) {
142  if ( collection.hasAttribute<Akonadi::EntityDisplayAttribute>() &&
143  !collection.attribute<Akonadi::EntityDisplayAttribute>()->iconName().isEmpty() ) {
144  return collection.attribute<Akonadi::EntityDisplayAttribute>()->icon();
145  }
146  }
147  } else if ( role == Qt::FontRole ) {
148  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
149  if ( !collection.contentMimeTypes().isEmpty() &&
150  KOHelper::isStandardCalendar( collection.id() ) &&
151  collection.rights() & Akonadi::Collection::CanCreateItem ) {
152  QFont font = qvariant_cast<QFont>( QSortFilterProxyModel::data( index, Qt::FontRole ) );
153  font.setBold( true );
154  if ( !mInitDefaultCalendar ) {
155  mInitDefaultCalendar = true;
156  CalendarSupport::KCalPrefs::instance()->setDefaultCalendarId( collection.id() );
157  }
158  return font;
159  }
160  }
161 
162  return QSortFilterProxyModel::data( index, role );
163  }
164 
165  /* reimp */
166  Qt::ItemFlags flags( const QModelIndex &index ) const
167  {
168  return Qt::ItemIsSelectable | QSortFilterProxyModel::flags( index );
169  }
170 
171  private:
172  mutable bool mInitDefaultCalendar;
173 };
174 
175 } // anonymous namespace
176 
177 CalendarViewExtension *AkonadiCollectionViewFactory::create( QWidget *parent )
178 {
179  mAkonadiCollectionView = new AkonadiCollectionView( view(), true, parent );
180  QObject::connect( mAkonadiCollectionView, SIGNAL(resourcesChanged(bool)),
181  mView, SLOT(resourcesChanged()) );
182  QObject::connect( mAkonadiCollectionView, SIGNAL(resourcesChanged(bool)),
183  mView, SLOT(updateCategories()) );
184  QObject::connect( mAkonadiCollectionView, SIGNAL(resourcesAddedRemoved()),
185  mView, SLOT(resourcesChanged()) );
186  QObject::connect( mAkonadiCollectionView, SIGNAL(resourcesAddedRemoved()),
187  mView, SLOT(updateCategories()) );
188  return mAkonadiCollectionView;
189 }
190 
191 CalendarView *AkonadiCollectionViewFactory::view() const
192 {
193  return mView;
194 }
195 
196 AkonadiCollectionView *AkonadiCollectionViewFactory::collectionView() const
197 {
198  return mAkonadiCollectionView;
199 }
200 
201 AkonadiCollectionView::AkonadiCollectionView( CalendarView *view, bool hasContextMenu,
202  QWidget *parent )
203  : CalendarViewExtension( parent ),
204  mActionManager(0),
205  mCollectionView(0),
206  mBaseModel( 0 ),
207  mSelectionProxyModel( 0 ),
208  mNotSendAddRemoveSignal( false ),
209  mWasDefaultCalendar( false ),
210  mHasContextMenu( hasContextMenu )
211 {
212  QVBoxLayout *topLayout = new QVBoxLayout( this );
213  topLayout->setMargin( 0 );
214  topLayout->setSpacing( KDialog::spacingHint() );
215 
216  //KLineEdit *searchCol = new KLineEdit( this );
217  //searchCol->setClearButtonShown( true );
218  //searchCol->setClickMessage( i18nc( "@info/plain Displayed grayed-out inside the "
219  // "textbox, verb to search", "Search" ) );
220  //topLayout->addWidget( searchCol );
221 
222  ColorProxyModel *colorProxy = new ColorProxyModel( this );
223  colorProxy->setObjectName( QLatin1String("Show calendar colors") );
224  colorProxy->setDynamicSortFilter( true );
225  mBaseModel = colorProxy;
226 
227  mCollectionView = new Akonadi::EntityTreeView( this );
228  topLayout->addWidget( mCollectionView );
229  mCollectionView->header()->hide();
230  mCollectionView->setRootIsDecorated( true );
231  mCollectionView->setItemDelegate( new ColorDelegate( this ) );
232 
233  //Filter tree view.
234  //KRecursiveFilterProxyModel *filterTreeViewModel = new KRecursiveFilterProxyModel( this );
235  //filterTreeViewModel->setDynamicSortFilter( true );
236  //filterTreeViewModel->setSourceModel( colorProxy );
237  //filterTreeViewModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
238  //filterTreeViewModel->setObjectName( "Recursive filtering, for the search bar" );
239  mCollectionView->setModel( colorProxy );
240  connect( mCollectionView->selectionModel(),
241  SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
242  SLOT(updateMenu()) );
243 
244  connect( mCollectionView->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
245  SLOT(checkNewCalendar(QModelIndex,int,int)) );
246 
247  //connect( searchCol, SIGNAL(textChanged(QString)),
248  // filterTreeViewModel, SLOT(setFilterFixedString(QString)) );
249 
250  connect( mBaseModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
251  this, SLOT(rowsInserted(QModelIndex,int,int)) );
252 
253  //mCollectionView->setSelectionMode( QAbstractItemView::NoSelection );
254  KXMLGUIClient *xmlclient = KOCore::self()->xmlguiClient( view );
255  if ( xmlclient ) {
256  mCollectionView->setXmlGuiClient( xmlclient );
257 
258  mActionManager =
259  new Akonadi::StandardCalendarActionManager( xmlclient->actionCollection(), mCollectionView );
260 
261  QList<Akonadi::StandardActionManager::Type> standardActions;
262  standardActions << Akonadi::StandardActionManager::CreateCollection
263  << Akonadi::StandardActionManager::CopyCollections
264  << Akonadi::StandardActionManager::DeleteCollections
265  << Akonadi::StandardActionManager::SynchronizeCollections
266  << Akonadi::StandardActionManager::CollectionProperties
267  << Akonadi::StandardActionManager::CopyItems
268  << Akonadi::StandardActionManager::Paste
269  << Akonadi::StandardActionManager::DeleteItems
270  << Akonadi::StandardActionManager::CutItems
271  << Akonadi::StandardActionManager::CutCollections
272  << Akonadi::StandardActionManager::CreateResource
273  << Akonadi::StandardActionManager::DeleteResources
274  << Akonadi::StandardActionManager::ResourceProperties
275  << Akonadi::StandardActionManager::SynchronizeResources
276  << Akonadi::StandardActionManager::SynchronizeCollectionsRecursive;
277 
278  Q_FOREACH( Akonadi::StandardActionManager::Type standardAction, standardActions ) {
279  mActionManager->createAction( standardAction );
280  }
281 
282  QList<Akonadi::StandardCalendarActionManager::Type> calendarActions;
283  calendarActions << Akonadi::StandardCalendarActionManager::CreateEvent
284  << Akonadi::StandardCalendarActionManager::CreateTodo
285  << Akonadi::StandardCalendarActionManager::CreateSubTodo
286  << Akonadi::StandardCalendarActionManager::CreateJournal
287  << Akonadi::StandardCalendarActionManager::EditIncidence;
288 
289  Q_FOREACH( Akonadi::StandardCalendarActionManager::Type calendarAction, calendarActions ) {
290  mActionManager->createAction( calendarAction );
291  }
292 
293  mActionManager->setCollectionSelectionModel( mCollectionView->selectionModel() );
294 
295  mActionManager->interceptAction( Akonadi::StandardActionManager::CreateResource );
296  mActionManager->interceptAction( Akonadi::StandardActionManager::DeleteResources );
297  mActionManager->interceptAction( Akonadi::StandardActionManager::DeleteCollections );
298 
299  connect( mActionManager->action( Akonadi::StandardActionManager::CreateResource ),
300  SIGNAL(triggered(bool)),
301  this, SLOT(newCalendar()) );
302  connect( mActionManager->action( Akonadi::StandardActionManager::DeleteResources ),
303  SIGNAL(triggered(bool)),
304  this, SLOT(deleteCalendar()) );
305  connect( mActionManager->action( Akonadi::StandardActionManager::DeleteCollections ),
306  SIGNAL(triggered(bool)),
307  this, SLOT(deleteCalendar()) );
308 
309  mActionManager->setContextText( Akonadi::StandardActionManager::CollectionProperties,
310  Akonadi::StandardActionManager::DialogTitle,
311  ki18nc( "@title:window", "Properties of Calendar Folder %1" ) );
312 
313  const QStringList pages =
314  QStringList() << QLatin1String( "CalendarSupport::CollectionGeneralPage" )
315  << QLatin1String( "Akonadi::CachePolicyPage" )
316  << QLatin1String( "PimCommon::CollectionAclPage" );
317 
318  mActionManager->setCollectionPropertiesPageNames( pages );
319 
320  mDisableColor = new KAction( mCollectionView );
321  mDisableColor->setText( i18n( "&Disable Color" ) );
322  mDisableColor->setEnabled( false );
323  xmlclient->actionCollection()->addAction( QString::fromLatin1( "disable_color" ),
324  mDisableColor );
325  connect( mDisableColor, SIGNAL(triggered(bool)), this, SLOT(disableColor()) );
326 
327  mAssignColor = new KAction( mCollectionView );
328  mAssignColor->setText( i18n( "&Assign Color..." ) );
329  mAssignColor->setEnabled( false );
330  xmlclient->actionCollection()->addAction( QString::fromLatin1( "assign_color" ), mAssignColor );
331  connect( mAssignColor, SIGNAL(triggered(bool)), this, SLOT(assignColor()) );
332 
333  mDefaultCalendar = new KAction( mCollectionView );
334  mDefaultCalendar->setText( i18n( "Use as &Default Calendar" ) );
335  mDefaultCalendar->setEnabled( false );
336  xmlclient->actionCollection()->addAction( QString::fromLatin1( "set_standard_calendar" ),
337  mDefaultCalendar );
338  connect( mDefaultCalendar, SIGNAL(triggered(bool)), this, SLOT(setDefaultCalendar()) );
339  }
340 }
341 
342 AkonadiCollectionView::~AkonadiCollectionView()
343 {
344  Akonadi::ETMViewStateSaver treeStateSaver;
345  KConfigGroup group( KOGlobals::self()->config(), "CollectionTreeView" );
346  treeStateSaver.setView( mCollectionView );
347  treeStateSaver.setSelectionModel( 0 ); // we only save expand state
348  treeStateSaver.saveState( group );
349 }
350 
351 void AkonadiCollectionView::restoreTreeState()
352 {
353  static QPointer<Akonadi::ETMViewStateSaver> treeStateRestorer;
354  if ( treeStateRestorer ) {// We don't need more than one to be running at the same time
355  delete treeStateRestorer;
356  }
357  treeStateRestorer = new Akonadi::ETMViewStateSaver(); // not a leak
358  KConfigGroup group( KOGlobals::self()->config(), "CollectionTreeView" );
359  treeStateRestorer->setView( mCollectionView );
360  treeStateRestorer->setSelectionModel( 0 ); // we only restore expand state
361  treeStateRestorer->restoreState( group );
362 }
363 
364 void AkonadiCollectionView::setDefaultCalendar()
365 {
366  QModelIndex index = mCollectionView->selectionModel()->currentIndex(); //selectedRows()
367  Q_ASSERT( index.isValid() );
368  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
369  CalendarSupport::KCalPrefs::instance()->setDefaultCalendarId( collection.id() );
370  CalendarSupport::KCalPrefs::instance()->usrWriteConfig();
371  updateMenu();
372  updateView();
373 
374  emit defaultResourceChanged( collection );
375 }
376 
377 void AkonadiCollectionView::assignColor()
378 {
379  QModelIndex index = mCollectionView->selectionModel()->currentIndex(); //selectedRows()
380  Q_ASSERT( index.isValid() );
381  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
382  Q_ASSERT( collection.isValid() );
383 
384  const QString identifier = QString::number( collection.id() );
385  const QColor defaultColor = KOPrefs::instance()->resourceColor( identifier );
386  QColor myColor;
387  const int result = KColorDialog::getColor( myColor, defaultColor );
388  if ( result == KColorDialog::Accepted && myColor != defaultColor ) {
389  KOPrefs::instance()->setResourceColor( identifier, myColor );
390  emit colorsChanged();
391  updateMenu();
392  updateView();
393  }
394 }
395 
396 void AkonadiCollectionView::disableColor()
397 {
398  QModelIndex index = mCollectionView->selectionModel()->currentIndex(); //selectedRows()
399  Q_ASSERT( index.isValid() );
400  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
401  Q_ASSERT( collection.isValid() );
402  const QString identifier = QString::number( collection.id() );
403  KOPrefs::instance()->setResourceColor( identifier, QColor() );
404  updateMenu();
405  updateView();
406  emit colorsChanged();
407 }
408 
409 void AkonadiCollectionView::setCollectionSelectionProxyModel( KCheckableProxyModel *m )
410 {
411  if ( mSelectionProxyModel == m ) {
412  return;
413  }
414 
415  mSelectionProxyModel = m;
416  if ( !mSelectionProxyModel ) {
417  return;
418  }
419 
420  mBaseModel->setSourceModel( mSelectionProxyModel );
421 }
422 
423 KCheckableProxyModel *AkonadiCollectionView::collectionSelectionProxyModel() const
424 {
425  return mSelectionProxyModel;
426 }
427 
428 Akonadi::EntityTreeView *AkonadiCollectionView::view() const
429 {
430  return mCollectionView;
431 }
432 
433 void AkonadiCollectionView::updateView()
434 {
435  emit resourcesChanged( mSelectionProxyModel ?
436  mSelectionProxyModel->selectionModel()->hasSelection() :
437  false );
438 }
439 
440 void AkonadiCollectionView::updateMenu()
441 {
442  if ( !mHasContextMenu ) {
443  return;
444  }
445  bool enableAction = mCollectionView->selectionModel()->hasSelection();
446  enableAction = enableAction &&
447  ( KOPrefs::instance()->agendaViewColors() != KOPrefs::CategoryOnly );
448  mAssignColor->setEnabled( enableAction );
449  QModelIndex index = mCollectionView->selectionModel()->currentIndex(); //selectedRows()
450 
451  bool disableStuff = false;
452 
453  if ( index.isValid() ) {
454  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
455  Q_ASSERT( collection.isValid() );
456 
457  if ( !collection.contentMimeTypes().isEmpty() ) {
458  const QString identifier = QString::number( collection.id() );
459  const QColor defaultColor = KOPrefs::instance()->resourceColor( identifier );
460  enableAction = enableAction && defaultColor.isValid();
461  mDisableColor->setEnabled( enableAction );
462  mDefaultCalendar->setEnabled( !KOHelper::isStandardCalendar( collection.id() ) &&
463  collection.rights() & Akonadi::Collection::CanCreateItem );
464  } else {
465  disableStuff = true;
466  }
467  } else {
468  disableStuff = true;
469  }
470 
471  if ( disableStuff ) {
472  mDisableColor->setEnabled( false );
473  mDefaultCalendar->setEnabled( false );
474  mAssignColor->setEnabled( false );
475  }
476 }
477 
478 void AkonadiCollectionView::newCalendar()
479 {
480  Akonadi::AgentTypeDialog dlg( this );
481  dlg.setWindowTitle( i18n( "Add Calendar" ) );
482  dlg.agentFilterProxyModel()->addMimeTypeFilter( QString::fromLatin1( "text/calendar" ) );
483  dlg.agentFilterProxyModel()->addCapabilityFilter( QLatin1String("Resource") ); // show only resources, no agents
484  if ( dlg.exec() ) {
485  mNotSendAddRemoveSignal = true;
486  const Akonadi::AgentType agentType = dlg.agentType();
487  if ( agentType.isValid() ) {
488  Akonadi::AgentInstanceCreateJob *job = new Akonadi::AgentInstanceCreateJob( agentType, this );
489  job->configure( this );
490  connect( job, SIGNAL(result(KJob*)), this, SLOT(newCalendarDone(KJob*)) );
491  job->start();
492  }
493  }
494 }
495 
496 void AkonadiCollectionView::newCalendarDone( KJob *job )
497 {
498  Akonadi::AgentInstanceCreateJob *createjob = static_cast<Akonadi::AgentInstanceCreateJob*>( job );
499  if ( createjob->error() ) {
500  //TODO(AKONADI_PORT)
501  // this should show an error dialog and should be merged
502  // with the identical code in ActionManager
503  kWarning() << "Create calendar failed:" << createjob->errorString();
504  mNotSendAddRemoveSignal = false;
505  return;
506  }
507  mNotSendAddRemoveSignal = false;
508  //TODO
509 }
510 
511 void AkonadiCollectionView::deleteCalendar()
512 {
513  QModelIndex index = mCollectionView->selectionModel()->currentIndex(); //selectedRows()
514  Q_ASSERT( index.isValid() );
515  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
516  Q_ASSERT( collection.isValid() );
517 
518  const QString displayname = index.model()->data( index, Qt::DisplayRole ).toString();
519  Q_ASSERT( !displayname.isEmpty() );
520 
521  if ( KMessageBox::warningContinueCancel(
522  this,
523  i18n( "Do you really want to delete calendar %1?", displayname ),
524  i18n( "Delete Calendar" ),
525  KStandardGuiItem::del(),
526  KStandardGuiItem::cancel(),
527  QString(),
528  KMessageBox::Dangerous ) == KMessageBox::Continue ) {
529 
530  bool isTopLevel = collection.parentCollection() == Akonadi::Collection::root();
531 
532  mNotSendAddRemoveSignal = true;
533  mWasDefaultCalendar = KOHelper::isStandardCalendar( collection.id() );
534 
535  if ( !isTopLevel ) {
536  // deletes contents
537  Akonadi::CollectionDeleteJob *job = new Akonadi::CollectionDeleteJob( collection, this );
538  connect( job, SIGNAL(result(KJob*)), this, SLOT(deleteCalendarDone(KJob*)) );
539  } else {
540  // deletes the agent, not the contents
541  const Akonadi::AgentInstance instance =
542  Akonadi::AgentManager::self()->instance( collection.resource() );
543  if ( instance.isValid() ) {
544  Akonadi::AgentManager::self()->removeInstance( instance );
545  }
546  }
547  }
548 }
549 
550 void AkonadiCollectionView::deleteCalendarDone( KJob *job )
551 {
552  Akonadi::CollectionDeleteJob *deletejob = static_cast<Akonadi::CollectionDeleteJob*>( job );
553  if ( deletejob->error() ) {
554  kWarning() << "Delete calendar failed:" << deletejob->errorString();
555  mNotSendAddRemoveSignal = false;
556  return;
557  }
558  if ( mWasDefaultCalendar ) {
559  CalendarSupport::KCalPrefs::instance()->setDefaultCalendarId( Akonadi::Collection().id() );
560  }
561  mNotSendAddRemoveSignal = false;
562  //TODO
563 }
564 
565 void AkonadiCollectionView::rowsInserted( const QModelIndex &, int, int )
566 {
567  if ( !mNotSendAddRemoveSignal ) {
568  emit resourcesAddedRemoved();
569  }
570  restoreTreeState();
571 }
572 
573 Akonadi::Collection AkonadiCollectionView::selectedCollection() const
574 {
575  Akonadi::Collection collection;
576  QItemSelectionModel *selectionModel = mCollectionView->selectionModel();
577  if ( !selectionModel ) {
578  return collection;
579  }
580  QModelIndexList indexes = selectionModel->selectedIndexes();
581  if ( !indexes.isEmpty() ) {
582  collection = indexes.first().data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
583  }
584  return collection;
585 }
586 
587 Akonadi::Collection::List AkonadiCollectionView::checkedCollections() const
588 {
589  Akonadi::Collection::List collections;
590  if ( !mSelectionProxyModel ) {
591  return collections;
592  }
593  QItemSelectionModel *selectionModel = mSelectionProxyModel->selectionModel();
594  if ( !selectionModel ) {
595  return collections;
596  }
597  QModelIndexList indexes = selectionModel->selectedIndexes();
598  foreach( const QModelIndex &index, indexes ) {
599  if ( index.isValid() ) {
600  Akonadi::Collection collection = index.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
601  if ( collection.isValid() )
602  collections << collection;
603  }
604  }
605  return collections;
606 }
607 
608 bool AkonadiCollectionView::isChecked(const Akonadi::Collection &collection) const
609 {
610  if (!mSelectionProxyModel)
611  return false;
612  QItemSelectionModel *selectionModel = mSelectionProxyModel->selectionModel();
613  if (!selectionModel)
614  return false;
615  QModelIndexList indexes = selectionModel->selectedIndexes();
616  foreach(const QModelIndex &index, indexes) {
617  if (index.isValid()) {
618  Akonadi::Collection c = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
619  if (c.id() == collection.id()) {
620  return true;
621  }
622  }
623  }
624  return false;
625 }
626 
627 Akonadi::EntityTreeModel *AkonadiCollectionView::entityTreeModel() const
628 {
629  QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel*>( mCollectionView->model() );
630  while( proxy ) {
631  Akonadi::EntityTreeModel *etm = qobject_cast<Akonadi::EntityTreeModel*>( proxy->sourceModel() );
632  if ( etm ) {
633  return etm;
634  }
635  proxy = qobject_cast<QAbstractProxyModel*>( proxy->sourceModel() );
636  }
637 
638  kWarning() << "Couldn't find EntityTreeModel";
639  return 0;
640 }
641 
642 void AkonadiCollectionView::checkNewCalendar( const QModelIndex &parent, int begin, int end )
643 {
644  // HACK: Check newly created calendars
645  Akonadi::EntityTreeModel *etm = entityTreeModel();
646  if ( etm && entityTreeModel()->isCollectionTreeFetched() ) {
647  for( int row=begin; row<=end; ++row ) {
648  QModelIndex index = mCollectionView->model()->index( row, 0, parent );
649  if ( index.isValid() )
650  mCollectionView->model()->setData( index, Qt::Checked, Qt::CheckStateRole );
651  }
652  if ( parent.isValid() ) {
653  mCollectionView->setExpanded( parent, true );
654  }
655  }
656 }
657 
658 #include "akonadicollectionview.moc" // for EntityModelStateSaver Q_PRIVATE_SLOT
KOPrefsBase::agendaViewColors
int agendaViewColors() const
Get Color Usage.
Definition: koprefs_base.h:702
koglobals.h
KCheckableProxyModel
AkonadiCollectionView::collectionSelectionProxyModel
KCheckableProxyModel * collectionSelectionProxyModel() const
Definition: akonadicollectionview.cpp:423
KOPrefs::setResourceColor
void setResourceColor(const QString &, const QColor &)
Definition: koprefs.cpp:105
AkonadiCollectionView::AkonadiCollectionView
AkonadiCollectionView(CalendarView *view, bool hasContextMenu=true, QWidget *parent=0)
Definition: akonadicollectionview.cpp:201
KOCore::xmlguiClient
KXMLGUIClient * xmlguiClient(QWidget *) const
Definition: kocore.cpp:226
AkonadiCollectionView::colorsChanged
void colorsChanged()
QWidget
AkonadiCollectionView::view
Akonadi::EntityTreeView * view() const
Definition: akonadicollectionview.cpp:428
AkonadiCollectionViewFactory::create
CalendarViewExtension * create(QWidget *)
Definition: akonadicollectionview.cpp:177
QObject
AkonadiCollectionViewFactory::collectionView
AkonadiCollectionView * collectionView() const
Definition: akonadicollectionview.cpp:196
KOPrefsBase::CategoryOnly
Definition: koprefs_base.h:15
akonadicollectionview.h
CalendarView
This is the main calendar widget.
Definition: calendarview.h:99
koprefs.h
AkonadiCollectionViewFactory::view
CalendarView * view() const
Definition: akonadicollectionview.cpp:191
CalendarViewExtension
Definition: calendarview.h:77
AkonadiCollectionView::checkedCollections
Akonadi::Collection::List checkedCollections() const
Definition: akonadicollectionview.cpp:587
AkonadiCollectionViewFactory::AkonadiCollectionViewFactory
AkonadiCollectionViewFactory(CalendarView *view)
Definition: akonadicollectionview.cpp:62
AkonadiCollectionView::selectedCollection
Akonadi::Collection selectedCollection() const
Definition: akonadicollectionview.cpp:573
KOGlobals::self
static KOGlobals * self()
Definition: koglobals.cpp:43
AkonadiCollectionView::~AkonadiCollectionView
~AkonadiCollectionView()
Definition: akonadicollectionview.cpp:342
AkonadiCollectionView
This class provides a view of calendar resources.
Definition: akonadicollectionview.h:67
AkonadiCollectionView::resourcesChanged
void resourcesChanged(bool enabled)
AkonadiCollectionView::resourcesAddedRemoved
void resourcesAddedRemoved()
kohelper.h
KOHelper::resourceColor
KORGANIZERPRIVATE_EXPORT QColor resourceColor(const Akonadi::Item &incidence)
This method returns the proper resource / subresource color for the view.
Definition: kohelper.cpp:48
KOPrefs::instance
static KOPrefs * instance()
Get instance of KOPrefs.
Definition: koprefs.cpp:68
AkonadiCollectionView::isChecked
bool isChecked(const Akonadi::Collection &) const
Definition: akonadicollectionview.cpp:608
AkonadiCollectionView::setCollectionSelectionProxyModel
void setCollectionSelectionProxyModel(KCheckableProxyModel *)
Definition: akonadicollectionview.cpp:409
KOHelper::isStandardCalendar
KORGANIZERPRIVATE_EXPORT bool isStandardCalendar(const Akonadi::Entity::Id &id)
Return true if it's the standard calendar.
Definition: kohelper.cpp:63
KOPrefs::resourceColor
QColor resourceColor(const QString &)
Definition: koprefs.cpp:110
KJob
kocore.h
KOCore::self
static KOCore * self()
Definition: kocore.cpp:37
AkonadiCollectionView::defaultResourceChanged
void defaultResourceChanged(const Akonadi::Collection &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

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

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