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