source: trunk/third/gnome-core/panel/logout.c @ 17167

Revision 17167, 5.3 KB checked in by ghudson, 23 years ago (diff)
Merge with gnome-core 1.4.0.6.
Line 
1/* logout.c - Panel applet to end current session.  */
2/* Original author unknown. CORBAized by Elliot Lee */
3/* uncorbized by George Lebl */
4
5#include <config.h>
6#include <gnome.h>
7
8#include "panel-include.h"
9
10extern GSList *applets;
11extern GSList *applets_last;
12
13extern GtkTooltips *panel_tooltips;
14
15extern GlobalConfig global_config;
16extern gboolean commie_mode;
17
18static void
19logout (GtkWidget *widget)
20{
21        gtk_signal_handler_block_by_func (GTK_OBJECT (widget), GTK_SIGNAL_FUNC(logout), NULL);
22        if (global_config.drawer_auto_close) {
23                GtkWidget *parent = PANEL_WIDGET(widget->parent)->panel_parent;
24                g_return_if_fail(parent!=NULL);
25                if(IS_DRAWER_WIDGET(parent)) {
26                        BasePWidget *basep = BASEP_WIDGET(parent);
27                        GtkWidget *grandparent = PANEL_WIDGET(basep->panel)->master_widget->parent;
28                        GtkWidget *grandparentw =
29                                PANEL_WIDGET(grandparent)->panel_parent;
30                        drawer_widget_close_drawer (DRAWER_WIDGET (parent),
31                                                    grandparentw);
32                }
33        }
34
35        panel_quit();
36        gtk_signal_handler_unblock_by_func (GTK_OBJECT (widget), GTK_SIGNAL_FUNC(logout), NULL);
37}
38
39static void 
40drag_data_get_cb (GtkWidget          *widget,
41                  GdkDragContext     *context,
42                  GtkSelectionData   *selection_data,
43                  guint               info,
44                  guint               time,
45                  gpointer            data)
46{
47        char *type = data;
48        char *foo;
49
50        g_return_if_fail (type != NULL);
51
52        foo = g_strdup_printf ("%s:%d", type, find_applet (widget));
53
54        gtk_selection_data_set (selection_data,
55                                selection_data->target, 8, (guchar *)foo,
56                                strlen (foo));
57
58        g_free (foo);
59}
60
61static GtkWidget *
62create_logout_widget (void)
63{
64        static GtkTargetEntry dnd_targets[] = {
65                { "application/x-panel-applet-internal", 0, 0 }
66        };
67        GtkWidget *button;
68        char *pixmap_name;
69
70        pixmap_name = gnome_datadir_file ("gnome/athena/logout-icon");
71
72        button = button_widget_new (pixmap_name, -1,
73                                    MISC_TILE,
74                                    FALSE,
75                                    ORIENT_UP,
76                                    _("Log out"));
77
78        /*A hack since this function only pretends to work on window
79          widgets (which we actually kind of are) this will select
80          some (already selected) events on the panel instead of
81          the button window (where they are also selected) but
82          we don't mind*/
83        GTK_WIDGET_UNSET_FLAGS (button, GTK_NO_WINDOW);
84        gtk_drag_source_set (button,
85                             GDK_BUTTON1_MASK,
86                             dnd_targets, 1,
87                             GDK_ACTION_COPY | GDK_ACTION_MOVE);
88        GTK_WIDGET_SET_FLAGS (button, GTK_NO_WINDOW);
89
90        gtk_signal_connect (GTK_OBJECT (button), "drag_data_get",
91                            GTK_SIGNAL_FUNC (drag_data_get_cb),
92                            "LOGOUT");
93
94        g_free (pixmap_name);
95        gtk_tooltips_set_tip (panel_tooltips, button, _("Log out"), NULL);
96
97        gtk_signal_connect (GTK_OBJECT (button), "clicked",
98                            GTK_SIGNAL_FUNC (logout), NULL);
99
100        return button;
101}
102
103void
104load_logout_applet(PanelWidget *panel, int pos, gboolean exactpos)
105{
106        GtkWidget *logout;
107
108        logout = create_logout_widget();
109        if(!logout)
110                return;
111
112        if (!register_toy(logout, NULL, NULL, panel,
113                          pos, exactpos, APPLET_LOGOUT))
114                return;
115
116        applet_add_callback(applets_last->data, "help",
117                            GNOME_STOCK_PIXMAP_HELP,
118                            _("Help"));
119}
120
121static GtkWidget *
122create_lock_widget(void)
123{
124        static GtkTargetEntry dnd_targets[] = {
125                { "application/x-panel-applet-internal", 0, 0 }
126        };
127        GtkWidget *button;
128        char *pixmap_name;
129
130        pixmap_name = gnome_pixmap_file("gnome-lockscreen.png");
131
132        button = button_widget_new (pixmap_name, -1,
133                                    MISC_TILE,
134                                    FALSE,
135                                    ORIENT_UP,
136                                    _("Lock screen"));
137
138        /*A hack since this function only pretends to work on window
139          widgets (which we actually kind of are) this will select
140          some (already selected) events on the panel instead of
141          the button window (where they are also selected) but
142          we don't mind*/
143        GTK_WIDGET_UNSET_FLAGS (button, GTK_NO_WINDOW);
144        gtk_drag_source_set (button,
145                             GDK_BUTTON1_MASK,
146                             dnd_targets, 1,
147                             GDK_ACTION_COPY | GDK_ACTION_MOVE);
148        GTK_WIDGET_SET_FLAGS (button, GTK_NO_WINDOW);
149
150        gtk_signal_connect (GTK_OBJECT (button), "drag_data_get",
151                            GTK_SIGNAL_FUNC (drag_data_get_cb),
152                            "LOCK");
153
154        g_free (pixmap_name);
155        gtk_tooltips_set_tip (panel_tooltips, button, _("Lock screen"), NULL);
156
157        gtk_signal_connect (GTK_OBJECT (button), "clicked",
158                            GTK_SIGNAL_FUNC (panel_lock), NULL);
159
160        return button;
161}
162
163void
164load_lock_applet(PanelWidget *panel, int pos, gboolean exactpos)
165{
166        GtkWidget *lock;
167        lock = create_lock_widget();
168
169        if(!lock)
170                return;
171        if (!register_toy(lock, NULL, NULL, panel, pos,
172                          exactpos, APPLET_LOCK))
173                return;
174
175        /*
176          <jwz> Blank Screen Now
177          <jwz> Lock Screen Now
178          <jwz> Kill Daemon
179          <jwz> Restart Daemon
180          <jwz> Preferences
181          <jwz> (or "configuration" instead?  whatever word you use)
182          <jwz> those should do xscreensaver-command -activate, -lock, -exit...
183          <jwz> and "xscreensaver-command -exit ; xscreensaver &"
184          <jwz> and "xscreensaver-demo"
185        */
186
187        applet_add_callback(applets_last->data, "activate",
188                            NULL, _("Blank Screen Now"));
189        applet_add_callback(applets_last->data, "lock",
190                            NULL, _("Lock Screen Now"));
191        applet_add_callback(applets_last->data, "exit",
192                            NULL, _("Kill Daemon"));
193        applet_add_callback(applets_last->data, "restart",
194                            NULL, _("Restart Daemon"));
195        if ( ! commie_mode)
196                applet_add_callback(applets_last->data, "prefs",
197                                    NULL, _("Preferences"));
198        applet_add_callback(applets_last->data, "help",
199                            GNOME_STOCK_PIXMAP_HELP,
200                            _("Help"));
201}
202
203
Note: See TracBrowser for help on using the repository browser.