File indexing completed on 2024-11-24 04:53:09

0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
0002 
0003    This file is part of the Trojita Qt IMAP e-mail client,
0004    http://trojita.flaska.net/
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public License as
0008    published by the Free Software Foundation; either version 2 of
0009    the License or (at your option) version 3 or any later version
0010    accepted by the membership of KDE e.V. (or its successor approved
0011    by the membership of KDE e.V.), which shall act as a proxy
0012    defined in Section 14 of version 3 of the license.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017    GNU General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #ifndef TROJITA_IMAPACCESS_H
0024 #define TROJITA_IMAPACCESS_H
0025 
0026 #include <QObject>
0027 #include <QSslError>
0028 
0029 #include "Common/ConnectionMethod.h"
0030 #include "Common/Logging.h"
0031 #include "Imap/Model/NetworkPolicy.h"
0032 #include "UiUtils/Formatting.h"
0033 
0034 class QModelIndex;
0035 class QNetworkAccessManager;
0036 class QSettings;
0037 
0038 namespace Plugins {
0039 class PluginManager;
0040 }
0041 
0042 namespace UiUtils {
0043 class PasswordWatcher;
0044 }
0045 
0046 namespace Imap {
0047 
0048 namespace Mailbox {
0049 class MailboxModel;
0050 class Model;
0051 class MsgListModel;
0052 class NetworkWatcher;
0053 class OneMessageModel;
0054 class SubtreeModelOfMailboxModel;
0055 class ThreadingMsgListModel;
0056 class VisibleTasksModel;
0057 }
0058 
0059 class ImapAccess : public QObject
0060 {
0061     Q_OBJECT
0062 
0063     Q_PROPERTY(bool isConfigured READ isConfigured NOTIFY modelsChanged)
0064     Q_PROPERTY(QObject *imapModel READ imapModel NOTIFY modelsChanged)
0065     Q_PROPERTY(QObject *mailboxModel READ mailboxModel NOTIFY modelsChanged)
0066     Q_PROPERTY(QObject *msgListModel READ msgListModel NOTIFY modelsChanged)
0067     Q_PROPERTY(QObject *threadingMsgListModel READ threadingMsgListModel NOTIFY modelsChanged)
0068     Q_PROPERTY(QObject *visibleTasksModel READ visibleTasksModel NOTIFY modelsChanged)
0069     Q_PROPERTY(QObject *oneMessageModel READ oneMessageModel NOTIFY modelsChanged)
0070     Q_PROPERTY(QObject *networkWatcher READ networkWatcher NOTIFY modelsChanged)
0071     Q_PROPERTY(QObject *msgQNAM READ msgQNAM NOTIFY modelsChanged)
0072     Q_PROPERTY(UiUtils::PasswordWatcher *passwordWatcher READ passwordWatcher NOTIFY modelsChanged)
0073     Q_PROPERTY(QString server READ server WRITE setServer NOTIFY serverChanged)
0074     Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
0075     Q_PROPERTY(QString username READ username WRITE setUsername NOTIFY usernameChanged)
0076     Q_PROPERTY(QString sslMode READ sslMode WRITE setSslMode NOTIFY connMethodChanged)
0077     Q_PROPERTY(QString sslInfoTitle READ sslInfoTitle NOTIFY checkSslPolicy)
0078     Q_PROPERTY(QString sslInfoMessage READ sslInfoMessage NOTIFY checkSslPolicy)
0079     Q_PROPERTY(int numberRefreshInterval READ numberRefreshInterval WRITE setNumberRefreshInterval NOTIFY numberRefreshIntervalChanged)
0080     Q_ENUMS(Imap::ImapAccess::ConnectionMethod)
0081 
0082 public:
0083     ImapAccess(QObject *parent, QSettings *settings, Plugins::PluginManager *pluginManager, const QString &accountName);
0084 
0085     bool isConfigured() const;
0086     QAbstractItemModel *imapModel() const;
0087     QAbstractItemModel *mailboxModel() const;
0088     QAbstractItemModel *msgListModel() const;
0089     QAbstractItemModel *visibleTasksModel() const;
0090     QObject *oneMessageModel() const;
0091     QObject *networkWatcher() const;
0092     QAbstractItemModel *threadingMsgListModel() const;
0093     QObject *msgQNAM() const;
0094     UiUtils::PasswordWatcher *passwordWatcher() const;
0095 
0096     QString server() const;
0097     void setServer(const QString &server);
0098     int port() const;
0099     void setPort(const int port);
0100     QString username() const;
0101     void setUsername(const QString &username);
0102     QString password() const;
0103     void setPassword(const QString &password);
0104     QString sslMode() const;
0105     void setSslMode(const QString &sslMode);
0106     int numberRefreshInterval() const;
0107     void setNumberRefreshInterval(const int interval);
0108 
0109     QString accountName() const;
0110 
0111     QString accountIconName() const;
0112     void setAccountIconName(const QString &iconName);
0113 
0114     Common::ConnectionMethod connectionMethod() const;
0115     void setConnectionMethod(const Common::ConnectionMethod mode);
0116 
0117     Imap::Mailbox::NetworkPolicy preferredNetworkPolicy() const;
0118 
0119     Q_INVOKABLE void doConnect();
0120 
0121     QString sslInfoTitle() const;
0122     QString sslInfoMessage() const;
0123     UiUtils::Formatting::IconType sslInfoIcon() const;
0124 
0125     Q_INVOKABLE void openMessage(const QString &mailbox, const uint uid);
0126     Q_INVOKABLE void setSslPolicy(bool accept);
0127     Q_INVOKABLE void forgetSslCertificate();
0128 
0129     Q_INVOKABLE void nukeCache();
0130 
0131     Q_INVOKABLE QString mailboxListShortMailboxName() const;
0132     Q_INVOKABLE QString mailboxListMailboxName() const;
0133 
0134     Q_INVOKABLE QModelIndex deproxifiedIndex(const QModelIndex index);
0135     Q_INVOKABLE void markMessageDeleted(const QModelIndex &message, bool marked);
0136 signals:
0137     void serverChanged();
0138     void portChanged();
0139     void usernameChanged();
0140     void connMethodChanged();
0141     void modelsChanged();
0142     void checkSslPolicy();
0143     void cacheError(const QString &message);
0144     void numberRefreshIntervalChanged();
0145 
0146 public slots:
0147     void alertReceived(const QString &message);
0148     void imapError(const QString &message);
0149     void networkError(const QString &message);
0150     void onCacheError(const QString &message);
0151     void slotLogged(uint parserId, const Common::LogMessage &message);
0152     void slotSslErrors(const QList<QSslCertificate> &sslCertificateChain, const QList<QSslError> &sslErrors);
0153     void reloadConfiguration();
0154 
0155 private slots:
0156     void onRequireStartTlsInFuture();
0157     void desiredNetworkPolicyChanged(const Imap::Mailbox::NetworkPolicy policy);
0158 
0159 private:
0160     QSettings *m_settings;
0161     Imap::Mailbox::Model *m_imapModel;
0162     Imap::Mailbox::MailboxModel *m_mailboxModel;
0163     Imap::Mailbox::SubtreeModelOfMailboxModel *m_mailboxSubtreeModel;
0164     Imap::Mailbox::MsgListModel *m_msgListModel;
0165     Imap::Mailbox::ThreadingMsgListModel *m_threadingMsgListModel;
0166     Imap::Mailbox::VisibleTasksModel *m_visibleTasksModel;
0167     Imap::Mailbox::OneMessageModel *m_oneMessageModel;
0168     Imap::Mailbox::NetworkWatcher *m_netWatcher;
0169     QNetworkAccessManager *m_msgQNAM;
0170     Plugins::PluginManager *m_pluginManager;
0171     UiUtils::PasswordWatcher *m_passwordWatcher;
0172 
0173     QString m_server;
0174     int m_port;
0175     QString m_username;
0176     QString m_password;
0177     Common::ConnectionMethod m_connectionMethod;
0178 
0179     QList<QSslCertificate> m_sslChain;
0180     QList<QSslError> m_sslErrors;
0181     QString m_sslInfoTitle;
0182     QString m_sslInfoMessage;
0183     UiUtils::Formatting::IconType m_sslInfoIcon;
0184 
0185     QString m_accountName;
0186     QString m_cacheDir;
0187 };
0188 
0189 }
0190 
0191 #endif // TROJITA_IMAPACCESS_H