cmake: Autogenerate most of the .qrc resource files
[quassel.git] / src / client / coreaccount.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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
35 void CoreAccount::setAccountId(AccountId id)
36 {
37     _accountId = id;
38 }
39
40
41 void CoreAccount::setAccountName(const QString &name)
42 {
43     _accountName = name;
44 }
45
46
47 void CoreAccount::setUuid(const QUuid &uuid)
48 {
49     _uuid = uuid;
50 }
51
52
53 void CoreAccount::setInternal(bool internal)
54 {
55     _internal = internal;
56 }
57
58
59 void CoreAccount::setUser(const QString &user)
60 {
61     _user = user;
62 }
63
64
65 void CoreAccount::setPassword(const QString &password)
66 {
67     _password = password;
68 }
69
70
71 void CoreAccount::setStorePassword(bool store)
72 {
73     _storePassword = store;
74 }
75
76
77 void CoreAccount::setHostName(const QString &hostname)
78 {
79     _hostName = hostname;
80 }
81
82
83 void CoreAccount::setPort(uint port)
84 {
85     _port = port;
86 }
87
88
89 void CoreAccount::setUseSsl(bool useSsl)
90 {
91     _useSsl = useSsl;
92 }
93
94
95 void CoreAccount::setProxyType(QNetworkProxy::ProxyType type)
96 {
97     _proxyType = type;
98 }
99
100
101 void CoreAccount::setProxyUser(const QString &proxyUser)
102 {
103     _proxyUser = proxyUser;
104 }
105
106
107 void CoreAccount::setProxyPassword(const QString &proxyPassword)
108 {
109     _proxyPassword = proxyPassword;
110 }
111
112
113 void CoreAccount::setProxyHostName(const QString &proxyHostName)
114 {
115     _proxyHostName = proxyHostName;
116 }
117
118
119 void CoreAccount::setProxyPort(uint proxyPort)
120 {
121     _proxyPort = proxyPort;
122 }
123
124
125 QVariantMap CoreAccount::toVariantMap(bool forcePassword) const
126 {
127     QVariantMap v;
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();
132     v["User"] = user();
133     if (_storePassword || forcePassword)
134         v["Password"] = password();
135     else
136         v["Password"] = QString();
137     v["StorePassword"] = storePassword();
138     v["HostName"] = hostName();
139     v["Port"] = port();
140     v["UseSSL"] = useSsl();
141     v["ProxyType"] = proxyType();
142     v["ProxyUser"] = proxyUser();
143     v["ProxyPassword"] = proxyPassword();
144     v["ProxyHostName"] = proxyHostName();
145     v["ProxyPort"] = proxyPort();
146     return v;
147 }
148
149
150 void CoreAccount::fromVariantMap(const QVariantMap &v)
151 {
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());
167
168     _storePassword = !password().isEmpty();
169 }
170
171
172 bool CoreAccount::operator==(const CoreAccount &other) const
173 {
174     return toVariantMap(true) == other.toVariantMap(true);
175 }
176
177
178 bool CoreAccount::operator!=(const CoreAccount &other) const
179 {
180     return !(*this == other);
181 }
182
183
184 QDebug operator<<(QDebug dbg, const CoreAccount &acc)
185 {
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();
201     return dbg.space();
202 }