summaryrefslogtreecommitdiff
path: root/src/bin/e_int_config_desklock.c
blob: 26ea489cffc4dcbcd78e018c4a9d937eca2828ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
#include "e.h"

#define LOGINBOX_SHOW_ALL_SCREENS	  -1
#define LOGINBOX_SHOW_CURRENT_SCREENS     -2
#define LOGINBOX_SHOW_SPECIFIC_SCREEN	  0

#define BG_LIST_ICON_SIZE_W 32
#define BG_LIST_ICON_SIZE_H 32

#define BG_PREVIEW_W 280
#define BG_PREVIEW_H ((BG_PREVIEW_W * e_zone_current_get(cfd->dia->win->container)->h) / \
		     e_zone_current_get(cfd->dia->win->container)->w)

#define DEF_DESKLOCK_BACKGROUND	"theme_desklock_background"
#define DEF_THEME_BACKGROUND	"theme_background"


static void *_create_data(E_Config_Dialog *cfd);
static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static int  _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object  *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas,
					   E_Config_Dialog_Data *cfdata);

static int  _advanced_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object  *_advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas,
					      E_Config_Dialog_Data *cfdata);


/******************************************************************************************/

static void _e_desklock_passwd_cb_change(void *data, Evas_Object *obj);
static void _e_desklock_cb_show_passwd(void *data, Evas_Object *obj, const char *emission,
				       const char *source);
static int  _e_desklock_zone_num_get();

static void _load_bgs(E_Config_Dialog_Data *cfdata);
static void _ibg_list_cb_bg_selected(void *data);

static void _e_desklock_cb_lb_show_on_all_screens(void *data, Evas_Object *obj,
						  const char *emission, const char *source);
static void _e_desklock_cb_lb_show_on_current_screen(void *data, Evas_Object *obj,
						     const char *emission, const char *source);
static void _e_desklock_cb_lb_show_on_specific_screen(void *data, Evas_Object *obj,
						      const char *emission, const char *source);

#ifdef HAVE_PAM
static void _e_desklock_cb_syswide_auth_method(void *data, Evas_Object *obj,
					       const char *emission, const char *source);
static void _e_desklock_cb_personalized_auth_method(void *data, Evas_Object *obj,
						    const char *emission, const char *source);
#endif

/*******************************************************************************************/

struct _E_Config_Dialog_Data
{
   E_Config_Dialog *cfd;
   
   char *desklock_passwd;
   char *desklock_passwd_cp;
   int show_password; // local
   
   int autolock; // in e_config;
   int use_timeout; // in e_config;
   double timeout; // in e_config;
   
   int login_box_zone; // in e_config;
   int specific_lb_zone; // local variable
   int specific_lb_zone_backup; // used to have smart iface
   
   int zone_count; // local variable;
   
   char *cur_bg; // local variable;
   Evas *evas; // local variable
   Evas_Object *preview_image; // local variable

#ifdef HAVE_PAM
   int auth_method;
#endif
   
   struct {
      Evas_Object *passwd_field;
      Evas_Object *bg_list;

      Evas_Object *show_passwd_check;
      
      struct {
	 Evas_Object *show_all_screens;
	 Evas_Object *show_current_screen;
	 Evas_Object *show_specific_screen;
	 Evas_Object *screen_slider;
      } loginbox_obj;
   } gui;
};

typedef struct _E_Widget_Entry_Data   E_Widget_Entry_Data;
typedef struct _E_Widget_Check_Data   E_Widget_Check_Data;
typedef	struct _E_Widget_Radio_Data   E_Widget_Radio_Data;
typedef struct _E_Widget_Slider_Data  E_Widget_Slider_Data;

struct _E_Widget_Entry_Data
{
   Evas_Object *o_entry;
   Evas_Object *obj;
   char **valptr;
   void (*on_change_func) (void *data, Evas_Object *obj);
   void  *on_change_data;
};

struct _E_Widget_Check_Data
{
   Evas_Object *o_check;
   int *valptr;
};

struct _E_Widget_Radio_Data
{
  E_Radio_Group *group;
  Evas_Object	*o_radio;
  int		valnum;
};

struct _E_Widget_Slider_Data
{
  Evas_Object *o_widget, *o_slider;
  double *dval;
  int	 *ival;
};

