r4567: Get ATK headers through Zero Install.
[rox-filer/translations.git] / ROX-Filer / src / session.c
blob2cf7a0c009c41622f78639b250744ee34be677f3
1 /*
2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
5 * This program 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)
8 * any later version.
10 * This program 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
13 * more details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 /* session.c - XSMP client support */
22 #include <stdio.h>
23 #include <fcntl.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <gtk/gtk.h>
27 #include <X11/SM/SMlib.h>
28 #include <pwd.h>
29 #include "global.h"
30 #include "filer.h"
31 #include "main.h"
32 #include "pinboard.h"
33 #include "panel.h"
34 #include "sc.h"
35 #include "session.h"
37 static void save_state(SmClient *client)
39 FilerWindow *filer_window;
40 Panel *panel;
41 Pinboard *pinboard = current_pinboard;
42 GList *list;
43 GPtrArray *restart_cmd = g_ptr_array_new();
44 SmPropValue *program;
45 gchar *types[] = { "-t", "-b", "-l", "-r" };
46 gint i, nvals;
48 sc_get_prop_value(client, SmProgram, &program, &nvals);
49 g_ptr_array_add(restart_cmd, program->value);
51 g_ptr_array_add(restart_cmd, "-c");
52 g_ptr_array_add(restart_cmd, client->id);
54 for (list = all_filer_windows; list; list = list->next)
56 filer_window = (FilerWindow *)list->data;
57 gdk_window_set_role(filer_window->window->window,
58 filer_window->sym_path);
59 g_ptr_array_add(restart_cmd, "-d");
60 g_ptr_array_add(restart_cmd, filer_window->sym_path);
63 for(i = 0; i < PANEL_NUMBER_OF_SIDES; i++)
65 panel = current_panel[i];
66 if(!panel)
67 continue;
68 g_ptr_array_add(restart_cmd, types[panel->side]);
69 g_ptr_array_add(restart_cmd, panel->name);
72 if (pinboard)
74 g_ptr_array_add(restart_cmd, "-p");
75 g_ptr_array_add(restart_cmd, (gchar *) pinboard_get_name());
78 sc_set_list_of_array_prop(client, SmRestartCommand,
79 (const gchar **) restart_cmd->pdata, restart_cmd->len);
81 g_ptr_array_free(restart_cmd, TRUE);
84 /* Callbacks for various SM messages */
86 static gboolean save_yourself(SmClient *client)
88 save_state(client);
89 return TRUE;
92 static void die(SmClient *client)
94 gtk_main_quit();
97 void session_init(const gchar *client_id)
99 SmClient *client;
100 struct passwd *pw;
101 gchar *bin_path;
102 gchar *clone_cmd[2];
104 if (!sc_session_up())
105 return;
107 pw = getpwuid(euid);
108 bin_path = g_strconcat(app_dir, "/AppRun", NULL);
109 clone_cmd[0] = bin_path,
110 clone_cmd[1] = "-n";
112 client = sc_new(client_id);
114 if (!sc_connect(client))
116 sc_destroy(client);
117 return;
120 sc_set_array_prop(client, SmProgram, bin_path);
121 sc_set_array_prop(client, SmUserID, pw->pw_name);
122 sc_set_list_of_array_prop(client, SmCloneCommand,
123 (const gchar **) clone_cmd, 2);
124 sc_set_card_prop(client, SmRestartStyleHint, SmRestartIfRunning);
126 client->save_yourself_fn = &save_yourself;
127 client->shutdown_cancelled_fn = NULL;
128 client->save_complete_fn = NULL;
129 client->die_fn = &die;