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

4
    Copyright (C) 2005 Frank Osterfeld <osterfeld@kde.org>
5 6 7 8 9 10 11 12 13 14 15 16 17

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
18
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 20 21 22 23 24 25 26 27 28 29 30 31 32

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/

#include "actionmanagerimpl.h"
#include "akregatorconfig.h"
#include "akregator_part.h"
#include "articlelistview.h"
#include "feed.h"
#include "fetchqueue.h"
#include "folder.h"
#include "kernel.h"
33
#include "mainwidget.h"
34
#include "subscriptionlistview.h"
Frank Osterfeld's avatar
Frank Osterfeld committed
35
#include "tabwidget.h"
36 37 38 39
#include "trayicon.h"
#include "treenode.h"
#include "treenodevisitor.h"

Laurent Montel's avatar
Laurent Montel committed
40
#include <WebEngineViewer/ZoomActionMenu>
Laurent Montel's avatar
Laurent Montel committed
41

Laurent Montel's avatar
Laurent Montel committed
42 43
#include <kactionmenu.h>
#include <ktoolbarpopupaction.h>
Laurent Montel's avatar
Laurent Montel committed
44
#include <QAction>
45
#include <KToggleAction>
Frank Osterfeld's avatar
Frank Osterfeld committed
46
#include <kactioncollection.h>
Laurent Montel's avatar
Laurent Montel committed
47
#include "akregator_debug.h"
Laurent Montel's avatar
Laurent Montel committed
48
#include <KLocalizedString>
Laurent Montel's avatar
Port++  
Laurent Montel committed
49
#include <QMenu>
Laurent Montel's avatar
Laurent Montel committed
50
#include <QKeySequence>
Aaron J. Seigo's avatar
build  
Aaron J. Seigo committed
51
#include <kstandardshortcut.h>
Aaron J. Seigo's avatar
Aaron J. Seigo committed
52
#include <kstandardaction.h>
Frank Osterfeld's avatar
Frank Osterfeld committed
53
#include <kxmlguifactory.h>
Laurent Montel's avatar
Laurent Montel committed
54
#include <KGuiItem>
Frank Osterfeld's avatar
Frank Osterfeld committed
55

56
#include <QApplication>
Frank Osterfeld's avatar
Frank Osterfeld committed
57
#include <QHash>
Frank Osterfeld's avatar
Frank Osterfeld committed
58
#include <QWidget>
59 60 61 62 63 64

