File indexing completed on 2024-05-19 05:14:38
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "manageshowcollectionproperties.h" 0008 #include "kaddressbook_debug.h" 0009 #include "mainwidget.h" 0010 #include <PimCommonAkonadi/CollectionAclPage> 0011 0012 #include <Akonadi/CollectionAttributesSynchronizationJob> 0013 #include <Akonadi/CollectionFetchJob> 0014 #include <Akonadi/CollectionFetchScope> 0015 #include <Akonadi/CollectionMaintenancePage> 0016 #include <Akonadi/CollectionPropertiesDialog> 0017 0018 #include <KLocalizedString> 0019 0020 ManageShowCollectionProperties::ManageShowCollectionProperties(MainWidget *mainWidget, QObject *parent) 0021 : QObject(parent) 0022 , mMainWidget(mainWidget) 0023 { 0024 static bool pageRegistered = false; 0025 0026 if (!pageRegistered) { 0027 Akonadi::CollectionPropertiesDialog::registerPage(new PimCommon::CollectionAclPageFactory); 0028 Akonadi::CollectionPropertiesDialog::registerPage(new Akonadi::CollectionMaintenancePageFactory); 0029 pageRegistered = true; 0030 } 0031 mPages = QStringList() << QStringLiteral("Akonadi::CollectionGeneralPropertiesPage") << QStringLiteral("Akonadi::CachePolicyPage") 0032 << QStringLiteral("PimCommon::CollectionAclPage") << QStringLiteral("Akonadi::CollectionMaintenancePage"); 0033 } 0034 0035 ManageShowCollectionProperties::~ManageShowCollectionProperties() = default; 0036 0037 void ManageShowCollectionProperties::showCollectionProperties() 0038 { 0039 const Akonadi::Collection col = mMainWidget->currentAddressBook(); 0040 const Akonadi::Collection::Id id = col.id(); 0041 QPointer<Akonadi::CollectionPropertiesDialog> dlg = mHashDialogBox.value(id); 0042 if (dlg) { 0043 dlg->activateWindow(); 0044 dlg->raise(); 0045 return; 0046 } 0047 auto sync = new Akonadi::CollectionAttributesSynchronizationJob(col); 0048 sync->setProperty("collectionId", id); 0049 connect(sync, &KJob::result, this, &ManageShowCollectionProperties::slotCollectionPropertiesContinued); 0050 sync->start(); 0051 } 0052 0053 void ManageShowCollectionProperties::slotCollectionPropertiesContinued(KJob *job) 0054 { 0055 if (job) { 0056 auto sync = qobject_cast<Akonadi::CollectionAttributesSynchronizationJob *>(job); 0057 Q_ASSERT(sync); 0058 if (sync->property("collectionId") != mMainWidget->currentAddressBook().id()) { 0059 return; 0060 } 0061 } 0062 auto fetch = new Akonadi::CollectionFetchJob(mMainWidget->currentAddressBook(), Akonadi::CollectionFetchJob::Base); 0063 fetch->fetchScope().setIncludeStatistics(true); 0064 connect(fetch, &KJob::result, this, &ManageShowCollectionProperties::slotCollectionPropertiesFinished); 0065 } 0066 0067 void ManageShowCollectionProperties::slotCollectionPropertiesFinished(KJob *job) 0068 { 0069 if (!job) { 0070 return; 0071 } 0072 0073 auto fetch = qobject_cast<Akonadi::CollectionFetchJob *>(job); 0074 Q_ASSERT(fetch); 0075 if (fetch->collections().isEmpty()) { 0076 qCWarning(KADDRESSBOOK_LOG) << "no collection"; 0077 return; 0078 } 0079 0080 const Akonadi::Collection collection = fetch->collections().constFirst(); 0081 0082 QPointer<Akonadi::CollectionPropertiesDialog> dlg = new Akonadi::CollectionPropertiesDialog(collection, mPages, mMainWidget); 0083 dlg->setWindowTitle(i18nc("@title:window", "Properties of Address Book Folder %1", collection.name())); 0084 0085 dlg->show(); 0086 mHashDialogBox.insert(collection.id(), dlg); 0087 } 0088 0089 #include "moc_manageshowcollectionproperties.cpp"