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

kmail

  • sources
  • kde-4.14
  • 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-2015 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 <QDBusInterface>
29 #include <QDBusConnectionInterface>
30 
31 #include <KDialog>
32 #include <KLocalizedString>
33 #include <KLocale>
34 #include <KPushButton>
35 #include <kio/global.h>
36 #include <KLocale>
37 
38 #include <QGroupBox>
39 #include <QLabel>
40 #include <QFormLayout>
41 #include <QCheckBox>
42 #include <akonadi/indexpolicyattribute.h>
43 
44 using namespace Akonadi;
45 
46 
47 CollectionMaintenancePage::CollectionMaintenancePage(QWidget * parent) :
48  CollectionPropertiesPage( parent ),
49  mIsNotAVirtualCollection( true ),
50  mFolderSizeLabel(0),
51  mCollectionCount(0)
52 {
53  setObjectName( QLatin1String( "KMail::CollectionMaintenancePage" ) );
54  setPageTitle( i18n("Maintenance") );
55 }
56 
57 void CollectionMaintenancePage::init(const Akonadi::Collection & col)
58 {
59  mCurrentCollection = col;
60 
61  QVBoxLayout *topLayout = new QVBoxLayout( this );
62  topLayout->setSpacing( KDialog::spacingHint() );
63  topLayout->setMargin( KDialog::marginHint() );
64  QGroupBox *filesGroup = new QGroupBox( i18n("Files"), this );
65  QFormLayout *box = new QFormLayout( filesGroup );
66  box->setSpacing( KDialog::spacingHint() );
67  mIsNotAVirtualCollection = !MailCommon::Util::isVirtualCollection( col );
68  connect( KMKernel::self()->folderCollectionMonitor(), SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)), this, SLOT(updateCollectionStatistic(Akonadi::Collection::Id,Akonadi::CollectionStatistics)) );
69 
70  const AgentInstance instance = Akonadi::AgentManager::self()->instance( col.resource() );
71  const QString folderDesc = instance.type().name();
72 
73  if ( mIsNotAVirtualCollection ) {
74  QLabel *label = new QLabel( folderDesc, filesGroup );
75  box->addRow( new QLabel( i18n("Folder type:"), filesGroup ), label );
76  }
77 
78  mFolderSizeLabel = new QLabel( i18nc( "folder size", "Not available" ), filesGroup );
79  box->addRow( new QLabel( i18n("Size:"), filesGroup ), mFolderSizeLabel );
80 
81  topLayout->addWidget( filesGroup );
82 
83  QGroupBox *messagesGroup = new QGroupBox( i18n("Messages"), this);
84  box = new QFormLayout( messagesGroup );
85  box->setSpacing( KDialog::spacingHint() );
86 
87  mCollectionCount = new QLabel( messagesGroup );
88  box->addRow( new QLabel( i18n("Total messages:"), messagesGroup ), mCollectionCount );
89 
90  mCollectionUnread = new QLabel( messagesGroup );
91  box->addRow( new QLabel( i18n("Unread messages:"), messagesGroup ), mCollectionUnread );
92 
93  topLayout->addWidget( messagesGroup );
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  topLayout->addWidget( indexingGroup );
103  topLayout->addStretch( 100 );
104 }
105 
106 void CollectionMaintenancePage::load(const Collection & col)
107 {
108  init( col );
109  if ( col.isValid() ) {
110  updateLabel( col.statistics().count(), col.statistics().unreadCount(), col.statistics().size() );
111  Akonadi::IndexPolicyAttribute *attr = col.attribute<Akonadi::IndexPolicyAttribute>();
112  const bool indexingWasEnabled(!attr || attr->indexingEnabled());
113  mIndexingEnabled->setChecked( indexingWasEnabled );
114  if(!indexingWasEnabled)
115  mLastIndexed->hide();
116  else {
117  QDBusInterface interfaceBalooIndexer( QLatin1String("org.freedesktop.Akonadi.Agent.akonadi_baloo_indexer"), QLatin1String("/") );
118  if(interfaceBalooIndexer.isValid()) {
119  if (!interfaceBalooIndexer.callWithCallback(QLatin1String("indexedItems"), QList<QVariant>() << (qlonglong)mCurrentCollection.id(), this, SLOT(onIndexedItemsReceived(qint64)))) {
120  kWarning() << "Failed to request indexed items";
121  }
122  }
123  }
124  }
125 }
126 
127 void CollectionMaintenancePage::onIndexedItemsReceived(qint64 num)
128 {
129  kDebug() << num;
130  if (num == 0) {
131  mLastIndexed->clear();
132  } else {
133  mLastIndexed->setText(i18np("Indexed %1 item of this collection", "Indexed %1 items of this collection", num));
134  }
135 }
136 
137 void CollectionMaintenancePage::updateLabel( qint64 nbMail, qint64 nbUnreadMail, qint64 size )
138 {
139  mCollectionCount->setText( QString::number( qMax( 0LL, nbMail ) ) );
140  mCollectionUnread->setText( QString::number( qMax( 0LL, nbUnreadMail ) ) );
141  mFolderSizeLabel->setText( KGlobal::locale()->formatByteSize( qMax( 0LL, size ) ) );
142 }
143 
144 void CollectionMaintenancePage::save(Collection &collection)
145 {
146  if ( !collection.hasAttribute<Akonadi::IndexPolicyAttribute>() && mIndexingEnabled->isChecked() )
147  return;
148  Akonadi::IndexPolicyAttribute *attr = collection.attribute<Akonadi::IndexPolicyAttribute>( Akonadi::Collection::AddIfMissing );
149  if( mIndexingEnabled->isChecked() )
150  attr->setIndexingEnabled( true );
151  else {
152  attr->setIndexingEnabled( false );
153  }
154 }
155 
156 void CollectionMaintenancePage::updateCollectionStatistic(Akonadi::Collection::Id id, const Akonadi::CollectionStatistics& statistic)
157 {
158  if ( id == mCurrentCollection.id() ) {
159  updateLabel( statistic.count(), statistic.unreadCount(), statistic.size() );
160  }
161 }
QWidget
QDBusAbstractInterface::isValid
bool isValid() const
QLabel::clear
void clear()
collectionmaintenancepage.h
KMKernel::self
static KMKernel * self()
normal control stuff
Definition: kmkernel.cpp:1471
QFormLayout::setSpacing
void setSpacing(int spacing)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::number
QString number(int n, int base)
CollectionMaintenancePage::CollectionMaintenancePage
CollectionMaintenancePage(QWidget *parent=0)
Definition: collectionmaintenancepage.cpp:47
QGroupBox
QCheckBox
CollectionMaintenancePage::save
void save(Akonadi::Collection &col)
Definition: collectionmaintenancepage.cpp:144
QVBoxLayout
QLabel::setText
void setText(const QString &)
QString
QList
QWidget::hide
void hide()
QLayout::setMargin
void setMargin(int margin)
QFormLayout::addRow
void addRow(QWidget *label, QWidget *field)
QDBusInterface
QAbstractButton::setChecked
void setChecked(bool)
kmkernel.h
CollectionMaintenancePage::updateCollectionStatistic
void updateCollectionStatistic(Akonadi::Collection::Id, const Akonadi::CollectionStatistics &)
Definition: collectionmaintenancepage.cpp:156
QLatin1String
QBoxLayout::addStretch
void addStretch(int stretch)
QDBusAbstractInterface::callWithCallback
bool callWithCallback(const QString &method, const QList< QVariant > &args, QObject *receiver, const char *returnMethod, const char *errorMethod)
CollectionMaintenancePage::load
void load(const Akonadi::Collection &col)
Definition: collectionmaintenancepage.cpp:106
QLabel
CollectionMaintenancePage::init
void init(const Akonadi::Collection &)
Definition: collectionmaintenancepage.cpp:57
QBoxLayout::setSpacing
void setSpacing(int spacing)
QFormLayout
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:32 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
  • 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