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>
31 #include "common/plugin.h"
32 #include "common/version.h"
33 #include "common/utils.h"
34 #include "common/hooks.h"
35 #include "common/defs.h"
36 #include "common/prefs.h"
38 #include "mainwindow.h"
39 #include "addr_compl.h"
41 #include "cm_gdata_contacts.h"
42 #include "cm_gdata_prefs.h"
44 static guint hook_address_completion;
45 static guint hook_offline_switch;
46 static guint timer_query_contacts = 0;
48 static gboolean my_address_completion_build_list_hook(gpointer source, gpointer data)
50 cm_gdata_add_contacts(source);
54 static gboolean my_offline_switch_hook(gpointer source, gpointer data)
56 cm_gdata_update_contacts_cache();
60 static void cm_gdata_save_config(void)
65 debug_print("Saving GData plugin configuration...\n");
67 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
68 pfile = prefs_write_open(rcpath);
70 if (!pfile || (prefs_set_block_label(pfile, "GDataPlugin") < 0))
73 if (prefs_write_param(cm_gdata_param, pfile->fp) < 0) {
74 debug_print("failed!\n");
75 g_warning("GData Plugin: Failed to write plugin configuration to file");
76 prefs_file_close_revert(pfile);
79 if (fprintf(pfile->fp, "\n") < 0) {
80 FILE_OP_ERROR(rcpath, "fprintf");
81 prefs_file_close_revert(pfile);
84 prefs_file_close(pfile);
85 debug_print("done.\n");
88 void cm_gdata_update_contacts_update_timer(void)
90 if(timer_query_contacts != 0)
91 g_source_remove(timer_query_contacts);
92 timer_query_contacts = g_timeout_add_seconds(cm_gdata_config.max_cache_age, (GSourceFunc)cm_gdata_update_contacts_cache, NULL);
95 gint plugin_init(gchar **error)
100 if(!check_plugin_version(MAKE_NUMERIC_VERSION(3,13,2,39),
101 VERSION_NUMERIC, _("GData"), error))
104 hook_address_completion = hooks_register_hook(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST,
105 my_address_completion_build_list_hook, NULL);
106 if(hook_address_completion == (guint) -1) {
107 *error = g_strdup(_("Failed to register address completion hook in the GData plugin"));
111 hook_offline_switch = hooks_register_hook(OFFLINE_SWITCH_HOOKLIST, my_offline_switch_hook, NULL);
112 if(hook_offline_switch == (guint) -1) {
113 hooks_unregister_hook(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST, hook_address_completion);
114 *error = g_strdup(_("Failed to register offline switch hook in the GData plugin"));
119 prefs_set_default(cm_gdata_param);
120 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
121 prefs_read_config(cm_gdata_param, "GDataPlugin", rcpath, NULL);
124 cm_gdata_prefs_init();
126 debug_print("GData plugin loaded\n");
129 cm_gdata_load_contacts_cache_from_file();
130 cm_gdata_update_contacts_update_timer();
131 cm_gdata_update_contacts_cache();
136 gboolean plugin_done(void)
138 if(!claws_is_exiting()) {
139 hooks_unregister_hook(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST, hook_address_completion);
140 hooks_unregister_hook(OFFLINE_SWITCH_HOOKLIST, hook_offline_switch);
141 g_source_remove(timer_query_contacts);
143 cm_gdata_prefs_done();
144 cm_gdata_contacts_done();
146 cm_gdata_save_config();
148 debug_print("GData plugin unloaded\n");
150 /* returning FALSE because dependant libraries may not be unload-safe. */
154 const gchar *plugin_name(void)
159 const gchar *plugin_desc(void)
161 return _("This plugin provides access to the GData protocol "
162 "for Claws Mail.\n\n"
163 "The GData protocol is an interface to Google services.\n"
164 "Currently, the only implemented functionality is to include "
165 "Google Contacts into the Tab-address completion.\n"
166 "\nFeedback to <berndth@gmx.de> is welcome.");
169 const gchar *plugin_type(void)
174 const gchar *plugin_licence(void)
179 const gchar *plugin_version(void)
184 void plugin_master_password_change (const gchar *oldp, const gchar *newp)
186 cm_gdata_prefs_master_password_change(oldp, newp);
189 struct PluginFeature *plugin_provides(void)
191 static struct PluginFeature features[] =
192 { {PLUGIN_UTILITY, N_("GData integration")},
193 {PLUGIN_NOTHING, NULL}};