r4370: Added Vietnamese translation (Xomhau Newnick).
[rox-filer/ma.git] / ROX-Filer / src / session.c
blobd66d08318aa704485e0ae427ebeb3d2ac531fdf8
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2005, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* session.c - XSMP client support */
24 #include <stdio.h>
25 #include <fcntl.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <gtk/gtk.h>
29 #include <X11/SM/SMlib.h>
30 #include <pwd.h>
31 #include "global.h"
32 #include "filer.h"
33 #include "main.h"
34 #include "pinboard.h"
35 #include "panel.h"
36 #include "sc.h"
37 #include "session.h"
39 static void save_state(SmClient *client)
41 FilerWindow *filer_window;
42 Panel *panel;
43 Pinboard *pinboard = current_pinboard;
44 GList *list;
45 GPtrArray *restart_cmd = g_ptr_array_new();
46 SmPropValue *program;
47 gchar *types[] = { "-t", "-b", "-l", "-r" };
48 gint i, nvals;
50 sc_get_prop_value(client, SmProgram, &program, &nvals);
51 g_ptr_array_add(restart_cmd, program->value);
53 g_ptr_array_add(restart_cmd, "-c");
54 g_ptr_array_add(restart_cmd, client->id);
56 for (list = all_filer_windows; list; list = list->next)
58 filer_window = (FilerWindow *)list->data;
59 gdk_window_set_role(filer_window->window->window,
60 filer_window->sym_path);
61 g_ptr_array_add(restart_cmd, "-d");
62 g_ptr_array_add(restart_cmd, filer_window->sym_path);
65 for(i = 0; i < PANEL_NUMBER_OF_SIDES; i++)
67 panel = current_panel[i];
68 if(!panel)
69 continue;
70 g_ptr_array_add(restart_cmd, types[panel->side]);
71 g_ptr_array_add(restart_cmd, panel->name);
74 if (pinboard)
76 g_ptr_array_add(restart_cmd, "-p");
77 g_ptr_array_add(restart_cmd, (gchar *) pinboard_get_name());
80 sc_set_list_of_array_prop(client, SmRestartCommand,
81 (const gchar **) restart_cmd->pdata, restart_cmd->len);
83 g_ptr_array_free(restart_cmd, TRUE);
86 /* Callbacks for various SM messages */
88 static gboolean save_yourself(SmClient *client)
90 save_state(client);
91 return TRUE;
94 static void die(SmClient *client)
96 gtk_main_quit();
99 void session_init(const gchar *client_id)
101 SmClient *client;
102 struct passwd *pw;
103 gchar *bin_path;
104 gchar *clone_cmd[2];
106 if (!sc_session_up())
107 return;
109 pw = getpwuid(euid);
110 bin_path = g_strconcat(app_dir, "/AppRun", NULL);
111 clone_cmd[0] = bin_path,
112 clone_cmd[1] = "-n";
114 client = sc_new(client_id);
116 if (!sc_connect(client))
118 sc_destroy(client);
119 return;
122 sc_set_array_prop(client, SmProgram, bin_path);
123 sc_set_array_prop(client, SmUserID, pw->pw_name);
124 sc_set_list_of_array_prop(client, SmCloneCommand,
125 (const gchar **) clone_cmd, 2);
126 sc_set_card_prop(client, SmRestartStyleHint, SmRestartIfRunning);
128 client->save_yourself_fn = &save_yourself;
129 client->shutdown_cancelled_fn = NULL;
130 client->save_complete_fn = NULL;
131 client->die_fn = &die;