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