-
Notifications
You must be signed in to change notification settings - Fork 15
/
gui.c
1760 lines (1581 loc) · 53.6 KB
/
gui.c
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* kalu - Copyright (C) 2012-2014 Olivier Brunel
*
* gui.c
* Copyright (C) 2012-2014 Olivier Brunel <jjk@jjacky.com>
*
* This file is part of kalu.
*
* kalu 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.
*
* kalu 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
* kalu. If not, see http://www.gnu.org/licenses/
*/
#include <config.h>
/* kalu */
#include "kalu.h"
#include "gui.h"
#include "util-gtk.h"
#include "watched.h"
#include "preferences.h"
#include "conf.h"
#include "news.h"
#include "rt_timeout.h"
#include "imagemenuitem.h"
#ifndef DISABLE_UPDATER
#include "kalu-updater.h"
#include "updater.h"
#endif
#ifndef DISABLE_UPDATER
#define run_updater() do { \
set_kalpm_busy (TRUE); \
updater_run (config->pacmanconf, \
config->cmdline_post); \
} while (0)
#endif
#ifndef DISABLE_UPDATER
static void notif_run_simulation (NotifyNotification *notification,
const gchar *action _UNUSED_,
gpointer data _UNUSED_);
#endif
static void menu_check_cb (GtkMenuItem *item, gpointer data);
static void menu_quit_cb (GtkMenuItem *item, gpointer data);
static gboolean set_status_icon (gboolean active);
#ifdef ENABLE_STATUS_NOTIFIER
static void sn_upd_status (gboolean active);
static void sn_refresh_tooltip (void);
#endif
extern kalpm_state_t kalpm_state;
void
free_notif (notif_t *notif)
{
if (!notif)
{
return;
}
free (notif->summary);
free (notif->text);
if (notif->type == CHECK_NEWS || notif->type == CHECK_AUR)
{
/* CHECK_NEWS has xml_news; CHECK_AUR has cmdline w/ $PACKAGES replaced */
free (notif->data);
}
else
{
/* CHECK_UPGRADES, CHECK_WATCHED & CHECK_WATCHED_AUR all use packages */
FREE_PACKAGE_LIST (notif->data);
}
free (notif);
}
void
show_notif (notif_t *notif)
{
NotifyNotification *notification;
debug ("showing notif: %s\n%s\n--- EOF ---", notif->summary, notif->text);
notification = new_notification (notif->summary, notif->text);
if (config->notif_buttons)
{
if (notif->type & CHECK_UPGRADES)
{
if (!notif->data)
{
/* no data in this case means this is an error message about a
* conflict, in which case we still add the "Update system"
* button/action */
#ifndef DISABLE_UPDATER
/* We also add the "Run simulation" button */
notify_notification_add_action (notification, "run_simulation",
_c("notif-button", "Run simulation..."),
(NotifyActionCallback) notif_run_simulation,
NULL, NULL);
#endif
}
else if (config->check_pacman_conflict
&& is_pacman_conflicting ((alpm_list_t *) notif->data))
{
notify_notification_add_action (notification, "do_conflict_warn",
_c("notif-button", "Possible pacman/kalu conflict..."),
(NotifyActionCallback) show_pacman_conflict,
NULL, NULL);
}
if (config->action != UPGRADE_NO_ACTION)
{
notify_notification_add_action (notification, "do_updates",
_c("notif-button", "Update system..."),
(NotifyActionCallback) action_upgrade,
NULL, NULL);
}
}
else if (!notif->data)
{
/* no data means the notification was modified afterwards, as
* news/packages have been marked read. No more data/action button,
* just a simple notification (where text explains to re-do checks
* to be up to date) */
}
else if (notif->type & CHECK_AUR)
{
notify_notification_add_action (notification, "do_updates_aur",
_c("notif-button", "Update AUR packages..."),
(NotifyActionCallback) action_upgrade,
notif->data,
NULL);
}
else if (notif->type & CHECK_WATCHED)
{
notify_notification_add_action (notification, "mark_watched",
_c("notif-button", "Mark packages..."),
(NotifyActionCallback) action_watched,
notif,
NULL);
}
else if (notif->type & CHECK_WATCHED_AUR)
{
notify_notification_add_action (notification, "mark_watched_aur",
_c("notif-button", "Mark packages..."),
(NotifyActionCallback) action_watched_aur,
notif,
NULL);
}
else if (notif->type & CHECK_NEWS)
{
notify_notification_add_action (notification, "mark_news",
_c("notif-button", "Show news..."),
(NotifyActionCallback) action_news,
notif,
NULL);
}
}
/* we use a callback on "closed" to unref it, because when there's an action
* we need to keep a ref, otherwise said action won't work */
g_signal_connect (G_OBJECT (notification), "closed",
G_CALLBACK (notification_closed_cb), NULL);
notify_notification_show (notification, NULL);
}
gboolean
show_error_cmdline (gchar *arg[])
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"%s",
_("Unable to start process"));
gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
_("Error while trying to run command line: %s\n\nThe error was: <b>%s</b>"),
arg[0],
arg[1]);
gtk_window_set_title (GTK_WINDOW (dialog), _("kalu: Unable to start process"));
gtk_window_set_decorated (GTK_WINDOW (dialog), FALSE);
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
gtk_window_set_skip_pager_hint (GTK_WINDOW (dialog), FALSE);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
free (arg[0]);
free (arg[1]);
free (arg);
return FALSE;
}
static void
run_cmdline (char *cmdline)
{
GError *error = NULL;
set_kalpm_busy (TRUE);
debug ("run cmdline: %s", cmdline);
if (!g_spawn_command_line_sync (cmdline, NULL, NULL, NULL, &error))
{
/* we can't just show the error message from here, because this is ran
* from another thread, hence no gtk_* functions can be used. */
char **arg;
arg = new (char *, 2);
arg[0] = strdup (cmdline);
arg[1] = strdup (error->message);
g_main_context_invoke (NULL, (GSourceFunc) show_error_cmdline, (gpointer) arg);
}
set_kalpm_busy (FALSE);
if (G_UNLIKELY (error))
{
g_clear_error (&error);
}
else
{
/* check again, to refresh the state (since an upgrade was probably just done) */
kalu_check (TRUE);
}
if (cmdline != config->cmdline && cmdline != config->cmdline_aur)
{
free (cmdline);
}
}
#ifndef DISABLE_UPDATER
static gboolean
run_simulation (NotifyNotification *notification)
{
if (kalpm_state.is_busy)
{
show_error (_("Cannot run simulation: kalu is busy"),
_("kalu cannot run a simulation while it is busy "
"(e.g. checking/upgrading the system).\n"
"Please wait until kalu isn't busy anymore and try again."),
NULL);
return FALSE;
}
if (notification)
{
notify_notification_close (notification, NULL);
}
set_kalpm_busy (TRUE);
updater_run (NULL, NULL);
return TRUE;
}
static void
notif_run_simulation (NotifyNotification *notification,
const gchar *action _UNUSED_,
gpointer data _UNUSED_)
{
if (!run_simulation (notification))
/* restore if hidden */
notify_notification_show (notification, NULL);
}
#endif
void
action_upgrade (NotifyNotification *notification, const char *action, gchar *_cmdline)
{
/* action can be "do_updates" or "do_updates_aur" -- In the former case,
* _cmdline is NULL, in the later case, it might contain the cmdline to run
* (with $PACKAGES replaces with the list of packages to update) */
gboolean do_updates = streq (action, "do_updates");
gchar *cmdline;
if (kalpm_state.is_busy)
{
if (do_updates)
show_error (_("Cannot upgrade system: kalu is busy"),
_("kalu cannot upgrade the system while it is busy "
"(e.g. checking/upgrading the system).\n"
"Please wait until kalu isn't busy anymore and try again."),
NULL);
else
show_error (_("Cannot launch AUR upgrade: kalu is busy"),
_("kalu cannot launch AUR upgrade while it is busy "
"(e.g. checking/upgrading the system).\n"
"Please wait until kalu isn't busy anymore and try again."),
NULL);
/* restore if hidden */
notify_notification_show (notification, NULL);
return;
}
/* we need to strdup cmdline because it will be free-d when notification
* is destroyed, while we need it up to the other thread (run_cmdline) */
cmdline = (_cmdline) ? strdup (_cmdline) : NULL;
notify_notification_close (notification, NULL);
if (!cmdline)
{
if (do_updates)
{
#ifndef DISABLE_UPDATER
if (config->action == UPGRADE_ACTION_KALU)
{
run_updater ();
}
else /* if (config->action == UPGRADE_ACTION_CMDLINE) */
{
#endif
cmdline = config->cmdline;
#ifndef DISABLE_UPDATER
}
#endif
}
else
{
cmdline = config->cmdline_aur;
}
}
if (cmdline)
{
/* run in a separate thread, to not block/make GUI unresponsive */
g_thread_unref (g_thread_try_new ("action_upgrade",
(GThreadFunc) run_cmdline,
(gpointer) cmdline,
NULL));
}
}
void
action_watched (NotifyNotification *notification, char *action _UNUSED_,
notif_t *notif)
{
notify_notification_close (notification, NULL);
if (notif->data)
{
watched_update ((alpm_list_t *) notif->data, FALSE);
}
else
{
show_error (_("Unable to mark watched packages"),
_("Watched packages have changed, "
"you need to run the checks again to be up-to-date."),
NULL);
}
}
void
action_watched_aur (NotifyNotification *notification, char *action _UNUSED_,
notif_t *notif)
{
notify_notification_close (notification, NULL);
if (notif->data)
{
watched_update ((alpm_list_t *) notif->data, TRUE);
}
else
{
show_error (_("Unable to mark watched AUR packages"),
_("Watched AUR packages have changed, "
"you need to run the checks again to be up-to-date."),
NULL);
}
}
void
action_news (NotifyNotification *notification, char *action _UNUSED_,
notif_t *notif)
{
GError *error = NULL;
notify_notification_close (notification, NULL);
if (notif->data)
{
set_kalpm_busy (TRUE);
if (!news_show ((gchar *) notif->data, TRUE, &error))
{
show_error (_("Unable to show the news"), error->message, NULL);
g_clear_error (&error);
}
}
else
{
show_error (_("Unable to show unread news"),
_("Read news have changed, "
"you need to run the checks again to be up-to-date."),
NULL);
}
}
void
notification_closed_cb (NotifyNotification *notification, gpointer data _UNUSED_)
{
g_object_unref (notification);
}
gboolean
is_pacman_conflicting (alpm_list_t *packages)
{
gboolean ret = FALSE;
alpm_list_t *i;
kalu_package_t *pkg;
char *s, *ss, *old, *new, *so, *sn;
FOR_LIST (i, packages)
{
pkg = i->data;
if (streq ("pacman", pkg->name))
{
/* because we'll mess with it */
old = strdup (pkg->old_version);
/* locate begining of (major) version number (might have epoch: before) */
s = strchr (old, ':');
if (s)
{
so = s + 1;
}
else
{
so = old;
}
s = strrchr (so, '-');
if (!s)
{
/* should not be possible */
free (old);
break;
}
*s = '.';
/* because we'll mess with it */
new = strdup (pkg->new_version);
/* locate begining of (major) version number (might have epoch: before) */
s = strchr (new, ':');
if (s)
{
sn = s + 1;
}
else
{
sn = new;
}
s = strrchr (sn, '-');
if (!s)
{
/* should not be possible */
free (old);
free (new);
break;
}
*s = '.';
int nb = 0; /* to know which part (major/minor) we're dealing with */
while ((s = strchr (so, '.')) && (ss = strchr (sn, '.')))
{
*s = '\0';
*ss = '\0';
++nb;
/* if major or minor goes up, API changes is likely and kalu's
* dependency will kick in */
if (atoi (sn) > atoi (so))
{
ret = TRUE;
break;
}
/* if nb is 2 this was the minor number, past this we don't care */
if (nb == 2)
{
break;
}
so = s + 1;
sn = ss + 1;
}
free (old);
free (new);
break;
}
}
return ret;
}
inline void
kalu_check (gboolean is_auto)
{
/* in case e.g. the menu was shown (sensitive) before an auto-check started */
if (kalpm_state.is_busy)
{
return;
}
set_kalpm_busy (TRUE);
/* run in a separate thread, to not block/make GUI unresponsive */
g_thread_unref (g_thread_try_new ("kalu_check_work",
(GThreadFunc) kalu_check_work,
GINT_TO_POINTER (is_auto),
NULL));
}
gboolean
kalu_auto_check (void)
{
kalu_check (TRUE);
return G_SOURCE_REMOVE;
}
static void
show_last_notifs (void)
{
alpm_list_t *i;
/* in case e.g. the menu was shown (sensitive) before an auto-check started */
if (kalpm_state.is_busy)
{
return;
}
if (!config->last_notifs)
{
notif_t notif;
notif.type = 0;
notif.summary = (gchar *) _("No notifications to show.");
notif.text = NULL;
notif.data = NULL;
show_notif (¬if);
return;
}
FOR_LIST (i, config->last_notifs)
{
show_notif ((notif_t *) i->data);
}
}
static void
set_pause (gboolean paused)
{
/* in case e.g. the menu was shown (sensitive) before an auto-check started */
if (kalpm_state.is_busy || kalpm_state.is_paused == paused)
{
return;
}
kalpm_state.is_paused = paused;
if (paused)
{
debug ("pausing: disable next auto-checks; update icon");
/* remove auto-check timeout */
if (kalpm_state.timeout > 0)
{
g_source_remove (kalpm_state.timeout);
kalpm_state.timeout = 0;
}
/* determine whether the icon is active or not to update it properly */
gint nb_upgrades;
nb_upgrades = (kalpm_state.nb_upgrades == UPGRADES_NB_CONFLICT)
? 1 : kalpm_state.nb_upgrades;
set_status_icon (nb_upgrades + kalpm_state.nb_watched
+ kalpm_state.nb_aur + kalpm_state.nb_watched_aur
+ kalpm_state.nb_news > 0);
#ifdef ENABLE_STATUS_NOTIFIER
sn_upd_status (nb_upgrades + kalpm_state.nb_watched
+ kalpm_state.nb_aur + kalpm_state.nb_watched_aur
+ kalpm_state.nb_news > 0);
sn_refresh_tooltip ();
#endif
}
else
{
debug ("resuming: starting auto-checks");
kalu_check (TRUE);
}
}
static void
menu_check_cb (GtkMenuItem *item _UNUSED_, gpointer data _UNUSED_)
{
kalu_check (FALSE);
}
static void
menu_pause_cb (GtkMenuItem *item _UNUSED_, gpointer data _UNUSED_)
{
set_pause (!kalpm_state.is_paused);
}
static void
menu_quit_cb (GtkMenuItem *item _UNUSED_, gpointer data _UNUSED_)
{
/* in case e.g. the menu was shown (sensitive) before an auto-check started */
if (kalpm_state.is_busy)
{
return;
}
gtk_main_quit ();
}
static void
menu_manage_cb (GtkMenuItem *item _UNUSED_, gboolean is_aur)
{
watched_manage (is_aur);
}
static inline void
kalu_sysupgrade (void)
{
/* in case e.g. the menu was shown (sensitive) before an auto-check started */
if (kalpm_state.is_busy || config->action == UPGRADE_NO_ACTION)
{
return;
}
#ifndef DISABLE_UPDATER
if (config->action == UPGRADE_ACTION_KALU)
{
run_updater ();
}
else /* if (config->action == UPGRADE_ACTION_CMDLINE) */
{
#endif
/* run in a separate thread, to not block/make GUI unresponsive */
g_thread_unref (g_thread_try_new ("cmd_sysupgrade",
(GThreadFunc) run_cmdline,
(gpointer) config->cmdline,
NULL));
#ifndef DISABLE_UPDATER
}
#endif
}
static void
menu_news_cb (GtkMenuItem *item _UNUSED_, gpointer data)
{
GError *error = NULL;
gboolean unread_only = GPOINTER_TO_INT (data);
/* in case e.g. the menu was shown (sensitive) before an auto-check started */
if (kalpm_state.is_busy)
{
return;
}
set_kalpm_busy (TRUE);
if (!news_show (NULL, unread_only, &error))
{
show_error (_("Unable to show the recent Arch Linux news"),
error->message, NULL);
g_clear_error (&error);
}
}
static void
menu_help_cb (GtkMenuItem *item _UNUSED_, gpointer data _UNUSED_)
{
GError *error = NULL;
if (!show_help (&error))
{
show_error (_("Unable to show help"), error->message, NULL);
g_clear_error (&error);
}
}
static void
menu_history_cb (GtkMenuItem *item _UNUSED_, gpointer data _UNUSED_)
{
GError *error = NULL;
if (!show_history (&error))
{
show_error (_("Unable to show change log"), error->message, NULL);
g_clear_error (&error);
}
}
static void
menu_prefs_cb (GtkMenuItem *item _UNUSED_, gpointer data _UNUSED_)
{
show_prefs ();
}
extern const void *_binary_kalu_logo_start;
extern const void *_binary_kalu_logo_size;
static void
menu_about_cb (GtkMenuItem *item _UNUSED_, gpointer data _UNUSED_)
{
GtkAboutDialog *about;
GInputStream *stream;
GdkPixbuf *pixbuf;
const char *authors[] = {
"Olivier Brunel", "Dave Gamble", "Pacman Development Team",
NULL };
const char *artists[] = { "Painless Rob", NULL };
about = GTK_ABOUT_DIALOG (gtk_about_dialog_new ());
stream = g_memory_input_stream_new_from_data (
&_binary_kalu_logo_start,
(gssize) &_binary_kalu_logo_size,
NULL);
pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
g_object_unref (G_OBJECT (stream));
gtk_window_set_icon (GTK_WINDOW (about), pixbuf);
gtk_about_dialog_set_logo (about, pixbuf);
g_object_unref (G_OBJECT (pixbuf));
gtk_about_dialog_set_program_name (about, PACKAGE_NAME);
gtk_about_dialog_set_version (about, PACKAGE_VERSION);
gtk_about_dialog_set_comments (about, PACKAGE_TAG);
gtk_about_dialog_set_website (about, "http://jjacky.com/kalu");
gtk_about_dialog_set_website_label (about, "http://jjacky.com/kalu");
gtk_about_dialog_set_copyright (about, "Copyright (C) 2012-2014 Olivier Brunel");
gtk_about_dialog_set_license_type (about, GTK_LICENSE_GPL_3_0);
gtk_about_dialog_set_authors (about, authors);
gtk_about_dialog_set_artists (about, artists);
/* TRANSLATORS: Put your name here to get credit on the About window */
gtk_about_dialog_set_translator_credits (about, _("translator-credits"));
gtk_dialog_run (GTK_DIALOG (about));
gtk_widget_destroy (GTK_WIDGET (about));
}
static gboolean
menu_unmap_cb (GtkWidget *menu, GdkEvent *event _UNUSED_, gpointer data _UNUSED_)
{
gtk_widget_destroy (menu);
g_object_unref (menu);
return TRUE;
}
void
#ifdef ENABLE_STATUS_NOTIFIER
icon_popup_cb (StatusNotifier *_sn _UNUSED_, gint x _UNUSED_, gint y _UNUSED_,
gpointer data _UNUSED_)
#else
icon_popup_cb (GtkStatusIcon *_icon _UNUSED_, guint button, guint activate_time,
gpointer data _UNUSED_)
#endif
{
GtkWidget *menu;
GtkWidget *item;
GtkWidget *image;
guint pos = 0;
menu = gtk_menu_new ();
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Re-show last notifications..."));
gtk_widget_set_sensitive (item, !kalpm_state.is_busy && config->last_notifs);
image = gtk_image_new_from_icon_name ("edit-redo", GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_tooltip_text (item,
_("Show notifications from last ran checks"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (show_last_notifs), NULL);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label ((kalpm_state.is_paused)
? _c("systray-menu", "Resume automatic checks")
: _c("systray-menu", "Pause automatic checks"));
gtk_widget_set_sensitive (item, !kalpm_state.is_busy);
image = gtk_image_new_from_icon_name ((kalpm_state.is_paused)
? "media-playback-start"
: "media-playback-pause",
GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_tooltip_text (item, (kalpm_state.is_paused)
? _("Resume automatic checks (starting now)")
: _("Pause automatic checks (until resumed)"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_pause_cb), NULL);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Check for Upgrades..."));
gtk_widget_set_sensitive (item, !kalpm_state.is_busy);
image = gtk_image_new_from_icon_name ("kalu", GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_tooltip_text (item,
_("Check if there are any upgrades available"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_check_cb), NULL);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
#ifndef DISABLE_UPDATER
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Upgrade simulation..."));
gtk_widget_set_sensitive (item, !kalpm_state.is_busy);
image = gtk_image_new_from_icon_name ("kalu", GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_tooltip_text (item, _("Run a system upgrade simulation "
"(to preview/help deal with conflicts)"));
g_signal_connect_swapped (G_OBJECT (item), "activate",
G_CALLBACK (run_simulation), NULL);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
#endif
if (config->action != UPGRADE_NO_ACTION)
{
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "System upgrade..."));
gtk_widget_set_sensitive (item, !kalpm_state.is_busy);
image = gtk_image_new_from_icon_name ("kalu", GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_tooltip_text (item, _("Perform a system upgrade"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (kalu_sysupgrade), NULL);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
}
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Show unread Arch Linux news..."));
gtk_widget_set_sensitive (item, !kalpm_state.is_busy);
image = gtk_image_new_from_icon_name ("kalu", GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_tooltip_text (item, _("Show only unread Arch Linux news"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_news_cb), GINT_TO_POINTER (1));
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Show recent Arch Linux news..."));
gtk_widget_set_sensitive (item, !kalpm_state.is_busy);
image = gtk_image_new_from_icon_name ("kalu", GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_tooltip_text (item, _("Show most recent Arch Linux news"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_news_cb), GINT_TO_POINTER (0));
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Manage watched packages..."));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_manage_cb), (gpointer) FALSE);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Manage watched AUR packages..."));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_manage_cb), (gpointer) TRUE);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Preferences"));
image = gtk_image_new_from_icon_name ("preferences-desktop", GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_tooltip_text (item, _("Edit preferences"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_prefs_cb), NULL);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Help"));
image = gtk_image_new_from_icon_name ("help-contents", GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_tooltip_text (item, _("Show help (man page)"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_help_cb), NULL);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Change log"));
gtk_widget_set_tooltip_text (item, _("Show change log"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_history_cb), (gpointer) TRUE);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "About"));
image = gtk_image_new_from_icon_name ("help-about", GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_tooltip_text (item,
_("Show Copyright & version information"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_about_cb), NULL);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
item = donna_image_menu_item_new_with_label (
_c("systray-menu", "Quit"));
image = gtk_image_new_from_icon_name ("application-exit", GTK_ICON_SIZE_MENU);
donna_image_menu_item_set_image (DONNA_IMAGE_MENU_ITEM (item), image);
gtk_widget_set_sensitive (item, !kalpm_state.is_busy);
gtk_widget_set_tooltip_text (item, _("Exit kalu"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (menu_quit_cb), NULL);
gtk_widget_show (item);
gtk_menu_attach (GTK_MENU (menu), item, 0, 1, pos, pos + 1); ++pos;
/* since we don't pack the menu anywhere, we need to "take ownership" of it,
* and we'll destroy it when done, i.e. when it's unmapped */
g_object_ref_sink (menu);
gtk_widget_add_events (menu, GDK_STRUCTURE_MASK);
g_signal_connect (G_OBJECT (menu), "unmap-event",
G_CALLBACK (menu_unmap_cb), NULL);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
#ifdef ENABLE_STATUS_NOTIFIER
0, gtk_get_current_event_time ()
#else
button, activate_time
#endif
);
}
void
process_fifo_command (const gchar *command)
{
if (streq (command, "run-checks") || streq (command, "manual-checks"))
kalu_check (FALSE);
else if (streq (command, "auto-checks"))
kalu_check (TRUE);
else if (streq (command, "show-last-notifs"))
show_last_notifs ();
else if (streq (command, "toggle-pause"))
set_pause (!kalpm_state.is_paused);
else if (streq (command, "sysupgrade"))
kalu_sysupgrade ();
else if (streq (command, "show-unread-news"))
menu_news_cb (NULL, GINT_TO_POINTER (1));
else if (streq (command, "show-recent-news"))
menu_news_cb (NULL, NULL);
else if (streq (command, "popup-menu"))
icon_popup_cb (NULL, 1, GDK_CURRENT_TIME, NULL);
#ifndef DISABLE_UPDATER
else if (streq (command, "run-simulation"))
run_simulation (NULL);
#endif
else
show_error (_("kalu received an unknown FIFO command"), command, NULL);
}
GPtrArray *open_windows = NULL;
static gboolean has_hidden_windows = FALSE;
void
add_open_window (gpointer window)
{
if (!open_windows)
{
open_windows = g_ptr_array_new ();
}
g_ptr_array_add (open_windows, window);
}
void
remove_open_window (gpointer window)
{
g_ptr_array_remove (open_windows, window);
}