namespace Akregator
{

class ActionManagerImpl::NodeSelectVisitor : public TreeNodeVisitor
{
Laurent Montel's avatar
Laurent Montel committed
65 66
public:
    NodeSelectVisitor(ActionManagerImpl *manager) : m_manager(manager) {}
67

Laurent Montel's avatar
Laurent Montel committed
68
    bool visitFeed(Feed *node) Q_DECL_OVERRIDE {
Laurent Montel's avatar
Laurent Montel committed
69
        QAction *remove = m_manager->action(QStringLiteral("feed_remove"));
Laurent Montel's avatar
Laurent Montel committed
70 71
        if (remove)
        {
72
            remove->setEnabled(true);
Laurent Montel's avatar
Laurent Montel committed
73
        }
Laurent Montel's avatar
Laurent Montel committed
74
        QAction *hp = m_manager->action(QStringLiteral("feed_homepage"));
Laurent Montel's avatar
Laurent Montel committed
75 76
        if (hp)
        {
77
            hp->setEnabled(!node->htmlUrl().isEmpty());
Laurent Montel's avatar
Laurent Montel committed
78
        }
Laurent Montel's avatar
Laurent Montel committed
79 80 81 82
        m_manager->action(QStringLiteral("feed_fetch"))->setText(i18n("&Fetch Feed"));
        m_manager->action(QStringLiteral("feed_remove"))->setText(i18n("&Delete Feed"));
        m_manager->action(QStringLiteral("feed_modify"))->setText(i18n("&Edit Feed..."));
        m_manager->action(QStringLiteral("feed_mark_all_as_read"))->setText(i18n("&Mark Feed as Read"));
83 84 85

        return true;
    }
86

Laurent Montel's avatar
Laurent Montel committed
87
    bool visitFolder(Folder *node) Q_DECL_OVERRIDE {
Laurent Montel's avatar
Laurent Montel committed
88
        QAction *remove = m_manager->action(QStringLiteral("feed_remove"));
Laurent Montel's avatar
Laurent Montel committed
89 90
        if (remove)
        {
Laurent Montel's avatar
Laurent Montel committed
91 92
            remove->setEnabled(node->parent());    // root nodes must not be deleted
        }
Laurent Montel's avatar
Laurent Montel committed
93
        QAction *hp = m_manager->action(QStringLiteral("feed_homepage"));
Laurent Montel's avatar
Laurent Montel committed
94 95
        if (hp)
        {
96
            hp->setEnabled(false);
Laurent Montel's avatar
Laurent Montel committed
97
        }
98

Laurent Montel's avatar
Laurent Montel committed
99 100 101 102
        m_manager->action(QStringLiteral("feed_fetch"))->setText(i18n("&Fetch Feeds"));
        m_manager->action(QStringLiteral("feed_remove"))->setText(i18n("&Delete Folder"));
        m_manager->action(QStringLiteral("feed_modify"))->setText(i18n("&Rename Folder"));
        m_manager->action(QStringLiteral("feed_mark_all_as_read"))->setText(i18n("&Mark Feeds as Read"));
103 104 105 106

        return true;
    }

Laurent Montel's avatar
Laurent Montel committed
107 108
private:
    ActionManagerImpl *m_manager;
109 110 111 112 113
};

class ActionManagerImpl::ActionManagerImplPrivate
{
public:
Laurent Montel's avatar
Laurent Montel committed
114
    QString quickSearchLineText() const;
Laurent Montel's avatar
Laurent Montel committed
115 116 117 118 119 120 121 122 123
    NodeSelectVisitor *nodeSelectVisitor;
    ArticleListView *articleList;
    SubscriptionListView *subscriptionListView;
    MainWidget *mainWidget;
    Part *part;
    TrayIcon *trayIcon;
    KActionMenu *tagMenu;
    KActionCollection *actionCollection;
    TabWidget *tabWidget;
124
    PimCommon::ShareServiceUrlManager *shareServiceManager;
Laurent Montel's avatar
Laurent Montel committed
125
    WebEngineViewer::ZoomActionMenu *zoomActionMenu;
Laurent Montel's avatar
Laurent Montel committed
126
    QAction *mQuickSearchAction;
127 128
};

Laurent Montel's avatar
Laurent Montel committed
129
void ActionManagerImpl::slotNodeSelected(TreeNode *node)
130
{
Laurent Montel's avatar
Laurent Montel committed
131
    if (node != 0) {
132
        d->nodeSelectVisitor->visit(node);
Laurent Montel's avatar
Laurent Montel committed
133
    }
134
}
135

Laurent Montel's avatar
Laurent Montel committed
136 137
ActionManagerImpl::ActionManagerImpl(Part *part, QObject *parent)
    : ActionManager(parent), d(new ActionManagerImplPrivate)
138 139 140
{
    d->nodeSelectVisitor = new NodeSelectVisitor(this);
    d->part = part;
141
    d->subscriptionListView = 0;
142 143
    d->articleList = 0;
    d->trayIcon = 0;
144
    d->mainWidget = 0;
145
    d->tabWidget = 0;
146
    d->tagMenu = 0;
147
    d->actionCollection = part->actionCollection();
148
    d->shareServiceManager = new PimCommon::ShareServiceUrlManager(this);
149 150 151 152 153
    initPart();
}

ActionManagerImpl::~ActionManagerImpl()
{
Frank Osterfeld's avatar
Frank Osterfeld committed
154
    delete d->nodeSelectVisitor;
155 156 157 158
    delete d;
    d = 0;
}

Laurent Montel's avatar
Laurent Montel committed
159
void ActionManagerImpl::setTrayIcon(TrayIcon *trayIcon)
160
{
Laurent Montel's avatar
Laurent Montel committed
161
    if (trayIcon == 0) {
162 163 164
        d->trayIcon = 0;
        return;
    }
Laurent Montel's avatar
Laurent Montel committed
165
    if (d->trayIcon) {
166
        return;
Laurent Montel's avatar
Laurent Montel committed
167 168 169
    } else {
        d->trayIcon = trayIcon;
    }
170

Laurent Montel's avatar
Laurent Montel committed
171
    QMenu *traypop = trayIcon->contextMenu();
172

Laurent Montel's avatar
Laurent Montel committed
173 174
    if (QAction *act = actionCollection()->action(QStringLiteral("feed_fetch_all"))) {
        traypop->addAction(act);
Laurent Montel's avatar
Laurent Montel committed
175
    }
Laurent Montel's avatar
Laurent Montel committed
176 177
    if (QAction *act = actionCollection()->action(QStringLiteral("options_configure"))) {
        traypop->addAction(act);
Laurent Montel's avatar
Laurent Montel committed
178
    }
179 180 181 182
}

void ActionManagerImpl::initPart()
{
Laurent Montel's avatar
Laurent Montel committed
183
    QAction *action = d->actionCollection->addAction(QStringLiteral("file_import"));
184
    action->setText(i18n("&Import Feeds..."));
Laurent Montel's avatar
Laurent Montel committed
185
    action->setIcon(QIcon::fromTheme(QStringLiteral("document-import")));
Laurent Montel's avatar
Laurent Montel committed
186
    connect(action, &QAction::triggered, d->part, &Part::fileImport);
Laurent Montel's avatar
Laurent Montel committed
187
    action = d->actionCollection->addAction(QStringLiteral("file_export"));
Laurent Montel's avatar
Laurent Montel committed
188
    action->setText(i18n("&Export Feeds..."));
Laurent Montel's avatar
Laurent Montel committed
189
    action->setIcon(QIcon::fromTheme(QStringLiteral("document-export")));
Laurent Montel's avatar
Laurent Montel committed
190
    connect(action, &QAction::triggered, d->part, &Part::fileExport);
191

Laurent Montel's avatar
Laurent Montel committed
192
    QAction *configure = d->actionCollection->addAction(QStringLiteral("options_configure"));
193
    configure->setText(i18n("&Configure Akregator..."));
Laurent Montel's avatar
Laurent Montel committed
194
    configure->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
Laurent Montel's avatar
Laurent Montel committed
195
    connect(configure, &QAction::triggered, d->part, &Part::showOptions);
196

197
    KStandardAction::configureNotifications(d->part, SLOT(showNotificationOptions()), d->actionCollection); // options_configure_notifications
198 199
}

Laurent Montel's avatar
Laurent Montel committed
200
void ActionManagerImpl::initMainWidget(MainWidget *mainWidget)
201
{
Laurent Montel's avatar
Laurent Montel committed
202
    if (d->mainWidget) {
203
        return;
Laurent Montel's avatar
Laurent Montel committed
204
    }
205

206
    d->mainWidget = mainWidget;
207

Laurent Montel's avatar
Laurent Montel committed
208
    KActionCollection *coll = actionCollection();
Allen Winter's avatar
Allen Winter committed
209

210
    // Feed/Feed Group popup menu
Laurent Montel's avatar
Laurent Montel committed
211
    QAction *action = coll->addAction(QStringLiteral("feed_homepage"));
212
    action->setText(i18n("&Open Homepage"));
Laurent Montel's avatar
Laurent Montel committed
213
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotOpenHomepage);
Laurent Montel's avatar
Laurent Montel committed
214
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_H));
215