EAPI E_Config_Dialog *
e_int_config_desklock(E_Container *con)
{
  E_Config_Dialog *cfd;
  E_Config_Dialog_View *v;

  v = E_NEW(E_Config_Dialog_View, 1);

  v->create_cfdata = _create_data;
  v->free_cfdata = _free_data;
  v->basic.apply_cfdata = _basic_apply_data;
  v->basic.create_widgets = _basic_create_widgets;
  v->advanced.apply_cfdata = _advanced_apply_data;
  v->advanced.create_widgets = _advanced_create_widgets;

  v->override_auto_apply = 1;

  cfd = e_config_dialog_new(con, _("Desktop Lock Settings"), NULL, 0, v, NULL);
  return cfd;
}

static void
_fill_desklock_data(E_Config_Dialog_Data *cfdata)
{
   // we have to read it from e_config->...
   if (e_config->desklock_personal_passwd)
     {
	cfdata->desklock_passwd = strdup(e_config->desklock_personal_passwd);
	cfdata->desklock_passwd_cp = strdup(e_config->desklock_personal_passwd);
     }
   else
     {
	cfdata->desklock_passwd = strdup("");
	cfdata->desklock_passwd_cp = strdup("");
     }
   
   cfdata->autolock = e_config->desklock_autolock;
   cfdata->use_timeout = e_config->desklock_use_timeout;
   cfdata->timeout = e_config->desklock_timeout;
   
   /* should be taken from e_config */
   //cfdata->login_box_on_zone = -1;
   
   if (e_config->desklock_login_box_zone >= 0)
     {
	cfdata->login_box_zone = LOGINBOX_SHOW_SPECIFIC_SCREEN;
	cfdata->specific_lb_zone_backup = cfdata->specific_lb_zone =
	  e_config->desklock_login_box_zone;
     }
   else
     {
	cfdata->login_box_zone = e_config->desklock_login_box_zone;
	cfdata->specific_lb_zone_backup = cfdata->specific_lb_zone = 0;
     }
   
   cfdata->zone_count = _e_desklock_zone_num_get();
   
   cfdata->show_password = 0;
   
   if (!e_config->desklock_background)
     cfdata->cur_bg = strdup(DEF_DESKLOCK_BACKGROUND);
   else
     cfdata->cur_bg = strdup(e_config->desklock_background);

#ifdef HAVE_PAM
   cfdata->auth_method = e_config->desklock_auth_method;
#endif
   
   //vertical_lb_align = e_config->desklock_login
}

static void *
_create_data(E_Config_Dialog *cfd)
{
  E_Config_Dialog_Data *cfdata;

  cfdata = E_NEW(E_Config_Dialog_Data, 1);
  cfdata->desklock_passwd = strdup("");
  cfdata->desklock_passwd_cp = strdup("");
  cfdata->cfd = cfd;

  _fill_desklock_data(cfdata);

  return cfdata;
}
static void
_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
  if (!cfdata) return;

  E_FREE(cfdata->desklock_passwd);
  E_FREE(cfdata->desklock_passwd_cp);
  E_FREE(cfdata->cur_bg);

  free(cfdata);
}

static int
_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
   if (cfdata->desklock_passwd_cp)
     {
	if (e_config->desklock_personal_passwd)
	  evas_stringshare_del(e_config->desklock_personal_passwd);
     }
   e_config->desklock_personal_passwd = (char *)evas_stringshare_add(cfdata->desklock_passwd_cp);
   e_config->desklock_autolock = cfdata->autolock;
   e_config->desklock_use_timeout = cfdata->use_timeout;
   e_config->desklock_timeout = cfdata->timeout;
#ifdef HAVE_PAM
   e_config->desklock_auth_method = cfdata->auth_method;
#endif
   if (e_config->desklock_use_timeout)
     {
	ecore_x_screensaver_timeout_set(e_config->desklock_timeout);
     }
   e_config_save_queue();
  return 1;
}

