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