Remove inclusion of sys/socket.h from nntp-thread.c
[claws.git] / src / plugins / gdata / cm_gdata_prefs.c
blobe78092ecd7f1dff436f753bed918869bf66db23a
1 /*
2 * GData plugin for Claws-Mail
3 * Claws Mail -- A GTK based, lightweight, and fast e-mail client
4 * Copyright (C) 2011-2018 Holger Berndt and the Claws Mail team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 # include "claws-features.h"
24 #endif
26 #include <glib.h>
27 #include <glib/gi18n.h>
29 #include "password.h"
30 #include "cm_gdata_prefs.h"
31 #include "gdata_plugin.h"
32 #include "cm_gdata_contacts.h"
34 #include "prefs_gtk.h"
35 #include "main.h"
37 #include <gtk/gtk.h>
40 typedef struct
42 PrefsPage page;
43 GtkWidget *entry_username;
44 GtkWidget *spin_max_num_results;
45 GtkWidget *spin_max_cache_age;
46 } CmGDataPage;
48 CmGDataPrefs cm_gdata_config;
49 CmGDataPage gdata_page;
51 PrefParam cm_gdata_param[] =
53 {"username", NULL, &cm_gdata_config.username, P_STRING,
54 &gdata_page.entry_username, prefs_set_data_from_entry, prefs_set_entry},
56 { "max_num_results", "1000", &cm_gdata_config.max_num_results, P_INT,
57 &gdata_page.spin_max_num_results, prefs_set_data_from_spinbtn, prefs_set_spinbtn},
59 { "max_cache_age", "300", &cm_gdata_config.max_cache_age, P_INT,
60 &gdata_page.spin_max_cache_age, prefs_set_data_from_spinbtn, prefs_set_spinbtn},
62 {"oauth2_refresh_token", NULL, &cm_gdata_config.oauth2_refresh_token, P_PASSWORD,
63 NULL, NULL, NULL},
65 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL }
68 static void gdata_create_prefs_page(PrefsPage *page, GtkWindow *window, gpointer data)
70 GtkWidget *vbox;
71 GtkWidget *frame;
72 GtkWidget *spinner;
73 GtkWidget *table;
74 GtkWidget *label;
75 GtkWidget *entry;
77 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
79 /* auth frame */
80 frame = gtk_frame_new(_("Authentication"));
81 gtk_container_set_border_width(GTK_CONTAINER(frame), 5);
82 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
84 /* username */
85 table = gtk_grid_new();
86 label = gtk_label_new(_("Username:"));
87 gtk_label_set_xalign(GTK_LABEL(label), 0.0);
88 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
89 entry = gtk_entry_new();
90 gtk_widget_set_size_request(entry, 250, -1);
91 gtk_grid_attach(GTK_GRID(table), entry, 1, 0, 1, 1);
92 gtk_widget_set_hexpand(entry, TRUE);
93 gtk_widget_set_halign(entry, GTK_ALIGN_FILL);
94 gdata_page.entry_username = entry;
95 gtk_container_add(GTK_CONTAINER(frame), table);
97 table = gtk_grid_new();
98 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
99 label = gtk_label_new(_("Polling interval (seconds):"));
100 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
101 gtk_label_set_xalign(GTK_LABEL(label), 0.0);
102 spinner = gtk_spin_button_new_with_range(10, 10000, 10);
103 gtk_grid_attach(GTK_GRID(table), spinner, 1, 0, 1, 1);
104 gdata_page.spin_max_cache_age = spinner;
106 label = gtk_label_new(_("Maximum number of results:"));
107 gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1);
108 gtk_label_set_xalign(GTK_LABEL(label), 0.0);
109 spinner = gtk_spin_button_new_with_range(0, G_MAXINT, 50);
110 gtk_grid_attach(GTK_GRID(table), spinner, 1, 1, 1, 1);
111 gdata_page.spin_max_num_results = spinner;
113 gtk_widget_show_all(vbox);
114 page->widget = vbox;
116 prefs_set_dialog(cm_gdata_param);
119 static void gdata_destroy_prefs_page(PrefsPage *page)
123 static void gdata_save_prefs(PrefsPage *page)
125 int old_max_cache_age = cm_gdata_config.max_cache_age;
127 if (!page->page_open)
128 return;
130 prefs_set_data_from_dialog(cm_gdata_param);
132 cm_gdata_update_contacts_cache();
133 if(old_max_cache_age != cm_gdata_config.max_cache_age)
134 cm_gdata_update_contacts_update_timer();
137 void cm_gdata_prefs_init(void)
139 static gchar *path[3];
141 path[0] = _("Plugins");
142 path[1] = _("GData");
143 path[2] = NULL;
145 gdata_page.page.path = path;
146 gdata_page.page.create_widget = gdata_create_prefs_page;
147 gdata_page.page.destroy_widget = gdata_destroy_prefs_page;
148 gdata_page.page.save_page = gdata_save_prefs;
149 gdata_page.page.weight = 40.0;
150 prefs_gtk_register_page((PrefsPage*) &gdata_page);
153 void cm_gdata_prefs_done(void)
155 if(!claws_is_exiting()) {
156 prefs_gtk_unregister_page((PrefsPage*) &gdata_page);