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