bee826d3804b21dda9222f18b5d3af2c1a4dd6fa
[debian/lxdm.git] / src / config.c
1 /*
2 * lxdm.c - main entry of lxdm
3 *
4 * Copyright 2009 dgod <dgod.osa@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <gtk/gtk.h>
27 #include <glib/gi18n.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <pwd.h>
31 #include <unistd.h>
32
33 #define CONFIG_UI_FILE LXDM_DATA_DIR"/config.ui"
34 //#define CONFIG_UI_FILE "../data/config.ui"
35 #define FACES_DIR "/usr/share/pixmaps/faces"
36
37 #define ROW_SPAN 6
38
39 GtkBuilder *builder;
40 GKeyFile *config;
41 int dirty;
42 char *user_name;
43 struct passwd *user;
44 gboolean root;
45 char *theme_name;
46 char *theme_dir;
47 char *ui_nobody;
48 GtkWidget *photo_popup;
49
50 void prepare_user(void)
51 {
52 root=getuid()==0;
53 if(!user_name)
54 {
55 if(!root)
56 user_name=getenv("USER");
57 if(!user_name)
58 user_name=getenv("SUDO_USER");
59 if(!user_name)
60 user_name=getenv("USER");
61 if(!user_name)
62 exit(1);
63 }
64 user=getpwnam(user_name);
65 if(!user)
66 {
67 exit(1);
68 }
69 }
70
71 void prepare_config(void)
72 {
73 config=g_key_file_new();
74 g_key_file_load_from_file(config,CONFIG_FILE,G_KEY_FILE_KEEP_COMMENTS,NULL);
75 theme_name=g_key_file_get_string(config,"display", "theme", NULL);
76 theme_dir=g_build_filename(LXDM_DATA_DIR "/themes", theme_name, NULL);
77
78 ui_nobody = g_build_filename(theme_dir, "nobody.png", NULL);
79 if( !g_file_test(ui_nobody, G_FILE_TEST_EXISTS) )
80 {
81 g_free(ui_nobody);
82 ui_nobody = NULL;
83 }
84 }
85
86 void popup_menu_below_button (GtkMenu *menu,
87 gint *x,
88 gint *y,
89 gboolean *push_in,
90 GtkWidget *button)
91 {
92 GtkRequisition menu_req;
93 GtkTextDirection direction;
94 GtkAllocation allocation;
95
96 #if GTK_CHECK_VERSION(3,0,0)
97 gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &menu_req);
98 #else
99 gtk_widget_size_request(GTK_WIDGET(menu),&menu_req);
100 #endif
101
102 direction = gtk_widget_get_direction (button);
103
104 gdk_window_get_origin (gtk_widget_get_window (button), x, y);
105 gtk_widget_get_allocation (button, &allocation);
106 *x += allocation.x;
107 *y += allocation.y + allocation.height;
108
109 if (direction == GTK_TEXT_DIR_LTR)
110 *x += MAX (allocation.width - menu_req.width, 0);
111 else if (menu_req.width > allocation.width)
112 *x -= menu_req.width - allocation.width;
113
114 *push_in = TRUE;
115 }
116
117 static gboolean image_file_valid(const char *filename)
118 {
119 GdkPixbuf *pixbuf;
120 pixbuf=gdk_pixbuf_new_from_file(filename,NULL);
121 if(pixbuf) g_object_unref(pixbuf);
122 return pixbuf?TRUE:FALSE;
123 }
124
125 static void update_face_image(GtkWidget *w)
126 {
127 GdkPixbuf *pixbuf;
128 char *path=g_build_filename(user->pw_dir,".face",NULL);
129 pixbuf=gdk_pixbuf_new_from_file_at_scale(path,48,48,FALSE,NULL);
130 g_free(path);
131 if(!pixbuf && ui_nobody)
132 pixbuf=gdk_pixbuf_new_from_file_at_scale(ui_nobody,48,48,FALSE,NULL);
133 if(!pixbuf)
134 pixbuf=gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
135 "avatar-default", 48,GTK_ICON_LOOKUP_FORCE_SIZE,NULL);
136 if(pixbuf)
137 {
138 gtk_image_set_from_pixbuf(GTK_IMAGE(w),pixbuf);
139 g_object_unref(pixbuf);
140 }
141 }
142
143 static void set_face_file(const char *filename)
144 {
145 GtkWidget *w;
146 if(filename)
147 {
148 gchar *contents;
149 gsize length;
150 GdkPixbuf *pixbuf;
151 pixbuf=gdk_pixbuf_new_from_file(filename,NULL);
152 if(!pixbuf) return;
153 g_object_unref(pixbuf);
154 if(g_file_get_contents(filename,&contents,&length,NULL))
155 {
156 gchar *path=g_build_filename(user->pw_dir,".face",NULL);
157 g_file_set_contents(path,contents,length,NULL);
158 chown(path,user->pw_uid,user->pw_gid);
159 g_free(path);
160 }
161 }
162 else
163 {
164 gchar *path=g_build_filename(user->pw_dir,".face",NULL);
165 unlink(path);
166 g_free(path);
167 }
168 w=(GtkWidget*)gtk_builder_get_object(builder,"user-icon-image");
169 update_face_image(w);
170 }
171
172 static void stock_icon_selected (GtkMenuItem *menuitem)
173 {
174 const char *filename;
175 filename = g_object_get_data (G_OBJECT (menuitem), "filename");
176 set_face_file(filename);
177 }
178
179 static GtkWidget *menu_item_for_filename(const char *filename)
180 {
181 GtkWidget *image, *menuitem;
182 GFile *file;
183 GIcon *icon;
184
185 file = g_file_new_for_path (filename);
186 icon = g_file_icon_new (file);
187 g_object_unref (file);
188 image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
189 g_object_unref (icon);
190
191 menuitem = gtk_menu_item_new ();
192 gtk_container_add (GTK_CONTAINER (menuitem), image);
193 gtk_widget_show_all (menuitem);
194
195 g_object_set_data_full (G_OBJECT (menuitem), "filename",
196 g_strdup (filename), (GDestroyNotify) g_free);
197 g_signal_connect (G_OBJECT (menuitem), "activate",
198 G_CALLBACK (stock_icon_selected), NULL);
199
200 return menuitem;
201 }
202
203 static void
204 on_photo_popup_unmap (GtkWidget *popup_menu,
205 GtkWidget *popup_button)
206 {
207 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (popup_button), FALSE);
208 }
209
210 static void
211 update_preview (GtkFileChooser *chooser)
212 {
213 gchar *uri;
214
215 uri = gtk_file_chooser_get_preview_filename(chooser);
216
217 if (uri)
218 {
219 GdkPixbuf *pixbuf = NULL;
220 GtkWidget *preview;
221
222 preview = gtk_file_chooser_get_preview_widget (chooser);
223
224 pixbuf=gdk_pixbuf_new_from_file_at_scale(uri,96,96,TRUE,NULL);
225
226 gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
227 GTK_RESPONSE_ACCEPT,
228 (pixbuf != NULL));
229
230 if (pixbuf != NULL) {
231 gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
232 g_object_unref (pixbuf);
233 }
234 else {
235 gtk_image_set_from_stock (GTK_IMAGE (preview),
236 GTK_STOCK_DIALOG_QUESTION,
237 GTK_ICON_SIZE_DIALOG);
238 }
239
240 g_free (uri);
241 }
242
243 gtk_file_chooser_set_preview_widget_active (chooser, TRUE);
244 }
245
246 static void file_icon_selected (GtkMenuItem *menuitem)
247 {
248 gint res;
249 GtkWidget *w;
250 const gchar *folder;
251 folder = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
252 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-image-chooser");
253 if(folder)
254 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(w),folder);
255 g_signal_connect(w,"update-preview",G_CALLBACK(update_preview),NULL);
256 res=gtk_dialog_run(GTK_DIALOG(w));
257 if(res==GTK_RESPONSE_ACCEPT)
258 {
259 char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(w));
260 set_face_file(filename);
261 g_free(filename);
262 }
263 gtk_widget_hide(GTK_WIDGET(w));
264 }
265
266 void on_user_icon_toggled(GtkToggleButton *togglebutton,gpointer user_data)
267 {
268 if(!photo_popup)
269 {
270 gboolean added_faces=TRUE;
271 GtkWidget *menu,*menuitem;
272 int x=0,y=0;
273 GDir *dir;
274 const char *face;
275 menu=gtk_menu_new();
276
277 dir=g_dir_open(FACES_DIR,0,NULL);
278 if(dir) while((face=g_dir_read_name(dir))!=NULL)
279 {
280 char *path=g_build_filename(FACES_DIR,face,NULL);
281 menuitem=menu_item_for_filename(path);
282 g_free(path);
283 gtk_menu_attach (GTK_MENU (menu), GTK_WIDGET (menuitem),
284 x, x + 1, y, y + 1);
285 gtk_widget_show (menuitem);
286 x++;
287 if (x >= ROW_SPAN - 1)
288 {
289 y++;
290 x = 0;
291 }
292 added_faces = TRUE;
293 }
294 if(added_faces)
295 {
296 GtkWidget *image = gtk_image_new_from_icon_name("avatar-default", GTK_ICON_SIZE_DIALOG);
297 menuitem = gtk_menu_item_new ();
298 gtk_container_add (GTK_CONTAINER (menuitem), image);
299 gtk_widget_show_all (menuitem);
300 gtk_menu_attach (GTK_MENU (menu), GTK_WIDGET (menuitem),
301 x, x + 1, y, y + 1);
302 g_signal_connect (G_OBJECT (menuitem), "activate",
303 G_CALLBACK (stock_icon_selected), NULL);
304 gtk_widget_show (menuitem);
305 y++;
306
307 menuitem = gtk_separator_menu_item_new ();
308 gtk_menu_attach (GTK_MENU (menu), GTK_WIDGET (menuitem),
309 0, ROW_SPAN - 1, y, y + 1);
310 gtk_widget_show (menuitem);
311 y++;
312 }
313 menuitem=gtk_menu_item_new_with_label(_("Browse for more pictures..."));
314 gtk_menu_attach (GTK_MENU (menu), GTK_WIDGET (menuitem),
315 0, ROW_SPAN - 1, y, y + 1);
316 g_signal_connect (G_OBJECT (menuitem), "activate",
317 G_CALLBACK (file_icon_selected), NULL);
318 gtk_widget_show (menuitem);
319 photo_popup=menu;
320
321 g_signal_connect (menu, "unmap",G_CALLBACK (on_photo_popup_unmap), togglebutton);
322 }
323 if(gtk_toggle_button_get_active(togglebutton))
324 {
325 gtk_menu_popup(GTK_MENU(photo_popup),NULL,NULL,
326 (GtkMenuPositionFunc) popup_menu_below_button,
327 GTK_WIDGET(togglebutton),
328 0, gtk_get_current_event_time ());
329 }
330 else
331 {
332 gtk_menu_popdown(GTK_MENU(photo_popup));
333 }
334 }
335
336 static gboolean
337 on_popup_button_button_pressed (GtkToggleButton *button,
338 GdkEventButton *event)
339 {
340 if (event->button == 1) {
341 if (!gtk_widget_get_visible (photo_popup)) {
342 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
343 } else {
344 gtk_menu_popdown (GTK_MENU (photo_popup));
345 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
346 }
347
348 return TRUE;
349 }
350
351 return FALSE;
352 }
353
354 void prepare_user_icon(GtkBuilder *builder)
355 {
356 GtkWidget *w;
357 w=(GtkWidget*)gtk_builder_get_object(builder,"user-icon-image");
358 update_face_image(w);
359 w=(GtkWidget*)gtk_builder_get_object(builder,"user-icon-button");
360 g_signal_connect(w,"toggled",G_CALLBACK(on_user_icon_toggled),NULL);
361 }
362
363 void prepare_user_name(GtkBuilder *builder)
364 {
365 GtkWidget *w;
366 w=(GtkWidget*)gtk_builder_get_object(builder,"user-name");
367 gtk_label_set_text(GTK_LABEL(w),user_name);
368 }
369
370 void on_user_autologin_toggled(GtkToggleButton *togglebutton,gpointer user_data)
371 {
372 if(gtk_toggle_button_get_active(togglebutton))
373 g_key_file_set_string(config,"base","autologin",user_name);
374 else
375 g_key_file_remove_key(config,"base","autologin",NULL);
376 dirty++;
377 }
378
379 void prepare_user_autologin(GtkBuilder *builder)
380 {
381 char *name;
382 GtkWidget *w;
383 w=(GtkWidget*)gtk_builder_get_object(builder,"user-autologin");
384 if(!root) gtk_widget_set_sensitive(w,FALSE);
385 g_signal_connect(w,"toggled",G_CALLBACK(on_user_autologin_toggled),NULL);
386 name=g_key_file_get_string(config,"base","autologin",NULL);
387 if(!name) return;
388 if(!strcmp(name,user_name))
389 {
390 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),TRUE);
391 }
392 g_free(name);
393 }
394
395 static void on_bg_type_toggled(void)
396 {
397 GtkWidget *w;
398 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-image-button");
399 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
400 {
401 char *s;
402 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-file");
403 s=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(w));
404 if(s)
405 {
406 if(!image_file_valid(s))
407 {
408 g_free(s);
409 s=g_key_file_get_string(config,"display","bg",NULL);
410 if(s)
411 {
412 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w),s);
413 g_free(s);
414 }
415 return;
416 }
417 g_key_file_set_string(config,"display","bg",s);
418 g_free(s);
419 }
420 }
421 else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder,"lxdm-bg-color-button"))))
422 {
423 gchar *s;
424 GdkColor color;
425 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-color");
426 gtk_color_button_get_color(GTK_COLOR_BUTTON(w),&color);
427 s=gdk_color_to_string(&color);
428 g_key_file_set_string(config,"display","bg",s);
429 g_free(s);
430 }
431 else
432 {
433 g_key_file_remove_key(config,"display","bg",NULL);
434 }
435 dirty++;
436 }
437
438 void prepare_bg(GtkBuilder *builder)
439 {
440 char *s;
441 GtkWidget *w;
442 s=g_key_file_get_string(config,"display","bg",NULL);
443 if(!s)
444 {
445 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-default");
446 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),TRUE);
447 }
448 else if(s[0]=='#')
449 {
450 GdkColor color;
451 gdk_color_parse(s,&color);
452 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-color");
453 gtk_color_button_set_color(GTK_COLOR_BUTTON(w),&color);
454 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-color-button");
455 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),TRUE);
456 }
457 else
458 {
459 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-file");
460 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w),s);
461 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-image-button");
462 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),TRUE);
463 }
464 g_free(s);
465 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-image-button");
466 if(!root) gtk_widget_set_sensitive(w,FALSE);
467 g_signal_connect(w,"toggled",on_bg_type_toggled,NULL);
468 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-color-button");
469 if(!root) gtk_widget_set_sensitive(w,FALSE);
470 g_signal_connect(w,"toggled",on_bg_type_toggled,NULL);
471 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-file");
472 if(!root) gtk_widget_set_sensitive(w,FALSE);
473 g_signal_connect(w,"file-set",G_CALLBACK(on_bg_type_toggled),NULL);
474 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-color");
475 if(!root) gtk_widget_set_sensitive(w,FALSE);
476 g_signal_connect(w,"color-set",G_CALLBACK(on_bg_type_toggled),NULL);
477 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-default");
478 if(!root) gtk_widget_set_sensitive(w,FALSE);
479 g_signal_connect(w,"toggled",on_bg_type_toggled,NULL);
480 }
481
482 static void on_enable_pane_toggled(GtkToggleButton *button)
483 {
484 int val;
485 val=gtk_toggle_button_get_active(button);
486 g_key_file_set_integer(config,"display","bottom_pane",val);
487 GtkWidget *w;
488 w=(GtkWidget*)gtk_builder_get_object(builder,"vbox2");
489 gtk_widget_set_sensitive(w,val?TRUE:FALSE);
490 dirty++;
491 }
492
493 static void prepare_enable_pane(GtkBuilder *builder)
494 {
495 gint val;
496 GtkWidget *w;
497 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-enable-bottom-pane");
498 val=g_key_file_get_integer(config,"display","bottom_pane",NULL);
499 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
500 if(!root) gtk_widget_set_sensitive(w,FALSE);
501 g_signal_connect(w,"toggled",G_CALLBACK(on_enable_pane_toggled),NULL);
502 }
503
504 static void prepare_vbox2(GtkBuilder *builder)
505 {
506 gint val;
507 GtkWidget *w;
508 w=(GtkWidget*)gtk_builder_get_object(builder,"vbox2");
509 val=g_key_file_get_integer(config,"display","bottom_pane",NULL);
510 if(!root)
511 {
512 gtk_widget_set_sensitive(w,FALSE);
513 }
514 else
515 {
516 gtk_widget_set_sensitive(w,val?TRUE:FALSE);
517 }
518 }
519
520 static void on_transparent_pane_toggled(GtkToggleButton *button)
521 {
522 int val;
523 val=gtk_toggle_button_get_active(button);
524 g_key_file_set_integer(config,"display","transparent_pane",val);
525 dirty++;
526 }
527
528 static void prepare_transparent_pane(GtkBuilder *builder)
529 {
530 gint val;
531 GtkWidget *w;
532 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-transparent-pane");
533 val=g_key_file_get_integer(config,"display","transparent_pane",NULL);
534 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
535 if(!root) gtk_widget_set_sensitive(w,FALSE);
536 g_signal_connect(w,"toggled",G_CALLBACK(on_transparent_pane_toggled),NULL);
537 }
538
539 static void on_hide_sessions_toggled(GtkToggleButton *button)
540 {
541 int val;
542 val=gtk_toggle_button_get_active(button);
543 g_key_file_set_integer(config,"display","hide_sessions",val);
544 dirty++;
545 }
546
547 static void prepare_hide_sessions(GtkBuilder *builder)
548 {
549 gint val;
550 GtkWidget *w;
551 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-hide-sessions");
552 val=g_key_file_get_integer(config,"display","hide_sessions",NULL);
553 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
554 if(!root) gtk_widget_set_sensitive(w,FALSE);
555 g_signal_connect(w,"toggled",G_CALLBACK(on_hide_sessions_toggled),NULL);
556 }
557
558 static void on_show_lang_toggled(GtkToggleButton *button)
559 {
560 int val;
561 val=gtk_toggle_button_get_active(button);
562 g_key_file_set_integer(config,"display","lang",val);
563 dirty++;
564 }
565
566 static void prepare_show_lang(GtkBuilder *builder)
567 {
568 gint val;
569 GtkWidget *w;
570 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-show-lang");
571 val=g_key_file_get_integer(config,"display","lang",NULL);
572 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
573 if(!root) gtk_widget_set_sensitive(w,FALSE);
574 g_signal_connect(w,"toggled",G_CALLBACK(on_show_lang_toggled),NULL);
575 }
576
577 static void on_show_keyboard_toggled(GtkToggleButton *button)
578 {
579 int val;
580 val=gtk_toggle_button_get_active(button);
581 g_key_file_set_integer(config,"display","keyboard",val);
582 dirty++;
583 }
584
585 static void prepare_show_keyboard(GtkBuilder *builder)
586 {
587 gint val;
588 GtkWidget *w;
589 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-show-keyboard");
590 val=g_key_file_get_integer(config,"display","keyboard",NULL);
591 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
592 if(!root) gtk_widget_set_sensitive(w,FALSE);
593 g_signal_connect(w,"toggled",G_CALLBACK(on_show_keyboard_toggled),NULL);
594 }
595
596 static void on_hide_exit_toggled(GtkToggleButton *button)
597 {
598 int val;
599 val=gtk_toggle_button_get_active(button);
600 g_key_file_set_integer(config,"display","hide_exit",val);
601 dirty++;
602 }
603
604 static void prepare_hide_exit(GtkBuilder *builder)
605 {
606 gint val;
607 GtkWidget *w;
608 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-hide-exit");
609 val=g_key_file_get_integer(config,"display","hide_exit",NULL);
610 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
611 if(!root) gtk_widget_set_sensitive(w,FALSE);
612 g_signal_connect(w,"toggled",G_CALLBACK(on_hide_exit_toggled),NULL);
613 }
614
615 static void on_hide_time_toggled(GtkToggleButton *button)
616 {
617 int val;
618 val=gtk_toggle_button_get_active(button);
619 g_key_file_set_integer(config,"display","hide_time",val);
620 dirty++;
621 }
622
623 static void prepare_hide_time(GtkBuilder *builder)
624 {
625 gint val;
626 GtkWidget *w;
627 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-hide-time");
628 val=g_key_file_get_integer(config,"display","hide_time",NULL);
629 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
630 if(!root) gtk_widget_set_sensitive(w,FALSE);
631 g_signal_connect(w,"toggled",G_CALLBACK(on_hide_time_toggled),NULL);
632 }
633
634 static void on_show_userlist_toggled(GtkToggleButton *button)
635 {
636 int val;
637 val=gtk_toggle_button_get_active(button);
638 g_key_file_set_integer(config,"userlist","disable",!val);
639 dirty++;
640 }
641
642 static void prepare_show_userlist(GtkBuilder *builder)
643 {
644 gint val;
645 GtkWidget *w;
646 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-user-list");
647 val=g_key_file_get_integer(config,"userlist","disable",NULL);
648 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?FALSE:TRUE);
649 if(!root) gtk_widget_set_sensitive(w,FALSE);
650 g_signal_connect(w,"toggled",G_CALLBACK(on_show_userlist_toggled),NULL);
651 }
652
653 GtkDialog *dialog_create(void)
654 {
655 GtkDialog *dlg;
656
657 builder=gtk_builder_new();
658 gtk_builder_add_from_file(builder,CONFIG_UI_FILE,NULL);
659 dlg=(GtkDialog*)gtk_builder_get_object(builder,"lxdm-config-dlg");
660 if(!dlg) return NULL;
661 prepare_user_icon(builder);
662 prepare_user_name(builder);
663 prepare_user_autologin(builder);
664 prepare_bg(builder);
665 prepare_enable_pane(builder);
666 prepare_vbox2(builder);
667 prepare_transparent_pane(builder);
668 prepare_hide_sessions(builder);
669 prepare_show_lang(builder);
670 prepare_show_keyboard(builder);
671 prepare_hide_exit(builder);
672 prepare_hide_time(builder);
673 prepare_show_userlist(builder);
674
675 return dlg;
676 }
677
678 static GOptionEntry entries[] =
679 {
680 { "user", 0, 0, G_OPTION_ARG_STRING, &user_name, "user name", NULL },
681 { NULL }
682 };
683
684 int main(int arc,char *arg[])
685 {
686 GError *error = NULL;
687 GOptionContext *context;
688 GtkDialog *dlg;
689
690 context = g_option_context_new ("- lxdm config");
691 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
692 g_option_context_add_group (context, gtk_get_option_group (TRUE));
693 if (!g_option_context_parse (context, &arc, &arg, &error))
694 {
695 g_print ("option parsing failed: %s\n", error->message);
696 exit (1);
697 }
698 prepare_user();
699
700 #if !GTK_CHECK_VERSION(3,0,0)
701 gtk_set_locale();
702 #endif
703 bindtextdomain("lxdm", "/usr/share/locale");
704 textdomain("lxdm");
705
706 gtk_init(&arc,&arg);
707 prepare_config();
708 dlg=dialog_create();
709 if(!dlg) exit(-1);
710 gtk_dialog_run(dlg);
711
712 if(dirty)
713 {
714 gsize length;
715 gchar *s=g_key_file_to_data(config,&length,NULL);
716 g_file_set_contents(CONFIG_FILE,s,length,NULL);
717 }
718
719 return 0;
720 }