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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
|
diff -up gnome-panel-2.22.0/gnome-panel/Makefile.am.ck-shutdown gnome-panel-2.22.0/gnome-panel/Makefile.am
--- gnome-panel-2.22.0/gnome-panel/Makefile.am.ck-shutdown 2008-03-10 16:44:57.000000000 -0400
+++ gnome-panel-2.22.0/gnome-panel/Makefile.am 2008-04-05 20:48:37.000000000 -0400
@@ -16,6 +16,7 @@ INCLUDES = \
$(STANDARD_PROPERTIES_CFLAGS) \
$(PANEL_CFLAGS) \
$(PANELCONFIG_CFLAGS) \
+ $(POLKIT_GNOME_CFLAGS) \
$(WARN_CFLAGS) \
$(NULL)
@@ -98,6 +99,7 @@ panel_sources = \
panel-logout.c \
panel-gdm.c \
panel-power-manager.c \
+ panel-consolekit.c \
panel-ditem-editor.c \
panel-mount-operation.c \
$(NULL)
@@ -148,6 +150,7 @@ panel_headers = \
panel-logout.h \
panel-gdm.h \
panel-power-manager.h \
+ panel-consolekit.h \
panel-ditem-editor.h \
panel-icon-names.h \
panel-mount-operation.h \
@@ -161,6 +164,7 @@ gnome_panel_SOURCES = \
gnome_panel_LDADD = \
$(PANEL_LIBS) \
+ $(POLKIT_GNOME_LIBS) \
$(X_LIBS)
gnome_panel_LDFLAGS = -export-dynamic
diff -up gnome-panel-2.22.0/gnome-panel/panel-action-button.c.ck-shutdown gnome-panel-2.22.0/gnome-panel/panel-action-button.c
--- gnome-panel-2.22.0/gnome-panel/panel-action-button.c.ck-shutdown 2008-04-05 20:48:37.000000000 -0400
+++ gnome-panel-2.22.0/gnome-panel/panel-action-button.c 2008-04-05 20:48:37.000000000 -0400
@@ -46,7 +46,6 @@
#include "panel-lockdown.h"
#include "panel-logout.h"
#include "panel-compatibility.h"
-#include "panel-gdm.h"
#include "panel-icon-names.h"
G_DEFINE_TYPE (PanelActionButton, panel_action_button, BUTTON_TYPE_WIDGET);
@@ -183,8 +182,7 @@ static gboolean
panel_action_shutdown_reboot_is_disabled (void)
{
return (panel_lockdown_get_disable_log_out() ||
- (!gdm_supports_logout_action (GDM_LOGOUT_ACTION_SHUTDOWN) &&
- !gdm_supports_logout_action (GDM_LOGOUT_ACTION_REBOOT)));
+ !panel_logout_supports_shutdown_reboot ());
}
/* Run Application
diff -up /dev/null gnome-panel-2.22.0/gnome-panel/panel-consolekit.c
--- /dev/null 2008-04-05 22:04:35.194004710 -0400
+++ gnome-panel-2.22.0/gnome-panel/panel-consolekit.c 2008-04-05 20:48:37.000000000 -0400
@@ -0,0 +1,682 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Jon McCann <jmccann@redhat.com>
+ *
+ * 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 2, 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+#include <dbus/dbus-glib.h>
+
+#ifdef HAVE_POLKIT
+#include <polkit-gnome/polkit-gnome.h>
+#endif
+
+#include "panel-consolekit.h"
+
+#define CK_NAME "org.freedesktop.ConsoleKit"
+#define CK_PATH "/org/freedesktop/ConsoleKit"
+#define CK_INTERFACE "org.freedesktop.ConsoleKit"
+
+#define CK_MANAGER_PATH "/org/freedesktop/ConsoleKit/Manager"
+#define CK_MANAGER_INTERFACE "org.freedesktop.ConsoleKit.Manager"
+#define CK_SEAT_INTERFACE "org.freedesktop.ConsoleKit.Seat"
+#define CK_SESSION_INTERFACE "org.freedesktop.ConsoleKit.Session"
+
+#define PANEL_CONSOLEKIT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_CONSOLEKIT, PanelConsolekitPrivate))
+
+struct _PanelConsolekitPrivate {
+ DBusGConnection *dbus_connection;
+ DBusGProxy *bus_proxy;
+ DBusGProxy *ck_proxy;
+ guint32 is_connected : 1;
+};
+
+enum {
+ PROP_0 = 0,
+ PROP_IS_CONNECTED
+};
+
+enum {
+ REQUEST_COMPLETED = 0,
+ LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL];
+
+static void panel_consolekit_class_init (PanelConsolekitClass *klass);
+static void panel_consolekit_init (PanelConsolekit *ck);
+static void panel_consolekit_finalize (GObject *object);
+static void panel_consolekit_on_name_owner_changed (DBusGProxy *bus_proxy,
+ const char *name,
+ const char *prev_owner,
+ const char *new_owner,
+ PanelConsolekit *manager);
+
+G_DEFINE_TYPE (PanelConsolekit, panel_consolekit, G_TYPE_OBJECT);
+
+static void
+panel_consolekit_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PanelConsolekit *manager = PANEL_CONSOLEKIT (object);
+
+ switch (prop_id) {
+ case PROP_IS_CONNECTED:
+ g_value_set_boolean (value,
+ manager->priv->is_connected);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
+ prop_id,
+ pspec);
+ }
+}
+
+static void
+panel_consolekit_class_init (PanelConsolekitClass *manager_class)
+{
+ GObjectClass *object_class;
+ GParamSpec *param_spec;
+
+ object_class = G_OBJECT_CLASS (manager_class);
+
+ object_class->finalize = panel_consolekit_finalize;
+ object_class->get_property = panel_consolekit_get_property;
+
+ param_spec = g_param_spec_boolean ("is-connected",
+ "Is connected",
+ "Whether the panel is connected to ConsoleKit",
+ FALSE,
+ G_PARAM_READABLE);
+ g_object_class_install_property (object_class, PROP_IS_CONNECTED,
+ param_spec);
+
+ signals [REQUEST_COMPLETED] =
+ g_signal_new ("request-completed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PanelConsolekitClass, request_completed),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1, G_TYPE_POINTER);
+
+ g_type_class_add_private (manager_class,
+ sizeof (PanelConsolekitPrivate));
+}
+
+static gboolean
+panel_consolekit_ensure_ck_connection (PanelConsolekit *manager,
+ GError **error)
+{
+ GError *connection_error;
+ gboolean is_connected;
+
+ connection_error = NULL;
+ if (manager->priv->dbus_connection == NULL) {
+ manager->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM,
+ &connection_error);
+
+ if (manager->priv->dbus_connection == NULL) {
+ g_propagate_error (error, connection_error);
+ is_connected = FALSE;
+ goto out;
+ }
+ }
+
+ if (manager->priv->bus_proxy == NULL) {
+ manager->priv->bus_proxy =
+ dbus_g_proxy_new_for_name_owner (manager->priv->dbus_connection,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ &connection_error);
+
+ if (manager->priv->bus_proxy == NULL) {
+ g_propagate_error (error, connection_error);
+ is_connected = FALSE;
+ goto out;
+ }
+
+ dbus_g_proxy_add_signal (manager->priv->bus_proxy,
+ "NameOwnerChanged",
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal (manager->priv->bus_proxy,
+ "NameOwnerChanged",
+ G_CALLBACK (panel_consolekit_on_name_owner_changed),
+ manager, NULL);
+ }
+
+ if (manager->priv->ck_proxy == NULL) {
+ manager->priv->ck_proxy =
+ dbus_g_proxy_new_for_name_owner (manager->priv->dbus_connection,
+ "org.freedesktop.ConsoleKit",
+ "/org/freedesktop/ConsoleKit/Manager",
+ "org.freedesktop.ConsoleKit.Manager",
+ &connection_error);
+
+ if (manager->priv->ck_proxy == NULL) {
+ g_propagate_error (error, connection_error);
+ is_connected = FALSE;
+ goto out;
+ }
+ }
+ is_connected = TRUE;
+
+out:
+ if (manager->priv->is_connected != is_connected) {
+ manager->priv->is_connected = is_connected;
+ g_object_notify (G_OBJECT (manager), "is-connected");
+ }
+
+ if (!is_connected) {
+ if (manager->priv->dbus_connection == NULL) {
+ if (manager->priv->bus_proxy != NULL) {
+ g_object_unref (manager->priv->bus_proxy);
+ manager->priv->bus_proxy = NULL;
+ }
+
+ if (manager->priv->ck_proxy != NULL) {
+ g_object_unref (manager->priv->ck_proxy);
+ manager->priv->ck_proxy = NULL;
+ }
+ } else if (manager->priv->bus_proxy == NULL) {
+ if (manager->priv->ck_proxy != NULL) {
+ g_object_unref (manager->priv->ck_proxy);
+ manager->priv->ck_proxy = NULL;
+ }
+ }
+ }
+
+ return is_connected;
+}
+
+static void
+panel_consolekit_on_name_owner_changed (DBusGProxy *bus_proxy,
+ const char *name,
+ const char *prev_owner,
+ const char *new_owner,
+ PanelConsolekit *manager)
+{
+ if (name != NULL && strcmp (name, "org.freedesktop.ConsoleKit") != 0)
+ return;
+
+ if (manager->priv->ck_proxy != NULL) {
+ g_object_unref (manager->priv->ck_proxy);
+ manager->priv->ck_proxy = NULL;
+ }
+
+ panel_consolekit_ensure_ck_connection (manager, NULL);
+}
+
+static void
+panel_consolekit_init (PanelConsolekit *manager)
+{
+ GError *error;
+
+ manager->priv = PANEL_CONSOLEKIT_GET_PRIVATE (manager);
+
+ error = NULL;
+ if (!panel_consolekit_ensure_ck_connection (manager, &error)) {
+ g_message ("Could not connect to ConsoleKit: %s",
+ error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+panel_consolekit_finalize (GObject *object)
+{
+ PanelConsolekit *manager;
+ GObjectClass *parent_class;
+
+ manager = PANEL_CONSOLEKIT (object);
+
+ parent_class = G_OBJECT_CLASS (panel_consolekit_parent_class);
+
+ if (manager->priv->bus_proxy != NULL) {
+ g_object_unref (manager->priv->bus_proxy);
+ }
+
+ if (manager->priv->ck_proxy != NULL) {
+ g_object_unref (manager->priv->ck_proxy);
+ }
+
+ if (parent_class->finalize != NULL)
+ parent_class->finalize (object);
+}
+
+GQuark
+panel_consolekit_error_quark (void)
+{
+ static GQuark error_quark = 0;
+
+ if (error_quark == 0)
+ error_quark = g_quark_from_static_string ("panel-consolekit-error");
+
+ return error_quark;
+}
+
+PanelConsolekit *
+panel_consolekit_new (void)
+{
+ PanelConsolekit *manager;
+
+ manager = g_object_new (PANEL_TYPE_CONSOLEKIT, NULL);
+
+ return manager;
+}
+
+static gboolean
+try_system_stop (DBusGConnection *connection,
+ GError **error)
+{
+ DBusGProxy *proxy;
+ gboolean res;
+
+ proxy = dbus_g_proxy_new_for_name (connection,
+ CK_NAME,
+ CK_MANAGER_PATH,
+ CK_MANAGER_INTERFACE);
+ res = dbus_g_proxy_call_with_timeout (proxy,
+ "Stop",
+ INT_MAX,
+ error,
+ /* parameters: */
+ G_TYPE_INVALID,
+ /* return values: */
+ G_TYPE_INVALID);
+ return res;
+}
+
+static gboolean
+try_system_restart (DBusGConnection *connection,
+ GError **error)
+{
+ DBusGProxy *proxy;
+ gboolean res;
+
+ proxy = dbus_g_proxy_new_for_name (connection,
+ CK_NAME,
+ CK_MANAGER_PATH,
+ CK_MANAGER_INTERFACE);
+ res = dbus_g_proxy_call_with_timeout (proxy,
+ "Restart",
+ INT_MAX,
+ error,
+ /* parameters: */
+ G_TYPE_INVALID,
+ /* return values: */
+ G_TYPE_INVALID);
+ return res;
+}
+
+static void
+emit_restart_complete (PanelConsolekit *manager,
+ const char *error_message)
+{
+ GError *call_error;
+
+ call_error = NULL;
+
+ if (error_message != NULL) {
+ call_error = g_error_new_literal (PANEL_CONSOLEKIT_ERROR,
+ PANEL_CONSOLEKIT_ERROR_RESTARTING,
+ error_message);
+ }
+
+ g_signal_emit (G_OBJECT (manager),
+ signals [REQUEST_COMPLETED],
+ 0, call_error);
+ if (call_error != NULL) {
+ g_error_free (call_error);
+ }
+}
+
+static void
+emit_stop_complete (PanelConsolekit *manager,
+ GError *error)
+{
+ GError *call_error;
+
+ call_error = NULL;
+
+ if (error != NULL) {
+ call_error = g_error_new_literal (PANEL_CONSOLEKIT_ERROR,
+ PANEL_CONSOLEKIT_ERROR_STOPPING,
+ error->message);
+ }
+
+ g_signal_emit (G_OBJECT (manager),
+ signals [REQUEST_COMPLETED],
+ 0, call_error);
+ if (call_error != NULL) {
+ g_error_free (call_error);
+ }
+}
+
+#ifdef HAVE_POLKIT
+static void
+system_restart_auth_cb (PolKitAction *action,
+ gboolean gained_privilege,
+ GError *error,
+ PanelConsolekit *manager)
+{
+ GError *local_error;
+ gboolean res;
+
+ if (! gained_privilege) {
+ if (error != NULL) {
+ emit_restart_complete (manager, error->message);
+ }
+ return;
+ }
+
+ local_error = NULL;
+ res = try_system_restart (manager->priv->dbus_connection, &local_error);
+ if (! res) {
+ g_warning ("Unable to restart system: %s", local_error->message);
+ emit_restart_complete (manager, local_error->message);
+ g_error_free (local_error);
+ return;
+ }
+}
+
+static void
+system_stop_auth_cb (PolKitAction *action,
+ gboolean gained_privilege,
+ GError *error,
+ PanelConsolekit *manager)
+{
+ GError *local_error;
+ gboolean res;
+
+ if (! gained_privilege) {
+ if (error != NULL) {
+ emit_stop_complete (manager, error);
+ }
+ return;
+ }
+
+ local_error = NULL;
+ res = try_system_stop (manager->priv->dbus_connection, &local_error);
+ if (! res) {
+ g_warning ("Unable to stop system: %s", local_error->message);
+ emit_stop_complete (manager, local_error);
+ g_error_free (local_error);
+ return;
+ }
+}
+
+static PolKitAction *
+get_action_from_error (GError *error)
+{
+ PolKitAction *action;
+ char *paction;
+ char *p;
+
+ action = polkit_action_new ();
+
+ paction = NULL;
+ if (g_str_has_prefix (error->message, "Not privileged for action: ")) {
+ paction = g_strdup (error->message + strlen ("Not privileged for action: "));
+ p = strchr (paction, ' ');
+ if (p)
+ *p = '\0';
+ }
+ polkit_action_set_action_id (action, paction);
+
+ g_free (paction);
+
+ return action;
+}
+
+static PolKitResult
+get_result_from_error (GError *error)
+{
+ PolKitResult result = POLKIT_RESULT_UNKNOWN;
+ const char *p;
+
+ p = strrchr (error->message, ' ');
+ if (p) {
+ p++;
+ polkit_result_from_string_representation (p, &result);
+ }
+
+ return result;
+}
+
+#endif /* HAVE_POLKIT */
+
+static void
+request_restart_priv (PanelConsolekit *manager,
+ GError *error)
+{
+#ifdef HAVE_POLKIT
+ gboolean res = FALSE;
+ char *error_message = NULL;
+ PolKitAction *action;
+ PolKitAction *action2;
+ PolKitResult result;
+ guint xid;
+ pid_t pid;
+ GError *local_error;
+
+ action = get_action_from_error (error);
+ result = get_result_from_error (error);
+
+ if (result == POLKIT_RESULT_NO) {
+ action2 = polkit_action_new ();
+ polkit_action_set_action_id (action2, "org.freedesktop.consolekit.system.restart-multiple-users");
+ if (polkit_action_equal (action, action2)) {
+ emit_restart_complete (manager, _("You are not allowed to restart the computer "
+ "because multiple users are logged in"));
+ }
+ else {
+ emit_restart_complete (manager, _("You are not allowed to restart the computer"));
+ }
+ polkit_action_unref (action);
+ polkit_action_unref (action2);
+
+ return;
+ }
+
+
+ xid = 0;
+ pid = getpid ();
+
+ local_error = NULL;
+ res = polkit_gnome_auth_obtain (action,
+ xid,
+ pid,
+ (PolKitGnomeAuthCB) system_restart_auth_cb,
+ manager,
+ &local_error);
+ polkit_action_unref (action);
+ if (local_error != NULL) {
+ error_message = g_strdup (local_error->message);
+ g_error_free (local_error);
+ }
+
+ if (! res) {
+ emit_restart_complete (manager, error_message);
+ g_free (error_message);
+ }
+#else
+ g_assert_not_reached ();
+#endif /* HAVE POLKIT */
+}
+
+static void
+request_stop_priv (PanelConsolekit *manager,
+ GError *error)
+{
+#ifdef HAVE_POLKIT
+ gboolean res = FALSE;
+ char *error_message = NULL;
+ PolKitAction *action;
+ PolKitAction *action2;
+ PolKitResult result;
+ guint xid;
+ pid_t pid;
+ GError *local_error;
+
+ result = get_result_from_error (error);
+ action = get_action_from_error (error);
+
+ if (result == POLKIT_RESULT_NO) {
+ action2 = polkit_action_new ();
+ polkit_action_set_action_id (action2, "org.freedesktop.consolekit.system.stop-multiple-users");
+ if (polkit_action_equal (action, action2)) {
+ emit_restart_complete (manager, _("You are not allowed to stop the computer "
+ "because multiple users are logged in"));
+ }
+ else {
+ emit_restart_complete (manager, _("You are not allowed to stop the computer"));
+ }
+ polkit_action_unref (action);
+ polkit_action_unref (action2);
+
+ return;
+ }
+
+ xid = 0;
+ pid = getpid ();
+
+ xid = 0;
+ pid = getpid ();
+
+ local_error = NULL;
+ res = polkit_gnome_auth_obtain (action,
+ xid,
+ pid,
+ (PolKitGnomeAuthCB) system_stop_auth_cb,
+ manager,
+ &local_error);
+ polkit_action_unref (action);
+ if (local_error != NULL) {
+ error_message = g_strdup (local_error->message);
+ g_error_free (local_error);
+ }
+ if (! res) {
+ emit_stop_complete (manager, error_message);
+ g_free (error_message);
+ }
+#else
+ g_assert_not_reached ();
+#endif /* HAVE POLKIT */
+}
+
+void
+panel_consolekit_attempt_restart (PanelConsolekit *manager)
+{
+ gboolean res;
+ GError *error;
+
+ error = NULL;
+
+ if (!panel_consolekit_ensure_ck_connection (manager, &error)) {
+ g_warning ("Could not connect to ConsoleKit: %s",
+ error->message);
+ g_error_free (error);
+ return;
+ }
+
+ res = try_system_restart (manager->priv->dbus_connection, &error);
+ if (! res) {
+ if (dbus_g_error_has_name (error, "org.freedesktop.ConsoleKit.Manager.NotPrivileged")) {
+ request_restart_priv (manager, error);
+ } else {
+ emit_restart_complete (manager, error);
+ }
+ g_error_free (error);
+ }
+}
+
+void
+panel_consolekit_attempt_stop (PanelConsolekit *manager)
+{
+ gboolean res;
+ GError *error;
+
+ error = NULL;
+
+ if (!panel_consolekit_ensure_ck_connection (manager, &error)) {
+ g_warning ("Could not connect to ConsoleKit: %s",
+ error->message);
+ g_error_free (error);
+ return;
+ }
+
+ res = try_system_stop (manager->priv->dbus_connection, &error);
+ if (! res) {
+ if (dbus_g_error_has_name (error, "org.freedesktop.ConsoleKit.Manager.NotPrivileged")) {
+ request_stop_priv (manager, error);
+ } else {
+ emit_stop_complete (manager, error);
+ }
+ g_error_free (error);
+ }
+}
+
+gboolean
+panel_consolekit_can_restart (PanelConsolekit *manager)
+{
+#ifdef HAVE_POLKIT
+ return panel_consolekit_ensure_ck_connection (manager, NULL);
+#else
+ return FALSE;
+#endif
+}
+
+gboolean
+panel_consolekit_can_stop (PanelConsolekit *manager)
+{
+#ifdef HAVE_POLKIT
+ return panel_consolekit_ensure_ck_connection (manager, NULL);
+#else
+ return FALSE;
+#endif
+}
+
+PanelConsolekit *
+panel_get_consolekit (void)
+{
+ static PanelConsolekit *manager = NULL;
+
+ if (manager == NULL) {
+ manager = panel_consolekit_new ();
+ }
+
+ return g_object_ref (manager);
+}
diff -up /dev/null gnome-panel-2.22.0/gnome-panel/panel-consolekit.h
--- /dev/null 2008-04-05 22:04:35.194004710 -0400
+++ gnome-panel-2.22.0/gnome-panel/panel-consolekit.h 2008-04-05 20:48:37.000000000 -0400
@@ -0,0 +1,77 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Jon McCann <jmccann@redhat.com>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ * Jon McCann <jmccann@redhat.com>
+ */
+
+#ifndef PANEL_CONSOLEKIT_H
+#define PANEL_CONSOLEKIT_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PANEL_TYPE_CONSOLEKIT (panel_consolekit_get_type ())
+#define PANEL_CONSOLEKIT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_CONSOLEKIT, PanelConsolekit))
+#define PANEL_CONSOLEKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_CONSOLEKIT, PanelConsolekitClass))
+#define PANEL_IS_CONSOLEKIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_CONSOLEKIT))
+#define PANEL_IS_CONSOLEKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_CONSOLEKIT))
+#define PANEL_CONSOLEKIT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_CONSOLEKIT, PanelConsolekitClass))
+#define PANEL_CONSOLEKIT_ERROR (panel_consolekit_error_quark ())
+
+typedef struct _PanelConsolekit PanelConsolekit;
+typedef struct _PanelConsolekitClass PanelConsolekitClass;
+typedef struct _PanelConsolekitPrivate PanelConsolekitPrivate;
+typedef enum _PanelConsolekitError PanelConsolekitError;
+
+struct _PanelConsolekit {
+ GObject parent;
+ PanelConsolekitPrivate *priv;
+};
+
+struct _PanelConsolekitClass {
+ GObjectClass parent_class;
+
+ void (* request_completed) (PanelConsolekit *manager,
+ GError *error);
+};
+
+enum _PanelConsolekitError {
+ PANEL_CONSOLEKIT_ERROR_RESTARTING = 0,
+ PANEL_CONSOLEKIT_ERROR_STOPPING
+};
+
+GType panel_consolekit_get_type (void);
+GQuark panel_consolekit_error_quark (void);
+
+PanelConsolekit *panel_consolekit_new (void) G_GNUC_MALLOC;
+
+gboolean panel_consolekit_can_stop (PanelConsolekit *manager);
+gboolean panel_consolekit_can_restart (PanelConsolekit *manager);
+
+void panel_consolekit_attempt_stop (PanelConsolekit *manager);
+void panel_consolekit_attempt_restart (PanelConsolekit *manager);
+
+PanelConsolekit *panel_get_consolekit (void);
+
+G_END_DECLS
+
+#endif /* PANEL_CONSOLEKIT_H */
diff -up gnome-panel-2.22.0/gnome-panel/panel-logout.c.ck-shutdown gnome-panel-2.22.0/gnome-panel/panel-logout.c
--- gnome-panel-2.22.0/gnome-panel/panel-logout.c.ck-shutdown 2008-04-05 20:48:37.000000000 -0400
+++ gnome-panel-2.22.0/gnome-panel/panel-logout.c 2008-04-05 22:18:24.000000000 -0400
@@ -1,4 +1,5 @@
-/*
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
* panel-logout.c:
*
* Copyright (C) 2006 Vincent Untz
@@ -35,8 +36,10 @@
#include "panel-logout.h"
#include "panel-gdm.h"
#include "panel-power-manager.h"
+#include "panel-consolekit.h"
#include "panel-session.h"
#include "panel-icon-names.h"
+#include "panel-gconf.h"
#define PANEL_LOGOUT_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_LOGOUT_DIALOG, PanelLogoutDialogPrivate))
@@ -55,6 +58,7 @@ struct _PanelLogoutDialogPrivate {
PanelLogoutDialogType type;
PanelPowerManager *power_manager;
+ PanelConsolekit *consolekit;
int timeout;
unsigned int timeout_id;
@@ -76,7 +80,7 @@ enum {
};
G_DEFINE_TYPE (PanelLogoutDialog, panel_logout, GTK_TYPE_MESSAGE_DIALOG);
-static void
+static void
panel_logout_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -91,7 +95,7 @@ panel_logout_set_property (GObject
}
}
-static void
+static void
panel_logout_get_property (GObject *object,
guint prop_id,
GValue *value,
@@ -130,6 +134,57 @@ panel_logout_class_init (PanelLogoutDial
}
static void
+ck_restart_error_window (GError *error)
+{
+ GtkWidget *dialog;
+ const char *primary;
+
+ g_assert (error != NULL);
+
+ switch (error->code) {
+ case PANEL_CONSOLEKIT_ERROR_RESTARTING:
+ primary = _("Unable to restart system");
+ break;
+ case PANEL_CONSOLEKIT_ERROR_STOPPING:
+ primary = _("Unable to stop system");
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ dialog = gtk_message_dialog_new (NULL, 0,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_NONE,
+ primary);
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", error->message);
+
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ GTK_STOCK_CLOSE,
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+ GTK_RESPONSE_CLOSE);
+ gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
+ gtk_window_set_title (GTK_WINDOW (dialog), "");
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_widget_show (dialog);
+}
+
+static void
+on_ck_request_completed (PanelConsolekit *panel_consolekit,
+ GError *error)
+{
+ if (error) {
+ ck_restart_error_window (error);
+ }
+}
+
+static void
panel_logout_init (PanelLogoutDialog *logout_dialog)
{
logout_dialog->priv = PANEL_LOGOUT_DIALOG_GET_PRIVATE (logout_dialog);
@@ -146,6 +201,10 @@ panel_logout_init (PanelLogoutDialog *lo
GTK_WIN_POS_CENTER_ALWAYS);
logout_dialog->priv->power_manager = panel_get_power_manager ();
+ logout_dialog->priv->consolekit = panel_get_consolekit ();
+ g_signal_connect (logout_dialog->priv->consolekit,
+ "request-completed",
+ G_CALLBACK (on_ck_request_completed), NULL);
g_signal_connect (logout_dialog, "destroy",
G_CALLBACK (panel_logout_destroy), NULL);
@@ -163,37 +222,129 @@ panel_logout_destroy (PanelLogoutDialog
g_object_unref (logout_dialog->priv->power_manager);
logout_dialog->priv->power_manager = NULL;
+ g_object_unref (logout_dialog->priv->consolekit);
+ logout_dialog->priv->consolekit = NULL;
current_dialog = NULL;
}
+static gboolean
+panel_logout_supports_reboot (PanelLogoutDialog *logout_dialog)
+{
+ gboolean ret;
+
+ ret = panel_consolekit_can_restart (logout_dialog->priv->consolekit);
+ if (!ret) {
+ ret = gdm_supports_logout_action (GDM_LOGOUT_ACTION_REBOOT);
+ }
+ return ret;
+}
+
+static gboolean
+panel_logout_supports_shutdown (PanelLogoutDialog *logout_dialog)
+{
+ gboolean ret;
+
+ ret = panel_consolekit_can_stop (logout_dialog->priv->consolekit);
+ if (!ret) {
+ ret = gdm_supports_logout_action (GDM_LOGOUT_ACTION_SHUTDOWN);
+ }
+ return ret;
+}
+
+gboolean
+panel_logout_supports_shutdown_reboot (void)
+{
+ PanelConsolekit *consolekit;
+ gboolean ret;
+
+ ret = FALSE;
+
+ /* if we can do any then return true */
+
+ consolekit = panel_get_consolekit ();
+ if (consolekit != NULL) {
+ ret = panel_consolekit_can_restart (consolekit)
+ || panel_consolekit_can_stop (consolekit);
+ g_object_unref (consolekit);
+ }
+
+ if (!ret) {
+ ret = gdm_supports_logout_action (GDM_LOGOUT_ACTION_REBOOT)
+ || gdm_supports_logout_action (GDM_LOGOUT_ACTION_SHUTDOWN);
+ }
+
+ return ret;
+}
+
+static void
+do_request_logout (PanelConsolekit *consolekit)
+{
+ gdm_set_logout_action (GDM_LOGOUT_ACTION_NONE);
+ panel_session_request_logout ();
+}
+
+static void
+maybe_request_session_save (void)
+{
+ if (gconf_client_get_bool (panel_gconf_get_client (),
+ "/apps/gnome-session/options/auto_save_session",
+ NULL))
+ panel_session_request_save ();
+}
+
+static void
+do_request_reboot (PanelConsolekit *consolekit)
+{
+ if (panel_consolekit_can_restart (consolekit)) {
+ gdm_set_logout_action (GDM_LOGOUT_ACTION_NONE);
+ maybe_request_session_save ();
+ panel_consolekit_attempt_restart (consolekit);
+ } else {
+ gdm_set_logout_action (GDM_LOGOUT_ACTION_REBOOT);
+ panel_session_request_logout ();
+ }
+}
+
+static void
+do_request_shutdown (PanelConsolekit *consolekit)
+{
+ if (panel_consolekit_can_stop (consolekit)) {
+ gdm_set_logout_action (GDM_LOGOUT_ACTION_NONE);
+ maybe_request_session_save ();
+ panel_consolekit_attempt_stop (consolekit);
+ } else {
+ gdm_set_logout_action (GDM_LOGOUT_ACTION_SHUTDOWN);
+ panel_session_request_logout ();
+ }
+}
+
static void
panel_logout_response (PanelLogoutDialog *logout_dialog,
guint response_id,
gpointer data)
{
PanelPowerManager *power_manager;
+ PanelConsolekit *consolekit;
power_manager = g_object_ref (logout_dialog->priv->power_manager);
+ consolekit = g_object_ref (logout_dialog->priv->consolekit);
gtk_widget_destroy (GTK_WIDGET (logout_dialog));
switch (response_id) {
case GTK_RESPONSE_CANCEL:
break;
case PANEL_LOGOUT_RESPONSE_LOGOUT:
- gdm_set_logout_action (GDM_LOGOUT_ACTION_NONE);
- panel_session_request_logout ();
+ do_request_logout (consolekit);
break;
case PANEL_LOGOUT_RESPONSE_SWITCH_USER:
gdm_new_login ();
break;
case PANEL_LOGOUT_RESPONSE_SHUTDOWN:
- gdm_set_logout_action (GDM_LOGOUT_ACTION_SHUTDOWN);
- panel_session_request_logout ();
+ do_request_shutdown (consolekit);
break;
case PANEL_LOGOUT_RESPONSE_REBOOT:
- gdm_set_logout_action (GDM_LOGOUT_ACTION_REBOOT);
- panel_session_request_logout ();
+ do_request_reboot (consolekit);
break;
case PANEL_LOGOUT_RESPONSE_STD:
if (panel_power_manager_can_hibernate (power_manager))
@@ -210,6 +361,7 @@ panel_logout_response (PanelLogoutDialog
g_assert_not_reached ();
}
g_object_unref (power_manager);
+ g_object_unref (consolekit);
}
static gboolean
@@ -363,7 +515,7 @@ panel_logout_new (PanelLogoutDialogType
_("_Hibernate"),
PANEL_LOGOUT_RESPONSE_STD);
- if (gdm_supports_logout_action (GDM_LOGOUT_ACTION_REBOOT))
+ if (panel_logout_supports_reboot (logout_dialog))
gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
_("_Restart"),
PANEL_LOGOUT_RESPONSE_REBOOT);
@@ -372,7 +524,7 @@ panel_logout_new (PanelLogoutDialogType
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
- if (gdm_supports_logout_action (GDM_LOGOUT_ACTION_SHUTDOWN))
+ if (panel_logout_supports_shutdown (logout_dialog))
gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
_("_Shut Down"),
PANEL_LOGOUT_RESPONSE_SHUTDOWN);
diff -up gnome-panel-2.22.0/gnome-panel/panel-logout.h.ck-shutdown gnome-panel-2.22.0/gnome-panel/panel-logout.h
--- gnome-panel-2.22.0/gnome-panel/panel-logout.h.ck-shutdown 2008-03-10 16:44:57.000000000 -0400
+++ gnome-panel-2.22.0/gnome-panel/panel-logout.h 2008-04-05 20:48:37.000000000 -0400
@@ -57,6 +57,8 @@ struct _PanelLogoutDialogClass {
GType panel_logout_get_type (void) G_GNUC_CONST;
+gboolean panel_logout_supports_shutdown_reboot (void);
+
void panel_logout_new (PanelLogoutDialogType type,
GdkScreen *screen,
guint32 activate_time);
diff -up gnome-panel-2.22.0/gnome-panel/panel-session.c.ck-shutdown gnome-panel-2.22.0/gnome-panel/panel-session.c
--- gnome-panel-2.22.0/gnome-panel/panel-session.c.ck-shutdown 2008-03-10 16:44:57.000000000 -0400
+++ gnome-panel-2.22.0/gnome-panel/panel-session.c 2008-04-05 20:48:37.000000000 -0400
@@ -60,6 +60,34 @@ panel_session_request_logout (void)
recursion_guard--;
}
+void
+panel_session_request_save (void)
+{
+ GnomeClient *client;
+ static int recursion_guard = 0;
+
+ if (recursion_guard)
+ return;
+
+ recursion_guard++;
+
+ if (!(client = gnome_master_client ()))
+ return;
+
+ /* Only request a Global save. We only want a Local
+ * save if the user selects 'Save current setup'
+ * from the dialog.
+ */
+ gnome_client_request_save (client,
+ GNOME_SAVE_GLOBAL,
+ FALSE,
+ GNOME_INTERACT_NONE,
+ TRUE, /* do not use the gnome-session gui */
+ TRUE);
+
+ recursion_guard--;
+}
+
static void
panel_session_handle_die_request (GnomeClient *client)
{
diff -up gnome-panel-2.22.0/gnome-panel/panel-session.h.ck-shutdown gnome-panel-2.22.0/gnome-panel/panel-session.h
--- gnome-panel-2.22.0/gnome-panel/panel-session.h.ck-shutdown 2008-03-10 16:44:57.000000000 -0400
+++ gnome-panel-2.22.0/gnome-panel/panel-session.h 2008-04-05 20:48:37.000000000 -0400
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
void panel_session_init (void);
void panel_session_do_not_restart (void);
void panel_session_request_logout (void);
+void panel_session_request_save (void);
G_END_DECLS
diff -up gnome-panel-2.22.0/gnome-panel/panel-toplevel.c.ck-shutdown gnome-panel-2.22.0/gnome-panel/panel-toplevel.c
--- gnome-panel-2.22.0/gnome-panel/panel-toplevel.c.ck-shutdown 2008-03-10 16:44:57.000000000 -0400
+++ gnome-panel-2.22.0/gnome-panel/panel-toplevel.c 2008-04-05 20:48:37.000000000 -0400
@@ -3329,7 +3329,8 @@ panel_toplevel_get_animation_time (Panel
}
static void
-panel_toplevel_start_animation (PanelToplevel *toplevel)
+panel_toplevel_start_animation (PanelToplevel *toplevel,
+ gboolean auto_hide)
{
GdkScreen *screen;
int monitor_width, monitor_height;
@@ -3480,7 +3481,7 @@ panel_toplevel_hide (PanelToplevel *t
}
if (toplevel->priv->animate && GTK_WIDGET_REALIZED (toplevel))
- panel_toplevel_start_animation (toplevel);
+ panel_toplevel_start_animation (toplevel, auto_hide);
else if (toplevel->priv->attached)
gtk_widget_hide (GTK_WIDGET (toplevel));
@@ -3528,7 +3529,7 @@ panel_toplevel_unhide (PanelToplevel *to
panel_toplevel_push_autohide_disabler (toplevel->priv->attach_toplevel);
if (toplevel->priv->animate && GTK_WIDGET_REALIZED (toplevel))
- panel_toplevel_start_animation (toplevel);
+ panel_toplevel_start_animation (toplevel, FALSE);
else if (toplevel->priv->attached)
gtk_widget_show (GTK_WIDGET (toplevel));
|