Ubuntu Pastebin

Paste from bluesabre at Fri, 2 Jan 2015 03:55:38 +0000

Download as text
  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
Description: Light Locker Integration
 Integrate Light Locker configuration into Xfce Power Manager. This allows proper settings
 synchronization between the two applications and eliminates some of the hackiness
 used in Light Locker Settings to accomplish the same effect, and streamlines similar
 tools into a single location. This depends on light-locker 1.5.1 configured with
 the GSettings backend.
Author: Sean Davis, bluesabre@ubuntu.com
Origin: vendor
Last-Update: 2015-01-01
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
Index: xfce4-power-manager-1.4.2/data/interfaces/xfpm-settings.ui
===================================================================
--- xfce4-power-manager-1.4.2.orig/data/interfaces/xfpm-settings.ui
+++ xfce4-power-manager-1.4.2/data/interfaces/xfpm-settings.ui
@@ -65,6 +65,34 @@
     <property name="value">3</property>
     <property name="step_increment">1</property>
   </object>
+  <object class="GtkAdjustment" id="light-locker-late-locking-adjustment">
+    <property name="lower">1</property>
+    <property name="upper">120</property>
+    <property name="value">1</property>
+    <property name="step_increment">1</property>
+  </object>
+  <object class="GtkListStore" id="liststore1">
+    <columns>
+      <!-- column-name value -->
+      <column type="gint"/>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0">0</col>
+        <col id="1" translatable="yes">Never</col>
+      </row>
+      <row>
+        <col id="0">1</col>
+        <col id="1" translatable="yes">When the screensaver is activated</col>
+      </row>
+      <row>
+        <col id="0">2</col>
+        <col id="1" translatable="yes">When the screensaver is deactivated</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkListStore" id="model1">
     <columns>
       <!-- column-name gchararray -->
@@ -87,6 +115,17 @@
       </row>
     </data>
   </object>
+  <object class="GtkListStore" id="model11">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Nothing</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkListStore" id="model3">
     <columns>
       <!-- column-name gchararray -->
@@ -374,7 +413,6 @@
                                         <signal name="toggled" handler="brightness_handle_keys_toggled_cb" swapped="no"/>
                                       </object>
                                       <packing>
-                                        <property name="left_attach">0</property>
                                         <property name="right_attach">2</property>
                                         <property name="top_attach">3</property>
                                         <property name="bottom_attach">4</property>
@@ -522,6 +560,12 @@
                                 <child>
                                   <placeholder/>
                                 </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
                               </object>
                             </child>
                           </object>
@@ -778,6 +822,12 @@
                                 <child>
                                   <placeholder/>
                                 </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
                               </object>
                             </child>
                           </object>
@@ -977,6 +1027,9 @@
                       </packing>
                     </child>
                   </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
                 </child>
                 <child type="tab">
                   <object class="GtkLabel" id="system">
@@ -985,6 +1038,7 @@
                     <property name="label" translatable="yes">System</property>
                   </object>
                   <packing>
+                    <property name="position">1</property>
                     <property name="tab_fill">False</property>
                   </packing>
                 </child>
@@ -1571,6 +1625,172 @@
                   </object>
                   <packing>
                     <property name="position">2</property>
