[polari] initialSetup: Add a dedicated setup window



commit 50006899b5448dc1239db7e1b6e07abb37b33fbb
Author: Danny Mølgaard <moelgaard dmp gmail com>
Date:   Wed Dec 14 21:58:11 2016 +0100

    initialSetup: Add a dedicated setup window
    
    Our current initial setup experience is essentially a label telling
    the user where to click. We can do much better by combining the
    existing elements in a separate, guided setup window ...
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772458

 data/org.gnome.Polari.data.gresource.xml |    1 +
 data/resources/application.css           |    8 ++
 data/resources/initial-setup-window.ui   |  138 ++++++++++++++++++++++++++++++
 po/POTFILES.in                           |    2 +
 src/connections.js                       |    6 ++
 src/initialSetup.js                      |  123 ++++++++++++++++++++++++++
 src/org.gnome.Polari.src.gresource.xml   |    1 +
 7 files changed, 279 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.Polari.data.gresource.xml b/data/org.gnome.Polari.data.gresource.xml
index f06c123..a836bc1 100644
--- a/data/org.gnome.Polari.data.gresource.xml
+++ b/data/org.gnome.Polari.data.gresource.xml
@@ -16,5 +16,6 @@
     <file alias="ui/server-room-list.ui" preprocess="xml-stripblanks">resources/server-room-list.ui</file>
     <file alias="ui/user-details.ui" preprocess="xml-stripblanks">resources/user-details.ui</file>
     <file alias="ui/user-popover.ui" preprocess="xml-stripblanks">resources/user-popover.ui</file>
+    <file alias="ui/initial-setup-window.ui" 
preprocess="xml-stripblanks">resources/initial-setup-window.ui</file>
   </gresource>
 </gresources>
diff --git a/data/resources/application.css b/data/resources/application.css
index c75a2ea..44741a0 100644
--- a/data/resources/application.css
+++ b/data/resources/application.css
@@ -128,6 +128,14 @@ treeview.polari-server-room-list {
     font-size: larger;
 }
 
+.polari-setup-page {
+    padding: 48px 156px;
+}
+
+.polari-setup-title {
+    font-size: 175%;
+}
+
 .polari-error-information {
     background-color: @polari_dark_bg_color;
     border-style: solid;
diff --git a/data/resources/initial-setup-window.ui b/data/resources/initial-setup-window.ui
new file mode 100644
index 0000000..a183fc6
--- /dev/null
+++ b/data/resources/initial-setup-window.ui
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="Gjs_InitialSetupWindow">
+    <property name="icon-name">org.gnome.Polari</property>
+    <property name="default-width">800</property>
+    <property name="default-height">600</property>
+    <child type="titlebar">
+      <object class="GtkHeaderBar">
+        <property name="visible">True</property>
+        <property name="title" translatable="yes">Polari Setup</property>
+        <child>
+          <object class="GtkButton" id="prevButton">
+            <property name="visible">True</property>
+            <property name="use-underline">True</property>
+            <property name="valign">center</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton" id="nextButton">
+            <property name="visible">True</property>
+            <property name="use-underline">True</property>
+            <property name="can-default">True</property>
+            <property name="valign">center</property>
+          </object>
+          <packing>
+            <property name="pack-type">end</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkStack" id="contentStack">
+        <property name="visible">True</property>
+        <property name="transition-type">slide-left-right</property>
+        <property name="vexpand">True</property>
+        <child>
+          <object class="GtkBox">
+            <property name="orientation">vertical</property>
+            <property name="visible">True</property>
+            <property name="vexpand">True</property>
+            <property name="spacing">24</property>
+            <style>
+              <class name="polari-setup-page"/>
+            </style>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">24</property>
+                <property name="halign">center</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Welcome to Polari</property>
+                    <style>
+                      <class name="polari-setup-title"/>
+                    </style>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="max-width-chars">42</property>
+                    <property name="wrap">True</property>
+                    <property name="justify">center</property>
+                    <property name="label" translatable="yes">Polari is an easy way to chat using IRC. 
Select a networks to get started.</property>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="Gjs_ConnectionsList" id="connectionsList">
+                <property name="visible">True</property>
+                <property name="vscrollbar-policy">never</property>
+                <property name="shadow-type">in</property>
+                <property name="favorites-only">True</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="name">connections</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="orientation">vertical</property>
+            <property name="visible">True</property>
+            <property name="spacing">24</property>
+            <style>
+              <class name="polari-setup-page"/>
+            </style>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <property name="halign">center</property>
+                <property name="spacing">24</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Welcome to Polari</property>
+                    <style>
+                      <class name="polari-setup-title"/>
+                    </style>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="max-width-chars">60</property>
+                    <property name="wrap">True</property>
+                    <property name="justify">center</property>
+                    <property name="label" translatable="yes">Select rooms you want to connect to. You can 
add more networks and rooms later, by clicking the + button.</property>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                </child>
+                </object>
+            </child>
+            <child>
+              <object class="Gjs_ServerRoomList" id="serverRoomList">
+                <property name="visible">True</property>
+                <property name="vexpand">True</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="name">rooms</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1193a5b..5fbda49 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -7,6 +7,7 @@ data/resources/connection-details.ui
 data/resources/connection-properties.ui
 data/resources/entry-area.ui
 data/resources/help-overlay.ui
+data/resources/initial-setup-window.ui
 data/resources/join-room-dialog.ui
 data/resources/main-window.ui
 data/resources/menus.ui
@@ -18,6 +19,7 @@ src/appNotifications.js
 src/chatView.js
 src/connections.js
 src/entryArea.js
+src/initialSetup.js
 src/ircParser.js
 src/joinDialog.js
 src/mainWindow.js
diff --git a/src/connections.js b/src/connections.js
index e4d7b43..fbec967 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -139,6 +139,12 @@ var ConnectionsList = new Lang.Class({
             row.activate();
     },
 
+    activateSelected: function() {
+        let row = this._list.get_selected_row();
+        if (row)
+            row.activate();
+    },
+
     _filterRows: function(row) {
         let matchTerms = this._networksManager.getNetworkMatchTerms(row.id);
         return this._filterTerms.every(term => {
diff --git a/src/initialSetup.js b/src/initialSetup.js
new file mode 100644
index 0000000..e677015
--- /dev/null
+++ b/src/initialSetup.js
@@ -0,0 +1,123 @@
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+
+const Lang = imports.lang;
+const Utils = imports.utils;
+
+const SetupPage = {
+    CONNECTION: 0,
+    ROOM: 1
+};
+
+var InitialSetupWindow = new Lang.Class({
+    Name: 'InitialSetupWindow',
+    Extends: Gtk.Window,
+    Template: 'resource:///org/gnome/Polari/ui/initial-setup-window.ui',
+    InternalChildren: ['contentStack',
+                       'connectionsList',
+                       'nextButton',
+                       'prevButton',
+                       'serverRoomList'],
+
+    _init: function(params) {
+
+        this.parent(params);
+
+        this._currentAccount = null;
+
+        this._connectionsList.connect('account-created', (w, account) => {
+            this._setPage(SetupPage.ROOM);
+            this._currentAccount = account;
+            this._serverRoomList.setAccount(account);
+        });
+
+        this.connect('destroy', () => { this._unsetAccount(); });
+
+        this._serverRoomList.connect('notify::can-join',
+                                     Lang.bind(this, this._updateNextSensitivity));
+
+        this._nextButton.connect('clicked', () => {
+            if (this._page == SetupPage.CONNECTION) {
+                this._connectionsList.activateSelected();
+            } else {
+                this._joinRooms();
+                this._currentAccount = null;
+                this.destroy();
+            }
+        });
+
+        this._prevButton.connect('clicked', () => {
+            if (this._page == SetupPage.ROOM) {
+                this._setPage(SetupPage.CONNECTION);
+                this._unsetAccount();
+            } else {
+                this.destroy();
+            }
+        });
+
+        this._setPage(SetupPage.CONNECTION);
+    },
+
+    _setPage: function(page) {
+        let isLastPage = page == SetupPage.ROOM;
+
+        this._contentStack.visible_child_name = isLastPage ? 'rooms'
+                                                           : 'connections';
+
+        this._prevButton.label = isLastPage ? _("_Back") : _("_Cancel");
+        this._nextButton.label = isLastPage ? _("_Done") : _("_Next");
+
+        let context = this._nextButton.get_style_context();
+        if (isLastPage)
+            context.add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION);
+        else
+            context.remove_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION);
+
+        this._nextButton.grab_default();
+        this._updateNextSensitivity();
+    },
+
+    _unsetAccount: function() {
+        if (!this._currentAccount)
+            return;
+
+        this._currentAccount.remove_async((a, res) => {
+            a.remove_finish(res);
+        });
+        this._currentAccount = null;
+    },
+
+    get _page() {
+        if (this._contentStack.visible_child_name == 'rooms')
+            return SetupPage.ROOM;
+        else
+            return SetupPage.CONNECTION;
+    },
+
+    _updateNextSensitivity: function() {
+        let sensitive = true;
+
+        if (this._page == SetupPage.ROOM)
+            sensitive = this._serverRoomList.can_join;
+
+        this._nextButton.sensitive = sensitive;
+    },
+
+    _joinRooms: function() {
+        this.hide();
+
+        let toJoinRooms = this._serverRoomList.selectedRooms;
+
+        let accountPath = this._currentAccount.get_object_path();
+        let time = Utils.getTpEventTime();
+        toJoinRooms.forEach(room => {
+            if (room[0] != '#')
+                room = '#' + room;
+
+            let app = Gio.Application.get_default();
+            let action = app.lookup_action('join-room');
+            action.activate(GLib.Variant.new('(ssu)', [accountPath, room, time]));
+        });
+    }
+});
diff --git a/src/org.gnome.Polari.src.gresource.xml b/src/org.gnome.Polari.src.gresource.xml
index a526f25..a383a03 100644
--- a/src/org.gnome.Polari.src.gresource.xml
+++ b/src/org.gnome.Polari.src.gresource.xml
@@ -22,5 +22,6 @@
     <file>userList.js</file>
     <file>utils.js</file>
     <file>userTracker.js</file>
+    <file>initialSetup.js</file>
   </gresource>
 </gresources>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]