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