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