static Evas_Object *
_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
{
   Evas_Object *o, *of, *ob;
   E_Widget_Check_Data *wd;

#ifdef HAVE_PAM
   E_Radio_Group  *rg_auth;
   Evas_Object	  *oc;
#endif
   
   //_fill_desklock_data(cfdata);
   
   o = e_widget_list_add(evas, 0, 0);

#ifdef HAVE_PAM
   of = e_widget_framelist_add(evas, _("Password Type"), 0);
   {
     rg_auth = e_widget_radio_group_new((int*)(&cfdata->auth_method));
     oc = e_widget_radio_add(evas, _("Use my login password"), 0, rg_auth);
     e_widget_framelist_object_append(of, oc);

     rwd = e_widget_data_get(oc);
     edje_object_signal_callback_add(rwd->o_radio, "toggle_on", "",
				     _e_desklock_cb_syswide_auth_method, cfdata);

     oc = e_widget_radio_add(evas, _("Personalized password"), 1, rg_auth);
     e_widget_framelist_object_append(of,oc);

     rwd = e_widget_data_get(oc);
     edje_object_signal_callback_add(rwd->o_radio, "toggle_on", "",
				     _e_desklock_cb_personalized_auth_method, cfdata);
   }
   e_widget_list_object_append(o, of, 1, 1, 0.5);
#endif
   
   of = e_widget_framelist_add(evas, _("Personalized Password:"), 0);
   
   cfdata->gui.passwd_field = ob = e_widget_entry_add(evas, &(cfdata->desklock_passwd));
#ifdef HAVE_PAM
   if (cfdata->auth_method == 0)
     e_widget_disabled_set(ob, 1);
#endif
   _e_desklock_passwd_cb_change(cfdata, ob);
   e_widget_entry_on_change_callback_set(ob, _e_desklock_passwd_cb_change, cfdata);
   e_widget_min_size_set(ob, 200, 25);
   e_widget_framelist_object_append(of, ob);
   
   ob = e_widget_check_add(evas, _("Show password"), &(cfdata->show_password));
   cfdata->gui.show_passwd_check = ob;
#ifdef HAVE_PAM
   if (cfdata->auth_method == 0)
     e_widget_disabled_set(ob, 1);
#endif
   e_widget_framelist_object_append(of, ob);
   
   wd = (E_Widget_Check_Data*)e_widget_data_get(ob);
   edje_object_signal_callback_add(wd->o_check,"toggle_on", "", _e_desklock_cb_show_passwd, cfdata);
   edje_object_signal_callback_add(wd->o_check,"toggle_off", "", _e_desklock_cb_show_passwd, cfdata);
   e_widget_list_object_append(o, of, 1, 1, 0.5);
   
   of = e_widget_framelist_add(evas, _("Automatic Locking"), 0);
   e_widget_disabled_set(of, !ecore_x_screensaver_event_available_get());
   
   ob = e_widget_check_add(evas, _("Enable screensaver"), &(cfdata->use_timeout));
   e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
   e_widget_framelist_object_append(of, ob);
   
   ob = e_widget_check_add(evas, _("Lock when the screensaver starts"), &(cfdata->autolock));
   e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
   e_widget_framelist_object_append(of, ob);

   ob = e_widget_label_add(evas, _("Time until screensaver starts"));
   e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
   e_widget_framelist_object_append(of, ob);
   ob = e_widget_slider_add(evas, 1, 0, _("%1.0f seconds"),
			    1.0, 600.0,
			    1.0, 0, &(cfdata->timeout), NULL,
			    200);
   e_widget_framelist_object_append(of, ob);
   
   e_widget_list_object_append(o, of, 1, 1, 0.5);
   
   e_dialog_resizable_set(cfd->dia, 0);
   
   return o;
}

/* advanced window */

static int
_advanced_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
   if (!cfdata) return 0;
   
   if (cfdata->desklock_passwd_cp)
     {
	if (e_config->desklock_personal_passwd)
	  evas_stringshare_del(e_config->desklock_personal_passwd);
     }
   e_config->desklock_personal_passwd = (char *)evas_stringshare_add(cfdata->desklock_passwd_cp);

   if (cfdata->cur_bg)
     {
	if (e_config->desklock_background)
	  evas_stringshare_del(e_config->desklock_background);
	e_config->desklock_background = (char *)evas_stringshare_add(cfdata->cur_bg);
     }
   
   if (_e_desklock_zone_num_get() > 1)
     {
	if (cfdata->login_box_zone >= 0)
	  e_config->desklock_login_box_zone = cfdata->specific_lb_zone;
	else
	  e_config->desklock_login_box_zone = cfdata->login_box_zone;
     }
   else
     e_config->desklock_login_box_zone = LOGINBOX_SHOW_ALL_SCREENS;

   e_config->desklock_autolock = cfdata->autolock;
   e_config->desklock_use_timeout = cfdata->use_timeout;
   e_config->desklock_timeout = cfdata->timeout;
