Updated to release 1.10.0
[siplcs.git] / src / purple / purple-plugin.c
blob0ed6d39594524c4f11f43b1e54f232411d4ed97b
1 /**
2 * @file purple-plugin.c
4 * pidgin-sipe
6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include "sipe-common.h"
29 /* Flag needed for correct version of PURPLE_INIT_PLUGIN() */
30 #ifndef PURPLE_PLUGINS
31 #define PURPLE_PLUGINS
32 #endif
34 #include "accountopt.h"
35 #include "connection.h"
36 #include "prpl.h"
37 #include "plugin.h"
38 #include "request.h"
39 #include "version.h"
41 #include "sipe-core.h"
42 #include "sipe-nls.h"
44 #include "core-depurple.h"
46 /* PurplePluginInfo function calls & data structure */
47 static gboolean sipe_plugin_load(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
49 return TRUE;
52 static gboolean sipe_plugin_unload(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
54 return TRUE;
57 static void sipe_plugin_destroy(SIPE_UNUSED_PARAMETER PurplePlugin *plugin)
59 GList *entry;
61 sipe_core_destroy();
63 entry = prpl_info.protocol_options;
64 while (entry) {
65 purple_account_option_destroy(entry->data);
66 entry = g_list_delete_link(entry, entry);
68 prpl_info.protocol_options = NULL;
70 entry = prpl_info.user_splits;
71 while (entry) {
72 purple_account_user_split_destroy(entry->data);
73 entry = g_list_delete_link(entry, entry);
75 prpl_info.user_splits = NULL;
78 static void sipe_show_about_plugin(PurplePluginAction *action)
80 gchar *tmp = sipe_core_about();
81 purple_notify_formatted((PurpleConnection *) action->context,
82 NULL, " ", NULL, tmp, NULL, NULL);
83 g_free(tmp);
86 static void sipe_show_find_contact(PurplePluginAction *action)
88 PurpleConnection *gc = (PurpleConnection *) action->context;
89 PurpleRequestFields *fields;
90 PurpleRequestFieldGroup *group;
91 PurpleRequestField *field;
93 fields = purple_request_fields_new();
94 group = purple_request_field_group_new(NULL);
95 purple_request_fields_add_group(fields, group);
97 field = purple_request_field_string_new("givenName", _("First name"), NULL, FALSE);
98 purple_request_field_group_add_field(group, field);
99 field = purple_request_field_string_new("sn", _("Last name"), NULL, FALSE);
100 purple_request_field_group_add_field(group, field);
101 field = purple_request_field_string_new("company", _("Company"), NULL, FALSE);
102 purple_request_field_group_add_field(group, field);
103 field = purple_request_field_string_new("c", _("Country"), NULL, FALSE);
104 purple_request_field_group_add_field(group, field);
106 purple_request_fields(gc,
107 _("Search"),
108 _("Search for a contact"),
109 _("Enter the information for the person you wish to find. Empty fields will be ignored."),
110 fields,
111 _("_Search"), G_CALLBACK(sipe_search_contact_with_cb),
112 _("_Cancel"), NULL,
113 purple_connection_get_account(gc), NULL, NULL, gc);
116 static void sipe_republish_calendar(PurplePluginAction *action)
118 PurpleConnection *gc = (PurpleConnection *) action->context;
119 struct sipe_account_data *sip = gc->proto_data;
121 sipe_core_update_calendar(sip);
124 static void sipe_reset_status(PurplePluginAction *action)
126 PurpleConnection *gc = (PurpleConnection *) action->context;
127 struct sipe_account_data *sip = gc->proto_data;
129 sipe_core_reset_status(sip);
132 static GList *sipe_actions(SIPE_UNUSED_PARAMETER PurplePlugin *plugin,
133 gpointer context)
135 PurpleConnection *gc = (PurpleConnection *)context;
136 GList *menu = NULL;
137 PurplePluginAction *act;
138 const char* calendar = purple_account_get_string(purple_connection_get_account(gc),
139 "calendar", "EXCH");
141 act = purple_plugin_action_new(_("About SIPE plugin..."), sipe_show_about_plugin);
142 menu = g_list_prepend(menu, act);
144 act = purple_plugin_action_new(_("Contact search..."), sipe_show_find_contact);
145 menu = g_list_prepend(menu, act);
147 if (sipe_strequal(calendar, "EXCH")) {
148 act = purple_plugin_action_new(_("Republish Calendar"), sipe_republish_calendar);
149 menu = g_list_prepend(menu, act);
152 act = purple_plugin_action_new(_("Reset status"), sipe_reset_status);
153 menu = g_list_prepend(menu, act);
155 return g_list_reverse(menu);
158 static PurplePluginInfo info = {
159 PURPLE_PLUGIN_MAGIC,
160 PURPLE_MAJOR_VERSION,
161 PURPLE_MINOR_VERSION,
162 PURPLE_PLUGIN_PROTOCOL, /**< type */
163 NULL, /**< ui_requirement */
164 0, /**< flags */
165 NULL, /**< dependencies */
166 PURPLE_PRIORITY_DEFAULT, /**< priority */
167 "prpl-sipe", /**< id */
168 "Office Communicator", /**< name */
169 PACKAGE_VERSION, /**< version */
170 "Microsoft Office Communicator Protocol Plugin", /**< summary */
171 "A plugin for the extended SIP/SIMPLE protocol used by " /**< description */
172 "Microsoft Live/Office Communications Server (LCS2005/OCS2007+)", /**< description */
173 "Anibal Avelar <avelar@gmail.com>, " /**< author */
174 "Gabriel Burt <gburt@novell.com>, " /**< author */
175 "Stefan Becker <stefan.becker@nokia.com>, " /**< author */
176 "pier11 <pier11@operamail.com>", /**< author */
177 PACKAGE_URL, /**< homepage */
178 sipe_plugin_load, /**< load */
179 sipe_plugin_unload, /**< unload */
180 sipe_plugin_destroy, /**< destroy */
181 NULL, /**< ui_info */
182 &prpl_info, /**< extra_info */
183 NULL,
184 sipe_actions,
185 NULL,
186 NULL,
187 NULL,
188 NULL
191 static void init_plugin(PurplePlugin *plugin)
193 PurpleAccountUserSplit *split;
194 PurpleAccountOption *option;
196 /* This needs to be called first */
197 sipe_core_init();
199 purple_plugin_register(plugin);
201 split = purple_account_user_split_new(_("Login\n user or DOMAIN\\user or\n user@company.com"), NULL, ',');
202 purple_account_user_split_set_reverse(split, FALSE);
203 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
205 option = purple_account_option_string_new(_("Server[:Port]\n(leave empty for auto-discovery)"), "server", "");
206 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
208 option = purple_account_option_list_new(_("Connection type"), "transport", NULL);
209 purple_account_option_add_list_item(option, _("Auto"), "auto");
210 purple_account_option_add_list_item(option, _("SSL/TLS"), "tls");
211 purple_account_option_add_list_item(option, _("TCP"), "tcp");
212 purple_account_option_add_list_item(option, _("UDP"), "udp");
213 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
215 /*option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "doservice", TRUE);
216 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);*/
218 option = purple_account_option_string_new(_("User Agent"), "useragent", "");
219 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
221 #ifdef HAVE_LIBKRB5
222 option = purple_account_option_bool_new(_("Use Kerberos"), "krb5", FALSE);
223 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
225 /* Suitable for sspi/NTLM, sspi/Kerberos and krb5 security mechanisms
226 * No login/password is taken into account if this option present,
227 * instead used default credentials stored in OS.
229 option = purple_account_option_bool_new(_("Use Single Sign-On"), "sso", TRUE);
230 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
231 #endif
233 option = purple_account_option_list_new(_("Calendar source"), "calendar", NULL);
234 purple_account_option_add_list_item(option, _("Exchange 2007/2010"), "EXCH");
235 purple_account_option_add_list_item(option, _("None"), "NONE");
236 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
238 /** Example: https://server.company.com/EWS/Exchange.asmx */
239 option = purple_account_option_string_new(_("Email services URL\n(leave empty for auto-discovery)"), "email_url", "");
240 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
242 option = purple_account_option_string_new(_("Email address\n(if different from Username)"), "email", "");
243 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
245 /** Example: DOMAIN\user or user@company.com */
246 option = purple_account_option_string_new(_("Email login\n(if different from Login)"), "email_login", "");
247 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
249 option = purple_account_option_string_new(_("Email password\n(if different from Password)"), "email_password", "");
250 purple_account_option_set_masked(option, TRUE);
251 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
254 /* This macro makes the code a purple plugin */
255 PURPLE_INIT_PLUGIN(sipe, init_plugin, info);
258 Local Variables:
259 mode: c
260 c-file-style: "bsd"
261 indent-tabs-mode: t
262 tab-width: 8
263 End: