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