~ubuntu-branches/ubuntu/saucy/indicator-appmenu/saucy-updates

« back to all changes in this revision

Viewing changes to src/huddebugsource.c

  • Committer: Package Import Robot
  • Author(s): Automatic PS uploader, Mathieu Trudel-Lapierre, Automatic PS uploader
  • Date: 2013-02-20 09:41:54 UTC
  • mfrom: (1.1.40)
  • Revision ID: package-import@ubuntu.com-20130220094154-zrxsx0vgay436wyt
Tags: 13.01.0daily13.02.20-0ubuntu1
[ Mathieu Trudel-Lapierre ]
* Artificially bump upstream major version to please hud.

[ Automatic PS uploader ]
* Automatic snapshot from revision 234

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2012 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it
5
 
 * under the terms of the GNU General Public License version 3, as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
10
 
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
 
 * PURPOSE.  See the GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License along
14
 
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Author: Ryan Lortie <desrt@desrt.ca>
17
 
 */
18
 
 
19
 
#include "huddebugsource.h"
20
 
 
21
 
#include "hudsource.h"
22
 
#include "hudresult.h"
23
 
 
24
 
/**
25
 
 * SECTION:huddebugsource
26
 
 * @title: HudDebugSource
27
 
 * @short_description: a source to assist with debugging
28
 
 *
29
 
 * #HudDebugSource is a source for debugging purposes.  It is not
30
 
 * enabled by default but you can have it added to the global list of
31
 
 * sources by setting the HUD_DEBUG_SOURCE environment variable.
32
 
 *
33
 
 * Presently it creates a #HudItem corresponding to the current date and
34
 
 * time (and updates it as the time changes).
35
 
 **/
36
 
 
37
 
/**
38
 
 * HudDebugSource:
39
 
 *
40
 
 * This is an opaque structure type.
41
 
 **/
42
 
 
43
 
struct _HudDebugSource
44
 
{
45
 
  GObject parent_instance;
46
 
 
47
 
  HudItem *item;
48
 
  gint use_count;
49
 
  gint timeout;
50
 
};
51
 
 
52
 
typedef GObjectClass HudDebugSourceClass;
53
 
 
54
 
static void hud_debug_source_iface_init (HudSourceInterface *iface);
55
 
G_DEFINE_TYPE_WITH_CODE (HudDebugSource, hud_debug_source, G_TYPE_OBJECT,
56
 
                         G_IMPLEMENT_INTERFACE (HUD_TYPE_SOURCE, hud_debug_source_iface_init))
57
 
 
58
 
static gboolean
59
 
hud_debug_source_timeout (gpointer user_data)
60
 
{
61
 
  HudDebugSource *source = user_data;
62
 
  HudStringList *tokens;
63
 
  GDateTime *now;
64
 
  gchar *time;
65
 
 
66
 
  g_clear_object (&source->item);
67
 
 
68
 
  now = g_date_time_new_now_local ();
69
 
  time = g_date_time_format (now, "hud-debug time: %c");
70
 
  tokens = hud_string_list_cons (time, NULL);
71
 
  g_date_time_unref (now);
72
 
  g_free (time);
73
 
 
74
 
  source->item = hud_item_new (tokens, NULL, NULL, TRUE);
75
 
  hud_string_list_unref (tokens);
76
 
 
77
 
  hud_source_changed (HUD_SOURCE (source));
78
 
 
79
 
  return TRUE;
80
 
}
81
 
 
82
 
static void
83
 
hud_debug_source_use (HudSource *hud_source)
84
 
{
85
 
  HudDebugSource *source = HUD_DEBUG_SOURCE (hud_source);
86
 
 
87
 
  if (source->use_count == 0)
88
 
    source->timeout = g_timeout_add (1000, hud_debug_source_timeout, source);
89
 
 
90
 
  source->use_count++;
91
 
}
92
 
 
93
 
static void
94
 
hud_debug_source_unuse (HudSource *hud_source)
95
 
{
96
 
  HudDebugSource *source = HUD_DEBUG_SOURCE (hud_source);
97
 
 
98
 
  source->use_count--;
99
 
 
100
 
  if (source->use_count == 0)
101
 
    {
102
 
      g_source_remove (source->timeout);
103
 
      source->timeout = 0;
104
 
    }
105
 
}
106
 
 
107
 
static void
108
 
hud_debug_source_search (HudSource    *hud_source,
109
 
                         GPtrArray    *results_array,
110
 
                         HudTokenList *search_string)
111
 
{
112
 
  HudDebugSource *source = HUD_DEBUG_SOURCE (hud_source);
113
 
 
114
 
  if (source->item)
115
 
    {
116
 
      HudResult *result;
117
 
 
118
 
      result = hud_result_get_if_matched (source->item, search_string, 0);
119
 
      if (result != NULL)
120
 
        g_ptr_array_add (results_array, result);
121
 
    }
122
 
}
123
 
 
124
 
static void
125
 
hud_debug_source_finalize (GObject *object)
126
 
{
127
 
  HudDebugSource *source = HUD_DEBUG_SOURCE (object);
128
 
 
129
 
  g_clear_object (&source->item);
130
 
 
131
 
  if (source->timeout)
132
 
    g_source_remove (source->timeout);
133
 
 
134
 
  G_OBJECT_CLASS (hud_debug_source_parent_class)
135
 
    ->finalize (object);
136
 
}
137
 
 
138
 
static void
139
 
hud_debug_source_init (HudDebugSource *source)
140
 
{
141
 
}
142
 
 
143
 
static void
144
 
hud_debug_source_iface_init (HudSourceInterface *iface)
145
 
{
146
 
  iface->use = hud_debug_source_use;
147
 
  iface->unuse = hud_debug_source_unuse;
148
 
  iface->search = hud_debug_source_search;
149
 
}
150
 
 
151
 
static void
152
 
hud_debug_source_class_init (HudDebugSourceClass *class)
153
 
{
154
 
  class->finalize = hud_debug_source_finalize;
155
 
}
156
 
 
157
 
/**
158
 
 * hud_debug_source_new:
159
 
 *
160
 
 * Creates a #HudDebugSource.
161
 
 *
162
 
 * Returns: a new empty #HudDebugSource
163
 
 **/
164
 
HudDebugSource *
165
 
hud_debug_source_new (void)
166
 
{
167
 
  return g_object_new (HUD_TYPE_DEBUG_SOURCE, NULL);
168
 
}