1/*
2    Copyright 2012 Julien Lavergne <gilir@ubuntu.com>
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17using Gtk;
18using Posix;
19
20const string GETTEXT_PACKAGE = "lxsession";
21
22namespace LDefaultApps
23{
24    public class UpdateWindows : Gtk.Window
25    {
26        public Pid pid;
27        public KeyFile kf;
28
29	    public UpdateWindows ()
30        {
31	        this.title = _("Update lxsession database");
32	        this.window_position = Gtk.WindowPosition.CENTER;
33            try
34            {
35                this.icon = IconTheme.get_default ().load_icon ("preferences-desktop", 48, 0);
36            }
37            catch (Error e)
38            {
39                message ("Could not load application icon: %s\n", e.message);
40            }
41	        this.set_default_size (300, 70);
42
43	        // Widget content:
44	        this.add (new Gtk.Label (_("The database is updating, please wait")));
45
46            kf = get_keyfile();
47            update_database();
48        }
49
50        public void update_database()
51        {
52            try
53            {
54                string[] command = "lxsession-db -m write".split_set(" ",0);
55                Process.spawn_async (
56                             null,
57                             command,
58                             null,
59                             SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD,
60                             null,
61                             out pid);
62                ChildWatch.add(pid, callback_pid);
63            }
64            catch (SpawnError err)
65            {
66                warning ("Error updating the database: %s\n", err.message);
67            }
68        }
69
70        private void callback_pid(Pid pid, int status)
71        {
72            Process.close_pid (pid);
73            MainWindows win = new MainWindows(kf);
74            win.show_all();
75#if USE_GTK2
76            this.hide_all();
77#endif
78#if USE_GTK3
79            this.hide();
80#endif
81        }
82
83        public KeyFile get_keyfile()
84        {
85        /* Configuration file */
86            string config_path_directory = Path.build_filename(Environment.get_user_config_dir (),"lxsession-default-apps");
87
88            KeyFile kf = load_key_conf(config_path_directory, "settings.conf");
89
90            return kf;
91        }
92    }
93
94    public class MainWindows : Gtk.Window
95    {
96	    public MainWindows (KeyFile kf)
97        {
98		    this.title = _("LXSession configuration");
99		    this.window_position = Gtk.WindowPosition.CENTER;
100            try
101            {
102                this.icon = IconTheme.get_default ().load_icon ("preferences-desktop", 48, 0);
103            }
104            catch (Error e)
105            {
106                message ("Could not load application icon: %s\n", e.message);
107            }
108		    this.set_default_size (600, 400);
109            this.destroy.connect (Gtk.main_quit);
110
111            var builder = new Builder ();
112            try
113            {
114                // If the UI contains custom widgets, their types must've been instantiated once
115                // Type type = typeof(Foo.BarEntry);
116                // assert(type != 0);
117
118                var builder_file_path = Path.build_filename("data","ui","lxsession-default-apps.ui");
119                var builder_file = File.new_for_path(builder_file_path);
120
121                if (builder_file.query_exists())
122                {
123                    builder.add_from_file (builder_file_path);
124                }
125                else
126                {
127                    /* TODO Make it smart with prefix */
128                    builder_file_path = Path.build_filename("/usr/local","share","lxsession","ui","lxsession-default-apps.ui");
129                    builder.add_from_file (builder_file_path);
130                }
131            }
132            catch (GLib.Error e)
133            {
134                critical ("Could not load UI: %s\n", e.message);
135            }
136            builder.connect_signals (null);
137            var main_vbox = builder.get_object ("main_vbox") as VBox;
138            main_vbox.show_all();
139            this.add(main_vbox);
140            main_vbox.reparent(this);
141
142            try
143            {
144                this.icon = IconTheme.get_default ().load_icon ("xfwm4", 48, 0);
145            }
146            catch (Error e)
147            {
148                message ("Could not load application icon: %s\n", e.message);
149            }
150
151            var dbus_backend = new DbusBackend("session");
152
153            /* Autostart list */
154            manual_autostart_init(builder);
155            autostart_core_applications(builder, dbus_backend);
156
157            /* Common string */
158            string manual_setting_help = _("Manual Settings: Manually sets the command (you need to restart lxsession-default-apps to see the change)\n");
159            string session_string_help = _("Session : specify the session\n");
160            string extra_string_help = _("Extra: Add an extra parameter to the launch option\n");
161            string mime_association_help = _("Mime association: Automatically associates mime types to this application ?\n");
162            string mime_available_help = _("Available applications : Applications of this type available on your repositories\n");
163            string handle_desktop_help = _("Handle Desktop: Draw the desktop using the file manager ?\n");
164            string autostart_help = _("Autostart the application ?\n");
165            string debian_default_help = _("Set default program for Debian system (using update-alternatives, need root password)\n");
166
167            /* New inits */
168            string windows_manager_help_message = _("Windows manager draws and manage the windows. \nYou can choose openbox, openbox-custom (for a custom openbox configuration, see \"More\"), kwin, compiz ...");
169            string[] windows_manager_more = {"session", "extras"};
170            string windows_manager_more_help_message = session_string_help + extra_string_help;
171            init_application(builder, kf, dbus_backend, "windows_manager", "", windows_manager_help_message, windows_manager_more, windows_manager_more_help_message, null);
172
173            string panel_help_message = _("Panel is the component usually at the bottom of the screen which manages a list of opened windows, shortcuts, notification area ...");
174            string[] panel_more = {"session"};
175            string panel_more_help_message = session_string_help;
176            init_application(builder, kf, dbus_backend, "panel", "", panel_help_message, panel_more, panel_more_help_message, null);
177
178            string dock_help_message = _("Dock is a second panel. It's used to launch a different program to handle a second type of panel.");
179            string[] dock_more = {"session"};
180            string dock_more_help_message = session_string_help;
181            init_application(builder, kf, dbus_backend, "dock", "", dock_help_message, dock_more, dock_more_help_message, null);
182
183            string file_manager_help_message = _("File manager is the component which open the files.\nSee \"More\" to add options to handle the desktop, or opening files ");
184            string[] file_manager_more = {"combobox_manual", "session", "extra", "handle_desktop", "mime_association", "mime_available"};
185            string file_manager_more_help_message = manual_setting_help + session_string_help + extra_string_help + handle_desktop_help + mime_association_help + mime_available_help;
186            init_application_combobox (builder, kf, dbus_backend, "file_manager", "", file_manager_help_message, file_manager_more, file_manager_more_help_message, null);
187
188            string composite_manager_help_message = _("Composite manager enables graphics effects, like transpacency and shadows, if the windows manager doesn't handle it. \nExample: compton");
189            string[] composite_manager_more = {""};
190            string composite_manager_more_help_message = "";
191            init_application(builder, kf, dbus_backend, "composite_manager", "", composite_manager_help_message, composite_manager_more, composite_manager_more_help_message, null);
192
193            string desktop_manager_help_message = _("Desktop manager draws the desktop and manages the icons inside it.\nYou can manage it with the file manager by setting \"filemanager\"");
194            string[] desktop_manager_more = {"wallpaper", "handle_desktop"};
195            string desktop_manager_more_help_message = _("Wallpaper: Set an image path to draw the wallpaper");
196            init_application(builder, kf, dbus_backend, "desktop_manager", "", desktop_manager_help_message, desktop_manager_more, desktop_manager_more_help_message, null);
197
198            string screensaver_help_message = _("Screensaver is a program which displays animations when your computer is idle");
199            string[] screensaver_more = {""};
200            string screensaver_more_help_message = "";
201            init_application(builder, kf, dbus_backend, "screensaver", "", screensaver_help_message, screensaver_more, screensaver_more_help_message, null);
202
203            string power_manager_help_message = _("Power Manager helps you to reduce the usage of batteries. You probably don't need one if you have a desktop computer.\nAuto option will set it automatically, depending of the laptop mode option.");
204            string[] power_manager_more = {""};
205            string power_manager_more_help_message = "";
206            init_application(builder, kf, dbus_backend, "power_manager", "", power_manager_help_message, power_manager_more, power_manager_more_help_message, null);
207
208            string polkit_help_message = _("Polkit agent provides authorisations to use some actions, like suspend, hibernate, using Consolekit ... It's not advised to make it blank.");
209            string[] polkit_more = {""};
210            string polkit_more_help_message = "";
211            init_application(builder, kf, dbus_backend, "polkit", "", polkit_help_message, polkit_more, polkit_more_help_message, null);
212
213            string network_gui_help_message = _("Set an utility to manager connections, such as nm-applet");
214            string[] network_gui_more = {""};
215            string network_gui_more_help_message = "";
216            init_application(builder, kf, dbus_backend, "network_gui", "", network_gui_help_message, network_gui_more, network_gui_more_help_message, null);
217
218            string im1_help_message = _("Use a communication software (an IRC client, an IM client ...)");
219            string[] im1_more = {"combobox_manual", "autostart", "mime_association", "mime_available"};
220            string im1_more_help_message = manual_setting_help + autostart_help + mime_association_help + mime_available_help;
221            init_application_combobox (builder, kf, dbus_backend, "im1", "", im1_help_message, im1_more, im1_more_help_message, "im");
222
223            string im2_help_message = _("Use another communication software (an IRC client, an IM client ...)");
224            string[] im2_more = {"combobox_manual", "autostart", "mime_association", "mime_available"};
225            string im2_more_help_message = manual_setting_help + autostart_help + mime_association_help + mime_available_help;
226            init_application_combobox (builder, kf, dbus_backend, "im2", "", im2_help_message, im2_more, im2_more_help_message, "im");
227
228            string terminal_manager_help_message = _("Terminal by default to launch command line.");
229            string[] terminal_manager_more = {"combobox_manual", "debian_default", "mime_association", "mime_available"};
230            string terminal_manager_more_help_message = manual_setting_help + debian_default_help + mime_association_help + mime_available_help;
231            init_application_combobox (builder, kf, dbus_backend, "terminal_manager", "", terminal_manager_help_message, terminal_manager_more, terminal_manager_more_help_message, null);
232
233            string webbrowser_help_message = _("Application to go to Internet, Google, Facebook, debian.org ...");
234            string[] webbrowser_more = {"combobox_manual", "debian_default", "mime_association", "mime_available"};
235            string webbrowser_more_help_message = manual_setting_help + debian_default_help + mime_association_help + mime_available_help;
236            init_application_combobox (builder, kf, dbus_backend, "webbrowser", "", webbrowser_help_message, webbrowser_more, webbrowser_more_help_message, null);
237
238            string email_help_message = _("Application to send mails");
239            string[] email_more = {"combobox_manual", "mime_association", "mime_available"};
240            string email_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
241            init_application_combobox (builder, kf, dbus_backend, "email", "", email_help_message, email_more, email_more_help_message, null);
242
243            string widget_help_message = _("Utility to launch gadgets, like conky, screenlets ...");
244            string[] widget_more = {"autostart"};
245            string widget_more_help_message = autostart_help;
246            init_application(builder, kf, dbus_backend, "widget1", "", widget_help_message, widget_more, widget_more_help_message, "widget");
247
248            string launcher_manager_help_message = _("Utility to launch application, like synapse, kupfer ... \nFor using lxpanel or lxde default utility, use \"lxpanelctl\" ");
249            string[] launcher_manager_more = {"autostart"};
250            string launcher_manager_more_help_message = autostart_help;
251            init_application(builder, kf, dbus_backend, "launcher_manager", "", launcher_manager_help_message, launcher_manager_more, launcher_manager_more_help_message, null);
252
253            string screenshot_manager_help_message = _("Application for taking screeshot of your desktop, like scrot ...");
254            string[] screenshot_manager_more = {""};
255            string screenshot_manager_more_help_message = autostart_help;
256            init_application(builder, kf, dbus_backend, "screenshot_manager", "", screenshot_manager_help_message, screenshot_manager_more, screenshot_manager_more_help_message, null);
257
258            string pdf_reader_help_message = "Viewer for PDF, like evince";
259            string[] pdf_reader_more = {"combobox_manual", "mime_association", "mime_available"};
260            string pdf_reader_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
261            init_application_combobox (builder, kf, dbus_backend, "pdf_reader", "", pdf_reader_help_message, pdf_reader_more, pdf_reader_more_help_message, null);
262
263            string video_player_help_message = _("Video application");
264            string[] video_player_more = {"combobox_manual", "mime_association", "mime_available"};
265            string video_player_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
266            init_application_combobox (builder, kf, dbus_backend, "video_player", "", video_player_help_message, video_player_more, video_player_more_help_message, null);
267
268            string audio_player_help_message = _("Audio application");
269            string[] audio_player_more = {"combobox_manual", "mime_association", "mime_available"};
270            string audio_player_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
271            init_application_combobox (builder, kf, dbus_backend, "audio_player", "", audio_player_help_message, audio_player_more, audio_player_more_help_message, null);
272
273            string image_display_help_message = _("Application to display images");
274            string[] image_display_more = {"combobox_manual", "mime_association", "mime_available"};
275            string image_display_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
276            init_application_combobox (builder, kf, dbus_backend, "image_display", "", image_display_help_message, image_display_more, image_display_more_help_message, "image_display");
277
278            string text_editor_help_message = _("Application to edit text");
279            string[] text_editor_more = {"combobox_manual", "mime_association", "mime_available", "debian_default"};
280            string text_editor_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
281            init_application_combobox (builder, kf, dbus_backend, "text_editor", "", text_editor_help_message, text_editor_more, text_editor_more_help_message, "text_editor");
282
283            string archive_help_message = _("Application to create archives, like file-roller");
284            string[] archive_more = {"combobox_manual", "mime_association", "mime_available"};
285            string archive_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
286            init_application_combobox (builder, kf, dbus_backend, "archive", "", archive_help_message, archive_more, archive_more_help_message, null);
287
288            string charmap_help_message = _("Charmap application");
289            string[] charmap_more = {""};
290            string charmap_more_help_message = "";
291            init_application(builder, kf, dbus_backend, "charmap", "", charmap_help_message, charmap_more, charmap_more_help_message, null);
292
293            string calculator_help_message = _("Calculator application");
294            string[] calculator_more = {""};
295            string calculator_more_help_message = "";
296            init_application(builder, kf, dbus_backend, "calculator", "", calculator_help_message, calculator_more, calculator_more_help_message, null);
297
298            string spreadsheet_help_message = _("Application to create spreedsheet, like gnumeric");
299            string[] spreadsheet_more = {"combobox_manual", "mime_association", "mime_available"};
300            string spreadsheet_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
301            init_application_combobox (builder, kf, dbus_backend, "spreadsheet", "", spreadsheet_help_message, spreadsheet_more, spreadsheet_more_help_message, null);
302
303            string bittorent_help_message = _("Application to manage bittorent, like transmission");
304            string[] bittorent_more = {"combobox_manual", "mime_association", "mime_available"};
305            string bittorent_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
306            init_application_combobox (builder, kf, dbus_backend, "bittorent", "", bittorent_help_message, bittorent_more, bittorent_more_help_message, null);
307
308            string document_help_message = _("Application to manage office text, like abiword");
309            string[] document_more = {"combobox_manual", "mime_association", "mime_available"};
310            string document_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
311            init_application_combobox (builder, kf, dbus_backend, "document", "", document_help_message, document_more, document_more_help_message, null);
312
313            string webcam_help_message = _("Application to manage webcam");
314            string[] webcam_more = {""};
315            string webcam_more_help_message = manual_setting_help;
316            init_application(builder, kf, dbus_backend, "webcam", "", webcam_help_message, webcam_more, webcam_more_help_message, null);
317
318            string burn_help_message = _("Application to manage burning CD/DVD utilty ");
319            string[] burn_more = {"combobox_manual", "mime_association", "mime_available"};
320            string burn_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
321            init_application_combobox (builder, kf, dbus_backend, "burn", "", burn_help_message, burn_more, burn_more_help_message, null);
322
323            string notes_help_message = _("Application to manage notes utility");
324            string[] notes_more = {""};
325            string notes_more_help_message = manual_setting_help;
326            init_application(builder, kf, dbus_backend, "notes", "", notes_help_message, notes_more, notes_more_help_message, null);
327
328            string disk_utility_help_message = _("Application to manage disks");
329            string[] disk_utility_more = {""};
330            string disk_utility_more_help_message = manual_setting_help;
331            init_application(builder, kf, dbus_backend, "disk_utility", "", disk_utility_help_message, disk_utility_more, disk_utility_more_help_message, null);
332
333            string tasks_help_message = _("Application to monitor tasks running on your system");
334            string[] tasks_more = {"combobox_manual", "mime_association", "mime_available"};
335            string tasks_more_help_message = manual_setting_help + mime_association_help + mime_available_help;
336            init_application_combobox (builder, kf, dbus_backend, "tasks", "", tasks_help_message, tasks_more, tasks_more_help_message, null);
337
338            string lock_manager_help_message = _("Application to lock your screen");
339            string[] lock_manager_more = {""};
340            string lock_manager_more_help_message = manual_setting_help;
341            init_application(builder, kf, dbus_backend, "lock_manager", "", lock_manager_help_message, lock_manager_more, lock_manager_more_help_message, null);
342
343            string audio_manager_help_message = _("Managing your audio configuration");
344            string[] audio_manager_more = {""};
345            string audio_manager_more_help_message = manual_setting_help;
346            init_application(builder, kf, dbus_backend, "audio_manager", "", audio_manager_help_message, audio_manager_more, audio_manager_more_help_message, null);
347
348            string workspace_manager_help_message = _("Managing your workspace configuration");
349            string[] workspace_manager_more = {""};
350            string workspace_manager_more_help_message = manual_setting_help;
351            init_application(builder, kf, dbus_backend, "workspace_manager", "", workspace_manager_help_message, workspace_manager_more, workspace_manager_more_help_message, null);
352
353            string quit_manager_help_message = _("Managing the application to quit your session");
354            string[] quit_manager_more = {""};
355            string quit_manager_more_help_message = manual_setting_help;
356            init_application(builder, kf, dbus_backend, "quit_manager", "", quit_manager_help_message, quit_manager_more, quit_manager_more_help_message, null);
357
358            string upgrade_manager_help_message = _("Managing the application to update and upgrade your system");
359            string[] upgrade_manager_more = {""};
360            string upgrade_manager_more_help_message = manual_setting_help;
361            init_application(builder, kf, dbus_backend, "upgrade_manager", "", upgrade_manager_help_message, upgrade_manager_more, upgrade_manager_more_help_message, null);
362
363            string clipboard_help_message = _("Managing clipboard support");
364            string[] clipboard_more = {""};
365            string clipboard_more_help_message = manual_setting_help;
366            init_application(builder, kf, dbus_backend, "clipboard", "", clipboard_help_message, clipboard_more, clipboard_more_help_message, null);
367
368            string security_help_message = _("Managing keyring support.\nStandard options available \"gnome\" for gnome-keyring support  or \"ssh-agent\" for ssh-agent support");
369            string[] security_more = {""};
370            string security_more_help_message = manual_setting_help;
371            init_application(builder, kf, dbus_backend, "keyring", "", security_help_message, security_more, security_more_help_message, null);
372
373            string a11y_help_message = _("Managing support for accessibility.\nStardart option are gnome, for stardart gnome support.");
374            string[] a11y_more = {""};
375            string a11y_more_help_message = manual_setting_help;
376            init_application(builder, kf, dbus_backend, "a11y", "", a11y_help_message, a11y_more, a11y_more_help_message, null);
377
378            string proxy_manager_help_message = _("Managing proxy support");
379            string[] proxy_manager_more = {""};
380            string proxy_manager_more_help_message = manual_setting_help;
381            init_application(builder, kf, dbus_backend, "proxy_manager", "", proxy_manager_help_message, proxy_manager_more, proxy_manager_more_help_message, null);
382
383            string xrandr_help_message = _("Managing XRandr parameters. Use a command like xrandr --something");
384            string[] xrandr_more = {""};
385            string xrandr_more_help_message = manual_setting_help;
386            init_application(builder, kf, dbus_backend, "xrandr", "", xrandr_help_message, xrandr_more, xrandr_more_help_message, null);
387
388            /* TODO Adapat to be generic ? A bit too complex for now */
389            var disable_autostart_combobox = new Gtk.ComboBox();
390            string[] disable_autostart_commands = { "no", "config-only", "all"};
391            string disable_autostart_default = dbus_backend.Get("disable_autostart", "");
392            disable_autostart_combobox = ui_combobox_init(  builder,
393                                                            "disable_autostart_combobox",
394                                                            disable_autostart_commands,
395                                                            null,
396                                                            disable_autostart_default);
397
398            dbus_backend.Set("disable_autostart", "", return_combobox_text(disable_autostart_combobox));
399            var auto_vbox = builder.get_object("manual_autostart_vbox") as Gtk.VBox;
400            var running_apps = builder.get_object("running_apps_vbox") as Gtk.VBox;
401
402            var known_apps_box = builder.get_object("autostart_known_box") as Gtk.HBox;
403            var known_apps =  builder.get_object("autostart_treeview") as Gtk.TreeView;
404
405            init_list_view(known_apps);
406            load_autostart(Environment.get_variable("XDG_CURRENT_DESKTOP"));
407            known_apps.set_model (get_autostart_list ());
408#if USE_GTK2
409            known_apps_box.hide_all();
410#endif
411#if USE_GTK3
412            known_apps_box.hide();
413#endif
414
415            disable_autostart_combobox.changed.connect (() => {
416                if (return_combobox_text(disable_autostart_combobox) == "all")
417                {
418#if USE_GTK2
419                    auto_vbox.hide_all();
420                    running_apps.hide_all();
421#endif
422#if USE_GTK3
423                    auto_vbox.hide();
424                    running_apps.hide();
425#endif
426                }
427                else
428                {
429                    running_apps.show_all();
430                    auto_vbox.show_all();
431                }
432
433                if (return_combobox_text(disable_autostart_combobox) == "no")
434                {
435                    known_apps_box.show_all();
436                }
437                else
438                {
439#if USE_GTK2
440                    known_apps_box.hide_all();
441#endif
442#if USE_GTK3
443                    known_apps_box.hide();
444#endif
445                }
446                dbus_backend.Set("disable_autostart", "", return_combobox_text(disable_autostart_combobox));
447            });
448
449            /* TODO Make this generic */
450            /* Note using glade + Vala for checkbutton doesnt work, so we have to create it in the code */
451            var upstart_session_checkbutton = new Gtk.CheckButton.with_label ("Upstart ");
452            var upstart_session_hbox = builder.get_object ("upstart_session_hbox") as Gtk.HBox;
453            upstart_session_hbox.add(upstart_session_checkbutton);
454
455            if (dbus_backend.Get("upstart_user_session", "") == "true")
456            {
457                upstart_session_checkbutton.set_active(true);
458            }
459            else
460            {
461                upstart_session_checkbutton.set_active(false);
462            }
463
464            upstart_session_checkbutton.toggled.connect (() => {
465                if (upstart_session_checkbutton.get_active())
466                {
467                    dbus_backend.Set("upstart_user_session", "", "true");
468                }
469                else
470                {
471                    dbus_backend.Set("upstart_user_session", "", "false");
472                }
473            });
474
475            /* Keymap init */
476            var keymap_mode_combobox = new Gtk.ComboBox();
477            string[] keymap_mode_commands = { "", "user"};
478            string keymap_mode_default = dbus_backend.KeymapGet("mode", null);
479            keymap_mode_combobox = ui_combobox_init(    builder,
480                                                        "keymap_mode_combobox",
481                                                        keymap_mode_commands,
482                                                        null,
483                                                        keymap_mode_default);
484
485            var keymap_model_entry = builder.get_object("keymap_model_entry") as Gtk.Entry;
486            keymap_model_entry.set_text(dbus_backend.KeymapGet("model", null));
487
488            var keymap_layout_entry = builder.get_object("keymap_layout_entry") as Gtk.Entry;
489            keymap_layout_entry.set_text(dbus_backend.KeymapGet("layout", null));
490
491            var keymap_variant_entry = builder.get_object("keymap_variant_entry") as Gtk.Entry;
492            keymap_variant_entry.set_text(dbus_backend.KeymapGet("variant", null));
493
494            var keymap_options_entry = builder.get_object("keymap_options_entry") as Gtk.Entry;
495            keymap_options_entry.set_text(dbus_backend.KeymapGet("options", null));
496
497            var keymap_apply_button = builder.get_object("keymap_apply") as Gtk.Button;
498            keymap_apply_button.clicked.connect (() => {
499                message ("Click !");
500                dbus_backend.KeymapSet("mode", null, return_combobox_text(keymap_mode_combobox));
501                dbus_backend.KeymapSet("model", null, keymap_model_entry.get_text());
502                dbus_backend.KeymapSet("layout", null, keymap_layout_entry.get_text());
503                dbus_backend.KeymapSet("variant", null, keymap_variant_entry.get_text());
504                dbus_backend.KeymapSet("options", null, keymap_options_entry.get_text());
505            });
506
507            var keymap_reload_button = builder.get_object("keymap_reload") as Gtk.Button;
508            keymap_reload_button.clicked.connect (() => {
509                dbus_backend.KeymapActivate();
510            });
511
512            /* Laptop mode */
513            var laptop_mode_combobox = new Gtk.ComboBox();
514            string[] laptop_mode_commands = { "no", "yes", "unknown"};
515            string laptop_mode_default = dbus_backend.StateGet("laptop_mode", null);
516            laptop_mode_combobox = ui_combobox_init(  builder,
517                                                      "laptop_mode_combobox",
518                                                      laptop_mode_commands,
519                                                      null,
520                                                      laptop_mode_default);
521
522            laptop_mode_combobox.changed.connect (() => {
523                dbus_backend.StateSet("laptop_mode", null, return_combobox_text(laptop_mode_combobox));
524            });
525
526            /* Dbus */
527            var dbus_gnome_checkbutton = new Gtk.CheckButton.with_label ("Gnome");
528            var dbus_vbox = builder.get_object ("dbus_vbox") as Gtk.VBox;
529
530            dbus_vbox.add(dbus_gnome_checkbutton);
531
532            if (dbus_backend.DbusGet("gnome", null) == "true")
533            {
534                dbus_gnome_checkbutton.set_active(true);
535            }
536            else
537            {
538                dbus_gnome_checkbutton.set_active(false);
539            }
540
541            dbus_gnome_checkbutton.toggled.connect (() => {
542                message ("Click !");
543                if (dbus_gnome_checkbutton.get_active())
544                {
545                    dbus_backend.DbusSet("gnome", null, "true");
546                }
547                else
548                {
549                    dbus_backend.DbusSet("gnome", null, "false");
550                }
551            });
552
553            /* Environment */
554            var environment_type_combobox = new Gtk.ComboBox();
555            string[] environment_type_commands = { "", "lubuntu"};
556            string environment_type_default = dbus_backend.EnvironmentGet("type", null);
557            environment_type_combobox = ui_combobox_init(   builder,
558                                                            "environment_type_combobox",
559                                                            environment_type_commands,
560                                                            null,
561                                                            environment_type_default);
562
563            environment_type_combobox.changed.connect (() => {
564                dbus_backend.EnvironmentSet("type", null, return_combobox_text(environment_type_combobox));
565            });
566
567            var enviroment_menu_prefix_entry = builder.get_object("environment_menu_prefix_entry") as Gtk.Entry;
568            enviroment_menu_prefix_entry.set_text(dbus_backend.EnvironmentGet("menu_prefix", null));
569
570            var env_apply_button = builder.get_object("env_apply") as Gtk.Button;
571            env_apply_button.clicked.connect (() => {
572                message ("Click !");
573                dbus_backend.EnvironmentSet("menu_prefix", null, enviroment_menu_prefix_entry.get_text());
574            });
575        }
576    }
577
578    public static int main(string[] args)
579    {
580        Intl.textdomain(GETTEXT_PACKAGE);
581        Intl.bind_textdomain_codeset(GETTEXT_PACKAGE, "utf-8");
582        /* Init GTK */
583        Gtk.init (ref args);
584
585
586        /* Log on .log file */
587        string log_directory = Path.build_filename(Environment.get_user_cache_dir(), "lxsession-default-apps");
588        var dir_log = File.new_for_path (log_directory);
589
590        string log_path = Path.build_filename(log_directory, "run.log");
591
592        message ("log directory: %s",log_directory);
593        message ("log path: %s",log_path);
594
595        if (!dir_log.query_exists ())
596        {
597            try
598            {
599                dir_log.make_directory_with_parents();
600            }
601            catch (GLib.Error e)
602            {
603                GLib.stderr.printf ("Could not write log: %s\n", e.message);
604            }
605        }
606
607        int fint;
608        fint = open (log_path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
609        dup2 (fint, STDOUT_FILENO);
610        dup2 (fint, STDERR_FILENO);
611        close(fint);
612
613        /* Update the database before anything */
614		UpdateWindows app = new UpdateWindows ();
615		app.show_all ();
616
617        /* start main loop */
618        Gtk.main ();
619
620
621        return 0;
622    }
623}
624