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
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
|
/* $Id$ */
/*
* Papadimitriou Spiros <spapadim+@cs.cmu.edu>
*
* This code released under the GNU GPL.
* Read the file COPYING for more information.
*
* Preferences dialog
*
*/
/* Radar map on by default. */
#define RADARMAP
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <locale.h>
#include <mate-panel-applet.h>
#include <gio/gio.h>
#define MATEWEATHER_I_KNOW_THIS_IS_UNSTABLE
#include <libmateweather/mateweather-xml.h>
#include "mateweather.h"
#include "mateweather-pref.h"
#include "mateweather-applet.h"
#include "mateweather-dialog.h"
#define NEVER_SENSITIVE "never_sensitive"
#if GTK_CHECK_VERSION (3, 0, 0)
#define gtk_vbox_new(X,Y) gtk_box_new(GTK_ORIENTATION_VERTICAL,Y)
#define gtk_hbox_new(X,Y) gtk_box_new(GTK_ORIENTATION_HORIZONTAL,Y)
#endif
struct _MateWeatherPrefPrivate {
GtkWidget* basic_temp_combo;
GtkWidget* basic_speed_combo;
GtkWidget* basic_dist_combo;
GtkWidget* basic_pres_combo;
GtkWidget* find_entry;
GtkWidget* find_next_btn;
#ifdef RADARMAP
GtkWidget* basic_radar_btn;
GtkWidget* basic_radar_url_btn;
GtkWidget* basic_radar_url_hbox;
GtkWidget* basic_radar_url_entry;
#endif /* RADARMAP */
#ifdef HAVE_LIBNOTIFY
GtkWidget* basic_show_notifications_btn;
#endif
GtkWidget* basic_update_spin;
GtkWidget* basic_update_btn;
GtkWidget* tree;
GtkTreeModel* model;
MateWeatherApplet* applet;
};
enum {
PROP_0,
PROP_MATEWEATHER_APPLET,
};
G_DEFINE_TYPE(MateWeatherPref, mateweather_pref, GTK_TYPE_DIALOG);
#define MATEWEATHER_PREF_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), MATEWEATHER_TYPE_PREF, MateWeatherPrefPrivate))
/* set sensitive and setup NEVER_SENSITIVE appropriately */
static void hard_set_sensitive(GtkWidget* w, gboolean sensitivity)
{
gtk_widget_set_sensitive(w, sensitivity);
g_object_set_data(G_OBJECT(w), NEVER_SENSITIVE, GINT_TO_POINTER(!sensitivity));
}
/* set sensitive, but always insensitive if NEVER_SENSITIVE is set */
static void soft_set_sensitive(GtkWidget* w, gboolean sensitivity)
{
if (g_object_get_data(G_OBJECT(w), NEVER_SENSITIVE))
{
gtk_widget_set_sensitive(w, FALSE);
}
else
{
gtk_widget_set_sensitive(w, sensitivity);
}
}
/* sets up ATK Relation between the widgets */
static void add_atk_relation(GtkWidget* widget1, GtkWidget* widget2, AtkRelationType type)
{
AtkObject* atk_obj1;
AtkObject* atk_obj2;
AtkRelationSet* relation_set;
AtkRelation* relation;
atk_obj1 = gtk_widget_get_accessible(widget1);
if (!GTK_IS_ACCESSIBLE(atk_obj1))
{
return;
}
atk_obj2 = gtk_widget_get_accessible(widget2);
relation_set = atk_object_ref_relation_set(atk_obj1);
relation = atk_relation_new(&atk_obj2, 1, type);
atk_relation_set_add(relation_set, relation);
g_object_unref(G_OBJECT(relation));
}
/* sets accessible name and description */
void set_access_namedesc(GtkWidget* widget, const gchar* name, const gchar* desc)
{
AtkObject* obj = gtk_widget_get_accessible(widget);
if (!GTK_IS_ACCESSIBLE(obj))
{
return;
}
if (desc)
{
atk_object_set_description(obj, desc);
}
if (name)
{
atk_object_set_name(obj, name);
}
}
/* sets accessible name, description, CONTROLLED_BY
* and CONTROLLER_FOR relations for the components
* in mateweather preference dialog.
*/
static void mateweather_pref_set_accessibility(MateWeatherPref* pref)
{
/* Relation between components in General page */
add_atk_relation(pref->priv->basic_update_btn, pref->priv->basic_update_spin, ATK_RELATION_CONTROLLER_FOR);
add_atk_relation(pref->priv->basic_radar_btn, pref->priv->basic_radar_url_btn, ATK_RELATION_CONTROLLER_FOR);
add_atk_relation(pref->priv->basic_radar_btn, pref->priv->basic_radar_url_entry, ATK_RELATION_CONTROLLER_FOR);
add_atk_relation(pref->priv->basic_update_spin, pref->priv->basic_update_btn, ATK_RELATION_CONTROLLED_BY);
add_atk_relation(pref->priv->basic_radar_url_btn, pref->priv->basic_radar_btn, ATK_RELATION_CONTROLLED_BY);
add_atk_relation(pref->priv->basic_radar_url_entry, pref->priv->basic_radar_btn, ATK_RELATION_CONTROLLED_BY);
/* Accessible Name and Description for the components in Preference Dialog */
set_access_namedesc(pref->priv->tree, _("Location view"), _("Select Location from the list"));
set_access_namedesc(pref->priv->basic_update_spin, _("Update spin button"), _("Spinbutton for updating"));
set_access_namedesc(pref->priv->basic_radar_url_entry, _("Address Entry"), _("Enter the URL"));
}
/* Update pref dialog from mateweather_pref */
static gboolean update_dialog(MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
g_return_val_if_fail(gw_applet->mateweather_pref.location != NULL, FALSE);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(pref->priv->basic_update_spin), gw_applet->mateweather_pref.update_interval / 60);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref->priv->basic_update_btn), gw_applet->mateweather_pref.update_enabled);
soft_set_sensitive(pref->priv->basic_update_spin, gw_applet->mateweather_pref.update_enabled);
gtk_combo_box_set_active(GTK_COMBO_BOX(pref->priv->basic_temp_combo), gw_applet->mateweather_pref.temperature_unit - 2);
gtk_combo_box_set_active(GTK_COMBO_BOX(pref->priv->basic_speed_combo), gw_applet->mateweather_pref.speed_unit - 2);
gtk_combo_box_set_active(GTK_COMBO_BOX(pref->priv->basic_pres_combo), gw_applet->mateweather_pref.pressure_unit - 2);
gtk_combo_box_set_active(GTK_COMBO_BOX(pref->priv->basic_dist_combo), gw_applet->mateweather_pref.distance_unit - 2);
#ifdef RADARMAP
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref->priv->basic_radar_btn), gw_applet->mateweather_pref.radar_enabled);
soft_set_sensitive(pref->priv->basic_radar_url_btn, gw_applet->mateweather_pref.radar_enabled);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref->priv->basic_radar_url_btn), gw_applet->mateweather_pref.use_custom_radar_url);
soft_set_sensitive(pref->priv->basic_radar_url_hbox, gw_applet->mateweather_pref.radar_enabled);
if (gw_applet->mateweather_pref.radar)
{
gtk_entry_set_text(GTK_ENTRY(pref->priv->basic_radar_url_entry), gw_applet->mateweather_pref.radar);
}
#endif /* RADARMAP */
#ifdef HAVE_LIBNOTIFY
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref->priv->basic_show_notifications_btn), gw_applet->mateweather_pref.show_notifications);
#endif
return TRUE;
}
static void row_selected_cb(GtkTreeSelection* selection, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
GtkTreeModel* model;
WeatherLocation* loc = NULL;
GtkTreeIter iter;
if (!gtk_tree_selection_get_selected(selection, &model, &iter))
return;
gtk_tree_model_get(model, &iter, MATEWEATHER_XML_COL_POINTER, &loc, -1);
if (!loc)
{
return;
}
g_settings_set_string (gw_applet->settings, "location1", loc->code);
g_settings_set_string (gw_applet->settings, "location2", loc->zone);
g_settings_set_string (gw_applet->settings, "location3", loc->radar);
g_settings_set_string (gw_applet->settings, "location4", loc->name);
g_settings_set_string (gw_applet->settings, "coordinates", loc->coordinates);
if (gw_applet->mateweather_pref.location)
{
weather_location_free(gw_applet->mateweather_pref.location);
}
gw_applet->mateweather_pref.location =
weather_location_new (loc->name, loc->code, loc->zone, loc->radar, loc->coordinates,
NULL, NULL);
mateweather_update(gw_applet);
}
static gboolean compare_location(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, gpointer user_data)
{
MateWeatherPref* pref = user_data;
WeatherLocation* loc;
GtkTreeView* view;
gtk_tree_model_get(model, iter, MATEWEATHER_XML_COL_POINTER, &loc, -1);
if (!loc)
{
return FALSE;
}
if (!weather_location_equal(loc, pref->priv->applet->mateweather_pref.location))
{
return FALSE;
}
view = GTK_TREE_VIEW(pref->priv->tree);
gtk_tree_view_expand_to_path(view, path);
gtk_tree_view_set_cursor(view, path, NULL, FALSE);
gtk_tree_view_scroll_to_cell(view, path, NULL, TRUE, 0.5, 0.5);
return TRUE;
}
static void load_locations(MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
GtkTreeView* tree = GTK_TREE_VIEW(pref->priv->tree);
GtkTreeViewColumn* column;
GtkCellRenderer* cell_renderer;
WeatherLocation* current_location;
/* Add a column for the locations */
cell_renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("not used", cell_renderer, "text", MATEWEATHER_XML_COL_LOC, NULL);
gtk_tree_view_append_column(tree, column);
gtk_tree_view_set_expander_column(GTK_TREE_VIEW(tree), column);
/* load locations from xml file */
pref->priv->model = mateweather_xml_load_locations();
if (!pref->priv->model)
{
GtkWidget* d = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Failed to load the Locations XML database. Please report this as a bug."));
gtk_dialog_run(GTK_DIALOG(d));
gtk_widget_destroy(d);
}
gtk_tree_view_set_model (tree, pref->priv->model);
if (pref->priv->applet->mateweather_pref.location)
{
/* Select the current (default) location */
gtk_tree_model_foreach(GTK_TREE_MODEL(pref->priv->model), compare_location, pref);
}
}
static void show_notifications_toggled(GtkToggleButton* button, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
gboolean toggled = gtk_toggle_button_get_active(button);
if (toggled != gw_applet->mateweather_pref.show_notifications)
{
/* sync with mateweather_pref struct */
gw_applet->mateweather_pref.show_notifications = toggled;
/* sync with gsettings */
g_settings_set_boolean (gw_applet->settings, "show-notifications", toggled);
}
}
static void auto_update_toggled(GtkToggleButton* button, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
gboolean toggled;
gint nxtSunEvent;
toggled = gtk_toggle_button_get_active(button);
gw_applet->mateweather_pref.update_enabled = toggled;
soft_set_sensitive(pref->priv->basic_update_spin, toggled);
g_settings_set_boolean (gw_applet->settings, "auto-update", toggled);
if (gw_applet->timeout_tag > 0)
{
g_source_remove(gw_applet->timeout_tag);
}
if (gw_applet->suncalc_timeout_tag > 0)
{
g_source_remove(gw_applet->suncalc_timeout_tag);
}
if (gw_applet->mateweather_pref.update_enabled)
{
gw_applet->timeout_tag = g_timeout_add_seconds(gw_applet->mateweather_pref.update_interval, timeout_cb, gw_applet);
nxtSunEvent = weather_info_next_sun_event(gw_applet->mateweather_info);
if (nxtSunEvent >= 0)
{
gw_applet->suncalc_timeout_tag = g_timeout_add_seconds(nxtSunEvent, suncalc_timeout_cb, gw_applet);
}
}
}
static void temp_combo_changed_cb(GtkComboBox* combo, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
TempUnit new_unit, old_unit;
g_return_if_fail(gw_applet != NULL);
new_unit = gtk_combo_box_get_active(combo) + 2;
old_unit = gw_applet->mateweather_pref.temperature_unit;
if (new_unit == old_unit)
{
return;
}
gw_applet->mateweather_pref.temperature_unit = new_unit;
g_settings_set_enum (gw_applet->settings, "temperature-unit", new_unit);
gtk_label_set_text(GTK_LABEL(gw_applet->label), weather_info_get_temp_summary(gw_applet->mateweather_info));
if (gw_applet->details_dialog)
{
mateweather_dialog_update(MATEWEATHER_DIALOG(gw_applet->details_dialog));
}
}
static void speed_combo_changed_cb(GtkComboBox* combo, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
SpeedUnit new_unit, old_unit;
g_return_if_fail(gw_applet != NULL);
new_unit = gtk_combo_box_get_active(combo) + 2;
old_unit = gw_applet->mateweather_pref.speed_unit;
if (new_unit == old_unit)
{
return;
}
gw_applet->mateweather_pref.speed_unit = new_unit;
g_settings_set_enum (gw_applet->settings, "speed-unit", new_unit);
if (gw_applet->details_dialog)
{
mateweather_dialog_update(MATEWEATHER_DIALOG(gw_applet->details_dialog));
}
}
static void pres_combo_changed_cb(GtkComboBox* combo, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
PressureUnit new_unit, old_unit;
g_return_if_fail(gw_applet != NULL);
new_unit = gtk_combo_box_get_active(combo) + 2;
old_unit = gw_applet->mateweather_pref.pressure_unit;
if (new_unit == old_unit)
{
return;
}
gw_applet->mateweather_pref.pressure_unit = new_unit;
g_settings_set_enum (gw_applet->settings, "pressure-unit", new_unit);
if (gw_applet->details_dialog)
{
mateweather_dialog_update(MATEWEATHER_DIALOG(gw_applet->details_dialog));
}
}
static void dist_combo_changed_cb(GtkComboBox* combo, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
DistanceUnit new_unit, old_unit;
g_return_if_fail(gw_applet != NULL);
new_unit = gtk_combo_box_get_active(combo) + 2;
old_unit = gw_applet->mateweather_pref.distance_unit;
if (new_unit == old_unit)
{
return;
}
gw_applet->mateweather_pref.distance_unit = new_unit;
g_settings_set_enum (gw_applet->settings, "distance-unit", new_unit);
if (gw_applet->details_dialog)
{
mateweather_dialog_update(MATEWEATHER_DIALOG(gw_applet->details_dialog));
}
}
static void radar_toggled(GtkToggleButton* button, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
gboolean toggled;
toggled = gtk_toggle_button_get_active(button);
gw_applet->mateweather_pref.radar_enabled = toggled;
g_settings_set_boolean (gw_applet->settings, "enable-radar-map", toggled);
soft_set_sensitive(pref->priv->basic_radar_url_btn, toggled);
if (toggled == FALSE || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (pref->priv->basic_radar_url_btn)) == TRUE)
{
soft_set_sensitive (pref->priv->basic_radar_url_hbox, toggled);
}
}
static void use_radar_url_toggled(GtkToggleButton* button, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
gboolean toggled;
toggled = gtk_toggle_button_get_active(button);
gw_applet->mateweather_pref.use_custom_radar_url = toggled;
g_settings_set_boolean (gw_applet->settings, "use-custom-radar-url", toggled);
soft_set_sensitive(pref->priv->basic_radar_url_hbox, toggled);
}
static gboolean radar_url_changed(GtkWidget* widget, GdkEventFocus* event, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
gchar *text;
text = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
if (gw_applet->mateweather_pref.radar)
{
g_free(gw_applet->mateweather_pref.radar);
}
if (text)
{
gw_applet->mateweather_pref.radar = g_strdup(text);
g_free (text);
}
else
{
gw_applet->mateweather_pref.radar = NULL;
}
g_settings_set_string (gw_applet->settings, "radar", gw_applet->mateweather_pref.radar);
return FALSE;
}
static void update_interval_changed(GtkSpinButton* button, MateWeatherPref* pref)
{
MateWeatherApplet* gw_applet = pref->priv->applet;
gw_applet->mateweather_pref.update_interval = gtk_spin_button_get_value_as_int(button)*60;
g_settings_set_int (gw_applet->settings, "auto-update-interval", gw_applet->mateweather_pref.update_interval);
if (gw_applet->timeout_tag > 0)
{
g_source_remove(gw_applet->timeout_tag);
}
if (gw_applet->mateweather_pref.update_enabled)
{
gw_applet->timeout_tag = g_timeout_add_seconds(gw_applet->mateweather_pref.update_interval, timeout_cb, gw_applet);
}
}
static gboolean free_data(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, gpointer data)
{
WeatherLocation* location;
gtk_tree_model_get(model, iter, MATEWEATHER_XML_COL_POINTER, &location, -1);
if (!location)
{
return FALSE;
}
weather_location_free(location);
return FALSE;
}
static GtkWidget* create_hig_category(GtkWidget* main_box, gchar* title)
{
GtkWidget* vbox;
GtkWidget* vbox2;
GtkWidget* hbox;
GtkWidget*label;
gchar* tmp;
vbox = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (main_box), vbox, FALSE, FALSE, 0);
tmp = g_strdup_printf ("<b>%s</b>", title);
label = gtk_label_new (NULL);
#if GTK_CHECK_VERSION (3, 16, 0)
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
#else
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
#endif
gtk_label_set_markup (GTK_LABEL (label), tmp);
g_free (tmp);
gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, FALSE, 0);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (" ");
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
vbox2 = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
return vbox2;
}
static gboolean find_location(GtkTreeModel* model, GtkTreeIter* iter, const gchar* location, gboolean go_parent)
{
GtkTreeIter iter_child;
GtkTreeIter iter_parent;
gchar* aux_loc;
gboolean valid;
int len;
len = strlen (location);
if (len <= 0)
{
return FALSE;
}
do {
gtk_tree_model_get (model, iter, MATEWEATHER_XML_COL_LOC, &aux_loc, -1);
if (g_ascii_strncasecmp (aux_loc, location, len) == 0)
{
g_free (aux_loc);
return TRUE;
}
if (gtk_tree_model_iter_has_child(model, iter))
{
gtk_tree_model_iter_nth_child(model, &iter_child, iter, 0);
if (find_location (model, &iter_child, location, FALSE))
{
/* Manual copying of the iter */
iter->stamp = iter_child.stamp;
iter->user_data = iter_child.user_data;
iter->user_data2 = iter_child.user_data2;
iter->user_data3 = iter_child.user_data3;
g_free (aux_loc);
return TRUE;
}
}
g_free (aux_loc);
valid = gtk_tree_model_iter_next(model, iter);
} while (valid);
if (go_parent)
{
iter_parent = *iter;
while (gtk_tree_model_iter_parent (model, iter, &iter_parent))
{
if (gtk_tree_model_iter_next (model, iter))
{
return find_location (model, iter, location, TRUE);
}
iter_parent = *iter;
}
}
return FALSE;
}
static void find_next_clicked(GtkButton* button, MateWeatherPref* pref)
{
GtkTreeView *tree;
GtkTreeModel *model;
GtkEntry *entry;
GtkTreeSelection *selection;
GtkTreeIter iter;
GtkTreeIter iter_parent;
GtkTreePath *path;
const gchar *location;
tree = GTK_TREE_VIEW (pref->priv->tree);
model = gtk_tree_view_get_model (tree);
entry = GTK_ENTRY (pref->priv->find_entry);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
if (gtk_tree_selection_count_selected_rows (selection) >= 1)
{
gtk_tree_selection_get_selected (selection, &model, &iter);
/* Select next or select parent */
if (!gtk_tree_model_iter_next (model, &iter))
{
iter_parent = iter;
if (!gtk_tree_model_iter_parent (model, &iter, &iter_parent) || !gtk_tree_model_iter_next (model, &iter))
{
gtk_tree_model_get_iter_first (model, &iter);
}
}
}
else
{
gtk_tree_model_get_iter_first (model, &iter);
}
location = gtk_entry_get_text (entry);
if (find_location (model, &iter, location, TRUE))
{
gtk_widget_set_sensitive (pref->priv->find_next_btn, TRUE);
path = gtk_tree_model_get_path (model, &iter);
gtk_tree_view_expand_to_path (tree, path);
gtk_tree_selection_select_path (selection, path);
gtk_tree_view_scroll_to_cell (tree, path, NULL, TRUE, 0.5, 0);
gtk_tree_path_free (path);
}
else
{
gtk_widget_set_sensitive (pref->priv->find_next_btn, FALSE);
}
}
static void find_entry_changed(GtkEditable* entry, MateWeatherPref* pref)
{
GtkTreeView *tree;
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeIter iter;
GtkTreePath *path;
const gchar *location;
tree = GTK_TREE_VIEW (pref->priv->tree);
model = gtk_tree_view_get_model (tree);
g_return_if_fail (model != NULL);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
gtk_tree_model_get_iter_first (model, &iter);
location = gtk_entry_get_text (GTK_ENTRY (entry));
if (find_location (model, &iter, location, TRUE))
{
gtk_widget_set_sensitive (pref->priv->find_next_btn, TRUE);
path = gtk_tree_model_get_path (model, &iter);
gtk_tree_view_expand_to_path (tree, path);
gtk_tree_selection_select_iter (selection, &iter);
gtk_tree_view_scroll_to_cell (tree, path, NULL, TRUE, 0.5, 0);
gtk_tree_path_free (path);
}
else
{
gtk_widget_set_sensitive (pref->priv->find_next_btn, FALSE);
}
}
static void help_cb(GtkDialog* dialog)
{
GError* error = NULL;
gtk_show_uri(gtk_widget_get_screen(GTK_WIDGET(dialog)), "help:mateweather/mateweather-prefs", gtk_get_current_event_time(), &error);
if (error)
{
GtkWidget* error_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("There was an error displaying help: %s"), error->message);
g_signal_connect (G_OBJECT (error_dialog), "response", G_CALLBACK (gtk_widget_destroy), NULL);
gtk_window_set_resizable (GTK_WINDOW (error_dialog), FALSE);
gtk_window_set_screen (GTK_WINDOW (error_dialog), gtk_widget_get_screen (GTK_WIDGET (dialog)));
gtk_widget_show (error_dialog);
g_error_free (error);
error = NULL;
}
}
static void response_cb(GtkDialog* dialog, gint id, MateWeatherPref* pref)
{
if (id == GTK_RESPONSE_HELP)
{
help_cb(dialog);
}
else
{
gtk_widget_destroy(GTK_WIDGET(dialog));
}
}
static void mateweather_pref_create(MateWeatherPref* pref)
{
GtkWidget* pref_vbox;
GtkWidget* pref_notebook;
#ifdef RADARMAP
GtkWidget* radar_toggle_hbox;
#endif /* RADARMAP */
GtkWidget* pref_basic_update_alignment;
GtkWidget* pref_basic_update_lbl;
GtkWidget* pref_basic_update_hbox;
GObject* pref_basic_update_spin_adj;
GtkWidget* pref_basic_update_sec_lbl;
GtkWidget* pref_basic_note_lbl;
GtkWidget* pref_loc_hbox;
GtkWidget* pref_loc_note_lbl;
GtkWidget* scrolled_window;
GtkWidget* label;
GtkWidget* value_hbox;
GtkWidget* tree_label;
GtkTreeSelection *selection;
GtkWidget* pref_basic_vbox;
GtkWidget* vbox;
GtkWidget* frame;
GtkWidget* temp_label;
GtkWidget* temp_combo;
GtkWidget* speed_label;
GtkWidget* speed_combo;
GtkWidget* pres_label;
GtkWidget* pres_combo;
GtkWidget* dist_label;
GtkWidget* dist_combo;
#if GTK_CHECK_VERSION (3, 0, 0)
GtkWidget* unit_grid;
#else
GtkWidget* unit_table;
#endif
GtkWidget* pref_find_label;
GtkWidget* pref_find_hbox;
GtkWidget* image;
g_object_set (pref, "destroy-with-parent", TRUE, NULL);
gtk_window_set_title (GTK_WINDOW (pref), _("Weather Preferences"));
gtk_dialog_add_buttons (GTK_DIALOG (pref), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, GTK_STOCK_HELP, GTK_RESPONSE_HELP, NULL);
gtk_dialog_set_default_response (GTK_DIALOG (pref), GTK_RESPONSE_CLOSE);
gtk_container_set_border_width (GTK_CONTAINER (pref), 5);
gtk_window_set_resizable (GTK_WINDOW (pref), TRUE);
gtk_window_set_screen (GTK_WINDOW (pref), gtk_widget_get_screen (GTK_WIDGET (pref->priv->applet->applet)));
pref_vbox = gtk_dialog_get_content_area (GTK_DIALOG (pref));
gtk_box_set_spacing (GTK_BOX (pref_vbox), 2);
gtk_widget_show (pref_vbox);
pref_notebook = gtk_notebook_new ();
gtk_container_set_border_width (GTK_CONTAINER (pref_notebook), 5);
gtk_widget_show (pref_notebook);
gtk_box_pack_start (GTK_BOX (pref_vbox), pref_notebook, TRUE, TRUE, 0);
/*
* General settings page.
*/
pref_basic_vbox = gtk_vbox_new (FALSE, 18);
gtk_container_set_border_width (GTK_CONTAINER (pref_basic_vbox), 12);
gtk_container_add (GTK_CONTAINER (pref_notebook), pref_basic_vbox);
pref_basic_update_alignment = gtk_alignment_new (0, 0.5, 0, 1);
gtk_widget_show (pref_basic_update_alignment);
pref->priv->basic_update_btn = gtk_check_button_new_with_mnemonic (_("_Automatically update every:"));
gtk_widget_show (pref->priv->basic_update_btn);
gtk_container_add (GTK_CONTAINER (pref_basic_update_alignment), pref->priv->basic_update_btn);
g_signal_connect (G_OBJECT (pref->priv->basic_update_btn), "toggled", G_CALLBACK (auto_update_toggled), pref);
if (!g_settings_is_writable (pref->priv->applet->settings, "auto-update"))
{
hard_set_sensitive (pref->priv->basic_update_btn, FALSE);
}
/*
* Units settings page.
*/
/* Temperature Unit */
temp_label = gtk_label_new_with_mnemonic (_("_Temperature unit:"));
gtk_label_set_use_markup (GTK_LABEL (temp_label), TRUE);
gtk_label_set_justify (GTK_LABEL (temp_label), GTK_JUSTIFY_LEFT);
#if GTK_CHECK_VERSION (3, 16, 0)
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
#else
gtk_misc_set_alignment (GTK_MISC (temp_label), 0.0, 0.5);
#endif
gtk_widget_show (temp_label);
temp_combo = gtk_combo_box_text_new ();
pref->priv->basic_temp_combo = temp_combo;
gtk_label_set_mnemonic_widget (GTK_LABEL (temp_label), temp_combo);
//gtk_combo_box_append_text (GTK_COMBO_BOX (temp_combo), _("Default"));
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (temp_combo), _("Kelvin"));
/* TRANSLATORS: Celsius is sometimes referred Centigrade */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (temp_combo), _("Celsius"));
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (temp_combo), _("Fahrenheit"));
gtk_widget_show (temp_combo);
if ( ! g_settings_is_writable (pref->priv->applet->settings, "temperature-unit"))
{
hard_set_sensitive (pref->priv->basic_temp_combo, FALSE);
}
/* Speed Unit */
speed_label = gtk_label_new_with_mnemonic (_("_Wind speed unit:"));
gtk_label_set_use_markup (GTK_LABEL (speed_label), TRUE);
gtk_label_set_justify (GTK_LABEL (speed_label), GTK_JUSTIFY_LEFT);
#if GTK_CHECK_VERSION (3, 16, 0)
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
#else
gtk_misc_set_alignment (GTK_MISC (speed_label), 0.0, 0.5);
#endif
gtk_widget_show (speed_label);
speed_combo = gtk_combo_box_text_new ();
pref->priv->basic_speed_combo = speed_combo;
gtk_label_set_mnemonic_widget (GTK_LABEL (speed_label), speed_combo);
//gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("Default"));
/* TRANSLATOR: The wind speed unit "meters per second" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (speed_combo), _("m/s"));
/* TRANSLATOR: The wind speed unit "kilometers per hour" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (speed_combo), _("km/h"));
/* TRANSLATOR: The wind speed unit "miles per hour" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (speed_combo), _("mph"));
/* TRANSLATOR: The wind speed unit "knots" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (speed_combo), _("knots"));
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (speed_combo), _("Beaufort scale"));
gtk_widget_show (speed_combo);
if (!g_settings_is_writable (pref->priv->applet->settings, "speed-unit"))
{
hard_set_sensitive (pref->priv->basic_speed_combo, FALSE);
}
/* Pressure Unit */
pres_label = gtk_label_new_with_mnemonic (_("_Pressure unit:"));
gtk_label_set_use_markup (GTK_LABEL (pres_label), TRUE);
gtk_label_set_justify (GTK_LABEL (pres_label), GTK_JUSTIFY_LEFT);
#if GTK_CHECK_VERSION (3, 16, 0)
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
#else
gtk_misc_set_alignment (GTK_MISC (pres_label), 0.0, 0.5);
#endif
gtk_widget_show (pres_label);
pres_combo = gtk_combo_box_text_new ();
pref->priv->basic_pres_combo = pres_combo;
gtk_label_set_mnemonic_widget (GTK_LABEL (pres_label), pres_combo);
//gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("Default"));
/* TRANSLATOR: The pressure unit "kiloPascals" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (pres_combo), _("kPa"));
/* TRANSLATOR: The pressure unit "hectoPascals" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (pres_combo), _("hPa"));
/* TRANSLATOR: The pressure unit "millibars" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (pres_combo), _("mb"));
/* TRANSLATOR: The pressure unit "millibars of mercury" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (pres_combo), _("mmHg"));
/* TRANSLATOR: The pressure unit "inches of mercury" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (pres_combo), _("inHg"));
/* TRANSLATOR: The pressure unit "atmospheres" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (pres_combo), _("atm"));
gtk_widget_show (pres_combo);
if (!g_settings_is_writable(pref->priv->applet->settings, "pressure-unit"))
{
hard_set_sensitive(pref->priv->basic_pres_combo, FALSE);
}
/* Distance Unit */
dist_label = gtk_label_new_with_mnemonic (_("_Visibility unit:"));
gtk_label_set_use_markup (GTK_LABEL (dist_label), TRUE);
gtk_label_set_justify (GTK_LABEL (dist_label), GTK_JUSTIFY_LEFT);
#if GTK_CHECK_VERSION (3, 16, 0)
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
#else
gtk_misc_set_alignment (GTK_MISC (dist_label), 0, 0.5);
#endif
gtk_widget_show (dist_label);
dist_combo = gtk_combo_box_text_new ();
pref->priv->basic_dist_combo = dist_combo;
gtk_label_set_mnemonic_widget (GTK_LABEL (dist_label), dist_combo);
//gtk_combo_box_append_text (GTK_COMBO_BOX (dist_combo), _("Default"));
/* TRANSLATOR: The distance unit "meters" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dist_combo), _("meters"));
/* TRANSLATOR: The distance unit "kilometers" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dist_combo), _("km"));
/* TRANSLATOR: The distance unit "miles" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dist_combo), _("miles"));
gtk_widget_show (dist_combo);
if ( ! g_settings_is_writable (pref->priv->applet->settings, "distance-unit"))
hard_set_sensitive (pref->priv->basic_dist_combo, FALSE);
#if GTK_CHECK_VERSION (3, 0, 0)
unit_grid = gtk_grid_new ();
gtk_grid_set_row_spacing(GTK_GRID(unit_grid), 6);
gtk_grid_set_column_spacing(GTK_GRID(unit_grid), 12);
gtk_widget_set_halign (temp_label, GTK_ALIGN_START);
gtk_grid_attach(GTK_GRID(unit_grid), temp_label, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(unit_grid), temp_combo, 1, 0, 1, 1);
gtk_widget_set_halign (speed_label, GTK_ALIGN_START);
gtk_grid_attach(GTK_GRID(unit_grid), speed_label, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(unit_grid), speed_combo, 1, 1, 1, 1);
gtk_widget_set_halign (pres_label, GTK_ALIGN_START);
gtk_grid_attach(GTK_GRID(unit_grid), pres_label, 0, 2, 1, 1);
gtk_grid_attach(GTK_GRID(unit_grid), pres_combo, 1, 2, 1, 1);
gtk_widget_set_halign (dist_label, GTK_ALIGN_START);
gtk_grid_attach(GTK_GRID(unit_grid), dist_label, 0, 3, 1, 1);
gtk_grid_attach(GTK_GRID(unit_grid), dist_combo, 1, 3, 1, 1);
gtk_widget_show(unit_grid);
#else
unit_table = gtk_table_new(5, 2, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(unit_table), 6);
gtk_table_set_col_spacings(GTK_TABLE(unit_table), 12);
gtk_table_attach(GTK_TABLE(unit_table), temp_label, 0, 1, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_table_attach_defaults(GTK_TABLE(unit_table), temp_combo, 1, 2, 0, 1);
gtk_table_attach(GTK_TABLE(unit_table), speed_label, 0, 1, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_table_attach_defaults(GTK_TABLE(unit_table), speed_combo, 1, 2, 1, 2);
gtk_table_attach(GTK_TABLE(unit_table), pres_label, 0, 1, 2, 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_table_attach_defaults(GTK_TABLE(unit_table), pres_combo, 1, 2, 2, 3);
gtk_table_attach(GTK_TABLE(unit_table), dist_label, 0, 1, 3, 4, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_table_attach_defaults(GTK_TABLE(unit_table), dist_combo, 1, 2, 3, 4);
gtk_widget_show(unit_table);
#endif
g_signal_connect (temp_combo, "changed", G_CALLBACK (temp_combo_changed_cb), pref);
g_signal_connect (speed_combo, "changed", G_CALLBACK (speed_combo_changed_cb), pref);
g_signal_connect (dist_combo, "changed", G_CALLBACK (dist_combo_changed_cb), pref);
g_signal_connect (pres_combo, "changed", G_CALLBACK (pres_combo_changed_cb), pref);
#ifdef RADARMAP
pref->priv->basic_radar_btn = gtk_check_button_new_with_mnemonic (_("Enable _radar map"));
gtk_widget_show (pref->priv->basic_radar_btn);
g_signal_connect (G_OBJECT (pref->priv->basic_radar_btn), "toggled", G_CALLBACK (radar_toggled), pref);
if (!g_settings_is_writable (pref->priv->applet->settings, "enable-radar-map"))
{
hard_set_sensitive(pref->priv->basic_radar_btn, FALSE);
}
radar_toggle_hbox = gtk_hbox_new(FALSE, 12);
gtk_widget_show(radar_toggle_hbox);
label = gtk_label_new (" ");
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (radar_toggle_hbox), label, FALSE, FALSE, 0);
pref->priv->basic_radar_url_btn = gtk_check_button_new_with_mnemonic (_("Use _custom address for radar map"));
gtk_widget_show (pref->priv->basic_radar_url_btn);
gtk_box_pack_start (GTK_BOX (radar_toggle_hbox), pref->priv->basic_radar_url_btn, FALSE, FALSE, 0);
g_signal_connect (G_OBJECT (pref->priv->basic_radar_url_btn), "toggled", G_CALLBACK (use_radar_url_toggled), pref);
if ( ! g_settings_is_writable (pref->priv->applet->settings, "use-custom-radar-url"))
{
hard_set_sensitive (pref->priv->basic_radar_url_btn, FALSE);
}
pref->priv->basic_radar_url_hbox = gtk_hbox_new (FALSE, 12);
gtk_widget_show (pref->priv->basic_radar_url_hbox);
label = gtk_label_new (" ");
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (pref->priv->basic_radar_url_hbox), label, FALSE, FALSE, 0);
label = gtk_label_new_with_mnemonic (_("A_ddress:"));
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (pref->priv->basic_radar_url_hbox), label, FALSE, FALSE, 0);
pref->priv->basic_radar_url_entry = gtk_entry_new ();
gtk_widget_show (pref->priv->basic_radar_url_entry);
gtk_box_pack_start (GTK_BOX (pref->priv->basic_radar_url_hbox), pref->priv->basic_radar_url_entry, TRUE, TRUE, 0);
g_signal_connect (G_OBJECT (pref->priv->basic_radar_url_entry), "focus_out_event", G_CALLBACK (radar_url_changed), pref);
if ( ! g_settings_is_writable (pref->priv->applet->settings, "radar"))
{
hard_set_sensitive (pref->priv->basic_radar_url_entry, FALSE);
}
#endif /* RADARMAP */
#ifdef HAVE_LIBNOTIFY
/* setup show-notifications button */
pref->priv->basic_show_notifications_btn = gtk_check_button_new_with_mnemonic (_("Show _notifications"));
if (!g_settings_is_writable (pref->priv->applet->settings, "show-notifications"))
{
hard_set_sensitive (pref->priv->basic_show_notifications_btn, FALSE);
}
g_signal_connect (G_OBJECT (pref->priv->basic_show_notifications_btn), "toggled", G_CALLBACK (show_notifications_toggled), pref);
#endif
frame = create_hig_category (pref_basic_vbox, _("Update"));
pref_basic_update_hbox = gtk_hbox_new (FALSE, 12);
pref_basic_update_lbl = gtk_label_new_with_mnemonic (_("_Automatically update every:"));
gtk_widget_show (pref_basic_update_lbl);
gtk_widget_show (pref_basic_update_hbox);
pref_basic_update_spin_adj = gtk_adjustment_new (30, 1, 3600, 5, 25, 1);
pref->priv->basic_update_spin = gtk_spin_button_new (GTK_ADJUSTMENT (pref_basic_update_spin_adj), 1, 0);
gtk_widget_show (pref->priv->basic_update_spin);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (pref->priv->basic_update_spin), TRUE);
gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (pref->priv->basic_update_spin), GTK_UPDATE_IF_VALID);
g_signal_connect (G_OBJECT (pref->priv->basic_update_spin), "value_changed", G_CALLBACK (update_interval_changed), pref);
pref_basic_update_sec_lbl = gtk_label_new (_("minutes"));
gtk_widget_show (pref_basic_update_sec_lbl);
if ( ! g_settings_is_writable (pref->priv->applet->settings, "auto-update-interval"))
{
hard_set_sensitive (pref->priv->basic_update_spin, FALSE);
hard_set_sensitive (pref_basic_update_sec_lbl, FALSE);
}
value_hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (pref_basic_update_hbox), pref_basic_update_alignment, FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (pref_basic_update_hbox), value_hbox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (value_hbox), pref->priv->basic_update_spin, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (value_hbox), pref_basic_update_sec_lbl, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (frame), pref_basic_update_hbox);
frame = create_hig_category (pref_basic_vbox, _("Display"));
vbox = gtk_vbox_new (FALSE, 6);
#if GTK_CHECK_VERSION (3, 0, 0)
gtk_box_pack_start (GTK_BOX (vbox), unit_grid, TRUE, TRUE, 0);
#else
gtk_box_pack_start (GTK_BOX (vbox), unit_table, TRUE, TRUE, 0);
#endif
#ifdef RADARMAP
gtk_box_pack_start (GTK_BOX (vbox), pref->priv->basic_radar_btn, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), radar_toggle_hbox, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), pref->priv->basic_radar_url_hbox, TRUE, TRUE, 0);
#endif /* RADARMAP */
#ifdef HAVE_LIBNOTIFY
/* add the show-notification toggle button to the vbox of the display section */
gtk_box_pack_start (GTK_BOX (vbox), pref->priv->basic_show_notifications_btn, TRUE, TRUE, 0);
#endif
gtk_container_add (GTK_CONTAINER (frame), vbox);
pref_basic_note_lbl = gtk_label_new (_("General"));
gtk_widget_show (pref_basic_note_lbl);
gtk_notebook_set_tab_label (GTK_NOTEBOOK (pref_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (pref_notebook), 0), pref_basic_note_lbl);
/*
* Location page.
*/
pref_loc_hbox = gtk_vbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (pref_loc_hbox), 12);
gtk_container_add (GTK_CONTAINER (pref_notebook), pref_loc_hbox);
tree_label = gtk_label_new_with_mnemonic (_("_Select a location:"));
#if GTK_CHECK_VERSION (3, 16, 0)
gtk_label_set_xalign (GTK_LABEL (tree_label), 0.0);
#else
gtk_misc_set_alignment (GTK_MISC (tree_label), 0.0, 0.5);
#endif
gtk_box_pack_start (GTK_BOX (pref_loc_hbox), tree_label, FALSE, FALSE, 0);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
pref->priv->tree = gtk_tree_view_new ();
gtk_label_set_mnemonic_widget (GTK_LABEL (tree_label), GTK_WIDGET (pref->priv->tree));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (pref->priv->tree), FALSE);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pref->priv->tree));
g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (row_selected_cb), pref);
gtk_container_add (GTK_CONTAINER (scrolled_window), pref->priv->tree);
gtk_widget_show (pref->priv->tree);
gtk_widget_show (scrolled_window);
gtk_box_pack_start (GTK_BOX (pref_loc_hbox), scrolled_window, TRUE, TRUE, 0);
load_locations(pref);
pref_find_hbox = gtk_hbox_new (FALSE, 6);
pref_find_label = gtk_label_new (_("_Find:"));
gtk_label_set_use_underline (GTK_LABEL (pref_find_label), TRUE);
pref->priv->find_entry = gtk_entry_new ();
gtk_label_set_mnemonic_widget (GTK_LABEL (pref_find_label), pref->priv->find_entry);
pref->priv->find_next_btn = gtk_button_new_with_mnemonic (_("Find _Next"));
gtk_widget_set_sensitive (pref->priv->find_next_btn, FALSE);
image = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_BUTTON);
gtk_button_set_image (GTK_BUTTON (pref->priv->find_next_btn), image);
g_signal_connect (G_OBJECT (pref->priv->find_next_btn), "clicked", G_CALLBACK (find_next_clicked), pref);
g_signal_connect (G_OBJECT (pref->priv->find_entry), "changed", G_CALLBACK (find_entry_changed), pref);
gtk_container_set_border_width (GTK_CONTAINER (pref_find_hbox), 0);
gtk_box_pack_start (GTK_BOX (pref_find_hbox), pref_find_label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (pref_find_hbox), pref->priv->find_entry, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (pref_find_hbox), pref->priv->find_next_btn, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (pref_loc_hbox), pref_find_hbox, FALSE, FALSE, 0);
if ( ! g_settings_is_writable (pref->priv->applet->settings, "location0"))
{
hard_set_sensitive (scrolled_window, FALSE);
}
pref_loc_note_lbl = gtk_label_new (_("Location"));
gtk_widget_show (pref_loc_note_lbl);
gtk_notebook_set_tab_label (GTK_NOTEBOOK (pref_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (pref_notebook), 1), pref_loc_note_lbl);
g_signal_connect (G_OBJECT (pref), "response", G_CALLBACK (response_cb), pref);
mateweather_pref_set_accessibility (pref);
gtk_label_set_mnemonic_widget (GTK_LABEL (pref_basic_update_sec_lbl), pref->priv->basic_update_spin);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), pref->priv->basic_radar_url_entry);
}
static void mateweather_pref_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec *pspec)
{
MateWeatherPref* pref = MATEWEATHER_PREF(object);
switch (prop_id)
{
case PROP_MATEWEATHER_APPLET:
pref->priv->applet = g_value_get_pointer(value);
break;
}
}
static void mateweather_pref_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
{
MateWeatherPref* pref = MATEWEATHER_PREF(object);
switch (prop_id)
{
case PROP_MATEWEATHER_APPLET:
g_value_set_pointer(value, pref->priv->applet);
break;
}
}
static void mateweather_pref_init(MateWeatherPref* self)
{
self->priv = MATEWEATHER_PREF_GET_PRIVATE(self);
}
static GObject* mateweather_pref_constructor(GType type, guint n_construct_params, GObjectConstructParam* construct_params)
{
GObject* object;
MateWeatherPref* self;
object = G_OBJECT_CLASS(mateweather_pref_parent_class)->constructor(type, n_construct_params, construct_params);
self = MATEWEATHER_PREF(object);
mateweather_pref_create(self);
update_dialog(self);
return object;
}
GtkWidget* mateweather_pref_new(MateWeatherApplet* applet)
{
return g_object_new(MATEWEATHER_TYPE_PREF, "mateweather-applet", applet, NULL);
}
static void mateweather_pref_finalize(GObject* object)
{
MateWeatherPref* self = MATEWEATHER_PREF(object);
gtk_tree_model_foreach(self->priv->model, free_data, NULL);
g_object_unref(G_OBJECT(self->priv->model));
G_OBJECT_CLASS(mateweather_pref_parent_class)->finalize(object);
}
static void mateweather_pref_class_init(MateWeatherPrefClass* klass)
{
GObjectClass* object_class = G_OBJECT_CLASS(klass);
mateweather_pref_parent_class = g_type_class_peek_parent(klass);
object_class->set_property = mateweather_pref_set_property;
object_class->get_property = mateweather_pref_get_property;
object_class->constructor = mateweather_pref_constructor;
object_class->finalize = mateweather_pref_finalize;
/* This becomes an OBJECT property when MateWeatherApplet is redone */
g_object_class_install_property(object_class, PROP_MATEWEATHER_APPLET, g_param_spec_pointer("mateweather-applet", "MateWeather Applet", "The MateWeather Applet", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private(klass, sizeof(MateWeatherPrefPrivate));
}
|