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

korganizer

  • sources
  • kde-4.14
  • 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-2015 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 "prefs/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() && (collection.remoteId() != QLatin1String("akonadi_birthdays_resource")) ) {
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(resourcesAddedRemoved()),
183  mView, SLOT(resourcesChanged()) );
184  return mAkonadiCollectionView;
185 }
186 
187 CalendarView *AkonadiCollectionViewFactory::view() const
188 {
189  return mView;
190 }
191 
192 AkonadiCollectionView *AkonadiCollectionViewFactory::collectionView() const
193 {
194  return mAkonadiCollectionView;
195 }
196 
197 AkonadiCollectionView::AkonadiCollectionView( CalendarView *view, bool hasContextMenu,
198  QWidget *parent )
199  : CalendarViewExtension( parent ),
200  mActionManager(0),
201  mCollectionView(0),
202  mBaseModel( 0 ),
203  mSelectionProxyModel( 0 ),
204  mNotSendAddRemoveSignal( false ),
205  mWasDefaultCalendar( false ),
206  mHasContextMenu( hasContextMenu )
207 {
208  QVBoxLayout *topLayout = new QVBoxLayout( this );
209  topLayout->setMargin( 0 );
210  topLayout->setSpacing( KDialog::spacingHint() );
211 
212  //KLineEdit *searchCol = new KLineEdit( this );
213  //searchCol->setClearButtonShown( true );
214  //searchCol->setClickMessage( i18nc( "@info/plain Displayed grayed-out inside the "
215  // "textbox, verb to search", "Search" ) );
216  //topLayout->addWidget( searchCol );
217 
218  ColorProxyModel *colorProxy = new ColorProxyModel( this );
219  colorProxy->setObjectName( QLatin1String("Show calendar colors") );
220  colorProxy->setDynamicSortFilter( true );
221  mBaseModel = colorProxy;
222 
223  mCollectionView = new Akonadi::EntityTreeView( this );
224  topLayout->addWidget( mCollectionView );
225  mCollectionView->header()->hide();
226  mCollectionView->setRootIsDecorated( true );
227  mCollectionView->setItemDelegate( new ColorDelegate( this ) );
228 
229  //Filter tree view.
230  //KRecursiveFilterProxyModel *filterTreeViewModel = new KRecursiveFilterProxyModel( this );
231  //filterTreeViewModel->setDynamicSortFilter( true );
232  //filterTreeViewModel->setSourceModel( colorProxy );
233  //filterTreeViewModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
234  //filterTreeViewModel->setObjectName( "Recursive filtering, for the search bar" );
235  mCollectionView->setModel( colorProxy );
236  connect( mCollectionView->selectionModel(),
237  SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
238  SLOT(updateMenu()) );
239 
240  connect( mCollectionView->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
241  SLOT(checkNewCalendar(QModelIndex,int,int)) );
242 
243  //connect( searchCol, SIGNAL(textChanged(QString)),
244  // filterTreeViewModel, SLOT(setFilterFixedString(QString)) );
245 
246  connect( mBaseModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
247  this, SLOT(rowsInserted(QModelIndex,int,int)) );
248 
249  //mCollectionView->setSelectionMode( QAbstractItemView::NoSelection );
250  KXMLGUIClient *xmlclient = KOCore::self()->xmlguiClient( view );
251  if ( xmlclient ) {
252  mCollectionView->setXmlGuiClient( xmlclient );
253 
254  mActionManager =
255  new Akonadi::StandardCalendarActionManager( xmlclient->actionCollection(), mCollectionView );
256 
257  QList<Akonadi::StandardActionManager::Type> standardActions;
258  standardActions << Akonadi::StandardActionManager::CreateCollection
259  << Akonadi::StandardActionManager::DeleteCollections
260  << Akonadi::StandardActionManager::SynchronizeCollections
261  << Akonadi::StandardActionManager::CollectionProperties
262  << Akonadi::StandardActionManager::CopyItems
263  << Akonadi::StandardActionManager::Paste
264  << Akonadi::StandardActionManager::DeleteItems
265  << Akonadi::StandardActionManager::CutItems
266  << Akonadi::StandardActionManager::CreateResource
267  << Akonadi::StandardActionManager::DeleteResources
268  << Akonadi::StandardActionManager::ResourceProperties
269  << Akonadi::StandardActionManager::SynchronizeResources
270  << Akonadi::StandardActionManager::SynchronizeCollectionsRecursive
271  << Akonadi::StandardActionManager::CopyCollectionToMenu
272  << Akonadi::StandardActionManager::MoveCollectionToMenu;
273 
274  Q_FOREACH( Akonadi::StandardActionManager::Type standardAction, standardActions ) {
275  mActionManager->createAction( standardAction );
276  }
277 
278  QList<Akonadi::StandardCalendarActionManager::Type> calendarActions;
279  calendarActions << Akonadi::StandardCalendarActionManager::CreateEvent
280  << Akonadi::StandardCalendarActionManager::CreateTodo
281  << Akonadi::StandardCalendarActionManager::CreateSubTodo
282  << Akonadi::StandardCalendarActionManager::CreateJournal
283  << Akonadi::StandardCalendarActionManager::EditIncidence;
284 
285  Q_FOREACH( Akonadi::StandardCalendarActionManager::Type calendarAction, calendarActions ) {
286  mActionManager->createAction( calendarAction );
287  }
288 
289  mActionManager->setCollectionSelectionModel( mCollectionView->selectionModel() );
290 
291  mActionManager->interceptAction( Akonadi::StandardActionManager::CreateResource );
292  mActionManager->interceptAction( Akonadi::StandardActionManager::DeleteResources );
293  mActionManager->interceptAction( Akonadi::StandardActionManager::DeleteCollections );
294 
295  connect( mActionManager->action( Akonadi::StandardActionManager::CreateResource ),
296  SIGNAL(triggered(bool)),
297  this, SLOT(newCalendar()) );
298  connect( mActionManager->action( Akonadi::StandardActionManager::DeleteResources ),
299  SIGNAL(triggered(bool)),
300  this, SLOT(deleteCalendar()) );
301  connect( mActionManager->action( Akonadi::StandardActionManager::DeleteCollections ),
302  SIGNAL(triggered(bool)),
303  this, SLOT(deleteCalendar()) );
304 
305  mActionManager->setContextText( Akonadi::StandardActionManager::CollectionProperties,
306  Akonadi::StandardActionManager::DialogTitle,
307  ki18nc( "@title:window", "Properties of Calendar Folder %1" ) );
308 
309  const QStringList pages =
310  QStringList() << QLatin1String( "CalendarSupport::CollectionGeneralPage" )
311  << QLatin1String( "Akonadi::CachePolicyPage" )
312  << QLatin1String( "PimCommon::CollectionAclPage" );
313 
314  mActionManager->setCollectionPropertiesPageNames( pages );
315 
316  mDisableColor = new KAction( mCollectionView );
317  mDisableColor->setText( i18n( "&Disable Color" ) );
318  mDisableColor->setEnabled( false );
319  xmlclient->actionCollection()->addAction( QString::fromLatin1( "disable_color" ),
320  mDisableColor );
321  connect( mDisableColor, SIGNAL(triggered(bool)), this, SLOT(disableColor()) );
322 
323  mAssignColor = new KAction( mCollectionView );
324  mAssignColor->setText( i18n( "&Assign Color..." ) );
325  mAssignColor->setEnabled( false );
326  xmlclient->actionCollection()->addAction( QString::fromLatin1( "assign_color" ), mAssignColor );
327  connect( mAssignColor, SIGNAL(triggered(bool)), this, SLOT(assignColor()) );
328 
329  mDefaultCalendar = new KAction( mCollectionView );
330  mDefaultCalendar->setText( i18n( "Use as &Default Calendar" ) );
331  mDefaultCalendar->setEnabled( false );
332  xmlclient->actionCollection()->addAction( QString::fromLatin1( "set_standard_calendar" ),
333  mDefaultCalendar );
334  connect( mDefaultCalendar, SIGNAL(triggered(bool)), this, SLOT(setDefaultCalendar()) );
335  }
336 }
337 
338 AkonadiCollectionView::~AkonadiCollectionView()
339 {
340  Akonadi::ETMViewStateSaver treeStateSaver;
341  KConfigGroup group( KOGlobals::self()->config(), "CollectionTreeView" );
342  treeStateSaver.setView( mCollectionView );
343  treeStateSaver.setSelectionModel( 0 ); // we only save expand state
344  treeStateSaver.saveState( group );
345 }
346 
347 void AkonadiCollectionView::restoreTreeState()
348 {
349  static QPointer<Akonadi::ETMViewStateSaver> treeStateRestorer;
350  if ( treeStateRestorer ) {// We don't need more than one to be running at the same time
351  delete treeStateRestorer;
352  }
353  treeStateRestorer = new Akonadi::ETMViewStateSaver(); // not a leak
354  KConfigGroup group( KOGlobals::self()->config(), "CollectionTreeView" );
355  treeStateRestorer->setView( mCollectionView );
356  treeStateRestorer->setSelectionModel( 0 ); // we only restore expand state
357  treeStateRestorer->restoreState( group );
358 }
359 
360 void AkonadiCollectionView::setDefaultCalendar()
361 {
362  QModelIndex index = mCollectionView->selectionModel()->currentIndex(); //selectedRows()
363  Q_ASSERT( index.isValid() );
364  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
365  CalendarSupport::KCalPrefs::instance()->setDefaultCalendarId( collection.id() );
366  CalendarSupport::KCalPrefs::instance()->usrWriteConfig();
367  updateMenu();
368  updateView();
369 
370  emit defaultResourceChanged( collection );
371 }
372 
373 void AkonadiCollectionView::assignColor()
374 {
375  QModelIndex index = mCollectionView->selectionModel()->currentIndex(); //selectedRows()
376  Q_ASSERT( index.isValid() );
377  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
378  Q_ASSERT( collection.isValid() );
379 
380  const QString identifier = QString::number( collection.id() );
381  const QColor defaultColor = KOPrefs::instance()->resourceColor( identifier );
382  QColor myColor;
383  const int result = KColorDialog::getColor( myColor, defaultColor );
384  if ( result == KColorDialog::Accepted && myColor != defaultColor ) {
385  KOPrefs::instance()->setResourceColor( identifier, myColor );
386  emit colorsChanged();
387  updateMenu();
388  updateView();
389  }
390 }
391 
392 void AkonadiCollectionView::disableColor()
393 {
394  QModelIndex index = mCollectionView->selectionModel()->currentIndex(); //selectedRows()
395  Q_ASSERT( index.isValid() );
396  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
397  Q_ASSERT( collection.isValid() );
398  const QString identifier = QString::number( collection.id() );
399  KOPrefs::instance()->setResourceColor( identifier, QColor() );
400  updateMenu();
401  updateView();
402  emit colorsChanged();
403 }
404 
405 void AkonadiCollectionView::setCollectionSelectionProxyModel( KCheckableProxyModel *m )
406 {
407  if ( mSelectionProxyModel == m ) {
408  return;
409  }
410 
411  mSelectionProxyModel = m;
412  if ( !mSelectionProxyModel ) {
413  return;
414  }
415 
416  mBaseModel->setSourceModel( mSelectionProxyModel );
417 }
418 
419 KCheckableProxyModel *AkonadiCollectionView::collectionSelectionProxyModel() const
420 {
421  return mSelectionProxyModel;
422 }
423 
424 Akonadi::EntityTreeView *AkonadiCollectionView::view() const
425 {
426  return mCollectionView;
427 }
428 
429 void AkonadiCollectionView::updateView()
430 {
431  emit resourcesChanged( mSelectionProxyModel ?
432  mSelectionProxyModel->selectionModel()->hasSelection() :
433  false );
434 }
435 
436 void AkonadiCollectionView::updateMenu()
437 {
438  if ( !mHasContextMenu ) {
439  return;
440  }
441  bool enableAction = mCollectionView->selectionModel()->hasSelection();
442  enableAction = enableAction &&
443  ( KOPrefs::instance()->agendaViewColors() != KOPrefs::CategoryOnly );
444  mAssignColor->setEnabled( enableAction );
445  QModelIndex index = mCollectionView->selectionModel()->currentIndex(); //selectedRows()
446 
447  bool disableStuff = false;
448 
449  if ( index.isValid() ) {
450  const Akonadi::Collection collection = CalendarSupport::collectionFromIndex( index );
451  Q_ASSERT( collection.isValid() );
452  if ( !collection.contentMimeTypes().isEmpty() ) {
453  const QString identifier = QString::number( collection.id() );
454  const QColor defaultColor = KOPrefs::instance()->resourceColor( identifier );
455  enableAction = enableAction && defaultColor.isValid();
456  if (collection.remoteId() == QLatin1String("akonadi_birthdays_resource")) {
457  enableAction = false;
458  mAssignColor->setEnabled( enableAction );
459  }
460  mDisableColor->setEnabled( enableAction );
461  mDefaultCalendar->setEnabled( !KOHelper::isStandardCalendar( collection.id() ) &&
462  collection.rights() & Akonadi::Collection::CanCreateItem );
463 
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 
646  if (begin < end) {
647  return;
648  }
649 
650  Akonadi::EntityTreeModel *etm = entityTreeModel();
651  if ( etm && etm->isCollectionTreeFetched() ) {
652  QAbstractItemModel *model = mCollectionView->model();
653  for ( int row = begin; row <= end; ++row ) {
654  QModelIndex index = model->index( row, 0, parent );
655  if ( index.isValid() ) {
656  model->setData( index, Qt::Checked, Qt::CheckStateRole );
657  checkNewCalendar( index, 0, model->rowCount(index) - 1 );
658  }
659  }
660  if ( parent.isValid() ) {
661  mCollectionView->setExpanded( parent, true );
662  }
663  }
664 }
665 
QModelIndex
QWidget
QAbstractItemModel::rowCount
virtual int rowCount(const QModelIndex &parent) const =0
QAbstractItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
koglobals.h
KCheckableProxyModel
AkonadiCollectionView::collectionSelectionProxyModel
KCheckableProxyModel * collectionSelectionProxyModel() const
Definition: akonadicollectionview.cpp:419
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:197
QSortFilterProxyModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
QPainter::strokePath
void strokePath(const QPainterPath &path, const QPen &pen)
QAbstractProxyModel
KOCore::xmlguiClient
KXMLGUIClient * xmlguiClient(QWidget *) const
Definition: kocore.cpp:193
AkonadiCollectionView::colorsChanged
void colorsChanged()
QFont
QList::at
const T & at(int i) const
AkonadiCollectionView::view
Akonadi::EntityTreeView * view() const
Definition: akonadicollectionview.cpp:424
QPainterPath::addRoundedRect
void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
QPointer
AkonadiCollectionViewFactory::create
CalendarViewExtension * create(QWidget *)
Definition: akonadicollectionview.cpp:177
QPainter::save
void save()
QVariant::value
T value() const
QColor::setAlpha
void setAlpha(int alpha)
QWidget::isTopLevel
bool isTopLevel() const
QRect::height
int height() const
AkonadiCollectionViewFactory::collectionView
AkonadiCollectionView * collectionView() const
Definition: akonadicollectionview.cpp:192
QFont::setBold
void setBold(bool enable)
akonadicollectionview.h
QRect
QModelIndex::isValid
bool isValid() const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::number
QString number(int n, int base)
QList::count
int count(const T &value) const
CalendarView
This is the main calendar widget.
Definition: calendarview.h:99
koprefs.h
QPainter::fillPath
void fillPath(const QPainterPath &path, const QBrush &brush)
QStyleOptionViewItem
QObject
QStyledItemDelegate::paint
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
QList::isEmpty
bool isEmpty() const
QPainter
QItemSelectionModel::selectedIndexes
QModelIndexList selectedIndexes() const
AkonadiCollectionViewFactory::view
CalendarView * view() const
Definition: akonadicollectionview.cpp:187
QAbstractProxyModel::setSourceModel
virtual void setSourceModel(QAbstractItemModel *sourceModel)
QVBoxLayout
CalendarViewExtension
Definition: calendarview.h:77
QAbstractItemModel::data
virtual QVariant data(const QModelIndex &index, int role) const =0
QString
QList
QColor
QPen::setColor
void setColor(const QColor &color)
QLayout::setMargin
void setMargin(int margin)
QStringList
AkonadiCollectionView::checkedCollections
Akonadi::Collection::List checkedCollections() const
Definition: akonadicollectionview.cpp:587
QSortFilterProxyModel
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
QPainter::restore
void restore()
QItemSelection
QAbstractProxyModel::sourceModel
QAbstractItemModel * sourceModel() const
AkonadiCollectionView::~AkonadiCollectionView
~AkonadiCollectionView()
Definition: akonadicollectionview.cpp:338
QPainterPath
QRect::width
int width() const
QModelIndex::model
const QAbstractItemModel * model() const
AkonadiCollectionView
This class provides a view of calendar resources.
Definition: akonadicollectionview.h:67
QModelIndex::data
QVariant data(int role) const
AkonadiCollectionView::resourcesChanged
void resourcesChanged(bool enabled)
QLatin1String
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
QRect::adjust
void adjust(int dx1, int dy1, int dx2, int dy2)
KOPrefs::instance
static KOPrefs * instance()
Get instance of KOPrefs.
Definition: koprefs.cpp:68
QAbstractItemModel
QAbstractItemModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
AkonadiCollectionView::isChecked
bool isChecked(const Akonadi::Collection &) const
Definition: akonadicollectionview.cpp:608
QPen
QString::fromLatin1
QString fromLatin1(const char *str, int size)
AkonadiCollectionView::setCollectionSelectionProxyModel
void setCollectionSelectionProxyModel(KCheckableProxyModel *)
Definition: akonadicollectionview.cpp:405
QStyleOptionViewItemV4
QItemSelectionModel
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KOHelper::isStandardCalendar
KORGANIZERPRIVATE_EXPORT bool isStandardCalendar(const Akonadi::Entity::Id &id)
Return true if it's the standard calendar.
Definition: kohelper.cpp:63
QPainter::pen
const QPen & pen() const
QVariant::toString
QString toString() const
KOPrefs::resourceColor
QColor resourceColor(const QString &)
Definition: koprefs.cpp:110
KJob
kocore.h
QBoxLayout::setSpacing
void setSpacing(int spacing)
KOCore::self
static KOCore * self()
Definition: kocore.cpp:37
QSortFilterProxyModel::data
virtual QVariant data(const QModelIndex &index, int role) const
AkonadiCollectionView::defaultResourceChanged
void defaultResourceChanged(const Akonadi::Collection &)
QColor::isValid
bool isValid() const
QVariant
QStyledItemDelegate
Qt::ItemFlags
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:59 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
  • pimprint

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