[polari/message-user-2] app: Implement show-message-user-dialog action



commit 3e6c0ce0dc125ac90be8598a4137297b8b5affa9
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Sep 28 22:22:37 2013 +0200

    app: Implement show-message-user-dialog action

 data/polari.gresource.xml             |    1 +
 data/resources/message-user-dialog.ui |  190 +++++++++++++++++++++++++++++++++
 po/POTFILES.in                        |    1 +
 src/Makefile.am                       |    1 +
 src/application.js                    |    6 +-
 src/mainWindow.js                     |   11 ++
 src/messageDialog.js                  |  130 ++++++++++++++++++++++
 7 files changed, 338 insertions(+), 2 deletions(-)
---
diff --git a/data/polari.gresource.xml b/data/polari.gresource.xml
index 7ecc781..2e2e819 100644
--- a/data/polari.gresource.xml
+++ b/data/polari.gresource.xml
@@ -6,6 +6,7 @@
     <file alias="connection-list-dialog.ui" 
preprocess="xml-stripblanks">resources/connection-list-dialog.ui</file>
     <file alias="join-room-dialog.ui" preprocess="xml-stripblanks">resources/join-room-dialog.ui</file>
     <file alias="main-window.ui" preprocess="xml-stripblanks">resources/main-window.ui</file>
+    <file alias="message-user-dialog.ui" preprocess="xml-stripblanks">resources/message-user-dialog.ui</file>
     <file alias="application.css">resources/application.css</file>
   </gresource>
 </gresources>
diff --git a/data/resources/message-user-dialog.ui b/data/resources/message-user-dialog.ui
new file mode 100644
index 0000000..15607a4
--- /dev/null
+++ b/data/resources/message-user-dialog.ui
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.15.4 on Sun Sep 29 01:37:46 2013 -->
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <object class="GtkListStore" id="liststore1">
+    <columns>
+      <!-- column-name names -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <object class="GtkEntryCompletion" id="name_completion">
+    <property name="model">liststore1</property>
+    <property name="text_column">0</property>
+    <property name="inline_completion">True</property>
+    <property name="popup_completion">False</property>
+    <property name="popup_single_match">False</property>
+  </object>
+  <object class="GtkDialog" id="message_user_dialog">
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">Message User</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancel_button">
+                <property name="label" translatable="yes">_Cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="message_button">
+                <property name="label" translatable="yes">_Message</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">center</property>
+            <property name="margin_left">96</property>
+            <property name="margin_right">96</property>
+            <property name="margin_top">24</property>
+            <property name="margin_bottom">48</property>
+            <property name="row_spacing">12</property>
+            <property name="column_spacing">12</property>
+            <child>
+              <object class="GtkLabel" id="server_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Server</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">2</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="connection_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">C_onnection</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">connection_combo</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="user_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_top">24</property>
+                <property name="label" translatable="yes">User</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+                <property name="width">2</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBoxText" id="connection_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="name_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">_Name</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBoxText" id="name_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="has_entry">True</property>
+                <child internal-child="entry">
+                  <object class="GtkEntry" id="comboboxtext-entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="completion">name_completion</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">3</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">cancel_button</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1b5fa4c..4dd4c6c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,6 +5,7 @@ data/polari.desktop.in
 [type: gettext/glade]data/resources/connection-list-dialog.ui
 [type: gettext/glade]data/resources/join-room-dialog.ui
 [type: gettext/glade]data/resources/main-window.ui
+[type: gettext/glade]data/resources/message-user-dialog.ui
 src/application.js
 src/chatView.js
 src/connections.js
diff --git a/src/Makefile.am b/src/Makefile.am
index 13de457..0c68b0a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,6 +37,7 @@ dist_js_DATA = \
        joinDialog.js \
        main.js \
        mainWindow.js \
+       messageDialog.js \
        notify.js \
        pasteManager.js \
        roomList.js \
diff --git a/src/application.js b/src/application.js
index 5f7e51f..584a5b5 100644
--- a/src/application.js
+++ b/src/application.js
@@ -74,7 +74,9 @@ const Application = new Lang.Class({
             create_hook: Lang.bind(this, this._accountActionsCreateHook),
             accel: '<Primary>n' },
           { name: 'show-message-user-dialog',
-            activate: Lang.bind(this, this._onShowMessageUserDialog) },
+            activate: Lang.bind(this, this._onShowMessageUserDialog),
+            create_hook: Lang.bind(this, this._accountActionsCreateHook),
+            accel: '<Primary>m' },
           { name: 'join-room',
             activate: Lang.bind(this, this._onJoinRoom),
             parameter_type: GLib.VariantType.new('(ssu)') },
