7#include "remotecontentmanager.h"
8#include "remotecontentinfo.h"
10#include <KSharedConfig>
12using namespace MessageViewer;
15static const char myRemoteContentGroupName[] =
"RemoteContent";
17RemoteContentManager::RemoteContentManager(
QObject *parent)
23RemoteContentManager::~RemoteContentManager()
30 static RemoteContentManager s_self;
34void RemoteContentManager::clear()
36 mRemoveContentInfo.clear();
39bool RemoteContentManager::isAutorized(
const QString &url)
const
41 for (
const RemoteContentInfo &info : std::as_const(mRemoveContentInfo)) {
42 if (info.url() == url) {
43 return info.status() == RemoteContentInfo::RemoteContentInfoStatus::Authorized;
49bool RemoteContentManager::isAutorized(
const QUrl &url,
bool &contains)
const
51 const QString host = url.
host();
52 const QString urlToString = url.
toString();
56 for (
const RemoteContentInfo &info : std::as_const(mRemoveContentInfo)) {
57 if (info.url() == urlToString) {
59 return info.status() == RemoteContentInfo::RemoteContentInfoStatus::Authorized;
60 }
else if (info.url() == host) {
62 return info.status() == RemoteContentInfo::RemoteContentInfoStatus::Authorized;
68bool RemoteContentManager::isBlocked(
const QUrl &url,
bool &contains)
const
70 const QString host = url.
host();
71 const QString urlToString = url.
toString();
75 for (
const RemoteContentInfo &info : std::as_const(mRemoveContentInfo)) {
76 if (info.url() == urlToString) {
78 return info.status() == RemoteContentInfo::RemoteContentInfoStatus::Blocked;
79 }
else if (info.url() == host) {
81 return info.status() == RemoteContentInfo::RemoteContentInfoStatus::Blocked;
87void RemoteContentManager::loadSettings()
89 mRemoveContentInfo.clear();
91 KConfigGroup group(config, QLatin1StringView(myRemoteContentGroupName));
92 const QStringList blockedUrl = group.readEntry(
"Blocked", QStringList());
93 const QStringList authorizedUrl = group.readEntry(
"Authorized", QStringList());
94 mRemoveContentInfo.reserve(blockedUrl.
count() + authorizedUrl.
count());
95 for (
const QString &url : blockedUrl) {
96 RemoteContentInfo info;
98 info.setStatus(RemoteContentInfo::RemoteContentInfoStatus::Blocked);
99 mRemoveContentInfo.append(info);
101 for (
const QString &url : authorizedUrl) {
102 RemoteContentInfo info;
104 info.setStatus(RemoteContentInfo::RemoteContentInfoStatus::Authorized);
105 mRemoveContentInfo.append(info);
109void RemoteContentManager::writeSettings()
112 KConfigGroup group(config, QLatin1StringView(myRemoteContentGroupName));
113 QStringList blockedUrl;
114 QStringList authorizedUrl;
115 for (
const RemoteContentInfo &info : std::as_const(mRemoveContentInfo)) {
116 switch (info.status()) {
117 case RemoteContentInfo::RemoteContentInfoStatus::Unknown:
119 case RemoteContentInfo::RemoteContentInfoStatus::Blocked:
120 blockedUrl.
append(info.url());
122 case RemoteContentInfo::RemoteContentInfoStatus::Authorized:
123 authorizedUrl.
append(info.url());
127 group.writeEntry(
"Blocked", blockedUrl);
128 group.writeEntry(
"Authorized", authorizedUrl);
132void RemoteContentManager::setRemoveContentInfo(
const QList<RemoteContentInfo> &removeContentInfo)
134 mRemoveContentInfo = removeContentInfo;
137QList<RemoteContentInfo> RemoteContentManager::removeContentInfo()
const
139 return mRemoveContentInfo;
144 mRemoveContentInfo.append(info);
149 for (
const RemoteContentInfo &info : std::as_const(mRemoveContentInfo)) {
150 if (info.url() == newInfo.url()) {
157#include "moc_remotecontentmanager.cpp"
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
The RemoteContentInfo class.
The RemoteContentManager class.
void append(QList< T > &&value)
qsizetype count() const const
QString host(ComponentFormattingOptions options) const const
QString toString(FormattingOptions options) const const