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