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