Messagelib

remotecontentmenu.cpp
1 /*
2  SPDX-FileCopyrightText: 2020-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "remotecontentmenu.h"
8 #include "remote-content/remotecontentmanager.h"
9 #include "remotecontentconfiguredialog.h"
10 #include "remotecontentinfo.h"
11 #include <KLocalizedString>
12 #include <QAction>
13 
14 using namespace MessageViewer;
15 RemoteContentMenu::RemoteContentMenu(QWidget *parent)
16  : QMenu(parent)
17  , mConfigureRemoteContentAction(new QAction(QIcon::fromTheme(QStringLiteral("settings-configure")), i18n("Configure"), this))
18 {
19  setTitle(i18n("Remote Content"));
20  connect(this, &QMenu::aboutToShow, this, &RemoteContentMenu::updateMenu);
21 }
22 
23 RemoteContentMenu::~RemoteContentMenu() = default;
24 
25 void RemoteContentMenu::slotConfigure()
26 {
28  dlg.exec();
29 }
30 
31 QStringList RemoteContentMenu::urls() const
32 {
33  return mUrls;
34 }
35 
36 void RemoteContentMenu::setUrls(const QStringList &urls)
37 {
38  mUrls = urls;
39 }
40 
41 void RemoteContentMenu::updateMenu()
42 {
43  for (auto act : std::as_const(mListAction)) {
44  removeAction(act);
45  }
46  const int numberOfUrl{mUrls.count()};
47  if (numberOfUrl > 0) {
48  mListAction.reserve(numberOfUrl + 3);
49  for (const QString &url : std::as_const(mUrls)) {
50  QAction *act = addAction(i18n("Authorize %1", url));
51  connect(act, &QAction::triggered, this, [this, url]() {
52  authorize(url);
53  mUrls.removeAll(url);
54  });
55  mListAction << act;
56  }
57  mListAction << addSeparator();
58  QAction *act = addAction(i18n("Authorize all Urls"));
59  connect(act, &QAction::triggered, this, [this]() {
60  for (const QString &url : std::as_const(mUrls)) {
61  authorize(url);
62  }
63  mUrls.clear();
64  });
65  mListAction << act;
66  mListAction << addSeparator();
67  }
68  addAction(mConfigureRemoteContentAction);
69  connect(mConfigureRemoteContentAction, &QAction::triggered, this, &RemoteContentMenu::slotConfigure);
70 }
71 
72 void RemoteContentMenu::authorize(const QString &url)
73 {
74  RemoteContentInfo info;
75  info.setUrl(url);
76  info.setStatus(RemoteContentInfo::RemoteContentInfoStatus::Authorized);
77  RemoteContentManager::self()->addRemoteContent(info);
78  Q_EMIT updateEmail();
79 }
80 
81 void RemoteContentMenu::clearUrls()
82 {
83  mUrls.clear();
84 }
85 
86 void RemoteContentMenu::appendUrl(const QString &url)
87 {
88  if (!mUrls.contains(url)) {
89  mUrls.append(url);
90  }
91 }
void triggered(bool checked)
The RemoteContentInfo class.
The RemoteContentConfigureDialog class.
void aboutToShow()
QString i18n(const char *text, const TYPE &arg...)
KCONFIGCORE_EXPORT bool authorize(const QString &action)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.