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
|
422
|
23 static GtkWidget * bm_dialog = NULL, * bm_hostedit, * bm_portedit,
|
|
24 * bm_localdiredit, * bm_remotediredit, * bm_useredit,
|
|
25 * bm_passedit, * bm_acctedit, * anon_chk, * bm_pathedit,
|
452
|
26 * bm_protocol, * tree, * edit_bookmarks_dialog;
|
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
|
1
|
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 {
|
|
62 GtkItemFactoryEntry test = { NULL, NULL, run_bookmark, 0 };
|
|
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
|
|
84 dpos = tempentry->path = g_malloc (strlen (edttxt) + 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 {
|
|
153 GtkItemFactoryEntry test = { NULL, NULL, NULL, 0 };
|
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 }
|
|
170 gtk_item_factory_create_item (factory, &test,
|
|
171 (gpointer) tempentry->path, 1);
|
|
172 g_free (test.path);
|
|
173 if (tempentry->children != NULL)
|
|
174 {
|
|
175 tempentry = tempentry->children;
|
|
176 continue;
|
|
177 }
|
|
178 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
179 tempentry = tempentry->prev;
|
|
180
|
|
181 tempentry = tempentry->next;
|
|
182 }
|
|
183 }
|
|
184
|
|
185
|
129
|
186 static gftp_bookmarks_var *
|
|
187 copy_bookmarks (gftp_bookmarks_var * bookmarks)
|
1
|
188 {
|
129
|
189 gftp_bookmarks_var * new_bm, * preventry, * tempentry, * sibling, * newentry,
|
1
|
190 * tentry;
|
|
191
|
|
192 new_bm = g_malloc0 (sizeof (*new_bm));
|
|
193 new_bm->path = g_malloc0 (1);
|
|
194 new_bm->isfolder = bookmarks->isfolder;
|
|
195 preventry = new_bm;
|
|
196 tempentry = bookmarks->children;
|
|
197 sibling = NULL;
|
|
198 while (tempentry != NULL)
|
|
199 {
|
|
200 newentry = g_malloc0 (sizeof (*newentry));
|
|
201 newentry->isfolder = tempentry->isfolder;
|
|
202 newentry->save_password = tempentry->save_password;
|
|
203 newentry->cnode = tempentry->cnode;
|
|
204 if (tempentry->path)
|
129
|
205 newentry->path = g_strdup (tempentry->path);
|
|
206
|
1
|
207 if (tempentry->hostname)
|
129
|
208 newentry->hostname = g_strdup (tempentry->hostname);
|
|
209
|
1
|
210 if (tempentry->protocol)
|
129
|
211 newentry->protocol = g_strdup (tempentry->protocol);
|
|
212
|
1
|
213 if (tempentry->local_dir)
|
129
|
214 newentry->local_dir = g_strdup (tempentry->local_dir);
|
|
215
|
1
|
216 if (tempentry->remote_dir)
|
129
|
217 newentry->remote_dir = g_strdup (tempentry->remote_dir);
|
|
218
|
1
|
219 if (tempentry->user)
|
129
|
220 newentry->user = g_strdup (tempentry->user);
|
|
221
|
1
|
222 if (tempentry->pass)
|
129
|
223 newentry->pass = g_strdup (tempentry->pass);
|
|
224
|
1
|
225 if (tempentry->acct)
|
129
|
226 newentry->acct = g_strdup (tempentry->acct);
|
|
227
|
1
|
228 newentry->port = tempentry->port;
|
|
229
|
229
|
230 gftp_copy_local_options (&newentry->local_options_vars,
|
|
231 &newentry->local_options_hash,
|
429
|
232 &newentry->num_local_options_vars,
|
229
|
233 tempentry->local_options_vars,
|
|
234 tempentry->num_local_options_vars);
|
|
235 newentry->num_local_options_vars = tempentry->num_local_options_vars;
|
|
236
|
1
|
237 if (sibling == NULL)
|
|
238 {
|
|
239 if (preventry->children == NULL)
|
|
240 preventry->children = newentry;
|
|
241 else
|
|
242 {
|
|
243 tentry = preventry->children;
|
|
244 while (tentry->next != NULL)
|
|
245 tentry = tentry->next;
|
|
246 tentry->next = newentry;
|
|
247 }
|
|
248 }
|
|
249 else
|
|
250 sibling->next = newentry;
|
|
251 newentry->prev = preventry;
|
|
252
|
|
253 if (tempentry->children != NULL)
|
|
254 {
|
|
255 preventry = newentry;
|
|
256 sibling = NULL;
|
|
257 tempentry = tempentry->children;
|
|
258 }
|
|
259 else
|
|
260 {
|
|
261 if (tempentry->next == NULL)
|
|
262 {
|
|
263 sibling = NULL;
|
|
264 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
265 {
|
|
266 tempentry = tempentry->prev;
|
|
267 preventry = preventry->prev;
|
|
268 }
|
|
269 tempentry = tempentry->next;
|
|
270 }
|
|
271 else
|
|
272 {
|
|
273 sibling = newentry;
|
|
274 tempentry = tempentry->next;
|
|
275 }
|
|
276 }
|
|
277 }
|
229
|
278
|
1
|
279 return (new_bm);
|
|
280 }
|
|
281
|
|
282
|
|
283 static void
|
48
|
284 bm_apply_changes (GtkWidget * widget, gpointer backup_data)
|
|
285 {
|
129
|
286 gftp_bookmarks_var * tempentry, * delentry;
|
48
|
287 char *tempstr;
|
|
288
|
129
|
289 tempentry = gftp_bookmarks->children;
|
48
|
290 while (tempentry != NULL)
|
|
291 {
|
|
292 if (tempentry->path && !tempentry->isfolder)
|
|
293 {
|
|
294 tempstr = g_strdup_printf ("/Bookmarks/%s", tempentry->path);
|
|
295 gtk_widget_destroy (gtk_item_factory_get_item (factory, tempstr));
|
|
296 g_free (tempentry->path);
|
|
297 g_free (tempstr);
|
|
298 }
|
|
299
|
199
|
300 gftp_free_bookmark (tempentry);
|
48
|
301
|
|
302 if (tempentry->children != NULL)
|
|
303 tempentry = tempentry->children;
|
|
304 else
|
|
305 {
|
|
306 if (tempentry->next == NULL)
|
|
307 {
|
|
308 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
309 {
|
|
310 delentry = tempentry;
|
|
311 tempentry = tempentry->prev;
|
|
312 if (delentry->isfolder)
|
|
313 {
|
|
314 tempstr = g_strdup_printf ("/Bookmarks/%s",
|
|
315 delentry->path);
|
|
316 gtk_widget_destroy (gtk_item_factory_get_item (factory,
|
|
317 tempstr));
|
|
318 g_free (tempstr);
|
|
319 g_free (delentry->path);
|
|
320 }
|
|
321 g_free (delentry);
|
|
322 }
|
|
323 delentry = tempentry;
|
|
324 tempentry = tempentry->next;
|
|
325 if (delentry->isfolder && tempentry != NULL)
|
|
326 {
|
|
327 tempstr = g_strdup_printf ("/Bookmarks/%s",
|
|
328 delentry->path);
|
|
329 gtk_widget_destroy (gtk_item_factory_get_item (factory,
|
|
330 tempstr));
|
|
331 g_free (delentry->path);
|
|
332 g_free (tempstr);
|
|
333 g_free (delentry);
|
|
334 }
|
|
335 }
|
|
336 else
|
|
337 {
|
|
338 delentry = tempentry;
|
|
339 tempentry = tempentry->next;
|
|
340 g_free (delentry);
|
|
341 }
|
|
342 }
|
|
343 }
|
129
|
344 g_free (gftp_bookmarks);
|
|
345 g_hash_table_destroy (gftp_bookmarks_htable);
|
48
|
346
|
129
|
347 gftp_bookmarks = new_bookmarks;
|
|
348 gftp_bookmarks_htable = new_bookmarks_htable;
|
48
|
349 if (backup_data)
|
|
350 {
|
129
|
351 new_bookmarks = copy_bookmarks (gftp_bookmarks);
|
48
|
352 new_bookmarks_htable = build_bookmarks_hash_table (new_bookmarks);
|
|
353 }
|
|
354 else
|
|
355 {
|
|
356 new_bookmarks = NULL;
|
|
357 new_bookmarks_htable = NULL;
|
|
358 }
|
|
359 build_bookmarks_menu ();
|
|
360 gftp_write_bookmarks_file ();
|
|
361 }
|
|
362
|
|
363
|
|
364 static void
|
1
|
365 bm_close_dialog (GtkWidget * widget, GtkWidget * dialog)
|
|
366 {
|
201
|
367 if (new_bookmarks_htable != NULL)
|
1
|
368 {
|
201
|
369 g_hash_table_destroy (new_bookmarks_htable);
|
|
370 new_bookmarks_htable = NULL;
|
1
|
371 }
|
23
|
372
|
227
|
373 if (new_bookmarks != NULL)
|
|
374 {
|
|
375 gftp_bookmarks_destroy (new_bookmarks);
|
|
376 new_bookmarks = NULL;
|
|
377 }
|
201
|
378
|
452
|
379 gtk_widget_destroy (edit_bookmarks_dialog);
|
|
380 edit_bookmarks_dialog = NULL;
|
1
|
381 }
|
|
382
|
|
383
|
48
|
384 #if GTK_MAJOR_VERSION > 1
|
1
|
385 static void
|
48
|
386 editbm_action (GtkWidget * widget, gint response, gpointer user_data)
|
1
|
387 {
|
48
|
388 switch (response)
|
1
|
389 {
|
48
|
390 case GTK_RESPONSE_OK:
|
|
391 bm_apply_changes (widget, NULL);
|
|
392 /* no break */
|
|
393 default:
|
|
394 bm_close_dialog (NULL, widget);
|
1
|
395 }
|
|
396 }
|
48
|
397 #endif
|
1
|
398
|
|
399
|
|
400 static void
|
19
|
401 do_make_new (gpointer data, gftp_dialog_data * ddata)
|
1
|
402 {
|
|
403 GdkPixmap * closedir_pixmap, * opendir_pixmap;
|
|
404 GdkBitmap * closedir_bitmap, * opendir_bitmap;
|
129
|
405 gftp_bookmarks_var * tempentry, * newentry;
|
1
|
406 GtkCTreeNode * sibling;
|
|
407 char *pos, *text[2];
|
|
408 const char *str;
|
45
|
409 #if GTK_MAJOR_VERSION > 1
|
|
410 gsize bread, bwrite;
|
|
411 #endif
|
1
|
412
|
|
413 gftp_get_pixmap (tree, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap);
|
|
414 gftp_get_pixmap (tree, "dir.xpm", &closedir_pixmap, &closedir_bitmap);
|
|
415
|
19
|
416 str = gtk_entry_get_text (GTK_ENTRY (ddata->edit));
|
1
|
417
|
|
418 newentry = g_malloc0 (sizeof (*newentry));
|
45
|
419 #if GTK_MAJOR_VERSION == 1
|
|
420 newentry->path = g_strdup (str);
|
|
421
|
1
|
422 while ((pos = strchr (str, '/')) != NULL)
|
|
423 *pos++ = ' ';
|
45
|
424 #else
|
|
425 if (g_utf8_validate (str, -1, NULL))
|
|
426 newentry->path = g_strdup (str);
|
|
427 else
|
|
428 newentry->path = g_locale_to_utf8 (str, -1, &bread, &bwrite, NULL);
|
|
429
|
|
430 while ((pos = g_utf8_strchr (str, -1, '/')) != NULL)
|
|
431 *pos++ = ' ';
|
|
432 #endif
|
1
|
433
|
|
434 newentry->prev = new_bookmarks;
|
19
|
435 if (data)
|
1
|
436 newentry->isfolder = 1;
|
|
437
|
|
438 if (new_bookmarks->children == NULL)
|
|
439 {
|
|
440 new_bookmarks->children = newentry;
|
|
441 sibling = NULL;
|
|
442 }
|
|
443 else
|
|
444 {
|
|
445 tempentry = new_bookmarks->children;
|
|
446 while (tempentry->next != NULL)
|
|
447 tempentry = tempentry->next;
|
|
448 tempentry->next = newentry;
|
|
449 sibling = tempentry->cnode;
|
|
450 }
|
|
451
|
|
452 text[0] = text[1] = newentry->path;
|
|
453
|
|
454 if (newentry->isfolder)
|
|
455 newentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree),
|
|
456 new_bookmarks->cnode, NULL,
|
|
457 text, 5, closedir_pixmap,
|
|
458 closedir_bitmap, opendir_pixmap,
|
|
459 opendir_bitmap, FALSE, FALSE);
|
|
460 else
|
|
461 newentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree),
|
|
462 new_bookmarks->cnode, NULL,
|
|
463 text, 5, NULL, NULL, NULL, NULL,
|
|
464 FALSE, FALSE);
|
|
465
|
|
466 gtk_ctree_node_set_row_data (GTK_CTREE (tree), newentry->cnode, newentry);
|
|
467 g_hash_table_insert (new_bookmarks_htable, newentry->path, newentry);
|
|
468 }
|
|
469
|
|
470
|
48
|
471 static void
|
|
472 new_folder_entry (gpointer data)
|
|
473 {
|
|
474 MakeEditDialog (_("New Folder"),
|
|
475 _("Enter the name of the new folder to create"), NULL, 1,
|
|
476 NULL, gftp_dialog_button_create,
|
|
477 do_make_new, (gpointer) 0x1, NULL, NULL);
|
|
478 }
|
|
479
|
|
480
|
|
481 static void
|
|
482 new_item_entry (gpointer data)
|
|
483 {
|
|
484 MakeEditDialog (_("New Folder"),
|
|
485 _("Enter the name of the new item to create"), NULL, 1,
|
|
486 NULL, gftp_dialog_button_create,
|
|
487 do_make_new, NULL, NULL, NULL);
|
|
488 }
|
|
489
|
|
490
|
|
491 static void
|
129
|
492 do_delete_entry (gftp_bookmarks_var * entry, gftp_dialog_data * ddata)
|
48
|
493 {
|
129
|
494 gftp_bookmarks_var * tempentry, * delentry;
|
48
|
495
|
|
496 g_hash_table_remove (new_bookmarks_htable, entry->path);
|
|
497 gtk_ctree_remove_node (GTK_CTREE (tree), entry->cnode);
|
|
498 if (entry->prev->children == entry)
|
|
499 entry->prev->children = entry->prev->children->next;
|
|
500 else
|
|
501 {
|
|
502 tempentry = entry->prev->children;
|
|
503 while (tempentry->next != entry)
|
|
504 tempentry = tempentry->next;
|
|
505 tempentry->next = entry->next;
|
|
506 }
|
|
507
|
|
508 entry->prev = NULL;
|
|
509 entry->next = NULL;
|
|
510 tempentry = entry;
|
|
511 while (tempentry != NULL)
|
|
512 {
|
199
|
513 gftp_free_bookmark (tempentry);
|
48
|
514
|
|
515 if (tempentry->children != NULL)
|
|
516 {
|
|
517 tempentry = tempentry->children;
|
|
518 continue;
|
|
519 }
|
|
520 else if (tempentry->next == NULL && tempentry->prev != NULL)
|
|
521 {
|
|
522 delentry = tempentry->prev;
|
|
523 g_free (tempentry);
|
|
524 tempentry = delentry->next;
|
|
525 if (delentry != entry)
|
|
526 g_free (delentry);
|
|
527 }
|
|
528 else
|
|
529 tempentry = tempentry->next;
|
|
530 }
|
|
531 g_free (entry);
|
|
532 }
|
|
533
|
|
534
|
|
535 static void
|
|
536 delete_entry (gpointer data)
|
|
537 {
|
129
|
538 gftp_bookmarks_var * entry;
|
48
|
539 char *tempstr, *pos;
|
|
540
|
|
541 if (GTK_CLIST (tree)->selection == NULL)
|
|
542 return;
|
|
543 entry =
|
|
544 gtk_ctree_node_get_row_data (GTK_CTREE (tree),
|
|
545 GTK_CLIST (tree)->selection->data);
|
|
546 if (entry == NULL || entry->prev == NULL)
|
|
547 return;
|
|
548
|
|
549 if (!entry->isfolder)
|
|
550 do_delete_entry (entry, NULL);
|
|
551 else
|
|
552 {
|
|
553 if ((pos = strrchr (entry->path, '/')) == NULL)
|
|
554 pos = entry->path;
|
|
555 else
|
|
556 pos++;
|
|
557
|
|
558 tempstr = g_strdup_printf (_("Are you sure you want to erase the bookmark\n%s and all it's children?"), pos);
|
|
559 MakeYesNoDialog (_("Delete Bookmark"), tempstr, do_delete_entry, entry,
|
|
560 NULL, NULL);
|
|
561 g_free (tempstr);
|
|
562 }
|
|
563 }
|
|
564
|
|
565
|
|
566 static void
|
|
567 set_userpass_visible (GtkWidget * checkbutton, GtkWidget * entry)
|
|
568 {
|
|
569 gtk_widget_set_sensitive (bm_useredit, !GTK_TOGGLE_BUTTON (anon_chk)->active);
|
|
570 gtk_widget_set_sensitive (bm_passedit, !GTK_TOGGLE_BUTTON (anon_chk)->active);
|
|
571 gtk_widget_set_sensitive (bm_acctedit, !GTK_TOGGLE_BUTTON (anon_chk)->active);
|
|
572 }
|
|
573
|
|
574
|
|
575 static void
|
|
576 build_bookmarks_tree (void)
|
|
577 {
|
|
578 GdkPixmap * closedir_pixmap, * opendir_pixmap;
|
|
579 GdkBitmap * closedir_bitmap, * opendir_bitmap;
|
129
|
580 gftp_bookmarks_var * tempentry, * preventry;
|
48
|
581 char *pos, *prevpos, *text[2], *str;
|
|
582 GtkCTreeNode * parent;
|
|
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 text[0] = text[1] = _("Bookmarks");
|
|
587 parent = gtk_ctree_insert_node (GTK_CTREE (tree), NULL, NULL, text, 5,
|
|
588 closedir_pixmap, closedir_bitmap,
|
|
589 opendir_pixmap, opendir_bitmap, FALSE, TRUE);
|
|
590 gtk_ctree_node_set_row_data (GTK_CTREE (tree), parent, new_bookmarks);
|
|
591 new_bookmarks->cnode = parent;
|
|
592
|
|
593 tempentry = new_bookmarks->children;
|
|
594 while (tempentry != NULL)
|
|
595 {
|
|
596 tempentry->cnode = NULL;
|
|
597 if (tempentry->children != NULL)
|
|
598 {
|
|
599 tempentry = tempentry->children;
|
|
600 continue;
|
|
601 }
|
|
602 else
|
|
603 {
|
|
604 pos = tempentry->path;
|
|
605 while ((pos = strchr (pos, '/')) != NULL)
|
|
606 {
|
|
607 *pos = '\0';
|
129
|
608 str = g_strdup (tempentry->path);
|
48
|
609 *pos = '/';
|
|
610 preventry = g_hash_table_lookup (new_bookmarks_htable, str);
|
|
611 if (preventry->cnode == NULL)
|
|
612 {
|
|
613 if ((prevpos = strrchr (str, '/')) == NULL)
|
|
614 prevpos = str;
|
|
615 else
|
|
616 prevpos++;
|
|
617 text[0] = text[1] = prevpos;
|
|
618 preventry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree),
|
|
619 preventry->prev->cnode, NULL, text,
|
|
620 5, closedir_pixmap, closedir_bitmap,
|
|
621 opendir_pixmap, opendir_bitmap,
|
|
622 FALSE, FALSE);
|
|
623 gtk_ctree_node_set_row_data (GTK_CTREE (tree),
|
|
624 preventry->cnode, preventry);
|
|
625 }
|
|
626
|
|
627 g_free (str);
|
|
628 pos++;
|
|
629 }
|
|
630 }
|
|
631
|
|
632 if ((pos = strrchr (tempentry->path, '/')) == NULL)
|
|
633 pos = tempentry->path;
|
|
634 else
|
|
635 pos++;
|
|
636
|
|
637 text[0] = text[1] = pos;
|
|
638 tempentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree),
|
|
639 tempentry->prev->cnode, NULL,
|
|
640 text, 5, NULL, NULL, NULL, NULL, FALSE, FALSE);
|
|
641 gtk_ctree_node_set_row_data (GTK_CTREE (tree), tempentry->cnode,
|
|
642 tempentry);
|
|
643
|
|
644 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
645 tempentry = tempentry->prev;
|
|
646 tempentry = tempentry->next;
|
|
647 }
|
|
648 }
|
|
649
|
|
650
|
|
651 static void
|
|
652 clear_bookmarks_tree (void)
|
|
653 {
|
129
|
654 gftp_bookmarks_var * tempentry;
|
48
|
655
|
|
656 tempentry = new_bookmarks->children;
|
|
657 while (tempentry != NULL)
|
|
658 {
|
|
659 if (tempentry->children != NULL)
|
|
660 {
|
|
661 tempentry = tempentry->children;
|
|
662 continue;
|
|
663 }
|
|
664 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
665 {
|
|
666 gtk_ctree_remove_node (GTK_CTREE (tree), tempentry->cnode);
|
|
667 tempentry->cnode = NULL;
|
|
668 tempentry = tempentry->prev;
|
|
669 }
|
|
670 gtk_ctree_remove_node (GTK_CTREE (tree), tempentry->cnode);
|
|
671 tempentry->cnode = NULL;
|
|
672 tempentry = tempentry->next;
|
|
673 }
|
|
674 }
|
|
675
|
|
676
|
|
677 static void
|
129
|
678 entry_apply_changes (GtkWidget * widget, gftp_bookmarks_var * entry)
|
48
|
679 {
|
|
680 char *pos, *newpath, tempchar, *tempstr, *origpath;
|
129
|
681 gftp_bookmarks_var * tempentry, * nextentry;
|
48
|
682 GtkWidget * tempwid;
|
|
683 const char *str;
|
|
684 int oldpathlen;
|
|
685
|
|
686 oldpathlen = strlen (entry->path);
|
|
687 if ((pos = strrchr (entry->path, '/')) == NULL)
|
|
688 {
|
|
689 pos = entry->path;
|
|
690 tempchar = *entry->path;
|
|
691 *entry->path = '\0';
|
|
692 }
|
|
693 else
|
|
694 {
|
|
695 tempchar = *pos;
|
|
696 *pos = '\0';
|
|
697 }
|
303
|
698
|
|
699 origpath = newpath = gftp_build_path (entry->path, gtk_entry_get_text (GTK_ENTRY (bm_pathedit)), NULL);
|
48
|
700 *pos = tempchar;
|
|
701
|
|
702 str = gtk_entry_get_text (GTK_ENTRY (bm_hostedit));
|
|
703 if (entry->hostname)
|
|
704 g_free (entry->hostname);
|
129
|
705 entry->hostname = g_strdup (str);
|
48
|
706
|
|
707 str = gtk_entry_get_text (GTK_ENTRY (bm_portedit));
|
|
708 entry->port = strtol (str, NULL, 10);
|
|
709
|
|
710 tempwid = gtk_menu_get_active (GTK_MENU (bm_protocol));
|
|
711 str = gtk_object_get_user_data (GTK_OBJECT (tempwid));
|
|
712 if (entry->protocol)
|
|
713 g_free (entry->protocol);
|
129
|
714 entry->protocol = g_strdup (str);
|
48
|
715
|
|
716 str = gtk_entry_get_text (GTK_ENTRY (bm_remotediredit));
|
|
717 if (entry->remote_dir)
|
|
718 g_free (entry->remote_dir);
|
129
|
719 entry->remote_dir = g_strdup (str);
|
48
|
720
|
|
721 str = gtk_entry_get_text (GTK_ENTRY (bm_localdiredit));
|
|
722 if (entry->local_dir)
|
|
723 g_free (entry->local_dir);
|
129
|
724 entry->local_dir = g_strdup (str);
|
48
|
725
|
|
726 if (GTK_TOGGLE_BUTTON (anon_chk)->active)
|
|
727 str = "anonymous";
|
|
728 else
|
|
729 str = gtk_entry_get_text (GTK_ENTRY (bm_useredit));
|
|
730 if (entry->user)
|
|
731 g_free (entry->user);
|
129
|
732 entry->user = g_strdup (str);
|
48
|
733
|
|
734 if (GTK_TOGGLE_BUTTON (anon_chk)->active)
|
|
735 str = "@EMAIL@";
|
|
736 else
|
|
737 str = gtk_entry_get_text (GTK_ENTRY (bm_passedit));
|
|
738 if (entry->pass)
|
|
739 g_free (entry->pass);
|
129
|
740 entry->pass = g_strdup (str);
|
48
|
741 entry->save_password = *entry->pass != '\0';
|
|
742
|
|
743 if (GTK_TOGGLE_BUTTON (anon_chk)->active)
|
|
744 str = "";
|
|
745 else
|
|
746 str = gtk_entry_get_text (GTK_ENTRY (bm_acctedit));
|
|
747 if (entry->acct)
|
|
748 g_free (entry->acct);
|
129
|
749 entry->acct = g_strdup (str);
|
48
|
750
|
229
|
751 gftp_gtk_save_bookmark_options (entry);
|
|
752
|
48
|
753 if (strcmp (entry->path, newpath) != 0)
|
|
754 {
|
|
755 tempentry = entry;
|
|
756 nextentry = entry->next;
|
|
757 entry->next = NULL;
|
|
758 while (tempentry != NULL)
|
|
759 {
|
|
760 g_hash_table_remove (new_bookmarks_htable, tempentry->path);
|
422
|
761
|
|
762 if (tempentry->path + oldpathlen == '\0')
|
|
763 tempstr = g_strdup (newpath);
|
|
764 else
|
|
765 tempstr = gftp_build_path (newpath, tempentry->path + oldpathlen, NULL);
|
|
766
|
48
|
767 g_free (tempentry->path);
|
|
768 tempentry->path = tempstr;
|
|
769 g_hash_table_insert (new_bookmarks_htable, tempentry->path,
|
|
770 tempentry);
|
|
771 if (tempentry->children != NULL)
|
|
772 {
|
|
773 tempentry = tempentry->children;
|
|
774 continue;
|
|
775 }
|
|
776 while (tempentry->next == NULL && tempentry != entry &&
|
|
777 tempentry->prev != NULL)
|
|
778 tempentry = tempentry->prev;
|
|
779
|
|
780 tempentry = tempentry->next;
|
|
781 }
|
|
782 entry->next = nextentry;
|
|
783 clear_bookmarks_tree ();
|
|
784 build_bookmarks_tree ();
|
|
785 }
|
|
786
|
|
787 g_free (origpath);
|
|
788 }
|
|
789
|
|
790
|
422
|
791 #if GTK_MAJOR_VERSION == 1
|
|
792
|
|
793 static void
|
|
794 entry_close_dialog (void * data)
|
|
795 {
|
|
796 gtk_widget_destroy (bm_dialog);
|
|
797 bm_dialog = NULL;
|
|
798 }
|
|
799
|
|
800
|
|
801 #else
|
|
802
|
19
|
803 static void
|
|
804 bmedit_action (GtkWidget * widget, gint response, gpointer user_data)
|
|
805 {
|
|
806 switch (response)
|
|
807 {
|
|
808 case GTK_RESPONSE_APPLY:
|
|
809 entry_apply_changes (widget, user_data);
|
|
810 break;
|
|
811 case GTK_RESPONSE_OK:
|
|
812 entry_apply_changes (widget, user_data);
|
|
813 /* no break */
|
|
814 default:
|
|
815 gtk_widget_destroy (widget);
|
422
|
816 bm_dialog = NULL;
|
19
|
817 }
|
|
818 }
|
|
819 #endif
|
|
820
|
|
821
|
1
|
822 static void
|
|
823 edit_entry (gpointer data)
|
|
824 {
|
422
|
825 GtkWidget * table, * tempwid, * menu, * notebook;
|
129
|
826 gftp_bookmarks_var * entry;
|
1
|
827 int i, num;
|
|
828 char *pos;
|
|
829
|
422
|
830 if (bm_dialog != NULL)
|
|
831 {
|
|
832 gtk_widget_grab_focus (bm_dialog);
|
|
833 return;
|
|
834 }
|
|
835
|
1
|
836 if (GTK_CLIST (tree)->selection == NULL)
|
|
837 return;
|
|
838
|
|
839 entry = gtk_ctree_node_get_row_data (GTK_CTREE (tree),
|
|
840 GTK_CLIST (tree)->selection->data);
|
|
841
|
|
842 if (entry == NULL || entry == new_bookmarks)
|
|
843 return;
|
|
844
|
45
|
845 #if GTK_MAJOR_VERSION == 1
|
422
|
846 bm_dialog = gtk_dialog_new ();
|
|
847 gtk_window_set_title (GTK_WINDOW (bm_dialog), _("Edit Entry"));
|
|
848 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (bm_dialog)->action_area), 15);
|
19
|
849 #else
|
422
|
850 bm_dialog = gtk_dialog_new_with_buttons (_("Edit Entry"), NULL, 0,
|
|
851 GTK_STOCK_SAVE,
|
|
852 GTK_RESPONSE_OK,
|
|
853 GTK_STOCK_CANCEL,
|
|
854 GTK_RESPONSE_CANCEL,
|
|
855 GTK_STOCK_APPLY,
|
|
856 GTK_RESPONSE_APPLY,
|
|
857 NULL);
|
19
|
858 #endif
|
422
|
859 gtk_window_set_wmclass (GTK_WINDOW (bm_dialog), "Edit Bookmark Entry",
|
|
860 "gFTP");
|
|
861 gtk_window_set_position (GTK_WINDOW (bm_dialog), GTK_WIN_POS_MOUSE);
|
|
862 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (bm_dialog)->vbox), 10);
|
|
863 gtk_widget_realize (bm_dialog);
|
19
|
864
|
|
865 if (gftp_icon != NULL)
|
|
866 {
|
422
|
867 gdk_window_set_icon (bm_dialog->window, NULL, gftp_icon->pixmap,
|
19
|
868 gftp_icon->bitmap);
|
422
|
869 gdk_window_set_icon_name (bm_dialog->window, gftp_version);
|
19
|
870 }
|
1
|
871
|
227
|
872 notebook = gtk_notebook_new ();
|
422
|
873 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (bm_dialog)->vbox), notebook, TRUE,
|
1
|
874 TRUE, 0);
|
227
|
875 gtk_widget_show (notebook);
|
1
|
876
|
|
877 table = gtk_table_new (11, 2, FALSE);
|
|
878 gtk_container_border_width (GTK_CONTAINER (table), 5);
|
|
879 gtk_table_set_row_spacings (GTK_TABLE (table), 5);
|
|
880 gtk_table_set_col_spacings (GTK_TABLE (table), 5);
|
|
881 gtk_widget_show (table);
|
|
882
|
227
|
883 tempwid = gtk_label_new (_("Bookmark"));
|
|
884 gtk_widget_show (tempwid);
|
|
885
|
|
886 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), table, tempwid);
|
|
887
|
1
|
888 tempwid = gtk_label_new (_("Description:"));
|
|
889 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
890 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 0, 1);
|
|
891 gtk_widget_show (tempwid);
|
|
892
|
|
893 bm_pathedit = gtk_entry_new ();
|
|
894 gtk_table_attach_defaults (GTK_TABLE (table), bm_pathedit, 1, 2, 0, 1);
|
|
895 if ((pos = strrchr (entry->path, '/')) == NULL)
|
|
896 pos = entry->path;
|
|
897 else
|
|
898 pos++;
|
|
899 if (pos)
|
|
900 gtk_entry_set_text (GTK_ENTRY (bm_pathedit), pos);
|
|
901 gtk_widget_show (bm_pathedit);
|
|
902
|
|
903 tempwid = gtk_label_new (_("Hostname:"));
|
|
904 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
905 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 1, 2);
|
|
906 gtk_widget_show (tempwid);
|
|
907
|
|
908 bm_hostedit = gtk_entry_new ();
|
|
909 gtk_table_attach_defaults (GTK_TABLE (table), bm_hostedit, 1, 2, 1, 2);
|
|
910 if (entry->isfolder)
|
|
911 gtk_widget_set_sensitive (bm_hostedit, 0);
|
|
912 else if (entry->hostname)
|
|
913 gtk_entry_set_text (GTK_ENTRY (bm_hostedit), entry->hostname);
|
|
914 gtk_widget_show (bm_hostedit);
|
|
915
|
|
916 tempwid = gtk_label_new (_("Port:"));
|
|
917 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
918 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 2, 3);
|
|
919 gtk_widget_show (tempwid);
|
|
920
|
|
921 bm_portedit = gtk_entry_new ();
|
|
922 gtk_table_attach_defaults (GTK_TABLE (table), bm_portedit, 1, 2, 2, 3);
|
|
923 if (entry->isfolder)
|
|
924 gtk_widget_set_sensitive (bm_portedit, 0);
|
|
925 else if (entry->port)
|
|
926 {
|
|
927 pos = g_strdup_printf ("%d", entry->port);
|
|
928 gtk_entry_set_text (GTK_ENTRY (bm_portedit), pos);
|
|
929 g_free (pos);
|
|
930 }
|
|
931 gtk_widget_show (bm_portedit);
|
|
932
|
|
933 tempwid = gtk_label_new (_("Protocol:"));
|
|
934 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
935 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 3, 4);
|
|
936 gtk_widget_show (tempwid);
|
|
937
|
|
938 menu = gtk_option_menu_new ();
|
|
939 gtk_table_attach_defaults (GTK_TABLE (table), menu, 1, 2, 3, 4);
|
|
940 gtk_widget_show (menu);
|
|
941
|
|
942 num = 0;
|
|
943 bm_protocol = gtk_menu_new ();
|
|
944 for (i = 0; gftp_protocols[i].name; i++)
|
|
945 {
|
|
946 tempwid = gtk_menu_item_new_with_label (gftp_protocols[i].name);
|
|
947 gtk_object_set_user_data (GTK_OBJECT (tempwid), gftp_protocols[i].name);
|
|
948 gtk_menu_append (GTK_MENU (bm_protocol), tempwid);
|
|
949 gtk_widget_show (tempwid);
|
|
950 if (entry->protocol &&
|
|
951 strcmp (gftp_protocols[i].name, entry->protocol) == 0)
|
|
952 num = i;
|
|
953 }
|
|
954 gtk_option_menu_set_menu (GTK_OPTION_MENU (menu), bm_protocol);
|
|
955 gtk_option_menu_set_history (GTK_OPTION_MENU (menu), num);
|
|
956
|
|
957 tempwid = gtk_label_new (_("Remote Directory:"));
|
|
958 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
959 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 4, 5);
|
|
960 gtk_widget_show (tempwid);
|
|
961
|
|
962 bm_remotediredit = gtk_entry_new ();
|
|
963 gtk_table_attach_defaults (GTK_TABLE (table), bm_remotediredit, 1, 2, 4, 5);
|
|
964 if (entry->isfolder)
|
|
965 gtk_widget_set_sensitive (bm_remotediredit, 0);
|
|
966 else if (entry->remote_dir)
|
|
967 gtk_entry_set_text (GTK_ENTRY (bm_remotediredit), entry->remote_dir);
|
|
968 gtk_widget_show (bm_remotediredit);
|
|
969
|
|
970 tempwid = gtk_label_new (_("Local Directory:"));
|
|
971 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
972 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 5, 6);
|
|
973 gtk_widget_show (tempwid);
|
|
974
|
|
975 bm_localdiredit = gtk_entry_new ();
|
|
976 gtk_table_attach_defaults (GTK_TABLE (table), bm_localdiredit, 1, 2, 5, 6);
|
|
977 if (entry->isfolder)
|
|
978 gtk_widget_set_sensitive (bm_localdiredit, 0);
|
|
979 else if (entry->local_dir)
|
|
980 gtk_entry_set_text (GTK_ENTRY (bm_localdiredit), entry->local_dir);
|
|
981 gtk_widget_show (bm_localdiredit);
|
|
982
|
|
983 tempwid = gtk_hseparator_new ();
|
|
984 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 2, 7, 8);
|
|
985 gtk_widget_show (tempwid);
|
|
986
|
|
987 tempwid = gtk_label_new (_("Username:"));
|
|
988 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
989 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 8, 9);
|
|
990 gtk_widget_show (tempwid);
|
|
991
|
|
992 bm_useredit = gtk_entry_new ();
|
|
993 gtk_table_attach_defaults (GTK_TABLE (table), bm_useredit, 1, 2, 8, 9);
|
|
994 if (entry->isfolder)
|
|
995 gtk_widget_set_sensitive (bm_useredit, 0);
|
|
996 else if (entry->user)
|
|
997 gtk_entry_set_text (GTK_ENTRY (bm_useredit), entry->user);
|
|
998 gtk_widget_show (bm_useredit);
|
|
999
|
|
1000 tempwid = gtk_label_new (_("Password:"));
|
|
1001 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
1002 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 9, 10);
|
|
1003 gtk_widget_show (tempwid);
|
|
1004
|
|
1005 bm_passedit = gtk_entry_new ();
|
|
1006 gtk_table_attach_defaults (GTK_TABLE (table), bm_passedit, 1, 2, 9, 10);
|
|
1007 gtk_entry_set_visibility (GTK_ENTRY (bm_passedit), FALSE);
|
|
1008 if (entry->isfolder)
|
|
1009 gtk_widget_set_sensitive (bm_passedit, 0);
|
|
1010 else if (entry->pass)
|
|
1011 gtk_entry_set_text (GTK_ENTRY (bm_passedit), entry->pass);
|
|
1012 gtk_widget_show (bm_passedit);
|
|
1013
|
|
1014 tempwid = gtk_label_new (_("Account:"));
|
|
1015 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5);
|
|
1016 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 10, 11);
|
|
1017 gtk_widget_show (tempwid);
|
|
1018
|
|
1019 bm_acctedit = gtk_entry_new ();
|
|
1020 gtk_table_attach_defaults (GTK_TABLE (table), bm_acctedit, 1, 2, 10, 11);
|
|
1021 gtk_entry_set_visibility (GTK_ENTRY (bm_acctedit), FALSE);
|
|
1022 if (entry->isfolder)
|
|
1023 gtk_widget_set_sensitive (bm_acctedit, 0);
|
|
1024 else if (entry->acct)
|
|
1025 gtk_entry_set_text (GTK_ENTRY (bm_acctedit), entry->acct);
|
|
1026 gtk_widget_show (bm_acctedit);
|
|
1027
|
|
1028 anon_chk = gtk_check_button_new_with_label (_("Log in as ANONYMOUS"));
|
|
1029 gtk_table_attach_defaults (GTK_TABLE (table), anon_chk, 0, 2, 11, 12);
|
|
1030 if (entry->isfolder)
|
|
1031 gtk_widget_set_sensitive (anon_chk, 0);
|
|
1032 else
|
|
1033 {
|
|
1034 gtk_signal_connect (GTK_OBJECT (anon_chk), "toggled",
|
|
1035 GTK_SIGNAL_FUNC (set_userpass_visible), NULL);
|
|
1036 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (anon_chk), entry->user
|
|
1037 && strcmp (entry->user, "anonymous") == 0);
|
|
1038 }
|
|
1039 gtk_widget_show (anon_chk);
|
|
1040
|
45
|
1041 #if GTK_MAJOR_VERSION == 1
|
1
|
1042 tempwid = gtk_button_new_with_label (_("OK"));
|
422
|
1043 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (bm_dialog)->action_area), tempwid,
|
1
|
1044 TRUE, TRUE, 0);
|
|
1045 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
1046 GTK_SIGNAL_FUNC (entry_apply_changes),
|
|
1047 (gpointer) entry);
|
|
1048 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
422
|
1049 GTK_SIGNAL_FUNC (entry_close_dialog), NULL);
|
1
|
1050 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
1051 gtk_widget_show (tempwid);
|
|
1052
|
|
1053 tempwid = gtk_button_new_with_label (_(" Cancel "));
|
422
|
1054 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (bm_dialog)->action_area), tempwid,
|
1
|
1055 TRUE, TRUE, 0);
|
|
1056 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
1057 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
422
|
1058 GTK_OBJECT (bm_dialog));
|
1
|
1059 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
1060 gtk_widget_grab_focus (tempwid);
|
|
1061 gtk_widget_show (tempwid);
|
|
1062
|
|
1063 tempwid = gtk_button_new_with_label (_("Apply"));
|
422
|
1064 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (bm_dialog)->action_area), tempwid,
|
1
|
1065 TRUE, TRUE, 0);
|
|
1066 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
1067 GTK_SIGNAL_FUNC (entry_apply_changes),
|
|
1068 (gpointer) entry);
|
|
1069 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
1070 gtk_widget_show (tempwid);
|
19
|
1071 #else
|
422
|
1072 g_signal_connect (GTK_OBJECT (bm_dialog), "response",
|
19
|
1073 G_CALLBACK (bmedit_action), (gpointer) entry);
|
|
1074 #endif
|
1
|
1075
|
229
|
1076 gftp_gtk_setup_bookmark_options (notebook, entry);
|
227
|
1077
|
422
|
1078 gtk_widget_show (bm_dialog);
|
1
|
1079 }
|
|
1080
|
|
1081
|
48
|
1082 static gint
|
|
1083 bm_enter (GtkWidget * widget, GdkEventKey * event, gpointer data)
|
1
|
1084 {
|
48
|
1085 if (event->type == GDK_KEY_PRESS)
|
1
|
1086 {
|
48
|
1087 if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter)
|
|
1088 {
|
|
1089 edit_entry (NULL);
|
|
1090 return (FALSE);
|
|
1091 }
|
|
1092 else if (event->keyval == GDK_KP_Delete || event->keyval == GDK_Delete)
|
|
1093 {
|
|
1094 delete_entry (NULL);
|
|
1095 return (FALSE);
|
|
1096 }
|
1
|
1097 }
|
48
|
1098 return (TRUE);
|
1
|
1099 }
|
|
1100
|
|
1101
|
366
|
1102 static inline gboolean
|
|
1103 move_possible (GtkCTree *ctree, GtkCTreeNode *child, GtkCTreeNode *parent,
|
|
1104 GtkCTreeNode *sibling)
|
|
1105 {
|
|
1106 return (parent != NULL && sibling != NULL);
|
|
1107 }
|
|
1108
|
|
1109
|
1
|
1110 static void
|
48
|
1111 after_move (GtkCTree * ctree, GtkCTreeNode * child, GtkCTreeNode * parent,
|
|
1112 GtkCTreeNode * sibling, gpointer data)
|
1
|
1113 {
|
48
|
1114
|
129
|
1115 gftp_bookmarks_var * childentry, * siblingentry, * parententry, * tempentry;
|
48
|
1116 char *tempstr, *pos, *stpos;
|
|
1117
|
|
1118 childentry = gtk_ctree_node_get_row_data (ctree, child);
|
|
1119 parententry = gtk_ctree_node_get_row_data (ctree, parent);
|
|
1120 siblingentry = gtk_ctree_node_get_row_data (ctree, sibling);
|
1
|
1121
|
48
|
1122 tempentry = childentry->prev->children;
|
|
1123 if (tempentry == childentry)
|
|
1124 childentry->prev->children = childentry->prev->children->next;
|
|
1125 else
|
1
|
1126 {
|
48
|
1127 while (tempentry->next != childentry)
|
|
1128 tempentry = tempentry->next;
|
|
1129 tempentry->next = childentry->next;
|
|
1130 }
|
|
1131 childentry->prev = parententry;
|
|
1132 if (!parententry->isfolder)
|
|
1133 {
|
|
1134 childentry->next = parententry->children;
|
|
1135 parententry->children = childentry;
|
|
1136 gtk_ctree_move (ctree, child, parententry->prev->cnode,
|
|
1137 parententry->cnode);
|
1
|
1138 }
|
|
1139 else
|
|
1140 {
|
48
|
1141 if (siblingentry == NULL || parententry->children == siblingentry)
|
|
1142 {
|
|
1143 childentry->next = parententry->children;
|
|
1144 parententry->children = childentry;
|
|
1145 }
|
|
1146 else
|
|
1147 {
|
|
1148 tempentry = parententry->children;
|
|
1149 while (tempentry->next != siblingentry)
|
|
1150 tempentry = tempentry->next;
|
|
1151 childentry->next = tempentry->next;
|
|
1152 tempentry->next = childentry;
|
|
1153 }
|
1
|
1154
|
48
|
1155 tempentry = childentry;
|
1
|
1156 while (tempentry != NULL)
|
|
1157 {
|
|
1158 g_hash_table_remove (new_bookmarks_htable, tempentry->path);
|
48
|
1159 if ((pos = strrchr (tempentry->path, '/')) == NULL)
|
|
1160 pos = tempentry->path;
|
|
1161 else
|
|
1162 pos++;
|
|
1163 tempstr = g_strdup_printf ("%s/%s", tempentry->prev->path, pos);
|
|
1164 for (stpos = tempstr; *stpos == '/'; stpos++);
|
1
|
1165 g_free (tempentry->path);
|
129
|
1166 tempentry->path = g_strdup (stpos);
|
48
|
1167 g_free (tempstr);
|
1
|
1168 g_hash_table_insert (new_bookmarks_htable, tempentry->path,
|
|
1169 tempentry);
|
|
1170 if (tempentry->children != NULL)
|
48
|
1171 tempentry = tempentry->children;
|
|
1172 else
|
1
|
1173 {
|
48
|
1174 if (tempentry->next == NULL)
|
1
|
1175 {
|
48
|
1176 if (tempentry->prev == childentry)
|
|
1177 break;
|
1
|
1178 else
|
48
|
1179 {
|
|
1180 while (tempentry->next == NULL
|
|
1181 && tempentry->prev != NULL)
|
|
1182 tempentry = tempentry->prev;
|
|
1183 }
|
1
|
1184 }
|
48
|
1185 tempentry = tempentry->next;
|
1
|
1186 }
|
|
1187 }
|
|
1188 }
|
|
1189 }
|
|
1190
|
|
1191
|
48
|
1192 static gint
|
|
1193 bm_dblclick (GtkWidget * widget, GdkEventButton * event, gpointer data)
|
1
|
1194 {
|
48
|
1195 if (event->button == 3)
|
|
1196 gtk_item_factory_popup (edit_factory, (guint) event->x_root,
|
|
1197 (guint) event->y_root, 1, 0);
|
|
1198 else if (event->type == GDK_2BUTTON_PRESS)
|
1
|
1199 {
|
48
|
1200 edit_entry (NULL);
|
|
1201 return (FALSE);
|
1
|
1202 }
|
48
|
1203 return (TRUE);
|
1
|
1204 }
|
|
1205
|
48
|
1206
|
|
1207 void
|
|
1208 edit_bookmarks (gpointer data)
|
|
1209 {
|
|
1210 GtkItemFactory * ifactory;
|
452
|
1211 GtkWidget * scroll;
|
48
|
1212 GtkItemFactoryEntry menu_items[] = {
|
|
1213 {N_("/_File"), NULL, 0, 0, "<Branch>"},
|
|
1214 {N_("/File/tearoff"), NULL, 0, 0, "<Tearoff>"},
|
|
1215 {N_("/File/New Folder..."), NULL, new_folder_entry, 0, MN_(NULL)},
|
|
1216 {N_("/File/New Item..."), NULL, new_item_entry, 0, MS_(GTK_STOCK_NEW)},
|
|
1217 {N_("/File/Delete"), NULL, delete_entry, 0, MS_(GTK_STOCK_DELETE)},
|
|
1218 {N_("/File/Properties..."), NULL, edit_entry, 0, MS_(GTK_STOCK_PROPERTIES)},
|
|
1219 {N_("/File/sep"), NULL, 0, 0, "<Separator>"},
|
|
1220 {N_("/File/Close"), NULL, gtk_widget_destroy, 0, MS_(GTK_STOCK_CLOSE)}
|
|
1221 };
|
|
1222 #if GTK_MAJOR_VERSION == 1
|
|
1223 GtkWidget * tempwid;
|
|
1224 #endif
|
|
1225
|
452
|
1226 if (edit_bookmarks_dialog != NULL)
|
|
1227 {
|
|
1228 gtk_widget_grab_focus (edit_bookmarks_dialog);
|
|
1229 return;
|
|
1230 }
|
|
1231
|
129
|
1232 new_bookmarks = copy_bookmarks (gftp_bookmarks);
|
48
|
1233 new_bookmarks_htable = build_bookmarks_hash_table (new_bookmarks);
|
|
1234
|
|
1235 #if GTK_MAJOR_VERSION == 1
|
452
|
1236 edit_bookmarks_dialog = gtk_dialog_new ();
|
|
1237 gtk_window_set_title (GTK_WINDOW (edit_bookmarks_dialog),
|
|
1238 _("Edit Bookmarks"));
|
|
1239 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (edit_bookmarks_dialog)->action_area), 15);
|
48
|
1240 #else
|
452
|
1241 edit_bookmarks_dialog = gtk_dialog_new_with_buttons (_("Edit Bookmarks"),
|
|
1242 NULL, 0, GTK_STOCK_SAVE,
|
|
1243 GTK_RESPONSE_OK,
|
|
1244 GTK_STOCK_CANCEL,
|
|
1245 GTK_RESPONSE_CANCEL,
|
|
1246 NULL);
|
48
|
1247 #endif
|
452
|
1248 gtk_window_set_wmclass (GTK_WINDOW(edit_bookmarks_dialog), "Edit Bookmarks",
|
|
1249 "gFTP");
|
|
1250 gtk_window_set_position (GTK_WINDOW (edit_bookmarks_dialog),
|
|
1251 GTK_WIN_POS_MOUSE);
|
|
1252 gtk_widget_realize (edit_bookmarks_dialog);
|
48
|
1253
|
|
1254 if (gftp_icon != NULL)
|
|
1255 {
|
452
|
1256 gdk_window_set_icon (edit_bookmarks_dialog->window, NULL,
|
|
1257 gftp_icon->pixmap, gftp_icon->bitmap);
|
|
1258 gdk_window_set_icon_name (edit_bookmarks_dialog->window, gftp_version);
|
48
|
1259 }
|
|
1260
|
|
1261 ifactory = item_factory_new (GTK_TYPE_MENU_BAR, "<bookmarks>", NULL, NULL);
|
|
1262 create_item_factory (ifactory, 7, menu_items, NULL);
|
452
|
1263 create_item_factory (ifactory, 1, menu_items + 7, edit_bookmarks_dialog);
|
|
1264 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (edit_bookmarks_dialog)->vbox),
|
|
1265 ifactory->widget, FALSE, FALSE, 0);
|
48
|
1266 gtk_widget_show (ifactory->widget);
|
|
1267
|
|
1268 scroll = gtk_scrolled_window_new (NULL, NULL);
|
|
1269 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
|
|
1270 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
1271 gtk_widget_set_size_request (scroll, 150, 200);
|
|
1272
|
452
|
1273 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (edit_bookmarks_dialog)->vbox),
|
|
1274 scroll, TRUE, TRUE, 0);
|
48
|
1275 gtk_container_border_width (GTK_CONTAINER (scroll), 3);
|
|
1276 gtk_widget_show (scroll);
|
|
1277
|
|
1278 edit_factory = item_factory_new (GTK_TYPE_MENU, "<edit_bookmark>", NULL, "/File");
|
|
1279
|
452
|
1280 create_item_factory (edit_factory, 6, menu_items + 2, edit_bookmarks_dialog);
|
48
|
1281
|
|
1282 tree = gtk_ctree_new (1, 0);
|
|
1283 gtk_clist_set_selection_mode (GTK_CLIST (tree), GTK_SELECTION_BROWSE);
|
|
1284 gtk_clist_set_reorderable (GTK_CLIST (tree), 1);
|
|
1285 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll), tree);
|
|
1286 gtk_signal_connect_after (GTK_OBJECT (tree), "key_press_event",
|
|
1287 GTK_SIGNAL_FUNC (bm_enter), (gpointer) tree);
|
|
1288 gtk_signal_connect_after (GTK_OBJECT (tree), "tree_move",
|
|
1289 GTK_SIGNAL_FUNC (after_move), NULL);
|
|
1290 gtk_signal_connect_after (GTK_OBJECT (tree), "button_press_event",
|
|
1291 GTK_SIGNAL_FUNC (bm_dblclick), (gpointer) tree);
|
366
|
1292 gtk_ctree_set_drag_compare_func (GTK_CTREE(tree), &move_possible);
|
48
|
1293 gtk_widget_show (tree);
|
|
1294
|
|
1295 #if GTK_MAJOR_VERSION == 1
|
|
1296 tempwid = gtk_button_new_with_label (_("OK"));
|
452
|
1297 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (edit_bookmarks_dialog)->action_area),
|
|
1298 tempwid, TRUE, TRUE, 0);
|
48
|
1299 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
1300 GTK_SIGNAL_FUNC (bm_apply_changes), NULL);
|
|
1301 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
452
|
1302 GTK_SIGNAL_FUNC (bm_close_dialog),
|
|
1303 (gpointer) edit_bookmarks_dialog);
|
48
|
1304 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
1305 gtk_widget_show (tempwid);
|
|
1306
|
|
1307 tempwid = gtk_button_new_with_label (_(" Cancel "));
|
452
|
1308 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (edit_bookmarks_dialog)->action_area),
|
|
1309 tempwid, TRUE, TRUE, 0);
|
48
|
1310 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
452
|
1311 GTK_SIGNAL_FUNC (bm_close_dialog),
|
|
1312 (gpointer) edit_bookmarks_dialog);
|
48
|
1313 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
1314 gtk_widget_grab_focus (tempwid);
|
|
1315 gtk_widget_show (tempwid);
|
|
1316 #else
|
452
|
1317 g_signal_connect (GTK_OBJECT (edit_bookmarks_dialog), "response",
|
48
|
1318 G_CALLBACK (editbm_action), NULL);
|
|
1319 #endif
|
|
1320
|
452
|
1321 gtk_widget_show (edit_bookmarks_dialog);
|
48
|
1322
|
|
1323 build_bookmarks_tree ();
|
|
1324 }
|
|
1325
|