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