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

kjots

  • sources
  • kde-4.12
  • kdepim
  • kjots
  • plasmoid
akonotes_noteslistapplet.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "akonotes_noteslistapplet.h"
21 
22 #include <QGraphicsLinearLayout>
23 
24 #include <KConfigDialog>
25 
26 #include <akonadi/changerecorder.h>
27 #include <akonadi/collection.h>
28 #include <akonadi/collectionfilterproxymodel.h>
29 #include <akonadi/entitydisplayattribute.h>
30 #include <akonadi/entitytreemodel.h>
31 #include <akonadi/entityrightsfiltermodel.h>
32 #include <akonadi/itemmodel.h>
33 #include <akonadi/itemfetchscope.h>
34 #include <akonadi/session.h>
35 
36 #include "akonadi_next/note.h"
37 
38 #include "../kjotsmodel.h"
39 #include "plasmatreeview.h"
40 
41 using namespace Akonadi;
42 
43 K_EXPORT_PLASMA_APPLET( akonotes_list, AkonotesListApplet )
44 
45 AkonotesListApplet::AkonotesListApplet(QObject* parent, const QVariantList& args)
46  : PopupApplet(parent, args)
47 {
48 
49  setHasConfigurationInterface( true );
50  setPopupIcon( QLatin1String("kjots") );
51  m_treeView = new PlasmaTreeView;
52 
53  setGraphicsWidget( m_treeView );
54 
55  setBackgroundHints( DefaultBackground );
56 }
57 
58 void AkonotesListApplet::setupModel( Collection::Id id )
59 {
60  // This can be used when it is possible to monitor a non-root collection
61  ItemFetchScope scope;
62  scope.fetchFullPayload( true ); // Need to have full item when adding it to the internal data structure
63  scope.fetchAttribute< EntityDisplayAttribute >();
64 
65  ChangeRecorder *monitor = new ChangeRecorder( this );
66  monitor->fetchCollection( true );
67  monitor->setItemFetchScope( scope );
68 
69  monitor->setCollectionMonitored( Collection( id ) );
70  monitor->setMimeTypeMonitored( Akonotes::Note::mimeType() );
71 
72  EntityTreeModel *model = new KJotsModel( monitor, this );
73  model->setCollectionFetchStrategy( EntityTreeModel::FetchNoCollections );
74 
75  m_treeView->setModel( model );
76 }
77 
78 void AkonotesListApplet::init()
79 {
80  KConfigGroup cg = config();
81  Collection::Id rootCollectionId = cg.readEntry("rootCollection", -1);
82 
83  if ( rootCollectionId < 0 )
84  {
85  setConfigurationRequired( true, i18n("This widget needs to be configured.") );
86  return;
87  }
88 
89  setupModel( rootCollectionId );
90 }
91 
92 
93 void AkonotesListApplet::createConfigurationInterface(KConfigDialog *configDialog)
94 {
95  QWidget *widget = new QWidget();
96  ui.setupUi(widget);
97  configDialog->addPage(widget, i18n("Selected Collection"), QLatin1String("view-media-visualization"));
98 
99  ui.treeView->header()->hide();
100 
101  // TODO: Refactor into a collection chooser widget.
102  Akonadi::ChangeRecorder *monitor = new Akonadi::ChangeRecorder( this );
103  monitor->fetchCollection( true );
104  monitor->setMimeTypeMonitored( Akonotes::Note::mimeType(), true );
105  monitor->setCollectionMonitored( Akonadi::Collection::root() );
106 
107  EntityTreeModel *model = new EntityTreeModel( monitor, this );
108  model->setItemPopulationStrategy( EntityTreeModel::NoItemPopulation );
109 
110  CollectionFilterProxyModel *mimeTypeFilterModel = new CollectionFilterProxyModel( this );
111  mimeTypeFilterModel->addMimeTypeFilter( Akonotes::Note::mimeType() );
112  mimeTypeFilterModel->setSourceModel( model );
113 
114  EntityRightsFilterModel *rightsFilterModel = new EntityRightsFilterModel( this );
115  rightsFilterModel->setSourceModel( mimeTypeFilterModel );
116 
117  ui.treeView->setModel(rightsFilterModel);
118 
119  connect(configDialog, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
120  connect(configDialog, SIGNAL(okClicked()), this, SLOT(configAccepted()));
121 }
122 
123 void AkonotesListApplet::configAccepted()
124 {
125  KConfigGroup cg = config();
126 
127  QModelIndexList rows = ui.treeView->selectionModel()->selectedRows();
128 
129  if ( rows.isEmpty() )
130  return;
131 
132  Q_ASSERT( rows.size() == 1 );
133 
134  Collection col = rows.at( 0 ).data( EntityTreeModel::CollectionRole ).value<Collection>();
135 
136  cg.writeEntry( "rootCollection", col.id() );
137 
138  setupModel( col.id() );
139 
140  setConfigurationRequired( false );
141 
142  emit configNeedsSaving();
143 }
144 
145 
146 
147 
148 #include "akonotes_noteslistapplet.moc"
AkonotesListApplet::createConfigurationInterface
void createConfigurationInterface(KConfigDialog *parent)
Definition: akonotes_noteslistapplet.cpp:93
AkonotesListApplet
Definition: akonotes_noteslistapplet.h:37
AkonotesListApplet::configAccepted
void configAccepted()
Definition: akonotes_noteslistapplet.cpp:123
QWidget
EntityTreeModel
QObject
akonotes_noteslistapplet.h
KJotsModel
Definition: kjotsmodel.h:74
AkonotesListApplet::init
void init()
Definition: akonotes_noteslistapplet.cpp:78
Akonadi::PlasmaTreeView
Provides a plasma-themed Akonadi::EntityTreeView.
Definition: plasmatreeview.h:38
plasmatreeview.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kjots

Skip menu "kjots"
  • Main Page
  • Namespace List
  • 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