← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~flscogna/ubuntu-terminal-app/profile-selection into lp:ubuntu-terminal-app

 

Filippo Scognamiglio has proposed merging lp:~flscogna/ubuntu-terminal-app/profile-selection into lp:ubuntu-terminal-app.

Commit message:
Custom profile visibility in settings

Requested reviews:
  Alan Pope  (popey)

For more details, see:
https://code.launchpad.net/~flscogna/ubuntu-terminal-app/profile-selection/+merge/255077

Custom profile visibility in settings. It is possible to show only a subset of the installed layouts.
-- 
Your team Ubuntu Terminal Developers is subscribed to branch lp:ubuntu-terminal-app.
=== modified file 'po/com.ubuntu.terminal.pot'
--- po/com.ubuntu.terminal.pot	2015-02-26 10:57:55 +0000
+++ po/com.ubuntu.terminal.pot	2015-04-02 12:56:38 +0000
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: \n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2015-02-20 14:00+0100\n"
+"POT-Creation-Date: 2015-04-02 14:49+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@xxxxxx>\n"
@@ -53,23 +53,27 @@
 msgid "Authentication failed"
 msgstr ""
 
-#: ../src/app/qml/KeyboardBar.qml:157
+#: ../src/app/qml/KeyboardBar.qml:163
 msgid "Change Keyboard"
 msgstr ""
 
+#: ../src/app/qml/LayoutsPage.qml:27 ../src/app/qml/SettingsPage.qml:36
+msgid "Layouts"
+msgstr ""
+
 #: ../src/app/qml/SettingsPage.qml:27
 msgid "Settings"
 msgstr ""
 
-#: ../src/app/qml/SettingsPage.qml:36
+#: ../src/app/qml/SettingsPage.qml:42
+msgid "Show Keyboard Bar"
+msgstr ""
+
+#: ../src/app/qml/SettingsPage.qml:52
 msgid "Font Size:"
 msgstr ""
 
-#: ../src/app/qml/SettingsPage.qml:59
-msgid "Show Keyboard Bar"
-msgstr ""
-
-#: ../src/app/qml/SettingsPage.qml:73
+#: ../src/app/qml/SettingsPage.qml:78
 msgid "Color Scheme"
 msgstr ""
 
@@ -81,7 +85,7 @@
 msgid "New tab"
 msgstr ""
 
-#: ../src/app/qml/TerminalPage.qml:111
+#: ../src/app/qml/TerminalPage.qml:164
 msgid "Selection Mode"
 msgstr ""
 

=== modified file 'src/app/fileio.cpp'
--- src/app/fileio.cpp	2015-02-03 21:43:38 +0000
+++ src/app/fileio.cpp	2015-04-02 12:56:38 +0000
@@ -8,8 +8,7 @@
     if (sourceUrl.isEmpty())
         return false;
 
-    QUrl url(sourceUrl);
-    QFile file(url.toLocalFile());
+    QFile file(sourceUrl);
     if (!file.open(QFile::WriteOnly | QFile::Truncate))
         return false;
 
@@ -23,8 +22,7 @@
     if (sourceUrl.isEmpty())
         return "";
 
-    QUrl url(sourceUrl);
-    QFile file(url.toLocalFile());
+    QFile file(sourceUrl);
     if (!file.open(QFile::ReadOnly))
         return "";
 

=== modified file 'src/app/qml/KeyboardBar.qml'
--- src/app/qml/KeyboardBar.qml	2015-02-14 10:33:32 +0000
+++ src/app/qml/KeyboardBar.qml	2015-04-02 12:56:38 +0000
@@ -40,9 +40,9 @@
         }
     }
 
-    function createLayoutObject(profileUrl) {
+    function createLayoutObject(profileObject) {
         var object = layoutComponent.createObject(keyboardContainer);
-        object.loadProfile(fileIO.read(profileUrl));
+        object.loadProfile(profileObject);
         return object;
     }
 
@@ -97,13 +97,19 @@
     }
 
     function loadProfiles() {
-        for (var i = 0; i < keyboardLayouts.length; i++) {
+        dropProfiles();
+
+        for (var i = 0; i < settings.profilesList.count; i++) {
+            var profile = settings.profilesList.get(i);
+            if (!profile.profileVisible)
+                continue;
+
             try {
-                console.log("Loading Layout:", Qt.resolvedUrl(keyboardLayouts[i]));
-                var layoutObject = createLayoutObject(Qt.resolvedUrl(keyboardLayouts[i]));
+                console.log("Loading Layout:", Qt.resolvedUrl(profile.file));
+                var layoutObject = createLayoutObject(profile.object);
                 layoutsList.append({layout: layoutObject});
             } catch (e) {
-                console.error("Error in profile " + keyboardLayouts[i]);
+                console.error("Error in profile " + profile.file);
                 console.error(e);
             }
         }
@@ -187,6 +193,11 @@
         }
     }
 
