2
* Copyright (C) 2009-2011 Nick Schermer <nick@xfce.org>
3
* Copyright (c) 2009 Brian Tarricone <brian@tarricone.org>
5
* This library is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License as published by the Free
7
* Software Foundation; either version 2 of the License, or (at your option)
10
* This library is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
#include <libxfce4panel/libxfce4panel.h>
26
#include <libxfce4util/libxfce4util.h>
27
#include <libxfce4ui/libxfce4ui.h>
29
#include <dbus/dbus-glib.h>
31
#include <common/panel-private.h>
32
#include <common/panel-xfconf.h>
33
#include <common/panel-utils.h>
36
#include "actions-dialog_ui.h"
40
#define DEFAULT_ICON_SIZE (16)
41
#define DEFAULT_TIMEOUT (30)
45
static void actions_plugin_get_property (GObject *object,
49
static void actions_plugin_set_property (GObject *object,
53
static void actions_plugin_construct (XfcePanelPlugin *panel_plugin);
54
static void actions_plugin_free_data (XfcePanelPlugin *panel_plugin);
55
static gboolean actions_plugin_size_changed (XfcePanelPlugin *panel_plugin,
57
static void actions_plugin_configure_plugin (XfcePanelPlugin *panel_plugin);
58
static void actions_plugin_mode_changed (XfcePanelPlugin *panel_plugin,
59
XfcePanelPluginMode mode);
60
static void actions_plugin_pack (ActionsPlugin *plugin);
61
static GPtrArray *actions_plugin_default_array (void);
62
static void actions_plugin_menu (GtkWidget *button,
63
ActionsPlugin *plugin);
69
APPEARANCE_TYPE_BUTTONS,
79
PROP_INVERT_ORIENTATION,
91
struct _ActionsPluginClass
93
XfcePanelPluginClass __parent__;
98
XfcePanelPlugin __parent__;
103
guint invert_orientation : 1;
104
guint ask_confirmation : 1;
110
ACTION_TYPE_SEPARATOR = 1 << 1,
111
ACTION_TYPE_LOGOUT = 1 << 2,
112
ACTION_TYPE_LOGOUT_DIALOG = 1 << 3,
113
ACTION_TYPE_SWITCH_USER = 1 << 4,
114
ACTION_TYPE_LOCK_SCREEN = 1 << 5,
115
ACTION_TYPE_HIBERNATE = 1 << 6,
116
ACTION_TYPE_SUSPEND = 1 << 7,
117
ACTION_TYPE_RESTART = 1 << 8,
118
ACTION_TYPE_SHUTDOWN = 1 << 9
126
const gchar *display_name;
127
const gchar *mnemonic;
128
const gchar *question;
130
const gchar *icon_name;
139
guint unattended : 1;
143
static ActionEntry action_entries[] =
145
{ ACTION_TYPE_SEPARATOR,
147
NULL, NULL, NULL, NULL, NULL /* not needed */
149
{ ACTION_TYPE_LOGOUT,
153
N_("Are you sure you want to log out?"),
154
N_("Logging out in %d seconds."),
157
{ ACTION_TYPE_LOGOUT_DIALOG,
161
NULL, NULL, /* already shows a dialog */
164
{ ACTION_TYPE_SWITCH_USER,
168
NULL, NULL, /* not needed */
171
{ ACTION_TYPE_LOCK_SCREEN,
175
NULL, NULL, /* not needed */
178
{ ACTION_TYPE_HIBERNATE,
182
N_("Do you want to suspend to disk?"),
183
N_("Hibernating computer in %d seconds."),
186
{ ACTION_TYPE_SUSPEND,
190
N_("Do you want to suspend to RAM?"),
191
N_("Suspending computer in %d seconds."),
194
{ ACTION_TYPE_RESTART,
198
N_("Are you sure you want to restart?"),
199
N_("Restarting computer in %d seconds."),
202
{ ACTION_TYPE_SHUTDOWN,
206
N_("Are you sure you want to shut down?"),
207
N_("Turning off computer in %d seconds."),
214
/* define the plugin */
215
XFCE_PANEL_DEFINE_PLUGIN (ActionsPlugin, actions_plugin)
219
static GtkIconSize menu_icon_size = GTK_ICON_SIZE_INVALID;
220
static GQuark action_quark = 0;
225
actions_plugin_class_init (ActionsPluginClass *klass)
227
XfcePanelPluginClass *plugin_class;
228
GObjectClass *gobject_class;
230
gobject_class = G_OBJECT_CLASS (klass);
231
gobject_class->set_property = actions_plugin_set_property;
232
gobject_class->get_property = actions_plugin_get_property;
234
plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
235
plugin_class->construct = actions_plugin_construct;
236
plugin_class->free_data = actions_plugin_free_data;
237
plugin_class->size_changed = actions_plugin_size_changed;
238
plugin_class->configure_plugin = actions_plugin_configure_plugin;
239
plugin_class->mode_changed = actions_plugin_mode_changed;
241
g_object_class_install_property (gobject_class,
243
g_param_spec_boxed ("items",
245
PANEL_PROPERTIES_TYPE_VALUE_ARRAY,
246
EXO_PARAM_READWRITE));
248
g_object_class_install_property (gobject_class,
250
g_param_spec_uint ("appearance",
252
APPEARANCE_TYPE_BUTTONS,
253
APPEARANCE_TYPE_MENU,
254
APPEARANCE_TYPE_MENU,
255
EXO_PARAM_READWRITE));
257
g_object_class_install_property (gobject_class,
258
PROP_INVERT_ORIENTATION,
259
g_param_spec_boolean ("invert-orientation",
262
EXO_PARAM_READWRITE));
264
g_object_class_install_property (gobject_class,
265
PROP_ASK_CONFIRMATION,
266
g_param_spec_boolean ("ask-confirmation",
269
EXO_PARAM_READWRITE));
271
menu_icon_size = gtk_icon_size_from_name ("panel-actions-menu");
272
if (menu_icon_size == GTK_ICON_SIZE_INVALID)
273
menu_icon_size = gtk_icon_size_register ("panel-actions-menu",
277
action_quark = g_quark_from_string ("panel-action-quark");
283
actions_plugin_init (ActionsPlugin *plugin)
285
plugin->type = APPEARANCE_TYPE_MENU;
286
plugin->invert_orientation = FALSE;
287
plugin->ask_confirmation = TRUE;
293
actions_plugin_get_property (GObject *object,
298
ActionsPlugin *plugin = XFCE_ACTIONS_PLUGIN (object);
303
g_value_set_boxed (value, plugin->items);
306
case PROP_APPEARANCE:
307
g_value_set_uint (value, plugin->type);
310
case PROP_INVERT_ORIENTATION:
311
g_value_set_boolean (value, plugin->invert_orientation);
314
case PROP_ASK_CONFIRMATION:
315
g_value_set_boolean (value, plugin->ask_confirmation);
319
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
327
actions_plugin_set_property (GObject *object,
332
ActionsPlugin *plugin = XFCE_ACTIONS_PLUGIN (object);
337
if (plugin->items != NULL)
338
xfconf_array_free (plugin->items);
339
plugin->items = g_value_dup_boxed (value);
340
actions_plugin_pack (plugin);
343
case PROP_APPEARANCE:
344
plugin->type = g_value_get_uint (value);
345
actions_plugin_pack (plugin);
348
case PROP_INVERT_ORIENTATION:
349
plugin->invert_orientation = g_value_get_boolean (value);
350
actions_plugin_pack (plugin);
353
case PROP_ASK_CONFIRMATION:
354
plugin->ask_confirmation = g_value_get_boolean (value);
358
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
366
actions_plugin_construct (XfcePanelPlugin *panel_plugin)
368
ActionsPlugin *plugin = XFCE_ACTIONS_PLUGIN (panel_plugin);
369
const PanelProperty properties[] =
371
{ "items", PANEL_PROPERTIES_TYPE_VALUE_ARRAY },
372
{ "appearance", G_TYPE_UINT },
373
{ "invert-orientation", G_TYPE_BOOLEAN },
374
{ "ask-confirmation", G_TYPE_BOOLEAN },
378
/* show the properties dialog */
379
xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
381
/* bind all properties */
382
panel_properties_bind (NULL, G_OBJECT (plugin),
383
xfce_panel_plugin_get_property_base (panel_plugin),
386
actions_plugin_pack (plugin);
388
/* set orientation and size */
389
actions_plugin_mode_changed (panel_plugin,
390
xfce_panel_plugin_get_mode (panel_plugin));
396
actions_plugin_free_data (XfcePanelPlugin *panel_plugin)
398
ActionsPlugin *plugin = XFCE_ACTIONS_PLUGIN (panel_plugin);
400
if (plugin->pack_idle_id != 0)
401
g_source_remove (plugin->pack_idle_id);
403
if (plugin->items != NULL)
404
xfconf_array_free (plugin->items);
406
if (plugin->menu != NULL)
407
gtk_widget_destroy (plugin->menu);
413
actions_plugin_size_changed_child (GtkWidget *child,
416
gint size = GPOINTER_TO_INT (data);
418
if (!GTK_IS_SEPARATOR (child))
419
gtk_widget_set_size_request (child, size, size);
425
actions_plugin_size_changed (XfcePanelPlugin *panel_plugin,
428
ActionsPlugin *plugin = XFCE_ACTIONS_PLUGIN (panel_plugin);
430
GList *children, *li;
435
if (plugin->type == APPEARANCE_TYPE_BUTTONS)
437
max_size = size / xfce_panel_plugin_get_nrows (panel_plugin);
438
box = gtk_bin_get_child (GTK_BIN (plugin));
441
if (plugin->invert_orientation !=
442
(xfce_panel_plugin_get_mode (panel_plugin) == XFCE_PANEL_PLUGIN_MODE_DESKBAR))
444
children = gtk_container_get_children (GTK_CONTAINER (box));
445
if (G_UNLIKELY (children == NULL))
447
n_children = g_list_length (children);
449
for (li = children; li != NULL; li = li->next)
451
child_size = MIN (size / n_children, max_size);
455
gtk_widget_set_size_request (GTK_WIDGET (li->data),
456
child_size, child_size);
461
gtk_container_foreach (GTK_CONTAINER (box),
462
actions_plugin_size_changed_child,
463
GINT_TO_POINTER (max_size));
474
actions_plugin_configure_store (gpointer data)
476
ActionsPlugin *plugin = XFCE_ACTIONS_PLUGIN (data);
485
model = g_object_get_data (G_OBJECT (plugin), "items-store");
486
panel_return_val_if_fail (GTK_IS_LIST_STORE (model), FALSE);
488
array = g_ptr_array_new ();
490
if (gtk_tree_model_get_iter_first (model, &iter))
494
gtk_tree_model_get (model, &iter,
495
COLUMN_VISIBLE, &visible,
496
COLUMN_NAME, &name, -1);
498
val = g_new0 (GValue, 1);
499
g_value_init (val, G_TYPE_STRING);
500
g_snprintf (save_name, sizeof (save_name), "%s%s",
501
visible ? "+" : "-", name);
502
g_value_set_string (val, save_name);
503
g_ptr_array_add (array, val);
506
if (!gtk_tree_model_iter_next (model, &iter))
511
/* Store the new array */
512
if (plugin->items != NULL)
513
xfconf_array_free (plugin->items);
514
plugin->items = array;
515
g_object_notify (G_OBJECT (plugin), "items");
523
actions_plugin_configure_store_idle (ActionsPlugin *plugin)
525
g_idle_add (actions_plugin_configure_store, plugin);
531
actions_plugin_configure_visible_toggled (GtkCellRendererToggle *renderer,
532
const gchar *path_string,
533
ActionsPlugin *plugin)
539
panel_return_if_fail (XFCE_IS_ACTIONS_PLUGIN (plugin));
541
model = g_object_get_data (G_OBJECT (plugin), "items-store");
542
panel_return_if_fail (GTK_IS_LIST_STORE (model));
543
if (gtk_tree_model_get_iter_from_string (model, &iter, path_string))
545
gtk_tree_model_get (model, &iter, COLUMN_VISIBLE, &visible, -1);
546
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
547
COLUMN_VISIBLE, !visible, -1);
549
actions_plugin_configure_store (plugin);
556
actions_plugin_lookup_entry (const gchar *name)
560
for (i = 0; i < G_N_ELEMENTS (action_entries); i++)
561
if (g_strcmp0 (name, action_entries[i].name) == 0)
562
return &action_entries[i];
570
actions_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
572
ActionsPlugin *plugin = XFCE_ACTIONS_PLUGIN (panel_plugin);
586
const gchar *display_name;
588
panel_return_if_fail (XFCE_IS_ACTIONS_PLUGIN (plugin));
589
panel_return_if_fail (plugin->items != NULL);
591
/* setup the dialog */
593
builder = panel_utils_builder_new (panel_plugin, actions_dialog_ui,
594
actions_dialog_ui_length, &dialog);
595
if (G_UNLIKELY (builder == NULL))
598
combo = gtk_builder_get_object (builder, "combo-mode");
599
exo_mutual_binding_new (G_OBJECT (plugin), "appearance",
600
G_OBJECT (combo), "active");
602
object = gtk_builder_get_object (builder, "invert-orientation");
603
exo_mutual_binding_new (G_OBJECT (plugin), "invert-orientation",
604
G_OBJECT (object), "active");
605
exo_binding_new_with_negation (G_OBJECT (combo), "active",
606
G_OBJECT (object), "sensitive");
608
object = gtk_builder_get_object (builder, "confirmation-dialog");
609
exo_mutual_binding_new (G_OBJECT (plugin), "ask-confirmation",
610
G_OBJECT (object), "active");
612
store = gtk_builder_get_object (builder, "items-store");
613
panel_return_if_fail (GTK_IS_LIST_STORE (store));
614
g_object_set_data (G_OBJECT (plugin), "items-store", store);
616
object = gtk_builder_get_object (builder, "visible-toggle");
617
panel_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (object));
618
g_signal_connect (G_OBJECT (object), "toggled",
619
G_CALLBACK (actions_plugin_configure_visible_toggled), plugin);
621
sep_str = g_markup_printf_escaped ("<span color='grey' style='italic'>%s</span>", _("Separator"));
623
/* add items from the settings */
624
for (i = 0; i < plugin->items->len; i++)
626
/* get the value and check if it is within range */
627
val = g_ptr_array_index (plugin->items, i);
628
name = g_value_get_string (val);
629
if (exo_str_is_empty (name))
632
/* find the entry in the available actions */
633
entry = actions_plugin_lookup_entry (name + 1);
637
if (entry->type == ACTION_TYPE_SEPARATOR)
638
display_name = sep_str;
640
display_name = _(entry->display_name);
642
/* insert in the model */
643
gtk_list_store_insert_with_values (GTK_LIST_STORE (store), NULL, i,
644
COLUMN_VISIBLE, *name == '+',
645
COLUMN_DISPLAY_NAME, display_name,
646
COLUMN_NAME, entry->name,
647
COLUMN_TYPE, entry->type,
653
/* check if there are known actions not in the settings */
654
for (i = 0; i < G_N_ELEMENTS (action_entries); i++)
656
entry = &action_entries[i];
659
for (n = 0; n < plugin->items->len; n++)
661
val = g_ptr_array_index (plugin->items, n);
662
name = g_value_get_string (val);
663
if (g_strcmp0 (entry->name, name + 1) == 0)
672
gtk_list_store_append (GTK_LIST_STORE (store), &iter);
673
gtk_list_store_set (GTK_LIST_STORE (store), &iter,
674
COLUMN_VISIBLE, FALSE,
675
COLUMN_DISPLAY_NAME, _(entry->display_name),
676
COLUMN_TYPE, entry->type,
677
COLUMN_NAME, entry->name,
682
/* save on dnd changes */
683
g_signal_connect_swapped (G_OBJECT (store), "row-inserted",
684
G_CALLBACK (actions_plugin_configure_store_idle), plugin);
686
gtk_widget_show (GTK_WIDGET (dialog));
692
actions_plugin_mode_changed (XfcePanelPlugin *panel_plugin,
693
XfcePanelPluginMode mode)
695
actions_plugin_pack (XFCE_ACTIONS_PLUGIN (panel_plugin));
701
actions_plugin_action_confirmation_time (gpointer data)
703
ActionTimeout *timeout = data;
705
panel_return_val_if_fail (timeout->entry != NULL, FALSE);
707
if (timeout->time_left == 0)
709
/* unattended shutdown, don't save the session to avoid blocking the logout */
710
timeout->unattended = TRUE;
712
gtk_dialog_response (GTK_DIALOG (timeout->dialog),
713
GTK_RESPONSE_ACCEPT);
717
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (timeout->dialog),
718
_(timeout->entry->status),
722
return --timeout->time_left >= 0;
728
actions_plugin_action_confirmation (ActionsPlugin *plugin,
730
gboolean *unattended)
736
ActionTimeout *timeout;
739
panel_return_val_if_fail (entry->question != NULL, FALSE);
740
panel_return_val_if_fail (entry->status != NULL, FALSE);
742
dialog = gtk_message_dialog_new (NULL, 0,
743
GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL,
744
"%s", _(entry->question));
745
gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
746
gtk_window_stick (GTK_WINDOW (dialog));
747
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
748
gtk_window_set_title (GTK_WINDOW (dialog), _(entry->name));
750
button = gtk_dialog_add_button (GTK_DIALOG (dialog), _(entry->mnemonic), GTK_RESPONSE_ACCEPT);
751
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
753
image = gtk_image_new_from_icon_name (entry->icon_name, GTK_ICON_SIZE_BUTTON);
754
gtk_button_set_image (GTK_BUTTON (button), image);
756
timeout = g_slice_new0 (ActionTimeout);
757
timeout->entry = entry;
758
timeout->time_left = DEFAULT_TIMEOUT;
759
timeout->dialog = dialog;
760
timeout->unattended = FALSE;
762
/* first second looks out of sync with a second timer */
763
timeout_id = g_timeout_add (1000, actions_plugin_action_confirmation_time, timeout);
764
actions_plugin_action_confirmation_time (timeout);
766
result = gtk_dialog_run (GTK_DIALOG (dialog));
768
if (unattended != NULL)
769
*unattended = timeout->unattended;
771
g_source_remove (timeout_id);
772
gtk_widget_destroy (dialog);
773
g_slice_free (ActionTimeout, timeout);
775
return result == GTK_RESPONSE_ACCEPT;
781
actions_plugin_action_dbus_proxy_session (DBusGConnection *conn)
783
return dbus_g_proxy_new_for_name (conn,
784
"org.xfce.SessionManager",
785
"/org/xfce/SessionManager",
786
"org.xfce.Session.Manager");
792
actions_plugin_action_dbus_xfsm (const gchar *method,
793
gboolean show_dialog,
797
DBusGConnection *conn;
799
gboolean retval = FALSE;
801
conn = dbus_g_bus_get (DBUS_BUS_SESSION, error);
805
proxy = actions_plugin_action_dbus_proxy_session (conn);
806
if (G_LIKELY (proxy != NULL))
808
if (g_strcmp0 (method, "Logout") == 0)
810
retval = dbus_g_proxy_call (proxy, method, error,
811
G_TYPE_BOOLEAN, show_dialog,
812
G_TYPE_BOOLEAN, allow_save,
813
G_TYPE_INVALID, G_TYPE_INVALID);
815
else if (g_strcmp0 (method, "Suspend") == 0
816
|| g_strcmp0 (method, "Hibernate") == 0)
818
retval = dbus_g_proxy_call (proxy, method, error,
819
G_TYPE_INVALID, G_TYPE_INVALID);
823
retval = dbus_g_proxy_call (proxy, method, error,
824
G_TYPE_BOOLEAN, allow_save,
825
G_TYPE_INVALID, G_TYPE_INVALID);
828
g_object_unref (G_OBJECT (proxy));
837
actions_plugin_action_dbus_can (DBusGProxy *proxy,
840
gboolean allowed = FALSE;
842
if (dbus_g_proxy_call (proxy, method, NULL,
844
G_TYPE_BOOLEAN, &allowed,
854
actions_plugin_actions_allowed (void)
856
DBusGConnection *conn;
857
ActionType allow_mask = ACTION_TYPE_SEPARATOR;
860
GError *error = NULL;
862
/* check for commands we use */
863
path = g_find_program_in_path ("gdmflexiserver");
865
PANEL_SET_FLAG (allow_mask, ACTION_TYPE_SWITCH_USER);
868
path = g_find_program_in_path ("xflock4");
870
PANEL_SET_FLAG (allow_mask, ACTION_TYPE_LOCK_SCREEN);
873
/* session bus for querying the managers */
874
conn = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
878
proxy = actions_plugin_action_dbus_proxy_session (conn);
879
if (G_LIKELY (proxy != NULL))
881
/* when xfce4-session is connected, we can logout */
882
PANEL_SET_FLAG (allow_mask, ACTION_TYPE_LOGOUT | ACTION_TYPE_LOGOUT_DIALOG);
884
if (actions_plugin_action_dbus_can (proxy, "CanShutdown"))
885
PANEL_SET_FLAG (allow_mask, ACTION_TYPE_SHUTDOWN);
887
if (actions_plugin_action_dbus_can (proxy, "CanRestart"))
888
PANEL_SET_FLAG (allow_mask, ACTION_TYPE_RESTART);
890
if (actions_plugin_action_dbus_can (proxy, "CanSuspend"))
891
PANEL_SET_FLAG (allow_mask, ACTION_TYPE_SUSPEND);
893
if (actions_plugin_action_dbus_can (proxy, "CanHibernate"))
894
PANEL_SET_FLAG (allow_mask, ACTION_TYPE_HIBERNATE);
896
g_object_unref (G_OBJECT (proxy));
901
g_critical ("Unable to open DBus session bus: %s", error->message);
902
g_error_free (error);
911
actions_plugin_action_activate (GtkWidget *widget,
912
ActionsPlugin *plugin)
915
gboolean unattended = FALSE;
916
GError *error = NULL;
917
gboolean succeed = FALSE;
919
entry = g_object_get_qdata (G_OBJECT (widget), action_quark);
920
panel_return_if_fail (entry != NULL);
922
if (plugin->ask_confirmation
923
&& entry->question != NULL
924
&& entry->status != NULL
925
&& !actions_plugin_action_confirmation (plugin, entry, &unattended))
930
case ACTION_TYPE_LOGOUT:
931
succeed = actions_plugin_action_dbus_xfsm ("Logout", FALSE,
932
!unattended, &error);
935
case ACTION_TYPE_LOGOUT_DIALOG:
936
succeed = actions_plugin_action_dbus_xfsm ("Logout", TRUE,
937
!unattended, &error);
940
case ACTION_TYPE_RESTART:
941
succeed = actions_plugin_action_dbus_xfsm ("Restart", FALSE,
942
!unattended, &error);
945
case ACTION_TYPE_SHUTDOWN:
946
succeed = actions_plugin_action_dbus_xfsm ("Shutdown", FALSE,
947
!unattended, &error);
950
case ACTION_TYPE_HIBERNATE:
951
succeed = actions_plugin_action_dbus_xfsm ("Hibernate", FALSE,
955
case ACTION_TYPE_SUSPEND:
956
succeed = actions_plugin_action_dbus_xfsm ("Suspend", FALSE,
960
case ACTION_TYPE_SWITCH_USER:
961
succeed = g_spawn_command_line_async ("gdmflexiserver", &error);
964
case ACTION_TYPE_LOCK_SCREEN:
965
succeed = g_spawn_command_line_async ("xflock4", &error);
969
panel_assert_not_reached ();
975
xfce_dialog_show_error (NULL, error,
976
_("Failed to run action \"%s\""),
977
_(entry->display_name));
984
actions_plugin_action_button (ActionsPlugin *plugin,
986
GtkOrientation orientation,
993
/* lookup the action entry */
994
entry = actions_plugin_lookup_entry (name);
1001
if (entry->type == ACTION_TYPE_SEPARATOR)
1003
if (orientation == GTK_ORIENTATION_HORIZONTAL)
1004
widget = gtk_vseparator_new ();
1006
widget = gtk_hseparator_new ();
1010
widget = xfce_panel_create_button ();
1011
gtk_button_set_relief (GTK_BUTTON (widget), GTK_RELIEF_NONE);
1012
g_object_set_qdata (G_OBJECT (widget), action_quark, entry);
1013
gtk_widget_set_tooltip_text (widget, _(entry->display_name));
1014
g_signal_connect (G_OBJECT (widget), "clicked",
1015
G_CALLBACK (actions_plugin_action_activate), plugin);
1017
image = xfce_panel_image_new_from_source (entry->icon_name);
1018
gtk_container_add (GTK_CONTAINER (widget), image);
1019
gtk_widget_show (image);
1022
xfce_panel_plugin_add_action_widget (XFCE_PANEL_PLUGIN (plugin), widget);
1030
actions_plugin_action_menu_item (ActionsPlugin *plugin,
1039
/* lookup the action entry */
1040
entry = actions_plugin_lookup_entry (name);
1045
*type = entry->type;
1047
if (entry->type == ACTION_TYPE_SEPARATOR)
1048
return gtk_separator_menu_item_new ();
1050
mi = gtk_image_menu_item_new_with_mnemonic (_(entry->mnemonic));
1051
g_object_set_qdata (G_OBJECT (mi), action_quark, entry);
1052
g_signal_connect (G_OBJECT (mi), "activate",
1053
G_CALLBACK (actions_plugin_action_activate), plugin);
1057
image = xfce_panel_image_new_from_source (entry->icon_name);
1058
xfce_panel_image_set_size (XFCE_PANEL_IMAGE (image), size);
1059
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image);
1060
gtk_widget_show (image);
1069
actions_plugin_pack_idle (gpointer data)
1071
ActionsPlugin *plugin = XFCE_ACTIONS_PLUGIN (data);
1075
const gchar *username;
1081
GtkOrientation orientation;
1082
ActionType allowed_types;
1084
XfcePanelPluginMode mode;
1086
child = gtk_bin_get_child (GTK_BIN (plugin));
1088
gtk_widget_destroy (child);
1090
if (plugin->menu != NULL)
1091
gtk_widget_destroy (plugin->menu);
1093
if (plugin->items == NULL)
1094
plugin->items = actions_plugin_default_array ();
1096
allowed_types = actions_plugin_actions_allowed ();
1098
if (plugin->type == APPEARANCE_TYPE_BUTTONS)
1100
if (xfce_panel_plugin_get_mode (XFCE_PANEL_PLUGIN (plugin)) == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
1101
orientation = GTK_ORIENTATION_VERTICAL;
1103
orientation = GTK_ORIENTATION_HORIZONTAL;
1105
if (plugin->invert_orientation)
1106
orientation = !orientation;
1107
box = xfce_hvbox_new (orientation, FALSE, 0);
1108
gtk_container_add (GTK_CONTAINER (plugin), box);
1109
gtk_widget_show (box);
1111
for (i = 0; i < plugin->items->len; i++)
1113
val = g_ptr_array_index (plugin->items, i);
1114
name = g_value_get_string (val);
1115
if (name == NULL || *name != '+')
1118
/* skip separators when packing buttons in the opposite
1120
if (plugin->invert_orientation !=
1121
(xfce_panel_plugin_get_mode (XFCE_PANEL_PLUGIN (plugin)) == XFCE_PANEL_PLUGIN_MODE_DESKBAR)
1122
&& g_strcmp0 (name + 1, "separator") == 0)
1125
widget = actions_plugin_action_button (plugin, name + 1, orientation, &type);
1128
gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
1129
gtk_widget_set_sensitive (widget, PANEL_HAS_FLAG (allowed_types, type));
1130
gtk_widget_show (widget);
1134
actions_plugin_size_changed (XFCE_PANEL_PLUGIN (plugin),
1135
xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin)));
1139
/* get a decent username, not the glib defaults */
1140
username = g_get_real_name ();
1141
if (exo_str_is_empty (username)
1142
|| strcmp (username, "Unknown") == 0)
1144
username = g_get_user_name ();
1145
if (exo_str_is_empty (username)
1146
|| strcmp (username, "somebody") == 0)
1147
username = _("John Doe");
1150
button = xfce_arrow_button_new (GTK_ARROW_NONE);
1151
gtk_widget_set_name (button, "actions-button");
1152
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
1153
xfce_panel_plugin_add_action_widget (XFCE_PANEL_PLUGIN (plugin), button);
1154
gtk_container_add (GTK_CONTAINER (plugin), button);
1155
g_signal_connect (G_OBJECT (button), "toggled",
1156
G_CALLBACK (actions_plugin_menu), plugin);
1157
gtk_widget_show (button);
1159
label = gtk_label_new (username);
1160
gtk_container_add (GTK_CONTAINER (button), label);
1161
mode = xfce_panel_plugin_get_mode (XFCE_PANEL_PLUGIN (plugin));
1162
gtk_label_set_angle (GTK_LABEL (label),
1163
(mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? 270 : 0);
1164
gtk_widget_show (label);
1173
actions_plugin_pack_idle_destoyed (gpointer data)
1175
XFCE_ACTIONS_PLUGIN (data)->pack_idle_id = 0;
1181
actions_plugin_pack (ActionsPlugin *plugin)
1183
if (plugin->pack_idle_id == 0)
1185
plugin->pack_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, actions_plugin_pack_idle,
1186
plugin, actions_plugin_pack_idle_destoyed);
1193
actions_plugin_default_array (void)
1198
const gchar *defaults[] =
1212
array = g_ptr_array_sized_new (G_N_ELEMENTS (defaults));
1213
for (i = 0; i < G_N_ELEMENTS (defaults); i++)
1215
val = g_new0 (GValue, 1);
1216
g_value_init (val, G_TYPE_STRING);
1217
g_value_set_static_string (val, defaults[i]);
1218
g_ptr_array_add (array, val);
1227
actions_plugin_menu_deactivate (GtkWidget *menu,
1230
panel_return_if_fail (button == NULL || GTK_IS_TOGGLE_BUTTON (button));
1231
panel_return_if_fail (GTK_IS_MENU (menu));
1233
/* button is NULL when we popup the menu under the cursor position */
1235
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
1237
gtk_menu_popdown (GTK_MENU (menu));
1243
actions_plugin_menu (GtkWidget *button,
1244
ActionsPlugin *plugin)
1252
ActionType allowed_types;
1254
panel_return_if_fail (XFCE_IS_ACTIONS_PLUGIN (plugin));
1255
panel_return_if_fail (button != NULL);
1257
/* do not popup the menu if the button is being toggled off */
1258
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1261
if (plugin->menu == NULL)
1263
plugin->menu = gtk_menu_new ();
1264
g_signal_connect (G_OBJECT (plugin->menu), "selection-done",
1265
G_CALLBACK (actions_plugin_menu_deactivate), button);
1266
g_object_add_weak_pointer (G_OBJECT (plugin->menu), (gpointer) &plugin->menu);
1268
size = DEFAULT_ICON_SIZE;
1269
if (gtk_icon_size_lookup (menu_icon_size, &w, &h))
1272
allowed_types = actions_plugin_actions_allowed ();
1274
for (i = 0; i < plugin->items->len; i++)
1276
val = g_ptr_array_index (plugin->items, i);
1277
name = g_value_get_string (val);
1278
if (name == NULL || *name != '+')
1281
mi = actions_plugin_action_menu_item (plugin, name + 1, size, &type);
1284
gtk_menu_shell_append (GTK_MENU_SHELL (plugin->menu), mi);
1285
gtk_widget_set_sensitive (mi, PANEL_HAS_FLAG (allowed_types, type));
1286
gtk_widget_show (mi);
1291
gtk_menu_popup (GTK_MENU (plugin->menu), NULL, NULL,
1292
button != NULL ? xfce_panel_plugin_position_menu : NULL,
1293
plugin, 1, gtk_get_current_event_time ());