• 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
  • collectionpage
collectionmaintenancepage.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2  This file is part of KMail, the KDE mail client.
3  Copyright (c) 2009-2010 Montel Laurent <montel@kde.org>
4 
5  KMail is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License, version 2, as
7  published by the Free Software Foundation.
8 
9  KMail is distributed in the hope that it will be useful, but
10  WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "collectionmaintenancepage.h"
20 #include "util/mailutil.h"
21 #include "kmkernel.h"
22 
23 #include <akonadi/collectionstatistics.h>
24 #include <akonadi/collection.h>
25 #include <Akonadi/AgentManager>
26 #include <Akonadi/ChangeRecorder>
27 
28 #include <Soprano/Vocabulary/NAO>
29 #include <Nepomuk2/Variant>
30 #include <Nepomuk2/ResourceManager>
31 #include <nepomuk2/datamanagement.h>
32 
33 #include <QDBusInterface>
34 #include <QDBusConnectionInterface>
35 
36 #include <QLabel>
37 #include <KDialog>
38 #include <QGroupBox>
39 #include <KLocale>
40 #include <KPushButton>
41 #include <QFormLayout>
42 #include <kio/global.h>
43 #include <QCheckBox>
44 #include <akonadi/indexpolicyattribute.h>
45 
46 using namespace Akonadi;
47 
48 
49 CollectionMaintenancePage::CollectionMaintenancePage(QWidget * parent) :
50  CollectionPropertiesPage( parent ), mIsNotAVirtualCollection( true ), mFolderSizeLabel(0), mCollectionCount(0)
51 {
52  setObjectName( QLatin1String( "KMail::CollectionMaintenancePage" ) );
53  setPageTitle( i18n("Maintenance") );
54 }
55 
56 void CollectionMaintenancePage::init(const Akonadi::Collection & col)
57 {
58  mCurrentCollection = col;
59 
60  QVBoxLayout *topLayout = new QVBoxLayout( this );
61  topLayout->setSpacing( KDialog::spacingHint() );
62  topLayout->setMargin( KDialog::marginHint() );
63  QGroupBox *filesGroup = new QGroupBox( i18n("Files"), this );
64  QFormLayout *box = new QFormLayout( filesGroup );
65  box->setSpacing( KDialog::spacingHint() );
66  mIsNotAVirtualCollection = !MailCommon::Util::isVirtualCollection( col );
67  connect( KMKernel::self()->folderCollectionMonitor(), SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)), this, SLOT(updateCollectionStatistic(Akonadi::Collection::Id,Akonadi::CollectionStatistics)) );
68 
69  const AgentInstance instance = Akonadi::AgentManager::self()->instance( col.resource() );
70  const QString folderDesc = instance.type().name();
71 
72  if ( mIsNotAVirtualCollection ) {
73  QLabel *label = new QLabel( folderDesc, filesGroup );
74  box->addRow( new QLabel( i18n("Folder type:"), filesGroup ), label );
75  }
76 
77  mFolderSizeLabel = new QLabel( i18nc( "folder size", "Not available" ), filesGroup );
78  box->addRow( new QLabel( i18n("Size:"), filesGroup ), mFolderSizeLabel );
79 
80  topLayout->addWidget( filesGroup );
81 
82  QGroupBox *messagesGroup = new QGroupBox( i18n("Messages"), this);
83  box = new QFormLayout( messagesGroup );
84  box->setSpacing( KDialog::spacingHint() );
85 
86  mCollectionCount = new QLabel( messagesGroup );
87  box->addRow( new QLabel( i18n("Total messages:"), messagesGroup ), mCollectionCount );
88 
89  mCollectionUnread = new QLabel( messagesGroup );
90  box->addRow( new QLabel( i18n("Unread messages:"), messagesGroup ), mCollectionUnread );
91 
92  topLayout->addWidget( messagesGroup );
93 
94  QGroupBox *indexingGroup = new QGroupBox( i18n( "Indexing" ), this );
95  QVBoxLayout *indexingLayout = new QVBoxLayout( indexingGroup );
96  mIndexingEnabled = new QCheckBox( i18n( "Enable Full Text Indexing" ) );
97  indexingLayout->addWidget( mIndexingEnabled );
98 
99  mLastIndexed = new QLabel( i18n( "Still not indexed." ) );
100 
101  indexingLayout->addWidget( mLastIndexed );
102 
103  KPushButton *forceReindex = new KPushButton(i18n("Force reindexing"));
104  indexingLayout->addWidget( forceReindex );
105 
106  if(!Nepomuk2::ResourceManager::instance()->initialized()) {
107  mLastIndexed->hide();
108  forceReindex->setEnabled(false);
109  } else {
110  connect(forceReindex,SIGNAL(clicked()),SLOT(slotReindexing()));
111  }
112 
113  topLayout->addWidget( indexingGroup );
114 
115  topLayout->addStretch( 100 );
116 }
117 
118 void CollectionMaintenancePage::load(const Collection & col)
119 {
120  init( col );
121  if ( col.isValid() ) {
122  updateLabel( col.statistics().count(), col.statistics().unreadCount(), col.statistics().size() );
123  Akonadi::IndexPolicyAttribute *attr = col.attribute<Akonadi::IndexPolicyAttribute>();
124  const bool indexingWasEnabled(!attr || attr->indexingEnabled());
125  mIndexingEnabled->setChecked( indexingWasEnabled );
126  if(!indexingWasEnabled)
127  mLastIndexed->hide();
128  else {
129  const KUrl url = col.url( Akonadi::Collection::UrlShort );
130  if(!url.isEmpty()) {
131  const Nepomuk2::Resource parentResource( url );
132  const QDateTime dt = parentResource.property( Soprano::Vocabulary::NAO::lastModified() ).toDateTime();
133  KDateTime localTime(dt, KDateTime::LocalZone);
134  if(localTime.isValid()) {
135  mLastIndexed->setText(i18n("Folder was indexed: %1",KGlobal::locale()->formatDateTime(localTime)));
136  }
137  }
138  }
139  }
140 }
141 
142 void CollectionMaintenancePage::updateLabel( qint64 nbMail, qint64 nbUnreadMail, qint64 size )
143 {
144  mCollectionCount->setText( QString::number( qMax( 0LL, nbMail ) ) );
145  mCollectionUnread->setText( QString::number( qMax( 0LL, nbUnreadMail ) ) );
146  mFolderSizeLabel->setText( KGlobal::locale()->formatByteSize( qMax( 0LL, size ) ) );
147 
148 }
149 
150 void CollectionMaintenancePage::save(Collection &collection )
151 {
152  if ( !collection.hasAttribute<Akonadi::IndexPolicyAttribute>() && mIndexingEnabled->isChecked() )
153  return;
154  Akonadi::IndexPolicyAttribute *attr = collection.attribute<Akonadi::IndexPolicyAttribute>( Akonadi::Collection::AddIfMissing );
155  if( mIndexingEnabled->isChecked() )
156  attr->setIndexingEnabled( true );
157  else {
158  attr->setIndexingEnabled( false );
159  Nepomuk2::removeResources( QList <QUrl>() << collection.url() );
160  }
161 }
162 
163 void CollectionMaintenancePage::updateCollectionStatistic(Akonadi::Collection::Id id, const Akonadi::CollectionStatistics& statistic)
164 {
165  if ( id == mCurrentCollection.id() ) {
166  updateLabel( statistic.count(), statistic.unreadCount(), statistic.size() );
167  }
168 }
169 
170 void CollectionMaintenancePage::slotReindexing()
171 {
172  //Be sure to remove collection resources before to reindex.
173  Nepomuk2::removeResources( QList <QUrl>() << mCurrentCollection.url() );
174  QDBusInterface interfaceNepomukFeeder( QLatin1String("org.freedesktop.Akonadi.Agent.akonadi_nepomuk_feeder"), QLatin1String("/") );
175  if(interfaceNepomukFeeder.isValid()) {
176  interfaceNepomukFeeder.asyncCall(QLatin1String("forceReindexCollection"),(qlonglong)mCurrentCollection.id());
177  }
178 }
179 
180 #include "collectionmaintenancepage.moc"
QWidget
collectionmaintenancepage.h
KMKernel::self
static KMKernel * self()
normal control stuff
Definition: kmkernel.cpp:1451
CollectionMaintenancePage::CollectionMaintenancePage
CollectionMaintenancePage(QWidget *parent=0)
Definition: collectionmaintenancepage.cpp:49
CollectionMaintenancePage::slotReindexing
void slotReindexing()
Definition: collectionmaintenancepage.cpp:170
CollectionMaintenancePage::save
void save(Akonadi::Collection &col)
Definition: collectionmaintenancepage.cpp:150
kmkernel.h
CollectionMaintenancePage::updateCollectionStatistic
void updateCollectionStatistic(Akonadi::Collection::Id, const Akonadi::CollectionStatistics &)
Definition: collectionmaintenancepage.cpp:163
QLabel
CollectionMaintenancePage::load
void load(const Akonadi::Collection &col)
Definition: collectionmaintenancepage.cpp:118
CollectionMaintenancePage::init
void init(const Akonadi::Collection &)
Definition: collectionmaintenancepage.cpp:56
QList
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