Improve some sieve-related translations
[claws.git] / src / plugins / gdata / gdata_plugin.c
blob071cb3168ab60445d2d6cbe2484a9b7ea54e6e20
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/>.
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 # include "claws-features.h"
22 #endif
24 #include <glib.h>
25 #include <glib/gi18n.h>
27 #ifdef G_OS_UNIX
28 # include <libintl.h>
29 #endif
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"
37 #include "main.h"
38 #include "mainwindow.h"
39 #include "addr_compl.h"
40 #include "passwordstore.h"
42 #include "cm_gdata_contacts.h"
43 #include "cm_gdata_prefs.h"
45 static gulong hook_address_completion= 0;
46 static gulong hook_offline_switch = 0;
47 static gulong timer_query_contacts = 0;
49 static gboolean my_address_completion_build_list_hook(gpointer source, gpointer data)
51 cm_gdata_add_contacts(source);
52 return FALSE;
55 static gboolean my_offline_switch_hook(gpointer source, gpointer data)
57 cm_gdata_update_contacts_cache();
58 return FALSE;
61 static void cm_gdata_save_config(void)
63 PrefFile *pfile;
64 gchar *rcpath;
66 debug_print("Saving GData plugin configuration...\n");
68 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
69 pfile = prefs_write_open(rcpath);
70 g_free(rcpath);
71 if (!pfile || (prefs_set_block_label(pfile, "GDataPlugin") < 0))
72 return;
74 if (prefs_write_param(cm_gdata_param, pfile->fp) < 0) {
75 debug_print("failed!\n");
76 g_warning("GData plugin: failed to write plugin configuration to file");
77 prefs_file_close_revert(pfile);
78 return;
80 if (fprintf(pfile->fp, "\n") < 0) {
81 FILE_OP_ERROR(rcpath, "fprintf");
82 prefs_file_close_revert(pfile);
84 else
85 prefs_file_close(pfile);
86 debug_print("done.\n");
89 void cm_gdata_update_contacts_update_timer(void)
91 if(timer_query_contacts != 0)
92 g_source_remove(timer_query_contacts);
93 timer_query_contacts = g_timeout_add_seconds(cm_gdata_config.max_cache_age, (GSourceFunc)cm_gdata_update_contacts_cache, NULL);
96 gint plugin_init(gchar **error)
98 gchar *rcpath;
100 /* Version check */
101 if(!check_plugin_version(MAKE_NUMERIC_VERSION(3,13,2,39),
102 VERSION_NUMERIC, _("GData"), error))
103 return -1;
105 hook_address_completion = hooks_register_hook(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST,
106 my_address_completion_build_list_hook, NULL);
107 if(hook_address_completion == 0) {
108 *error = g_strdup(_("Failed to register address completion hook in the GData plugin"));
109 return -1;
112 hook_offline_switch = hooks_register_hook(OFFLINE_SWITCH_HOOKLIST, my_offline_switch_hook, NULL);
113 if(hook_offline_switch == 0) {
114 hooks_unregister_hook(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST, hook_address_completion);
115 *error = g_strdup(_("Failed to register offline switch hook in the GData plugin"));
116 return -1;
119 /* Configuration */
120 prefs_set_default(cm_gdata_param);
121 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
122 prefs_read_config(cm_gdata_param, "GDataPlugin", rcpath, NULL);
123 g_free(rcpath);
125 /* If the refresh token is still stored in config, save it to
126 * password store. */
127 if(cm_gdata_config.oauth2_refresh_token != NULL) {
128 passwd_store_set(PWS_PLUGIN, "GData", GDATA_TOKEN_PWD_STRING,
129 cm_gdata_config.oauth2_refresh_token, TRUE);
130 passwd_store_write_config();
133 cm_gdata_prefs_init();
135 debug_print("GData plugin loaded\n");
137 /* contacts cache */
138 cm_gdata_load_contacts_cache_from_file();
139 cm_gdata_update_contacts_update_timer();
140 cm_gdata_update_contacts_cache();
142 return 0;
145 gboolean plugin_done(void)
147 if(!claws_is_exiting()) {
148 hooks_unregister_hook(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST, hook_address_completion);
149 hooks_unregister_hook(OFFLINE_SWITCH_HOOKLIST, hook_offline_switch);
150 g_source_remove(timer_query_contacts);
152 cm_gdata_prefs_done();
153 cm_gdata_contacts_done();
155 cm_gdata_save_config();
157 debug_print("GData plugin unloaded\n");
159 /* returning FALSE because dependant libraries may not be unload-safe. */
160 return FALSE;
163 const gchar *plugin_name(void)
165 return _("GData");
168 const gchar *plugin_desc(void)
170 return _("This plugin provides access to the GData protocol "
171 "for Claws Mail.\n\n"
172 "The GData protocol is an interface to Google services.\n"
173 "Currently, the only implemented functionality is to include "
174 "Google Contacts into the Tab-address completion.\n"
175 "\nFeedback to <berndth@gmx.de> is welcome.");
178 const gchar *plugin_type(void)
180 return "GTK3";
183 const gchar *plugin_licence(void)
185 return "GPL3+";
188 const gchar *plugin_version(void)
190 return VERSION;
193 struct PluginFeature *plugin_provides(void)
195 static struct PluginFeature features[] =
196 { {PLUGIN_UTILITY, N_("GData integration")},
197 {PLUGIN_NOTHING, NULL}};
198 return features;