1
|
1 /*****************************************************************************/
|
|
2 /* bookmarks.c - routines for the bookmarks */
|
|
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */
|
|
4 /* */
|
|
5 /* This program is free software; you can redistribute it and/or modify */
|
|
6 /* it under the terms of the GNU General Public License as published by */
|
|
7 /* the Free Software Foundation; either version 2 of the License, or */
|
|
8 /* (at your option) any later version. */
|
|
9 /* */
|
|
10 /* This program is distributed in the hope that it will be useful, */
|
|
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
13 /* GNU General Public License for more details. */
|
|
14 /* */
|
|
15 /* You should have received a copy of the GNU General Public License */
|
|
16 /* along with this program; if not, write to the Free Software */
|
|
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
|
|
18 /*****************************************************************************/
|
|
19
|
|
20 #include "gftp-gtk.h"
|
|
21
|
19
|
22 static void doadd_bookmark ( gpointer * data,
|
|
23 gftp_dialog_data * ddata);
|
1
|
24 static void bm_apply_changes ( GtkWidget * widget,
|
|
25 gpointer backup_data );
|
|
26 static gftp_bookmarks * copy_bookmarks ( gftp_bookmarks * bookmarks );
|
|
27 static void bm_close_dialog ( GtkWidget * widget,
|
|
28 GtkWidget * dialog );
|
|
29 static void after_move ( GtkCTree * ctree,
|
|
30 GtkCTreeNode * child,
|
|
31 GtkCTreeNode * parent,
|
|
32 GtkCTreeNode * sibling,
|
|
33 gpointer data );
|
|
34 static gint bm_dblclick ( GtkWidget * widget,
|
|
35 GdkEventButton * event,
|
|
36 gpointer data );
|
|
37 static gint bm_enter ( GtkWidget * widget,
|
|
38 GdkEventKey * event,
|
|
39 gpointer data );
|
|
40 static void new_folder_entry ( gpointer data );
|
19
|
41 static void do_make_new ( gpointer data,
|
|
42 gftp_dialog_data * ddata );
|
1
|
43 static void new_item_entry ( gpointer data );
|
|
44 static void edit_entry ( gpointer data );
|
|
45 static void delete_entry ( gpointer data );
|
19
|
46 static void do_delete_entry ( gftp_bookmarks * entry,
|
|
47 gftp_dialog_data * ddata );
|
1
|
48 static void entry_apply_changes ( GtkWidget * widget,
|
|
49 gftp_bookmarks * entry );
|
|
50 static void set_userpass_visible ( GtkWidget * checkbutton,
|
|
51 GtkWidget * entry );
|
|
52 static void build_bookmarks_tree ( void );
|
|
53 static void clear_bookmarks_tree ( void );
|
|
54
|
|
55 static GtkWidget * bm_hostedit, * bm_portedit, * bm_localdiredit,
|
|
56 * bm_remotediredit, * bm_useredit, * bm_passedit, * bm_acctedit, * anon_chk,
|
|
57 * bm_pathedit, * bm_protocol, * tree, *bm_sftppath;
|
|
58 static GHashTable * new_bookmarks_htable;
|
|
59 static gftp_bookmarks * new_bookmarks;
|
|
60 static GtkItemFactory * edit_factory;
|
|
61
|
|
62
|
|
63 void
|
|
64 run_bookmark (gpointer data)
|
|
65 {
|
|
66 gftp_bookmarks * tempentry;
|
|
67 int i;
|
|
68
|
|
69 if (window1.request->stopable || window2.request->stopable)
|
|
70 {
|
|
71 ftp_log (gftp_logging_misc, NULL,
|
|
72 _("%s: Please hit the stop button first to do anything else\n"),
|
|
73 _("Run Bookmark"));
|
|
74 return;
|
|
75 }
|
|
76
|
|
77 if ((tempentry = g_hash_table_lookup (bookmarks_htable, (char *) data)) == NULL)
|
|
78 {
|
|
79 ftp_log (gftp_logging_misc, NULL,
|
|
80 _("Internal gFTP Error: Could not look up bookmark entry. This is definately a bug. Please email masneyb@gftp.org about it. Please be sure to include the version number and how you can reproduce it\n"));
|
|
81 return;
|
|
82 }
|
|
83 else if (tempentry->hostname == NULL || *tempentry->hostname == '\0' ||
|
|
84 tempentry->user == NULL || *tempentry->user == '\0')
|
|
85 {
|
|
86 ftp_log (gftp_logging_misc, NULL, _("Bookmarks Error: There are some missing entries in this bookmark. Make sure you have a hostname and username\n"));
|
|
87 return;
|
|
88 }
|
|
89
|
|
90 if (GFTP_IS_CONNECTED (current_wdata->request))
|
|
91 disconnect (current_wdata);
|
|
92
|
|
93 if (tempentry->local_dir && *tempentry->local_dir != '\0')
|
|
94 {
|
|
95 gftp_set_directory (other_wdata->request, tempentry->local_dir);
|
|
96 gtk_clist_freeze (GTK_CLIST (other_wdata->listbox));
|
|
97 remove_files_window (other_wdata);
|
|
98 ftp_list_files (other_wdata, 1);
|
|
99 gtk_clist_thaw (GTK_CLIST (other_wdata->listbox));
|
|
100 }
|
|
101
|
|
102 gftp_set_username (current_wdata->request, tempentry->user);
|
|
103 if (strncmp (tempentry->pass, "@EMAIL@", 7) == 0)
|
|
104 gftp_set_password (current_wdata->request, emailaddr);
|
|
105 else
|
|
106 gftp_set_password (current_wdata->request, tempentry->pass);
|
|
107 if (tempentry->acct != NULL)
|
|
108 gftp_set_account (current_wdata->request, tempentry->acct);
|
|
109 gftp_set_hostname (current_wdata->request, tempentry->hostname);
|
|
110 gftp_set_directory (current_wdata->request, tempentry->remote_dir);
|
|
111 gftp_set_port (current_wdata->request, tempentry->port);
|
|
112 gftp_set_sftpserv_path (current_wdata->request, tempentry->sftpserv_path);
|
|
113
|
|
114 for (i = 0; gftp_protocols[i].name; i++)
|
|
115 {
|
|
116 if (strcmp (gftp_protocols[i].name, tempentry->protocol) == 0)
|
|
117 {
|
|
118 gftp_protocols[i].init (current_wdata->request);
|
|
119 break;
|
|
120 }
|
|
121 }
|
|
122
|
|
123 if (!gftp_protocols[i].name)
|
|
124 gftp_protocols[0].init (current_wdata->request);
|
|
125
|
7
|
126 /* If we're using one of the SSH protocols, override the value of
|
|
127 ssh_need_userpass in the config file */
|
|
128 if (strncmp (tempentry->protocol, "SSH", 3) == 0)
|
|
129 current_wdata->request->need_userpass = 1;
|
|
130
|
1
|
131 ftp_connect (current_wdata, current_wdata->request, 1);
|
|
132 }
|
|
133
|
|
134 void
|
|
135 add_bookmark (gpointer data)
|
|
136 {
|
|
137 const char *edttxt;
|
|
138
|
|
139 if (!check_status (_("Add Bookmark"), current_wdata, 0, 0, 0, 1))
|
|
140 return;
|
|
141
|
|
142 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry));
|
|
143 if (*edttxt == '\0')
|
|
144 {
|
|
145 ftp_log (gftp_logging_error, NULL,
|
|
146 _("Add Bookmark: You must enter a hostname\n"));
|
|
147 return;
|
|
148 }
|
|
149
|
19
|
150 MakeEditDialog (_("Add Bookmark"), _("Enter the name of the bookmark you want to add\nYou can separate items by a / to put it into a submenu\n(ex: Linux Sites/Debian)"), NULL, 1, _("Remember password"), gftp_dialog_button_create, doadd_bookmark, data, NULL, NULL);
|
1
|
151 }
|
|
152
|
|
153
|
|
154 static void
|
19
|
155 doadd_bookmark (gpointer * data, gftp_dialog_data * ddata)
|
1
|
156 {
|
|
157 GtkItemFactoryEntry test = { NULL, NULL, run_bookmark, 0 };
|
|
158 const char *edttxt, *spos;
|
|
159 gftp_bookmarks * tempentry;
|
|
160 char *dpos;
|
|
161
|
19
|
162 edttxt = gtk_entry_get_text (GTK_ENTRY (ddata->edit));
|
1
|
163 if (*edttxt == '\0')
|
|
164 {
|
|
165 ftp_log (gftp_logging_error, NULL,
|
|
166 _("Add Bookmark: You must enter a name for the bookmark\n"));
|
|
167 return;
|
|
168 }
|
|
169
|
|
170 if (g_hash_table_lookup (bookmarks_htable, edttxt) != NULL)
|
|
171 {
|
|
172 ftp_log (gftp_logging_error, NULL,
|
|
173 _("Add Bookmark: Cannot add bookmark %s because that name already exists\n"), edttxt);
|
|
174 return;
|
|
175 }
|
|
176
|
|
177 tempentry = g_malloc0 (sizeof (*tempentry));
|
|
178
|
|
179 dpos = tempentry->path = g_malloc (strlen (edttxt) + 1);
|
|
180 for (spos = edttxt; *spos != '\0';)
|
|
181 {
|
|
182 *dpos++ = *spos++;
|
|
183 if (*spos == '/')
|
|
184 {
|
|
185 *dpos++ = '/';
|
|
186 for (; *spos == '/'; spos++);
|
|
187 }
|
|
188 }
|
|
189 *dpos = '\0';
|
|
190
|
|
191 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry));
|
|
192 tempentry->hostname = g_malloc (strlen (edttxt) + 1);
|
|
193 strcpy (tempentry->hostname, edttxt);
|
|
194
|
|
195 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (portedit)->entry));
|
|
196 tempentry->port = strtol (edttxt, NULL, 10);
|
|
197
|
|
198 tempentry->protocol =
|
|
199 g_malloc (strlen (GFTP_GET_PROTOCOL_NAME (current_wdata->request)) + 1);
|
|
200 strcpy (tempentry->protocol, GFTP_GET_PROTOCOL_NAME (current_wdata->request));
|
|
201
|
|
202 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (other_wdata->combo)->entry));
|
|
203 tempentry->local_dir = g_malloc (strlen (edttxt) + 1);
|
|
204 strcpy (tempentry->local_dir, edttxt);
|
|
205
|
|
206 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (current_wdata->combo)->entry));
|
|
207 tempentry->remote_dir = g_malloc (strlen (edttxt) + 1);
|
|
208 strcpy (tempentry->remote_dir, edttxt);
|
|
209
|
7
|
210 if ((edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (useredit)->entry))) != NULL)
|
1
|
211 {
|
|
212 tempentry->user = g_malloc (strlen (edttxt) + 1);
|
|
213 strcpy (tempentry->user, edttxt);
|
|
214
|
|
215 edttxt = gtk_entry_get_text (GTK_ENTRY (passedit));
|
|
216 tempentry->pass = g_malloc (strlen (edttxt) + 1);
|
|
217 strcpy (tempentry->pass, edttxt);
|
19
|
218 tempentry->save_password = GTK_TOGGLE_BUTTON (ddata->checkbox)->active;
|
1
|
219 }
|
|
220
|
|
221 add_to_bookmark (tempentry);
|
|
222
|
7
|
223 test.path = g_strconcat ("/Bookmarks/", tempentry->path, NULL);
|
1
|
224 gtk_item_factory_create_item (factory, &test, (gpointer) tempentry->path,
|
|
225 1);
|
|
226 g_free (test.path);
|
|
227 gftp_write_config_file ();
|
|
228 }
|
|
229
|
|
230
|
|
231 void
|
|
232 build_bookmarks_menu (void)
|
|
233 {
|
|
234 GtkItemFactoryEntry test = { NULL, NULL, NULL, 0 };
|
|
235 gftp_bookmarks * tempentry;
|
|
236
|
|
237 tempentry = bookmarks->children;
|
|
238 while (tempentry != NULL)
|
|
239 {
|
7
|
240 test.path = g_strconcat ("/Bookmarks/", tempentry->path, NULL);
|
1
|
241 if (tempentry->isfolder)
|
|
242 {
|
|
243 test.item_type = "<Branch>";
|
|
244 test.callback = NULL;
|
|
245 }
|
|
246 else
|
|
247 {
|
|
248 test.item_type = "";
|
|
249 test.callback = run_bookmark;
|
|
250 }
|
|
251 gtk_item_factory_create_item (factory, &test,
|
|
252 (gpointer) tempentry->path, 1);
|
|
253 g_free (test.path);
|
|
254 if (tempentry->children != NULL)
|
|
255 {
|
|
256 tempentry = tempentry->children;
|
|
257 continue;
|
|
258 }
|
|
259 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
260 tempentry = tempentry->prev;
|
|
261
|
|
262 tempentry = tempentry->next;
|
|
263 }
|
|
264 }
|
|
265
|
|
266
|
19
|
267 #if !(GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2)
|
|
268 static void
|
|
269 editbm_action (GtkWidget * widget, gint response, gpointer user_data)
|
|
270 {
|
|
271 switch (response)
|
|
272 {
|
|
273 case GTK_RESPONSE_OK:
|
|
274 bm_apply_changes (widget, NULL);
|
|
275 /* no break */
|
|
276 default:
|
|
277 bm_close_dialog (NULL, widget);
|
|
278 }
|
|
279 }
|
|
280 #endif
|
|
281
|
|
282
|
1
|
283 void
|
|
284 edit_bookmarks (gpointer data)
|
|
285 {
|
19
|
286 GtkWidget * dialog, * scroll;
|
1
|
287 GtkItemFactory * ifactory;
|
7
|
288 GtkItemFactoryEntry menu_items[] = {
|
1
|
289 {N_("/_File"), NULL, 0, 0, "<Branch>"},
|
|
290 {N_("/File/tearoff"), NULL, 0, 0, "<Tearoff>"},
|
19
|
291 {N_("/File/New Folder..."), NULL, new_folder_entry, 0, MN_(NULL)},
|
|
292 {N_("/File/New Item..."), NULL, new_item_entry, 0, MS_(GTK_STOCK_NEW)},
|
|
293 {N_("/File/Delete"), NULL, delete_entry, 0, MS_(GTK_STOCK_DELETE)},
|
|
294 {N_("/File/Properties..."), NULL, edit_entry, 0, MS_(GTK_STOCK_PROPERTIES)},
|
1
|
295 {N_("/File/sep"), NULL, 0, 0, "<Separator>"},
|
19
|
296 {N_("/File/Close"), NULL, gtk_widget_destroy, 0, MS_(GTK_STOCK_CLOSE)}
|
1
|
297 };
|
19
|
298 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
|
299 GtkWidget * tempwid;
|
|
300 #endif
|
1
|
301
|
|
302 new_bookmarks = copy_bookmarks (bookmarks);
|
|
303 new_bookmarks_htable = build_bookmarks_hash_table (new_bookmarks);
|
|
304
|
19
|
305 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
1
|
306 dialog = gtk_dialog_new ();
|
|
307 gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Bookmarks"));
|
19
|
308 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 15);
|
|
309 #else
|
|
310 dialog = gtk_dialog_new_with_buttons (_("Edit Bookmarks"), NULL, 0,
|
|
311 GTK_STOCK_SAVE,
|
|
312 GTK_RESPONSE_OK,
|
|
313 GTK_STOCK_CANCEL,
|
|
314 GTK_RESPONSE_CANCEL,
|
|
315 NULL);
|
|
316 #endif
|
1
|
317 gtk_window_set_wmclass (GTK_WINDOW(dialog), "Edit Bookmarks", "gFTP");
|
|
318 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
19
|
319 gtk_widget_realize (dialog);
|
|
320
|
|
321 if (gftp_icon != NULL)
|
|
322 {
|
|
323 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap,
|
|
324 gftp_icon->bitmap);
|
|
325 gdk_window_set_icon_name (dialog->window, _("gFTP Icon"));
|
|
326 }
|
1
|
327
|
23
|
328 /* FIXME - memory leak */
|
7
|
329 ifactory = item_factory_new (GTK_TYPE_MENU_BAR, "<bookmarks>", NULL, NULL);
|
1
|
330 create_item_factory (ifactory, 7, menu_items, NULL);
|
|
331 create_item_factory (ifactory, 1, menu_items + 7, dialog);
|
|
332 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), ifactory->widget,
|
|
333 FALSE, FALSE, 0);
|
|
334 gtk_widget_show (ifactory->widget);
|
|
335
|
|
336 scroll = gtk_scrolled_window_new (NULL, NULL);
|
|
337 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
|
|
338 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
339 gtk_widget_set_size_request (scroll, 150, 200);
|
|
340
|
|
341 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), scroll, TRUE, TRUE,
|
|
342 0);
|
|
343 gtk_container_border_width (GTK_CONTAINER (scroll), 3);
|
|
344 gtk_widget_show (scroll);
|
|
345
|
23
|
346 /* FIXME - memory leak */
|
7
|
347 edit_factory = item_factory_new (GTK_TYPE_MENU, "<edit_bookmark>", NULL, "/File");
|
|
348
|
|
349 create_item_factory (edit_factory, 6, menu_items + 2, dialog);
|
1
|
350
|
|
351 tree = gtk_ctree_new (1, 0);
|
|
352 gtk_clist_set_selection_mode (GTK_CLIST (tree), GTK_SELECTION_BROWSE);
|
|
353 gtk_clist_set_reorderable (GTK_CLIST (tree), 1);
|
|
354 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll), tree);
|
|
355 gtk_signal_connect_after (GTK_OBJECT (tree), "key_press_event",
|
|
356 GTK_SIGNAL_FUNC (bm_enter), (gpointer) tree);
|
|
357 gtk_signal_connect_after (GTK_OBJECT (tree), "tree_move",
|
|
358 GTK_SIGNAL_FUNC (after_move), NULL);
|
|
359 gtk_signal_connect_after (GTK_OBJECT (tree), "button_press_event",
|
|
360 GTK_SIGNAL_FUNC (bm_dblclick), (gpointer) tree);
|
|
361 gtk_widget_show (tree);
|
|
362
|
19
|
363 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
1
|
364 tempwid = gtk_button_new_with_label (_("OK"));
|
|
365 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
366 TRUE, TRUE, 0);
|
|
367 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
368 GTK_SIGNAL_FUNC (bm_apply_changes), NULL);
|
|
369 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
370 GTK_SIGNAL_FUNC (bm_close_dialog), (gpointer) dialog);
|
|
371 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
372 gtk_widget_show (tempwid);
|
|
373
|
|
374 tempwid = gtk_button_new_with_label (_(" Cancel "));
|
|
375 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
376 TRUE, TRUE, 0);
|
|
377 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
378 GTK_SIGNAL_FUNC (bm_close_dialog), (gpointer) dialog);
|
|
379 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
380 gtk_widget_grab_focus (tempwid);
|
|
381 gtk_widget_show (tempwid);
|
19
|
382 #else
|
|
383 g_signal_connect (GTK_OBJECT (dialog), "response",
|
|
384 G_CALLBACK (editbm_action), NULL);
|
|
385 #endif
|
1
|
386
|
|
387 gtk_widget_show (dialog);
|
|
388
|
|
389 build_bookmarks_tree ();
|
|
390 }
|
|
391
|
|
392
|
|
393 static void
|
23
|
394 free_bookmark_entry_items (gftp_bookmarks * entry)
|
|
395 {
|
|
396 if (entry->hostname)
|
|
397 g_free (entry->hostname);
|
|
398 if (entry->remote_dir)
|
|
399 g_free (entry->remote_dir);
|
|
400 if (entry->local_dir)
|
|
401 g_free (entry->local_dir);
|
|
402 if (entry->user)
|
|
403 g_free (entry->user);
|
|
404 if (entry->pass)
|
|
405 g_free (entry->pass);
|
|
406 if (entry->acct)
|
|
407 g_free (entry->acct);
|
|
408 if (entry->protocol)
|
|
409 g_free (entry->protocol);
|
|
410 }
|
|
411
|
|
412
|
|
413 static void
|
1
|
414 bm_apply_changes (GtkWidget * widget, gpointer backup_data)
|
|
415 {
|
|
416 gftp_bookmarks * tempentry, * delentry;
|
|
417 char *tempstr;
|
|
418
|
|
419 tempentry = bookmarks->children;
|
|
420 while (tempentry != NULL)
|
|
421 {
|
|
422 if (tempentry->path && !tempentry->isfolder)
|
|
423 {
|
7
|
424 tempstr = g_strdup_printf ("/Bookmarks/%s", tempentry->path);
|
1
|
425 gtk_widget_destroy (gtk_item_factory_get_item (factory, tempstr));
|
|
426 g_free (tempentry->path);
|
|
427 g_free (tempstr);
|
|
428 }
|
23
|
429
|
|
430 free_bookmark_entry_items (tempentry);
|
1
|
431
|
|
432 if (tempentry->children != NULL)
|
|
433 tempentry = tempentry->children;
|
|
434 else
|
|
435 {
|
|
436 if (tempentry->next == NULL)
|
|
437 {
|
|
438 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
439 {
|
|
440 delentry = tempentry;
|
|
441 tempentry = tempentry->prev;
|
|
442 if (delentry->isfolder)
|
|
443 {
|
7
|
444 tempstr = g_strdup_printf ("/Bookmarks/%s",
|
1
|
445 delentry->path);
|
|
446 gtk_widget_destroy (gtk_item_factory_get_item (factory,
|
|
447 tempstr));
|
|
448 g_free (tempstr);
|
|
449 g_free (delentry->path);
|
|
450 }
|
|
451 g_free (delentry);
|
|
452 }
|
|
453 delentry = tempentry;
|
|
454 tempentry = tempentry->next;
|
|
455 if (delentry->isfolder && tempentry != NULL)
|
|
456 {
|
7
|
457 tempstr = g_strdup_printf ("/Bookmarks/%s",
|
1
|
458 delentry->path);
|
|
459 gtk_widget_destroy (gtk_item_factory_get_item (factory,
|
|
460 tempstr));
|
|
461 g_free (delentry->path);
|
|
462 g_free (tempstr);
|
|
463 g_free (delentry);
|
|
464 }
|
|
465 }
|
|
466 else
|
|
467 {
|
|
468 delentry = tempentry;
|
|
469 tempentry = tempentry->next;
|
|
470 g_free (delentry);
|
|
471 }
|
|
472 }
|
|
473 }
|
|
474 g_free (bookmarks);
|
|
475 g_hash_table_destroy (bookmarks_htable);
|
|
476
|
|
477 bookmarks = new_bookmarks;
|
|
478 bookmarks_htable = new_bookmarks_htable;
|
|
479 if (backup_data)
|
|
480 {
|
|
481 new_bookmarks = copy_bookmarks (bookmarks);
|
|
482 new_bookmarks_htable = build_bookmarks_hash_table (new_bookmarks);
|
|
483 }
|
|
484 else
|
|
485 {
|
|
486 new_bookmarks = NULL;
|
|
487 new_bookmarks_htable = NULL;
|
|
488 }
|
|
489 build_bookmarks_menu ();
|
|
490 gftp_write_config_file ();
|
|
491 }
|
|
492
|
|
493
|
|
494 static gftp_bookmarks *
|
|
495 copy_bookmarks (gftp_bookmarks * bookmarks)
|
|
496 {
|
|
497 gftp_bookmarks * new_bm, * preventry, * tempentry, * sibling, * newentry,
|
|
498 * tentry;
|
|
499
|
|
500 new_bm = g_malloc0 (sizeof (*new_bm));
|
23
|
501 /* FIXME - memory leak */
|
1
|
502 new_bm->path = g_malloc0 (1);
|
|
503 new_bm->isfolder = bookmarks->isfolder;
|
|
504 preventry = new_bm;
|
|
505 tempentry = bookmarks->children;
|
|
506 sibling = NULL;
|
|
507 while (tempentry != NULL)
|
|
508 {
|
|
509 newentry = g_malloc0 (sizeof (*newentry));
|
|
510 newentry->isfolder = tempentry->isfolder;
|
|
511 newentry->save_password = tempentry->save_password;
|
|
512 newentry->cnode = tempentry->cnode;
|
|
513 if (tempentry->path)
|
|
514 {
|
|
515 newentry->path = g_malloc (strlen (tempentry->path) + 1);
|
|
516 strcpy (newentry->path, tempentry->path);
|
|
517 }
|
|
518 if (tempentry->hostname)
|
|
519 {
|
|
520 newentry->hostname = g_malloc (strlen (tempentry->hostname) + 1);
|
|
521 strcpy (newentry->hostname, tempentry->hostname);
|
|
522 }
|
|
523 if (tempentry->protocol)
|
|
524 {
|
|
525 newentry->protocol = g_malloc (strlen (tempentry->protocol) + 1);
|
|
526 strcpy (newentry->protocol, tempentry->protocol);
|
|
527 }
|
|
528 if (tempentry->local_dir)
|
|
529 {
|
|
530 newentry->local_dir = g_malloc (strlen (tempentry->local_dir) + 1);
|
|
531 strcpy (newentry->local_dir, tempentry->local_dir);
|
|
532 }
|
|
533 if (tempentry->remote_dir)
|
|
534 {
|
|
535 newentry->remote_dir =
|
|
536 g_malloc (strlen (tempentry->remote_dir) + 1);
|
|
537 strcpy (newentry->remote_dir, tempentry->remote_dir);
|
|
538 }
|
|
539 if (tempentry->user)
|
|
540 {
|
|
541 newentry->user = g_malloc (strlen (tempentry->user) + 1);
|
|
542 strcpy (newentry->user, tempentry->user);
|
|
543 }
|
|
544 if (tempentry->pass)
|
|
545 {
|
|
546 newentry->pass = g_malloc (strlen (tempentry->pass) + 1);
|
|
547 strcpy (newentry->pass, tempentry->pass);
|
|
548 }
|
|
549 if (tempentry->acct)
|
|
550 {
|
|
551 newentry->acct = g_malloc (strlen (tempentry->acct) + 1);
|
|
552 strcpy (newentry->acct, tempentry->acct);
|
|
553 }
|
|
554 if (tempentry->sftpserv_path)
|
|
555 {
|
|
556 newentry->sftpserv_path = g_malloc (strlen (tempentry->sftpserv_path) + 1);
|
|
557 strcpy (newentry->sftpserv_path, tempentry->sftpserv_path);
|
|
558 }
|
|
559 newentry->port = tempentry->port;
|
|
560
|
|
561 if (sibling == NULL)
|
|
562 {
|
|
563 if (preventry->children == NULL)
|
|
564 preventry->children = newentry;
|
|
565 else
|
|
566 {
|
|
567 tentry = preventry->children;
|
|
568 while (tentry->next != NULL)
|
|
569 tentry = tentry->next;
|
|
570 tentry->next = newentry;
|
|
571 }
|
|
572 }
|
|
573 else
|
|
574 sibling->next = newentry;
|
|
575 newentry->prev = preventry;
|
|
576
|
|
577 if (tempentry->children != NULL)
|
|
578 {
|
|
579 preventry = newentry;
|
|
580 sibling = NULL;
|
|
581 tempentry = tempentry->children;
|
|
582 }
|
|
583 else
|
|
584 {
|
|
585 if (tempentry->next == NULL)
|
|
586 {
|
|
587 sibling = NULL;
|
|
588 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
589 {
|
|
590 tempentry = tempentry->prev;
|
|
591 preventry = preventry->prev;
|
|
592 }
|
|
593 tempentry = tempentry->next;
|
|
594 }
|
|
595 else
|
|
596 {
|
|
597 sibling = newentry;
|
|
598 tempentry = tempentry->next;
|
|
599 }
|
|
600 }
|
|
601 }
|
|
602 return (new_bm);
|
|
603 }
|
|
604
|
|
605
|
|
606 static void
|
|
607 bm_close_dialog (GtkWidget * widget, GtkWidget * dialog)
|
|
608 {
|
23
|
609 gftp_bookmarks * tempentry, * delentry;
|
1
|
610
|
|
611 if (new_bookmarks_htable)
|
|
612 g_hash_table_destroy (new_bookmarks_htable);
|
23
|
613
|
1
|
614 tempentry = new_bookmarks;
|
|
615 while (tempentry != NULL)
|
|
616 {
|
23
|
617 free_bookmark_entry_items (tempentry);
|
|
618 g_free (tempentry->path);
|
|
619
|
1
|
620 if (tempentry->children != NULL)
|
|
621 {
|
|
622 tempentry = tempentry->children;
|
|
623 continue;
|
|
624 }
|
23
|
625
|
1
|
626 while (tempentry->next == NULL && tempentry->prev != NULL)
|
23
|
627 {
|
|
628 delentry = tempentry;
|
|
629 tempentry = tempentry->prev;
|
|
630 g_free (delentry);
|
|
631 }
|
|
632
|
|
633 delentry = tempentry;
|
1
|
634 tempentry = tempentry->next;
|
23
|
635 g_free (delentry);
|
1
|
636 }
|
23
|
637
|
1
|
638 new_bookmarks = NULL;
|
|
639 new_bookmarks_htable = NULL;
|
|
640 gtk_widget_destroy (dialog);
|
|
641 }
|
|
642
|
|
643
|
|
644 static void
|
|
645 after_move (GtkCTree * ctree, GtkCTreeNode * child, GtkCTreeNode * parent,
|
|
646 GtkCTreeNode * sibling, gpointer data)
|
|
647 {
|
|
648
|
|
649 gftp_bookmarks * childentry, * siblingentry, * parententry, * tempentry;
|
|
650 char *tempstr, *pos, *stpos;
|
|
651
|
|
652 childentry = gtk_ctree_node_get_row_data (ctree, child);
|
|
653 parententry = gtk_ctree_node_get_row_data (ctree, parent);
|
|
654 siblingentry = gtk_ctree_node_get_row_data (ctree, sibling);
|
|
655
|
|
656 tempentry = childentry->prev->children;
|
|
657 if (tempentry == childentry)
|
|
658 childentry->prev->children = childentry->prev->children->next;
|
|
659 else
|
|
660 {
|
|
661 while (tempentry->next != childentry)
|
|
662 tempentry = tempentry->next;
|
|
663 tempentry->next = childentry->next;
|
|
664 }
|
|
665 childentry->prev = parententry;
|
|
666 if (!parententry->isfolder)
|
|
667 {
|
|
668 childentry->next = parententry->children;
|
|
669 parententry->children = childentry;
|
|
670 gtk_ctree_move (ctree, child, parententry->prev->cnode,
|
|
671 parententry->cnode);
|
|
672 }
|
|
673 else
|
|
674 {
|
|
675 if (siblingentry == NULL || parententry->children == siblingentry)
|
|
676 {
|
|
677 childentry->next = parententry->children;
|
|
678 parententry->children = childentry;
|
|
679 }
|
|
680 else
|
|
681 {
|
|
682 tempentry = parententry->children;
|
|
683 while (tempentry->next != siblingentry)
|
|
684 tempentry = tempentry->next;
|
|
685 childentry->next = tempentry->next;
|
|
686 tempentry->next = childentry;
|
|
687 }
|
|
688
|
|
689 tempentry = childentry;
|
|
690 while (tempentry != NULL)
|
|
691 {
|
|
692 g_hash_table_remove (new_bookmarks_htable, tempentry->path);
|
|
693 if ((pos = strrchr (tempentry->path, '/')) == NULL)
|
|
694 pos = tempentry->path;
|
|
695 else
|
|
696 pos++;
|
|
697 tempstr = g_strdup_printf ("%s/%s", tempentry->prev->path, pos);
|
|
698 for (stpos = tempstr; *stpos == '/'; stpos++);
|
|
699 g_free (tempentry->path);
|
|
700 tempentry->path = g_malloc (strlen (stpos) + 1);
|
|
701 strcpy (tempentry->path, stpos);
|
|
702 g_free (tempstr);
|
|
703 g_hash_table_insert (new_bookmarks_htable, tempentry->path,
|
|
704 tempentry);
|
|
705 if (tempentry->children != NULL)
|
|
706 tempentry = tempentry->children;
|
|
707 else
|
|
708 {
|
|
709 if (tempentry->next == NULL)
|
|
710 {
|
|
711 if (tempentry->prev == childentry)
|
|
712 break;
|
|
713 else
|
|
714 {
|
|
715 while (tempentry->next == NULL
|
|
716 && tempentry->prev != NULL)
|
|
717 tempentry = tempentry->prev;
|
|
718 }
|
|
719 }
|
|
720 tempentry = tempentry->next;
|
|
721 }
|
|
722 }
|
|
723 }
|
|
724 }
|
|
725
|
|
726
|
|
727 static gint
|
|
728 bm_dblclick (GtkWidget * widget, GdkEventButton * event, gpointer data)
|
|
729 {
|
|
730 if (event->button == 3)
|
|
731 gtk_item_factory_popup (edit_factory, (guint) event->x_root,
|
|
732 (guint) event->y_root, 1, 0);
|
|
733 else if (event->type == GDK_2BUTTON_PRESS)
|
|
734 {
|
|
735 edit_entry (NULL);
|
|
736 return (FALSE);
|
|
737 }
|
|
738 return (TRUE);
|
|
739 }
|
|
740
|
|
741
|
|
742 static gint
|
|
743 bm_enter (GtkWidget * widget, GdkEventKey * event, gpointer data)
|
|
744 {
|
|
745 if (event->type == GDK_KEY_PRESS)
|
|
746 {
|
|
747 if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter)
|
|
748 {
|
|
749 edit_entry (NULL);
|
|
750 return (FALSE);
|
|
751 }
|
|
752 else if (event->keyval == GDK_KP_Delete || event->keyval == GDK_Delete)
|
|
753 {
|
|
754 delete_entry (NULL);
|
|
755 return (FALSE);
|
|
756 }
|
|
757 }
|
|
758 return (TRUE);
|
|
759 }
|
|
760
|
|
761
|
|
762 static void
|
|
763 new_folder_entry (gpointer data)
|
|
764 {
|
|
765 MakeEditDialog (_("New Folder"),
|
19
|
766 _("Enter the name of the new folder to create"), NULL, 1,
|
|
767 NULL, gftp_dialog_button_create,
|
|
768 do_make_new, (gpointer) 0x1, NULL, NULL);
|
1
|
769 }
|
|
770
|
|
771
|
|
772 static void
|
|
773 new_item_entry (gpointer data)
|
|
774 {
|
|
775 MakeEditDialog (_("New Folder"),
|
19
|
776 _("Enter the name of the new item to create"), NULL, 1,
|
|
777 NULL, gftp_dialog_button_create,
|
|
778 do_make_new, NULL, NULL, NULL);
|
1
|
779 }
|
|
780
|
|
781
|
|
782 static void
|
19
|
783 do_make_new (gpointer data, gftp_dialog_data * ddata)
|
1
|
784 {
|
|
785 GdkPixmap * closedir_pixmap, * opendir_pixmap;
|
|
786 GdkBitmap * closedir_bitmap, * opendir_bitmap;
|
|
787 gftp_bookmarks * tempentry, * newentry;
|
|
788 GtkCTreeNode * sibling;
|
|
789 char *pos, *text[2];
|
|
790 const char *str;
|
|
791
|
|
792 gftp_get_pixmap (tree, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap);
|
|
793 gftp_get_pixmap (tree, "dir.xpm", &closedir_pixmap, &closedir_bitmap);
|
|
794
|
19
|
795 str = gtk_entry_get_text (GTK_ENTRY (ddata->edit));
|
1
|
796
|
|
797 newentry = g_malloc0 (sizeof (*newentry));
|
|
798 newentry->path = g_malloc (strlen (str) + 1);
|
|
799 strcpy (newentry->path, str);
|
|
800 while ((pos = strchr (str, '/')) != NULL)
|
|
801 *pos++ = ' ';
|
|
802
|
|
803 newentry->prev = new_bookmarks;
|
19
|
804 if (data)
|
1
|
805 newentry->isfolder = 1;
|
|
806
|
|
807 if (new_bookmarks->children == NULL)
|
|
808 {
|
|
809 new_bookmarks->children = newentry;
|
|
810 sibling = NULL;
|
|
811 }
|
|
812 else
|
|
813 {
|
|
814 tempentry = new_bookmarks->children;
|
|
815 while (tempentry->next != NULL)
|
|
816 tempentry = tempentry->next;
|
|
817 tempentry->next = newentry;
|
|
818 sibling = tempentry->cnode;
|
|
819 }
|
|
820
|
|
821 text[0] = text[1] = newentry->path;
|
|
822
|
|
823 if (newentry->isfolder)
|
|
824 newentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree),
|
|
825 new_bookmarks->cnode, NULL,
|
|
826 text, 5, closedir_pixmap,
|
|
827 closedir_bitmap, opendir_pixmap,
|
|
828 opendir_bitmap, FALSE, FALSE);
|
|
829 else
|
|
830 newentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree),
|
|
831 new_bookmarks->cnode, NULL,
|
|
832 text, 5, NULL, NULL, NULL, NULL,
|
|
833 FALSE, FALSE);
|
|
834
|
|
835 gtk_ctree_node_set_row_data (GTK_CTREE (tree), newentry->cnode, newentry);
|
|
836 g_hash_table_insert (new_bookmarks_htable, newentry->path, newentry);
|
|
837 }
|
|
838
|
|
839
|
19
|
840 #if !(GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2)
|
|
841 static void
|
|
842 bmedit_action (GtkWidget * widget, gint response, gpointer user_data)
|
|
843 {
|
|
844 switch (response)
|
|
845 {
|
|
846 case GTK_RESPONSE_APPLY:
|
|
847 entry_apply_changes (widget, user_data);
|
|
848 break;
|
|
849 case GTK_RESPONSE_OK:
|
|
850 entry_apply_changes (widget, user_data);
|
|
851 /* no break */
|
|
852 default:
|
|
853 gtk_widget_destroy (widget);
|
|
854 }
|
|
855 }
|
|
856 #endif
|
|
857
|
|
858
|
1
|
859 static void
|
|
860 edit_entry (gpointer data)
|
|
861 {
|
|
862 GtkWidget * table, * tempwid, * dialog, * menu;
|
|
863 gftp_bookmarks * entry;
|
|
864 int i, num;
|
|
865 char *pos;
|
|
866
|
|
867 if (GTK_CLIST (tree)->selection == NULL)
|
|
868 return;
|
|
869
|
|
870 entry = gtk_ctree_node_get_row_data (GTK_CTREE (tree),
|
|
871 GTK_CLIST (tree)->selection->data);
|
|
872
|
|
873 if (entry == NULL || entry == new_bookmarks)
|
|
874 return;
|
|
875
|
19
|
876 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
1
|
877 dialog = gtk_dialog_new ();
|
|
878 gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Entry"));
|
19
|
879 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 15);
|
|
880 #else
|
|
881 dialog = gtk_dialog_new_with_buttons (_("Edit Entry"), NULL, 0,
|
|
882 GTK_STOCK_SAVE,
|
|
883 GTK_RESPONSE_OK,
|
|
884 GTK_STOCK_CANCEL,
|
|
885 GTK_RESPONSE_CANCEL,
|
|
886 GTK_STOCK_APPLY,
|
|
887 GTK_RESPONSE_APPLY,
|
|
888 NULL);
|
|
889 #endif
|
1
|
890 gtk_window_set_wmclass (GTK_WINDOW (dialog), "Edit Bookmark Entry", "gFTP");
|
19
|
891 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
1
|
892 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10);
|
19
|
893 gtk_widget_realize (dialog);
|
|
894
|
|
895 if (gftp_icon != NULL)
|
|
896 {
|
|
897 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap,
|
|
898 gftp_icon->bitmap);
|
|
899 gdk_window_set_icon_name (dialog->window, _("gFTP Icon"));
|
|
900 }
|
1
|
901
|
|
902 tempwid = gtk_frame_new (NULL);
|
|
903 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tempwid, TRUE,
|
|
904 TRUE, 0);
|
|
905 gtk_widget_show (tempwid);
|
|
906
|
|
907 table = gtk_table_new (11, 2, FALSE);
|
|
908 gtk_container_border_width (GTK_CONTAINER (table), 5);
|
|
909 gtk_table_set_row_spacings (GTK_TABLE (table), 5);
|
|
910 gtk_table_set_col_spacings (GTK_TABLE (table), 5);
|
|
911 gtk_container_add (GTK_CONTAINER (tempwid), table);
|
|
912 gtk_widget_show (table);
|
|
913
|
|
914 tempwid = gtk_label_new (_("Description:"));
|
|
915 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
916 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 0, 1);
|
|
917 gtk_widget_show (tempwid);
|
|
918
|
|
919 bm_pathedit = gtk_entry_new ();
|
|
920 gtk_table_attach_defaults (GTK_TABLE (table), bm_pathedit, 1, 2, 0, 1);
|
|
921 if ((pos = strrchr (entry->path, '/')) == NULL)
|
|
922 pos = entry->path;
|
|
923 else
|
|
924 pos++;
|
|
925 if (pos)
|
|
926 gtk_entry_set_text (GTK_ENTRY (bm_pathedit), pos);
|
|
927 gtk_widget_show (bm_pathedit);
|
|
928
|
|
929 tempwid = gtk_label_new (_("Hostname:"));
|
|
930 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
931 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 1, 2);
|
|
932 gtk_widget_show (tempwid);
|
|
933
|
|
934 bm_hostedit = gtk_entry_new ();
|
|
935 gtk_table_attach_defaults (GTK_TABLE (table), bm_hostedit, 1, 2, 1, 2);
|
|
936 if (entry->isfolder)
|
|
937 gtk_widget_set_sensitive (bm_hostedit, 0);
|
|
938 else if (entry->hostname)
|
|
939 gtk_entry_set_text (GTK_ENTRY (bm_hostedit), entry->hostname);
|
|
940 gtk_widget_show (bm_hostedit);
|
|
941
|
|
942 tempwid = gtk_label_new (_("Port:"));
|
|
943 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
944 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 2, 3);
|
|
945 gtk_widget_show (tempwid);
|
|
946
|
|
947 bm_portedit = gtk_entry_new ();
|
|
948 gtk_table_attach_defaults (GTK_TABLE (table), bm_portedit, 1, 2, 2, 3);
|
|
949 if (entry->isfolder)
|
|
950 gtk_widget_set_sensitive (bm_portedit, 0);
|
|
951 else if (entry->port)
|
|
952 {
|
|
953 pos = g_strdup_printf ("%d", entry->port);
|
|
954 gtk_entry_set_text (GTK_ENTRY (bm_portedit), pos);
|
|
955 g_free (pos);
|
|
956 }
|
|
957 gtk_widget_show (bm_portedit);
|
|
958
|
|
959 tempwid = gtk_label_new (_("Protocol:"));
|
|
960 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
961 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 3, 4);
|
|
962 gtk_widget_show (tempwid);
|
|
963
|
|
964 menu = gtk_option_menu_new ();
|
|
965 gtk_table_attach_defaults (GTK_TABLE (table), menu, 1, 2, 3, 4);
|
|
966 gtk_widget_show (menu);
|
|
967
|
|
968 num = 0;
|
|
969 bm_protocol = gtk_menu_new ();
|
|
970 for (i = 0; gftp_protocols[i].name; i++)
|
|
971 {
|
|
972 tempwid = gtk_menu_item_new_with_label (gftp_protocols[i].name);
|
|
973 gtk_object_set_user_data (GTK_OBJECT (tempwid), gftp_protocols[i].name);
|
|
974 gtk_menu_append (GTK_MENU (bm_protocol), tempwid);
|
|
975 gtk_widget_show (tempwid);
|
|
976 if (entry->protocol &&
|
|
977 strcmp (gftp_protocols[i].name, entry->protocol) == 0)
|
|
978 num = i;
|
|
979 }
|
|
980 gtk_option_menu_set_menu (GTK_OPTION_MENU (menu), bm_protocol);
|
|
981 gtk_option_menu_set_history (GTK_OPTION_MENU (menu), num);
|
|
982
|
|
983 tempwid = gtk_label_new (_("Remote Directory:"));
|
|
984 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
985 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 4, 5);
|
|
986 gtk_widget_show (tempwid);
|
|
987
|
|
988 bm_remotediredit = gtk_entry_new ();
|
|
989 gtk_table_attach_defaults (GTK_TABLE (table), bm_remotediredit, 1, 2, 4, 5);
|
|
990 if (entry->isfolder)
|
|
991 gtk_widget_set_sensitive (bm_remotediredit, 0);
|
|
992 else if (entry->remote_dir)
|
|
993 gtk_entry_set_text (GTK_ENTRY (bm_remotediredit), entry->remote_dir);
|
|
994 gtk_widget_show (bm_remotediredit);
|
|
995
|
|
996 tempwid = gtk_label_new (_("Local Directory:"));
|
|
997 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
998 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 5, 6);
|
|
999 gtk_widget_show (tempwid);
|
|
1000
|
|
1001 bm_localdiredit = gtk_entry_new ();
|
|
1002 gtk_table_attach_defaults (GTK_TABLE (table), bm_localdiredit, 1, 2, 5, 6);
|
|
1003 if (entry->isfolder)
|
|
1004 gtk_widget_set_sensitive (bm_localdiredit, 0);
|
|
1005 else if (entry->local_dir)
|
|
1006 gtk_entry_set_text (GTK_ENTRY (bm_localdiredit), entry->local_dir);
|
|
1007 gtk_widget_show (bm_localdiredit);
|
|
1008
|
|
1009 tempwid = gtk_label_new (_("Remote SSH sftp path:"));
|
|
1010 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
1011 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 6, 7);
|
|
1012 gtk_widget_show (tempwid);
|
|
1013
|
|
1014 bm_sftppath = gtk_entry_new ();
|
|
1015 gtk_table_attach_defaults (GTK_TABLE (table), bm_sftppath, 1, 2, 6, 7);
|
|
1016 if (entry->isfolder)
|
|
1017 gtk_widget_set_sensitive (bm_sftppath, 0);
|
|
1018 else if (entry->sftpserv_path)
|
|
1019 gtk_entry_set_text (GTK_ENTRY (bm_sftppath), entry->sftpserv_path);
|
|
1020 gtk_widget_show (bm_sftppath);
|
|
1021
|
|
1022 tempwid = gtk_hseparator_new ();
|
|
1023 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 2, 7, 8);
|
|
1024 gtk_widget_show (tempwid);
|
|
1025
|
|
1026 tempwid = gtk_label_new (_("Username:"));
|
|
1027 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
1028 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 8, 9);
|
|
1029 gtk_widget_show (tempwid);
|
|
1030
|
|
1031 bm_useredit = gtk_entry_new ();
|
|
1032 gtk_table_attach_defaults (GTK_TABLE (table), bm_useredit, 1, 2, 8, 9);
|
|
1033 if (entry->isfolder)
|
|
1034 gtk_widget_set_sensitive (bm_useredit, 0);
|
|
1035 else if (entry->user)
|
|
1036 gtk_entry_set_text (GTK_ENTRY (bm_useredit), entry->user);
|
|
1037 gtk_widget_show (bm_useredit);
|
|
1038
|
|
1039 tempwid = gtk_label_new (_("Password:"));
|
|
1040 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
1041 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 9, 10);
|
|
1042 gtk_widget_show (tempwid);
|
|
1043
|
|
1044 bm_passedit = gtk_entry_new ();
|
|
1045 gtk_table_attach_defaults (GTK_TABLE (table), bm_passedit, 1, 2, 9, 10);
|
|
1046 gtk_entry_set_visibility (GTK_ENTRY (bm_passedit), FALSE);
|
|
1047 if (entry->isfolder)
|
|
1048 gtk_widget_set_sensitive (bm_passedit, 0);
|
|
1049 else if (entry->pass)
|
|
1050 gtk_entry_set_text (GTK_ENTRY (bm_passedit), entry->pass);
|
|
1051 gtk_widget_show (bm_passedit);
|
|
1052
|
|
1053 tempwid = gtk_label_new (_("Account:"));
|
|
1054 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
1055 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 10, 11);
|
|
1056 gtk_widget_show (tempwid);
|
|
1057
|
|
1058 bm_acctedit = gtk_entry_new ();
|
|
1059 gtk_table_attach_defaults (GTK_TABLE (table), bm_acctedit, 1, 2, 10, 11);
|
|
1060 gtk_entry_set_visibility (GTK_ENTRY (bm_acctedit), FALSE);
|
|
1061 if (entry->isfolder)
|
|
1062 gtk_widget_set_sensitive (bm_acctedit, 0);
|
|
1063 else if (entry->acct)
|
|
1064 gtk_entry_set_text (GTK_ENTRY (bm_acctedit), entry->acct);
|
|
1065 gtk_widget_show (bm_acctedit);
|
|
1066
|
|
1067 anon_chk = gtk_check_button_new_with_label (_("Log in as ANONYMOUS"));
|
|
1068 gtk_table_attach_defaults (GTK_TABLE (table), anon_chk, 0, 2, 11, 12);
|
|
1069 if (entry->isfolder)
|
|
1070 gtk_widget_set_sensitive (anon_chk, 0);
|
|
1071 else
|
|
1072 {
|
|
1073 gtk_signal_connect (GTK_OBJECT (anon_chk), "toggled",
|
|
1074 GTK_SIGNAL_FUNC (set_userpass_visible), NULL);
|
|
1075 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (anon_chk), entry->user
|
|
1076 && strcmp (entry->user, "anonymous") == 0);
|
|
1077 }
|
|
1078 gtk_widget_show (anon_chk);
|
|
1079
|
19
|
1080 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
|
1
|
1081 tempwid = gtk_button_new_with_label (_("OK"));
|
|
1082 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
1083 TRUE, TRUE, 0);
|
|
1084 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
1085 GTK_SIGNAL_FUNC (entry_apply_changes),
|
|
1086 (gpointer) entry);
|
|
1087 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
1088 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
|
1089 GTK_OBJECT (dialog));
|
|
1090 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
1091 gtk_widget_show (tempwid);
|
|
1092
|
|
1093 tempwid = gtk_button_new_with_label (_(" Cancel "));
|
|
1094 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
1095 TRUE, TRUE, 0);
|
|
1096 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
1097 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
|
1098 GTK_OBJECT (dialog));
|
|
1099 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
1100 gtk_widget_grab_focus (tempwid);
|
|
1101 gtk_widget_show (tempwid);
|
|
1102
|
|
1103 tempwid = gtk_button_new_with_label (_("Apply"));
|
|
1104 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
1105 TRUE, TRUE, 0);
|
|
1106 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
1107 GTK_SIGNAL_FUNC (entry_apply_changes),
|
|
1108 (gpointer) entry);
|
|
1109 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
1110 gtk_widget_show (tempwid);
|
19
|
1111 #else
|
|
1112 g_signal_connect (GTK_OBJECT (dialog), "response",
|
|
1113 G_CALLBACK (bmedit_action), (gpointer) entry);
|
|
1114 #endif
|
1
|
1115
|
|
1116 gtk_widget_show (dialog);
|
|
1117 }
|
|
1118
|
|
1119
|
|
1120 static void
|
|
1121 delete_entry (gpointer data)
|
|
1122 {
|
|
1123 gftp_bookmarks * entry;
|
|
1124 char *tempstr, *pos;
|
|
1125
|
|
1126 if (GTK_CLIST (tree)->selection == NULL)
|
|
1127 return;
|
|
1128 entry =
|
|
1129 gtk_ctree_node_get_row_data (GTK_CTREE (tree),
|
|
1130 GTK_CLIST (tree)->selection->data);
|
|
1131 if (entry == NULL || entry->prev == NULL)
|
|
1132 return;
|
|
1133
|
|
1134 if (!entry->isfolder)
|
19
|
1135 do_delete_entry (entry, NULL);
|
1
|
1136 else
|
|
1137 {
|
|
1138 if ((pos = strrchr (entry->path, '/')) == NULL)
|
|
1139 pos = entry->path;
|
|
1140 else
|
|
1141 pos++;
|
|
1142
|
|
1143 tempstr = g_strdup_printf (_("Are you sure you want to erase the bookmark\n%s and all it's children?"), pos);
|
19
|
1144 MakeYesNoDialog (_("Delete Bookmark"), tempstr, do_delete_entry, entry,
|
|
1145 NULL, NULL);
|
1
|
1146 g_free (tempstr);
|
|
1147 }
|
|
1148 }
|
|
1149
|
|
1150
|
|
1151 static void
|
19
|
1152 do_delete_entry (gftp_bookmarks * entry, gftp_dialog_data * ddata)
|
1
|
1153 {
|
19
|
1154 gftp_bookmarks * tempentry, * delentry;
|
1
|
1155
|
|
1156 g_hash_table_remove (new_bookmarks_htable, entry->path);
|
|
1157 gtk_ctree_remove_node (GTK_CTREE (tree), entry->cnode);
|
|
1158 if (entry->prev->children == entry)
|
|
1159 entry->prev->children = entry->prev->children->next;
|
|
1160 else
|
|
1161 {
|
|
1162 tempentry = entry->prev->children;
|
|
1163 while (tempentry->next != entry)
|
|
1164 tempentry = tempentry->next;
|
|
1165 tempentry->next = entry->next;
|
|
1166 }
|
|
1167
|
|
1168 entry->prev = NULL;
|
|
1169 entry->next = NULL;
|
|
1170 tempentry = entry;
|
|
1171 while (tempentry != NULL)
|
|
1172 {
|
|
1173 if (tempentry->path)
|
|
1174 g_free (tempentry->path);
|
|
1175 if (tempentry->hostname)
|
|
1176 g_free (tempentry->hostname);
|
|
1177 if (tempentry->remote_dir)
|
|
1178 g_free (tempentry->remote_dir);
|
|
1179 if (tempentry->user)
|
|
1180 g_free (tempentry->user);
|
|
1181 if (tempentry->pass)
|
|
1182 g_free (tempentry->pass);
|
|
1183 if (tempentry->sftpserv_path)
|
|
1184 g_free (tempentry->sftpserv_path);
|
|
1185
|
|
1186 if (tempentry->children != NULL)
|
|
1187 {
|
|
1188 tempentry = tempentry->children;
|
|
1189 continue;
|
|
1190 }
|
|
1191 else if (tempentry->next == NULL && tempentry->prev != NULL)
|
|
1192 {
|
|
1193 delentry = tempentry->prev;
|
|
1194 g_free (tempentry);
|
|
1195 tempentry = delentry->next;
|
|
1196 if (delentry != entry)
|
|
1197 g_free (delentry);
|
|
1198 }
|
|
1199 else
|
|
1200 tempentry = tempentry->next;
|
|
1201 }
|
|
1202 g_free (entry);
|
|
1203 }
|
|
1204
|
|
1205
|
|
1206 static void
|
|
1207 entry_apply_changes (GtkWidget * widget, gftp_bookmarks * entry)
|
|
1208 {
|
|
1209 char *pos, *newpath, tempchar, *tempstr, *origpath;
|
|
1210 gftp_bookmarks * tempentry, * nextentry;
|
|
1211 GtkWidget * tempwid;
|
|
1212 const char *str;
|
|
1213 int oldpathlen;
|
|
1214
|
|
1215 oldpathlen = strlen (entry->path);
|
|
1216 if ((pos = strrchr (entry->path, '/')) == NULL)
|
|
1217 {
|
|
1218 pos = entry->path;
|
|
1219 tempchar = *entry->path;
|
|
1220 *entry->path = '\0';
|
|
1221 }
|
|
1222 else
|
|
1223 {
|
|
1224 tempchar = *pos;
|
|
1225 *pos = '\0';
|
|
1226 }
|
|
1227 origpath = newpath = g_strconcat (entry->path, "/",
|
|
1228 gtk_entry_get_text (GTK_ENTRY (bm_pathedit)), NULL);
|
|
1229 remove_double_slashes (newpath);
|
|
1230 for (; *newpath == '/'; newpath++);
|
|
1231 *pos = tempchar;
|
|
1232
|
|
1233 str = gtk_entry_get_text (GTK_ENTRY (bm_hostedit));
|
|
1234 if (entry->hostname)
|
|
1235 g_free (entry->hostname);
|
|
1236 entry->hostname = g_malloc (strlen (str) + 1);
|
|
1237 strcpy (entry->hostname, str);
|
|
1238
|
|
1239 str = gtk_entry_get_text (GTK_ENTRY (bm_portedit));
|
|
1240 entry->port = strtol (str, NULL, 10);
|
|
1241
|
|
1242 tempwid = gtk_menu_get_active (GTK_MENU (bm_protocol));
|
|
1243 str = gtk_object_get_user_data (GTK_OBJECT (tempwid));
|
|
1244 if (entry->protocol)
|
|
1245 g_free (entry->protocol);
|
|
1246 entry->protocol = g_malloc (strlen (str) + 1);
|
|
1247 strcpy (entry->protocol, str);
|
|
1248
|
|
1249 str = gtk_entry_get_text (GTK_ENTRY (bm_remotediredit));
|
|
1250 if (entry->remote_dir)
|
|
1251 g_free (entry->remote_dir);
|
|
1252 entry->remote_dir = g_malloc (strlen (str) + 1);
|
|
1253 strcpy (entry->remote_dir, str);
|
|
1254
|
|
1255 str = gtk_entry_get_text (GTK_ENTRY (bm_localdiredit));
|
|
1256 if (entry->local_dir)
|
|
1257 g_free (entry->local_dir);
|
|
1258 entry->local_dir = g_malloc (strlen (str) + 1);
|
|
1259 strcpy (entry->local_dir, str);
|
|
1260
|
|
1261 str = gtk_entry_get_text (GTK_ENTRY (bm_sftppath));
|
|
1262 if (entry->sftpserv_path)
|
|
1263 g_free (entry->sftpserv_path);
|
|
1264 if (strlen (str) > 0)
|
|
1265 {
|
|
1266 entry->sftpserv_path = g_malloc (strlen (str) + 1);
|
|
1267 strcpy (entry->sftpserv_path, str);
|
|
1268 }
|
|
1269 else
|
|
1270 entry->sftpserv_path = NULL;
|
|
1271
|
|
1272 if (GTK_TOGGLE_BUTTON (anon_chk)->active)
|
|
1273 str = "anonymous";
|
|
1274 else
|
|
1275 str = gtk_entry_get_text (GTK_ENTRY (bm_useredit));
|
|
1276 if (entry->user)
|
|
1277 g_free (entry->user);
|
|
1278 entry->user = g_malloc (strlen (str) + 1);
|
|
1279 strcpy (entry->user, str);
|
|
1280
|
|
1281 if (GTK_TOGGLE_BUTTON (anon_chk)->active)
|
|
1282 str = "@EMAIL@";
|
|
1283 else
|
|
1284 str = gtk_entry_get_text (GTK_ENTRY (bm_passedit));
|
|
1285 if (entry->pass)
|
|
1286 g_free (entry->pass);
|
|
1287 entry->pass = g_malloc (strlen (str) + 1);
|
|
1288 strcpy (entry->pass, str);
|
|
1289 entry->save_password = *entry->pass != '\0';
|
|
1290
|
|
1291 if (GTK_TOGGLE_BUTTON (anon_chk)->active)
|
|
1292 str = "";
|
|
1293 else
|
|
1294 str = gtk_entry_get_text (GTK_ENTRY (bm_acctedit));
|
|
1295 if (entry->acct)
|
|
1296 g_free (entry->acct);
|
|
1297 entry->acct = g_malloc (strlen (str) + 1);
|
|
1298 strcpy (entry->acct, str);
|
|
1299
|
|
1300 if (strcmp (entry->path, newpath) != 0)
|
|
1301 {
|
|
1302 tempentry = entry;
|
|
1303 nextentry = entry->next;
|
|
1304 entry->next = NULL;
|
|
1305 while (tempentry != NULL)
|
|
1306 {
|
|
1307 g_hash_table_remove (new_bookmarks_htable, tempentry->path);
|
|
1308 tempstr = g_strconcat (newpath, "/", tempentry->path + oldpathlen,
|
|
1309 NULL);
|
|
1310 remove_double_slashes (tempstr);
|
|
1311 g_free (tempentry->path);
|
|
1312 tempentry->path = tempstr;
|
|
1313 g_hash_table_insert (new_bookmarks_htable, tempentry->path,
|
|
1314 tempentry);
|
|
1315 if (tempentry->children != NULL)
|
|
1316 {
|
|
1317 tempentry = tempentry->children;
|
|
1318 continue;
|
|
1319 }
|
|
1320 while (tempentry->next == NULL && tempentry != entry &&
|
|
1321 tempentry->prev != NULL)
|
|
1322 tempentry = tempentry->prev;
|
|
1323
|
|
1324 tempentry = tempentry->next;
|
|
1325 }
|
|
1326 entry->next = nextentry;
|
|
1327 clear_bookmarks_tree ();
|
|
1328 build_bookmarks_tree ();
|
|
1329 }
|
|
1330
|
|
1331 g_free (origpath);
|
|
1332 }
|
|
1333
|
|
1334
|
|
1335 static void
|
|
1336 set_userpass_visible (GtkWidget * checkbutton, GtkWidget * entry)
|
|
1337 {
|
|
1338 gtk_widget_set_sensitive (bm_useredit, !GTK_TOGGLE_BUTTON (anon_chk)->active);
|
|
1339 gtk_widget_set_sensitive (bm_passedit, !GTK_TOGGLE_BUTTON (anon_chk)->active);
|
|
1340 gtk_widget_set_sensitive (bm_acctedit, !GTK_TOGGLE_BUTTON (anon_chk)->active);
|
|
1341 }
|
|
1342
|
|
1343
|
|
1344 static void
|
|
1345 build_bookmarks_tree (void)
|
|
1346 {
|
|
1347 GdkPixmap * closedir_pixmap, * opendir_pixmap;
|
|
1348 GdkBitmap * closedir_bitmap, * opendir_bitmap;
|
|
1349 gftp_bookmarks * tempentry, * preventry;
|
|
1350 char *pos, *prevpos, *text[2], *str;
|
|
1351 GtkCTreeNode * parent;
|
|
1352
|
|
1353 gftp_get_pixmap (tree, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap);
|
|
1354 gftp_get_pixmap (tree, "dir.xpm", &closedir_pixmap, &closedir_bitmap);
|
|
1355 text[0] = text[1] = _("Bookmarks");
|
|
1356 parent = gtk_ctree_insert_node (GTK_CTREE (tree), NULL, NULL, text, 5,
|
|
1357 closedir_pixmap, closedir_bitmap,
|
|
1358 opendir_pixmap, opendir_bitmap, FALSE, TRUE);
|
|
1359 gtk_ctree_node_set_row_data (GTK_CTREE (tree), parent, new_bookmarks);
|
|
1360 new_bookmarks->cnode = parent;
|
|
1361
|
|
1362 tempentry = new_bookmarks->children;
|
|
1363 while (tempentry != NULL)
|
|
1364 {
|
23
|
1365 tempentry->cnode = NULL;
|
1
|
1366 if (tempentry->children != NULL)
|
|
1367 {
|
|
1368 tempentry = tempentry->children;
|
|
1369 continue;
|
|
1370 }
|
|
1371 else
|
|
1372 {
|
|
1373 pos = tempentry->path;
|
|
1374 while ((pos = strchr (pos, '/')) != NULL)
|
|
1375 {
|
|
1376 *pos = '\0';
|
|
1377 str = g_malloc (strlen (tempentry->path) + 1);
|
|
1378 strcpy (str, tempentry->path);
|
|
1379 *pos = '/';
|
|
1380 preventry = g_hash_table_lookup (new_bookmarks_htable, str);
|
|
1381 if (preventry->cnode == NULL)
|
|
1382 {
|
|
1383 if ((prevpos = strrchr (str, '/')) == NULL)
|
|
1384 prevpos = str;
|
|
1385 else
|
|
1386 prevpos++;
|
|
1387 text[0] = text[1] = prevpos;
|
|
1388 preventry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree),
|
|
1389 preventry->prev->cnode, NULL, text,
|
|
1390 5, closedir_pixmap, closedir_bitmap,
|
|
1391 opendir_pixmap, opendir_bitmap,
|
|
1392 FALSE, FALSE);
|
|
1393 gtk_ctree_node_set_row_data (GTK_CTREE (tree),
|
|
1394 preventry->cnode, preventry);
|
|
1395 }
|
23
|
1396
|
1
|
1397 g_free (str);
|
|
1398 pos++;
|
|
1399 }
|
|
1400 }
|
|
1401
|
|
1402 if ((pos = strrchr (tempentry->path, '/')) == NULL)
|
|
1403 pos = tempentry->path;
|
|
1404 else
|
|
1405 pos++;
|
|
1406
|
|
1407 text[0] = text[1] = pos;
|
|
1408 tempentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree),
|
|
1409 tempentry->prev->cnode, NULL,
|
|
1410 text, 5, NULL, NULL, NULL, NULL, FALSE, FALSE);
|
|
1411 gtk_ctree_node_set_row_data (GTK_CTREE (tree), tempentry->cnode,
|
|
1412 tempentry);
|
|
1413
|
|
1414 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
1415 tempentry = tempentry->prev;
|
|
1416 tempentry = tempentry->next;
|
|
1417 }
|
|
1418 }
|
|
1419
|
|
1420
|
|
1421 static void
|
|
1422 clear_bookmarks_tree (void)
|
|
1423 {
|
|
1424 gftp_bookmarks * tempentry;
|
|
1425
|
|
1426 tempentry = new_bookmarks->children;
|
|
1427 while (tempentry != NULL)
|
|
1428 {
|
|
1429 if (tempentry->children != NULL)
|
|
1430 {
|
|
1431 tempentry = tempentry->children;
|
|
1432 continue;
|
|
1433 }
|
|
1434 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
1435 {
|
|
1436 gtk_ctree_remove_node (GTK_CTREE (tree), tempentry->cnode);
|
|
1437 tempentry->cnode = NULL;
|
|
1438 tempentry = tempentry->prev;
|
|
1439 }
|
|
1440 gtk_ctree_remove_node (GTK_CTREE (tree), tempentry->cnode);
|
|
1441 tempentry->cnode = NULL;
|
|
1442 tempentry = tempentry->next;
|
|
1443 }
|
|
1444 }
|
|
1445
|