1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
/*
* GNOME Logs - View and search logs
* Copyright (C) 2014, 2015 Red Hat, Inc.
* Copyright (C) 2014 Jonathan Kang
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gl-eventview.h"
#include <glib/gi18n.h>
#include <glib-unix.h>
#include <stdlib.h>
#include "gl-categorylist.h"
#include "gl-enums.h"
#include "gl-eventtoolbar.h"
#include "gl-eventviewdetail.h"
#include "gl-eventviewlist.h"
#include "gl-journal.h"
#include "gl-util.h"
enum
{
PROP_0,
PROP_MODE,
N_PROPERTIES
};
struct _GlEventView
{
/*< private >*/
GtkStack parent_instance;
};
typedef struct
{
GtkWidget *events;
GlJournalEntry *entry;
GlUtilClockFormat clock_format;
GlEventViewMode mode;
} GlEventViewPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GlEventView, gl_event_view, GTK_TYPE_STACK)
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
static const gchar DESKTOP_SCHEMA[] = "org.gnome.desktop.interface";
static const gchar CLOCK_FORMAT[] = "clock-format";
gchar *
gl_event_view_get_output_logs (GlEventView *view)
{
GlEventViewPrivate *priv;
GlEventViewList *events;
priv = gl_event_view_get_instance_private (view);
events = GL_EVENT_VIEW_LIST (priv->events);
return gl_event_view_list_get_output_logs (events);
}
gchar *
gl_event_view_get_current_boot_time (GlEventView *view,
const gchar *boot_match)
{
GlEventViewPrivate *priv;
GlEventViewList *events;
priv = gl_event_view_get_instance_private (view);
events = GL_EVENT_VIEW_LIST (priv->events);
return gl_event_view_list_get_current_boot_time (events, boot_match);
}
GArray *
gl_event_view_get_boot_ids (GlEventView *view)
{
GlEventViewPrivate *priv;
GlEventViewList *events;
priv = gl_event_view_get_instance_private (view);
events = GL_EVENT_VIEW_LIST (priv->events);
return gl_event_view_list_get_boot_ids (events);
}
void
gl_event_view_view_boot (GlEventView *view, const gchar *match)
{
GlEventViewList *events;
GlEventViewPrivate *priv;
g_return_if_fail (GL_EVENT_VIEW (view));
priv = gl_event_view_get_instance_private (view);
events = GL_EVENT_VIEW_LIST (priv->events);
gl_event_view_list_view_boot (events, match);
}
void
gl_event_view_show_detail (GlEventView *view)
{
GlEventViewList *events;
GlEventViewPrivate *priv;
g_return_if_fail (GL_EVENT_VIEW (view));
priv = gl_event_view_get_instance_private (view);
events = GL_EVENT_VIEW_LIST (priv->events);
priv->entry = gl_event_view_list_get_detail_entry (events);
}
gboolean
gl_event_view_handle_search_event (GlEventView *view,
GAction *action,
GdkEvent *event)
{
GlEventViewPrivate *priv;
GlEventViewList *events;
priv = gl_event_view_get_instance_private (view);
events = GL_EVENT_VIEW_LIST (priv->events);
if (gl_event_view_list_handle_search_event (events, action,
event) == GDK_EVENT_STOP)
{
return GDK_EVENT_STOP;
}
return GDK_EVENT_PROPAGATE;
}
void
gl_event_view_set_search_mode (GlEventView *view,
gboolean state)
{
GlEventViewPrivate *priv;
GlEventViewList *events;
g_return_if_fail (GL_EVENT_VIEW (view));
priv = gl_event_view_get_instance_private (view);
events = GL_EVENT_VIEW_LIST (priv->events);
gl_event_view_list_set_search_mode (events, state);
}
void
gl_event_view_set_sort_order (GlEventView *view,
GlSortOrder sort_order)
{
GlEventViewPrivate *priv;
GlEventViewList *events;
g_return_if_fail (GL_EVENT_VIEW (view));
priv = gl_event_view_get_instance_private (view);
events = GL_EVENT_VIEW_LIST (priv->events);
gl_event_view_list_set_sort_order (events, sort_order);
}
static void
on_notify_mode (GlEventView *view,
GParamSpec *pspec,
gpointer user_data)
{
GlEventViewPrivate *priv;
GtkStack *stack;
GtkWidget *detail;
priv = gl_event_view_get_instance_private (view);
stack = GTK_STACK (view);
switch (priv->mode)
{
case GL_EVENT_VIEW_MODE_LIST:
{
GtkWidget *child;
child = gtk_stack_get_child_by_name (stack, "detail");
if (child)
{
gtk_container_remove (GTK_CONTAINER (stack), child);
}
gtk_stack_set_visible_child (stack, priv->events);
}
break;
case GL_EVENT_VIEW_MODE_DETAIL:
{
gl_event_view_show_detail (view);
detail = gl_event_view_detail_new (priv->entry,
priv->clock_format);
gtk_widget_show_all (detail);
gtk_stack_add_named (stack, detail, "detail");
gtk_stack_set_visible_child_name (stack, "detail");
}
break;
default:
g_assert_not_reached ();
break;
}
}
static void
gl_event_view_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GlEventView *view = GL_EVENT_VIEW (object);
GlEventViewPrivate *priv = gl_event_view_get_instance_private (view);
switch (prop_id)
{
case PROP_MODE:
g_value_set_enum (value, priv->mode);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gl_event_view_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GlEventView *view = GL_EVENT_VIEW (object);
GlEventViewPrivate *priv = gl_event_view_get_instance_private (view);
switch (prop_id)
{
case PROP_MODE:
priv->mode = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gl_event_view_class_init (GlEventViewClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gobject_class->get_property = gl_event_view_get_property;
gobject_class->set_property = gl_event_view_set_property;
obj_properties[PROP_MODE] = g_param_spec_enum ("mode", "Mode",
"Event display mode",
GL_TYPE_EVENT_VIEW_MODE,
GL_EVENT_VIEW_MODE_LIST,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPERTIES,
obj_properties);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Logs/gl-eventview.ui");
gtk_widget_class_bind_template_child_private (widget_class, GlEventView,
events);
}
static void
gl_event_view_init (GlEventView *view)
{
GlEventViewPrivate *priv;
GSettings *settings;
gtk_widget_init_template (GTK_WIDGET (view));
priv = gl_event_view_get_instance_private (view);
/* TODO: Monitor and propagate any GSettings changes. */
settings = g_settings_new (DESKTOP_SCHEMA);
priv->clock_format = g_settings_get_enum (settings, CLOCK_FORMAT);
g_object_unref (settings);
g_signal_connect (view, "notify::mode", G_CALLBACK (on_notify_mode),
NULL);
}
void
gl_event_view_set_mode (GlEventView *view,
GlEventViewMode mode)
{
GlEventViewPrivate *priv;
g_return_if_fail (GL_EVENT_VIEW (view));
priv = gl_event_view_get_instance_private (view);
if (priv->mode != mode)
{
priv->mode = mode;
g_object_notify_by_pspec (G_OBJECT (view),
obj_properties[PROP_MODE]);
}
}
GtkWidget *
gl_event_view_new (void)
{
return g_object_new (GL_TYPE_EVENT_VIEW, NULL);
}
|