diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 9433165a5..4757465b1 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -18,6 +18,8 @@ Kirigami.ApplicationWindow { property NeoChatConnection connection: Controller.activeConnection readonly property HoverLinkIndicator hoverLinkIndicator: linkIndicator + property bool initialized: false + title: NeoChatConfig.windowTitleFocus ? activeFocusItem + " " + (activeFocusItem ? activeFocusItem.Accessible.name : "") : "NeoChat" @@ -82,6 +84,17 @@ Kirigami.ApplicationWindow { Connections { target: RoomManager + function onCurrentRoomChanged() { + if (RoomManager.currentRoom && pageStack.depth <= 1 && initialized && Kirigami.Settings.isMobile) { + let roomPage = pageStack.layers.push(Qt.createComponent('org.kde.neochat', 'RoomPage'), { + connection: root.connection + }); + roomPage.backRequested.connect(event => { + RoomManager.clearCurrentRoom(); + }); + } + } + function onAskJoinRoom(room) { Qt.createComponent("org.kde.neochat", "JoinRoomDialog").createObject(root, { room: room, @@ -315,9 +328,14 @@ Kirigami.ApplicationWindow { function load() { pageStack.replace(roomListComponent); RoomManager.loadInitialRoom(); - let roomPage = pageStack.push(Qt.createComponent('org.kde.neochat', 'RoomPage'), { - connection: root.connection - }); - roomPage.forceActiveFocus(); + + if (!Kirigami.Settings.isMobile) { + let roomPage = pageStack.push(Qt.createComponent('org.kde.neochat', 'RoomPage'), { + connection: root.connection + }); + roomPage.forceActiveFocus(); + } + + initialized = true; } } diff --git a/src/roommanager.cpp b/src/roommanager.cpp index 4a1c7cdc9..2cb0ce511 100644 --- a/src/roommanager.cpp +++ b/src/roommanager.cpp @@ -14,7 +14,6 @@ #include "urlhelper.h" #include -#include #include #include #include @@ -41,6 +40,16 @@ RoomManager::RoomManager(QObject *parent) , m_mediaMessageFilterModel(new MediaMessageFilterModel(this, m_messageFilterModel)) , m_userListModel(new UserListModel(this)) { +#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(UBUNTU_TOUCH) + m_isMobile = true; +#else + // Mostly for debug purposes and for platforms which are always mobile, + // such as Plasma Mobile + if (qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE")) { + m_isMobile = QByteArrayList{"1", "true"}.contains(qgetenv("QT_QUICK_CONTROLS_MOBILE")); + } +#endif + m_lastRoomConfig = m_config->group(QStringLiteral("LastOpenRoom")); m_lastSpaceConfig = m_config->group(QStringLiteral("LastOpenSpace")); m_directChatsConfig = m_config->group(QStringLiteral("DirectChatsActive")); @@ -227,8 +236,9 @@ void RoomManager::loadInitialRoom() resolveResource(m_arg); } - const auto runtimePlatform = KRuntimePlatform::runtimePlatform(); - if (runtimePlatform.contains(QStringLiteral("phone")) || runtimePlatform.contains(QStringLiteral("handset"))) { + if (m_isMobile) { + // We still need to remember the last space on mobile + setCurrentSpace(m_lastSpaceConfig.readEntry(m_connection->userId(), QString()), false); // We don't want to open a room on startup on mobile return; } @@ -464,9 +474,10 @@ void RoomManager::setCurrentSpace(const QString &spaceId, bool setRoom) if (!setRoom) { return; } + if (spaceId.length() > 3) { resolveResource(spaceId, "no_join"_ls); - } else { + } else if (!m_isMobile) { visitRoom({}, {}); } } @@ -531,6 +542,11 @@ void RoomManager::setCurrentRoom(const QString &roomId) setCurrentSpace({}, false); } +void RoomManager::clearCurrentRoom() +{ + setCurrentRoom(QString()); +} + QString RoomManager::currentSpace() const { return m_currentSpaceId; diff --git a/src/roommanager.h b/src/roommanager.h index 465e7d04d..3fabf0a0e 100644 --- a/src/roommanager.h +++ b/src/roommanager.h @@ -252,6 +252,11 @@ public: */ void setConnection(NeoChatConnection *connection); + /** + * @brief Clear the current room. + */ + Q_INVOKABLE void clearCurrentRoom(); + /** * Closes the current room and space; for situations, where it is unclear which room should be opened. */ @@ -344,6 +349,8 @@ Q_SIGNALS: void currentSpaceChanged(); private: + bool m_isMobile = false; + void openRoomForActiveConnection(); /** The room currently being shown in the main view (RoomPage.qml). This can be null, if there is no room.