| |
1 /* |
| |
2 * Pidgin - Internet Messenger |
| |
3 * Copyright (C) Pidgin Developers <devel@pidgin.im> |
| |
4 * |
| |
5 * Pidgin is the legal property of its developers, whose names are too numerous |
| |
6 * to list here. Please refer to the COPYRIGHT file distributed with this |
| |
7 * source distribution. |
| |
8 * |
| |
9 * This program is free software; you can redistribute it and/or modify |
| |
10 * it under the terms of the GNU General Public License as published by |
| |
11 * the Free Software Foundation; either version 2 of the License, or |
| |
12 * (at your option) any later version. |
| |
13 * |
| |
14 * This program is distributed in the hope that it will be useful, |
| |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| |
17 * GNU General Public License for more details. |
| |
18 * |
| |
19 * You should have received a copy of the GNU General Public License |
| |
20 * along with this program; if not, see <https://www.gnu.org/licenses/>. |
| |
21 */ |
| |
22 |
| |
23 #include <purple.h> |
| |
24 |
| |
25 #include <handy.h> |
| |
26 |
| |
27 #include "pidginawayprefs.h" |
| |
28 #include "gtksavedstatuses.h" |
| |
29 #include "gtkutils.h" |
| |
30 #include "pidginprefsinternal.h" |
| |
31 |
| |
32 struct _PidginAwayPrefs { |
| |
33 HdyPreferencesPage parent; |
| |
34 |
| |
35 PidginPrefCombo idle_reporting; |
| |
36 GtkWidget *mins_before_away; |
| |
37 GtkWidget *idle_hbox; |
| |
38 GtkWidget *away_when_idle; |
| |
39 PidginPrefCombo auto_reply; |
| |
40 GtkWidget *startup_current_status; |
| |
41 GtkWidget *startup_hbox; |
| |
42 GtkWidget *startup_label; |
| |
43 }; |
| |
44 |
| |
45 G_DEFINE_TYPE(PidginAwayPrefs, pidgin_away_prefs, HDY_TYPE_PREFERENCES_PAGE) |
| |
46 |
| |
47 /****************************************************************************** |
| |
48 * Helpers |
| |
49 *****************************************************************************/ |
| |
50 static void |
| |
51 set_idle_away(PurpleSavedStatus *status) |
| |
52 { |
| |
53 purple_prefs_set_int("/purple/savedstatus/idleaway", |
| |
54 purple_savedstatus_get_creation_time(status)); |
| |
55 } |
| |
56 |
| |
57 static void |
| |
58 set_startupstatus(PurpleSavedStatus *status) |
| |
59 { |
| |
60 purple_prefs_set_int("/purple/savedstatus/startup", |
| |
61 purple_savedstatus_get_creation_time(status)); |
| |
62 } |
| |
63 |
| |
64 /****************************************************************************** |
| |
65 * GObject Implementation |
| |
66 *****************************************************************************/ |
| |
67 static void |
| |
68 pidgin_away_prefs_class_init(PidginAwayPrefsClass *klass) |
| |
69 { |
| |
70 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
| |
71 |
| |
72 gtk_widget_class_set_template_from_resource( |
| |
73 widget_class, |
| |
74 "/im/pidgin/Pidgin3/Prefs/away.ui" |
| |
75 ); |
| |
76 |
| |
77 gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, |
| |
78 idle_reporting.combo); |
| |
79 gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, |
| |
80 mins_before_away); |
| |
81 gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, |
| |
82 away_when_idle); |
| |
83 gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, |
| |
84 idle_hbox); |
| |
85 gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, |
| |
86 auto_reply.combo); |
| |
87 gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, |
| |
88 startup_current_status); |
| |
89 gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, |
| |
90 startup_hbox); |
| |
91 gtk_widget_class_bind_template_child(widget_class, PidginAwayPrefs, |
| |
92 startup_label); |
| |
93 } |
| |
94 |
| |
95 static void |
| |
96 pidgin_away_prefs_init(PidginAwayPrefs *prefs) |
| |
97 { |
| |
98 GtkWidget *menu; |
| |
99 |
| |
100 gtk_widget_init_template(GTK_WIDGET(prefs)); |
| |
101 |
| |
102 prefs->idle_reporting.type = PURPLE_PREF_STRING; |
| |
103 prefs->idle_reporting.key = "/purple/away/idle_reporting"; |
| |
104 pidgin_prefs_bind_dropdown(&prefs->idle_reporting); |
| |
105 |
| |
106 pidgin_prefs_bind_spin_button("/purple/away/mins_before_away", |
| |
107 prefs->mins_before_away); |
| |
108 |
| |
109 pidgin_prefs_bind_checkbox("/purple/away/away_when_idle", |
| |
110 prefs->away_when_idle); |
| |
111 |
| |
112 /* TODO: Show something useful if we don't have any saved statuses. */ |
| |
113 menu = pidgin_status_menu(purple_savedstatus_get_idleaway(), |
| |
114 G_CALLBACK(set_idle_away)); |
| |
115 gtk_widget_show_all(menu); |
| |
116 gtk_box_pack_start(GTK_BOX(prefs->idle_hbox), menu, FALSE, FALSE, 0); |
| |
117 |
| |
118 g_object_bind_property(prefs->away_when_idle, "active", |
| |
119 menu, "sensitive", |
| |
120 G_BINDING_SYNC_CREATE); |
| |
121 |
| |
122 /* Away stuff */ |
| |
123 prefs->auto_reply.type = PURPLE_PREF_STRING; |
| |
124 prefs->auto_reply.key = "/purple/away/auto_reply"; |
| |
125 pidgin_prefs_bind_dropdown(&prefs->auto_reply); |
| |
126 |
| |
127 /* Signon status stuff */ |
| |
128 pidgin_prefs_bind_checkbox("/purple/savedstatus/startup_current_status", |
| |
129 prefs->startup_current_status); |
| |
130 |
| |
131 /* TODO: Show something useful if we don't have any saved statuses. */ |
| |
132 menu = pidgin_status_menu(purple_savedstatus_get_startup(), |
| |
133 G_CALLBACK(set_startupstatus)); |
| |
134 gtk_widget_show_all(menu); |
| |
135 gtk_box_pack_start(GTK_BOX(prefs->startup_hbox), menu, FALSE, FALSE, 0); |
| |
136 gtk_label_set_mnemonic_widget(GTK_LABEL(prefs->startup_label), menu); |
| |
137 pidgin_set_accessible_label(menu, GTK_LABEL(prefs->startup_label)); |
| |
138 g_object_bind_property(prefs->startup_current_status, "active", |
| |
139 prefs->startup_hbox, "sensitive", |
| |
140 G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN); |
| |
141 } |
| |
142 |
| |
143 /****************************************************************************** |
| |
144 * API |
| |
145 *****************************************************************************/ |
| |
146 GtkWidget * |
| |
147 pidgin_away_prefs_new(void) { |
| |
148 return GTK_WIDGET(g_object_new(PIDGIN_TYPE_AWAY_PREFS, NULL)); |
| |
149 } |