#ifdef HAVE_PAM
   e_config->desklock_auth_method = cfdata->auth_method;
#endif

   if (e_config->desklock_use_timeout)
     {
	ecore_x_screensaver_timeout_set(e_config->desklock_timeout);
     }
   
   e_config_save_queue();
   return 1;
}

static Evas_Object *
_advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
{
  Evas_Object *of, *ob;
  E_Widget_Radio_Data *wd;

  E_Radio_Group *rg;
  Evas_Object *ot;

  E_Widget_Check_Data *cwd;

  cfdata->evas = evas;

  ot = e_widget_table_add(evas, 0);
  {
    /* start: bkg list */
    cfdata->gui.bg_list = e_widget_ilist_add(evas, BG_LIST_ICON_SIZE_W,
      				       BG_LIST_ICON_SIZE_H, &(cfdata->cur_bg));
    {
      e_widget_ilist_selector_set(cfdata->gui.bg_list, 1);
      e_widget_min_size_set(cfdata->gui.bg_list, 180, 200);

      _load_bgs(cfdata);

      e_widget_focus_set(cfdata->gui.bg_list, 1);
      e_widget_ilist_go(cfdata->gui.bg_list);
    }
    e_widget_table_object_append(ot, cfdata->gui.bg_list, 0, 0, 1, 2, 1, 1, 1, 1);
    /* end: bkg list */

    /* start: Desk Lock Window Preview */
     
    e_widget_table_object_append(ot, cfdata->preview_image, 1, 0, 1, 1, 1, 1, 1, 1);
    /* end: Desk Lock Window Preview */

    /* start: login box options */

    /* Actually I do not know if I have to enable this if. However, if it is enabled
     * this options will be seen only for those peoples who has xinerama.
     * Otherwise, all the other world will not even know about them.
     * Let the world know about them. Maybe in the feature somebody will turn this if
     */

    if (1 || _e_desklock_zone_num_get() > 1)
      {
        of = e_widget_framelist_add(evas, _("Login Box Settings"), 0);
        {
          rg = e_widget_radio_group_new((int *)(&(cfdata->login_box_zone)));

          ob = e_widget_radio_add(evas, _("Show on all screen zones"), LOGINBOX_SHOW_ALL_SCREENS,
      			    rg);
          cfdata->gui.loginbox_obj.show_all_screens = ob;
          if (cfdata->zone_count == 1) e_widget_disabled_set(ob, 1);
          e_widget_framelist_object_append(of, ob);

          ob = e_widget_radio_add(evas, _("Show on current screen zone"),
      			    LOGINBOX_SHOW_CURRENT_SCREENS, rg);
          cfdata->gui.loginbox_obj.show_current_screen = ob;
          if (cfdata->zone_count == 1) e_widget_disabled_set(ob, 1);
          e_widget_framelist_object_append(of, ob);

          ob = e_widget_radio_add(evas, _("Show on screen zone #:"), LOGINBOX_SHOW_SPECIFIC_SCREEN,
      			    rg);
          cfdata->gui.loginbox_obj.show_specific_screen = ob;
          if (cfdata->zone_count == 1) e_widget_disabled_set(ob, 1);
          e_widget_framelist_object_append(of, ob);

          ob = e_widget_slider_add(evas, 1, 0, _("%1.0f"), 0.0, (double)(cfdata->zone_count - 1),
      			     1.0, 0, NULL, &(cfdata->specific_lb_zone), 100);
          cfdata->gui.loginbox_obj.screen_slider = ob;
          if (cfdata->zone_count == 1 || cfdata->login_box_zone == LOGINBOX_SHOW_ALL_SCREENS)
	    e_widget_disabled_set(ob, 1);
          e_widget_framelist_object_append(of, ob);
        }
        e_widget_table_object_append(ot, of, 1, 1, 1, 1, 1, 1, 1, 1);
      }
    /* end: login box options */

#ifdef HAVE_PAM
      of = e_widget_framelist_add(evas, _("Password Type"), 0);
      {
        rg_auth = e_widget_radio_group_new((int*)(&cfdata->auth_method));
        oc = e_widget_radio_add(evas, _("Use my login password"), 0, rg_auth);
        e_widget_framelist_object_append(of, oc);

        wd = e_widget_data_get(oc);
        edje_object_signal_callback_add(wd->o_radio, "toggle_on", "",
       				 _e_desklock_cb_syswide_auth_method, cfdata);

        oc = e_widget_radio_add(evas, _("Personalized password"), 1, rg_auth);
        e_widget_framelist_object_append(of,oc);

        wd = e_widget_data_get(oc);
        edje_object_signal_callback_add(wd->o_radio, "toggle_on", "",
       				 _e_desklock_cb_personalized_auth_method, cfdata);
      }
      e_widget_table_object_append(ot, of, 0, 2, 1, 1, 1, 1, 1, 1);
#endif

      of = e_widget_framelist_add(evas, _("Personalized Password:"), 0);
      {
	cfdata->gui.passwd_field = ob = e_widget_entry_add(evas, &(cfdata->desklock_passwd));
#ifdef HAVE_PAM
	if (cfdata->auth_method == 0)
	  e_widget_disabled_set(ob, 1);
#endif

	_e_desklock_passwd_cb_change(cfdata, ob);
	e_widget_entry_on_change_callback_set(ob, _e_desklock_passwd_cb_change, cfdata);
	e_widget_min_size_set(ob, 200, 25);
	e_widget_framelist_object_append(of, ob);
     
	ob = e_widget_check_add(evas, _("Show password"), &(cfdata->show_password));
	cfdata->gui.show_passwd_check = ob;

#ifdef HAVE_PAM
	if (cfdata->auth_method == 0)
	  e_widget_disabled_set(ob, 1);
#endif
	e_widget_framelist_object_append(of, ob);
     
	cwd = (E_Widget_Check_Data*)e_widget_data_get(ob);
	edje_object_signal_callback_add(cwd->o_check,"toggle_on", "",
					_e_desklock_cb_show_passwd, cfdata);
	edje_object_signal_callback_add(cwd->o_check,"toggle_off", "",
					_e_desklock_cb_show_passwd, cfdata);
      }
#ifdef HAVE_PAM
      e_widget_table_object_append(ot, of, 0, 3, 1, 1, 1, 1, 1, 1);
#else
      e_widget_table_object_append(ot, of, 0, 2, 1, 1, 1, 1, 1, 1);
#endif

      of = e_widget_framelist_add(evas, _("Automatic Locking"), 0);
      {
	e_widget_disabled_set(of, !ecore_x_screensaver_event_available_get());
   
	ob = e_widget_check_add(evas, _("Enable screensaver"), &(cfdata->use_timeout));
	e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
	e_widget_framelist_object_append(of, ob);
   
	ob = e_widget_check_add(evas, _("Lock when the screensaver starts"), &(cfdata->autolock));
	e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
	e_widget_framelist_object_append(of, ob);

	ob = e_widget_label_add(evas, _("Time until screensaver starts"));
	e_widget_disabled_set(ob, !ecore_x_screensaver_event_available_get());
	e_widget_framelist_object_append(of, ob);
	ob = e_widget_slider_add(evas, 1, 0, _("%1.0f seconds"),
				 1.0, 600.0,
				 1.0, 0, &(cfdata->timeout), NULL,
				 200);
	e_widget_framelist_object_append(of, ob);
      }
#ifdef HAVE_PAM
      e_widget_table_object_append(ot, of, 1, 2, 1, 2 ,1 ,1 ,1 ,1);
#else
      e_widget_table_object_append(ot, of, 1, 2, 1, 1 ,1 ,1 ,1 ,1);
#endif
  }

  /* register callbacks for the radios in login box options
   * in order to propertly update interface
   */

  wd = e_widget_data_get(cfdata->gui.loginbox_obj.show_all_screens);
  edje_object_signal_callback_add(wd->o_radio, "toggle_on", "",
				  _e_desklock_cb_lb_show_on_all_screens, cfdata);

  wd = e_widget_data_get(cfdata->gui.loginbox_obj.show_current_screen);
  edje_object_signal_callback_add(wd->o_radio, "toggle_on", "",
				  _e_desklock_cb_lb_show_on_current_screen, cfdata);

  wd = e_widget_data_get(cfdata->gui.loginbox_obj.show_specific_screen);
  edje_object_signal_callback_add(wd->o_radio, "toggle_on", "",
				  _e_desklock_cb_lb_show_on_specific_screen, cfdata);


  e_dialog_resizable_set(cfd->dia, 0);
  return ot;
}


