File indexing completed on 2024-05-12 05:21:25

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 "akonadicollectionview.h"
0009 #include "korganizer_debug.h"
0010 #include <Akonadi/CollectionAttributesSynchronizationJob>
0011 #include <Akonadi/CollectionFetchJob>
0012 #include <Akonadi/CollectionFetchScope>
0013 #include <Akonadi/CollectionMaintenancePage>
0014 #include <Akonadi/CollectionPropertiesDialog>
0015 
0016 ManageShowCollectionProperties::ManageShowCollectionProperties(AkonadiCollectionView *collectionView, QObject *parent)
0017     : QObject(parent)
0018     , mPages{QStringLiteral("CalendarSupport::CollectionGeneralPage"),
0019              QStringLiteral("Akonadi::CachePolicyPage"),
0020              QStringLiteral("PimCommon::CollectionAclPage"),
0021              QStringLiteral("Akonadi::CollectionMaintenancePage")}
0022     , mCollectionView(collectionView)
0023 {
0024 }
0025 
0026 ManageShowCollectionProperties::~ManageShowCollectionProperties() = default;
0027 
0028 void ManageShowCollectionProperties::showCollectionProperties()
0029 {
0030     const Akonadi::Collection col = mCollectionView->currentCalendar();
0031     const Akonadi::Collection::Id id = col.id();
0032     QPointer<Akonadi::CollectionPropertiesDialog> dlg = mHashDialogBox.value(id);
0033     if (dlg) {
0034         dlg->activateWindow();
0035         dlg->raise();
0036         return;
0037     }
0038     auto sync = new Akonadi::CollectionAttributesSynchronizationJob(col);
0039     sync->setProperty("collectionId", id);
0040     connect(sync, &Akonadi::CollectionAttributesSynchronizationJob::result, this, &ManageShowCollectionProperties::slotCollectionPropertiesContinued);
0041     sync->start();
0042 }
0043 
0044 void ManageShowCollectionProperties::slotCollectionPropertiesContinued(KJob *job)
0045 {
0046     if (job) {
0047         auto sync = qobject_cast<Akonadi::CollectionAttributesSynchronizationJob *>(job);
0048         Q_ASSERT(sync);
0049         if (sync->property("collectionId") != mCollectionView->currentCalendar().id()) {
0050             return;
0051         }
0052     }
0053     auto fetch = new Akonadi::CollectionFetchJob(mCollectionView->currentCalendar(), Akonadi::CollectionFetchJob::Base);
0054     fetch->fetchScope().setIncludeStatistics(true);
0055     connect(fetch, &KJob::result, this, &ManageShowCollectionProperties::slotCollectionPropertiesFinished);
0056 }
0057 
0058 void ManageShowCollectionProperties::slotCollectionPropertiesFinished(KJob *job)
0059 {
0060     if (!job) {
0061         return;
0062     }
0063 
0064     auto fetch = qobject_cast<Akonadi::CollectionFetchJob *>(job);
0065     Q_ASSERT(fetch);
0066     if (fetch->collections().isEmpty()) {
0067         qCWarning(KORGANIZER_LOG) << "no collection";
0068         return;
0069     }
0070 
0071     const Akonadi::Collection::List collections = fetch->collections();
0072     if (!collections.isEmpty()) {
0073         const Akonadi::Collection collection = collections.first();
0074 
0075         QPointer<Akonadi::CollectionPropertiesDialog> dlg = new Akonadi::CollectionPropertiesDialog(collection, mPages, mCollectionView);
0076         dlg->setWindowTitle(i18nc("@title:window", "Properties of Calendar Folder %1", collection.name()));
0077 
0078         dlg->show();
0079         mHashDialogBox.insert(collection.id(), dlg);
0080     }
0081 }
0082 
0083 #include "moc_manageshowcollectionproperties.cpp"