1 /*
2 * Program: Rubrica
3 * file: statusbar.c
4 *
5 *
6 * Copyright (C) 2000-2005 Nicola Fragale <nicolafragale@libero.it>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 #include <gtk/gtk.h>
23 #include <glib/gi18n-lib.h>
24
25
26 #include "statusbar.h"
27 #include "types.h"
28
29
30 enum {
31 PROP_0,
32 STATUSBAR_MESSAGE,
33 STATUSBAR_EXTRA,
34 STATUSBAR_IMAGES,
35 STATUSBAR_RATE,
36 STATUSBAR_LOCK
37 };
38
39
40 struct _RubricaStatusbarPrivate {
41 gint ctxid;
42 gchar* message;
43 gboolean enable_extra;
44 gboolean enable_images;
45
46 RubricaPixmap rate;
47 RubricaPixmap lock;
48
49 GtkWidget* extra; // extra box
50 GtkWidget* images; // images's box
51 GtkWidget* label; //
52 GtkWidget* sep;
53 GtkWidget* rate_img; // rate image
54 GtkWidget* lock_img; // lock image
55
56 gboolean dispose_has_run;
57 };
58
59 #define RUBRICA_STATUSBAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
60 RUBRICA_STATUSBAR_TYPE, \
61 RubricaStatusbarPrivate))
62
63
64 static GObjectClass *parent_class = NULL;
65
66
67 static void rubrica_statusbar_class_init (RubricaStatusbarClass* klass);
68 static void rubrica_statusbar_init (RubricaStatusbar* obj);
69
70 static void rubrica_statusbar_finalize (RubricaStatusbar* self);
71 static void rubrica_statusbar_dispose (RubricaStatusbar* self);
72
73
74 static void rubrica_statusbar_set_property (GObject* obj, guint property_id,
75 GValue* value, GParamSpec* spec);
76 static void rubrica_statusbar_get_property (GObject* obj, guint property_id,
77 GValue* value, GParamSpec* spec);
78
79 static GdkPixbuf* load_pixbuf(gint pixmap);
80
test_event(GtkEventBox * e,gpointer data)81 void test_event (GtkEventBox* e, gpointer data)
82 {
83 RubricaStatusbar* bar = (RubricaStatusbar*) data;
84 RubricaPixmap pixmap;
85
86 g_object_get(bar, "lock", &pixmap, NULL);
87
88 if (pixmap == PIXMAP_LOCK)
89 g_object_set(bar, "lock", PIXMAP_UNLOCK, NULL);
90 else
91 g_object_set(bar, "lock", PIXMAP_LOCK, NULL);
92 }
93
94 static GdkPixbuf*
load_pixbuf(gint pixmap)95 load_pixbuf(gint pixmap)
96 {
97 GtkIconTheme* theme;
98 GdkPixbuf* pixbuf = NULL;
99
100 theme = gtk_icon_theme_get_default();
101
102 switch(pixmap)
103 {
104 case PIXMAP_RATE_NONE:
105 pixbuf = gtk_icon_theme_load_icon (theme, "rate1", 20, 0, NULL);
106 break;
107
108 case PIXMAP_RATE_FEW:
109 pixbuf = gtk_icon_theme_load_icon (theme, "rate2", 20, 0, NULL);
110 break;
111
112 case PIXMAP_RATE_NORMAL:
113 pixbuf = gtk_icon_theme_load_icon (theme, "rate3", 20, 0, NULL);
114 break;
115
116 case PIXMAP_RATE_HIGH:
117 pixbuf = gtk_icon_theme_load_icon (theme, "rate4", 20, 0, NULL);
118 break;
119
120 case PIXMAP_RATE_VERY_HIGH:
121 pixbuf = gtk_icon_theme_load_icon (theme, "rate5", 20, 0, NULL);
122 break;
123
124 case PIXMAP_LOCK:
125 pixbuf = gtk_icon_theme_load_icon (theme, "stock_lock-ok", 18, 0, NULL);
126 break;
127
128 case PIXMAP_UNLOCK:
129 pixbuf = gtk_icon_theme_load_icon (theme, "stock_lock-open",
130 18, 0, NULL);
131 break;
132
133
134 default:
135 break;
136 }
137
138 return pixbuf;
139 }
140
141
142 GType
rubrica_statusbar_get_type()143 rubrica_statusbar_get_type()
144 {
145 static GType rubrica_bar_type = 0;
146
147 if (!rubrica_bar_type)
148 {
149 static const GTypeInfo rubrica_bar_info =
150 {
151 sizeof(RubricaStatusbarClass),
152 NULL,
153 NULL,
154 (GClassInitFunc) rubrica_statusbar_class_init,
155 NULL,
156 NULL,
157 sizeof(RubricaStatusbar),
158 0,
159 (GInstanceInitFunc) rubrica_statusbar_init
160 };
161
162 rubrica_bar_type = g_type_register_static (GTK_TYPE_STATUSBAR,
163 "RubricaStatusbar",
164 &rubrica_bar_info, 0);
165 }
166
167 return rubrica_bar_type;
168 }
169
170
171
172 static void
rubrica_statusbar_dispose(RubricaStatusbar * self)173 rubrica_statusbar_dispose (RubricaStatusbar* self)
174 {
175 g_return_if_fail(IS_RUBRICA_STATUSBAR(self));
176
177 if (self->priv->dispose_has_run)
178 return;
179
180 self->priv->dispose_has_run = TRUE;
181 }
182
183
184 static void
rubrica_statusbar_finalize(RubricaStatusbar * self)185 rubrica_statusbar_finalize (RubricaStatusbar* self)
186 {
187 g_return_if_fail(IS_RUBRICA_STATUSBAR(self));
188
189 }
190
191
192 static void
rubrica_statusbar_class_init(RubricaStatusbarClass * klass)193 rubrica_statusbar_class_init(RubricaStatusbarClass* klass)
194 {
195 GObjectClass *object_class;
196 GParamSpec* pspec;
197
198 parent_class = g_type_class_peek_parent (klass);
199 object_class = G_OBJECT_CLASS (klass);
200
201 object_class->finalize = (GObjectFinalizeFunc) rubrica_statusbar_finalize;
202 object_class->dispose = (GObjectFinalizeFunc) rubrica_statusbar_dispose;
203
204 object_class->set_property = (gpointer) rubrica_statusbar_set_property;
205 object_class->get_property = (gpointer) rubrica_statusbar_get_property;
206
207 g_type_class_add_private (klass, sizeof(RubricaStatusbarPrivate));
208
209
210 /**
211 * RubricaStatusbar:enable-extra
212 *
213 *
214 */
215 pspec = g_param_spec_boolean("enable-extra",
216 "eneble extra",
217 "enable extra box",
218 FALSE,
219 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
220 g_object_class_install_property(object_class, STATUSBAR_EXTRA, pspec);
221
222 /**
223 * RubricaStatusbar:enable-images
224 *
225 *
226 */
227 pspec = g_param_spec_boolean("enable-images",
228 "eneble images",
229 "enable images box",
230 FALSE,
231 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
232 g_object_class_install_property(object_class, STATUSBAR_IMAGES, pspec);
233
234 /**
235 * RubricaCardsView:msg
236 *
237 * the name of the addressbook displayed
238 */
239 pspec = g_param_spec_string("message",
240 "message",
241 "a message",
242 "",
243 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
244 g_object_class_install_property(object_class, STATUSBAR_MESSAGE, pspec);
245
246
247 /**
248 * RubricaStatusbar:enable-rate
249 *
250 *
251 */
252 pspec = g_param_spec_int("rate",
253 "rate pixmap",
254 "set rate pixmap",
255 PIXMAP_RATE_NONE, // min
256 PIXMAP_RATE_VERY_HIGH, // manx
257 PIXMAP_RATE_NORMAL, // default
258 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
259 g_object_class_install_property(object_class, STATUSBAR_RATE, pspec);
260
261
262 /**
263 * RubricaStatusbar:enable-lock
264 *
265 *
266 */
267 pspec = g_param_spec_int("lock",
268 "lock pixmap",
269 "set lock pixmap",
270 PIXMAP_UNLOCK, // min
271 PIXMAP_LOCK, // max
272 PIXMAP_UNLOCK, // default
273 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
274 g_object_class_install_property(object_class, STATUSBAR_LOCK, pspec);
275 }
276
277
278
279 static void
rubrica_statusbar_init(RubricaStatusbar * self)280 rubrica_statusbar_init(RubricaStatusbar* self)
281 {
282 GtkWidget* sep;
283 GtkWidget* label;
284
285 g_return_if_fail(IS_RUBRICA_STATUSBAR(self));
286
287 self->priv = RUBRICA_STATUSBAR_GET_PRIVATE(self);
288
289 self->priv->extra = gtk_hbox_new(FALSE, 0);
290 self->priv->images = gtk_hbox_new(FALSE, 0);
291 self->priv->ctxid = 0;
292 self->priv->message = NULL;
293 self->priv->enable_extra = FALSE;
294 self->priv->label = gtk_label_new("");
295 self->priv->rate_img = gtk_image_new();
296 self->priv->lock_img = gtk_image_new();
297
298 /* Build the statusbar
299 */
300 gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(self), TRUE);
301 self->priv->ctxid = gtk_statusbar_get_context_id(GTK_STATUSBAR(self),
302 "RubricaContext");
303
304 /* Build extra box
305 */
306 gtk_box_pack_start(GTK_BOX(self), self->priv->extra, FALSE, FALSE, 2);
307 gtk_box_pack_start(GTK_BOX(self), self->priv->images, FALSE, FALSE, 2);
308 gtk_widget_show(self->priv->extra);
309 gtk_widget_show(self->priv->images);
310
311 sep = gtk_vseparator_new();
312 gtk_box_pack_start(GTK_BOX(self->priv->extra), sep, FALSE, FALSE, 2);
313 gtk_widget_show(sep);
314
315 gtk_box_pack_start(GTK_BOX(self->priv->extra), self->priv->label,
316 TRUE, TRUE, 2);
317 gtk_widget_show(self->priv->label);
318
319 self->priv->sep = gtk_vseparator_new();
320 gtk_box_pack_start(GTK_BOX(self->priv->extra), self->priv->sep,
321 FALSE, FALSE, 2);
322 gtk_widget_hide(self->priv->sep);
323
324 label = gtk_label_new(_("rate:"));
325 gtk_box_pack_start(GTK_BOX(self->priv->images), label, FALSE, FALSE, 2);
326 gtk_widget_show(label);
327
328 gtk_box_pack_start(GTK_BOX(self->priv->images), self->priv->rate_img,
329 FALSE, FALSE, 2);
330 gtk_widget_show(self->priv->rate_img);
331
332 sep = gtk_vseparator_new();
333 gtk_box_pack_start(GTK_BOX(self->priv->images), sep, FALSE, FALSE, 2);
334 gtk_widget_show(sep);
335
336 label = gtk_label_new(_("status:"));
337 gtk_box_pack_start(GTK_BOX(self->priv->images), label, FALSE, FALSE, 2);
338 gtk_widget_show(label);
339
340 gtk_box_pack_start(GTK_BOX(self->priv->images), self->priv->lock_img,
341 FALSE, FALSE, 2);
342 gtk_widget_show(self->priv->lock_img);
343
344 gtk_widget_set_sensitive(self->priv->extra, FALSE);
345 gtk_widget_set_sensitive(self->priv->images, FALSE);
346
347 gtk_widget_show(GTK_WIDGET(self));
348
349 self->priv->dispose_has_run = FALSE;
350 }
351
352
353 static void
rubrica_statusbar_set_property(GObject * obj,guint property_id,GValue * value,GParamSpec * spec)354 rubrica_statusbar_set_property (GObject* obj, guint property_id,
355 GValue* value, GParamSpec* spec)
356 {
357 RubricaStatusbar* self = (RubricaStatusbar*) obj;
358 RubricaStatusbarPrivate* priv = RUBRICA_STATUSBAR_GET_PRIVATE(self);
359 GdkPixbuf* pixbuf = NULL;
360
361 switch (property_id)
362 {
363 case STATUSBAR_MESSAGE:
364 if (priv->message)
365 g_free(priv->message);
366
367 priv->message = g_value_dup_string(value);
368
369 gtk_label_set_text(GTK_LABEL(priv->label), priv->message);
370 if (g_ascii_strcasecmp(priv->message, "") == 0)
371 gtk_widget_hide(self->priv->sep);
372 else
373 gtk_widget_show(self->priv->sep);
374 break;
375
376 case STATUSBAR_EXTRA:
377 priv->enable_extra = g_value_get_boolean(value);
378 gtk_widget_set_sensitive(priv->extra, priv->enable_extra);
379 break;
380
381 case STATUSBAR_IMAGES:
382 priv->enable_images = g_value_get_boolean(value);
383 gtk_widget_set_sensitive(priv->images, priv->enable_images);
384 break;
385
386 case STATUSBAR_RATE:
387 priv->rate = g_value_get_int(value);
388 pixbuf = load_pixbuf(priv->rate);
389
390 if (pixbuf)
391 {
392 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->rate_img), pixbuf);
393 gdk_pixbuf_unref (pixbuf);
394 }
395 break;
396
397 case STATUSBAR_LOCK:
398 priv->lock = g_value_get_int(value);
399 pixbuf = load_pixbuf(priv->lock);
400
401 if (pixbuf)
402 {
403 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->lock_img), pixbuf);
404 gdk_pixbuf_unref (pixbuf);
405 }
406 break;
407
408 default:
409 break;
410 }
411 }
412
413
414 static void
rubrica_statusbar_get_property(GObject * obj,guint property_id,GValue * value,GParamSpec * spec)415 rubrica_statusbar_get_property (GObject* obj, guint property_id,
416 GValue* value, GParamSpec* spec)
417 {
418 RubricaStatusbar* self = (RubricaStatusbar*) obj;
419 RubricaStatusbarPrivate* priv = RUBRICA_STATUSBAR_GET_PRIVATE(self);
420
421 switch (property_id)
422 {
423 case STATUSBAR_MESSAGE:
424 g_value_set_string(value, priv->message);
425 break;
426
427 case STATUSBAR_EXTRA:
428 g_value_set_boolean(value, priv->enable_extra);
429 break;
430
431 case STATUSBAR_IMAGES:
432 g_value_set_boolean(value, priv->enable_images);
433 break;
434
435 case STATUSBAR_RATE:
436 g_value_set_int(value, priv->rate);
437 break;
438
439 case STATUSBAR_LOCK:
440 g_value_set_int(value, priv->lock);
441 break;
442
443 default:
444 break;
445 }
446 }
447
448
449
450
451
452 /* Public
453 */
454 /**
455 * rubrica_statusbar_new
456 *
457 * create a #RubricaStatusbar
458 *
459 * returns: a new #RubricaStatusbar
460 */
461 GtkWidget*
rubrica_statusbar_new()462 rubrica_statusbar_new()
463 {
464 GtkWidget* bar;
465
466 bar = GTK_WIDGET(g_object_new(RUBRICA_STATUSBAR_TYPE, NULL));
467
468 return bar;
469 }
470
471 void
rubrica_statusbar_free(RubricaStatusbar * bar)472 rubrica_statusbar_free (RubricaStatusbar* bar)
473 {
474 g_object_unref(bar);
475 }
476
477
478
479 void
rubrica_statusbar_push_message(RubricaStatusbar * bar,gchar * msg)480 rubrica_statusbar_push_message (RubricaStatusbar* bar, gchar* msg)
481 {
482 g_return_if_fail(IS_RUBRICA_STATUSBAR(bar));
483
484 if (!msg)
485 return;
486
487 gtk_statusbar_push(GTK_STATUSBAR(bar), bar->priv->ctxid, msg);
488 }
489
490
491 void
rubrica_statusbar_clean_messages(RubricaStatusbar * bar)492 rubrica_statusbar_clean_messages (RubricaStatusbar* bar)
493 {
494 g_return_if_fail(IS_RUBRICA_STATUSBAR(bar));
495
496 gtk_statusbar_pop(GTK_STATUSBAR(bar), bar->priv->ctxid);
497 }
498
499
500 void
rubrica_statusbar_enable_extra(RubricaStatusbar * bar,gboolean bool)501 rubrica_statusbar_enable_extra (RubricaStatusbar* bar, gboolean bool)
502 {
503 g_return_if_fail(IS_RUBRICA_STATUSBAR(bar));
504
505 g_object_set(bar, "enable-extra", bool, NULL);
506 }
507
508 void
rubrica_statusbar_enable_images(RubricaStatusbar * bar,gboolean bool)509 rubrica_statusbar_enable_images (RubricaStatusbar* bar, gboolean bool)
510 {
511 g_return_if_fail(IS_RUBRICA_STATUSBAR(bar));
512
513 g_object_set(bar, "enable-images", bool, NULL);
514 }
515
516
517 void
rubrica_statusbar_extra_set_text(RubricaStatusbar * bar,gchar * text)518 rubrica_statusbar_extra_set_text (RubricaStatusbar* bar, gchar* text)
519 {
520 g_return_if_fail(IS_RUBRICA_STATUSBAR(bar));
521
522 if(!text)
523 return;
524
525 g_object_set(bar, "message", text, NULL);
526 }
527
528
529 void
rubrica_statusbar_extra_set_rate(RubricaStatusbar * bar,RubricaPixmap rate)530 rubrica_statusbar_extra_set_rate (RubricaStatusbar* bar, RubricaPixmap rate)
531 {
532 g_return_if_fail(IS_RUBRICA_STATUSBAR(bar));
533
534 g_object_set(bar, "rate", rate, NULL);
535 }
536
537
538 void
rubrica_statusbar_extra_set_lock(RubricaStatusbar * bar,RubricaPixmap lock)539 rubrica_statusbar_extra_set_lock (RubricaStatusbar* bar, RubricaPixmap lock)
540 {
541 g_return_if_fail(IS_RUBRICA_STATUSBAR(bar));
542
543 g_object_set(bar, "lock", lock, NULL);
544 }
545
546