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