@@ -219,7 +221,7 @@ const Application = new Lang.Class({
     },
 
     _onShowMessageUserDialog: function() {
-        log('Activated action "Message user"');
+        this._window.showMessageUserDialog();
     },
 
     _addSavedChannel: function(account, channel) {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index d784922..a977213 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -12,6 +12,7 @@ const IrcParser = imports.ircParser;
 const JoinDialog = imports.joinDialog;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
+const MessageDialog = imports.messageDialog;
 const RoomList = imports.roomList;
 const UserList = imports.userList;
 
@@ -334,6 +335,16 @@ const MainWindow = new Lang.Class({
             });
     },
 
+    showMessageUserDialog: function() {
+        let dialog = new MessageDialog.MessageDialog();
+        dialog.widget.transient_for = this.window;
+        dialog.widget.show();
+        dialog.widget.connect('response',
+            function(widget) {
+                widget.destroy();
+            });
+    },
+
     _updateTitlebar: function() {
         this._titlebarRight.title = this._room ? this._room.display_name : null;
         this._titlebarRight.subtitle = this._room ? this._room.topic : null;
diff --git a/src/messageDialog.js b/src/messageDialog.js
new file mode 100644
index 0000000..bde1156
--- /dev/null
+++ b/src/messageDialog.js
@@ -0,0 +1,130 @@
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const Tp = imports.gi.TelepathyGLib;
+const Tpl = imports.gi.TelepathyLogger;
+
+const AccountsMonitor = imports.accountsMonitor;
+const Lang = imports.lang;
+
+const TP_CURRENT_TIME = GLib.MAXUINT32;
+const MAX_RECENT_USERS = 5;
+
+const MessageDialog = new Lang.Class({
+    Name: 'MessageDialog',
+
+    _init: function() {
+        this._createWidget();
+
+        this._accounts = {};
+        AccountsMonitor.getDefault().dupAccounts().forEach(Lang.bind(this,
+            function(a) {
+                if (!a.enabled)
+                    return;
+                this._accounts[a.display_name] = a;
+            }));
+        let names = Object.keys(this._accounts).sort(
+            function(a, b) {
+                // TODO: figure out combo box sorting
+                return (a < b) ? -1 : ((a > b) ? 1 : 0);
+            });
+        for (let i = 0; i < names.length; i++)
+            this._connectionCombo.append_text(names[i]);
+        this._connectionCombo.set_active(0);
+        this._connectionCombo.sensitive = names.length > 1;
+        this._updateCanConfirm();
+    },
+
+    _createWidget: function() {
+        let builder = new Gtk.Builder();
+        builder.add_from_resource('/org/gnome/polari/message-user-dialog.ui');
+
+        this.widget = builder.get_object('message_user_dialog');
+
+        this._connectionCombo = builder.get_object('connection_combo');
+        this._connectionCombo.connect('changed',
+                                      Lang.bind(this, this._onAccountChanged));
+        this._connectionCombo.sensitive = false;
+
+        this._nameCombo = builder.get_object('name_combo');
+        this._nameCombo.connect('changed',
+                                Lang.bind(this, this._updateCanConfirm));
+        this._nameCompletion = builder.get_object('name_completion');
+
+        this._messageButton = builder.get_object('message_button');
+        this._messageButton.connect('clicked',
+                                 Lang.bind(this, this._onMessageClicked));
+        this._messageButton.sensitive = false;
+    },
+
+    _updateRecentList: function(names) {
+    },
+
+    _onAccountChanged: function() {
+        this._nameCombo.remove_all();
+        this._nameCompletion.model.clear();
+
+        let selected = this._connectionCombo.get_active_text();
+        let account = this._accounts[selected];
+        let logManager = Tpl.LogManager.dup_singleton();
+
+        logManager.get_entities_async(account, Lang.bind(this,
+            function(m, res) {
+                let [, entities] = logManager.get_entities_finish(res);
+                entities = entities.filter(function(e) {
+                    return e.type == Tpl.EntityType.CONTACT;
+                });
+
+                let pending = entities.length;
+                if (pending == 0)
+                    return;
+
+                for (let i = 0; i < entities.length; i++) {
+                    let entity = entities[i];
+                    logManager.get_filtered_events_async(account, entity,
+                        Tpl.EventTypeMask.TEXT, 1, null,
+                        Lang.bind(this, function(m, res) {
+                            let [, events] = m.get_filtered_events_finish(res);
+                            entity._timestamp = events[0].timestamp;
+                            if (--pending > 0)
+                               return;
+
+                            let names = entities.sort(function(a, b) {
+                                return b._timestamp - a._timestamp;
+                            }).map(function(e) {
+                                return e.alias;
+                            });
+                            for (let i = 0; i < names.length; i++) {
+                                this._nameCombo.append_text(names[i]);
+                                let model = this._nameCompletion.model;
+                                let iter = model.append();
+                                model.set_value(iter, 0, names[i]);
+                            }
+                        }));
+                }
+            }));
+    },
+
+    _onMessageClicked: function() {
+        this.widget.hide();
+
+        let selected = this._connectionCombo.get_active_text();
+        let account = this._accounts[selected];
+
+        let user = this._nameCombo.get_active_text();
+
+        let app = Gio.Application.get_default();
+        let action = app.lookup_action('message-user');
+        action.activate(GLib.Variant.new('(ssu)',
+                                         [ account.get_object_path(),
+                                           user,
+                                           TP_CURRENT_TIME ]));
+        this.widget.response(Gtk.ResponseType.OK);
+    },
+
+    _updateCanConfirm: function() {
+            let sensitive = this._connectionCombo.get_active() > -1  &&
+                            this._nameCombo.get_active_text().length > 0;
+            this._messageButton.sensitive = sensitive;
+    }
+});


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