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