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