comparison src/gtk/bookmarks.c @ 23:e19785b088d7

2002-09-18 Brian Masney <masneyb@gftp.org> * Updated French translation (from Damien Mascr? <damienmascre@free.fr>) * Updated Japanese translation (from Ryoichi INAGAKI <inagaki@ryo1.net>) 2002-09-17 Brian Masney <masneyb@gftp.org> * src/gtk/bookmarks.c - Fixed crash that would occur if you saved the changes two times in the bookmark editor. Also, fixed several memory leaks
author masneyb
date Wed, 18 Sep 2002 12:12:18 +0000
parents 3b2dcdefc7e9
children d74bfa342116
comparison
equal deleted inserted replaced
22:cc6431f1ca55 23:e19785b088d7
300 #endif 300 #endif
301 301
302 new_bookmarks = copy_bookmarks (bookmarks); 302 new_bookmarks = copy_bookmarks (bookmarks);
303 new_bookmarks_htable = build_bookmarks_hash_table (new_bookmarks); 303 new_bookmarks_htable = build_bookmarks_hash_table (new_bookmarks);
304 304
305 /* FIXME - busted if you pull this up twice */
306 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 305 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2
307 dialog = gtk_dialog_new (); 306 dialog = gtk_dialog_new ();
308 gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Bookmarks")); 307 gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Bookmarks"));
309 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 15); 308 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 15);
310 #else 309 #else
324 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap, 323 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap,
325 gftp_icon->bitmap); 324 gftp_icon->bitmap);
326 gdk_window_set_icon_name (dialog->window, _("gFTP Icon")); 325 gdk_window_set_icon_name (dialog->window, _("gFTP Icon"));
327 } 326 }
328 327
328 /* FIXME - memory leak */
329 ifactory = item_factory_new (GTK_TYPE_MENU_BAR, "<bookmarks>", NULL, NULL); 329 ifactory = item_factory_new (GTK_TYPE_MENU_BAR, "<bookmarks>", NULL, NULL);
330 create_item_factory (ifactory, 7, menu_items, NULL); 330 create_item_factory (ifactory, 7, menu_items, NULL);
331 create_item_factory (ifactory, 1, menu_items + 7, dialog); 331 create_item_factory (ifactory, 1, menu_items + 7, dialog);
332 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), ifactory->widget, 332 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), ifactory->widget,
333 FALSE, FALSE, 0); 333 FALSE, FALSE, 0);
341 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), scroll, TRUE, TRUE, 341 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), scroll, TRUE, TRUE,
342 0); 342 0);
343 gtk_container_border_width (GTK_CONTAINER (scroll), 3); 343 gtk_container_border_width (GTK_CONTAINER (scroll), 3);
344 gtk_widget_show (scroll); 344 gtk_widget_show (scroll);
345 345
346 /* FIXME - memory leak */
346 edit_factory = item_factory_new (GTK_TYPE_MENU, "<edit_bookmark>", NULL, "/File"); 347 edit_factory = item_factory_new (GTK_TYPE_MENU, "<edit_bookmark>", NULL, "/File");
347 348
348 create_item_factory (edit_factory, 6, menu_items + 2, dialog); 349 create_item_factory (edit_factory, 6, menu_items + 2, dialog);
349 350
350 tree = gtk_ctree_new (1, 0); 351 tree = gtk_ctree_new (1, 0);
388 build_bookmarks_tree (); 389 build_bookmarks_tree ();
389 } 390 }
390 391
391 392
392 static void 393 static void
394 free_bookmark_entry_items (gftp_bookmarks * entry)
395 {
396 if (entry->hostname)
397 g_free (entry->hostname);
398 if (entry->remote_dir)
399 g_free (entry->remote_dir);
400 if (entry->local_dir)
401 g_free (entry->local_dir);
402 if (entry->user)
403 g_free (entry->user);
404 if (entry->pass)
405 g_free (entry->pass);
406 if (entry->acct)
407 g_free (entry->acct);
408 if (entry->protocol)
409 g_free (entry->protocol);
410 }
411
412
413 static void
393 bm_apply_changes (GtkWidget * widget, gpointer backup_data) 414 bm_apply_changes (GtkWidget * widget, gpointer backup_data)
394 { 415 {
395 gftp_bookmarks * tempentry, * delentry; 416 gftp_bookmarks * tempentry, * delentry;
396 char *tempstr; 417 char *tempstr;
397 418
403 tempstr = g_strdup_printf ("/Bookmarks/%s", tempentry->path); 424 tempstr = g_strdup_printf ("/Bookmarks/%s", tempentry->path);
404 gtk_widget_destroy (gtk_item_factory_get_item (factory, tempstr)); 425 gtk_widget_destroy (gtk_item_factory_get_item (factory, tempstr));
405 g_free (tempentry->path); 426 g_free (tempentry->path);
406 g_free (tempstr); 427 g_free (tempstr);
407 } 428 }
408 if (tempentry->hostname) 429
409 g_free (tempentry->hostname); 430 free_bookmark_entry_items (tempentry);
410 if (tempentry->remote_dir)
411 g_free (tempentry->remote_dir);
412 if (tempentry->local_dir)
413 g_free (tempentry->local_dir);
414 if (tempentry->user)
415 g_free (tempentry->user);
416 if (tempentry->pass)
417 g_free (tempentry->pass);
418 if (tempentry->acct)
419 g_free (tempentry->acct);
420 if (tempentry->protocol)
421 g_free (tempentry->protocol);
422 431
423 if (tempentry->children != NULL) 432 if (tempentry->children != NULL)
424 tempentry = tempentry->children; 433 tempentry = tempentry->children;
425 else 434 else
426 { 435 {
487 { 496 {
488 gftp_bookmarks * new_bm, * preventry, * tempentry, * sibling, * newentry, 497 gftp_bookmarks * new_bm, * preventry, * tempentry, * sibling, * newentry,
489 * tentry; 498 * tentry;
490 499
491 new_bm = g_malloc0 (sizeof (*new_bm)); 500 new_bm = g_malloc0 (sizeof (*new_bm));
501 /* FIXME - memory leak */
492 new_bm->path = g_malloc0 (1); 502 new_bm->path = g_malloc0 (1);
493 new_bm->isfolder = bookmarks->isfolder; 503 new_bm->isfolder = bookmarks->isfolder;
494 preventry = new_bm; 504 preventry = new_bm;
495 tempentry = bookmarks->children; 505 tempentry = bookmarks->children;
496 sibling = NULL; 506 sibling = NULL;
594 604
595 605
596 static void 606 static void
597 bm_close_dialog (GtkWidget * widget, GtkWidget * dialog) 607 bm_close_dialog (GtkWidget * widget, GtkWidget * dialog)
598 { 608 {
599 gftp_bookmarks * tempentry; 609 gftp_bookmarks * tempentry, * delentry;
600 610
601 if (new_bookmarks_htable) 611 if (new_bookmarks_htable)
602 g_hash_table_destroy (new_bookmarks_htable); 612 g_hash_table_destroy (new_bookmarks_htable);
613
603 tempentry = new_bookmarks; 614 tempentry = new_bookmarks;
604 while (tempentry != NULL) 615 while (tempentry != NULL)
605 { 616 {
606 tempentry->cnode = NULL; 617 free_bookmark_entry_items (tempentry);
618 g_free (tempentry->path);
619
607 if (tempentry->children != NULL) 620 if (tempentry->children != NULL)
608 { 621 {
609 tempentry = tempentry->children; 622 tempentry = tempentry->children;
610 continue; 623 continue;
611 } 624 }
625
612 while (tempentry->next == NULL && tempentry->prev != NULL) 626 while (tempentry->next == NULL && tempentry->prev != NULL)
613 tempentry = tempentry->prev; 627 {
628 delentry = tempentry;
629 tempentry = tempentry->prev;
630 g_free (delentry);
631 }
632
633 delentry = tempentry;
614 tempentry = tempentry->next; 634 tempentry = tempentry->next;
615 } 635 g_free (delentry);
636 }
637
616 new_bookmarks = NULL; 638 new_bookmarks = NULL;
617 new_bookmarks_htable = NULL; 639 new_bookmarks_htable = NULL;
618 gtk_widget_destroy (dialog); 640 gtk_widget_destroy (dialog);
619 } 641 }
620 642
1338 new_bookmarks->cnode = parent; 1360 new_bookmarks->cnode = parent;
1339 1361
1340 tempentry = new_bookmarks->children; 1362 tempentry = new_bookmarks->children;
1341 while (tempentry != NULL) 1363 while (tempentry != NULL)
1342 { 1364 {
1365 tempentry->cnode = NULL;
1343 if (tempentry->children != NULL) 1366 if (tempentry->children != NULL)
1344 { 1367 {
1345 tempentry = tempentry->children; 1368 tempentry = tempentry->children;
1346 continue; 1369 continue;
1347 } 1370 }
1368 opendir_pixmap, opendir_bitmap, 1391 opendir_pixmap, opendir_bitmap,
1369 FALSE, FALSE); 1392 FALSE, FALSE);
1370 gtk_ctree_node_set_row_data (GTK_CTREE (tree), 1393 gtk_ctree_node_set_row_data (GTK_CTREE (tree),
1371 preventry->cnode, preventry); 1394 preventry->cnode, preventry);
1372 } 1395 }
1396
1373 g_free (str); 1397 g_free (str);
1374 pos++; 1398 pos++;
1375 } 1399 }
1376 } 1400 }
1377 1401