1 /***************************************************************************
2 * Copyright (C) 2005-2018 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;
35 void CoreAccount::setAccountId(AccountId id)
41 void CoreAccount::setAccountName(const QString &name)
47 void CoreAccount::setUuid(const QUuid &uuid)
53 void CoreAccount::setInternal(bool internal)
59 void CoreAccount::setUser(const QString &user)
65 void CoreAccount::setPassword(const QString &password)
71 void CoreAccount::setStorePassword(bool store)
73 _storePassword = store;
77 void CoreAccount::setHostName(const QString &hostname)
83 void CoreAccount::setPort(uint port)
89 void CoreAccount::setUseSsl(bool useSsl)
95 void CoreAccount::setProxyType(QNetworkProxy::ProxyType type)
101 void CoreAccount::setProxyUser(const QString &proxyUser)
103 _proxyUser = proxyUser;
107 void CoreAccount::setProxyPassword(const QString &proxyPassword)
109 _proxyPassword = proxyPassword;
113 void CoreAccount::setProxyHostName(const QString &proxyHostName)
115 _proxyHostName = proxyHostName;
119 void CoreAccount::setProxyPort(uint proxyPort)
121 _proxyPort = proxyPort;
125 QVariantMap CoreAccount::toVariantMap(bool forcePassword) const
128 v["AccountId"] = accountId().toInt(); // can't use AccountId because then comparison fails
129 v["AccountName"] = accountName();
130 v["Uuid"] = uuid().toString();
131 v["Internal"] = isInternal();
133 if (_storePassword || forcePassword)
134 v["Password"] = password();
136 v["Password"] = QString();
137 v["StorePassword"] = storePassword();
138 v["HostName"] = hostName();
140 v["UseSSL"] = useSsl();
141 v["ProxyType"] = proxyType();
142 v["ProxyUser"] = proxyUser();
143 v["ProxyPassword"] = proxyPassword();
144 v["ProxyHostName"] = proxyHostName();
145 v["ProxyPort"] = proxyPort();
150 void CoreAccount::fromVariantMap(const QVariantMap &v)
152 setAccountId((AccountId)v.value("AccountId").toInt());
153 setAccountName(v.value("AccountName").toString());
154 setUuid(QUuid(v.value("Uuid").toString()));
155 setInternal(v.value("Internal").toBool());
156 setUser(v.value("User").toString());
157 setPassword(v.value("Password").toString());
158 setStorePassword(v.value("StorePassword").toBool());
159 setHostName(v.value("HostName").toString());
160 setPort(v.value("Port").toUInt());
161 setUseSsl(v.value("UseSSL").toBool());
162 setProxyType((QNetworkProxy::ProxyType)v.value("ProxyType").toInt());
163 setProxyUser(v.value("ProxyUser").toString());
164 setProxyPassword(v.value("ProxyPassword").toString());
165 setProxyHostName(v.value("ProxyHostName").toString());
166 setProxyPort(v.value("ProxyPort").toUInt());
168 _storePassword = !password().isEmpty();
172 bool CoreAccount::operator==(const CoreAccount &other) const
174 return toVariantMap(true) == other.toVariantMap(true);
178 bool CoreAccount::operator!=(const CoreAccount &other) const
180 return !(*this == other);
184 QDebug operator<<(QDebug dbg, const CoreAccount &acc)
186 dbg.nospace() << qPrintable(QString("CoreAccount(AccountId:")) << acc.accountId()
187 << qPrintable(QString(", AccountName:")) << acc.accountName()
188 << qPrintable(QString(", Uuid:")) << acc.uuid()
189 << qPrintable(QString(", Internal:")) << acc.isInternal()
190 << qPrintable(QString(", User:")) << acc.user()
191 << qPrintable(QString(", Password:")) << acc.password()
192 << qPrintable(QString(", StorePassword:")) << acc.storePassword()
193 << qPrintable(QString(", HostName:")) << acc.hostName()
194 << qPrintable(QString(", Port:")) << acc.port()
195 << qPrintable(QString(", UseSSL:")) << acc.useSsl()
196 << qPrintable(QString(", ProxyType:")) << acc.proxyType()
197 << qPrintable(QString(", ProxyUser:")) << acc.proxyUser()
198 << qPrintable(QString(", ProxyPassword:")) << acc.proxyPassword()
199 << qPrintable(QString(", ProxyHostName:")) << acc.proxyHostName()
200 << qPrintable(QString(", ProxyPort:")) << acc.proxyPort();