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