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