Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Command-Line Sharing Plugin
Summary Tracker Lists News SCM Files
1 /*
2  * This file is part of Command-Line Sharing Plugin.
3  *
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.
7  *
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
10  * directory.
11  *
12  */
14 #include <gtk/gtk.h>
15 #include <glib.h>
16 #include <sharing-plugin-interface.h>
17 #include <sharing-transfer.h>
18 #include <conicconnection.h>
19 #include <osso-log.h>
20 #include <hildon/hildon.h>
21 #include <string.h>
23 #include "send.h"
26 /*
27 #define ULOG_DEBUG_L(FMT, ARG...) syslog(LOG_DEBUG | LOG_USER, \
28         "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
29 */
31 #ifdef ULOG_DEBUG_L
32 #undef ULOG_DEBUG_L
33 #endif
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);}
38 static void
39 gui_add_item(GtkWidget* table,
40                          guint row,
41                          gchar* id,
42                          const gchar* label, 
43                          const gchar* placeholder,
44                          gboolean invis,
45                          SharingAccount* a,
46                          GHashTable* h);
48 static gboolean
49 gui_read(GHashTable* h, SharingAccount* a);
51 static SharingPluginInterfaceEditAccountResult
52 edit_account(SharingAccount* account, 
53                          GtkWindow* parent,
54                          gboolean setup);
56 static gboolean
57 gui_read_item(GHashTable* h,
58                           const gchar* id,
59                           SharingAccount* a);
60 guint
61 sharing_plugin_interface_init (gboolean* dead_mans_switch);
63 guint
64 sharing_plugin_interface_uninit (gboolean* dead_mans_switch);
66 SharingPluginInterfaceSendResult
67 sharing_plugin_interface_send(SharingTransfer* transfer,
68                                                           ConIcConnection* con,
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, 
79                                                                                   ConIcConnection* con,
80                                                                                   gboolean *cont,
81                                                                                   gboolean* dead_mans_switch);
83 SharingPluginInterfaceEditAccountResult
84 sharing_plugin_interface_edit_account(GtkWindow* parent,
85                                                                           SharingAccount* account,
86                                                                           ConIcConnection* con,
87                                                                           gboolean* dead_mans_switch);
88 /**
89  * sharing_plugin_interface_init:
90  * @dead_mans_switch: What?
91  *
92  * Initialize interface
93  *
94  * Returns: 0
95  */
96 guint
97 sharing_plugin_interface_init(gboolean* dead_mans_switch)
98 {
99     ULOG_DEBUG_L("sharing_manager_plugin_interface_init");
100     return 0;
103 /**
104  * sharing_plugin_interface_uninit:
105  * @dead_mans_switch: What?
106  *
107  * Uninitialize interface
108  *
109  * Returns: 0
110  */
111 guint
112 sharing_plugin_interface_uninit(gboolean* dead_mans_switch)
114     ULOG_DEBUG_L("sharing_manager_plugin_interface_uninit");
115     return 0;
118 /**
119  * sharing_plugin_interface_send:
120  * @transfer: Transfer to be send
121  * @con: Connection used
122  * @dead_mans_switch: 
123  *
124  * Send interface.
125  *
126  * Returns: Result of send
127  */
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);
138     return ret_val;
141 /**
142  * sharing_plugin_interface_account_setup:
143  * @transfer: #SharingTransfer send
144  * @service: #SharingService
145  * @worked_on: Connection used
146  * @osso_context_t: Osso context
147  *
148  * Send interface
149  *
150  * Returns: Result of account setup
151  */
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);
165     
166     if (res == SHARING_EDIT_ACCOUNT_SUCCESS)
167           return SHARING_ACCOUNT_SETUP_SUCCESS;
168         else
169           return SHARING_ACCOUNT_SETUP_ERROR_UNKNOWN;
172 /**
173  * sharing_manager_plugin_interface_account_validate:
174  * @account: Account tested
175  * @con: Connection used to test account
176  * @dead_mans_switch: 
177  *
178  * Validates account information.
179  *
180  * Returns: Result of account validation
181  */
182 SharingPluginInterfaceAccountValidateResult
183 sharing_plugin_interface_account_validate(SharingAccount* account, 
184                                                                                   ConIcConnection* con,
185                                                                                   gboolean *cont,
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;
193     return ret_val;
196 /**
197  * sharing_plugin_interface_edit_account:
198  * @account: Account tested
199  * @con: Connection used to test account
200  * @dead_mans_switch: 
201  *
202  * Edit account plugin implementation.
203  *
204  * Returns: Result of account edit
205  */
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");
214         if (!account)
215           return SHARING_EDIT_ACCOUNT_NOT_STARTED;
216         
217         return edit_account (account, parent, FALSE);
222 static void
223 gui_add_item(GtkWidget* table,
224                          guint row,
225                          gchar* id,
226                          const gchar* label,
227                          const gchar* placeholder,
228                          gboolean invis,
229                          SharingAccount* a,
230                          GHashTable* h)
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);
236   
237   GtkWidget* wentry = hildon_entry_new (HILDON_SIZE_AUTO);
238   hildon_entry_set_placeholder (HILDON_ENTRY (wentry), placeholder);
240   if (invis) {
241         
242         hildon_gtk_entry_set_input_mode(GTK_ENTRY (wentry),
243                                                                         HILDON_GTK_INPUT_MODE_FULL |
244                                                                         HILDON_GTK_INPUT_MODE_INVISIBLE);
245   }
247   gtk_table_attach_defaults (GTK_TABLE (table), wentry, 1, 2, row, row+1);
248   
249   g_hash_table_insert (h, id, wentry);
250   
251   gchar* old = sharing_account_get_param (a, id);
253   if (old) {
254         gtk_entry_set_text (GTK_ENTRY (wentry), old);
255         g_free (old);
256   }
262 static gboolean
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;
267   
268   gchar* old = sharing_account_get_param (a, id);
269   const gchar* new = gtk_entry_get_text (GTK_ENTRY (wentry));
270   
271   gboolean changed = FALSE;
272   
273   if (!old || strcmp (old, new) != 0)
274         {
275           sharing_account_set_param (a, id, new);
276           changed = TRUE;
277         }
278   
279   g_free (old);
280   return changed;
283 static gboolean
284 gui_read(GHashTable* h, SharingAccount* a)
286   gboolean changed = FALSE;
288   if (gui_read_item (h, "command_line", a)) changed = TRUE;
290   return changed;
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);  
298   GtkWidget* dlg = 0;
299   GtkWidget* dlg_content;
300   GtkWidget* table;
301   GtkWidget* vbox;
302   GtkWidget* label;
304   ULOG_DEBUG_L ("edit_account");
307   if (setup) {
308         dlg = gtk_dialog_new_with_buttons ("Account setup - CLI", parent,
309                                                                            GTK_DIALOG_MODAL |
310                                                                            GTK_DIALOG_DESTROY_WITH_PARENT,
311                                                                            GTK_STOCK_OK, GTK_RESPONSE_YES,
312                                                                            NULL);
313   } else {
314         dlg = gtk_dialog_new_with_buttons ("Edit account - CLI", parent,
315                                                                            GTK_DIALOG_MODAL |
316                                                                            GTK_DIALOG_DESTROY_WITH_PARENT,
317                                                                            GTK_STOCK_SAVE, GTK_RESPONSE_YES,
318                                                                            GTK_STOCK_DELETE, GTK_RESPONSE_NO,
319                                                                            NULL);
320   }
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);
327   /* Add info label */
328   
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);
340   
341   gui_add_item(table, 0,
342                            "command_line", "CLI command",
343                            "Command line command to execute",
344                            FALSE, account, h);
345   
346   gtk_widget_show_all (GTK_WIDGET (dlg));
347   gint result = gtk_dialog_run (GTK_DIALOG (dlg));
348   
349   gboolean changed = FALSE;
350   if (result == GTK_RESPONSE_YES)
351         changed = gui_read (h, account);
352   
353   gtk_widget_destroy (dlg);
354   g_hash_table_unref (h);
355   
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;
362   else
363         return SHARING_EDIT_ACCOUNT_CANCELLED;

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment