Cleanup Controller
Remove unused functions and use setQuitOnLastWindowClosed as a slot for reacting to the tray icon setting change only.
This commit is contained in:
@@ -73,24 +73,8 @@ Controller::Controller(QObject *parent)
|
|||||||
setApplicationProxy();
|
setApplicationProxy();
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
if (NeoChatConfig::self()->systemTray()) {
|
setQuitOnLastWindowClosed();
|
||||||
m_trayIcon = new TrayIcon(this);
|
connect(NeoChatConfig::self(), &NeoChatConfig::SystemTrayChanged, this, &Controller::setQuitOnLastWindowClosed);
|
||||||
m_trayIcon->show();
|
|
||||||
connect(m_trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow);
|
|
||||||
QGuiApplication::setQuitOnLastWindowClosed(false);
|
|
||||||
}
|
|
||||||
connect(NeoChatConfig::self(), &NeoChatConfig::SystemTrayChanged, this, [this]() {
|
|
||||||
if (NeoChatConfig::self()->systemTray()) {
|
|
||||||
m_trayIcon = new TrayIcon(this);
|
|
||||||
m_trayIcon->show();
|
|
||||||
connect(m_trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow);
|
|
||||||
} else {
|
|
||||||
disconnect(m_trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow);
|
|
||||||
delete m_trayIcon;
|
|
||||||
m_trayIcon = nullptr;
|
|
||||||
}
|
|
||||||
QGuiApplication::setQuitOnLastWindowClosed(!NeoChatConfig::self()->systemTray());
|
|
||||||
});
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QTimer::singleShot(0, this, [this] {
|
QTimer::singleShot(0, this, [this] {
|
||||||
@@ -228,38 +212,6 @@ void Controller::showWindow()
|
|||||||
WindowController::instance().showAndRaiseWindow(QString());
|
WindowController::instance().showAndRaiseWindow(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::loginWithAccessToken(const QString &serverAddr, const QString &user, const QString &token, const QString &deviceName)
|
|
||||||
{
|
|
||||||
if (user.isEmpty() || token.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl serverUrl(serverAddr);
|
|
||||||
|
|
||||||
auto conn = new Connection();
|
|
||||||
if (serverUrl.isValid()) {
|
|
||||||
conn->setHomeserver(serverUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(conn, &Connection::connected, this, [this, conn, deviceName] {
|
|
||||||
AccountSettings account(conn->userId());
|
|
||||||
account.setKeepLoggedIn(true);
|
|
||||||
account.setHomeserver(conn->homeserver());
|
|
||||||
account.setDeviceId(conn->deviceId());
|
|
||||||
account.setDeviceName(deviceName);
|
|
||||||
if (!saveAccessTokenToKeyChain(account, conn->accessToken())) {
|
|
||||||
qWarning() << "Couldn't save access token";
|
|
||||||
}
|
|
||||||
account.sync();
|
|
||||||
addConnection(conn);
|
|
||||||
setActiveConnection(conn);
|
|
||||||
});
|
|
||||||
connect(conn, &Connection::networkError, this, [this](QString error, const QString &, int, int) {
|
|
||||||
Q_EMIT errorOccured(i18n("Network Error: %1", error));
|
|
||||||
});
|
|
||||||
conn->assumeIdentity(user, token, deviceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Controller::logout(Connection *conn, bool serverSideLogout)
|
void Controller::logout(Connection *conn, bool serverSideLogout)
|
||||||
{
|
{
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
@@ -302,8 +254,6 @@ void Controller::addConnection(Connection *c)
|
|||||||
c->setLazyLoading(true);
|
c->setLazyLoading(true);
|
||||||
|
|
||||||
connect(c, &Connection::syncDone, this, [this, c] {
|
connect(c, &Connection::syncDone, this, [this, c] {
|
||||||
setBusy(false);
|
|
||||||
|
|
||||||
Q_EMIT syncDone();
|
Q_EMIT syncDone();
|
||||||
|
|
||||||
c->sync(30000);
|
c->sync(30000);
|
||||||
@@ -319,8 +269,6 @@ void Controller::addConnection(Connection *c)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setBusy(true);
|
|
||||||
|
|
||||||
c->sync();
|
c->sync();
|
||||||
|
|
||||||
Q_EMIT connectionAdded(c);
|
Q_EMIT connectionAdded(c);
|
||||||
@@ -551,31 +499,22 @@ int Controller::accountCount() const
|
|||||||
return AccountRegistry::instance().count();
|
return AccountRegistry::instance().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Controller::quitOnLastWindowClosed()
|
void Controller::setQuitOnLastWindowClosed()
|
||||||
{
|
{
|
||||||
return QGuiApplication::quitOnLastWindowClosed();
|
#ifndef Q_OS_ANDROID
|
||||||
}
|
if (NeoChatConfig::self()->systemTray()) {
|
||||||
|
m_trayIcon = new TrayIcon(this);
|
||||||
void Controller::setQuitOnLastWindowClosed(bool value)
|
m_trayIcon->show();
|
||||||
{
|
connect(m_trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow);
|
||||||
if (quitOnLastWindowClosed() != value) {
|
} else {
|
||||||
QGuiApplication::setQuitOnLastWindowClosed(value);
|
disconnect(m_trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow);
|
||||||
Q_EMIT quitOnLastWindowClosedChanged();
|
delete m_trayIcon;
|
||||||
|
m_trayIcon = nullptr;
|
||||||
}
|
}
|
||||||
}
|
QGuiApplication::setQuitOnLastWindowClosed(!NeoChatConfig::self()->systemTray());
|
||||||
|
#else
|
||||||
bool Controller::busy() const
|
return;
|
||||||
{
|
#endif
|
||||||
return m_busy;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Controller::setBusy(bool busy)
|
|
||||||
{
|
|
||||||
if (m_busy == busy) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_busy = busy;
|
|
||||||
Q_EMIT busyChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection *Controller::activeConnection() const
|
Connection *Controller::activeConnection() const
|
||||||
@@ -834,4 +773,4 @@ QString Controller::activeAccountLabel() const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return m_connection->accountDataJson("org.kde.neochat.account_label")["account_label"].toString();
|
return m_connection->accountDataJson("org.kde.neochat.account_label")["account_label"].toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,7 @@ class Controller : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int accountCount READ accountCount NOTIFY accountCountChanged)
|
Q_PROPERTY(int accountCount READ accountCount NOTIFY accountCountChanged)
|
||||||
Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed NOTIFY quitOnLastWindowClosedChanged)
|
|
||||||
Q_PROPERTY(Quotient::Connection *activeConnection READ activeConnection WRITE setActiveConnection NOTIFY activeConnectionChanged)
|
Q_PROPERTY(Quotient::Connection *activeConnection READ activeConnection WRITE setActiveConnection NOTIFY activeConnectionChanged)
|
||||||
Q_PROPERTY(bool busy READ busy WRITE setBusy NOTIFY busyChanged)
|
|
||||||
Q_PROPERTY(bool supportSystemTray READ supportSystemTray CONSTANT)
|
Q_PROPERTY(bool supportSystemTray READ supportSystemTray CONSTANT)
|
||||||
Q_PROPERTY(bool hasWindowSystem READ hasWindowSystem CONSTANT)
|
Q_PROPERTY(bool hasWindowSystem READ hasWindowSystem CONSTANT)
|
||||||
Q_PROPERTY(bool isOnline READ isOnline NOTIFY isOnlineChanged)
|
Q_PROPERTY(bool isOnline READ isOnline NOTIFY isOnlineChanged)
|
||||||
@@ -53,20 +51,12 @@ public:
|
|||||||
void addConnection(Quotient::Connection *c);
|
void addConnection(Quotient::Connection *c);
|
||||||
void dropConnection(Quotient::Connection *c);
|
void dropConnection(Quotient::Connection *c);
|
||||||
|
|
||||||
Q_INVOKABLE void loginWithAccessToken(const QString &, const QString &, const QString &, const QString &);
|
|
||||||
|
|
||||||
Q_INVOKABLE void changePassword(Quotient::Connection *connection, const QString ¤tPassword, const QString &newPassword);
|
Q_INVOKABLE void changePassword(Quotient::Connection *connection, const QString ¤tPassword, const QString &newPassword);
|
||||||
|
|
||||||
Q_INVOKABLE bool setAvatar(Quotient::Connection *connection, const QUrl &avatarSource);
|
Q_INVOKABLE bool setAvatar(Quotient::Connection *connection, const QUrl &avatarSource);
|
||||||
|
|
||||||
[[nodiscard]] int accountCount() const;
|
[[nodiscard]] int accountCount() const;
|
||||||
|
|
||||||
[[nodiscard]] static bool quitOnLastWindowClosed();
|
|
||||||
void setQuitOnLastWindowClosed(bool value);
|
|
||||||
|
|
||||||
[[nodiscard]] bool busy() const;
|
|
||||||
void setBusy(bool busy);
|
|
||||||
|
|
||||||
[[nodiscard]] bool supportSystemTray() const;
|
[[nodiscard]] bool supportSystemTray() const;
|
||||||
|
|
||||||
bool saveAccessTokenToKeyChain(const Quotient::AccountSettings &account, const QByteArray &accessToken);
|
bool saveAccessTokenToKeyChain(const Quotient::AccountSettings &account, const QByteArray &accessToken);
|
||||||
@@ -143,6 +133,7 @@ private:
|
|||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void invokeLogin();
|
void invokeLogin();
|
||||||
void showWindow();
|
void showWindow();
|
||||||
|
void setQuitOnLastWindowClosed();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void busyChanged();
|
void busyChanged();
|
||||||
|
|||||||
Reference in New Issue
Block a user