/* general functionality/callbacks */

static void
_e_desklock_passwd_cb_change(void *data, Evas_Object *obj)
{
  E_Widget_Entry_Data *wd;
  E_Config_Dialog_Data	*cfdata;
  char *ptr;
  int i;

  cfdata = data;

  // here goes the hack to have e_widget_entry look like
  // password entry. However, I think, this should be implemented
  // at least on the e_widget_entry level. The best would be
  // e_entry.
  if (!cfdata->desklock_passwd[0])
  {
    E_FREE(cfdata->desklock_passwd_cp);
    cfdata->desklock_passwd_cp = strdup("");
    return;
  }

  if (strlen(cfdata->desklock_passwd) > strlen(cfdata->desklock_passwd_cp))
    {
      for (i = 0; i < strlen(cfdata->desklock_passwd_cp); i++)
	cfdata->desklock_passwd[i] = cfdata->desklock_passwd_cp[i];
      E_FREE(cfdata->desklock_passwd_cp);
      cfdata->desklock_passwd_cp = strdup(cfdata->desklock_passwd);
    }
  else if (strlen(cfdata->desklock_passwd) < strlen(cfdata->desklock_passwd_cp))
    {
      cfdata->desklock_passwd_cp[strlen(cfdata->desklock_passwd)] = 0;
      E_FREE(cfdata->desklock_passwd);
      cfdata->desklock_passwd = strdup(cfdata->desklock_passwd_cp);
    }
  else
    {
      E_FREE(cfdata->desklock_passwd);
      cfdata->desklock_passwd = strdup(cfdata->desklock_passwd_cp);
    }

  wd = e_widget_data_get(obj);
  
  if (cfdata->show_password)
    {
      e_entry_text_set(wd->o_entry, cfdata->desklock_passwd);
      return;
    }

  for (ptr = cfdata->desklock_passwd; *ptr; ptr++) *ptr = '*';
  e_entry_text_set(wd->o_entry, cfdata->desklock_passwd);
}

