190
142
for (l = list; l != NULL; l = g_list_next (l)) {
191
145
entry = (AlarmListEntry *) l->data;
193
pixbuf = gtk_icon_theme_load_icon (theme, entry->icon, 22, 0, NULL);
146
icon = g_icon_new_for_string (entry->icon, NULL);
195
148
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
196
149
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
198
TEXT_COL, entry->name,
202
g_object_unref (pixbuf);
151
TEXT_COL, entry->name,
154
g_object_unref (icon);
205
157
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
206
158
gtk_list_store_set (GTK_LIST_STORE (model), &iter, -1);
207
159
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
208
160
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
210
162
TEXT_COL, custom_label,
216
button_cb (GtkWidget *widget,
217
GdkEventButton *event,
220
AlarmApplet *applet = (AlarmApplet *)data;
222
g_debug("BUTTON: %d", event->button);
224
/* React only to left mouse button */
225
if (event->button == 2 || event->button == 3) {
229
if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) {
230
/* Double click: Open list alarms */
231
list_alarms_dialog_display (applet);
233
alarm_applet_snooze_alarms (applet);
236
/* Show edit alarms dialog */
237
//display_list_alarms_dialog (applet);
242
/* Taken from the GeyesApplet */
244
applet_back_change (PanelApplet *a,
245
PanelAppletBackgroundType type,
250
/* taken from the TrashApplet */
251
GtkRcStyle *rc_style;
255
gtk_widget_set_style (GTK_WIDGET (applet->parent), NULL);
256
rc_style = gtk_rc_style_new ();
257
gtk_widget_modify_style (GTK_WIDGET (applet->parent), rc_style);
258
gtk_rc_style_unref (rc_style);
261
case PANEL_COLOR_BACKGROUND:
262
gtk_widget_modify_bg (GTK_WIDGET (applet->parent),
263
GTK_STATE_NORMAL, color);
266
case PANEL_PIXMAP_BACKGROUND:
267
style = gtk_style_copy (GTK_WIDGET (
268
applet->parent)->style);
269
if (style->bg_pixmap[GTK_STATE_NORMAL])
271
(style->bg_pixmap[GTK_STATE_NORMAL]);
272
style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref
274
gtk_widget_set_style (GTK_WIDGET (applet->parent),
276
g_object_unref (style);
279
case PANEL_NO_BACKGROUND:
286
/* Taken from gnome-panel/button-widget.c */
288
alarm_applet_icon_update (AlarmApplet *applet)
290
static const gchar *prev_icon = ALARM_ICON;
295
const gchar *icon_name = ALARM_ICON;
297
if (applet->upcoming_alarm && applet->upcoming_alarm->type == ALARM_TYPE_TIMER) {
298
icon_name = TIMER_ICON;
301
w = GTK_WIDGET (applet->parent);
303
if (panel_applet_get_orient (applet->parent) == PANEL_APPLET_ORIENT_UP ||
304
panel_applet_get_orient (applet->parent) == PANEL_APPLET_ORIENT_DOWN)
305
size = w->allocation.height;
307
size = w->allocation.width;
322
// Reload icon only if the size is different.}
323
icon = gtk_image_get_pixbuf (GTK_IMAGE (applet->icon));
326
if (IS_HORIZONTAL (applet->parent))
327
pbsize = gdk_pixbuf_get_height (icon);
329
pbsize = gdk_pixbuf_get_width (icon);
331
if (prev_icon == icon_name && pbsize == size) {
333
//g_debug ("load_icon: Existing size the same.");
338
g_debug ("Resizing icon to %dx%d...", size, size);
340
icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
346
g_critical ("Icon not found.");
350
g_object_set (applet->icon, "pixbuf", icon, NULL);
353
g_object_unref (icon);
355
prev_icon = icon_name;
359
change_size_cb (GtkWidget *widget,
360
GtkAllocation *alloc,
363
alarm_applet_icon_update (applet);
369
update_orient (AlarmApplet *applet)
378
if (IS_HORIZONTAL (applet->parent) && ORIENT_IS_HORIZONTAL (applet->orient)) {
379
// Nothing to do, both old and new orientation is horizontal.
383
/* Do we need to repack? */
384
if (IS_HORIZONTAL (applet->parent) != ORIENT_IS_HORIZONTAL (applet->orient)) {
385
g_debug ("update_orient: REPACK");
388
if (IS_HORIZONTAL (applet->parent))
389
box = gtk_hbox_new(FALSE, 6);
391
box = gtk_vbox_new(FALSE, 6);
394
g_object_ref (applet->icon);
395
g_object_ref (applet->label);
398
gtk_container_remove (GTK_CONTAINER (applet->box), applet->icon);
399
gtk_container_remove (GTK_CONTAINER (applet->box), applet->label);
400
gtk_container_remove (GTK_CONTAINER (applet->parent), applet->box);
403
gtk_box_pack_start_defaults(GTK_BOX (box), applet->icon);
404
gtk_box_pack_start_defaults(GTK_BOX (box), applet->label);
408
/* Add to container and show */
409
gtk_container_add (GTK_CONTAINER (applet->parent), box);
410
gtk_widget_show_all (GTK_WIDGET (applet->parent));
413
switch (panel_applet_get_orient (applet->parent)) {
414
case PANEL_APPLET_ORIENT_LEFT:
417
case PANEL_APPLET_ORIENT_RIGHT:
426
angle = gtk_label_get_angle (GTK_LABEL (applet->label));
427
if (angle != new_angle) {
429
gtk_label_set_angle (GTK_LABEL (applet->label), new_angle);
434
orient_change_cb (PanelApplet *a,
435
PanelAppletOrient orient,
438
g_debug ("applet_orient_change");
440
update_orient (applet);
442
// Store new orientation
443
applet->orient = panel_applet_get_orient (applet->parent);
448
unrealize_cb (GtkWidget *object, AlarmApplet *applet)
450
alarm_applet_destroy (applet);
453
#ifdef HAVE_LIBNOTIFY
455
alarm_applet_notification_action_cb (NotifyNotification *notify,
459
Alarm *alarm = ALARM (data);
461
g_debug ("NOTIFY ACTION: %s", action);
463
if (strcmp (action, "clear") == 0) {
464
g_debug ("NOTIFY CLEAR #%d", alarm->id);
468
g_debug ("NOTIFY SNOOZE #%d", alarm->id);
469
alarm_snooze (alarm);
474
/* Taken from the battery applet */
476
alarm_applet_notification_display (AlarmApplet *applet, Alarm *alarm)
478
#ifdef HAVE_LIBNOTIFY
479
GError *error = NULL;
482
const gchar *message;
483
const gchar *icon = (alarm->type == ALARM_TYPE_CLOCK) ? ALARM_ICON : TIMER_ICON;
485
if (!notify_is_initted () && !notify_init (_("Alarm Applet")))
488
message = alarm->message;
490
applet->notify = notify_notification_new (_("Alarm!"), message, icon, GTK_WIDGET (applet->icon));
492
notify_notification_set_timeout (applet->notify, NOTIFY_EXPIRES_NEVER);
493
notify_notification_add_action (applet->notify, "clear", "Clear", alarm_applet_notification_action_cb, alarm, NULL);
496
notify_notification_add_action (applet->notify, "snooze", "Snooze", alarm_applet_notification_action_cb, alarm, NULL);
499
result = notify_notification_show (applet->notify, &error);
503
g_warning (error->message);
504
g_error_free (error);
514
alarm_applet_notification_close (AlarmApplet *applet)
516
#ifdef HAVE_LIBNOTIFY
518
GError *error = NULL;
520
result = notify_notification_close (applet->notify, &error);
524
g_warning (error->message);
525
g_error_free (error);
528
g_object_unref (applet->notify);
529
applet->notify = NULL;
167
* Show a notification
537
alarm_applet_ui_update (AlarmApplet *applet)
170
alarm_applet_notification_show (AlarmApplet *applet,
171
const gchar *summary,
539
if (applet->show_label) {
540
alarm_applet_label_update (applet);
176
NotifyNotification *n;
177
GError *error = NULL;
179
n = notify_notification_new_with_status_icon (summary, body, icon,
180
applet->status_icon);
182
if (!notify_notification_show (n, &error)) {
183
g_warning ("Failed to send notification: %s", error->message);
184
g_error_free (error);
543
alarm_applet_update_tooltip (applet);
187
g_object_unref(G_OBJECT(n));
549
195
alarm_applet_ui_init (AlarmApplet *applet)
554
/* Set up PanelApplet signals */
555
g_signal_connect (G_OBJECT(applet->parent), "button-press-event",
556
G_CALLBACK(button_cb), applet);
558
g_signal_connect (G_OBJECT(applet->parent), "unrealize",
559
G_CALLBACK(unrealize_cb), applet);
561
g_signal_connect (G_OBJECT(applet->parent), "change-background",
562
G_CALLBACK (applet_back_change), applet);
564
g_signal_connect (G_OBJECT(applet->parent), "change-orient",
565
G_CALLBACK (orient_change_cb), applet);
567
g_signal_connect (G_OBJECT(applet->parent), "size-allocate",
568
G_CALLBACK (change_size_cb), applet);
570
/* Set up container box */
571
if (IS_HORIZONTAL (applet->parent))
572
applet->box = gtk_hbox_new(FALSE, 6);
574
applet->box = gtk_vbox_new(FALSE, 6);
576
/* Store orientation for future reference */
577
applet->orient = panel_applet_get_orient (applet->parent);
579
/* Set up icon and label */
580
applet->icon = gtk_image_new ();
581
alarm_applet_icon_update (applet);
583
applet->label = g_object_new(GTK_TYPE_LABEL,
584
"label", ALARM_DEF_LABEL,
586
"visible", applet->show_label,
587
"no-show-all", TRUE, /* So gtk_widget_show_all() won't set visible to TRUE */
590
/* Set up UI updater */
591
alarm_applet_ui_update (applet);
592
applet->timer_id = g_timeout_add_seconds (1, (GSourceFunc)alarm_applet_ui_update, applet);
595
gtk_box_pack_start_defaults(GTK_BOX (applet->box), applet->icon);
596
gtk_box_pack_start_defaults(GTK_BOX (applet->box), applet->label);
598
/* Update orientation */
599
update_orient (applet);
601
/* Add to container and show */
602
gtk_container_add (GTK_CONTAINER (applet->parent), applet->box);
603
gtk_widget_show_all (GTK_WIDGET (applet->parent));
605
alarm_applet_update_tooltip (applet);
613
menu_snooze_alarm_cb (BonoboUIComponent *component,
617
g_debug("menu_snooze_alarm");
619
alarm_applet_snooze_alarms (applet);
623
menu_clear_alarm_cb (BonoboUIComponent *component,
627
g_debug("menu_clear_alarm");
629
alarm_applet_clear_alarms (applet);
633
menu_list_alarms_cb (BonoboUIComponent *component,
637
AlarmApplet *applet = (AlarmApplet *)data;
638
list_alarms_dialog_display (applet);
642
menu_preferences_cb (BonoboUIComponent *component,
646
/* Construct the preferences dialog and show it here */
647
g_debug("preferences_dialog");
649
preferences_dialog_display (applet);
653
menu_about_cb (BonoboUIComponent *component,
657
/* Construct the about dialog and show it here */
658
g_debug("about_dialog");
660
static const gchar *const authors[] = {
661
"Johannes H. Jensen <joh@pseudoberries.com>",
664
static const gchar *const documenters[] = {
665
"Johannes H. Jensen <joh@pseudoberries.com>",
668
static const gchar *const artists[] = {
669
"Lasse Gulvåg Sætre <lassegs@gmail.com>",
673
gtk_show_about_dialog (NULL,
674
"program-name", ALARM_NAME,
675
"title", _("About " ALARM_NAME),
677
"copyright", "\xC2\xA9 2007 Johannes H. Jensen",
678
"website", "http://alarm-clock.pseudoberries.com/",
680
"documenters", documenters,
682
"logo-icon-name",ALARM_ICON,
690
alarm_applet_menu_init (AlarmApplet *applet)
692
GtkIconInfo *info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default(), SNOOZE_ICON, 16, 0);
694
g_debug ("ICON: %s", gtk_icon_info_get_filename (info));
696
static const gchar *menu_xml =
697
"<popup name=\"button3\">\n"
698
" <menuitem name=\"Snooze Item\" "
699
" verb=\"SnoozeAlarm\" "
700
" _label=\"_Snooze alarms\" "
701
" pixtype=\"filename\" "
702
" pixname=\"%s\"/>\n"
703
" <menuitem name=\"Clear Item\" "
704
" verb=\"ClearAlarm\" "
705
" _label=\"_Clear alarms\" "
706
" pixtype=\"stock\" "
707
" pixname=\"gtk-clear\"/>\n"
709
" <menuitem name=\"List Alarms\" "
710
" verb=\"ListAlarms\" "
711
" _label=\"_Edit Alarms\" "
712
" pixtype=\"stock\" "
713
" pixname=\"gtk-edit\"/>\n"
714
" <menuitem name=\"Preferences Item\" "
715
" verb=\"Preferences\" "
716
" _label=\"_Preferences...\"\n"
717
" pixtype=\"stock\" "
718
" pixname=\"gtk-properties\"/>\n"
719
" <menuitem name=\"About Item\" "
721
" _label=\"_About...\"\n"
722
" pixtype=\"stock\" "
723
" pixname=\"gtk-about\"/>\n"
726
static const BonoboUIVerb menu_verbs [] = {
727
BONOBO_UI_VERB ("SnoozeAlarm", menu_snooze_alarm_cb),
728
BONOBO_UI_VERB ("ClearAlarm", menu_clear_alarm_cb),
729
BONOBO_UI_VERB ("ListAlarms", menu_list_alarms_cb),
730
BONOBO_UI_VERB ("Preferences", menu_preferences_cb),
731
BONOBO_UI_VERB ("About", menu_about_cb),
735
gchar *xml = g_strdup_printf (menu_xml, gtk_icon_info_get_filename (info));
737
panel_applet_setup_menu (PANEL_APPLET (applet->parent),
743
gtk_icon_info_free (info);
197
/* Load UI with GtkBuilder */
198
applet->ui = alarm_applet_ui_load ("alarm-clock.ui", applet);
201
/* Initialize status icon */
202
alarm_applet_status_init(applet);
204
/* Initialize libnotify */
205
if (!notify_init (PACKAGE_NAME)) {
206
g_critical ("Could not intialize libnotify!");
209
/* Initialize alarm list window */
210
applet->list_window = alarm_list_window_new (applet);
212
/* Initialize alarm settings dialog */
213
applet->settings_dialog = alarm_settings_dialog_new (applet);
215
/* Connect signals */
216
//gtk_builder_connect_signals (applet->ui, applet);
218
/* Initialize actions */
219
alarm_applet_actions_init (applet);
221
/* Initialize preferences dialog */
226
* Initialize status icon
229
alarm_applet_status_init (AlarmApplet *applet)
231
applet->status_icon = GTK_STATUS_ICON (gtk_builder_get_object (applet->ui, "status_icon"));
232
applet->status_menu = GTK_WIDGET (gtk_builder_get_object (applet->ui, "status_menu"));
234
gtk_status_icon_set_visible (applet->status_icon, TRUE);
238
* Update the status icon
241
alarm_applet_status_update (AlarmApplet *applet)
243
gtk_status_icon_set_blinking (applet->status_icon, applet->n_triggered > 0);
247
* Status icon callbacks:
251
alarm_applet_status_activate (GtkStatusIcon *status_icon,
254
AlarmApplet *applet = (AlarmApplet *)user_data;
256
// Snooze triggered alarms if any
257
if (applet->n_triggered > 0) {
258
gtk_action_activate (applet->action_snooze_all);
260
// No alarms triggered, toggle list window
261
gtk_action_activate (GTK_ACTION (applet->action_toggle_list_win));
266
alarm_applet_status_popup (GtkStatusIcon *status_icon,
271
AlarmApplet *applet = (AlarmApplet *)user_data;
273
gtk_menu_popup (GTK_MENU (applet->status_menu),
276
gtk_status_icon_position_menu,
287
status_menu_snooze_cb (GtkMenuItem *menuitem,
290
AlarmApplet *applet = (AlarmApplet *)user_data;
292
alarm_applet_alarms_snooze (applet);
296
status_menu_stop_cb (GtkMenuItem *menuitem,
299
AlarmApplet *applet = (AlarmApplet *)user_data;
301
alarm_applet_alarms_stop (applet);
306
alarm_applet_status_menu_edit_cb (GtkMenuItem *menuitem,
309
AlarmApplet *applet = (AlarmApplet *)user_data;
311
if (gtk_toggle_action_get_active (applet->action_toggle_list_win)) {
312
alarm_list_window_show (applet->list_window);
314
gtk_toggle_action_set_active (applet->action_toggle_list_win, TRUE);
319
alarm_applet_status_menu_prefs_cb (GtkMenuItem *menuitem,
322
AlarmApplet *applet = (AlarmApplet *)user_data;
324
prefs_dialog_show (applet);
328
alarm_applet_status_menu_about_cb (GtkMenuItem *menuitem,
331
AlarmApplet *applet = (AlarmApplet *)user_data;
335
GtkAboutDialog *dialog = GTK_ABOUT_DIALOG (
336
gtk_builder_get_object (applet->ui, "about-dialog"));
338
g_object_get (dialog, "visible", &visible, NULL);
342
title = g_strdup_printf (_("About %s"), _(ALARM_NAME));
343
g_object_set (G_OBJECT (dialog),
344
"program-name", _(ALARM_NAME),
350
gtk_dialog_run (GTK_DIALOG (dialog));
353
// Already visible, present it
354
gtk_window_present (GTK_WINDOW (dialog));
749
359
* An error callback for MediaPlayers
752
media_player_error_cb (MediaPlayer *player, GError *err, GtkWindow *parent)
362
media_player_error_cb (MediaPlayer *player, GError *err, gpointer data)
364
GtkWindow *parent = GTK_WINDOW (data);
754
365
gchar *uri, *tmp;
756
367
uri = media_player_get_uri (player);
757
tmp = g_strdup_printf (_("%s: %s"), uri, err->message);
368
tmp = g_strdup_printf ("%s: %s", uri, err->message);
759
370
g_critical (_("Could not play '%s': %s"), uri, err->message);
760
371
display_error_dialog (_("Could not play"), tmp, parent);