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