d4aed0f31efb8bb57d84a2c6c0c624f981d244f9
[quassel.git] / src / client / coreaccount.h
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 #pragma once
22
23 #include "client-export.h"
24
25 #include <QCoreApplication>
26 #include <QDebug>
27 #include <QNetworkProxy>
28 #include <QUuid>
29 #include <QVariantMap>
30
31 #include "types.h"
32
33 class CLIENT_EXPORT CoreAccount
34 {
35     Q_DECLARE_TR_FUNCTIONS(CoreAccount)
36
37 public:
38     CoreAccount(AccountId accountId = 0);
39     virtual ~CoreAccount() {};
40
41     inline bool isValid() const { return accountId().isValid(); }
42     inline AccountId accountId() const { return _accountId; }
43     inline QString accountName() const { return isInternal() ? tr("Internal Core") : _accountName; }
44     inline QUuid uuid() const { return _uuid; }
45     inline bool isInternal() const { return _internal; }
46
47     inline QString user() const { return _user; }
48     inline bool storePassword() const { return _storePassword; }
49     inline QString hostName() const { return _hostName; }
50     inline uint port() const { return _port; }
51     inline bool useSsl() const { return _useSsl; }
52
53     inline QNetworkProxy::ProxyType proxyType() const { return _proxyType; }
54     inline QString proxyUser() const { return _proxyUser; }
55     inline QString proxyHostName() const { return _proxyHostName; }
56     inline uint proxyPort() const { return _proxyPort; }
57
58     void setAccountId(AccountId id);
59     void setAccountName(const QString &accountName);
60     void setUuid(const QUuid &uuid);
61     void setInternal(bool);
62
63     void setUser(const QString &user);
64     void setStorePassword(bool);
65     void setHostName(const QString &hostname);
66     void setPort(uint port);
67     void setUseSsl(bool);
68
69     void setProxyType(QNetworkProxy::ProxyType);
70     void setProxyUser(const QString &);
71     void setProxyHostName(const QString &);
72     void setProxyPort(uint);
73
74     /* These might be overridden for KWallet/QtKeychain support */
75     virtual inline QString password() const { return _password; }
76     virtual void setPassword(const QString &password);
77     virtual inline QString proxyPassword() const { return _proxyPassword; }
78     virtual void setProxyPassword(const QString &);
79
80     virtual QVariantMap toVariantMap(bool forcePassword = false) const;
81     virtual void fromVariantMap(const QVariantMap &);
82
83     bool operator==(const CoreAccount &other) const;
84     bool operator!=(const CoreAccount &other) const;
85
86 private:
87     AccountId _accountId;
88     QString _accountName;
89     QUuid _uuid;
90     bool _internal;
91     QString _user, _password, _hostName;
92     uint _port;
93     bool _storePassword, _useSsl;
94     QNetworkProxy::ProxyType _proxyType;
95     QString _proxyUser, _proxyPassword, _proxyHostName;
96     uint _proxyPort;
97 };
98
99 QDebug operator<<(QDebug dbg, const CoreAccount &msg);