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