Laurent Montel's avatar
Laurent Montel committed
216 217
    action = coll->addAction(QStringLiteral("reload_all_tabs"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
Sune Vuorela's avatar
Sune Vuorela committed
218
    action->setText(i18n("Reload All Tabs"));
Laurent Montel's avatar
Laurent Montel committed
219
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotReloadAllTabs);
Laurent Montel's avatar
Laurent Montel committed
220
    coll->setDefaultShortcut(action, QKeySequence(Qt::SHIFT + Qt::Key_F5));
Sune Vuorela's avatar
Sune Vuorela committed
221

Laurent Montel's avatar
Laurent Montel committed
222 223
    action = coll->addAction(QStringLiteral("feed_add"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("feed-subscribe")));
224
    action->setText(i18n("&Add Feed..."));
Laurent Montel's avatar
Laurent Montel committed
225
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotFeedAdd);
Laurent Montel's avatar
Laurent Montel committed
226
    coll->setDefaultShortcut(action, QKeySequence(Qt::Key_Insert));
227

Laurent Montel's avatar
Laurent Montel committed
228 229
    action = coll->addAction(QStringLiteral("feed_add_group"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
230
    action->setText(i18n("Ne&w Folder..."));
Laurent Montel's avatar
Laurent Montel committed
231
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotFeedAddGroup);
Laurent Montel's avatar
Laurent Montel committed
232
    coll->setDefaultShortcut(action, QKeySequence(Qt::SHIFT + Qt::Key_Insert));
233

Laurent Montel's avatar
Laurent Montel committed
234 235
    action = coll->addAction(QStringLiteral("feed_remove"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
236
    action->setText(i18n("&Delete Feed"));
Laurent Montel's avatar
Laurent Montel committed
237
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotFeedRemove);
Laurent Montel's avatar
Laurent Montel committed
238
    coll->setDefaultShortcut(action, QKeySequence(Qt::ALT + Qt::Key_Delete));
239

Laurent Montel's avatar
Laurent Montel committed
240 241
    action = coll->addAction(QStringLiteral("feed_modify"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
242
    action->setText(i18n("&Edit Feed..."));
Laurent Montel's avatar
Laurent Montel committed
243
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotFeedModify);
Laurent Montel's avatar
Laurent Montel committed
244
    coll->setDefaultShortcut(action, QKeySequence(Qt::Key_F2));
245

246
    // toolbar / View
Laurent Montel's avatar
Laurent Montel committed
247 248

    const MainWidget::ViewMode viewMode = static_cast<MainWidget::ViewMode>(Settings::viewMode());
Laurent Montel's avatar
Laurent Montel committed
249
    QActionGroup *group = new QActionGroup(this);
Laurent Montel's avatar
Laurent Montel committed
250
    action = coll->addAction(QStringLiteral("normal_view"));
Laurent Montel's avatar
Laurent Montel committed
251
    action->setCheckable(true);
Laurent Montel's avatar
Laurent Montel committed
252
    action->setChecked(viewMode == MainWidget::NormalView);
Laurent Montel's avatar
Laurent Montel committed
253
    group->addAction(action);
Laurent Montel's avatar
Laurent Montel committed
254
    action->setIcon(QIcon::fromTheme(QStringLiteral("view-split-top-bottom")));
255
    action->setText(i18n("&Normal View"));
Laurent Montel's avatar
Laurent Montel committed
256
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotNormalView);
Laurent Montel's avatar
Laurent Montel committed
257
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_1));
258

Laurent Montel's avatar
Laurent Montel committed
259
    action = coll->addAction(QStringLiteral("widescreen_view"));
Laurent Montel's avatar
Laurent Montel committed
260
    action->setCheckable(true);
Laurent Montel's avatar
Laurent Montel committed
261
    action->setChecked(viewMode == MainWidget::WidescreenView);
Laurent Montel's avatar
Laurent Montel committed
262
    group->addAction(action);
Laurent Montel's avatar
Laurent Montel committed
263
    action->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
264
    action->setText(i18n("&Widescreen View"));
