src/mn-gmail-mailbox-properties.gob (6045B) - raw
1 /*
2 * Mail Notification
3 * Copyright (C) 2003-2008 Jean-Yves Lefort <jylefort@brutele.be>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 %headertop{
21 #include <gtk/gtk.h>
22 #include "mn-authenticated-mailbox-properties.h"
23 %}
24
25 %{
26 #include <glib/gi18n.h>
27 #include "mn-mailbox-properties.h"
28 #include "mn-mailbox-properties-private.h"
29 #include "mn-authenticated-mailbox-properties-private.h"
30 #include "mn-util.h"
31 #include "mn-properties-dialog.h"
32 #include "mn-authenticated-mailbox.h"
33 #include "mn-gmail-mailbox.h"
34 #include "mn-stock.h"
35 %}
36
37 class MN:Gmail:Mailbox:Properties from MN:Authenticated:Mailbox:Properties
38 {
39 private GtkWidget *label_check;
40 private GtkWidget *label_entry;
41
42 /*
43 * We do not provide a control for the atom feed location, because
44 * modifying it is probably unnecessary.
45 */
46 private char *location destroywith g_free;
47
48 property BOOLEAN complete (override)
49 get
50 {
51 gboolean complete;
52
53 complete = mn_authenticated_mailbox_properties_is_complete(MN_AUTHENTICATED_MAILBOX_PROPERTIES(self));
54 if (complete)
55 {
56 gboolean label_enabled;
57 const char *label;
58
59 label_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->label_check));
60 label = gtk_entry_get_text(GTK_ENTRY(selfp->label_entry));
61
62 if (label_enabled && ! *label)
63 complete = FALSE;
64 }
65
66 g_value_set_boolean(VAL, complete);
67 };
68
69 property STRING default_name (override)
70 get
71 {
72 const char *username;
73 gboolean label_enabled;
74 const char *label;
75
76 username = gtk_entry_get_text(GTK_ENTRY(MN_AUTHENTICATED_MAILBOX_PROPERTIES(self)->username_entry));
77 g_assert(*username != 0);
78
79 label_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->label_check));
80 label = gtk_entry_get_text(GTK_ENTRY(selfp->label_entry));
81
82 g_value_take_string(VAL, mn_gmail_mailbox_build_name(username, label_enabled ? label : NULL));
83 };
84
85 class_init (class)
86 {
87 MNMailboxPropertiesClass *p_class = MN_MAILBOX_PROPERTIES_CLASS(class);
88
89 p_class->type = "gmail";
90 p_class->stock_id = MN_STOCK_GMAIL;
91 p_class->combo_label = "Gmail";
92 }
93
94 init (self)
95 {
96 MNMailboxProperties *properties = MN_MAILBOX_PROPERTIES(self);
97 MNAuthenticatedMailboxProperties *auth = MN_AUTHENTICATED_MAILBOX_PROPERTIES(self);
98 GtkWidget *label_vbox;
99 GtkWidget *hbox;
100
101 gtk_box_pack_start(GTK_BOX(auth->account_vbox), auth->username_vbox, FALSE, FALSE, 0);
102 gtk_box_pack_start(GTK_BOX(auth->account_vbox), auth->password_vbox, FALSE, FALSE, 0);
103
104 /* translators: header capitalization */
105 label_vbox = mn_mailbox_properties_add_general_section(properties, _("Gmail Label"));
106
107 selfp->label_check = gtk_check_button_new_with_mnemonic(_("_Restrict to this label:"));
108 gtk_size_group_add_widget(properties->label_size_group, selfp->label_check);
109
110 selfp->label_entry = gtk_entry_new();
111 gtk_widget_set_sensitive(selfp->label_entry, FALSE);
112
113 hbox = gtk_hbox_new(FALSE, 12);
114 gtk_box_pack_start(GTK_BOX(hbox), selfp->label_check, FALSE, FALSE, 0);
115 gtk_box_pack_start(GTK_BOX(hbox), selfp->label_entry, TRUE, TRUE, 0);
116 gtk_box_pack_start(GTK_BOX(label_vbox), hbox, FALSE, FALSE, 0);
117 gtk_widget_show_all(label_vbox);
118
119 properties->entries = mn_g_slist_append_elements(properties->entries,
120 auth->username_entry,
121 auth->password_entry,
122 selfp->label_entry,
123 NULL);
124
125 g_signal_connect(selfp->label_check, "toggled", G_CALLBACK(self_check_toggled_h), self);
126
127 g_object_connect(auth->username_entry,
128 "swapped-signal::changed", mn_mailbox_properties_notify_complete, self,
129 "swapped-signal::changed", mn_mailbox_properties_notify_default_name, self,
130 NULL);
131
132 g_object_connect(selfp->label_entry,
133 "swapped-signal::changed", mn_mailbox_properties_notify_complete, self,
134 "swapped-signal::changed", mn_mailbox_properties_notify_default_name, self,
135 NULL);
136 }
137
138 private void
139 check_toggled_h (GtkToggleButton *togglebutton, gpointer user_data)
140 {
141 Self *self = user_data;
142
143 gtk_widget_set_sensitive(selfp->label_entry, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->label_check)));
144
145 g_object_notify(G_OBJECT(self), "complete");
146 g_object_notify(G_OBJECT(self), "default-name");
147 }
148
149 override (MN:Mailbox:Properties) void
150 set_mailbox (MNMailboxProperties *properties, MN:Mailbox *mailbox)
151 {
152 Self *self = SELF(properties);
153 MNGmailMailbox *gmail_mailbox = MN_GMAIL_MAILBOX(mailbox);
154
155 PARENT_HANDLER(properties, mailbox);
156
157 selfp->location = g_strdup(gmail_mailbox->location);
158
159 if (gmail_mailbox->label)
160 {
161 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(selfp->label_check), TRUE);
162 gtk_entry_set_text(GTK_ENTRY(selfp->label_entry), gmail_mailbox->label);
163 }
164 }
165
166 override (MN:Mailbox:Properties) MNMailbox *
167 get_mailbox (MNMailboxProperties *properties)
168 {
169 Self *self = SELF(properties);
170 MNMailbox *mailbox;
171
172 mailbox = PARENT_HANDLER(properties);
173
174 if (selfp->location)
175 g_object_set(mailbox, MN_GMAIL_MAILBOX_PROP_LOCATION(selfp->location), NULL);
176
177 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->label_check)))
178 g_object_set(mailbox, MN_GMAIL_MAILBOX_PROP_LABEL((char *) gtk_entry_get_text(GTK_ENTRY(selfp->label_entry))), NULL);
179
180 return mailbox;
181 }
182 }