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