Laurent Montel's avatar
Laurent Montel committed
265
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotWidescreenView);
Laurent Montel's avatar
Laurent Montel committed
266
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_2));
267

Laurent Montel's avatar
Laurent Montel committed
268
    action = coll->addAction(QStringLiteral("combined_view"));
Laurent Montel's avatar
Laurent Montel committed
269
    action->setCheckable(true);
Laurent Montel's avatar
Laurent Montel committed
270
    action->setChecked(viewMode == MainWidget::CombinedView);
Laurent Montel's avatar
Laurent Montel committed
271
    group->addAction(action);
Laurent Montel's avatar
Laurent Montel committed
272
    action->setIcon(QIcon::fromTheme(QStringLiteral("view-list-text")));
273
    action->setText(i18n("C&ombined View"));
Laurent Montel's avatar
Laurent Montel committed
274
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotCombinedView);
Laurent Montel's avatar
Laurent Montel committed
275
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_3));
276 277

    // toolbar / feed menu
Laurent Montel's avatar
Laurent Montel committed
278 279
    action = coll->addAction(QStringLiteral("feed_fetch"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("go-down")));
280
    action->setText(i18n("&Fetch Feed"));
Laurent Montel's avatar
Laurent Montel committed
281
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotFetchCurrentFeed);
Laurent Montel's avatar
Laurent Montel committed
282
    coll->setDefaultShortcuts(action, KStandardShortcut::shortcut(KStandardShortcut::Reload));
283

Laurent Montel's avatar
Laurent Montel committed
284 285
    action = coll->addAction(QStringLiteral("feed_fetch_all"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("go-bottom")));
286
    action->setText(i18n("Fe&tch All Feeds"));
Laurent Montel's avatar
Laurent Montel committed
287
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotFetchAllFeeds);
Laurent Montel's avatar
Laurent Montel committed
288
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_L));
Stephan Kulow's avatar
Stephan Kulow committed
289

Laurent Montel's avatar
Laurent Montel committed
290 291
    QAction *stopAction = coll->addAction(QStringLiteral("feed_stop"));
    stopAction->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
292
    stopAction->setText(i18n("C&ancel Feed Fetches"));
Laurent Montel's avatar
Laurent Montel committed
293
    connect(stopAction, &QAction::triggered, Kernel::self()->fetchQueue(), &FetchQueue::slotAbort);
Laurent Montel's avatar
Laurent Montel committed
294
    coll->setDefaultShortcut(stopAction, QKeySequence(Qt::Key_Escape));
295
    stopAction->setEnabled(false);
296

Laurent Montel's avatar
Laurent Montel committed
297 298
    action = coll->addAction(QStringLiteral("feed_mark_all_as_read"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("mail-mark-read")));
299
    action->setText(i18n("&Mark Feed as Read"));
Laurent Montel's avatar
Laurent Montel committed
300
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotMarkAllRead);
Laurent Montel's avatar
Laurent Montel committed
301
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_R));
302

Laurent Montel's avatar
Laurent Montel committed
303 304
    action = coll->addAction(QStringLiteral("feed_mark_all_feeds_as_read"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("mail-mark-read")));
305
    action->setText(i18n("Ma&rk All Feeds as Read"));
Laurent Montel's avatar
Laurent Montel committed
306
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotMarkAllFeedsRead);
Laurent Montel's avatar
Laurent Montel committed
307
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_R));
308 309

    // Settings menu
Laurent Montel's avatar
Laurent Montel committed
310
    KToggleAction *sqf = coll->add<KToggleAction>(QStringLiteral("show_quick_filter"));
311
    sqf->setText(i18n("Show Quick Filter"));
Laurent Montel's avatar
Laurent Montel committed
312
    connect(sqf, &QAction::triggered, d->mainWidget, &MainWidget::slotToggleShowQuickFilter);
Laurent Montel's avatar
Laurent Montel committed
313
    sqf->setChecked(Settings::showQuickFilter());
314

Laurent Montel's avatar
Laurent Montel committed
315 316
    action = coll->addAction(QStringLiteral("article_open"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
317
    action->setText(i18n("Open in Tab"));
Laurent Montel's avatar
Laurent Montel committed
318
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotOpenSelectedArticles);
Laurent Montel's avatar
Laurent Montel committed
319
    coll->setDefaultShortcut(action, QKeySequence(Qt::SHIFT + Qt::Key_Return));
Allen Winter's avatar
Allen Winter committed
320

Laurent Montel's avatar
Laurent Montel committed
321 322
    action = coll->addAction(QStringLiteral("article_open_in_background"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
323
    action->setText(i18n("Open in Background Tab"));
Laurent Montel's avatar
Laurent Montel committed
324
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotOpenSelectedArticlesInBackground);
Laurent Montel's avatar
Laurent Montel committed
325
    coll->setDefaultShortcut(action, QKeySequence(Qt::Key_Return));
326

Laurent Montel's avatar
Laurent Montel committed
327 328
    action = coll->addAction(QStringLiteral("article_open_external"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
329
    action->setText(i18n("Open in External Browser"));
Laurent Montel's avatar
Laurent Montel committed
330
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotOpenSelectedArticlesInBrowser);
Laurent Montel's avatar
Laurent Montel committed
331
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Return));
Allen Winter's avatar
Allen Winter committed
332

Laurent Montel's avatar
Laurent Montel committed
333
    action = coll->addAction(QStringLiteral("article_copy_link_address"));
334
    action->setText(i18n("Copy Link Address"));
Laurent Montel's avatar
Laurent Montel committed
335
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotCopyLinkAddress);
336

Laurent Montel's avatar
Laurent Montel committed
337 338
    action = coll->addAction(QStringLiteral("go_prev_unread_article"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("go-previous")));
339
    action->setText(i18n("Pre&vious Unread Article"));
Laurent Montel's avatar
Laurent Montel committed
340
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotPrevUnreadArticle);
341
    coll->setDefaultShortcuts(action, QList<QKeySequence>() << QKeySequence(Qt::Key_Minus) << QKeySequence(Qt::Key_Minus + Qt::KeypadModifier));
342

Laurent Montel's avatar
Laurent Montel committed
343 344
    action = coll->addAction(QStringLiteral("go_next_unread_article"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("go-next")));
345
    action->setText(i18n("Ne&xt Unread Article"));
Laurent Montel's avatar
Laurent Montel committed
346
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotNextUnreadArticle);
347 348
    coll->setDefaultShortcuts(action, QList<QKeySequence>() << QKeySequence(Qt::Key_Plus) << QKeySequence(Qt::Key_Plus + Qt::KeypadModifier)
                              << QKeySequence(Qt::Key_Equal) << QKeySequence(Qt::Key_Equal + Qt::KeypadModifier));
349

Laurent Montel's avatar
Laurent Montel committed
350 351
    action = coll->addAction(QStringLiteral("article_delete"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
352
    action->setText(i18n("&Delete"));
Laurent Montel's avatar
Laurent Montel committed
353
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotArticleDelete);
Laurent Montel's avatar
Laurent Montel committed
354
    coll->setDefaultShortcut(action, QKeySequence(Qt::Key_Delete));
355

Laurent Montel's avatar
Laurent Montel committed
356
    KActionMenu *statusMenu = coll->add<KActionMenu>(QStringLiteral("article_set_status"));
357
    statusMenu->setText(i18n("&Mark As"));
Laurent Montel's avatar
Laurent Montel committed
358
    statusMenu->setEnabled(false);
359

Laurent Montel's avatar
Laurent Montel committed
360
    action = coll->addAction(QStringLiteral("article_set_status_read"));
Laurent Montel's avatar
Laurent Montel committed
361
    action->setText(i18nc("as in: mark as read", "&Read"));
Laurent Montel's avatar
Laurent Montel committed
362
    action->setIcon(QIcon::fromTheme(QStringLiteral("mail-mark-read")));
Stephan Kulow's avatar
Stephan Kulow committed
363
    action->setToolTip(i18n("Mark selected article as read"));
Laurent Montel's avatar
Laurent Montel committed
364
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_E));
Laurent Montel's avatar
Laurent Montel committed
365
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotSetSelectedArticleRead);
Stephan Kulow's avatar
Stephan Kulow committed
366
    statusMenu->addAction(action);
Stephan Kulow's avatar
Stephan Kulow committed
367

Laurent Montel's avatar
Laurent Montel committed
368
    action = coll->addAction(QStringLiteral("article_set_status_new"));
Teemu Rytilahti's avatar
Teemu Rytilahti committed
369
    action->setText(i18nc("as in: mark as new", "&New"));
Laurent Montel's avatar
Laurent Montel committed
370
    action->setIcon(QIcon::fromTheme(QStringLiteral("mail-mark-unread-new")));
Laurent Montel's avatar
Laurent Montel committed
371
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_N));
Stephan Kulow's avatar
Stephan Kulow committed
372
    action->setToolTip(i18n("Mark selected article as new"));
Laurent Montel's avatar
Laurent Montel committed
373
    connect(action, &QAction::triggered,  d->mainWidget, &MainWidget::slotSetSelectedArticleNew);
Stephan Kulow's avatar
Stephan Kulow committed
374
    statusMenu->addAction(action);
Stephan Kulow's avatar
Stephan Kulow committed
375

Laurent Montel's avatar
Laurent Montel committed
376
    action = coll->addAction(QStringLiteral("article_set_status_unread"));
Teemu Rytilahti's avatar
Teemu Rytilahti committed
377
    action->setText(i18nc("as in: mark as unread", "&Unread"));
Laurent Montel's avatar
Laurent Montel committed
378
    action->setIcon(QIcon::fromTheme(QStringLiteral("mail-mark-unread")));
Stephan Kulow's avatar
Stephan Kulow committed
379
    action->setToolTip(i18n("Mark selected article as unread"));
Laurent Montel's avatar
Laurent Montel committed
380
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_U));
Laurent Montel's avatar
Laurent Montel committed
381
    connect(action, &QAction::triggered, d->mainWidget, &MainWidget::slotSetSelectedArticleUnread);
Stephan Kulow's avatar
Stephan Kulow committed
382
    statusMenu->addAction(action);
383

Laurent Montel's avatar
Laurent Montel committed
384
    KToggleAction *importantAction = coll->add<KToggleAction>(QStringLiteral("article_set_status_important"));
385
    importantAction->setText(i18n("&Mark as Important"));
Laurent Montel's avatar
Laurent Montel committed
386
    importantAction->setIcon(QIcon::fromTheme(QStringLiteral("mail-mark-important")));