static void
_e_desklock_cb_show_passwd(void *data, Evas_Object *obj, const char *emission, const char *source)
{
  E_Config_Dialog_Data *cfdata;

  cfdata = data;
  _e_desklock_passwd_cb_change(cfdata, cfdata->gui.passwd_field);
}

static int
_e_desklock_zone_num_get()
{
  int num;
  Evas_List *l, *l2;

  num = 0;
  for (l = e_manager_list(); l; l = l->next)
    {
      E_Manager *man = l->data;

      for (l2 = man->containers; l2; l2 = l2->next)
	{
	  E_Container *con = l2->data;

	  num += evas_list_count(con->zones);
	}
    }

  return num;
}

static void
_load_bgs(E_Config_Dialog_Data *cfdata)
{
  E_Config_Dialog *cfd;
  Evas_Object *o, *ic, *im;
  Ecore_Evas *eebuf;
  Evas *evasbuf;
  Evas_List *bg_dirs, *bg;
  const char *f, *f1;
  char *c;

  if (!cfdata || !cfdata->gui.bg_list)
    return;

  cfd = cfdata->cfd;
  eebuf = ecore_evas_buffer_new(1, 1);
  evasbuf = ecore_evas_get(eebuf);

  /* Desklock background */
  o = edje_object_add(evasbuf);
  f1 = e_theme_edje_file_get("base/theme/desklock", "desklock/background");
  c = strdup(f1);

  e_widget_ilist_header_append(cfdata->gui.bg_list, NULL, ("Theme Backgrounds"));
  if (edje_object_file_set(o, f1, "desklock/background"))
    {
      if (!e_thumb_exists(c))
	ic = e_thumb_generate_begin(c, BG_LIST_ICON_SIZE_W, BG_LIST_ICON_SIZE_H,
				   cfdata->evas, &ic, NULL, NULL);
      else
	ic = e_thumb_evas_object_get(c, cfdata->evas, BG_LIST_ICON_SIZE_W, BG_LIST_ICON_SIZE_H, 1);


      e_widget_ilist_append(cfdata->gui.bg_list, ic, _("Theme Desklock Background"),
			    _ibg_list_cb_bg_selected, cfdata, DEF_DESKLOCK_BACKGROUND);
    }

  if ((!e_config->desklock_background) ||
      (!strcmp(e_config->desklock_background, DEF_DESKLOCK_BACKGROUND)))
    e_widget_ilist_selected_set(cfdata->gui.bg_list, 0);

   im = e_widget_preview_add(cfdata->evas, BG_PREVIEW_W, BG_PREVIEW_H);
   e_widget_preview_edje_set(im, c, "desktop/background");

  evas_object_del(o);
  ecore_evas_free(eebuf);
  free(c);
  /* end: Desklock background */

  /* Theme Background */


  eebuf = ecore_evas_buffer_new(1, 1);
  evasbuf = ecore_evas_get(eebuf);

  o = edje_object_add(evasbuf);
  f = e_theme_edje_file_get("base/theme/backgrounds", "desktop/background");
  c = strdup(f);
  if (edje_object_file_set(o, f, "desktop/background"))
    {
      if (!e_thumb_exists(c))
	ic = e_thumb_generate_begin(c, BG_LIST_ICON_SIZE_W, BG_LIST_ICON_SIZE_H,
				   cfdata->evas, &ic, NULL, NULL);
      else
	ic = e_thumb_evas_object_get(c, cfdata->evas, BG_LIST_ICON_SIZE_W, BG_LIST_ICON_SIZE_H, 1);

      e_widget_ilist_append(cfdata->gui.bg_list, ic, _("Theme Background"), _ibg_list_cb_bg_selected,
			    cfdata, DEF_THEME_BACKGROUND);
    }

  if ((e_config->desklock_background) &&
      (!strcmp(e_config->desklock_background, DEF_THEME_BACKGROUND)))
    {
       e_widget_ilist_selected_set(cfdata->gui.bg_list, 1);
       im = e_widget_preview_add(cfdata->evas, BG_PREVIEW_W, BG_PREVIEW_H);
       e_widget_preview_edje_set(im, c, "desktop/background");
    }

  evas_object_del(o);
  ecore_evas_free(eebuf);
  free(c);
 
  e_widget_ilist_header_append(cfdata->gui.bg_list, NULL, _("Personal"));
  bg_dirs = e_path_dir_list_get(path_backgrounds);
  for (bg = bg_dirs; bg; bg = bg->next)
    {
      E_Path_Dir *d;

      d = bg->data;
      if (ecore_file_is_dir(d->dir))
	{
	  char *bg_file;
	  Ecore_List *bgs;
	  int i = e_widget_ilist_count(cfdata->gui.bg_list);

	  bgs = ecore_file_ls(d->dir);
	  if (!bgs) continue;
	  while ((bg_file = ecore_list_next(bgs)))
	    {
	      char full_path[4096];

	      snprintf(full_path, sizeof(full_path), "%s/%s", d->dir, bg_file);
	      if (ecore_file_is_dir(full_path)) continue;
	      if (!e_util_edje_collection_exists(full_path, "desktop/background")) continue;

	      if (!e_thumb_exists(full_path))
		ic = e_thumb_generate_begin(full_path, BG_LIST_ICON_SIZE_W, BG_LIST_ICON_SIZE_H,
					    cfdata->evas, &ic, NULL, NULL);
	      else
		ic = e_thumb_evas_object_get(full_path, cfdata->evas, BG_LIST_ICON_SIZE_W,
					     BG_LIST_ICON_SIZE_H, 1);

	      e_widget_ilist_append(cfdata->gui.bg_list, ic, ecore_file_strip_ext(bg_file),
				    _ibg_list_cb_bg_selected, cfdata, full_path);

	      if ((e_config->desklock_background) &&
		  (!strcmp(e_config->desklock_background, full_path)))
		{
		   e_widget_ilist_selected_set(cfdata->gui.bg_list, i);
		   evas_object_del(im);
		   im = e_widget_preview_add(cfdata->evas, BG_PREVIEW_W, BG_PREVIEW_H);
		   e_widget_preview_edje_set(im, full_path, "desktop/background");
		}
	      i++;
	    }
	  free(bg_file);
	  ecore_list_destroy(bgs);
	}
      free(d);
    }
  evas_list_free(bg);
  evas_list_free(bg_dirs);

  cfdata->preview_image = im;
}

