Messagelib

remotecontentmenu.cpp
1/*
2 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
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
14using namespace MessageViewer;
15RemoteContentMenu::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
23RemoteContentMenu::~RemoteContentMenu() = default;
24
25void RemoteContentMenu::slotConfigure()
26{
28 dlg.exec();
29}
30
31QStringList RemoteContentMenu::urls() const
32{
33 return mUrls;
34}
35
36void RemoteContentMenu::setUrls(const QStringList &urls)
37{
38 mUrls = urls;
39}
40
41void RemoteContentMenu::updateMenu()
42{
43 for (auto act : std::as_const(mListAction)) {
44 removeAction(act);
45 }
46 const auto 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
72void RemoteContentMenu::authorize(const QString &url)
73{
75 info.setUrl(url);
76 info.setStatus(RemoteContentInfo::RemoteContentInfoStatus::Authorized);
77 RemoteContentManager::self()->addRemoteContent(info);
78 Q_EMIT updateEmail();
79}
80
81void RemoteContentMenu::clearUrls()
82{
83 mUrls.clear();
84}
85
86void RemoteContentMenu::appendUrl(const QString &url)
87{
88 if (!mUrls.contains(url)) {
89 mUrls.append(url);
90 }
91}
92
93#include "moc_remotecontentmenu.cpp"
The RemoteContentInfo class.
QString i18n(const char *text, const TYPE &arg...)
void triggered(bool checked)
void append(QList< T > &&value)
void clear()
qsizetype count() const const
qsizetype removeAll(const AT &t)
void reserve(qsizetype size)
QAction * addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut)
void aboutToShow()
QAction * addSeparator()
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void removeAction(QAction *action)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.