Spectral/src/controller.h

104 lines
3.0 KiB
C
Raw Normal View History

2018-02-27 05:10:08 +00:00
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include "connection.h"
2018-10-19 14:02:12 +00:00
#include "notifications/manager.h"
#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>
#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
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)
Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE
setQuitOnLastWindowClosed NOTIFY quitOnLastWindowClosedChanged)
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);
QVector<Connection*> connections() { return m_connections; }
2018-07-09 02:45:26 +00:00
// All the non-Q_INVOKABLE functions.
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(); }
bool quitOnLastWindowClosed() {
return QApplication::quitOnLastWindowClosed();
}
void setQuitOnLastWindowClosed(bool value) {
if (quitOnLastWindowClosed() != value) {
QApplication::setQuitOnLastWindowClosed(value);
emit quitOnLastWindowClosedChanged();
}
}
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-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;
QPointer<Connection> m_connection;
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();
void errorOccured(QString error, QString detail);
void syncDone();
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);
void quitOnLastWindowClosedChanged();
void connectionChanged();
2018-07-09 02:45:26 +00:00
public slots:
void logout(Connection* conn);
void joinRoom(Connection* c, const QString& alias);
void createRoom(Connection* c, const QString& name, const QString& topic);
void createDirectChat(Connection* c, const QString& userID);
2018-08-04 20:35:31 +00:00
void copyToClipboard(const QString& text);
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,
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