static void
_ibg_list_cb_bg_selected(void *data)
{
   E_Config_Dialog_Data *cfdata;
   
   cfdata = data;
   
   if (cfdata->cur_bg[0])
     {
	if (strcmp(cfdata->cur_bg, DEF_DESKLOCK_BACKGROUND) == 0)
	  {
	     const char *theme;
	     
	     theme = e_theme_edje_file_get("base/theme/desklock", "desklock/background");
	     e_widget_preview_edje_set(cfdata->preview_image, theme, "desktop/background");
	  }
	else if (strcmp(cfdata->cur_bg, DEF_THEME_BACKGROUND) == 0)
	  {
	     const char *theme;
	     
	     theme = e_theme_edje_file_get("base/theme/backgrounds", "desktop/background");
	     e_widget_preview_edje_set(cfdata->preview_image, theme, "desktop/background");
	  }
	else
	  {
	     e_widget_preview_edje_set(cfdata->preview_image, cfdata->cur_bg, "desktop/background");
	  }
     }
   else
     {
	const char *theme;
	
	theme = e_theme_edje_file_get("base/theme/desklock", "desklock/background");
	e_widget_preview_edje_set(cfdata->preview_image, theme, "desktop/background");
     }
}

static void
_e_desklock_cb_lb_show_on_all_screens(void *data, Evas_Object *obj, const char *emission,
				      const char *source)
{
  E_Config_Dialog_Data *cfdata;

  if (!(cfdata = data)) return;

  cfdata->specific_lb_zone_backup = cfdata->specific_lb_zone;

  e_widget_disabled_set(cfdata->gui.loginbox_obj.screen_slider, 1);
}

