akregator_plugin.cpp 3.66 KB
Newer Older
1 2 3
/*
  This file is part of Akregator.

4
  SPDX-FileCopyrightText: 2004 Sashmit Bhaduri <smt@vfemail.net>
5

6
  SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
*/

#include "akregator_plugin.h"
#include "akregator_part.h"
#include "akregator_options.h"
#include "partinterface.h"

#include <KontactInterface/Core>

#include <QAction>
#include <KActionCollection>
#include <KLocalizedString>
#include <QIcon>
#include <QStandardPaths>

22
EXPORT_KONTACT_PLUGIN_WITH_JSON(AkregatorPlugin, "akregatorplugin.json")
23 24

AkregatorPlugin::AkregatorPlugin(KontactInterface::Core *core, const QVariantList &)
Laurent Montel's avatar
Laurent Montel committed
25
    : KontactInterface::Plugin(core, core, "akregator")
26
{
Laurent Montel's avatar
Laurent Montel committed
27
    setComponentName(QStringLiteral("akregator"), i18n("Akregator"));
28

Laurent Montel's avatar
Laurent Montel committed
29 30 31
    QAction *action
        = new QAction(QIcon::fromTheme(QStringLiteral("bookmark-new")),
                      i18nc("@action:inmenu", "New Feed..."), this);
32
    actionCollection()->addAction(QStringLiteral("feed_new"), action);
33
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_F));
Laurent Montel's avatar
Laurent Montel committed
34
    setHelpText(action, i18nc("@info:status", "Create a new feed"));
35 36 37 38 39 40 41 42 43 44 45 46 47
    action->setWhatsThis(
        i18nc("@info:whatsthis",
              "You will be presented with a dialog where you can add a new feed."));
    connect(action, &QAction::triggered, this, &AkregatorPlugin::addFeed);
    insertNewAction(action);

    mUniqueAppWatcher = new KontactInterface::UniqueAppWatcher(
        new KontactInterface::UniqueAppHandlerFactory<AkregatorUniqueAppHandler>(), this);
}

AkregatorPlugin::~AkregatorPlugin()
{
    delete m_interface;
Laurent Montel's avatar
Laurent Montel committed
48
    m_interface = nullptr;
49 50
}

Laurent Montel's avatar
Laurent Montel committed
51 52 53 54 55 56 57 58 59
void AkregatorPlugin::setHelpText(QAction *action, const QString &text)
{
    action->setStatusTip(text);
    action->setToolTip(text);
    if (action->whatsThis().isEmpty()) {
        action->setWhatsThis(text);
    }
}

60 61 62 63 64 65 66 67 68 69 70 71 72 73
bool AkregatorPlugin::isRunningStandalone() const
{
    return mUniqueAppWatcher->isRunningStandalone();
}

OrgKdeAkregatorPartInterface *AkregatorPlugin::interface()
{
    if (!m_interface) {
        part();
    }
    Q_ASSERT(m_interface);
    return m_interface;
}

74
KParts::Part *AkregatorPlugin::createPart()
75
{
76
    KParts::Part *part = loadPart();
77
    if (!part) {
Laurent Montel's avatar
Laurent Montel committed
78
        return nullptr;
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    }

    m_interface = new OrgKdeAkregatorPartInterface(
        QStringLiteral("org.kde.akregator"), QStringLiteral("/Akregator"), QDBusConnection::sessionBus());
    m_interface->openStandardFeedList();

    return part;
}

void AkregatorPlugin::addFeed()
{
    // Ensure part is loaded
    (void)part();

    org::kde::akregator::part akregator(
        QStringLiteral("org.kde.akregator"), QStringLiteral("/Akregator"), QDBusConnection::sessionBus());
    akregator.addFeed();
}

void AkregatorPlugin::readProperties(const KConfigGroup &config)
{
    if (part()) {
Laurent Montel's avatar
Laurent Montel committed
101
        auto *myPart = static_cast<Akregator::Part *>(part());
102 103 104 105 106 107 108
        myPart->readProperties(config);
    }
}

void AkregatorPlugin::saveProperties(KConfigGroup &config)
{
    if (part()) {
Laurent Montel's avatar
Laurent Montel committed
109
        auto *myPart = static_cast<Akregator::Part *>(part());
110 111 112 113
        myPart->saveProperties(config);
    }
}

114
void AkregatorUniqueAppHandler::loadCommandLineOptions(QCommandLineParser *parser)
115
{
116
    Akregator::akregator_options(parser);
117 118
}

119
int AkregatorUniqueAppHandler::activate(const QStringList &args, const QString &workingDir)
120 121 122 123 124 125 126
{
    // Ensure part is loaded
    (void)plugin()->part();

    org::kde::akregator::part akregator(
        QStringLiteral("org.kde.akregator"), QStringLiteral("/Akregator"), QDBusConnection::sessionBus());
    akregator.openStandardFeedList();
127
    akregator.handleCommandLine(args);
128

129
    return KontactInterface::UniqueAppHandler::activate(args, workingDir);
130
}
Laurent Montel's avatar
Laurent Montel committed
131

132
#include "akregator_plugin.moc"