[polari] joinDialog: Add entry completion for room names



commit 858cbf23939f0b0fd700a0e7ce5909861ae5aca5
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Oct 2 22:27:41 2013 +0200

    joinDialog: Add entry completion for room names
    
    Fetch the list of recently joined rooms from history and use it to
    provide room name completion.

 data/resources/join-room-dialog.ui |   20 ++++++++++++++++++--
 src/joinDialog.js                  |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 2 deletions(-)
---
diff --git a/data/resources/join-room-dialog.ui b/data/resources/join-room-dialog.ui
index f4c4b4c..16a0eca 100644
--- a/data/resources/join-room-dialog.ui
+++ b/data/resources/join-room-dialog.ui
@@ -1,7 +1,23 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.10 -->
-  <object class="GtkEntryCompletion" id="entrycompletion1"/>
+  <object class="GtkListStore" id="liststore1">
+    <columns>
+      <!-- column-name name -->
+      <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>
+    <child>
+      <object class="GtkCellRendererText" id="cellrenderertext1"/>
+      <attributes>
+        <attribute name="text">0</attribute>
+      </attributes>
+    </child>
+  </object>
   <object class="GtkDialog" id="join_room_dialog">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">Join Chat Room</property>
@@ -87,7 +103,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="activates_default">True</property>
-                <property name="completion">entrycompletion1</property>
+                <property name="completion">name_completion</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
diff --git a/src/joinDialog.js b/src/joinDialog.js
index 0bb22de..61a5b56 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -1,6 +1,7 @@
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
+const Tpl = imports.gi.TelepathyLogger;
 
 const AccountsMonitor = imports.accountsMonitor;
 const Lang = imports.lang;
@@ -39,6 +40,8 @@ const JoinDialog = new Lang.Class({
         this.widget = builder.get_object('join_room_dialog');
 
         this._connectionCombo = builder.get_object('connection_combo');
+        this._connectionCombo.connect('changed',
+                                      Lang.bind(this, this._onAccountChanged));
         this._connectionCombo.sensitive = false;
 
         this._joinButton = builder.get_object('join_button');
@@ -46,11 +49,41 @@ const JoinDialog = new Lang.Class({
                                  Lang.bind(this, this._onJoinClicked));
         this._joinButton.sensitive = false;
 
+        this._nameCompletion = builder.get_object('name_completion');
         this._nameEntry = builder.get_object('name_entry');
         this._nameEntry.connect('changed',
                                 Lang.bind(this, this._updateCanConfirm));
     },
 
+    _onAccountChanged: function() {
+        this._nameEntry.set_text('');
+        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);
+                let names = entities.filter(function(e) {
+                    return e.type == Tpl.EntityType.ROOM;
+                }).map(function(e) {
+                    return e.alias;
+                });
+                for (let i = 0; i < names.length; i++) {
+                    let model = this._nameCompletion.model;
+                    let iter = model.append();
+                    model.set_value(iter, 0, names[i]);
+                    if (names[i].startsWith('#')) {
+                        iter = model.append();
+                        model.set_value(iter, 0, names[i].substr(1));
+                    }
+                }
+            }));
+    },
+
+
     _onJoinClicked: function() {
         this.widget.hide();
 


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