File indexing completed on 2024-11-24 04:50:41

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carlschwan@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #include "contactapplication.h"
0005 #include "contactconfig.h"
0006 #include <KAuthorized>
0007 #include <KLocalizedString>
0008 #include <KShortcutsDialog>
0009 #include <KWindowConfig>
0010 #include <QIcon>
0011 #include <QQuickWindow>
0012 
0013 ContactApplication::ContactApplication(QObject *parent)
0014     : AbstractApplication(parent)
0015     , mContactCollection(new KActionCollection(parent, i18n("Contact")))
0016 {
0017     mContactCollection->setComponentDisplayName(i18n("Contact"));
0018     setupActions();
0019 }
0020 
0021 QList<KActionCollection *> ContactApplication::actionCollections() const
0022 {
0023     return {
0024         mCollection,
0025         mContactCollection,
0026     };
0027 }
0028 
0029 void ContactApplication::setupActions()
0030 {
0031     AbstractApplication::setupActions();
0032 
0033     auto actionName = QLatin1StringView("create_contact");
0034     if (KAuthorized::authorizeAction(actionName)) {
0035         auto action = mContactCollection->addAction(actionName, this, &ContactApplication::createNewContact);
0036         action->setText(i18n("New Contact…"));
0037         action->setIcon(QIcon::fromTheme(QStringLiteral("contact-new-symbolic")));
0038     }
0039 
0040     actionName = QLatin1StringView("refresh_all");
0041     if (KAuthorized::authorizeAction(actionName)) {
0042         auto refreshAllAction = mContactCollection->addAction(actionName, this, &ContactApplication::refreshAll);
0043         refreshAllAction->setText(i18n("Refresh All Address Books"));
0044         refreshAllAction->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
0045 
0046         mContactCollection->addAction(refreshAllAction->objectName(), refreshAllAction);
0047         mContactCollection->setDefaultShortcut(refreshAllAction, QKeySequence(QKeySequence::Refresh));
0048     }
0049 
0050     actionName = QLatin1StringView("create_contact_group");
0051     if (KAuthorized::authorizeAction(actionName)) {
0052         auto action = mContactCollection->addAction(actionName, this, &ContactApplication::createNewContactGroup);
0053         action->setText(i18n("New Contact Group…"));
0054         action->setIcon(QIcon::fromTheme(QStringLiteral("contact-new-symbolic")));
0055     }
0056 
0057     mCollection->readSettings();
0058     mContactCollection->readSettings();
0059 }
0060 
0061 void ContactApplication::saveWindowGeometry(QQuickWindow *window)
0062 {
0063     KConfig dataResource(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
0064     KConfigGroup windowGroup(&dataResource, QStringLiteral("Window"));
0065     KWindowConfig::saveWindowPosition(window, windowGroup);
0066     KWindowConfig::saveWindowSize(window, windowGroup);
0067     dataResource.sync();
0068 }
0069 
0070 #include "moc_contactapplication.cpp"