diff --git a/src/controller.cpp b/src/controller.cpp index 9d16f1983..499acc1f3 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -73,24 +73,8 @@ Controller::Controller(QObject *parent) setApplicationProxy(); #ifndef Q_OS_ANDROID - if (NeoChatConfig::self()->systemTray()) { - m_trayIcon = new TrayIcon(this); - 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()); - }); + setQuitOnLastWindowClosed(); + connect(NeoChatConfig::self(), &NeoChatConfig::SystemTrayChanged, this, &Controller::setQuitOnLastWindowClosed); #endif QTimer::singleShot(0, this, [this] { @@ -228,38 +212,6 @@ void Controller::showWindow() 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) { if (!conn) { @@ -302,8 +254,6 @@ void Controller::addConnection(Connection *c) c->setLazyLoading(true); connect(c, &Connection::syncDone, this, [this, c] { - setBusy(false); - Q_EMIT syncDone(); c->sync(30000); @@ -319,8 +269,6 @@ void Controller::addConnection(Connection *c) } }); - setBusy(true); - c->sync(); Q_EMIT connectionAdded(c); @@ -551,31 +499,22 @@ int Controller::accountCount() const return AccountRegistry::instance().count(); } -bool Controller::quitOnLastWindowClosed() +void Controller::setQuitOnLastWindowClosed() { - return QGuiApplication::quitOnLastWindowClosed(); -} - -void Controller::setQuitOnLastWindowClosed(bool value) -{ - if (quitOnLastWindowClosed() != value) { - QGuiApplication::setQuitOnLastWindowClosed(value); - Q_EMIT quitOnLastWindowClosedChanged(); +#ifndef Q_OS_ANDROID + 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; } -} - -bool Controller::busy() const -{ - return m_busy; -} - -void Controller::setBusy(bool busy) -{ - if (m_busy == busy) { - return; - } - m_busy = busy; - Q_EMIT busyChanged(); + QGuiApplication::setQuitOnLastWindowClosed(!NeoChatConfig::self()->systemTray()); +#else + return; +#endif } Connection *Controller::activeConnection() const @@ -834,4 +773,4 @@ QString Controller::activeAccountLabel() const return {}; } return m_connection->accountDataJson("org.kde.neochat.account_label")["account_label"].toString(); -} \ No newline at end of file +} diff --git a/src/controller.h b/src/controller.h index 2cbd90f82..90e7b3086 100644 --- a/src/controller.h +++ b/src/controller.h @@ -32,9 +32,7 @@ class Controller : public QObject { Q_OBJECT 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(bool busy READ busy WRITE setBusy NOTIFY busyChanged) Q_PROPERTY(bool supportSystemTray READ supportSystemTray CONSTANT) Q_PROPERTY(bool hasWindowSystem READ hasWindowSystem CONSTANT) Q_PROPERTY(bool isOnline READ isOnline NOTIFY isOnlineChanged) @@ -53,20 +51,12 @@ public: void addConnection(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 bool setAvatar(Quotient::Connection *connection, const QUrl &avatarSource); [[nodiscard]] int accountCount() const; - [[nodiscard]] static bool quitOnLastWindowClosed(); - void setQuitOnLastWindowClosed(bool value); - - [[nodiscard]] bool busy() const; - void setBusy(bool busy); - [[nodiscard]] bool supportSystemTray() const; bool saveAccessTokenToKeyChain(const Quotient::AccountSettings &account, const QByteArray &accessToken); @@ -143,6 +133,7 @@ private: private Q_SLOTS: void invokeLogin(); void showWindow(); + void setQuitOnLastWindowClosed(); Q_SIGNALS: void busyChanged();