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