Spectral/src/controller.h

88 lines
2.2 KiB
C
Raw Normal View History

2018-02-27 05:10:08 +00:00
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include "connection.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
Q_PROPERTY(bool busy READ busy WRITE setBusy NOTIFY busyChanged)
2018-09-13 00:22:41 +00:00
Q_PROPERTY(int accountCount READ accountCount NOTIFY connectionAdded NOTIFY
connectionDropped)
2018-07-09 02:45:26 +00:00
public:
explicit Controller(QObject* parent = nullptr);
~Controller();
// 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.
bool busy() { return m_busy; }
void setBusy(bool value) {
if (value != m_busy) {
m_busy = value;
2018-07-09 02:45:26 +00:00
emit busyChanged();
}
}
2018-09-13 00:22:41 +00:00
int accountCount() { return m_connections.count(); }
2018-09-10 07:01:01 +00:00
Q_INVOKABLE QColor color(QString userId);
Q_INVOKABLE void setColor(QString userId, QColor newColor);
2018-07-09 02:45:26 +00:00
private:
2018-08-04 20:35:31 +00:00
QClipboard* m_clipboard = QApplication::clipboard();
2018-08-19 06:32:18 +00:00
QSystemTrayIcon* tray = new QSystemTrayIcon();
QMenu* trayMenu = new QMenu();
2018-09-10 07:01:01 +00:00
QVector<Connection*> m_connections;
bool m_busy = false;
2018-08-04 20:35:31 +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();
void errorOccured(QString error, QString detail);
2018-09-14 04:16:25 +00:00
void showWindow();
void hideWindow();
void connectionAdded(Connection* conn);
void connectionDropped(Connection* conn);
2018-09-13 00:22:41 +00:00
void initiated();
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);
2018-08-04 20:35:31 +00:00
void copyToClipboard(const QString& text);
void playAudio(QUrl localFile);
2018-08-19 06:32:18 +00:00
void showMessage(const QString& title, const QString& msg, const QIcon& icon);
2018-09-10 01:51:02 +00:00
static QImage safeImage(QImage image);
2018-02-27 05:10:08 +00:00
};
2018-07-09 02:45:26 +00:00
#endif // CONTROLLER_H