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