File indexing completed on 2024-04-28 05:10:45
0001 /* 0002 This file is part of Akregator. 0003 0004 SPDX-FileCopyrightText: 2004 Sashmit Bhaduri <smt@vfemail.net> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0007 */ 0008 0009 #include "akregator_plugin.h" 0010 #include "akregator_options.h" 0011 #include "akregator_part.h" 0012 #include "partinterface.h" 0013 0014 #include <KontactInterface/Core> 0015 0016 #include <KActionCollection> 0017 #include <KLocalizedString> 0018 #include <QAction> 0019 #include <QIcon> 0020 #include <QStandardPaths> 0021 0022 EXPORT_KONTACT_PLUGIN_WITH_JSON(AkregatorPlugin, "akregatorplugin.json") 0023 0024 AkregatorPlugin::AkregatorPlugin(KontactInterface::Core *core, const KPluginMetaData &data, const QVariantList &) 0025 : KontactInterface::Plugin(core, core, data, "akregator") 0026 { 0027 setComponentName(QStringLiteral("akregator"), i18n("Akregator")); 0028 0029 auto action = new QAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), i18nc("@action:inmenu", "New Feed..."), this); 0030 actionCollection()->addAction(QStringLiteral("feed_new"), action); 0031 actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_F)); 0032 setHelpText(action, i18nc("@info:status", "Create a new feed")); 0033 action->setWhatsThis(i18nc("@info:whatsthis", "You will be presented with a dialog where you can add a new feed.")); 0034 connect(action, &QAction::triggered, this, &AkregatorPlugin::addFeed); 0035 insertNewAction(action); 0036 0037 mUniqueAppWatcher = new KontactInterface::UniqueAppWatcher(new KontactInterface::UniqueAppHandlerFactory<AkregatorUniqueAppHandler>(), this); 0038 } 0039 0040 AkregatorPlugin::~AkregatorPlugin() 0041 { 0042 delete m_interface; 0043 m_interface = nullptr; 0044 } 0045 0046 void AkregatorPlugin::setHelpText(QAction *action, const QString &text) 0047 { 0048 action->setStatusTip(text); 0049 action->setToolTip(text); 0050 if (action->whatsThis().isEmpty()) { 0051 action->setWhatsThis(text); 0052 } 0053 } 0054 0055 bool AkregatorPlugin::isRunningStandalone() const 0056 { 0057 return mUniqueAppWatcher->isRunningStandalone(); 0058 } 0059 0060 OrgKdeAkregatorPartInterface *AkregatorPlugin::interface() 0061 { 0062 if (!m_interface) { 0063 part(); 0064 } 0065 Q_ASSERT(m_interface); 0066 return m_interface; 0067 } 0068 0069 KParts::Part *AkregatorPlugin::createPart() 0070 { 0071 KParts::Part *part = loadPart(); 0072 if (!part) { 0073 return nullptr; 0074 } 0075 0076 m_interface = new OrgKdeAkregatorPartInterface(QStringLiteral("org.kde.akregator"), QStringLiteral("/Akregator"), QDBusConnection::sessionBus()); 0077 m_interface->openStandardFeedList(); 0078 0079 return part; 0080 } 0081 0082 void AkregatorPlugin::addFeed() 0083 { 0084 // Ensure part is loaded 0085 (void)part(); 0086 0087 org::kde::akregator::part akregator(QStringLiteral("org.kde.akregator"), QStringLiteral("/Akregator"), QDBusConnection::sessionBus()); 0088 akregator.addFeed(); 0089 } 0090 0091 void AkregatorPlugin::readProperties(const KConfigGroup &config) 0092 { 0093 if (part()) { 0094 auto myPart = static_cast<Akregator::Part *>(part()); 0095 myPart->readProperties(config); 0096 } 0097 } 0098 0099 void AkregatorPlugin::saveProperties(KConfigGroup &config) 0100 { 0101 if (part()) { 0102 auto myPart = static_cast<Akregator::Part *>(part()); 0103 myPart->saveProperties(config); 0104 } 0105 } 0106 0107 void AkregatorUniqueAppHandler::loadCommandLineOptions(QCommandLineParser *parser) 0108 { 0109 Akregator::akregator_options(parser); 0110 } 0111 0112 int AkregatorUniqueAppHandler::activate(const QStringList &args, const QString &workingDir) 0113 { 0114 // Ensure part is loaded 0115 (void)plugin()->part(); 0116 0117 org::kde::akregator::part akregator(QStringLiteral("org.kde.akregator"), QStringLiteral("/Akregator"), QDBusConnection::sessionBus()); 0118 akregator.openStandardFeedList(); 0119 akregator.handleCommandLine(args); 0120 0121 return KontactInterface::UniqueAppHandler::activate(args, workingDir); 0122 } 0123 0124 #include "akregator_plugin.moc" 0125 0126 #include "moc_akregator_plugin.cpp"