src: Yearly copyright bump
[quassel.git] / src / client / coreaccount.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2020 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "coreaccount.h"
22
23 CoreAccount::CoreAccount(AccountId accountId)
24 {
25     _accountId = accountId;
26     _internal = false;
27     _port = 4242;
28     _storePassword = false;
29     _useSsl = true;
30     _proxyType = QNetworkProxy::DefaultProxy;
31     _proxyPort = 8080;
32 }
33
34 void CoreAccount::setAccountId(AccountId id)
35 {
36     _accountId = id;
37 }
38
39 void CoreAccount::setAccountName(const QString& name)
40 {
41     _accountName = name;
42 }
43
44 void CoreAccount::setUuid(const QUuid& uuid)
45 {
46     _uuid = uuid;
47 }
48
49 void CoreAccount::setInternal(bool internal)
50 {
51     _internal = internal;
52 }
53
54 void CoreAccount::setUser(const QString& user)
55 {
56     _user = user;
57 }
58
59 void CoreAccount::setPassword(const QString& password)
60 {
61     _password = password;
62 }
63
64 void CoreAccount::setStorePassword(bool store)
65 {
66     _storePassword = store;
67 }
68
69 void CoreAccount::setHostName(const QString& hostname)
70 {
71     _hostName = hostname;
72 }
73
74 void CoreAccount::setPort(uint port)
75 {
76     _port = port;
77 }
78
79 void CoreAccount::setUseSsl(bool useSsl)
80 {
81     _useSsl = useSsl;
82 }
83
84 void CoreAccount::setProxyType(QNetworkProxy::ProxyType type)
85 {
86     _proxyType = type;
87 }
88
89 void CoreAccount::setProxyUser(const QString& proxyUser)
90 {
91     _proxyUser = proxyUser;
92 }
93
94 void CoreAccount::setProxyPassword(const QString& proxyPassword)
95 {
96     _proxyPassword = proxyPassword;
97 }
98
99 void CoreAccount::setProxyHostName(const QString& proxyHostName)
100 {
101     _proxyHostName = proxyHostName;
102 }
103
104 void CoreAccount::setProxyPort(uint proxyPort)
105 {
106     _proxyPort = proxyPort;
107 }
108
109 QVariantMap CoreAccount::toVariantMap(bool forcePassword) const
110 {
111     QVariantMap v;
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();
116     v["User"] = user();
117     if (_storePassword || forcePassword)
118         v["Password"] = password();
119     else
120         v["Password"] = QString();
121     v["StorePassword"] = storePassword();
122     v["HostName"] = hostName();
123     v["Port"] = port();
124     v["UseSSL"] = useSsl();
125     v["ProxyType"] = proxyType();
126     v["ProxyUser"] = proxyUser();
127     v["ProxyPassword"] = proxyPassword();
128     v["ProxyHostName"] = proxyHostName();
129     v["ProxyPort"] = proxyPort();
130     return v;
131 }
132
133 void CoreAccount::fromVariantMap(const QVariantMap& v)
134 {
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());
150
151     _storePassword = !password().isEmpty();
152 }
153
154 bool CoreAccount::operator==(const CoreAccount& other) const
155 {
156     return toVariantMap(true) == other.toVariantMap(true);
157 }
158
159 bool CoreAccount::operator!=(const CoreAccount& other) const
160 {
161     return !(*this == other);
162 }
163
164 QDebug operator<<(QDebug dbg, const CoreAccount& acc)
165 {
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();
181     return dbg.space();
182 }