2
* Copyright © 2012 Canonical Ltd.
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.
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.
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/>.
16
* Author: Ryan Lortie <desrt@desrt.ca>
19
#include "huddebugsource.h"
21
#include "hudsource.h"
22
#include "hudresult.h"
25
* SECTION:huddebugsource
26
* @title: HudDebugSource
27
* @short_description: a source to assist with debugging
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.
33
* Presently it creates a #HudItem corresponding to the current date and
34
* time (and updates it as the time changes).
40
* This is an opaque structure type.
43
struct _HudDebugSource
45
GObject parent_instance;
52
typedef GObjectClass HudDebugSourceClass;
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))
59
hud_debug_source_timeout (gpointer user_data)
61
HudDebugSource *source = user_data;
62
HudStringList *tokens;
66
g_clear_object (&source->item);
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);
74
source->item = hud_item_new (tokens, NULL, NULL, TRUE);
75
hud_string_list_unref (tokens);
77
hud_source_changed (HUD_SOURCE (source));
83
hud_debug_source_use (HudSource *hud_source)
85
HudDebugSource *source = HUD_DEBUG_SOURCE (hud_source);
87
if (source->use_count == 0)
88
source->timeout = g_timeout_add (1000, hud_debug_source_timeout, source);
94
hud_debug_source_unuse (HudSource *hud_source)
96
HudDebugSource *source = HUD_DEBUG_SOURCE (hud_source);
100
if (source->use_count == 0)
102
g_source_remove (source->timeout);
108
hud_debug_source_search (HudSource *hud_source,
109
GPtrArray *results_array,
110
HudTokenList *search_string)
112
HudDebugSource *source = HUD_DEBUG_SOURCE (hud_source);
118
result = hud_result_get_if_matched (source->item, search_string, 0);
120
g_ptr_array_add (results_array, result);
125
hud_debug_source_finalize (GObject *object)
127
HudDebugSource *source = HUD_DEBUG_SOURCE (object);
129
g_clear_object (&source->item);
132
g_source_remove (source->timeout);
134
G_OBJECT_CLASS (hud_debug_source_parent_class)
139
hud_debug_source_init (HudDebugSource *source)
144
hud_debug_source_iface_init (HudSourceInterface *iface)
146
iface->use = hud_debug_source_use;
147
iface->unuse = hud_debug_source_unuse;
148
iface->search = hud_debug_source_search;
152
hud_debug_source_class_init (HudDebugSourceClass *class)
154
class->finalize = hud_debug_source_finalize;
158
* hud_debug_source_new:
160
* Creates a #HudDebugSource.
162
* Returns: a new empty #HudDebugSource
165
hud_debug_source_new (void)
167
return g_object_new (HUD_TYPE_DEBUG_SOURCE, NULL);