20
20
21
21
#include "config.h"
22
22
23
- // #include <geoclue.h>
24
-
25
23
#define GNOME_DESKTOP_USE_UNSTABLE_API
26
24
#include "gnome-datetime-source.h"
27
25
28
26
#include "csd-color-state.h"
29
27
30
28
#include "csd-night-light.h"
31
29
#include "csd-night-light-common.h"
30
+ #include "tz-coords.h"
32
31
33
32
struct _CsdNightLight {
34
33
GObject parent ;
@@ -39,8 +38,6 @@ struct _CsdNightLight {
39
38
gboolean geoclue_enabled ;
40
39
GSource * source ;
41
40
guint validate_id ;
42
- // GClueClient *geoclue_client;
43
- // GClueSimple *geoclue_simple;
44
41
GSettings * location_settings ;
45
42
gdouble cached_sunrise ;
46
43
gdouble cached_sunset ;
@@ -378,27 +375,6 @@ night_light_recheck (CsdNightLight *self)
378
375
csd_night_light_set_temperature (self , temp_smeared );
379
376
}
380
377
381
- static gboolean
382
- night_light_recheck_schedule_cb (gpointer user_data )
383
- {
384
- CsdNightLight * self = CSD_NIGHT_LIGHT (user_data );
385
- night_light_recheck (self );
386
- self -> validate_id = 0 ;
387
- return G_SOURCE_REMOVE ;
388
- }
389
-
390
- /* called when something changed */
391
- static void
392
- night_light_recheck_schedule (CsdNightLight * self )
393
- {
394
- if (self -> validate_id != 0 )
395
- g_source_remove (self -> validate_id );
396
- self -> validate_id =
397
- g_timeout_add_seconds (CSD_NIGHT_LIGHT_SCHEDULE_TIMEOUT ,
398
- night_light_recheck_schedule_cb ,
399
- self );
400
- }
401
-
402
378
/* called when the time may have changed */
403
379
static gboolean
404
380
night_light_recheck_cb (gpointer user_data )
@@ -454,89 +430,34 @@ settings_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
454
430
night_light_recheck (self );
455
431
}
456
432
457
- // static void
458
- // on_location_notify (GClueSimple *simple,
459
- // GParamSpec *pspec,
460
- // gpointer user_data)
461
- // {
462
- // CsdNightLight *self = CSD_NIGHT_LIGHT (user_data);
463
- // GClueLocation *location;
464
- // gdouble latitude, longitude;
465
-
466
- // location = gclue_simple_get_location (simple);
467
- // latitude = gclue_location_get_latitude (location);
468
- // longitude = gclue_location_get_longitude (location);
469
-
470
- // g_settings_set_value (self->settings,
471
- // "night-light-last-coordinates",
472
- // g_variant_new ("(dd)", latitude, longitude));
473
-
474
- // g_debug ("got geoclue latitude %f, longitude %f", latitude, longitude);
475
-
476
- // /* recheck the levels if the location changed significantly */
477
- // if (update_cached_sunrise_sunset (self))
478
- // night_light_recheck_schedule (self);
479
- // }
480
-
481
- // static void
482
- // on_geoclue_simple_ready (GObject *source_object,
483
- // GAsyncResult *res,
484
- // gpointer user_data)
485
- // {
486
- // CsdNightLight *self = CSD_NIGHT_LIGHT (user_data);
487
- // GClueSimple *geoclue_simple;
488
- // g_autoptr(GError) error = NULL;
489
-
490
- // geoclue_simple = gclue_simple_new_finish (res, &error);
491
- // if (geoclue_simple == NULL) {
492
- // if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
493
- // g_warning ("Failed to connect to GeoClue2 service: %s", error->message);
494
- // return;
495
- // }
496
-
497
- // self->geoclue_simple = geoclue_simple;
498
- // self->geoclue_client = gclue_simple_get_client (self->geoclue_simple);
499
- // g_object_set (G_OBJECT (self->geoclue_client),
500
- // "time-threshold", 60*60, NULL); /* 1 hour */
501
-
502
- // g_signal_connect (self->geoclue_simple, "notify::location",
503
- // G_CALLBACK (on_location_notify), user_data);
504
-
505
- // on_location_notify (self->geoclue_simple, NULL, user_data);
506
- // }
507
-
508
- // static void
509
- // start_geoclue (CsdNightLight *self)
510
- // {
511
- // self->cancellable = g_cancellable_new ();
512
- // gclue_simple_new (DESKTOP_ID,
513
- // GCLUE_ACCURACY_LEVEL_CITY,
514
- // self->cancellable,
515
- // on_geoclue_simple_ready,
516
- // self);
517
-
518
- // }
519
-
520
- // static void
521
- // stop_geoclue (CsdNightLight *self)
522
- // {
523
- // g_cancellable_cancel (self->cancellable);
524
- // g_clear_object (&self->cancellable);
525
-
526
- // if (self->geoclue_client != NULL) {
527
- // gclue_client_call_stop (self->geoclue_client, NULL, NULL, NULL);
528
- // self->geoclue_client = NULL;
529
- // }
530
- // g_clear_object (&self->geoclue_simple);
531
- // }
433
+ static void
434
+ update_location_from_timezone (CsdNightLight * self )
435
+ {
436
+ GTimeZone * tz = g_time_zone_new_local ();
437
+ const gchar * id = g_time_zone_get_identifier (tz );
438
+
439
+ for (int i = 0 ; i < G_N_ELEMENTS (tz_coord_list ); i ++ )
440
+ {
441
+ const TZCoords * coords = & tz_coord_list [i ];
442
+ if (g_strcmp0 (coords -> timezone , id ) == 0 )
443
+ {
444
+ g_settings_set_value (self -> settings ,
445
+ "night-light-last-coordinates" ,
446
+ g_variant_new ("(dd)" , coords -> latitude , coords -> longitude ));
447
+ break ;
448
+ }
449
+ }
450
+
451
+ g_time_zone_unref (tz );
452
+ }
532
453
533
454
static void
534
455
check_location_settings (CsdNightLight * self )
535
456
{
536
- // if (g_settings_get_boolean (self->location_settings, "enabled") && self->geoclue_enabled)
537
- // start_geoclue (self);
538
- // else
539
- // stop_geoclue (self);
457
+ if (g_settings_get_boolean (self -> location_settings , "enabled" ) && self -> geoclue_enabled )
458
+ {
459
+ update_location_from_timezone ( self );
460
+ }
540
461
}
541
462
542
463
void
@@ -636,8 +557,6 @@ csd_night_light_finalize (GObject *object)
636
557
{
637
558
CsdNightLight * self = CSD_NIGHT_LIGHT (object );
638
559
639
- // stop_geoclue (self);
640
-
641
560
poll_timeout_destroy (self );
642
561
poll_smooth_destroy (self );
643
562
0 commit comments