1 /* GData plugin for Claws-Mail
2 * Copyright (C) 2011 Holger Berndt
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # include "claws-features.h"
25 #include <glib/gi18n.h>
27 #include "cm_gdata_prefs.h"
28 #include "gdata_plugin.h"
29 #include "cm_gdata_contacts.h"
31 #include "prefs_gtk.h"
40 GtkWidget *entry_username;
41 GtkWidget *entry_password;
42 GtkWidget *spin_max_num_results;
43 GtkWidget *spin_max_cache_age;
46 CmGDataPrefs cm_gdata_config;
47 CmGDataPage gdata_page;
49 PrefParam cm_gdata_param[] =
51 {"username", NULL, &cm_gdata_config.username, P_STRING,
52 &gdata_page.entry_username, prefs_set_data_from_entry, prefs_set_entry},
54 {"password", NULL, &cm_gdata_config.password, P_PASSWORD,
55 &gdata_page.entry_password, prefs_set_data_from_entry, prefs_set_entry},
57 { "max_num_results", "1000", &cm_gdata_config.max_num_results, P_INT,
58 &gdata_page.spin_max_num_results, prefs_set_data_from_spinbtn, prefs_set_spinbtn},
60 { "max_cache_age", "300", &cm_gdata_config.max_cache_age, P_INT,
61 &gdata_page.spin_max_cache_age, prefs_set_data_from_spinbtn, prefs_set_spinbtn},
63 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL }
66 static void gdata_create_prefs_page(PrefsPage *page, GtkWindow *window, gpointer data)
75 vbox = gtk_vbox_new(FALSE, 0);
78 frame = gtk_frame_new(_("Authentication"));
79 gtk_container_set_border_width(GTK_CONTAINER(frame), 5);
80 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
83 table = gtk_table_new(2, 2, FALSE);
84 label = gtk_label_new(_("Username:"));
85 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
86 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 4, 4);
87 entry = gtk_entry_new();
88 gtk_widget_set_size_request(entry, 250, -1);
89 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 4, 4);
90 gdata_page.entry_username = entry;
91 label = gtk_label_new(_("Password:"));
92 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
93 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 4, 4);
94 entry = gtk_entry_new();
95 gtk_widget_set_size_request(entry, 250, -1);
96 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
97 gdata_page.entry_password = entry;
98 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 4, 4);
99 gtk_container_add(GTK_CONTAINER(frame), table);
101 table = gtk_table_new(2, 2, FALSE);
102 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
103 label = gtk_label_new(_("Polling interval (seconds):"));
104 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 4, 4);
105 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
106 spinner = gtk_spin_button_new_with_range(10, 10000, 10);
107 gtk_table_attach(GTK_TABLE(table), spinner, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 4, 4);
108 gdata_page.spin_max_cache_age = spinner;
110 label = gtk_label_new(_("Maximum number of results:"));
111 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 4, 4);
112 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
113 spinner = gtk_spin_button_new_with_range(0, G_MAXINT, 50);
114 gtk_table_attach(GTK_TABLE(table), spinner, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 4, 4);
115 gdata_page.spin_max_num_results = spinner;
117 gtk_widget_show_all(vbox);
120 prefs_set_dialog(cm_gdata_param);
123 static void gdata_destroy_prefs_page(PrefsPage *page)
127 static void gdata_save_prefs(PrefsPage *page)
129 int old_max_cache_age = cm_gdata_config.max_cache_age;
131 if (!page->page_open)
134 prefs_set_data_from_dialog(cm_gdata_param);
136 cm_gdata_update_contacts_cache();
137 if(old_max_cache_age != cm_gdata_config.max_cache_age)
138 cm_gdata_update_contacts_update_timer();
141 void cm_gdata_prefs_init(void)
143 static gchar *path[3];
145 path[0] = _("Plugins");
146 path[1] = _("GData");
149 gdata_page.page.path = path;
150 gdata_page.page.create_widget = gdata_create_prefs_page;
151 gdata_page.page.destroy_widget = gdata_destroy_prefs_page;
152 gdata_page.page.save_page = gdata_save_prefs;
153 prefs_gtk_register_page((PrefsPage*) &gdata_page);
156 void cm_gdata_prefs_done(void)
158 if(!claws_is_exiting()) {
159 prefs_gtk_unregister_page((PrefsPage*) &gdata_page);