Laurent Montel's avatar
Laurent Montel committed
387
    QList<QKeySequence> importantSC;
Laurent Montel's avatar
Laurent Montel committed
388
    importantSC << QKeySequence(QKeySequence(Qt::CTRL + Qt::Key_I));
Laurent Montel's avatar
Laurent Montel committed
389
    importantSC << QKeySequence(Qt::Key_I);
Laurent Montel's avatar
Laurent Montel committed
390
    coll->setDefaultShortcuts(importantAction, importantSC);
Will Entriken's avatar
Will Entriken committed
391
    importantAction->setCheckedState(KGuiItem(i18n("Remove &Important Mark")));
Laurent Montel's avatar
Laurent Montel committed
392
    connect(importantAction, &QAction::triggered, d->mainWidget, &MainWidget::slotArticleToggleKeepFlag);
393

Laurent Montel's avatar
Laurent Montel committed
394
    action = coll->addAction(QStringLiteral("feedstree_move_up"));
395
    action->setText(i18n("Move Node Up"));
Laurent Montel's avatar
Laurent Montel committed
396
    connect(action, &QAction::triggered, mainWidget, &MainWidget::slotMoveCurrentNodeUp);
Laurent Montel's avatar
Laurent Montel committed
397
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Shift+Alt+Up")));
398

Laurent Montel's avatar
Laurent Montel committed
399
    action = coll->addAction(QStringLiteral("feedstree_move_down"));
400
    action->setText(i18n("Move Node Down"));
Laurent Montel's avatar
Laurent Montel committed
401
    connect(action, &QAction::triggered, mainWidget, &MainWidget::slotMoveCurrentNodeDown);
Laurent Montel's avatar
Laurent Montel committed
402
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Shift+Alt+Down")));
403

Laurent Montel's avatar
Laurent Montel committed
404
    action = coll->addAction(QStringLiteral("move_node_left"));
405
    action->setText(i18n("Move Node Left"));
Laurent Montel's avatar
Laurent Montel committed
406
    connect(action, &QAction::triggered, mainWidget, &MainWidget::slotMoveCurrentNodeLeft);
Laurent Montel's avatar
Laurent Montel committed
407
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Shift+Alt+Left")));
408

Laurent Montel's avatar
Laurent Montel committed
409
    action = coll->addAction(QStringLiteral("feedstree_move_right"));
410
    action->setText(i18n("Move Node Right"));
Laurent Montel's avatar
Laurent Montel committed
411
    connect(action, &QAction::triggered, mainWidget, &MainWidget::slotMoveCurrentNodeRight);
Laurent Montel's avatar
Laurent Montel committed
412
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Shift+Alt+Right")));
413

Laurent Montel's avatar
Laurent Montel committed
414 415
    action = coll->addAction(QStringLiteral("file_sendlink"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("mail-message-new")));
416
    action->setText(i18n("Send &Link Address..."));
Laurent Montel's avatar
Laurent Montel committed
417
    connect(action, &QAction::triggered, mainWidget, &MainWidget::slotSendLink);
418

Laurent Montel's avatar
Laurent Montel committed
419 420
    action = coll->addAction(QStringLiteral("file_sendfile"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("mail-message-new")));
421
    action->setText(i18n("Send &File..."));
Laurent Montel's avatar
Laurent Montel committed
422
    connect(action, &QAction::triggered, mainWidget, &MainWidget::slotSendFile);
423

Laurent Montel's avatar
Laurent Montel committed
424 425 426
    coll->addAction(QStringLiteral("share_serviceurl"), d->shareServiceManager->menu());
    connect(d->shareServiceManager, &PimCommon::ShareServiceUrlManager::serviceUrlSelected, this, &ActionManagerImpl::slotServiceUrlSelected);

Laurent Montel's avatar
Laurent Montel committed
427 428 429 430 431 432
    d->mQuickSearchAction = new QAction(i18n("Set Focus to Quick Search"), this);
    //If change shortcut change Panel::setQuickSearchClickMessage(...) message
    actionCollection()->setDefaultShortcut(d->mQuickSearchAction, QKeySequence(Qt::ALT + Qt::Key_Q));
    actionCollection()->addAction(QStringLiteral("focus_to_quickseach"), d->mQuickSearchAction);
    connect(d->mQuickSearchAction, &QAction::triggered, mainWidget, &MainWidget::slotFocusQuickSearch);

Laurent Montel's avatar
Laurent Montel committed
433
    setArticleActionsEnabled(false);
434 435
}

Laurent Montel's avatar
Laurent Montel committed
436 437 438 439 440 441 442 443 444 445 446
void ActionManagerImpl::slotServiceUrlSelected(PimCommon::ShareServiceUrlManager::ServiceType type)
{
    if (d->mainWidget) {
        QString title;
        QString link;
        d->mainWidget->currentArticleInfo(link, title);
        const QUrl url = d->shareServiceManager->generateServiceUrl(link, title, type);
        d->shareServiceManager->openUrl(url);
    }
}

