]> Pileus Git - ~andy/gtk/blobdiff - demos/gtk-demo/iconview.c
Deprecate widget flag: GTK_WIDGET_VISIBLE
[~andy/gtk] / demos / gtk-demo / iconview.c
index 9c76c7815d259b689542326e4db2de75815f48a2..1cfac12c955618f6799d853364a3ae9e2b7ba19c 100644 (file)
@@ -1,7 +1,7 @@
 /* Icon View/Icon View Basics
  *
- * The GtkIconView widget is used to display and manipulate icons.  
- * It uses a GtkTreeModel for data storage, so the list store 
+ * The GtkIconView widget is used to display and manipulate icons.
+ * It uses a GtkTreeModel for data storage, so the list store
  * example might be helpful.
  */
 
@@ -47,10 +47,10 @@ load_pixbufs (GError **error)
 
   file_pixbuf = gdk_pixbuf_new_from_file (filename, error);
   g_free (filename);
-  
+
   if (!file_pixbuf)
     return FALSE; /* Note that "error" was filled with a GError */
-  
+
   filename = demo_find_file (FOLDER_NAME, error);
   if (!filename)
     return FALSE; /* note that "error" was filled in and returned */
@@ -67,7 +67,7 @@ fill_store (GtkListStore *store)
   GDir *dir;
   const gchar *name;
   GtkTreeIter iter;
-  
+
   /* First clear the store */
   gtk_list_store_clear (store);
 
@@ -82,14 +82,14 @@ fill_store (GtkListStore *store)
     {
       gchar *path, *display_name;
       gboolean is_dir;
-      
+
       /* We ignore hidden files that start with a '.' */
       if (name[0] != '.')
        {
          path = g_build_filename (parent, name, NULL);
 
          is_dir = g_file_test (path, G_FILE_TEST_IS_DIR);
-         
+
          display_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
 
          gtk_list_store_append (store, &iter);
@@ -103,7 +103,7 @@ fill_store (GtkListStore *store)
          g_free (display_name);
        }
 
-      name = g_dir_read_name (dir);      
+      name = g_dir_read_name (dir);
     }
 }
 
@@ -121,7 +121,7 @@ sort_func (GtkTreeModel *model,
    * folders before files.
    */
 
-  
+
   gtk_tree_model_get (model, a,
                      COL_IS_DIRECTORY, &is_dir_a,
                      COL_DISPLAY_NAME, &name_a,
@@ -153,12 +153,12 @@ create_store (void)
   GtkListStore *store;
 
   store = gtk_list_store_new (NUM_COLS,
-                             G_TYPE_STRING, 
-                             G_TYPE_STRING, 
+                             G_TYPE_STRING,
+                             G_TYPE_STRING,
                              GDK_TYPE_PIXBUF,
                              G_TYPE_BOOLEAN);
 
-  /* Set sort column and function */ 
+  /* Set sort column and function */
   gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
                                           sort_func,
                                           NULL, NULL);
@@ -178,7 +178,7 @@ item_activated (GtkIconView *icon_view,
   gchar *path;
   GtkTreeIter iter;
   gboolean is_dir;
-  
+
   store = GTK_LIST_STORE (user_data);
 
   gtk_tree_model_get_iter (GTK_TREE_MODEL (store),
@@ -193,7 +193,7 @@ item_activated (GtkIconView *icon_view,
       g_free (path);
       return;
     }
-  
+
   /* Replace parent with path and re-fill the model*/
   g_free (parent);
   parent = path;
@@ -215,7 +215,7 @@ up_clicked (GtkToolItem *item,
 
   dir_name = g_path_get_dirname (parent);
   g_free (parent);
-  
+
   parent = dir_name;
 
   fill_store (store);
@@ -243,22 +243,34 @@ home_clicked (GtkToolItem *item,
                            TRUE);
 }
 
+static void close_window(void)
+{
+  gtk_widget_destroy (window);
+  window = NULL;
+
+  g_object_unref (file_pixbuf);
+  file_pixbuf = NULL;
+
+  g_object_unref (folder_pixbuf);
+  folder_pixbuf = NULL;
+}
+
 GtkWidget *
 do_iconview (GtkWidget *do_widget)
 {
   if (!window)
     {
       GError *error;
-            
+
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_default_size (GTK_WINDOW (window), 650, 400);
-      
+
       gtk_window_set_screen (GTK_WINDOW (window),
                             gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "GtkIconView demo");
 
       g_signal_connect (window, "destroy",
-                       G_CALLBACK (gtk_widget_destroyed), &window);
+                       G_CALLBACK (close_window), NULL);
 
       error = NULL;
       if (!load_pixbufs (&error))
@@ -287,13 +299,13 @@ do_iconview (GtkWidget *do_widget)
          GtkWidget *vbox;
          GtkWidget *tool_bar;
          GtkToolItem *home_button;
-         
+
          vbox = gtk_vbox_new (FALSE, 0);
          gtk_container_add (GTK_CONTAINER (window), vbox);
 
          tool_bar = gtk_toolbar_new ();
          gtk_box_pack_start (GTK_BOX (vbox), tool_bar, FALSE, FALSE, 0);
-         
+
          up_button = gtk_tool_button_new_from_stock (GTK_STOCK_GO_UP);
          gtk_tool_item_set_is_important (up_button, TRUE);
          gtk_widget_set_sensitive (GTK_WIDGET (up_button), FALSE);
@@ -302,17 +314,17 @@ do_iconview (GtkWidget *do_widget)
          home_button = gtk_tool_button_new_from_stock (GTK_STOCK_HOME);
          gtk_tool_item_set_is_important (home_button, TRUE);
          gtk_toolbar_insert (GTK_TOOLBAR (tool_bar), home_button, -1);
-         
-         
+
+
          sw = gtk_scrolled_window_new (NULL, NULL);
          gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
                                               GTK_SHADOW_ETCHED_IN);
          gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                          GTK_POLICY_AUTOMATIC,
                                          GTK_POLICY_AUTOMATIC);
-         
+
          gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
-         
+
          /* Create the store and fill it with the contents of '/' */
          parent = g_strdup ("/");
          store = create_store ();
@@ -322,7 +334,7 @@ do_iconview (GtkWidget *do_widget)
          gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
                                            GTK_SELECTION_MULTIPLE);
          g_object_unref (store);
-         
+
          /* Connect to the "clicked" signal of the "Up" tool button */
          g_signal_connect (up_button, "clicked",
                            G_CALLBACK (up_clicked), store);
@@ -330,23 +342,23 @@ do_iconview (GtkWidget *do_widget)
          /* Connect to the "clicked" signal of the "Home" tool button */
          g_signal_connect (home_button, "clicked",
                            G_CALLBACK (home_clicked), store);
-         
+
          /* We now set which model columns that correspond to the text
           * and pixbuf of each item
           */
          gtk_icon_view_set_text_column (GTK_ICON_VIEW (icon_view), COL_DISPLAY_NAME);
          gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_view), COL_PIXBUF);
 
-         /* Connect to the "item_activated" signal */
-         g_signal_connect (icon_view, "item_activated",
+         /* Connect to the "item-activated" signal */
+         g_signal_connect (icon_view, "item-activated",
                            G_CALLBACK (item_activated), store);
          gtk_container_add (GTK_CONTAINER (sw), icon_view);
 
          gtk_widget_grab_focus (icon_view);
        }
     }
-  
-  if (!GTK_WIDGET_VISIBLE (window))
+
+  if (!gtk_widget_get_visible (window))
     gtk_widget_show_all (window);
   else
     {