support_solarmoon_and_solarmidnight.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. From 72c34872bad6ff11cc6e74245ab5db805132c4bd Mon Sep 17 00:00:00 2001
  2. From: Goran <tiny.lasagna@protonmail.com>
  3. Date: Sat, 29 Feb 2020 23:50:00 -0500
  4. Subject: Support solarnoon and solarmidnight (bug #15771)
  5. ---
  6. panel-plugin/weather-data.c | 15 ++++++++-------
  7. panel-plugin/weather-parsers.c | 10 ++++++++++
  8. panel-plugin/weather-parsers.h | 2 ++
  9. panel-plugin/weather.c | 29 +++++++++++++++++++++++++----
  10. 4 files changed, 45 insertions(+), 11 deletions(-)
  11. diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
  12. index 008a60c..fa6a4bd 100644
  13. --- a/panel-plugin/weather-data.c
  14. +++ b/panel-plugin/weather-data.c
  15. @@ -552,13 +552,14 @@ is_night_time(const xml_astro *astro)
  16. time(&now_t);
  17. if (G_LIKELY(astro)) {
  18. - /* Polar night */
  19. - if (astro->sun_never_rises)
  20. - return TRUE;
  21. -
  22. - /* Polar day */
  23. - if (astro->sun_never_sets)
  24. - return FALSE;
  25. + if (astro->sun_never_rises || astro->sun_never_sets){
  26. + /* Polar night */
  27. + if (astro->solarnoon_elevation <= 0)
  28. + return TRUE;
  29. + /* Polar day */
  30. + if (astro->solarmidnight_elevation > 0)
  31. + return FALSE;
  32. + }
  33. /* Sunrise and sunset are known */
  34. if (difftime(astro->sunrise, now_t) > 0)
  35. diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
  36. index 786abf7..baa0250 100644
  37. --- a/panel-plugin/weather-parsers.c
  38. +++ b/panel-plugin/weather-parsers.c
  39. @@ -478,6 +478,14 @@ parse_astro_time(xmlNode *cur_node)
  40. }
  41. astro->moon_phase = g_strdup(parse_moonposition(moonposition));
  42. }
  43. +
  44. + if (NODE_IS_TYPE(child_node, "solarnoon")) {
  45. + astro->solarnoon_elevation = extract_double(PROP(child_node, "elevation"));
  46. + }
  47. +
  48. + if (NODE_IS_TYPE(child_node, "solarmidnight")) {
  49. + astro->solarmidnight_elevation = extract_double(PROP(child_node, "elevation"));
  50. + }
  51. }
  52. }
  53. @@ -737,6 +745,8 @@ xml_astro_copy(const xml_astro *src)
  54. dst->moon_never_rises = src->moon_never_rises;
  55. dst->moon_never_sets = src->moon_never_sets;
  56. dst->moon_phase = g_strdup(src->moon_phase);
  57. + dst->solarnoon_elevation = src->solarnoon_elevation;
  58. + dst->solarmidnight_elevation = src->solarmidnight_elevation;
  59. return dst;
  60. }
  61. diff --git a/panel-plugin/weather-parsers.h b/panel-plugin/weather-parsers.h
  62. index 2b98d2f..f0697a7 100644
  63. --- a/panel-plugin/weather-parsers.h
  64. +++ b/panel-plugin/weather-parsers.h
  65. @@ -86,6 +86,8 @@ typedef struct {
  66. time_t sunset;
  67. gboolean sun_never_rises;
  68. gboolean sun_never_sets;
  69. + gdouble solarnoon_elevation;
  70. + gdouble solarmidnight_elevation;
  71. time_t moonrise;
  72. time_t moonset;
  73. diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
  74. index 11f6f6f..8780c0e 100644
  75. --- a/panel-plugin/weather.c
  76. +++ b/panel-plugin/weather.c
  77. @@ -1125,6 +1125,8 @@ write_cache_file(plugin_data *data)
  78. astro->sun_never_rises ? "true" : "false");
  79. CACHE_APPEND("sun_never_sets=%s\n",
  80. astro->sun_never_sets ? "true" : "false");
  81. + CACHE_APPEND("solarnoon_elevation=%e\n", astro->solarnoon_elevation);
  82. + CACHE_APPEND("solarmidnight_elevation=%e\n", astro->solarmidnight_elevation);
  83. g_free(value);
  84. g_free(start);
  85. g_free(end);
  86. @@ -1312,6 +1314,10 @@ read_cache_file(plugin_data *data)
  87. g_key_file_get_boolean(keyfile, group, "sun_never_rises", NULL);
  88. astro->sun_never_sets =
  89. g_key_file_get_boolean(keyfile, group, "sun_never_sets", NULL);
  90. + astro->solarnoon_elevation =
  91. + g_key_file_get_double(keyfile, group, "solarnoon_elevation", NULL);
  92. + astro->solarmidnight_elevation =
  93. + g_key_file_get_double(keyfile, group, "solarmidnight_elevation", NULL);
  94. CACHE_READ_STRING(timestring, "moonrise");
  95. astro->moonrise = parse_timestring(timestring, NULL, TRUE);
  96. @@ -1725,10 +1731,25 @@ weather_get_tooltip_text(const plugin_data *data)
  97. /* use sunrise and sunset times if available */
  98. if (data->current_astro)
  99. - if (data->current_astro->sun_never_rises) {
  100. - sunval = g_strdup(_("The sun never rises today."));
  101. - } else if (data->current_astro->sun_never_sets) {
  102. - sunval = g_strdup(_("The sun never sets today."));
  103. + if (data->current_astro->sun_never_rises && data->current_astro->sun_never_sets) {
  104. + if (data->current_astro->solarmidnight_elevation > 0)
  105. + sunval = g_strdup(_("The sun never sets today."));
  106. + else if (data->current_astro->solarnoon_elevation <= 0)
  107. + sunval = g_strdup(_("The sun never rises today."));
  108. + }
  109. + else if (data->current_astro->sun_never_rises){
  110. + sunset = format_date(data->current_astro->sunset,
  111. + "%H:%M:%S", FALSE);
  112. + sunval =
  113. + g_strdup_printf(_("The sun never rises and sets at %s."),
  114. + sunset);
  115. + }
  116. + else if (data->current_astro->sun_never_sets){
  117. + sunrise = format_date(data->current_astro->sunrise,
  118. + "%H:%M:%S", FALSE);
  119. + sunval =
  120. + g_strdup_printf(_("The sun rises at %s and never sets."),
  121. + sunset);
  122. } else {
  123. sunrise = format_date(data->current_astro->sunrise,
  124. "%H:%M:%S", TRUE);
  125. --
  126. cgit v1.2.3