Merging upstream version 0.5.3 (Closes: #805659 CVE-2015-8308).
[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 seteuid(user->pw_uid);
158 setegid(user->pw_gid);
159 g_file_set_contents(path,contents,length,NULL);
160 seteuid(getuid());
161 setegid(getgid());
162 g_free(path);
163 }
164 }
165 else
166 {
167 gchar *path=g_build_filename(user->pw_dir,".face",NULL);
168 seteuid(user->pw_uid);
169 setegid(user->pw_gid);
170 unlink(path);
171 seteuid(getuid());
172 setegid(getgid());
173 g_free(path);
174 }
175 w=(GtkWidget*)gtk_builder_get_object(builder,"user-icon-image");
176 update_face_image(w);
177 }
178
179 static void stock_icon_selected (GtkMenuItem *menuitem)
180 {
181 const char *filename;
182 filename = g_object_get_data (G_OBJECT (menuitem), "filename");
183 set_face_file(filename);
184 }
185
186 static GtkWidget *menu_item_for_filename(const char *filename)
187 {
188 GtkWidget *image, *menuitem;
189 GFile *file;
190 GIcon *icon;
191
192 file = g_file_new_for_path (filename);
193 icon = g_file_icon_new (file);
194 g_object_unref (file);
195 image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
196 g_object_unref (icon);
197
198 menuitem = gtk_menu_item_new ();
199 gtk_container_add (GTK_CONTAINER (menuitem), image);
200 gtk_widget_show_all (menuitem);
201
202 g_object_set_data_full (G_OBJECT (menuitem), "filename",
203 g_strdup (filename), (GDestroyNotify) g_free);
204 g_signal_connect (G_OBJECT (menuitem), "activate",
205 G_CALLBACK (stock_icon_selected), NULL);
206
207 return menuitem;
208 }
209
210 static void
211 on_photo_popup_unmap (GtkWidget *popup_menu,
212 GtkWidget *popup_button)
213 {
214 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (popup_button), FALSE);
215 }
216
217 static void
218 update_preview (GtkFileChooser *chooser)
219 {
220 gchar *uri;
221
222 uri = gtk_file_chooser_get_preview_filename(chooser);
223
224 if (uri)
225 {
226 GdkPixbuf *pixbuf = NULL;
227 GtkWidget *preview;
228
229 preview = gtk_file_chooser_get_preview_widget (chooser);
230
231 pixbuf=gdk_pixbuf_new_from_file_at_scale(uri,96,96,TRUE,NULL);
232
233 gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
234 GTK_RESPONSE_ACCEPT,
235 (pixbuf != NULL));
236
237 if (pixbuf != NULL) {
238 gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
239 g_object_unref (pixbuf);
240 }
241 else {
242 gtk_image_set_from_stock (GTK_IMAGE (preview),
243 GTK_STOCK_DIALOG_QUESTION,
244 GTK_ICON_SIZE_DIALOG);
245 }
246
247 g_free (uri);
248 }
249
250 gtk_file_chooser_set_preview_widget_active (chooser, TRUE);
251 }
252
253 static void file_icon_selected (GtkMenuItem *menuitem)
254 {
255 gint res;
256 GtkWidget *w;
257 const gchar *folder;
258 folder = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
259 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-image-chooser");
260 if(folder)
261 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(w),folder);
262 g_signal_connect(w,"update-preview",G_CALLBACK(update_preview),NULL);
263 res=gtk_dialog_run(GTK_DIALOG(w));
264 if(res==GTK_RESPONSE_ACCEPT)
265 {
266 char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(w));
267 set_face_file(filename);
268 g_free(filename);
269 }
270 gtk_widget_hide(GTK_WIDGET(w));
271 }
272
273 void on_user_icon_toggled(GtkToggleButton *togglebutton,gpointer user_data)
274 {
275 if(!photo_popup)
276 {
277 gboolean added_faces=TRUE;
278 GtkWidget *menu,*menuitem;
279 int x=0,y=0;
280 GDir *dir;
281 const char *face;
282 menu=gtk_menu_new();
283
284 dir=g_dir_open(FACES_DIR,0,NULL);
285 if(dir) while((face=g_dir_read_name(dir))!=NULL)
286 {
287 char *path=g_build_filename(FACES_DIR,face,NULL);
288 menuitem=menu_item_for_filename(path);
289 g_free(path);
290 gtk_menu_attach (GTK_MENU (menu), GTK_WIDGET (menuitem),
291 x, x + 1, y, y + 1);
292 gtk_widget_show (menuitem);
293 x++;
294 if (x >= ROW_SPAN - 1)
295 {
296 y++;
297 x = 0;
298 }
299 added_faces = TRUE;
300 }
301 if(added_faces)
302 {
303 GtkWidget *image = gtk_image_new_from_icon_name("avatar-default", GTK_ICON_SIZE_DIALOG);
304 menuitem = gtk_menu_item_new ();
305 gtk_container_add (GTK_CONTAINER (menuitem), image);
306 gtk_widget_show_all (menuitem);
307 gtk_menu_attach (GTK_MENU (menu), GTK_WIDGET (menuitem),
308 x, x + 1, y, y + 1);
309 g_signal_connect (G_OBJECT (menuitem), "activate",
310 G_CALLBACK (stock_icon_selected), NULL);
311 gtk_widget_show (menuitem);
312 y++;
313
314 menuitem = gtk_separator_menu_item_new ();
315 gtk_menu_attach (GTK_MENU (menu), GTK_WIDGET (menuitem),
316 0, ROW_SPAN - 1, y, y + 1);
317 gtk_widget_show (menuitem);
318 y++;
319 }
320 menuitem=gtk_menu_item_new_with_label(_("Browse for more pictures..."));
321 gtk_menu_attach (GTK_MENU (menu), GTK_WIDGET (menuitem),
322 0, ROW_SPAN - 1, y, y + 1);
323 g_signal_connect (G_OBJECT (menuitem), "activate",
324 G_CALLBACK (file_icon_selected), NULL);
325 gtk_widget_show (menuitem);
326 photo_popup=menu;
327
328 g_signal_connect (menu, "unmap",G_CALLBACK (on_photo_popup_unmap), togglebutton);
329 }
330 if(gtk_toggle_button_get_active(togglebutton))
331 {
332 gtk_menu_popup(GTK_MENU(photo_popup),NULL,NULL,
333 (GtkMenuPositionFunc) popup_menu_below_button,
334 GTK_WIDGET(togglebutton),
335 0, gtk_get_current_event_time ());
336 }
337 else
338 {
339 gtk_menu_popdown(GTK_MENU(photo_popup));
340 }
341 }
342
343 static gboolean
344 on_popup_button_button_pressed (GtkToggleButton *button,
345 GdkEventButton *event)
346 {
347 if (event->button == 1) {
348 if (!gtk_widget_get_visible (photo_popup)) {
349 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
350 } else {
351 gtk_menu_popdown (GTK_MENU (photo_popup));
352 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
353 }
354
355 return TRUE;
356 }
357
358 return FALSE;
359 }
360
361 void prepare_user_icon(GtkBuilder *builder)
362 {
363 GtkWidget *w;
364 w=(GtkWidget*)gtk_builder_get_object(builder,"user-icon-image");
365 update_face_image(w);
366 w=(GtkWidget*)gtk_builder_get_object(builder,"user-icon-button");
367 g_signal_connect(w,"toggled",G_CALLBACK(on_user_icon_toggled),NULL);
368 }
369
370 void prepare_user_name(GtkBuilder *builder)
371 {
372 GtkWidget *w;
373 w=(GtkWidget*)gtk_builder_get_object(builder,"user-name");
374 gtk_label_set_text(GTK_LABEL(w),user_name);
375 }
376
377 void on_user_autologin_toggled(GtkToggleButton *togglebutton,gpointer user_data)
378 {
379 if(gtk_toggle_button_get_active(togglebutton))
380 g_key_file_set_string(config,"base","autologin",user_name);
381 else
382 g_key_file_remove_key(config,"base","autologin",NULL);
383 dirty++;
384 }
385
386 void prepare_user_autologin(GtkBuilder *builder)
387 {
388 char *name;
389 GtkWidget *w;
390 w=(GtkWidget*)gtk_builder_get_object(builder,"user-autologin");
391 if(!root) gtk_widget_set_sensitive(w,FALSE);
392 g_signal_connect(w,"toggled",G_CALLBACK(on_user_autologin_toggled),NULL);
393 name=g_key_file_get_string(config,"base","autologin",NULL);
394 if(!name) return;
395 if(!strcmp(name,user_name))
396 {
397 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),TRUE);
398 }
399 g_free(name);
400 }
401
402 static void on_bg_type_toggled(void)
403 {
404 GtkWidget *w;
405 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-image-button");
406 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
407 {
408 char *s;
409 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-file");
410 s=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(w));
411 if(s)
412 {
413 if(!image_file_valid(s))
414 {
415 g_free(s);
416 s=g_key_file_get_string(config,"display","bg",NULL);
417 if(s)
418 {
419 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w),s);
420 g_free(s);
421 }
422 return;
423 }
424 g_key_file_set_string(config,"display","bg",s);
425 g_free(s);
426 }
427 }
428 else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder,"lxdm-bg-color-button"))))
429 {
430 gchar *s;
431 GdkColor color;
432 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-color");
433 gtk_color_button_get_color(GTK_COLOR_BUTTON(w),&color);
434 s=gdk_color_to_string(&color);
435 g_key_file_set_string(config,"display","bg",s);
436 g_free(s);
437 }
438 else
439 {
440 g_key_file_remove_key(config,"display","bg",NULL);
441 }
442 dirty++;
443 }
444
445 void prepare_bg(GtkBuilder *builder)
446 {
447 char *s;
448 GtkWidget *w;
449 s=g_key_file_get_string(config,"display","bg",NULL);
450 if(!s)
451 {
452 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-default");
453 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),TRUE);
454 }
455 else if(s[0]=='#')
456 {
457 GdkColor color;
458 gdk_color_parse(s,&color);
459 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-color");
460 gtk_color_button_set_color(GTK_COLOR_BUTTON(w),&color);
461 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-color-button");
462 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),TRUE);
463 }
464 else
465 {
466 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-file");
467 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w),s);
468 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-image-button");
469 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),TRUE);
470 }
471 g_free(s);
472 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-image-button");
473 if(!root) gtk_widget_set_sensitive(w,FALSE);
474 g_signal_connect(w,"toggled",on_bg_type_toggled,NULL);
475 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-color-button");
476 if(!root) gtk_widget_set_sensitive(w,FALSE);
477 g_signal_connect(w,"toggled",on_bg_type_toggled,NULL);
478 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-file");
479 if(!root) gtk_widget_set_sensitive(w,FALSE);
480 g_signal_connect(w,"file-set",G_CALLBACK(on_bg_type_toggled),NULL);
481 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-color");
482 if(!root) gtk_widget_set_sensitive(w,FALSE);
483 g_signal_connect(w,"color-set",G_CALLBACK(on_bg_type_toggled),NULL);
484 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-bg-default");
485 if(!root) gtk_widget_set_sensitive(w,FALSE);
486 g_signal_connect(w,"toggled",on_bg_type_toggled,NULL);
487 }
488
489 static void on_enable_pane_toggled(GtkToggleButton *button)
490 {
491 int val;
492 val=gtk_toggle_button_get_active(button);
493 g_key_file_set_integer(config,"display","bottom_pane",val);
494 GtkWidget *w;
495 w=(GtkWidget*)gtk_builder_get_object(builder,"vbox2");
496 gtk_widget_set_sensitive(w,val?TRUE:FALSE);
497 dirty++;
498 }
499
500 static void prepare_enable_pane(GtkBuilder *builder)
501 {
502 gint val;
503 GtkWidget *w;
504 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-enable-bottom-pane");
505 val=g_key_file_get_integer(config,"display","bottom_pane",NULL);
506 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
507 if(!root) gtk_widget_set_sensitive(w,FALSE);
508 g_signal_connect(w,"toggled",G_CALLBACK(on_enable_pane_toggled),NULL);
509 }
510
511 static void prepare_vbox2(GtkBuilder *builder)
512 {
513 gint val;
514 GtkWidget *w;
515 w=(GtkWidget*)gtk_builder_get_object(builder,"vbox2");
516 val=g_key_file_get_integer(config,"display","bottom_pane",NULL);
517 if(!root)
518 {
519 gtk_widget_set_sensitive(w,FALSE);
520 }
521 else
522 {
523 gtk_widget_set_sensitive(w,val?TRUE:FALSE);
524 }
525 }
526
527 static void on_transparent_pane_toggled(GtkToggleButton *button)
528 {
529 int val;
530 val=gtk_toggle_button_get_active(button);
531 g_key_file_set_integer(config,"display","transparent_pane",val);
532 dirty++;
533 }
534
535 static void prepare_transparent_pane(GtkBuilder *builder)
536 {
537 gint val;
538 GtkWidget *w;
539 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-transparent-pane");
540 val=g_key_file_get_integer(config,"display","transparent_pane",NULL);
541 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
542 if(!root) gtk_widget_set_sensitive(w,FALSE);
543 g_signal_connect(w,"toggled",G_CALLBACK(on_transparent_pane_toggled),NULL);
544 }
545
546 static void on_hide_sessions_toggled(GtkToggleButton *button)
547 {
548 int val;
549 val=gtk_toggle_button_get_active(button);
550 g_key_file_set_integer(config,"display","hide_sessions",val);
551 dirty++;
552 }
553
554 static void prepare_hide_sessions(GtkBuilder *builder)
555 {
556 gint val;
557 GtkWidget *w;
558 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-hide-sessions");
559 val=g_key_file_get_integer(config,"display","hide_sessions",NULL);
560 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
561 if(!root) gtk_widget_set_sensitive(w,FALSE);
562 g_signal_connect(w,"toggled",G_CALLBACK(on_hide_sessions_toggled),NULL);
563 }
564
565 static void on_show_lang_toggled(GtkToggleButton *button)
566 {
567 int val;
568 val=gtk_toggle_button_get_active(button);
569 g_key_file_set_integer(config,"display","lang",val);
570 dirty++;
571 }
572
573 static void prepare_show_lang(GtkBuilder *builder)
574 {
575 gint val;
576 GtkWidget *w;
577 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-show-lang");
578 val=g_key_file_get_integer(config,"display","lang",NULL);
579 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
580 if(!root) gtk_widget_set_sensitive(w,FALSE);
581 g_signal_connect(w,"toggled",G_CALLBACK(on_show_lang_toggled),NULL);
582 }
583
584 static void on_show_keyboard_toggled(GtkToggleButton *button)
585 {
586 int val;
587 val=gtk_toggle_button_get_active(button);
588 g_key_file_set_integer(config,"display","keyboard",val);
589 dirty++;
590 }
591
592 static void prepare_show_keyboard(GtkBuilder *builder)
593 {
594 gint val;
595 GtkWidget *w;
596 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-show-keyboard");
597 val=g_key_file_get_integer(config,"display","keyboard",NULL);
598 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
599 if(!root) gtk_widget_set_sensitive(w,FALSE);
600 g_signal_connect(w,"toggled",G_CALLBACK(on_show_keyboard_toggled),NULL);
601 }
602
603 static void on_hide_exit_toggled(GtkToggleButton *button)
604 {
605 int val;
606 val=gtk_toggle_button_get_active(button);
607 g_key_file_set_integer(config,"display","hide_exit",val);
608 dirty++;
609 }
610
611 static void prepare_hide_exit(GtkBuilder *builder)
612 {
613 gint val;
614 GtkWidget *w;
615 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-hide-exit");
616 val=g_key_file_get_integer(config,"display","hide_exit",NULL);
617 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
618 if(!root) gtk_widget_set_sensitive(w,FALSE);
619 g_signal_connect(w,"toggled",G_CALLBACK(on_hide_exit_toggled),NULL);
620 }
621
622 static void on_hide_time_toggled(GtkToggleButton *button)
623 {
624 int val;
625 val=gtk_toggle_button_get_active(button);
626 g_key_file_set_integer(config,"display","hide_time",val);
627 dirty++;
628 }
629
630 static void prepare_hide_time(GtkBuilder *builder)
631 {
632 gint val;
633 GtkWidget *w;
634 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-hide-time");
635 val=g_key_file_get_integer(config,"display","hide_time",NULL);
636 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?TRUE:FALSE);
637 if(!root) gtk_widget_set_sensitive(w,FALSE);
638 g_signal_connect(w,"toggled",G_CALLBACK(on_hide_time_toggled),NULL);
639 }
640
641 static void on_show_userlist_toggled(GtkToggleButton *button)
642 {
643 int val;
644 val=gtk_toggle_button_get_active(button);
645 g_key_file_set_integer(config,"userlist","disable",!val);
646 dirty++;
647 }
648
649 static void prepare_show_userlist(GtkBuilder *builder)
650 {
651 gint val;
652 GtkWidget *w;
653 w=(GtkWidget*)gtk_builder_get_object(builder,"lxdm-user-list");
654 val=g_key_file_get_integer(config,"userlist","disable",NULL);
655 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),val?FALSE:TRUE);
656 if(!root) gtk_widget_set_sensitive(w,FALSE);
657 g_signal_connect(w,"toggled",G_CALLBACK(on_show_userlist_toggled),NULL);
658 }
659
660 GtkDialog *dialog_create(void)
661 {
662 GtkDialog *dlg;
663
664 builder=gtk_builder_new();
665 gtk_builder_add_from_file(builder,CONFIG_UI_FILE,NULL);
666 dlg=(GtkDialog*)gtk_builder_get_object(builder,"lxdm-config-dlg");
667 if(!dlg) return NULL;
668 prepare_user_icon(builder);
669 prepare_user_name(builder);
670 prepare_user_autologin(builder);
671 prepare_bg(builder);
672 prepare_enable_pane(builder);
673 prepare_vbox2(builder);
674 prepare_transparent_pane(builder);
675 prepare_hide_sessions(builder);
676 prepare_show_lang(builder);
677 prepare_show_keyboard(builder);
678 prepare_hide_exit(builder);
679 prepare_hide_time(builder);
680 prepare_show_userlist(builder);
681
682 return dlg;
683 }
684
685 static GOptionEntry entries[] =
686 {
687 { "user", 0, 0, G_OPTION_ARG_STRING, &user_name, "user name", NULL },
688 { NULL }
689 };
690
691 int main(int arc,char *arg[])
692 {
693 GError *error = NULL;
694 GOptionContext *context;
695 GtkDialog *dlg;
696
697 context = g_option_context_new ("- lxdm config");
698 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
699 g_option_context_add_group (context, gtk_get_option_group (TRUE));
700 if (!g_option_context_parse (context, &arc, &arg, &error))
701 {
702 g_print ("option parsing failed: %s\n", error->message);
703 exit (1);
704 }
705 prepare_user();
706
707 #if !GTK_CHECK_VERSION(3,0,0)
708 gtk_set_locale();
709 #endif
710 bindtextdomain("lxdm", "/usr/share/locale");
711 textdomain("lxdm");
712
713 gtk_init(&arc,&arg);
714 prepare_config();
715 dlg=dialog_create();
716 if(!dlg) exit(-1);
717 gtk_dialog_run(dlg);
718
719 if(dirty)
720 {
721 gsize length;
722 gchar *s=g_key_file_to_data(config,&length,NULL);
723 g_file_set_contents(CONFIG_FILE,s,length,NULL);
724 }
725
726 return 0;
727 }