Mercurial > gftp.yaz
comparison src/gtk/bookmarks.c @ 609:d97e985f5dbe
2004-11-3 Brian Masney <masneyb@gftp.org>
* lib/config_file.c (gftp_bookmarks_destroy)
src/gtk/bookmarks.c (bm_apply_changes) - cleaned up the tree parsing
code
* lib/gftp.h lib/misc.c lib/config_file.c src/gtk/bookmarks.c - added
free_node argument to gftp_free_bookmark()
* lib/gftp.h src/gtk/bookmarks.c - added oldpath variable to the
gftp_bookmarks structure.
author | masneyb |
---|---|
date | Wed, 03 Nov 2004 10:51:32 +0000 |
parents | b6887fbe3e11 |
children | 08e7b5186eb8 |
comparison
equal
deleted
inserted
replaced
608:7e575601841a | 609:d97e985f5dbe |
---|---|
165 else | 165 else |
166 { | 166 { |
167 test.item_type = ""; | 167 test.item_type = ""; |
168 test.callback = run_bookmark; | 168 test.callback = run_bookmark; |
169 } | 169 } |
170 | |
170 gtk_item_factory_create_item (factory, &test, | 171 gtk_item_factory_create_item (factory, &test, |
171 (gpointer) tempentry->path, 1); | 172 (gpointer) tempentry->path, 1); |
172 g_free (test.path); | 173 g_free (test.path); |
173 if (tempentry->children != NULL) | 174 if (tempentry->children != NULL) |
174 { | 175 { |
279 return (new_bm); | 280 return (new_bm); |
280 } | 281 } |
281 | 282 |
282 | 283 |
283 static void | 284 static void |
285 _free_menu_entry (gftp_bookmarks_var * entry) | |
286 { | |
287 GtkWidget * tempwid; | |
288 char *tempstr; | |
289 | |
290 if (entry->oldpath != NULL) | |
291 tempstr = gftp_build_path (NULL, "/Bookmarks", entry->oldpath, NULL); | |
292 else | |
293 tempstr = gftp_build_path (NULL, "/Bookmarks", entry->path, NULL); | |
294 | |
295 tempwid = gtk_item_factory_get_item (factory, tempstr); | |
296 if (GTK_IS_WIDGET (tempwid)) | |
297 gtk_widget_destroy (tempwid); | |
298 | |
299 g_free (tempstr); | |
300 } | |
301 | |
302 | |
303 static void | |
284 bm_apply_changes (GtkWidget * widget, gpointer backup_data) | 304 bm_apply_changes (GtkWidget * widget, gpointer backup_data) |
285 { | 305 { |
286 gftp_bookmarks_var * tempentry, * delentry; | 306 gftp_bookmarks_var * tempentry, * delentry; |
287 char *tempstr; | |
288 | 307 |
289 if (bm_dialog != NULL) | 308 if (bm_dialog != NULL) |
290 { | 309 { |
291 gtk_widget_grab_focus (bm_dialog); | 310 gtk_widget_grab_focus (bm_dialog); |
292 return; | 311 return; |
295 if (gftp_bookmarks != NULL) | 314 if (gftp_bookmarks != NULL) |
296 { | 315 { |
297 tempentry = gftp_bookmarks->children; | 316 tempentry = gftp_bookmarks->children; |
298 while (tempentry != NULL) | 317 while (tempentry != NULL) |
299 { | 318 { |
300 if (tempentry->path && !tempentry->isfolder) | |
301 { | |
302 tempstr = g_strdup_printf ("/Bookmarks/%s", tempentry->path); | |
303 gtk_widget_destroy (gtk_item_factory_get_item (factory, tempstr)); | |
304 g_free (tempentry->path); | |
305 g_free (tempstr); | |
306 } | |
307 | |
308 gftp_free_bookmark (tempentry); | |
309 | |
310 if (tempentry->children != NULL) | 319 if (tempentry->children != NULL) |
311 tempentry = tempentry->children; | 320 tempentry = tempentry->children; |
312 else | 321 else |
313 { | 322 { |
314 if (tempentry->next == NULL) | 323 while (tempentry->next == NULL && tempentry->prev != NULL) |
315 { | |
316 while (tempentry->next == NULL && tempentry->prev != NULL) | |
317 { | |
318 delentry = tempentry; | |
319 tempentry = tempentry->prev; | |
320 if (delentry->isfolder) | |
321 { | |
322 tempstr = g_strdup_printf ("/Bookmarks/%s", | |
323 delentry->path); | |
324 gtk_widget_destroy (gtk_item_factory_get_item (factory, | |
325 tempstr)); | |
326 g_free (tempstr); | |
327 g_free (delentry->path); | |
328 } | |
329 g_free (delentry); | |
330 } | |
331 | |
332 delentry = tempentry; | |
333 tempentry = tempentry->next; | |
334 if (delentry->isfolder && tempentry != NULL) | |
335 { | |
336 tempstr = g_strdup_printf ("/Bookmarks/%s", | |
337 delentry->path); | |
338 gtk_widget_destroy (gtk_item_factory_get_item (factory, | |
339 tempstr)); | |
340 g_free (delentry->path); | |
341 g_free (tempstr); | |
342 g_free (delentry); | |
343 } | |
344 } | |
345 else | |
346 { | 324 { |
347 delentry = tempentry; | 325 delentry = tempentry; |
348 tempentry = tempentry->next; | 326 tempentry = tempentry->prev; |
349 g_free (delentry); | 327 _free_menu_entry (delentry); |
328 gftp_free_bookmark (delentry, 1); | |
350 } | 329 } |
330 | |
331 delentry = tempentry; | |
332 tempentry = tempentry->next; | |
333 if (tempentry != NULL) | |
334 _free_menu_entry (delentry); | |
335 | |
336 gftp_free_bookmark (delentry, 1); | |
351 } | 337 } |
352 } | 338 } |
353 | 339 |
354 g_free (gftp_bookmarks); | |
355 g_hash_table_destroy (gftp_bookmarks_htable); | 340 g_hash_table_destroy (gftp_bookmarks_htable); |
356 } | 341 } |
357 | 342 |
358 if (backup_data) | 343 if (backup_data) |
359 { | 344 { |
360 gftp_bookmarks = copy_bookmarks (new_bookmarks); | 345 gftp_bookmarks = copy_bookmarks (new_bookmarks); |
361 gftp_bookmarks_htable = build_bookmarks_hash_table (new_bookmarks); | 346 gftp_bookmarks_htable = build_bookmarks_hash_table (gftp_bookmarks); |
362 } | 347 } |
363 else | 348 else |
364 { | 349 { |
365 gftp_bookmarks = new_bookmarks; | 350 gftp_bookmarks = new_bookmarks; |
366 gftp_bookmarks_htable = new_bookmarks_htable; | 351 gftp_bookmarks_htable = new_bookmarks_htable; |
473 opendir_bitmap, FALSE, FALSE); | 458 opendir_bitmap, FALSE, FALSE); |
474 else | 459 else |
475 newentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree), | 460 newentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree), |
476 new_bookmarks->cnode, NULL, | 461 new_bookmarks->cnode, NULL, |
477 text, 5, NULL, NULL, NULL, NULL, | 462 text, 5, NULL, NULL, NULL, NULL, |
478 FALSE, FALSE); | 463 TRUE, FALSE); |
479 | 464 |
480 gtk_ctree_node_set_row_data (GTK_CTREE (tree), newentry->cnode, newentry); | 465 gtk_ctree_node_set_row_data (GTK_CTREE (tree), newentry->cnode, newentry); |
481 g_hash_table_insert (new_bookmarks_htable, newentry->path, newentry); | 466 g_hash_table_insert (new_bookmarks_htable, newentry->path, newentry); |
482 } | 467 } |
483 | 468 |
522 entry->prev = NULL; | 507 entry->prev = NULL; |
523 entry->next = NULL; | 508 entry->next = NULL; |
524 tempentry = entry; | 509 tempentry = entry; |
525 while (tempentry != NULL) | 510 while (tempentry != NULL) |
526 { | 511 { |
527 gftp_free_bookmark (tempentry); | 512 gftp_free_bookmark (tempentry, 0); |
528 | 513 |
529 if (tempentry->children != NULL) | 514 if (tempentry->children != NULL) |
530 { | 515 { |
531 tempentry = tempentry->children; | 516 tempentry = tempentry->children; |
532 continue; | 517 continue; |
668 pos++; | 653 pos++; |
669 | 654 |
670 text[0] = text[1] = pos; | 655 text[0] = text[1] = pos; |
671 tempentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree), | 656 tempentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree), |
672 tempentry->prev->cnode, NULL, text, 5, NULL, | 657 tempentry->prev->cnode, NULL, text, 5, NULL, |
673 NULL, NULL, NULL, FALSE, FALSE); | 658 NULL, NULL, NULL, TRUE, FALSE); |
674 gtk_ctree_node_set_row_data (GTK_CTREE (tree), tempentry->cnode, | 659 gtk_ctree_node_set_row_data (GTK_CTREE (tree), tempentry->cnode, |
675 tempentry); | 660 tempentry); |
676 } | 661 } |
677 | 662 |
678 while (tempentry->next == NULL && tempentry->prev != NULL) | 663 while (tempentry->next == NULL && tempentry->prev != NULL) |
683 | 668 |
684 | 669 |
685 static void | 670 static void |
686 entry_apply_changes (GtkWidget * widget, gftp_bookmarks_var * entry) | 671 entry_apply_changes (GtkWidget * widget, gftp_bookmarks_var * entry) |
687 { | 672 { |
688 char *pos, *newpath, tempchar, *tempstr, *origpath; | |
689 gftp_bookmarks_var * tempentry, * nextentry; | 673 gftp_bookmarks_var * tempentry, * nextentry; |
674 char *pos, *newpath, tempchar, *tempstr; | |
690 GtkWidget * tempwid; | 675 GtkWidget * tempwid; |
691 size_t oldpathlen; | 676 size_t oldpathlen; |
692 const char *str; | 677 const char *str; |
693 | 678 |
694 tempstr = g_strdup (gtk_entry_get_text (GTK_ENTRY (bm_pathedit))); | 679 tempstr = g_strdup (gtk_entry_get_text (GTK_ENTRY (bm_pathedit))); |
699 if ((pos = strrchr (entry->path, '/')) == NULL) | 684 if ((pos = strrchr (entry->path, '/')) == NULL) |
700 pos = entry->path; | 685 pos = entry->path; |
701 | 686 |
702 tempchar = *pos; | 687 tempchar = *pos; |
703 *pos = '\0'; | 688 *pos = '\0'; |
704 origpath = newpath = gftp_build_path (NULL, entry->path, tempstr, NULL); | 689 newpath = gftp_build_path (NULL, entry->path, tempstr, NULL); |
705 *pos = tempchar; | 690 *pos = tempchar; |
706 | 691 |
707 g_free (tempstr); | 692 g_free (tempstr); |
708 | 693 |
709 str = gtk_entry_get_text (GTK_ENTRY (bm_hostedit)); | 694 str = gtk_entry_get_text (GTK_ENTRY (bm_hostedit)); |
762 entry->next = NULL; | 747 entry->next = NULL; |
763 while (tempentry != NULL) | 748 while (tempentry != NULL) |
764 { | 749 { |
765 g_hash_table_remove (new_bookmarks_htable, tempentry->path); | 750 g_hash_table_remove (new_bookmarks_htable, tempentry->path); |
766 | 751 |
752 if (tempentry->oldpath == NULL) | |
753 tempentry->oldpath = tempentry->path; | |
754 else | |
755 g_free (tempentry->path); | |
756 | |
767 if (*(tempentry->path + oldpathlen) == '\0') | 757 if (*(tempentry->path + oldpathlen) == '\0') |
768 tempstr = g_strdup (newpath); | 758 tempentry->path = g_strdup (newpath); |
769 else | 759 else |
770 tempstr = gftp_build_path (NULL, newpath, | 760 tempentry->path = gftp_build_path (NULL, newpath, |
771 tempentry->path + oldpathlen, NULL); | 761 tempentry->path + oldpathlen, |
772 | 762 NULL); |
773 g_free (tempentry->path); | 763 |
774 tempentry->path = tempstr; | |
775 g_hash_table_insert (new_bookmarks_htable, tempentry->path, | 764 g_hash_table_insert (new_bookmarks_htable, tempentry->path, |
776 tempentry); | 765 tempentry); |
777 if (tempentry->children != NULL) | 766 if (tempentry->children != NULL) |
778 { | 767 { |
779 tempentry = tempentry->children; | 768 tempentry = tempentry->children; |
787 } | 776 } |
788 | 777 |
789 entry->next = nextentry; | 778 entry->next = nextentry; |
790 } | 779 } |
791 | 780 |
792 g_free (origpath); | 781 g_free (newpath); |
793 } | 782 } |
794 | 783 |
795 | 784 |
796 #if GTK_MAJOR_VERSION == 1 | 785 #if GTK_MAJOR_VERSION == 1 |
797 | 786 |