+                    <property name="tab_fill">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkVBox" id="light-locker-vbox1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="border_width">12</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkFrame" id="light-locker-frame">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label_xalign">0</property>
+                        <property name="shadow_type">none</property>
+                        <child>
+                          <object class="GtkAlignment" id="light-locker-alignment">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="top_padding">12</property>
+                            <property name="bottom_padding">12</property>
+                            <property name="left_padding">12</property>
+                            <child>
+                              <object class="GtkVBox" id="light-locker-vbox2">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="spacing">5</property>
+                                <child>
+                                  <object class="GtkTable" id="light-locker-table">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="n_rows">4</property>
+                                    <property name="n_columns">2</property>
+                                    <property name="column_spacing">6</property>
+                                    <property name="row_spacing">12</property>
+                                    <child>
+                                      <object class="GtkCheckButton" id="light-locker-enable-check">
+                                        <property name="label" translatable="yes">Enable Light Locker</property>
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">False</property>
+                                        <property name="draw_indicator">True</property>
+                                        <signal name="toggled" handler="light_locker_enabled_toggled_cb" swapped="no"/>
+                                      </object>
+                                      <packing>
+                                        <property name="right_attach">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="light-locker-automatic-locking-label">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label" translatable="yes">Automatically lock the session:</property>
+                                      </object>
+                                      <packing>
+                                        <property name="top_attach">1</property>
+                                        <property name="x_options">GTK_FILL</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkComboBox" id="light-locker-automatic-locking-combo">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="model">liststore1</property>
+                                        <property name="active">0</property>
+                                        <signal name="changed" handler="light_locker_automatic_locking_changed_cb" swapped="no"/>
+                                        <child>
+                                          <object class="GtkCellRendererText" id="renderer11"/>
+                                          <attributes>
+                                            <attribute name="text">1</attribute>
+                                          </attributes>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                        <property name="top_attach">1</property>
+                                        <property name="bottom_attach">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="light-locker-late-locking-label">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label" translatable="yes">Delay locking after screensaver for</property>
+                                      </object>
+                                      <packing>
+                                        <property name="top_attach">2</property>
+                                        <property name="x_options">GTK_FILL</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkHScale" id="light-locker-late-locking-scale">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="update_policy">discontinuous</property>
+                                        <property name="adjustment">light-locker-late-locking-adjustment</property>
+                                        <property name="round_digits">0</property>
+                                        <property name="digits">0</property>
+                                        <property name="value_pos">bottom</property>
+                                        <signal name="format-value" handler="format_light_locker_value_cb" swapped="no"/>
+                                        <signal name="value-changed" handler="light_locker_late_locking_value_changed_cb" swapped="no"/>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                        <property name="top_attach">2</property>
+                                        <property name="bottom_attach">3</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkCheckButton" id="light-locker-suspend">
+                                        <property name="label" translatable="yes">Lock screen when system is going for sleep</property>
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">False</property>
+                                        <property name="draw_indicator">True</property>
+                                        <signal name="toggled" handler="lock_screen_toggled_cb" swapped="no"/>
+                                      </object>
+                                      <packing>
+                                        <property name="right_attach">2</property>
+                                        <property name="top_attach">3</property>
+                                        <property name="bottom_attach">4</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                        <child type="label">
+                          <object class="GtkLabel" id="light-locker-frame-label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">&lt;b&gt;Light Locker&lt;/b&gt;</property>
+                            <property name="use_markup">True</property>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+                <child type="tab">
+                  <object class="GtkLabel" id="light-locker-tab-label">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Security</property>
+                  </object>
+                  <packing>
+                    <property name="position">2</property>
                     <property name="tab_fill">False</property>
                   </packing>
                 </child>
Index: xfce4-power-manager-1.4.2/settings/xfpm-settings.c
===================================================================
--- xfce4-power-manager-1.4.2.orig/settings/xfpm-settings.c
+++ xfce4-power-manager-1.4.2/settings/xfpm-settings.c
@@ -63,6 +63,15 @@ static  GtkWidget *on_ac_dpms_off 		= NU
 static  GtkWidget *sideview                 = NULL; /* Sidebar tree view - all devices are in the sideview */
 static  GtkWidget *device_details_notebook  = NULL; /* Displays the details of a deivce */
 
+/* Light Locker Integration */
+static  GtkWidget *light_locker_tab             = NULL;
+static  GtkWidget *light_locker_enable          = NULL;
+static  GtkWidget *light_locker_autolock        = NULL;
+static  GtkWidget *light_locker_delay           = NULL;
+static  GtkWidget *light_locker_sleep           = NULL;
+static  GSettings *light_locker_settings        = NULL;
+/* END Light Locker Integration */
+
 static  gboolean  lcd_brightness = FALSE;
 static  gchar *starting_device_id = NULL;
 static  UpClient *upower = NULL;
@@ -190,6 +199,20 @@ void        on_ac_sleep_mode_changed_cb
 void        on_battery_sleep_mode_changed_cb	   (GtkWidget *w,
 						    XfconfChannel *channel);
 
