Merge lp:~ken-vandine/gwibber/cleaner_start into lp:gwibber

Proposed by Ken VanDine on 2012-10-04
Status: Merged
Approved by: Ken VanDine on 2012-10-04
Approved revision: 1391
Merged at revision: 1391
Proposed branch: lp:~ken-vandine/gwibber/cleaner_start
Merge into: lp:gwibber
Diff against target: 147 lines (+71/-19)
2 files modified
lens/src/Makefile.am (+1/-0)
lens/src/daemon.vala (+70/-19)
To merge this branch: bzr merge lp:~ken-vandine/gwibber/cleaner_start
Reviewer Review Type Date Requested Status
Didier Roche (community) 2012-10-04 Approve on 2012-10-04
Review via email: mp+128023@code.launchpad.net

Description of the change

Fixes bug 1046360
* Don't do anything to trigger starting gwibber-service unless data is needed.
* Show/Hide the lens based on enabled accounts

To post a comment you must log in.
Didier Roche (didrocks) wrote :

Looks totally legitimate to me. +1 :)
(great that we can hide lenses ;))

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lens/src/Makefile.am'
2--- lens/src/Makefile.am 2012-09-03 14:47:33 +0000
3+++ lens/src/Makefile.am 2012-10-04 14:08:24 +0000
4@@ -36,6 +36,7 @@
5 --pkg gio-2.0 \
6 --pkg gio-unix-2.0 \
7 --pkg json-glib-1.0 \
8+ --pkg accounts \
9 --basedir=.
10
11 unity_gwibber_daemon_LDADD = \
12
13=== modified file 'lens/src/daemon.vala'
14--- lens/src/daemon.vala 2012-10-03 00:10:30 +0000
15+++ lens/src/daemon.vala 2012-10-04 14:08:24 +0000
16@@ -41,8 +41,8 @@
17 private Gwibber.Service service;
18 private Gwibber.Accounts accounts;
19 private Gwibber.Utils utils;
20- private Dee.Model? _model;
21- private Dee.Model? _streams_model;
22+ private Dee.Model? _model = null;
23+ private Dee.Model? _streams_model = null;
24 private Dee.Filter _sort_filter;
25 /* Keep track of the previous search, so we can determine when to
26 * filter down the result set instead of rebuilding it */
27@@ -52,24 +52,65 @@
28 private Dee.Analyzer _analyzer;
29 private Dee.Index _index;
30 private Dee.ICUTermFilter _ascii_filter;
31+ private Ag.Manager _account_manager;
32+ private bool _has_accounts = false;
33
34 construct
35 {
36- streams_service = new Gwibber.Streams();
37- service = new Gwibber.Service();
38- utils = new Gwibber.Utils();
39- accounts = new Gwibber.Accounts();
40-
41+ lens = new Unity.Lens("/com/canonical/unity/lens/gwibber", "gwibber");
42+ lens.search_in_global = false;
43+ lens.search_hint = _("Enter name or content you would like to search for");
44+ lens.visible = false;
45+ try
46+ {
47+ lens.export ();
48+ } catch (GLib.IOError e)
49+ {
50+ warning ("failed to export lens: %s", e.message);
51+ }
52+
53+
54+ // Check for accounts
55+ _account_manager = new Ag.Manager.for_service_type("microblogging");
56+ GLib.List<Ag.AccountService> accts = _account_manager.get_enabled_account_services();
57+ foreach (Ag.AccountService account_service in accts) {
58+ Ag.Account account = account_service.get_account();
59+ account.set_enabled (false);
60+ message ("ACCOUNT PROVIDER: %s", account.get_provider_name());
61+ }
62+
63+ // We only want to trigger starting gwibber-service if there are accounts
64+ if (accts.length() > 0)
65+ {
66+ _has_accounts = true;
67+ setup ();
68+ }
69+
70+ _account_manager.enabled_event.connect ((id) =>
71+ {
72+ accts = _account_manager.get_enabled_account_services();
73+ if (accts.length() > 0 && !_has_accounts)
74+ {
75+ _has_accounts = true;
76+ setup ();
77+ }
78+ else if (accts.length() == 0)
79+ {
80+ lens.visible = false;
81+ _has_accounts = false;
82+ }
83+ });
84+ }
85+
86+
87+ void setup ()
88+ {
89 scope = new Unity.Scope ("/com/canonical/unity/scope/gwibber");
90 scope.search_in_global = false;
91 scope.preview_uri.connect (preview);
92
93- lens = new Unity.Lens("/com/canonical/unity/lens/gwibber", "gwibber");
94- lens.search_in_global = false;
95- lens.search_hint = _("Enter name or content you would like to search for");
96 lens.visible = true;
97- populate_categories ();
98- populate_filters();
99+
100 lens.add_local_scope (scope);
101
102 /* Listen for filter changes */
103@@ -116,13 +157,17 @@
104 scope.queue_search_changed (SearchType.DEFAULT);
105 });
106
107- try
108- {
109- lens.export ();
110- } catch (GLib.IOError e)
111- {
112- warning ("failed to export lens: %s", e.message);
113- }
114+ }
115+
116+ private void setup_gwibber ()
117+ {
118+ streams_service = new Gwibber.Streams();
119+ service = new Gwibber.Service();
120+ utils = new Gwibber.Utils();
121+ accounts = new Gwibber.Accounts();
122+
123+ populate_categories ();
124+ populate_filters();
125
126 _streams_model = streams_service.stream_model;
127 Intl.setlocale(LocaleCategory.COLLATE, "C");
128@@ -335,6 +380,9 @@
129
130 results_model.clear ();
131
132+ if (_model == null)
133+ setup_gwibber ();
134+
135 iter = _model.get_first_iter ();
136 end = _model.get_last_iter ();
137
138@@ -492,6 +540,9 @@
139 Icon icon;
140 string retweet_str, like_str, _img_uri = null;
141
142+ if (_streams_model == null)
143+ setup_gwibber ();
144+
145 var model = _streams_model;
146 unowned Dee.ModelIter iter, end;
147 iter = model.get_first_iter ();

Subscribers

People subscribed via source and target branches