2 * This file is part of Command-Line Sharing Plugin.
4 * Copyright (C) 2010 Tuomas Kulve.
5 * Copyright (C) 2009 Heikki Kallasjoki. All rights reserved.
6 * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved.
8 * This maemo code example is licensed under a MIT-style license,
9 * that can be found in the file called "COPYING" in the root
16 #include <sharing-plugin-interface.h>
17 #include <sharing-transfer.h>
18 #include <conicconnection.h>
20 #include <hildon/hildon.h>
27 #define ULOG_DEBUG_L(FMT, ARG...) syslog(LOG_DEBUG | LOG_USER, \
28 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
36 #define ULOG_DEBUG_L(FMT, ARG...) {FILE *f = fopen("/tmp/cli.log", "a"); fprintf(f, "%s:%d: " FMT, __FILE__, __LINE__, ## ARG); fprintf(f, "\n"); fclose(f);}
39 gui_add_item(GtkWidget* table,
43 const gchar* placeholder,
49 gui_read(GHashTable* h, SharingAccount* a);
51 static SharingPluginInterfaceEditAccountResult
52 edit_account(SharingAccount* account,
57 gui_read_item(GHashTable* h,
61 sharing_plugin_interface_init (gboolean* dead_mans_switch);
64 sharing_plugin_interface_uninit (gboolean* dead_mans_switch);
66 SharingPluginInterfaceSendResult
67 sharing_plugin_interface_send(SharingTransfer* transfer,
69 gboolean* dead_mans_switch);
71 SharingPluginInterfaceAccountSetupResult
72 sharing_plugin_interface_account_setup(GtkWindow* parent,
73 SharingService* service,
74 SharingAccount** worked_on,
75 osso_context_t* osso);
77 SharingPluginInterfaceAccountValidateResult
78 sharing_plugin_interface_account_validate(SharingAccount* account,
81 gboolean* dead_mans_switch);
83 SharingPluginInterfaceEditAccountResult
84 sharing_plugin_interface_edit_account(GtkWindow* parent,
85 SharingAccount* account,
87 gboolean* dead_mans_switch);
89 * sharing_plugin_interface_init:
90 * @dead_mans_switch: What?
92 * Initialize interface
97 sharing_plugin_interface_init(gboolean* dead_mans_switch)
99 ULOG_DEBUG_L("sharing_manager_plugin_interface_init");
104 * sharing_plugin_interface_uninit:
105 * @dead_mans_switch: What?
107 * Uninitialize interface
112 sharing_plugin_interface_uninit(gboolean* dead_mans_switch)
114 ULOG_DEBUG_L("sharing_manager_plugin_interface_uninit");
119 * sharing_plugin_interface_send:
120 * @transfer: Transfer to be send
121 * @con: Connection used
126 * Returns: Result of send
128 SharingPluginInterfaceSendResult
129 sharing_plugin_interface_send(SharingTransfer* transfer,
130 ConIcConnection* con,
131 gboolean* dead_mans_switch)
133 SharingPluginInterfaceSendResult ret_val;
134 ULOG_DEBUG_L ("sharing_plugin_interface_send");
136 ret_val = cli_send (transfer, con, dead_mans_switch);
142 * sharing_plugin_interface_account_setup:
143 * @transfer: #SharingTransfer send
144 * @service: #SharingService
145 * @worked_on: Connection used
146 * @osso_context_t: Osso context
150 * Returns: Result of account setup
152 SharingPluginInterfaceAccountSetupResult
153 sharing_plugin_interface_account_setup(GtkWindow* parent,
154 SharingService* service,
155 SharingAccount** worked_on,
156 osso_context_t* osso)
158 ULOG_DEBUG_L ("sharing_plugin_interface_account_setup");
159 SharingPluginInterfaceEditAccountResult res;
161 if (!worked_on || !*worked_on)
162 return SHARING_ACCOUNT_SETUP_ERROR_UNKNOWN;
164 res = edit_account (*worked_on, parent, TRUE);
166 if (res == SHARING_EDIT_ACCOUNT_SUCCESS)
167 return SHARING_ACCOUNT_SETUP_SUCCESS;
169 return SHARING_ACCOUNT_SETUP_ERROR_UNKNOWN;
173 * sharing_manager_plugin_interface_account_validate:
174 * @account: Account tested
175 * @con: Connection used to test account
178 * Validates account information.
180 * Returns: Result of account validation
182 SharingPluginInterfaceAccountValidateResult
183 sharing_plugin_interface_account_validate(SharingAccount* account,
184 ConIcConnection* con,
186 gboolean* dead_mans_switch)
188 ULOG_DEBUG_L ("sharing_plugin_interface_account_validate");
189 SharingPluginInterfaceAccountValidateResult ret_val;
191 ret_val = SHARING_ACCOUNT_VALIDATE_SUCCESS;
197 * sharing_plugin_interface_edit_account:
198 * @account: Account tested
199 * @con: Connection used to test account
202 * Edit account plugin implementation.
204 * Returns: Result of account edit
206 SharingPluginInterfaceEditAccountResult
207 sharing_plugin_interface_edit_account(GtkWindow* parent,
208 SharingAccount* account,
209 ConIcConnection* con,
210 gboolean* dead_mans_switch)
212 ULOG_DEBUG_L ("sharing_plugin_interface_edit_account");
215 return SHARING_EDIT_ACCOUNT_NOT_STARTED;
217 return edit_account (account, parent, FALSE);
223 gui_add_item(GtkWidget* table,
227 const gchar* placeholder,
232 GtkWidget* wlabel = gtk_label_new (label);
234 gtk_table_attach (GTK_TABLE (table), wlabel, 0, 1, row, row+1,
235 GTK_FILL, GTK_FILL|GTK_EXPAND, HILDON_MARGIN_DOUBLE, 0);
237 GtkWidget* wentry = hildon_entry_new (HILDON_SIZE_AUTO);
238 hildon_entry_set_placeholder (HILDON_ENTRY (wentry), placeholder);
242 hildon_gtk_entry_set_input_mode(GTK_ENTRY (wentry),
243 HILDON_GTK_INPUT_MODE_FULL |
244 HILDON_GTK_INPUT_MODE_INVISIBLE);
247 gtk_table_attach_defaults (GTK_TABLE (table), wentry, 1, 2, row, row+1);
249 g_hash_table_insert (h, id, wentry);
251 gchar* old = sharing_account_get_param (a, id);
254 gtk_entry_set_text (GTK_ENTRY (wentry), old);
263 gui_read_item (GHashTable* h, const gchar* id, SharingAccount* a)
265 GtkWidget* wentry = g_hash_table_lookup (h, id);
266 if (!wentry) return FALSE;
268 gchar* old = sharing_account_get_param (a, id);
269 const gchar* new = gtk_entry_get_text (GTK_ENTRY (wentry));
271 gboolean changed = FALSE;
273 if (!old || strcmp (old, new) != 0)
275 sharing_account_set_param (a, id, new);
284 gui_read(GHashTable* h, SharingAccount* a)
286 gboolean changed = FALSE;
288 if (gui_read_item (h, "command_line", a)) changed = TRUE;
294 static SharingPluginInterfaceEditAccountResult
295 edit_account(SharingAccount* account, GtkWindow* parent, gboolean setup)
297 GHashTable* h = g_hash_table_new (g_str_hash, g_str_equal);
299 GtkWidget* dlg_content;
304 ULOG_DEBUG_L ("edit_account");
308 dlg = gtk_dialog_new_with_buttons ("Account setup - CLI", parent,
310 GTK_DIALOG_DESTROY_WITH_PARENT,
311 GTK_STOCK_OK, GTK_RESPONSE_YES,
314 dlg = gtk_dialog_new_with_buttons ("Edit account - CLI", parent,
316 GTK_DIALOG_DESTROY_WITH_PARENT,
317 GTK_STOCK_SAVE, GTK_RESPONSE_YES,
318 GTK_STOCK_DELETE, GTK_RESPONSE_NO,
322 dlg_content = gtk_dialog_get_content_area (GTK_DIALOG (dlg));
323 vbox = gtk_vbox_new(FALSE, 0);
324 gtk_container_add (GTK_CONTAINER (dlg_content), vbox);
329 label = gtk_label_new("You must use 2x \"%s\", one for src filename, one for dst filename.");
330 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
331 gtk_label_set_single_line_mode(GTK_LABEL(label), FALSE);
333 gtk_box_pack_end(GTK_BOX(vbox), label, FALSE, FALSE, 0);
336 /* Add account info */
337 table = gtk_table_new (4, 2, FALSE);
339 gtk_box_pack_end(GTK_BOX(vbox), table, TRUE, TRUE, 0);
341 gui_add_item(table, 0,
342 "command_line", "CLI command",
343 "Command line command to execute",
346 gtk_widget_show_all (GTK_WIDGET (dlg));
347 gint result = gtk_dialog_run (GTK_DIALOG (dlg));
349 gboolean changed = FALSE;
350 if (result == GTK_RESPONSE_YES)
351 changed = gui_read (h, account);
353 gtk_widget_destroy (dlg);
354 g_hash_table_unref (h);
356 if (result == GTK_RESPONSE_YES && (changed || setup))
357 return SHARING_EDIT_ACCOUNT_SUCCESS;
358 else if (result == GTK_RESPONSE_YES) /* !changed in edit */
359 return SHARING_EDIT_ACCOUNT_NOT_STARTED;
360 else if (result == GTK_RESPONSE_NO)
361 return SHARING_EDIT_ACCOUNT_DELETE;
363 return SHARING_EDIT_ACCOUNT_CANCELLED;