+/* Light Locker Integration */
+gchar      *format_light_locker_value_cb           (GtkScale *scale,
+                                                    gdouble value,
+                                                    gpointer data);
+
+void        light_locker_late_locking_value_changed_cb (GtkWidget *w,
+                                                        XfconfChannel *channel);
+
+void        light_locker_automatic_locking_changed_cb (GtkWidget *w,
+                                                       XfconfChannel *channel);
+
+void        light_locker_enabled_toggled_cb        (GtkWidget *w,
+                                                    XfconfChannel *channel);
+/* END Light Locker Integration */
 
 void brightness_level_on_ac (GtkWidget *w,  XfconfChannel *channel)
 {
@@ -787,6 +810,18 @@ lock_screen_toggled_cb (GtkWidget *w, Xf
     XfconfChannel *session_channel = xfconf_channel_get ("xfce4-session");
     gboolean val = (gint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
 
+    /* Light Locker Integration - Since there are two checkboxes that need to be synced */
+    if ( light_locker_settings )
+    {
+        if ((xfconf_channel_get_bool (session_channel, "/shutdown/LockScreen", TRUE) ==
+             xfconf_channel_get_bool (session_channel, PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE)) &&
+            (xfconf_channel_get_bool (session_channel, "/shutdown/LockScreen", TRUE) == val))
+        {
+            return;
+        }
+    }
+    /* END Light Locker Integration */
+
     if ( !xfconf_channel_set_bool (session_channel, "/shutdown/LockScreen", val) )
     {
 	g_critical ("Unable to set value for property %s\n", LOCK_SCREEN_ON_SLEEP);
@@ -796,6 +831,21 @@ lock_screen_toggled_cb (GtkWidget *w, Xf
     {
 	g_critical ("Unable to set value for property %s\n", LOCK_SCREEN_ON_SLEEP);
     }
+
+    /* Light Locker Integration */
+    if ( light_locker_settings )
+    {
+        GtkWidget *widget;
+        GVariant *variant;
+        variant = g_variant_new_boolean (val);
+        if (!g_settings_set_value (light_locker_settings, "lock-on-suspend", variant))
+            g_critical ("Cannot set value for property lock-on-suspend\n");
+
+        widget = GTK_WIDGET (gtk_builder_get_object (xml, "lock-screen"));
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), val);
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(light_locker_sleep), val);
+    }
+    /* END Light Locker Integration */
 }
 
 static void
@@ -1469,6 +1519,393 @@ xfpm_settings_advanced (XfconfChannel *c
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(brg_handle_keys), val);
 }
 
