2018-02-27 05:10:08 +00:00
|
|
|
#ifndef CONTROLLER_H
|
|
|
|
#define CONTROLLER_H
|
|
|
|
|
2018-07-08 05:25:46 +00:00
|
|
|
#include "connection.h"
|
2018-10-19 14:02:12 +00:00
|
|
|
#include "notifications/manager.h"
|
2018-09-09 02:12:45 +00:00
|
|
|
#include "settings.h"
|
2018-07-09 02:45:26 +00:00
|
|
|
#include "user.h"
|
2018-02-27 11:07:50 +00:00
|
|
|
|
2018-08-04 20:35:31 +00:00
|
|
|
#include <QApplication>
|
2018-08-18 08:02:47 +00:00
|
|
|
#include <QMediaPlayer>
|
2018-08-19 06:51:09 +00:00
|
|
|
#include <QMenu>
|
2018-08-17 04:55:57 +00:00
|
|
|
#include <QObject>
|
2018-08-19 06:32:18 +00:00
|
|
|
#include <QSystemTrayIcon>
|
2018-08-04 20:35:31 +00:00
|
|
|
|
2018-07-29 16:00:41 +00:00
|
|
|
using namespace QMatrixClient;
|
2018-02-27 11:07:50 +00:00
|
|
|
|
2018-07-09 02:45:26 +00:00
|
|
|
class Controller : public QObject {
|
|
|
|
Q_OBJECT
|
2018-09-13 00:22:41 +00:00
|
|
|
Q_PROPERTY(int accountCount READ accountCount NOTIFY connectionAdded NOTIFY
|
|
|
|
connectionDropped)
|
2018-10-21 02:17:21 +00:00
|
|
|
Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE
|
|
|
|
setQuitOnLastWindowClosed NOTIFY quitOnLastWindowClosedChanged)
|
2018-11-16 16:04:51 +00:00
|
|
|
Q_PROPERTY(Connection* connection READ connection WRITE setConnection NOTIFY
|
|
|
|
connectionChanged)
|
2018-07-09 02:45:26 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Controller(QObject* parent = nullptr);
|
2018-11-11 01:55:41 +00:00
|
|
|
~Controller();
|
2018-07-09 02:45:26 +00:00
|
|
|
|
|
|
|
// All the Q_INVOKABLEs.
|
|
|
|
Q_INVOKABLE void loginWithCredentials(QString, QString, QString);
|
2018-09-09 02:12:45 +00:00
|
|
|
|
|
|
|
QVector<Connection*> connections() { return m_connections; }
|
2018-07-09 02:45:26 +00:00
|
|
|
|
|
|
|
// All the non-Q_INVOKABLE functions.
|
2018-09-09 02:12:45 +00:00
|
|
|
void addConnection(Connection* c);
|
|
|
|
void dropConnection(Connection* c);
|
2018-07-09 02:45:26 +00:00
|
|
|
|
|
|
|
// All the Q_PROPERTYs.
|
2018-09-13 00:22:41 +00:00
|
|
|
int accountCount() { return m_connections.count(); }
|
|
|
|
|
2018-10-21 02:17:21 +00:00
|
|
|
bool quitOnLastWindowClosed() {
|
|
|
|
return QApplication::quitOnLastWindowClosed();
|
|
|
|
}
|
|
|
|
void setQuitOnLastWindowClosed(bool value) {
|
|
|
|
if (quitOnLastWindowClosed() != value) {
|
|
|
|
QApplication::setQuitOnLastWindowClosed(value);
|
|
|
|
emit quitOnLastWindowClosedChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 16:04:51 +00:00
|
|
|
Connection* connection() {
|
|
|
|
if (m_connection.isNull()) return nullptr;
|
|
|
|
return m_connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setConnection(Connection* conn) {
|
|
|
|
if (!conn) return;
|
|
|
|
if (conn == m_connection) return;
|
|
|
|
m_connection = conn;
|
|
|
|
emit connectionChanged();
|
|
|
|
}
|
2018-09-09 02:12:45 +00:00
|
|
|
|
2018-07-09 02:45:26 +00:00
|
|
|
private:
|
2018-08-04 20:35:31 +00:00
|
|
|
QClipboard* m_clipboard = QApplication::clipboard();
|
2018-10-19 14:02:12 +00:00
|
|
|
NotificationsManager notificationsManager;
|
2018-09-10 07:01:01 +00:00
|
|
|
QVector<Connection*> m_connections;
|
2018-11-16 16:04:51 +00:00
|
|
|
QPointer<Connection> m_connection;
|
2018-08-18 08:02:47 +00:00
|
|
|
|
2018-09-09 02:12:45 +00:00
|
|
|
QByteArray loadAccessToken(const AccountSettings& account);
|
|
|
|
bool saveAccessToken(const AccountSettings& account,
|
|
|
|
const QByteArray& accessToken);
|
|
|
|
void loadSettings();
|
|
|
|
void saveSettings() const;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void invokeLogin();
|
2018-07-09 02:45:26 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void busyChanged();
|
2018-09-20 05:43:47 +00:00
|
|
|
void errorOccured(QString error, QString detail);
|
2018-11-16 16:04:51 +00:00
|
|
|
void syncDone();
|
2018-09-09 02:12:45 +00:00
|
|
|
void connectionAdded(Connection* conn);
|
|
|
|
void connectionDropped(Connection* conn);
|
2018-09-13 00:22:41 +00:00
|
|
|
void initiated();
|
2018-10-19 14:02:12 +00:00
|
|
|
void notificationClicked(const QString roomId, const QString eventId);
|
2018-10-21 02:17:21 +00:00
|
|
|
void quitOnLastWindowClosedChanged();
|
2018-11-16 16:04:51 +00:00
|
|
|
void connectionChanged();
|
2018-07-09 02:45:26 +00:00
|
|
|
|
|
|
|
public slots:
|
2018-09-09 13:13:43 +00:00
|
|
|
void logout(Connection* conn);
|
|
|
|
void joinRoom(Connection* c, const QString& alias);
|
|
|
|
void createRoom(Connection* c, const QString& name, const QString& topic);
|
2018-10-13 10:54:33 +00:00
|
|
|
void createDirectChat(Connection* c, const QString& userID);
|
2018-08-04 20:35:31 +00:00
|
|
|
void copyToClipboard(const QString& text);
|
2018-08-18 08:02:47 +00:00
|
|
|
void playAudio(QUrl localFile);
|
2018-10-19 14:02:12 +00:00
|
|
|
void postNotification(const QString& roomId, const QString& eventId,
|
|
|
|
const QString& roomName, const QString& senderName,
|
2018-10-21 02:17:21 +00:00
|
|
|
const QString& text, const QImage& icon,
|
|
|
|
const QUrl& iconPath);
|
2018-02-27 05:10:08 +00:00
|
|
|
};
|
|
|
|
|
2018-07-09 02:45:26 +00:00
|
|
|
#endif // CONTROLLER_H
|