NetworkManagerQt

proxysetting.cpp
1/*
2 SPDX-FileCopyrightText: Pranav Gade <pranavgade20@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "proxysetting.h"
8#include "proxysetting_p.h"
9
10#include <QDebug>
11
12#if !NM_CHECK_VERSION(1, 6, 0)
13#define NM_SETTING_PROXY_SETTING_NAME "proxy"
14#define NM_SETTING_PROXY_BROWSER_ONLY "browser-only"
15#define NM_SETTING_PROXY_METHOD "method"
16#define NM_SETTING_PROXY_PAC_SCRIPT "pac-script"
17#define NM_SETTING_PROXY_PAC_URL "pac-url"
18#endif
19
20NetworkManager::ProxySettingPrivate::ProxySettingPrivate()
21 : name(NM_SETTING_PROXY_SETTING_NAME)
22 , browserOnly(false)
23 , method(ProxySetting::None)
24{
25}
26
27NetworkManager::ProxySetting::ProxySetting()
28 : Setting(Setting::Proxy)
29 , d_ptr(new ProxySettingPrivate())
30{
31}
32
33NetworkManager::ProxySetting::ProxySetting(const Ptr &other)
34 : Setting(other)
35 , d_ptr(new ProxySettingPrivate())
36{
37 setBrowserOnly(other->browserOnly());
38 setMethod(other->method());
39 setPacScript(other->pacScript());
40 setPacUrl(other->pacUrl());
41}
42
43NetworkManager::ProxySetting::~ProxySetting()
44{
45 delete d_ptr;
46}
47
49{
50 Q_D(const ProxySetting);
51
52 return d->name;
53}
54
55void NetworkManager::ProxySetting::setBrowserOnly(bool browserOnly)
56{
58
59 d->browserOnly = browserOnly;
60}
61
62bool NetworkManager::ProxySetting::browserOnly() const
63{
64 Q_D(const ProxySetting);
65
66 return d->browserOnly;
67}
68
69void NetworkManager::ProxySetting::setMethod(NetworkManager::ProxySetting::Mode method)
70{
71 Q_D(ProxySetting);
72
73 d->method = method;
74}
75
76NetworkManager::ProxySetting::Mode NetworkManager::ProxySetting::method() const
77{
78 Q_D(const ProxySetting);
79
80 return d->method;
81}
82
83void NetworkManager::ProxySetting::setPacScript(const QString &script)
84{
85 Q_D(ProxySetting);
86
87 d->pacScript = script;
88}
89
90QString NetworkManager::ProxySetting::pacScript() const
91{
92 Q_D(const ProxySetting);
93
94 return d->pacScript;
95}
96
97void NetworkManager::ProxySetting::setPacUrl(const QString &url)
98{
99 Q_D(ProxySetting);
100
101 d->pacUrl = url;
102}
103
104QString NetworkManager::ProxySetting::pacUrl() const
105{
106 Q_D(const ProxySetting);
107
108 return d->pacUrl;
109}
110
111void NetworkManager::ProxySetting::fromMap(const QVariantMap &setting)
112{
113 if (setting.contains(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY))) {
114 setBrowserOnly(setting.value(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY)).toBool());
115 }
116
117 if (setting.contains(QLatin1String(NM_SETTING_PROXY_METHOD))) {
118 setMethod((Mode)setting.value(QLatin1String(NM_SETTING_PROXY_METHOD)).toUInt());
119 }
120
121 if (setting.contains(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT))) {
122 setPacScript(setting.value(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT)).toString());
123 }
124
125 if (setting.contains(QLatin1String(NM_SETTING_PROXY_PAC_URL))) {
126 setPacUrl(setting.value(QLatin1String(NM_SETTING_PROXY_PAC_URL)).toString());
127 }
128}
129
131{
132 QVariantMap setting;
133
134 setting.insert(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY), browserOnly());
135
136 if (method() > 0) {
137 setting.insert(QLatin1String(NM_SETTING_PROXY_METHOD), (int)method());
138 }
139
140 if (!pacScript().isEmpty()) {
141 setting.insert(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT), pacScript());
142 }
143
144 if (!pacUrl().isEmpty()) {
145 setting.insert(QLatin1String(NM_SETTING_PROXY_PAC_URL), pacUrl());
146 }
147
148 return setting;
149}
150
151QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::ProxySetting &setting)
152{
153 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
154 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
155
156 dbg.nospace() << NM_SETTING_PROXY_BROWSER_ONLY << ": " << setting.browserOnly() << '\n';
157 dbg.nospace() << NM_SETTING_PROXY_METHOD << ": " << setting.method() << '\n';
158 dbg.nospace() << NM_SETTING_PROXY_PAC_SCRIPT << ": " << setting.pacScript() << '\n';
159 dbg.nospace() << NM_SETTING_PROXY_PAC_URL << ": " << setting.pacUrl() << '\n';
160
161 return dbg.maybeSpace();
162}
Represents proxy setting.
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
QString name() const override
Must be reimplemented, default implementationd does nothing.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
QDebug & maybeSpace()
QDebug & nospace()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:56:22 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.