Laurent Montel's avatar
Laurent Montel committed
447
void ActionManagerImpl::initArticleListView(ArticleListView *articleList)
448
{
Laurent Montel's avatar
Laurent Montel committed
449
    if (d->articleList) {
450
        return;
Laurent Montel's avatar
Laurent Montel committed
451
    } else {
452
        d->articleList = articleList;
Laurent Montel's avatar
Laurent Montel committed
453
    }
454

Laurent Montel's avatar
Laurent Montel committed
455
    QAction *action = actionCollection()->addAction(QStringLiteral("go_previous_article"));
456
    action->setText(i18n("&Previous Article"));
Laurent Montel's avatar
Laurent Montel committed
457
    connect(action, &QAction::triggered, articleList, &ArticleListView::slotPreviousArticle);
Laurent Montel's avatar
Laurent Montel committed
458 459
    actionCollection()->setDefaultShortcut(action, QKeySequence(QStringLiteral("Left")));
    action = actionCollection()->addAction(QStringLiteral("go_next_article"));
460
    action->setText(i18n("&Next Article"));
Laurent Montel's avatar
Laurent Montel committed
461
    connect(action, &QAction::triggered, articleList, &ArticleListView::slotNextArticle);
Laurent Montel's avatar
Laurent Montel committed
462
    actionCollection()->setDefaultShortcut(action, QKeySequence(QStringLiteral("Right")));
463 464
}

Laurent Montel's avatar
Laurent Montel committed
465
void ActionManagerImpl::initSubscriptionListView(SubscriptionListView *subscriptionListView)
466
{
Laurent Montel's avatar
Laurent Montel committed
467
    if (d->subscriptionListView) {
468
        return;
Laurent Montel's avatar
Laurent Montel committed
469
    } else {
470
        d->subscriptionListView = subscriptionListView;
Laurent Montel's avatar
Laurent Montel committed
471
    }
472

473 474
    KActionCollection *coll = actionCollection();

Laurent Montel's avatar
Laurent Montel committed
475
    QAction *action = coll->addAction(QStringLiteral("go_prev_feed"));
476
    action->setText(i18n("&Previous Feed"));
Laurent Montel's avatar
Laurent Montel committed
477
    connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotPrevFeed);
Laurent Montel's avatar
Laurent Montel committed
478
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("P")));
479

Laurent Montel's avatar
Laurent Montel committed
480
    action = coll->addAction(QStringLiteral("go_next_feed"));
481
    action->setText(i18n("&Next Feed"));
Laurent Montel's avatar
Laurent Montel committed
482
    connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotNextFeed);
Laurent Montel's avatar
Laurent Montel committed
483
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("N")));
484

Laurent Montel's avatar
Laurent Montel committed
485 486
    action = coll->addAction(QStringLiteral("go_next_unread_feed"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("go-down")));
487
    action->setText(i18n("N&ext Unread Feed"));
Laurent Montel's avatar
Laurent Montel committed
488
    connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotNextUnreadFeed);
Laurent Montel's avatar
Laurent Montel committed
489
    coll->setDefaultShortcut(action, QKeySequence(Qt::ALT + Qt::Key_Plus));
490

Laurent Montel's avatar
Laurent Montel committed
491 492
    action = coll->addAction(QStringLiteral("go_prev_unread_feed"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("go-up")));
493
    action->setText(i18n("Prev&ious Unread Feed"));
Laurent Montel's avatar
Laurent Montel committed
494
    connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotPrevUnreadFeed);
Laurent Montel's avatar
Laurent Montel committed
495
    coll->setDefaultShortcut(action, QKeySequence(Qt::ALT + Qt::Key_Minus));
Stephan Kulow's avatar
Stephan Kulow committed
496

Laurent Montel's avatar
Laurent Montel committed
497
    action = coll->addAction(QStringLiteral("feedstree_home"));
498
    action->setText(i18n("Go to Top of Tree"));
Laurent Montel's avatar
Laurent Montel committed
499
    connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotItemBegin);
Laurent Montel's avatar
Laurent Montel committed
500
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Ctrl+Home")));
501

Laurent Montel's avatar
Laurent Montel committed
502
    action = coll->addAction(QStringLiteral("feedstree_end"));
503
    action->setText(i18n("Go to Bottom of Tree"));
Laurent Montel's avatar
Laurent Montel committed
504
    connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotItemEnd);
Laurent Montel's avatar
Laurent Montel committed
505
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Ctrl+End")));
506

Laurent Montel's avatar
Laurent Montel committed
507
    action = coll->addAction(QStringLiteral("feedstree_left"));
508
    action->setText(i18n("Go Left in Tree"));
Laurent Montel's avatar
Laurent Montel committed
509
    connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotItemLeft);
Laurent Montel's avatar
Laurent Montel committed
510
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Ctrl+Left")));
511

Laurent Montel's avatar
Laurent Montel committed
512
    action = coll->addAction(QStringLiteral("feedstree_right"));
513
    action->setText(i18n("Go Right in Tree"));
Laurent Montel's avatar
Laurent Montel committed
514
    connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotItemRight);
Laurent Montel's avatar
Laurent Montel committed
515
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Ctrl+Right")));
516

Laurent Montel's avatar
Laurent Montel committed
517
    action = coll->addAction(QStringLiteral("feedstree_up"));
518
    action->setText(i18n("Go Up in Tree"));
Laurent Montel's avatar
Laurent Montel committed
519
    connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotItemUp);