+/* Light Locker Integration */
+static gchar*
+get_light_locker_path (void)
+{
+    gchar** paths = NULL;
+    gchar* path = NULL;
+    int i = 0;
+
+    /* Check if executable in path */
+    paths = g_strsplit(g_getenv("PATH"), ":", 0);
+    for (i = 0; i < g_strv_length(paths); i++) {
+        path = g_strdup(g_build_filename(paths[i], "light-locker", NULL));
+        if (g_file_test(path, G_FILE_TEST_EXISTS))
+        {
+            break;
+        }
+        g_free(path);
+        path = NULL;
+    }
+    g_strfreev(paths);
+
+    return path;
+}
+
+static gint
+light_locker_get_running_process (void)
+{
+    /* Return TRUE if there is a running instance of light-locker */
+    gboolean exists = FALSE;
+
+    GDir* proc = NULL;
+    GError* error = NULL;
+    gchar* subdir = "a";
+    gchar* dir_path = NULL;
+    gchar* file_path = NULL;
+    gchar* contents = NULL;
+    gchar** paths = NULL;
+    gchar* path = NULL;
+    gsize length;
+    guint i = 0;
+    gint pid = 0;
+
+    /* Check the /proc directory for pids */
+    proc = g_dir_open("/proc", 0, &error);
+    if (error)
+    {
+        g_critical("%s", error->message);
+        g_error_free(error);
+        return FALSE;
+    }
+
+    /* Iterate through each file, the PIDs are directories */
+    while (subdir != NULL)
+    {
+        subdir = g_strdup(g_dir_read_name(proc));
+        dir_path = g_build_filename("/proc", subdir, (gchar*)NULL);
+
+        /* If its a directory, check it out. */
+        if (g_file_test(dir_path, G_FILE_TEST_IS_DIR))
+        {
+            /* Check for the cmdline file, which has the command. */
+            file_path = g_build_filename(dir_path, "cmdline", (gchar*)NULL);
+            if (g_file_test(file_path, G_FILE_TEST_EXISTS)) {
+                if (g_file_get_contents(g_strdup(file_path), &contents, &length, &error))
+                {
+                    /* Check if light-locker is running */
+                    if (g_str_has_suffix(contents, "light-locker"))
+                    {
+                        /* Check for just "light-locker" */
+                        if (g_strcmp0(contents, "light-locker") == 0)
+                        {
+                            exists = TRUE;
+                        }
+                        if (!exists)
+                        {
+                            /* Check if executable in path */
+                            paths = g_strsplit(g_getenv("PATH"), ":", 0);
+                            for (i = 0; i < g_strv_length(paths); i++) {
+                                path = g_strdup(g_build_filename(paths[i], "light-locker", NULL));
+                                if (g_strcmp0(contents, path) == 0)
+                                {
+                                    exists = TRUE;
+                                    g_free(path);
+                                    break;
+                                }
+                                g_free(path);
+                            }
+                            g_strfreev(paths);
+                        }
+                    }
+                }
+                g_free(contents);
+                if (error)
+                {
+                    g_error_free(error);
+                    error = NULL;
+                }
+            }
+            g_free(file_path);
+        }
+        g_free(dir_path);
+
+        /* If found, stop the loop */
+        if (exists)
+        {
+            pid = atoi(subdir);
+            g_free(subdir);
+            subdir = NULL;
+        }
+    }
+    g_dir_close(proc);
+
+    return pid;
+}
+
+static void
+light_locker_start_process (void)
+{
+    if (light_locker_get_running_process())
+        return;
+
+    g_spawn_command_line_async("light-locker", NULL);
+}
+
+static void
+light_locker_end_process (void)
+{
+    gint pid = light_locker_get_running_process();
+    if (pid)
+        kill (pid, SIGKILL);
+}
+
+static gchar *
+light_locker_get_desktop_file (void)
+{
+    const gchar         *local_dir = g_get_user_config_dir ();
+    const gchar * const *dirs = g_get_system_config_dirs ();
+    const gchar * const *dir;
+    gchar               *filename = NULL;
+
+    /* Try local first, then system files */
+    filename = g_build_filename (local_dir, "autostart", "light-locker.desktop", NULL);
+    if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
+        return filename;
+    } else {
+        for( dir = dirs; *dir; ++dir ) {
+            filename = g_build_filename (*dir, "autostart", "light-locker.desktop", NULL);
+            if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
+                return filename;
+            }
+            g_free (filename);
+        }
+    }
+
+    if (filename)
+        g_free (filename);
+
+    return NULL;
+}
+
+static gboolean
+light_locker_get_enabled (void)
+{
+    GKeyFile *desktop_file = g_key_file_new ();
+    gchar    *filename = NULL;
+    gchar    *exec = NULL;
+    gboolean  enabled = FALSE;
+
+    filename = light_locker_get_desktop_file();
+    if (g_key_file_load_from_file (desktop_file, filename, G_KEY_FILE_NONE, NULL)) {
+        exec = g_key_file_get_string (desktop_file, "Desktop Entry", "Exec", NULL);
+        if (g_strrstr(exec, "light-locker") != NULL) {
+            enabled = TRUE;
+        }
+        g_free (exec);
+    } else {
+        g_warning ("Unable to load desktop file \"%s\"", filename);
+    }
+
+    if (filename)
+        g_free (filename);
+
+    if (desktop_file)
+        g_key_file_free (desktop_file);
+
+    return enabled;
+}
+
+static void
+light_locker_set_enabled (gboolean enable)
+{
+    GKeyFile *desktop_file = g_key_file_new ();
+    gchar    *filename = light_locker_get_desktop_file ();
+
+    if (!g_key_file_load_from_file (desktop_file, filename, G_KEY_FILE_NONE, NULL)) {
+        g_key_file_set_value (desktop_file, "Desktop Entry", "Type", "Application");
+        g_key_file_set_value (desktop_file, "Desktop Entry", "Name", "Screen Locker");
+        g_key_file_set_value (desktop_file, "Desktop Entry", "Comment", "Launch screen locker program");
+        g_key_file_set_value (desktop_file, "Desktop Entry", "Icon", "preferences-desktop-screensaver");
+        g_key_file_set_value (desktop_file, "Desktop Entry", "NoDisplay", "true");
+        g_key_file_set_value (desktop_file, "Desktop Entry", "NotShownIn", "Gnome;Unity");
+    }
+
+    if (enable) {
+        g_key_file_set_value (desktop_file, "Desktop Entry", "Exec", "light-locker");
+        light_locker_start_process ();
+    } else {
+        g_key_file_set_value (desktop_file, "Desktop Entry", "Exec", "");
+        light_locker_end_process ();
+    }
+
+    g_free (filename);
+    filename = g_build_filename (g_get_user_config_dir(), "autostart", "light-locker.desktop", NULL);
+
+    if (!g_key_file_save_to_file (desktop_file, filename, NULL)) {
+        g_warning ("Unable to save desktop file \"%s\"", filename);
+    }
+
+    g_key_file_free (desktop_file);
+    g_free (filename);
+
+    /* Toggle widget sensitivity */
+    gtk_widget_set_sensitive(light_locker_autolock, enable);
+    gtk_widget_set_sensitive(light_locker_delay,
+                             enable && gtk_combo_box_get_active(GTK_COMBO_BOX(light_locker_autolock)) != 0);
+    gtk_widget_set_sensitive(light_locker_sleep, enable);
+}
+
+gchar *
+format_light_locker_value_cb (GtkScale *scale, gdouble value, gpointer data)
+{
+    gint h, min;
+
+    if ( (gint)value <= 0 )
+        return g_strdup (_("Never"));
+    else if ( (gint)value < 60 )
+        return g_strdup_printf ("%d %s", (gint)value, _("Seconds"));
+    else if ( (gint)value == 60)
+        return g_strdup (_("One Minute"));
+
+    /* value > 60 */
+    min = (gint)value - 60;
+
+    return g_strdup_printf ("%d %s", (gint)min, _("Minutes"));
+}
+
+void
+light_locker_late_locking_value_changed_cb (GtkWidget *widget, XfconfChannel *channel)
+{
+    GVariant *variant;
+    gint      value = (gint)gtk_range_get_value (GTK_RANGE (widget));
+
+    if (value > 60) {
+        value = (value - 60) * 60;
+    }
+
+    variant = g_variant_new_uint32 (value);
+
+    if (!g_settings_set_value (light_locker_settings, "lock-after-screensaver", variant))
+    {
+        g_critical ("Cannot set value for property lock-after-screensaver\n");
+    }
+}
+
+void
+light_locker_automatic_locking_changed_cb (GtkWidget *widget, XfconfChannel *channel)
+{
+    GVariant *variant;
+    gint      value;
+    gint      lock_after_screensaver;
+    gboolean  late_locking = FALSE;
+
+    value = gtk_combo_box_get_active (GTK_COMBO_BOX(widget));
+    gtk_widget_set_sensitive (light_locker_delay, value != 0);
+
+    if (value == 0)
+        lock_after_screensaver = 0;
+    else {
+        lock_after_screensaver = (gint)gtk_range_get_value (GTK_RANGE (light_locker_delay));
+        if (lock_after_screensaver > 60) {
+            lock_after_screensaver = (lock_after_screensaver - 60) * 60;
+        }
+    }
+
+    if (value == 2)
+        late_locking = TRUE;
+
+    variant = g_variant_new_uint32 (lock_after_screensaver);
+    if (!g_settings_set_value (light_locker_settings, "lock-after-screensaver", variant))
+        g_critical ("Cannot set value for property lock-after-screensaver\n");
+
+    variant = g_variant_new_boolean (late_locking);
+    if (!g_settings_set_value (light_locker_settings, "late-locking", variant))
+        g_critical ("Cannot set value for property late-locking\n");
+}
+
+void
+light_locker_enabled_toggled_cb  (GtkWidget *widget, XfconfChannel *channel)
+{
+    gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(light_locker_enable));
+
+    light_locker_set_enabled (enabled);
+}
+
+static void xfpm_settings_light_locker (XfconfChannel *channel,
+                                        gboolean auth_suspend, gboolean auth_hibernate,
+                                        gboolean can_suspend, gboolean can_hibernate)
+{
+    GSettingsSchemaSource *schema_source;
+    GSettingsSchema       *schema;
+    GVariant              *variant;
+    gboolean               late_locking, lock_on_suspend, xfpm_lock_on_suspend;
+    guint32                lock_after_screensaver;
+    GtkWidget             *security_frame;
+
+    /* Collect the Light Locker widgets */
+    light_locker_tab = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-vbox1"));
+    light_locker_enable = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-enable-check"));
+    light_locker_autolock = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-automatic-locking-combo"));
+    light_locker_delay = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-late-locking-scale"));
+    light_locker_sleep = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-suspend"));
+
+    if ( !can_suspend && !can_hibernate )
+    {
+        gtk_widget_set_sensitive (light_locker_sleep, FALSE);
+        gtk_widget_set_tooltip_text (light_locker_sleep, _("Hibernate and suspend operations not supported"));
+    }
+    else if ( !auth_hibernate && !auth_suspend)
+    {
+        gtk_widget_set_sensitive (light_locker_sleep, FALSE);
+        gtk_widget_set_tooltip_text (light_locker_sleep, _("Hibernate and suspend operations not permitted"));
+    }
+
+    schema_source = g_settings_schema_source_get_default();
+    schema = g_settings_schema_source_lookup (schema_source, "apps.light-locker", FALSE);
+
+    if (schema != NULL && get_light_locker_path() != NULL) {
+        security_frame = GTK_WIDGET (gtk_builder_get_object (xml, "security-frame"));
+        gtk_widget_hide(security_frame);
+        /* Load the settings (Light Locker compiled with GSettings backend required) */
+        light_locker_settings = g_settings_new ("apps.light-locker");
+
+        variant = g_settings_get_value (light_locker_settings, "late-locking");
+        late_locking = g_variant_get_boolean (variant);
+
+        variant = g_settings_get_value (light_locker_settings, "lock-on-suspend");
+        lock_on_suspend = g_variant_get_boolean (variant);
+        xfpm_lock_on_suspend = xfconf_channel_get_bool (channel, PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE);
+        if (lock_on_suspend != xfpm_lock_on_suspend) {
+            variant = g_variant_new_boolean (xfpm_lock_on_suspend);
+            g_settings_set_value (light_locker_settings, "lock-on-suspend", variant);
+            lock_on_suspend = xfpm_lock_on_suspend;
+        }
+
+        variant = g_settings_get_value (light_locker_settings, "lock-after-screensaver");
+        lock_after_screensaver = g_variant_get_uint32 (variant);
+
+        gtk_widget_set_sensitive (light_locker_delay, lock_after_screensaver != 0);
+
+        if (lock_after_screensaver > 60) {
+            lock_after_screensaver = (lock_after_screensaver / 60) + 60;
+        }
+
+        /* Apply the settings */
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(light_locker_enable), light_locker_get_enabled());
+
+        if (lock_after_screensaver == 0) {
+            gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 0);
+        } else {
+            if (!late_locking) {
+                gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 1);
+            } else {
+                gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 2);
+            }
+            gtk_range_set_value (GTK_RANGE(light_locker_delay), lock_after_screensaver);
+        }
+
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(light_locker_sleep), lock_on_suspend);
+
+        g_settings_schema_unref (schema);
+    } else {
+        g_warning("Schema \"apps.light-locker\" not found. Not configuring Light Locker.");
+        gtk_widget_hide (light_locker_tab);
+    }
+}
+/* END Light Locker Integration */
+
 /* Call gtk_tree_iter_free when done with the tree iter */
 static GtkTreeIter*
 find_device_in_tree (const gchar *object_path)
@@ -2181,6 +2618,10 @@ xfpm_settings_dialog_new (XfconfChannel
 
     xfpm_settings_advanced (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate, has_battery);
 
+    /* Light Locker Integration */
+    xfpm_settings_light_locker (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate);
+    /* END Light Locker Integration */
+
     if ( !has_lcd_brightness )
     {
     frame = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-frame"));
Download as text