+    Connections {
+        target: settings
+        onProfilesChanged: rootItem.loadProfiles();
+    }
+
     Component.onDestruction: dropProfiles();
     Component.onCompleted: loadProfiles();
 }

=== modified file 'src/app/qml/KeyboardRows/KeyboardLayout.qml'
--- src/app/qml/KeyboardRows/KeyboardLayout.qml	2015-02-14 10:56:28 +0000
+++ src/app/qml/KeyboardRows/KeyboardLayout.qml	2015-04-02 12:56:38 +0000
@@ -68,13 +68,13 @@
         return objectString;
     }
 
-    function loadProfile(profileString) {
+    function loadProfile(profileObject) {
         dropProfile();
 
         var maxWidth = 0;
 
         // This function might raise exceptions which are handled in KeyboardBar.qml
-        var profile = profile = Parser.parseJson(profileString);
+        var profile = profileObject;
 
         name = profile.name;
         short_name = profile.short_name;

=== added file 'src/app/qml/LayoutsPage.qml'
--- src/app/qml/LayoutsPage.qml	1970-01-01 00:00:00 +0000
+++ src/app/qml/LayoutsPage.qml	2015-04-02 12:56:38 +0000
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2013, 2014 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Filippo Scognamiglio <flscogna@xxxxxxxxx>
+ */
+
+import QtQuick 2.0
+import Ubuntu.Components 1.1
+import Ubuntu.Components.ListItems 1.0 as ListItem
+
+Page {
+    id: rootItem
+    objectName: "layoutsPage"
+
+    title: i18n.tr("Layouts")
+
+    onVisibleChanged: {
+        if (visible === false)
+            settings.profilesChanged();
+    }
+
+    ListView {
+        anchors.fill: parent
+        model: settings.profilesList
+        delegate: ListItem.Standard {
+            control: Switch {
+                checked: profileVisible
+                onCheckedChanged: {
+                    settings.profilesList.setProperty(index, "profileVisible", checked);
+                }
+            }
+            text: name
+        }
+    }
+}

=== modified file 'src/app/qml/SettingsPage.qml'
--- src/app/qml/SettingsPage.qml	2015-01-17 02:02:04 +0000
+++ src/app/qml/SettingsPage.qml	2015-04-02 12:56:38 +0000
@@ -30,50 +30,57 @@
         id: mainColumn
 
         spacing: units.gu(1)
-        anchors { margins: units.gu(2); fill: parent }
-
-        Label {
-            text: i18n.tr("Font Size:")
-        }
-
-        Slider {
-            id: slFont
-            objectName: "slFont"
-            anchors { left: parent.left; right: parent.right }
-            minimumValue: 8;
-            maximumValue: 32;
-            onValueChanged: {
-                settings.fontSize = value;
-            }
-            Component.onCompleted: {
-                value = settings.fontSize;
-            }
-        }
-
-        ListItem.ThinDivider { }
+        anchors.fill: parent
+
+        ListItem.Standard {
+            text: i18n.tr("Layouts")
+            progression: true
+            onClicked: pageStack.push(layoutsPage);
+        }
+
+        ListItem.Standard {
+            text: i18n.tr("Show Keyboard Bar")
+            control: Switch {
+                onCheckedChanged: settings.showKeyboardBar = checked;
+                Component.onCompleted: checked = settings.showKeyboardBar;
+            }
+        }
 
         ListItem.Empty {
-            showDivider: false
+            height: units.gu(10)
             Label {
-                anchors { left: parent.left; verticalCenter: parent.verticalCenter }
-                text: i18n.tr("Show Keyboard Bar")
+                text: i18n.tr("Font Size:")
+                x: units.gu(2)
             }
-            Switch {
-                anchors { right: parent.right; verticalCenter: parent.verticalCenter }
-                onCheckedChanged: settings.showKeyboardBar = checked;
-                Component.onCompleted: checked = settings.showKeyboardBar;
+            Slider {
+                id: slFont
+                objectName: "slFont"
+                anchors {
+                    left: parent.left
+                    right: parent.right
+                    bottom: parent.bottom
+                    margins: units.gu(2)
+                }
+                minimumValue: 8;
+                maximumValue: 32;
+                onValueChanged: {
+                    settings.fontSize = value;
+                }
+                Component.onCompleted: {
+                    value = settings.fontSize;
+                }
             }
         }
 
-        ListItem.ThinDivider { }
-
         OptionSelector {
             id: colorsSchemeSelector
             objectName: "colorsSchemeSelector"
             text: i18n.tr("Color Scheme")
+            width: parent.width - units.gu(4)
+            x: units.gu(2)
 
             // TODO Hackish, but works quite well.
-            containerHeight: parent.height - y - units.gu(4)
+            containerHeight: parent.height - y - units.gu(6)
 
             // TODO This is a workaround at the moment.
             // The application should get them from the c++.

=== modified file 'src/app/qml/TerminalSettings.qml'
--- src/app/qml/TerminalSettings.qml	2015-01-17 02:02:04 +0000
+++ src/app/qml/TerminalSettings.qml	2015-04-02 12:56:38 +0000
@@ -1,9 +1,73 @@
 import QtQuick 2.0
 import Qt.labs.settings 1.0
 
-Settings {
-    property int fontSize: 14
-    property string fontStyle: "Ubuntu Mono"
-    property string colorScheme: "Ubuntu"
-    property bool showKeyboardBar: true
+import "KeyboardRows/jsonParser.js" as Parser
+
+Item {
+    id: rootItem
+    property alias fontSize: innerSettings.fontSize
+    property alias fontStyle: innerSettings.fontStyle
+    property alias colorScheme: innerSettings.colorScheme
+    property alias showKeyboardBar: innerSettings.showKeyboardBar
+
+    property alias jsonVisibleProfiles: innerSettings.jsonVisibleProfiles
+
+    property ListModel profilesList: ListModel {}
+
+    signal profilesChanged();
+
+    onProfilesChanged: saveProfileVisibleStrings();
+
+    function saveProfileVisibleStrings() {
+        var result = {};
+
+        for (var i = 0; i < profilesList.count; i++) {
+            var profileObject = profilesList.get(i);
+            result[profileObject.file] = profileObject.profileVisible;
+        }
+
+        jsonVisibleProfiles = JSON.stringify(result);
+    }
+
+    Settings {
+        id: innerSettings
+        property int fontSize: 14
+        property string fontStyle: "Ubuntu Mono"
+        property string colorScheme: "Ubuntu"
+        property bool showKeyboardBar: true
+        property string jsonVisibleProfiles: "[]"
+    }
+
+    // Load the keyboard profiles.
+    Component.onCompleted: {
+        var visibleProfiles = undefined;
+        try {
+            visibleProfiles = JSON.parse(innerSettings.jsonVisibleProfiles);
+        } catch (e) {}
+
+        function isProfileVisible(profilePath) {
+            return !(visibleProfiles[profilePath] == false);
+        }
+
+        for (var i = 0; i < keyboardLayouts.length; i++) {
+            var filePath = keyboardLayouts[i];
+            var isVisible = isProfileVisible(filePath);
+
+            try {
+                var profileObject = Parser.parseJson(fileIO.read(filePath));
+
+                profilesList.append(
+                        {
+                            file: filePath,
+                            profileVisible: isVisible,
+                            object: profileObject,
+                            name: profileObject.name
+                        });
+            } catch (e) {
+                console.error("Error in profile", filePath);
+                console.error(e);
+            }
+        }
+        profilesChanged();
+    }
 }

=== modified file 'src/app/qml/ubuntu-terminal-app.qml'
--- src/app/qml/ubuntu-terminal-app.qml	2014-12-05 22:52:26 +0000
+++ src/app/qml/ubuntu-terminal-app.qml	2015-04-02 12:56:38 +0000
@@ -106,6 +106,11 @@
             id: settingsPage
             visible: false
         }
+
+        LayoutsPage {
+            id: layoutsPage
+            visible: false
+        }
     }
 
     Component.onCompleted: {


Follow ups