Laurent Montel's avatar
Laurent Montel committed
520
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Ctrl+Up")));
521

Laurent Montel's avatar
Laurent Montel committed
522
    action = coll->addAction(QStringLiteral("feedstree_down"));
523
    action->setText(i18n("Go Down in Tree"));
Laurent Montel's avatar
Laurent Montel committed
524
    connect(action, &QAction::triggered, subscriptionListView, &SubscriptionListView::slotItemDown);
Laurent Montel's avatar
Laurent Montel committed
525
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Ctrl+Down")));
526 527
}

Laurent Montel's avatar
Laurent Montel committed
528
void ActionManagerImpl::initTabWidget(TabWidget *tabWidget)
529
{
Laurent Montel's avatar
Laurent Montel committed
530
    if (d->tabWidget) {
531
        return;
Laurent Montel's avatar
Laurent Montel committed
532
    } else {
533
        d->tabWidget = tabWidget;
Laurent Montel's avatar
Laurent Montel committed
534
    }
535

536 537
    KActionCollection *coll = actionCollection();

Laurent Montel's avatar
Laurent Montel committed
538
    QAction *action = coll->addAction(QStringLiteral("select_next_tab"));
539
    action->setText(i18n("Select Next Tab"));
Laurent Montel's avatar
Laurent Montel committed
540
    connect(action, &QAction::triggered, d->tabWidget, &TabWidget::slotNextTab);
Laurent Montel's avatar
Laurent Montel committed
541
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Ctrl+Period")));
542

Laurent Montel's avatar
Laurent Montel committed
543
    action = coll->addAction(QStringLiteral("select_previous_tab"));
544
    action->setText(i18n("Select Previous Tab"));
Laurent Montel's avatar
Laurent Montel committed
545
    connect(action, &QAction::triggered, d->tabWidget, &TabWidget::slotPreviousTab);
Laurent Montel's avatar
Laurent Montel committed
546
    coll->setDefaultShortcut(action, QKeySequence(QStringLiteral("Ctrl+Comma")));
547

Laurent Montel's avatar
Laurent Montel committed
548 549
    action = coll->addAction(QStringLiteral("tab_detach"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("tab-detach")));
550
    action->setText(i18n("Detach Tab"));
Laurent Montel's avatar
Laurent Montel committed
551
    connect(action, &QAction::triggered, d->tabWidget, &TabWidget::slotDetachTab);
Laurent Montel's avatar
Laurent Montel committed
552
    coll->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B));
553

Laurent Montel's avatar
Laurent Montel committed
554 555 556 557 558 559
    action = KStandardAction::copy(d->tabWidget, SLOT(slotCopy()), coll);
    coll->addAction(QStringLiteral("viewer_copy"), action);

    action = KStandardAction::print(d->tabWidget, SLOT(slotPrint()), coll);
    coll->addAction(QStringLiteral("viewer_print"), action);

Laurent Montel's avatar
Laurent Montel committed
560 561 562
    action = KStandardAction::printPreview(d->tabWidget, SLOT(slotPrintPreview()), coll);
    coll->addAction(QStringLiteral("viewer_printpreview"), action);

563 564 565 566 567 568 569 570 571 572
    action = new QAction(i18n("Speak Text"), this);
    action->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-text-to-speech")));
    coll->addAction(QStringLiteral("speak_text"), action);
    connect(action, &QAction::triggered, d->tabWidget, &TabWidget::slotTextToSpeech);

    action = new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("&Find in Message..."), this);
    coll->addAction(QStringLiteral("find_in_messages"), action);
    connect(action, &QAction::triggered, d->tabWidget, &TabWidget::slotFindTextInHtml);
    coll->setDefaultShortcut(action, KStandardShortcut::find().first());

Laurent Montel's avatar
Laurent Montel committed
573
    action = coll->addAction(QStringLiteral("tab_copylinkaddress"));
574
    action->setText(i18n("Copy Link Address"));
Laurent Montel's avatar
Laurent Montel committed
575
    connect(action, &QAction::triggered, d->tabWidget, &TabWidget::slotCopyLinkAddress);
576

Laurent Montel's avatar
Laurent Montel committed
577 578
    action = coll->addAction(QStringLiteral("tab_remove"));
    action->setIcon(QIcon::fromTheme(QStringLiteral("tab-close")));
579
    action->setText(i18n("Close Tab"));
Laurent Montel's avatar
Laurent Montel committed
580
    connect(action, &QAction::triggered, d->tabWidget, &TabWidget::slotCloseTab);
Laurent Montel's avatar
Laurent Montel committed
581
    coll->setDefaultShortcuts(action, KStandardShortcut::close());
Frank Osterfeld's avatar
Frank Osterfeld committed
582

Laurent Montel's avatar
Laurent Montel committed
583 584
    d->zoomActionMenu = new WebEngineViewer::ZoomActionMenu(this);
    connect(d->zoomActionMenu, &WebEngineViewer::ZoomActionMenu::zoomChanged, d->tabWidget, &TabWidget::slotZoomChanged);
Laurent Montel's avatar
Laurent Montel committed
585

Laurent Montel's avatar
Laurent Montel committed
586 587 588
    d->zoomActionMenu->setActionCollection(coll);
    d->zoomActionMenu->createZoomActions();