1 /***************************************************************************
2 * Copyright (C) 2005-2022 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "coreaccount.h"
23 CoreAccount::CoreAccount(AccountId accountId)
25 _accountId = accountId;
28 _storePassword = false;
29 _proxyType = QNetworkProxy::DefaultProxy;
33 void CoreAccount::setAccountId(AccountId id)
38 void CoreAccount::setAccountName(const QString& name)
43 void CoreAccount::setUuid(const QUuid& uuid)
48 void CoreAccount::setInternal(bool internal)
53 void CoreAccount::setUser(const QString& user)
58 void CoreAccount::setPassword(const QString& password)
63 void CoreAccount::setStorePassword(bool store)
65 _storePassword = store;
68 void CoreAccount::setHostName(const QString& hostname)
73 void CoreAccount::setPort(uint port)
78 void CoreAccount::setProxyType(QNetworkProxy::ProxyType type)
83 void CoreAccount::setProxyUser(const QString& proxyUser)
85 _proxyUser = proxyUser;
88 void CoreAccount::setProxyPassword(const QString& proxyPassword)
90 _proxyPassword = proxyPassword;
93 void CoreAccount::setProxyHostName(const QString& proxyHostName)
95 _proxyHostName = proxyHostName;
98 void CoreAccount::setProxyPort(uint proxyPort)
100 _proxyPort = proxyPort;
103 QVariantMap CoreAccount::toVariantMap(bool forcePassword) const
106 v["AccountId"] = accountId().toInt(); // can't use AccountId because then comparison fails
107 v["AccountName"] = accountName();
108 v["Uuid"] = uuid().toString();
109 v["Internal"] = isInternal();
111 if (_storePassword || forcePassword)
112 v["Password"] = password();
114 v["Password"] = QString();
115 v["StorePassword"] = storePassword();
116 v["HostName"] = hostName();
118 v["ProxyType"] = proxyType();
119 v["ProxyUser"] = proxyUser();
120 v["ProxyPassword"] = proxyPassword();
121 v["ProxyHostName"] = proxyHostName();
122 v["ProxyPort"] = proxyPort();
126 void CoreAccount::fromVariantMap(const QVariantMap& v)
128 setAccountId((AccountId)v.value("AccountId").toInt());
129 setAccountName(v.value("AccountName").toString());
130 setUuid(QUuid(v.value("Uuid").toString()));
131 setInternal(v.value("Internal").toBool());
132 setUser(v.value("User").toString());
133 setPassword(v.value("Password").toString());
134 setStorePassword(v.value("StorePassword").toBool());
135 setHostName(v.value("HostName").toString());
136 setPort(v.value("Port").toUInt());
137 setProxyType((QNetworkProxy::ProxyType)v.value("ProxyType").toInt());
138 setProxyUser(v.value("ProxyUser").toString());
139 setProxyPassword(v.value("ProxyPassword").toString());
140 setProxyHostName(v.value("ProxyHostName").toString());
141 setProxyPort(v.value("ProxyPort").toUInt());
143 _storePassword = !password().isEmpty();
146 bool CoreAccount::operator==(const CoreAccount& other) const
148 return toVariantMap(true) == other.toVariantMap(true);
151 bool CoreAccount::operator!=(const CoreAccount& other) const
153 return !(*this == other);
156 QDebug operator<<(QDebug dbg, const CoreAccount& acc)
158 dbg.nospace() << qPrintable(QString("CoreAccount(AccountId:")) << acc.accountId()
159 << qPrintable(QString(", AccountName:")) << acc.accountName()
160 << qPrintable(QString(", Uuid:")) << acc.uuid()
161 << qPrintable(QString(", Internal:")) << acc.isInternal()
162 << qPrintable(QString(", User:")) << acc.user()
163 << qPrintable(QString(", Password:")) << acc.password()
164 << qPrintable(QString(", StorePassword:")) << acc.storePassword()
165 << qPrintable(QString(", HostName:")) << acc.hostName()
166 << qPrintable(QString(", Port:")) << acc.port()
167 << qPrintable(QString(", ProxyType:")) << acc.proxyType()
168 << qPrintable(QString(", ProxyUser:")) << acc.proxyUser()
169 << qPrintable(QString(", ProxyPassword:")) << acc.proxyPassword()
170 << qPrintable(QString(", ProxyHostName:")) << acc.proxyHostName()
171 << qPrintable(QString(", ProxyPort:")) << acc.proxyPort();