aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/calendar-file
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2010-02-04 19:55:42 +0800
committerMilan Crha <mcrha@redhat.com>2010-02-04 19:55:42 +0800
commit9a8fa88b6a3fe12409ff0358bed45187c9c743a5 (patch)
tree2686e65a6fa77973efac264c3ce14c388906f650 /plugins/calendar-file
parentcaee31bac657c69b3dd8ec2d9ebfebd4510a6608 (diff)
downloadgsoc2013-evolution-9a8fa88b6a3fe12409ff0358bed45187c9c743a5.tar
gsoc2013-evolution-9a8fa88b6a3fe12409ff0358bed45187c9c743a5.tar.gz
gsoc2013-evolution-9a8fa88b6a3fe12409ff0358bed45187c9c743a5.tar.bz2
gsoc2013-evolution-9a8fa88b6a3fe12409ff0358bed45187c9c743a5.tar.lz
gsoc2013-evolution-9a8fa88b6a3fe12409ff0358bed45187c9c743a5.tar.xz
gsoc2013-evolution-9a8fa88b6a3fe12409ff0358bed45187c9c743a5.tar.zst
gsoc2013-evolution-9a8fa88b6a3fe12409ff0358bed45187c9c743a5.zip
Move some ESource-plugin common code to e-plugin-util.h/.c
Diffstat (limited to 'plugins/calendar-file')
-rw-r--r--plugins/calendar-file/Makefile.am1
-rw-r--r--plugins/calendar-file/calendar-file.c134
2 files changed, 12 insertions, 123 deletions
diff --git a/plugins/calendar-file/Makefile.am b/plugins/calendar-file/Makefile.am
index ba8af51ad4..a4577e5019 100644
--- a/plugins/calendar-file/Makefile.am
+++ b/plugins/calendar-file/Makefile.am
@@ -16,6 +16,7 @@ liborg_gnome_calendar_file_la_SOURCES = calendar-file.c
liborg_gnome_calendar_file_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED)
liborg_gnome_calendar_file_la_LIBADD = \
+ $(top_builddir)/e-util/libeutil.la \
$(EVOLUTION_CALENDAR_LIBS) \
$(GNOME_PLATFORM_LIBS)
diff --git a/plugins/calendar-file/calendar-file.c b/plugins/calendar-file/calendar-file.c
index b5fe2c23ff..e82feaa11a 100644
--- a/plugins/calendar-file/calendar-file.c
+++ b/plugins/calendar-file/calendar-file.c
@@ -21,9 +21,9 @@
#include <gtk/gtk.h>
#include <e-util/e-config.h>
+#include <e-util/e-plugin-util.h>
#include <calendar/gui/e-cal-config.h>
#include <libedataserver/e-source.h>
-#include <libedataserver/e-url.h>
#include <glib/gi18n.h>
#include <string.h>
@@ -41,85 +41,6 @@ location_changed (GtkFileChooserButton *widget, ESource *source)
}
static void
-set_refresh_time (ESource *source, GtkWidget *spin, GtkWidget *combobox)
-{
- gint time;
- gint item_num = 0;
- const gchar *refresh_str = e_source_get_property (source, "refresh");
- time = refresh_str ? atoi (refresh_str) : 30;
-
- if (time && !(time % 10080)) {
- /* weeks */
- item_num = 3;
- time /= 10080;
- } else if (time && !(time % 1440)) {
- /* days */
- item_num = 2;
- time /= 1440;
- } else if (time && !(time % 60)) {
- /* hours */
- item_num = 1;
- time /= 60;
- }
- gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), item_num);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), time);
-}
-
-static gchar *
-get_refresh_minutes (GtkWidget *spin, GtkWidget *combobox)
-{
- gint setting = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin));
- switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combobox))) {
- case 0:
- /* minutes */
- break;
- case 1:
- /* hours */
- setting *= 60;
- break;
- case 2:
- /* days */
- setting *= 1440;
- break;
- case 3:
- /* weeks - is this *really* necessary? */
- setting *= 10080;
- break;
- default:
- g_warning ("Time unit out of range");
- break;
- }
-
- return g_strdup_printf ("%d", setting);
-}
-
-static void
-spin_changed (GtkSpinButton *spin, ESource *source)
-{
- gchar *refresh_str;
- GtkWidget *combobox;
-
- combobox = g_object_get_data (G_OBJECT (spin), "combobox");
-
- refresh_str = get_refresh_minutes ((GtkWidget *) spin, combobox);
- e_source_set_property (source, "refresh", refresh_str);
- g_free (refresh_str);
-}
-
-static void
-combobox_changed (GtkComboBox *combobox, ESource *source)
-{
- gchar *refresh_str;
- GtkWidget *spin;
-
- spin = g_object_get_data (G_OBJECT (combobox), "spin");
-
- refresh_str = get_refresh_minutes (spin, (GtkWidget *) combobox);
- e_source_set_property (source, "refresh", refresh_str);
- g_free (refresh_str);
-}
-
-static void
maincheck_toggled (GtkToggleButton *check, ESource *source)
{
GtkWidget *w;
@@ -147,34 +68,25 @@ maincheck_toggled (GtkToggleButton *check, ESource *source)
static void
refresh_type_changed (GtkComboBox *refresh_type, ESource *source)
{
- GtkWidget *spin, *combobox;
+ GtkWidget *refresh_hbox;
gint active = gtk_combo_box_get_active (refresh_type);
gchar buff[2] = {0};
- spin = g_object_get_data (G_OBJECT (refresh_type), "spin");
- combobox = g_object_get_data (G_OBJECT (refresh_type), "combobox");
+ refresh_hbox = g_object_get_data (G_OBJECT (refresh_type), "refresh-hbox");
if (active < 0 || active > 2)
active = 0;
if (active == 2) {
- gtk_widget_show (spin);
- gtk_widget_show (combobox);
+ gtk_widget_show (refresh_hbox);
} else {
- gtk_widget_hide (spin);
- gtk_widget_hide (combobox);
+ gtk_widget_hide (refresh_hbox);
}
buff [0] = '0' + active;
e_source_set_property (source, "refresh-type", buff);
}
-static void
-force_readonly_toggled (GtkToggleButton *check, ESource *source)
-{
- e_source_set_property (source, "custom-file-readonly", gtk_toggle_button_get_active (check) ? "1" : NULL);
-}
-
GtkWidget *e_calendar_file_customs (EPlugin *epl, EConfigHookItemFactoryData *data);
GtkWidget *
@@ -182,23 +94,15 @@ e_calendar_file_customs (EPlugin *epl, EConfigHookItemFactoryData *data)
{
ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target;
ESource *source = t->source;
- gchar *uri_text;
const gchar *relative_uri, *value;
- GtkWidget *w1, *w2, *w3, *box1, *box2, *mainbox, *maincheck;
-
- uri_text = e_source_get_uri (source);
- if (strncmp (uri_text, "file", 4)) {
- g_free (uri_text);
+ GtkWidget *w1, *w2, *box1, *box2, *mainbox, *maincheck;
+ if (!e_plugin_util_is_source_proto (source, "file"))
return NULL;
- }
relative_uri = e_source_peek_relative_uri (source);
-
- if (relative_uri && g_str_equal (relative_uri, "system")) {
- g_free (uri_text);
+ if (relative_uri && g_str_equal (relative_uri, "system"))
return NULL;
- }
e_source_set_relative_uri (source, e_source_peek_uid (source));
@@ -286,29 +190,14 @@ e_calendar_file_customs (EPlugin *epl, EConfigHookItemFactoryData *data)
gtk_combo_box_set_active ((GtkComboBox *)w2, (value && *value && !value[1] && value [0] >= '0' && value [0] <= '2') ? value [0] - '0' : 0);
w1 = w2;
- w2 = gtk_spin_button_new_with_range (1, 100, 1);
+ w2 = e_plugin_util_add_refresh (NULL, NULL, source, "refresh");
gtk_box_pack_start (GTK_BOX (box2), w2, FALSE, TRUE, 0);
- w3 = gtk_combo_box_new_text ();
- gtk_combo_box_append_text (GTK_COMBO_BOX (w3), _("minutes"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (w3), _("hours"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (w3), _("days"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (w3), _("weeks"));
- set_refresh_time (source, w2, w3);
- gtk_box_pack_start (GTK_BOX (box2), w3, FALSE, TRUE, 0);
-
- g_object_set_data (G_OBJECT (w1), "spin", w2);
- g_object_set_data (G_OBJECT (w1), "combobox", w3);
- g_object_set_data (G_OBJECT (w2), "combobox", w3);
+ g_object_set_data (G_OBJECT (w1), "refresh-hbox", w2);
g_signal_connect (G_OBJECT (w1), "changed", G_CALLBACK (refresh_type_changed), source);
- g_signal_connect (G_OBJECT (w2), "value-changed", G_CALLBACK (spin_changed), source);
- g_signal_connect (G_OBJECT (w3), "changed", G_CALLBACK (combobox_changed), source);
- w2 = gtk_check_button_new_with_mnemonic (_("Force read _only"));
- value = e_source_get_property (source, "custom-file-readonly");
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), value && g_str_equal (value, "1"));
- g_signal_connect (G_OBJECT (w2), "toggled", G_CALLBACK (force_readonly_toggled), source);
+ w2 = e_plugin_util_add_check (NULL, _("Force read _only"), source, "custom-file-readonly", "1", NULL);
gtk_box_pack_start ((GtkBox *)box1, w2, TRUE, TRUE, 2);
gtk_widget_show_all (mainbox);
@@ -316,7 +205,6 @@ e_calendar_file_customs (EPlugin *epl, EConfigHookItemFactoryData *data)
/* w1 is a refresh-type combobox, and it hides widgets,
thus should be called after show_all call */
refresh_type_changed (GTK_COMBO_BOX (w1), source);
- g_free (uri_text);
return mainbox;
}