Commit 847be2b6 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Import CollectionMaintenancePage from KMail

Rewrote to use PIMPL, .ui and fixed the wording - use "folder" instead
of "collection" (which is an implementation detail), use "item" instead
of "message", because the page can be used on non-mail collections
too.
parent d24149ff
cmake_minimum_required(VERSION 3.0)
set(PIM_VERSION "5.5.41")
set(PIM_VERSION "5.5.42")
project(Akonadi VERSION ${PIM_VERSION})
......
......@@ -8,6 +8,7 @@ set(akonadiwidgets_SRCS
collectioncombobox.cpp
collectiondialog.cpp
collectiongeneralpropertiespage.cpp
collectionmaintenancepage.cpp
collectionpropertiesdialog.cpp
collectionpropertiespage.cpp
collectionrequester.cpp
......@@ -39,13 +40,14 @@ ecm_qt_declare_logging_category(akonadiwidgets_SRCS HEADER akonadiwidgets_debug.
set(akonadiwidgets_UI
cachepolicypage.ui
collectiongeneralpropertiespage.ui
collectionmaintenancepage.ui
controlprogressindicator.ui
erroroverlay.ui
manageaccountwidget.ui
selftestdialog.ui
selftestdialog.ui
)
ecm_generate_headers(AkonadiWidgets_HEADERS
HEADER_NAMES
AgentActionManager
......@@ -56,6 +58,7 @@ ecm_generate_headers(AkonadiWidgets_HEADERS
CollectionDialog
CollectionPropertiesDialog
CollectionPropertiesPage
CollectionMaintenancePage
CollectionRequester
CollectionStatisticsDelegate
CollectionView
......@@ -76,11 +79,6 @@ ecm_generate_headers(AkonadiWidgets_HEADERS
REQUIRED_HEADERS AkonadiWidgets_HEADERS
)
set(akonadiwidgets_UI
${akonadiwidgets_UI}
collectiongeneralpropertiespage.ui
)
ki18n_wrap_ui(akonadiwidgets_SRCS ${akonadiwidgets_UI})
add_library(KF5AkonadiWidgets ${akonadiwidgets_SRCS})
......
/*
Copyright (C) 2009-2017 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "collectionmaintenancepage.h"
#include "ui_collectionmaintenancepage.h"
#include "core/collectionstatistics.h"
#include "monitor.h"
#include "agentmanager.h"
#include "akonadiwidgets_debug.h"
#include "indexpolicyattribute.h"
#include "cachepolicy.h"
#include <QDBusInterface>
#include <QDBusConnectionInterface>
#include <QDialog>
#include <QPushButton>
#include <KLocalizedString>
#include <QGroupBox>
#include <QLabel>
#include <QFormLayout>
#include <QCheckBox>
#include <KFormat>
#include <KConfigGroup>
using namespace Akonadi;
class CollectionMaintenancePage::Private
{
public:
Private(CollectionMaintenancePage *q)
: q(q)
{}
void slotReindexCollection()
{
if (currentCollection.isValid()) {
//Don't allow to reindex twice.
ui.reindexButton->setEnabled(false);
QDBusInterface indexingAgentIface(QStringLiteral("org.freedesktop.Akonadi.Agent.akonadi_indexing_agent"),
QStringLiteral("/"),
QStringLiteral("org.freedesktop.Akonadi.Indexer"));
if (indexingAgentIface.isValid()) {
indexingAgentIface.call(QStringLiteral("reindexCollection"), (qlonglong)currentCollection.id());
ui.indexedCountLbl->setText(i18n("Remember that indexing can take some minutes."));
} else {
qCWarning(AKONADIWIDGETS_LOG) << "indexer interface not valid";
}
}
}
void updateLabel(qint64 nbMail, qint64 nbUnreadMail, qint64 size)
{
ui.itemsCountLbl->setText(QString::number(qMax(0LL, nbMail)));
ui.unreadItemsCountLbl->setText(QString::number(qMax(0LL, nbUnreadMail)));
ui.folderSizeLbl->setText(KFormat().formatByteSize(qMax(0LL, size)));
}
Akonadi::Collection currentCollection;
Akonadi::Monitor *monitor;
Ui::CollectionMaintenancePage ui;
private:
CollectionMaintenancePage * const q;
};
CollectionMaintenancePage::CollectionMaintenancePage(QWidget *parent)
: CollectionPropertiesPage(parent)
, d(new Private(this))
{
setObjectName(QStringLiteral("KMail::CollectionMaintenancePage"));
setPageTitle(i18n("Maintenance"));
}
CollectionMaintenancePage::~CollectionMaintenancePage()
{
delete d;
}
void CollectionMaintenancePage::init(const Collection &col)
{
d->ui.setupUi(this);
d->currentCollection = col;
d->monitor = new Monitor(this);
d->monitor->setCollectionMonitored(col, true);
d->monitor->fetchCollectionStatistics(true);
connect(d->monitor, &Monitor::collectionStatisticsChanged,
this, [this](Collection::Id, const CollectionStatistics &stats) {
d->updateLabel(stats.count(), stats.unreadCount(), stats.size());
});
if (!col.isVirtual()) {
const AgentInstance instance = Akonadi::AgentManager::self()->instance(col.resource());
d->ui.folderTypeLbl->setText(instance.type().name());
} else {
d->ui.folderTypeLbl->hide();
d->ui.filesLayout->labelForField(d->ui.folderTypeLbl)->hide();
}
connect(d->ui.reindexButton, &QPushButton::clicked,
this, [this]() { d->slotReindexCollection(); });
// Check if the resource caches full payloads or at least has local storage
// (so that the indexer can retrieve the payloads on demand)
const auto resource = Akonadi::AgentManager::self()->instance(col.resource()).type();
if (!col.cachePolicy().localParts().contains(QStringLiteral("RFC822"))
&& resource.customProperties().value(QStringLiteral("HasLocalStorage"), QString()) != QLatin1String("true")) {
d->ui.indexingGroup->hide();
}
}
void CollectionMaintenancePage::load(const Collection &col)
{
init(col);
if (col.isValid()) {
d->updateLabel(col.statistics().count(), col.statistics().unreadCount(), col.statistics().size());
Akonadi::IndexPolicyAttribute *attr = col.attribute<Akonadi::IndexPolicyAttribute>();
const bool indexingWasEnabled(!attr || attr->indexingEnabled());
d->ui.enableIndexingChkBox->setChecked(indexingWasEnabled);
if (!indexingWasEnabled) {
d->ui.indexedCountLbl->hide();
} else {
QDBusInterface indexingAgentIface(QStringLiteral("org.freedesktop.Akonadi.Agent.akonadi_indexing_agent"),
QStringLiteral("/"),
QStringLiteral("org.freedesktop.Akonadi.Indexer"));
if (indexingAgentIface.isValid()) {
auto reply = indexingAgentIface.asyncCall(QStringLiteral("indexedItems"), (qlonglong) col.id());
auto w = new QDBusPendingCallWatcher(reply, this);
connect(w, &QDBusPendingCallWatcher::finished,
this, [this](QDBusPendingCallWatcher *w) {
QDBusPendingReply<qlonglong> reply = *w;
if (reply.isError()) {
d->ui.indexedCountLbl->setText(i18n("Error while retrieving indexed items count"));
qCWarning(AKONADIWIDGETS_LOG) << "Failed to retrieve indexed items count:" << reply.error().message();
} else {
d->ui.indexedCountLbl->setText(i18np("Indexed %1 item in this folder",
"Indexed %1 items in this folder",
reply.argumentAt<0>()));
}
w->deleteLater();
});
d->ui.indexedCountLbl->setText(i18n("Calculating indexed items..."));
} else {
qCDebug(AKONADIWIDGETS_LOG) << "Failed to obtain Indexer interface";
d->ui.indexedCountLbl->hide();
}
}
}
}
void CollectionMaintenancePage::save(Collection &collection)
{
if (!collection.hasAttribute<Akonadi::IndexPolicyAttribute>() && d->ui.enableIndexingChkBox->isChecked()) {
return;
}
Akonadi::IndexPolicyAttribute *attr = collection.attribute<Akonadi::IndexPolicyAttribute>(Akonadi::Collection::AddIfMissing);
attr->setIndexingEnabled(d->ui.enableIndexingChkBox->isChecked());
}
/*
Copyright (C) 2009-2017 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef AKONADI_COLLECTIONMAINTENANCEPAGE_H
#define AKONADI_COLLECTIONMAINTENANCEPAGE_H
#include "akonadiwidgets_export.h"
#include "collectionpropertiespage.h"
namespace Akonadi
{
class AKONADIWIDGETS_EXPORT CollectionMaintenancePage : public Akonadi::CollectionPropertiesPage
{
Q_OBJECT
public:
explicit CollectionMaintenancePage(QWidget *parent = nullptr);
~CollectionMaintenancePage() Q_DECL_OVERRIDE;
void load(const Akonadi::Collection &col) Q_DECL_OVERRIDE;
void save(Akonadi::Collection &col) Q_DECL_OVERRIDE;
protected:
void init(const Akonadi::Collection &);
private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
};
AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY(CollectionMaintenancePageFactory, CollectionMaintenancePage)
}
#endif /* COLLECTIONMAINTENANCEPAGE_H */
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CollectionMaintenancePage</class>
<widget class="QWidget" name="CollectionMaintenancePage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>468</width>
<height>371</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="filesGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Files</string>
</property>
<layout class="QFormLayout" name="filesLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Folder type:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="folderTypeLbl">
<property name="text">
<string>uknown</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="folderSizeLbl">
<property name="text">
<string>unknown</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="itemsGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Items</string>
</property>
<layout class="QFormLayout" name="itemsLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Total items:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="itemsCountLbl">
<property name="text">
<string>unknown</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Unread items:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="unreadItemsCountLbl">
<property name="text">
<string>unknown</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="indexingGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Indexing</string>
</property>
<layout class="QVBoxLayout" name="indexingLayout">
<item>
<widget class="QCheckBox" name="enableIndexingChkBox">
<property name="text">
<string>Enable fulltext indexing</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="indexedCountLbl">
<property name="text">
<string>Retrieving indexed items count ...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="reindexButton">
<property name="text">
<string>Reindex folder</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment