internationalise plugin appdata files
[claws.git] / src / plugins / gdata / gdata_plugin.c
1 /* GData plugin for Claws-Mail
2  * Copyright (C) 2011 Holger Berndt
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18
19 #ifdef HAVE_CONFIG_H
20 #  include "config.h"
21 #  include "claws-features.h"
22 #endif
23
24 #include <glib.h>
25 #include <glib/gi18n.h>
26
27 #ifdef G_OS_UNIX
28 # include <libintl.h>
29 #endif
30
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
41 #include "cm_gdata_contacts.h"
42 #include "cm_gdata_prefs.h"
43
44 static guint hook_address_completion;
45 static guint hook_offline_switch;
46 static guint timer_query_contacts = 0;
47
48 static gboolean my_address_completion_build_list_hook(gpointer source, gpointer data)
49 {
50   cm_gdata_add_contacts(source);
51   return FALSE;
52 }
53
54 static gboolean my_offline_switch_hook(gpointer source, gpointer data)
55 {
56   cm_gdata_update_contacts_cache();
57   return FALSE;
58 }
59
60 static void cm_gdata_save_config(void)
61 {
62   PrefFile *pfile;
63   gchar *rcpath;
64
65   debug_print("Saving GData plugin configuration...\n");
66
67   rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
68   pfile = prefs_write_open(rcpath);
69   g_free(rcpath);
70   if (!pfile || (prefs_set_block_label(pfile, "GDataPlugin") < 0))
71     return;
72
73   if (prefs_write_param(cm_gdata_param, pfile->fp) < 0) {
74     debug_print("failed!\n");
75     g_warning(_("\nGData Plugin: Failed to write plugin configuration to file\n"));
76     prefs_file_close_revert(pfile);
77     return;
78   }
79   if (fprintf(pfile->fp, "\n") < 0) {
80     FILE_OP_ERROR(rcpath, "fprintf");
81     prefs_file_close_revert(pfile);
82   }
83   else
84     prefs_file_close(pfile);
85   debug_print("done.\n");
86 }
87
88 void cm_gdata_update_contacts_update_timer(void)
89 {
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);
93 }
94
95 gint plugin_init(gchar **error)
96 {
97   gchar *rcpath;
98
99   /* Version check */
100   if(!check_plugin_version(MAKE_NUMERIC_VERSION(3,7,1,55),
101                            VERSION_NUMERIC, _("GData"), error))
102     return -1;
103
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"));
108     return -1;
109   }
110
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"));
115     return -1;
116   }
117
118   /* Configuration */
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);
122   g_free(rcpath);
123
124   cm_gdata_prefs_init();
125
126   /* contacts cache */
127   cm_gdata_load_contacts_cache_from_file();
128   cm_gdata_update_contacts_update_timer();
129   cm_gdata_update_contacts_cache();
130
131   debug_print("GData plugin loaded\n");
132
133   return 0;
134 }
135
136 gboolean plugin_done(void)
137 {
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);
142   }
143   cm_gdata_prefs_done();
144   cm_gdata_contacts_done();
145
146   cm_gdata_save_config();
147
148   debug_print("GData plugin unloaded\n");
149
150   /* returning FALSE because dependant libraries may not be unload-safe. */
151   return FALSE;
152 }
153
154 const gchar *plugin_name(void)
155 {
156   return _("GData");
157 }
158
159 const gchar *plugin_desc(void)
160 {
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.");
167 }
168
169 const gchar *plugin_type(void)
170 {
171   return "GTK2";
172 }
173
174 const gchar *plugin_licence(void)
175 {
176   return "GPL3+";
177 }
178
179 const gchar *plugin_version(void)
180 {
181   return VERSION;
182 }
183
184 struct PluginFeature *plugin_provides(void)
185 {
186   static struct PluginFeature features[] =
187     { {PLUGIN_UTILITY, N_("GData integration")},
188       {PLUGIN_NOTHING, NULL}};
189   return features;
190 }