static void
_e_desklock_cb_lb_show_on_current_screen(void *data, Evas_Object *obj, const char *emission,
					 const char *source)
{
  _e_desklock_cb_lb_show_on_all_screens(data, obj, emission, source);
}

static void
_e_desklock_cb_lb_show_on_specific_screen(void *data, Evas_Object *obj, const char *emission,
					 const char *source)
{
  E_Widget_Slider_Data	*wd;
  E_Config_Dialog_Data	*cfdata;

  if (!(cfdata = data)) return;

  wd = e_widget_data_get(cfdata->gui.loginbox_obj.screen_slider);
  e_slider_value_set(wd->o_slider, cfdata->specific_lb_zone_backup);
  cfdata->specific_lb_zone = cfdata->specific_lb_zone_backup;

  e_widget_disabled_set(wd->o_widget, 0);
}

#ifdef HAVE_PAM
static void
_e_desklock_cb_syswide_auth_method(void *data, Evas_Object *obj, const char *emission,
				   const char *source)
{
  E_Widget_Entry_Data *ewd;
  E_Widget_Check_Data *cwd;
  E_Config_Dialog_Data *cfdata;

  if (!(cfdata = data)) return;

  e_widget_disabled_set(cfdata->gui.passwd_field, 1);
  e_widget_disabled_set(cfdata->gui.show_passwd_check, 1);
}

static void
_e_desklock_cb_personalized_auth_method(void *data, Evas_Object *obj, const char *emission,
					const char *source)
{
  E_Config_Dialog_Data *cfdata;

  if (!(cfdata = data)) return;

  e_widget_disabled_set(cfdata->gui.passwd_field, 0);
  e_widget_disabled_set(cfdata->gui.show_passwd_check, 0);
}
#endif