~gwibber-committers/gwibber/3.6

« back to all changes in this revision

Viewing changes to lens/src/daemon.vala

  • Committer: Ken VanDine
  • Date: 2012-10-04 16:11:25 UTC
  • mfrom: (1390.1.1 autostart)
  • Revision ID: ken.vandine@canonical.com-20121004161125-e6c5rxkfrcq3814w
* Don't do anything to trigger starting gwibber-service unless data is needed.
* Show/Hide the lens based on enabled accounts

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    private Gwibber.Service service;
42
42
    private Gwibber.Accounts accounts;
43
43
    private Gwibber.Utils utils;
44
 
    private Dee.Model? _model;
45
 
    private Dee.Model? _streams_model;
 
44
    private Dee.Model? _model = null;
 
45
    private Dee.Model? _streams_model = null;
46
46
    private Dee.Filter _sort_filter;
47
47
    /* Keep track of the previous search, so we can determine when to
48
48
     * filter down the result set instead of rebuilding it */
52
52
    private Dee.Analyzer _analyzer;
53
53
    private Dee.Index _index;
54
54
    private Dee.ICUTermFilter _ascii_filter;
 
55
    private Ag.Manager _account_manager;
 
56
    private bool _has_accounts = false;
55
57
 
56
58
    construct
57
59
    {
58
 
      streams_service = new Gwibber.Streams();
59
 
      service = new Gwibber.Service();
60
 
      utils = new Gwibber.Utils();
61
 
      accounts = new Gwibber.Accounts();
62
 
 
 
60
      lens = new Unity.Lens("/com/canonical/unity/lens/gwibber", "gwibber");
 
61
      lens.search_in_global = false;
 
62
      lens.search_hint = _("Enter name or content you would like to search for");
 
63
      lens.visible = false;
 
64
      try
 
65
      {
 
66
        lens.export ();
 
67
      } catch (GLib.IOError e)
 
68
      {
 
69
        warning ("failed to export lens: %s", e.message);
 
70
      }
 
71
 
 
72
 
 
73
      // Check for accounts
 
74
      _account_manager = new Ag.Manager.for_service_type("microblogging");
 
75
      GLib.List<Ag.AccountService> accts = _account_manager.get_enabled_account_services();
 
76
      foreach (Ag.AccountService account_service in accts) {
 
77
        Ag.Account account = account_service.get_account();
 
78
        account.set_enabled (false);
 
79
        message ("ACCOUNT PROVIDER: %s", account.get_provider_name());
 
80
      }
 
81
 
 
82
      // We only want to trigger starting gwibber-service if there are accounts
 
83
      if (accts.length() > 0)
 
84
      {
 
85
        _has_accounts = true;
 
86
        setup ();
 
87
      }
 
88
 
 
89
      _account_manager.enabled_event.connect ((id) =>
 
90
      {
 
91
        accts = _account_manager.get_enabled_account_services();
 
92
        if (accts.length() > 0 && !_has_accounts)
 
93
        {
 
94
          _has_accounts = true;
 
95
          setup ();
 
96
        }
 
97
        else if (accts.length() == 0)
 
98
        {
 
99
          lens.visible = false;
 
100
          _has_accounts = false;
 
101
        }
 
102
      });
 
103
    }
 
104
 
 
105
 
 
106
    void setup ()
 
107
    {
63
108
      scope = new Unity.Scope ("/com/canonical/unity/scope/gwibber");
64
109
      scope.search_in_global = false;
65
110
      scope.preview_uri.connect (preview);
66
111
 
67
 
      lens = new Unity.Lens("/com/canonical/unity/lens/gwibber", "gwibber");
68
 
      lens.search_in_global = false;
69
 
      lens.search_hint = _("Enter name or content you would like to search for");
70
112
      lens.visible = true;
71
 
      populate_categories ();
72
 
      populate_filters();
 
113
 
73
114
      lens.add_local_scope (scope);
74
115
 
75
116
      /* Listen for filter changes */
116
157
        scope.queue_search_changed (SearchType.DEFAULT);
117
158
      });
118
159
 
119
 
      try
120
 
      {
121
 
        lens.export ();
122
 
      } catch (GLib.IOError e)
123
 
      {
124
 
        warning ("failed to export lens: %s", e.message);
125
 
      }
 
160
    }
 
161
 
 
162
    private void setup_gwibber ()
 
163
    {
 
164
      streams_service = new Gwibber.Streams();
 
165
      service = new Gwibber.Service();
 
166
      utils = new Gwibber.Utils();
 
167
      accounts = new Gwibber.Accounts();
 
168
 
 
169
      populate_categories ();
 
170
      populate_filters();
126
171
 
127
172
      _streams_model = streams_service.stream_model;
128
173
      Intl.setlocale(LocaleCategory.COLLATE, "C");
335
380
 
336
381
      results_model.clear ();
337
382
 
 
383
      if (_model == null)
 
384
        setup_gwibber ();
 
385
 
338
386
      iter = _model.get_first_iter ();
339
387
      end = _model.get_last_iter ();
340
388
 
492
540
      Icon icon;
493
541
      string retweet_str, like_str, _img_uri = null;
494
542
 
 
543
      if (_streams_model == null)
 
544
        setup_gwibber ();
 
545
 
495
546
      var model = _streams_model;
496
547
      unowned Dee.ModelIter iter, end;
497
548
      iter = model.get_first_iter ();