1 /***************************************************************************
2 * Copyright (C) 2005-2019 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;
30 _proxyType = QNetworkProxy::DefaultProxy;
34 void CoreAccount::setAccountId(AccountId id)
39 void CoreAccount::setAccountName(const QString& name)
44 void CoreAccount::setUuid(const QUuid& uuid)
49 void CoreAccount::setInternal(bool internal)
54 void CoreAccount::setUser(const QString& user)
59 void CoreAccount::setPassword(const QString& password)
64 void CoreAccount::setStorePassword(bool store)
66 _storePassword = store;
69 void CoreAccount::setHostName(const QString& hostname)
74 void CoreAccount::setPort(uint port)
79 void CoreAccount::setUseSsl(bool useSsl)
84 void CoreAccount::setProxyType(QNetworkProxy::ProxyType type)
89 void CoreAccount::setProxyUser(const QString& proxyUser)
91 _proxyUser = proxyUser;
94 void CoreAccount::setProxyPassword(const QString& proxyPassword)
96 _proxyPassword = proxyPassword;
99 void CoreAccount::setProxyHostName(const QString& proxyHostName)
101 _proxyHostName = proxyHostName;
104 void CoreAccount::setProxyPort(uint proxyPort)
106 _proxyPort = proxyPort;
109 QVariantMap CoreAccount::toVariantMap(bool forcePassword) const
112 v["AccountId"] = accountId().toInt(); // can't use AccountId because then comparison fails
113 v["AccountName"] = accountName();
114 v["Uuid"] = uuid().toString();
115 v["Internal"] = isInternal();
117 if (_storePassword || forcePassword)
118 v["Password"] = password();
120 v["Password"] = QString();
121 v["StorePassword"] = storePassword();
122 v["HostName"] = hostName();
124 v["UseSSL"] = useSsl();
125 v["ProxyType"] = proxyType();
126 v["ProxyUser"] = proxyUser();
127 v["ProxyPassword"] = proxyPassword();
128 v["ProxyHostName"] = proxyHostName();
129 v["ProxyPort"] = proxyPort();
133 void CoreAccount::fromVariantMap(const QVariantMap& v)
135 setAccountId((AccountId)v.value("AccountId").toInt());
136 setAccountName(v.value("AccountName").toString());
137 setUuid(QUuid(v.value("Uuid").toString()));
138 setInternal(v.value("Internal").toBool());
139 setUser(v.value("User").toString());
140 setPassword(v.value("Password").toString());
141 setStorePassword(v.value("StorePassword").toBool());
142 setHostName(v.value("HostName").toString());
143 setPort(v.value("Port").toUInt());
144 setUseSsl(v.value("UseSSL").toBool());
145 setProxyType((QNetworkProxy::ProxyType)v.value("ProxyType").toInt());
146 setProxyUser(v.value("ProxyUser").toString());
147 setProxyPassword(v.value("ProxyPassword").toString());
148 setProxyHostName(v.value("ProxyHostName").toString());
149 setProxyPort(v.value("ProxyPort").toUInt());
151 _storePassword = !password().isEmpty();
154 bool CoreAccount::operator==(const CoreAccount& other) const
156 return toVariantMap(true) == other.toVariantMap(true);
159 bool CoreAccount::operator!=(const CoreAccount& other) const
161 return !(*this == other);
164 QDebug operator<<(QDebug dbg, const CoreAccount& acc)
166 dbg.nospace() << qPrintable(QString("CoreAccount(AccountId:")) << acc.accountId()
167 << qPrintable(QString(", AccountName:")) << acc.accountName()
168 << qPrintable(QString(", Uuid:")) << acc.uuid()
169 << qPrintable(QString(", Internal:")) << acc.isInternal()
170 << qPrintable(QString(", User:")) << acc.user()
171 << qPrintable(QString(", Password:")) << acc.password()
172 << qPrintable(QString(", StorePassword:")) << acc.storePassword()
173 << qPrintable(QString(", HostName:")) << acc.hostName()
174 << qPrintable(QString(", Port:")) << acc.port()
175 << qPrintable(QString(", UseSSL:")) << acc.useSsl()
176 << qPrintable(QString(", ProxyType:")) << acc.proxyType()
177 << qPrintable(QString(", ProxyUser:")) << acc.proxyUser()
178 << qPrintable(QString(", ProxyPassword:")) << acc.proxyPassword()
179 << qPrintable(QString(", ProxyHostName:")) << acc.proxyHostName()
180 << qPrintable(QString(", ProxyPort:")) << acc.proxyPort();