diff --git a/CHANGELOG.md b/CHANGELOG.md index 36f5842c..3601d30d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added - Support renaming profiles +- Allow switching profile from the GUI ### Changed - Profile name is no longer displayed if default diff --git a/pext/__main__.py b/pext/__main__.py index 6779bd49..b504804a 100644 --- a/pext/__main__.py +++ b/pext/__main__.py @@ -1810,6 +1810,7 @@ def __init__(self, config_retriever: ConfigRetriever, parent=None) -> None: self.engine = QQmlApplicationEngine(self) + # Set QML variables self.context = self.engine.rootContext() self.context.setContextProperty( "applicationVersion", UpdateManager().get_core_version()) @@ -1822,6 +1823,8 @@ def __init__(self, config_retriever: ConfigRetriever, parent=None) -> None: "themesPath", os.path.join(self.config_retriever.get_setting('config_path'), 'themes')) self.context.setContextProperty("currentTheme", Settings.get('theme')) + self.context.setContextProperty("currentProfile", Settings.get('profile')) + self.context.setContextProperty("profiles", ProfileManager(self.config_retriever).list_profiles()) # Load the main UI self.engine.load(QUrl.fromLocalFile(os.path.join(AppFile.get_path(), 'qml', 'main.qml'))) @@ -1881,6 +1884,9 @@ def __init__(self, config_retriever: ConfigRetriever, parent=None) -> None: menu_update_all_themes_shortcut = self.window.findChild( QObject, "menuUpdateAllThemes") + menu_load_profile_shortcut = self.window.findChild( + QObject, "menuLoadProfile") + menu_sort_module_shortcut = self.window.findChild( QObject, "menuSortModule") menu_sort_ascending_shortcut = self.window.findChild( @@ -1929,6 +1935,8 @@ def __init__(self, config_retriever: ConfigRetriever, parent=None) -> None: menu_update_all_themes_shortcut.updateAllThemesRequest.connect( self._menu_update_all_themes) + menu_load_profile_shortcut.loadProfileRequest.connect(self._menu_switch_profile) + menu_sort_module_shortcut.toggled.connect(self._menu_sort_module) menu_sort_ascending_shortcut.toggled.connect(self._menu_sort_ascending) menu_sort_descending_shortcut.toggled.connect(self._menu_sort_descending) @@ -2155,12 +2163,13 @@ def _menu_update_all_modules(self) -> None: ] threading.Thread(target=RunConseq, args=(functions,)).start() # type: ignore - def _menu_restart_pext(self) -> None: + def _menu_restart_pext(self, extra_args=[]) -> None: # Call _shut_down manually because it isn't called when using os.execv _shut_down(self, self.config_retriever) args = sys.argv[:] + args.extend(extra_args) args.insert(0, sys.executable) if sys.platform == 'win32': @@ -2174,7 +2183,9 @@ def _menu_switch_theme(self, theme_name: Optional[str]) -> None: self._menu_restart_pext() - """Restart Pext after switching theme.""" + def _menu_switch_profile(self, profile_name: str) -> None: + self._menu_restart_pext(['--profile={}'.format(profile_name)]) + def _menu_install_theme(self, theme_url: str) -> None: functions = [ { diff --git a/pext/qml/LoadProfileDialog.qml b/pext/qml/LoadProfileDialog.qml new file mode 100644 index 00000000..10c8c130 --- /dev/null +++ b/pext/qml/LoadProfileDialog.qml @@ -0,0 +1,64 @@ +/* + Copyright (c) 2017 Sylvia van Os + + This file is part of Pext + + Pext is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import QtQuick 2.3 +import QtQuick.Controls 1.2 +import QtQuick.Dialogs 1.2 +import QtQuick.Layouts 1.0 + +Dialog { + title: qsTr("Load profile") + standardButtons: StandardButton.Ok | StandardButton.Cancel + + property var currentProfile + property var profiles + property var loadRequest + + ColumnLayout { + id: columnLayout + width: parent.width + + anchors.fill: parent + + Label { + text: qsTr("Choose the profile to switch to:") + } + + ComboBox { + id: combobox + model: profiles + Layout.fillWidth: true + } + + Label { + text: qsTr("Note: Pext will restart to switch profile.") + } + } + + Component.onCompleted: { + combobox.currentIndex = profiles.indexOf(currentProfile); + visible = true; + combobox.focus = true; + } + + onAccepted: { + loadRequest(combobox.currentText); + } +} + diff --git a/pext/qml/main.qml b/pext/qml/main.qml index 93f01af4..5edd8dfb 100644 --- a/pext/qml/main.qml +++ b/pext/qml/main.qml @@ -503,6 +503,25 @@ ApplicationWindow { } } + Menu { + title: qsTr("&Profile") + + MenuItem { + objectName: "menuLoadProfile" + text: qsTr("Switch profile") + + signal loadProfileRequest(string name) + + onTriggered: { + var loadProfileDialog = Qt.createComponent("LoadProfileDialog.qml"); + loadProfileDialog.createObject(applicationWindow, + {"currentProfile": currentProfile, + "profiles": profiles.sort(), + "loadRequest": loadProfileRequest}); + } + } + } + Menu { title: qsTr("&Settings")