File indexing completed on 2024-05-19 05:00:38
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Elvis Angelaccio <elvis.angelaccio@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 * 0006 */ 0007 0008 #include "kaccountsplugin.h" 0009 0010 #include <KAccounts/Core> 0011 0012 #include <KIO/OpenUrlJob> 0013 #include <KLocalizedString> 0014 #include <KNotification> 0015 0016 #include <KPluginFactory> 0017 0018 K_PLUGIN_CLASS_WITH_JSON(GoogleDrivePlugin, "kaccountsplugin.json") 0019 0020 GoogleDrivePlugin::GoogleDrivePlugin(QObject *parent, const QVariantList &args) 0021 : KAccounts::KAccountsDPlugin(parent, args) 0022 { 0023 } 0024 0025 void GoogleDrivePlugin::onAccountCreated(const Accounts::AccountId accountId, const Accounts::ServiceList &serviceList) 0026 { 0027 Q_UNUSED(serviceList) 0028 auto account = Accounts::Account::fromId(KAccounts::accountsManager(), accountId); 0029 0030 if (account->providerName() != QLatin1String("google")) { 0031 return; 0032 } 0033 0034 auto notification = new KNotification(QStringLiteral("new-account-added")); 0035 notification->setComponentName(QStringLiteral("gdrive")); 0036 notification->setTitle(i18n("New Online Account")); 0037 notification->setText( 0038 xi18nc("@info", "You can now manage the Google Drive files of your <emphasis strong='true'>%1</emphasis> account.", account->displayName())); 0039 0040 QUrl url; 0041 url.setScheme(QStringLiteral("gdrive")); 0042 url.setPath(QStringLiteral("/%1").arg(account->displayName())); 0043 0044 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0045 notification->setActions({i18n("Open")}); 0046 connect(notification, static_cast<void (KNotification::*)(unsigned int)>(&KNotification::activated), this, [=]() { 0047 #else 0048 auto action = notification->addAction(i18n("Open")); 0049 connect(action, &KNotificationAction::activated, this, [url] { 0050 #endif 0051 KIO::OpenUrlJob *job = new KIO::OpenUrlJob(url, QStringLiteral("inode/directory")); 0052 job->start(); 0053 }); 0054 0055 notification->sendEvent(); 0056 } 0057 0058 void GoogleDrivePlugin::onAccountRemoved(const Accounts::AccountId accountId) 0059 { 0060 Q_UNUSED(accountId) 0061 } 0062 0063 void GoogleDrivePlugin::onServiceEnabled(const Accounts::AccountId accountId, const Accounts::Service &service) 0064 { 0065 Q_UNUSED(accountId) 0066 Q_UNUSED(service) 0067 } 0068 0069 void GoogleDrivePlugin::onServiceDisabled(const Accounts::AccountId accountId, const Accounts::Service &service) 0070 { 0071 Q_UNUSED(accountId) 0072 Q_UNUSED(service) 0073 } 0074 0075 #include "kaccountsplugin.moc"