Merge lp:~mefrio-g/cable/1200886 into lp:cable

Proposed by Mario Guerriero
Status: Merged
Merge reported by: Eduard Gotwig
Merged at revision: not available
Proposed branch: lp:~mefrio-g/cable/1200886
Merge into: lp:cable
Diff against target: 241 lines (+122/-7)
5 files modified
CMakeLists.txt (+4/-1)
src/Cable.vala (+3/-0)
src/Services/Unity.vala (+64/-0)
src/Widgets/Room.vala (+50/-6)
src/Widgets/User.vala (+1/-0)
To merge this branch: bzr merge lp:~mefrio-g/cable/1200886
Reviewer Review Type Date Requested Status
Cable Developers Pending
Review via email: mp+174582@code.launchpad.net

Description of the change

the badges are removed once the entry is focused. It happens because it seems that the entry is the only widget of which we can detect focus_in_event. I think you should focus the entry every time a key is pressed, every time the window is focused and every time the user changes between channels.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-07-09 20:35:11 +0000
3+++ CMakeLists.txt 2013-07-13 20:46:22 +0000
4@@ -33,7 +33,8 @@
5 gio-2.0>=2.28.0
6 gtk+-3.0>=3.4.0
7 gee-1.0
8- libnotify)
9+ libnotify
10+ unity)
11
12 add_definitions(${DEPS_CFLAGS})
13
14@@ -54,6 +55,7 @@
15 src/Services/Settings.vala
16 src/Services/Identity.vala
17 src/Services/Network.vala
18+ src/Services/Unity.vala
19
20 src/Widgets/Room.vala
21 src/Widgets/Server.vala
22@@ -73,6 +75,7 @@
23 gtk+-3.0
24 granite
25 libnotify
26+ unity
27 #WebKit-3.0
28 OPTIONS
29 --target-glib=2.32
30
31=== modified file 'src/Cable.vala'
32--- src/Cable.vala 2013-07-09 20:35:11 +0000
33+++ src/Cable.vala 2013-07-13 20:46:22 +0000
34@@ -73,6 +73,9 @@
35
36 Notify.init ("Cable");
37
38+ // libunity support
39+ Cable.Services.unity = new Cable.Services.Unity ("cable.desktop");
40+
41 try {
42 context.parse (ref args);
43 }
44
45=== added file 'src/Services/Unity.vala'
46--- src/Services/Unity.vala 1970-01-01 00:00:00 +0000
47+++ src/Services/Unity.vala 2013-07-13 20:46:22 +0000
48@@ -0,0 +1,64 @@
49+// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
50+/***
51+ BEGIN LICENSE
52+
53+ Copyright (C) 2013 Mario Guerriero <mario@elementaryos.org>
54+ This program is free software: you can redistribute it and/or modify it
55+ under the terms of the GNU Lesser General Public License version 3, as published
56+ by the Free Software Foundation.
57+
58+ This program is distributed in the hope that it will be useful, but
59+ WITHOUT ANY WARRANTY; without even the implied warranties of
60+ MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
61+ PURPOSE. See the GNU General Public License for more details.
62+
63+ You should have received a copy of the GNU General Public License along
64+ with this program. If not, see <http://www.gnu.org/licenses/>
65+
66+ END LICENSE
67+***/
68+
69+using Unity;
70+
71+namespace Cable.Services {
72+
73+ public Unity unity;
74+
75+ public class Unity : GLib.Object {
76+
77+ private int jobs = 0;
78+ private LauncherEntry launcher_entry;
79+
80+ public Unity (string desktop_id) {
81+ launcher_entry = LauncherEntry.get_for_desktop_id (desktop_id);
82+ }
83+
84+ public void set_progress (double percentage) {
85+ // If it is not 100 % show it
86+ launcher_entry.progress = (percentage/jobs);
87+ launcher_entry.progress_visible = true;
88+ }
89+
90+ // Add new red badge to show the number of pending works
91+ public void append_job () {
92+ jobs++;
93+
94+ launcher_entry.count = jobs;
95+ launcher_entry.count_visible = (jobs > 0);
96+ }
97+
98+ public void remove_job () {
99+ jobs--;
100+
101+ launcher_entry.count = jobs;
102+ launcher_entry.count_visible = (jobs > 0);
103+ }
104+
105+ public void clear () {
106+ jobs = 0;
107+ launcher_entry.count = jobs;
108+ launcher_entry.count_visible = false;
109+ launcher_entry.progress_visible = false;
110+ }
111+ }
112+}
113
114=== modified file 'src/Widgets/Room.vala'
115--- src/Widgets/Room.vala 2013-07-09 20:35:11 +0000
116+++ src/Widgets/Room.vala 2013-07-13 20:46:22 +0000
117@@ -44,6 +44,7 @@
118 Granite.Widgets.SourceList.ExpandableItem regular;
119
120 Granite.Widgets.SourceList users;
121+ Gtk.Entry entry;
122 ChatDisplay chat;
123 Gtk.ScrolledWindow left_scrolled;
124
125@@ -51,7 +52,9 @@
126 Gtk.Box user_box;
127
128 Gee.HashMap<string, string> color_map;
129-
130+
131+ private int unity_badge_count = 0;
132+
133 public Gtk.InfoBar topic;
134 public Gtk.Label topic_name;
135 private Gtk.Button identity_button;
136@@ -68,7 +71,7 @@
137 public Room (string channel, Server server) {
138 this.channel = channel;
139 this.server = server;
140-
141+
142 color_map = new Gee.HashMap<string, string> (null, null);
143
144 this.orientation = Gtk.Orientation.VERTICAL;
145@@ -137,14 +140,14 @@
146 var content = topic.get_content_area () as Gtk.Container;
147 content.add (topic_name);
148
149- var entry = new Gtk.Entry ();
150+ entry = new Gtk.Entry ();
151 entry.hexpand = true;
152
153 left_scrolled = new Gtk.ScrolledWindow (null, null);
154 left_scrolled.hscrollbar_policy = Gtk.PolicyType.NEVER;
155-
156+
157 chat = new ChatDisplay ();
158-
159+
160 var pseudo_label = new Gtk.Label (server.identity.nick_name);
161 pseudo_label.set_alignment (1, (float)0.5);
162 pseudo_label.width_request = 80;
163@@ -165,11 +168,46 @@
164 box.pack_start (entry_eventbox, false);
165
166 this.pack_start (paned);
167-
168+
169+ entry.focus_in_event.connect (() => {
170+ for (int n = 0; n < unity_badge_count; n++)
171+ Cable.Services.unity.remove_job ();
172+ unity_badge_count = 0;
173+ return false;
174+ });
175 entry.activate.connect (() => {
176 send_message (entry.text);
177 entry.text = "";
178 });
179+ string text = "";
180+ entry.key_press_event.connect ((ev) => {
181+ if (ev.keyval == Gdk.Key.Tab) {
182+ if (entry.text == null || entry.text == "")
183+ return false;
184+
185+ var txt = entry.text.split (" ");
186+ var word = txt[txt.length-1];
187+
188+ if (word == null || word == "")
189+ return false;
190+
191+ var collection = new Gee.LinkedList<Granite.Widgets.SourceList.Item> ();
192+ collection.add_all (operators.children);
193+ collection.add_all (voiced.children);
194+ collection.add_all (regular.children);
195+ var user_array = collection.to_array ();
196+
197+ for (int n = 0; n < user_array.length; n++)
198+ if (user_array[n].name != null)
199+ if (word == user_array[n].name[0:word.length]) {
200+ entry.delete_from_cursor (Gtk.DeleteType.WORDS, 1);
201+ entry.insert_at_cursor (user_array[n].name + ": ");
202+ return true;
203+ }
204+ return true;
205+ }
206+ return false;
207+ });
208
209 /* Load nickname's color from settings */
210 string[] colors = Settings.settings.get_strv ("colors");
211@@ -216,6 +254,7 @@
212 regular.name = _("Regular") + " (" + regular.n_children.to_string () + ")";
213 operators.name = _("Operators") + " (" + operators.n_children.to_string () + ")";
214 voiced.name = _("Voiced") + " (" + voiced.n_children.to_string () + ")";
215+
216 }
217
218 public void remove_user (string name, bool silent = false) {
219@@ -282,6 +321,11 @@
220 try {
221 notify.show ();
222 } catch (Error e) { warning (e.message); }
223+ // libunity badge
224+ if (!entry.has_focus) {
225+ Cable.Services.unity.append_job ();
226+ unity_badge_count++;
227+ }
228 } else {
229 if (color_map.has_key (from)) {
230 chat.add_message ("<span color='"+color_map.get (from)+@"'>$from</span>", new_message);
231
232=== modified file 'src/Widgets/User.vala'
233--- src/Widgets/User.vala 2013-07-04 01:34:38 +0000
234+++ src/Widgets/User.vala 2013-07-13 20:46:22 +0000
235@@ -31,6 +31,7 @@
236
237 public User (string name) {
238 base (name);
239+
240 menu = new Gtk.Menu ();
241 var item_color = new Gtk.MenuItem.with_label (_("Change color…"));
242

Subscribers

People subscribed via source and target branches

to all changes: