20 #include "util/mailutil.h"
23 #include <akonadi/collectionstatistics.h>
24 #include <akonadi/collection.h>
25 #include <Akonadi/AgentManager>
26 #include <Akonadi/ChangeRecorder>
28 #include <Soprano/Vocabulary/NAO>
29 #include <Nepomuk2/Variant>
30 #include <Nepomuk2/ResourceManager>
31 #include <nepomuk2/datamanagement.h>
33 #include <QDBusInterface>
34 #include <QDBusConnectionInterface>
40 #include <KPushButton>
41 #include <QFormLayout>
42 #include <kio/global.h>
44 #include <akonadi/indexpolicyattribute.h>
46 using namespace Akonadi;
50 CollectionPropertiesPage( parent ), mIsNotAVirtualCollection( true ), mFolderSizeLabel(0), mCollectionCount(0)
52 setObjectName( QLatin1String(
"KMail::CollectionMaintenancePage" ) );
53 setPageTitle( i18n(
"Maintenance") );
58 mCurrentCollection = col;
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)) );
69 const AgentInstance instance = Akonadi::AgentManager::self()->instance( col.resource() );
70 const QString folderDesc = instance.type().name();
72 if ( mIsNotAVirtualCollection ) {
74 box->addRow(
new QLabel( i18n(
"Folder type:"), filesGroup ), label );
77 mFolderSizeLabel =
new QLabel( i18nc(
"folder size",
"Not available" ), filesGroup );
78 box->addRow(
new QLabel( i18n(
"Size:"), filesGroup ), mFolderSizeLabel );
80 topLayout->addWidget( filesGroup );
82 QGroupBox *messagesGroup =
new QGroupBox( i18n(
"Messages"),
this);
83 box =
new QFormLayout( messagesGroup );
84 box->setSpacing( KDialog::spacingHint() );
86 mCollectionCount =
new QLabel( messagesGroup );
87 box->addRow(
new QLabel( i18n(
"Total messages:"), messagesGroup ), mCollectionCount );
89 mCollectionUnread =
new QLabel( messagesGroup );
90 box->addRow(
new QLabel( i18n(
"Unread messages:"), messagesGroup ), mCollectionUnread );
92 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 );
99 mLastIndexed =
new QLabel( i18n(
"Still not indexed." ) );
101 indexingLayout->addWidget( mLastIndexed );
103 KPushButton *forceReindex =
new KPushButton(i18n(
"Force reindexing"));
104 indexingLayout->addWidget( forceReindex );
106 if(!Nepomuk2::ResourceManager::instance()->initialized()) {
107 mLastIndexed->hide();
108 forceReindex->setEnabled(
false);
113 topLayout->addWidget( indexingGroup );
115 topLayout->addStretch( 100 );
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();
129 const KUrl url = col.url( Akonadi::Collection::UrlShort );
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)));
142 void CollectionMaintenancePage::updateLabel( qint64 nbMail, qint64 nbUnreadMail, qint64 size )
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 ) ) );
152 if ( !collection.hasAttribute<Akonadi::IndexPolicyAttribute>() && mIndexingEnabled->isChecked() )
154 Akonadi::IndexPolicyAttribute *attr = collection.attribute<Akonadi::IndexPolicyAttribute>( Akonadi::Collection::AddIfMissing );
155 if( mIndexingEnabled->isChecked() )
156 attr->setIndexingEnabled(
true );
158 attr->setIndexingEnabled(
false );
159 Nepomuk2::removeResources(
QList <QUrl>() << collection.url() );
165 if (
id == mCurrentCollection.id() ) {
166 updateLabel( statistic.count(), statistic.unreadCount(), statistic.size() );
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());
180 #include "collectionmaintenancepage.moc"
static KMKernel * self()
normal control stuff
CollectionMaintenancePage(QWidget *parent=0)
void save(Akonadi::Collection &col)
void updateCollectionStatistic(Akonadi::Collection::Id, const Akonadi::CollectionStatistics &)
void load(const Akonadi::Collection &col)
void init(const Akonadi::Collection &)