]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilechooserdefault.c
Deprecate widget flag: GTK_WIDGET_MAPPED
[~andy/gtk] / gtk / gtkfilechooserdefault.c
index c8c4d2a5d6804d8b97e53af7fc09690e2fd71512..c2f29e9cdd5b929450aa15825ab61b02b7308530 100644 (file)
@@ -209,6 +209,20 @@ enum {
   MODEL_COL_NUM_COLUMNS
 };
 
+/* This list of types is passed to _gtk_file_system_model_new*() */
+#define MODEL_COLUMN_TYPES                                     \
+       MODEL_COL_NUM_COLUMNS,                                  \
+       G_TYPE_STRING,            /* MODEL_COL_NAME */          \
+       G_TYPE_INT64,             /* MODEL_COL_SIZE */          \
+       G_TYPE_LONG,              /* MODEL_COL_MTIME */         \
+       G_TYPE_FILE,              /* MODEL_COL_FILE */          \
+       G_TYPE_STRING,            /* MODEL_COL_NAME_COLLATED */ \
+       G_TYPE_BOOLEAN,           /* MODEL_COL_IS_FOLDER */     \
+       GDK_TYPE_PIXBUF,          /* MODEL_COL_PIXBUF */        \
+       G_TYPE_STRING,            /* MODEL_COL_SIZE_TEXT */     \
+       G_TYPE_STRING,            /* MODEL_COL_MTIME_TEXT */    \
+       PANGO_TYPE_ELLIPSIZE_MODE /* MODEL_COL_ELLIPSIZE */
+
 /* Identifiers for target types */
 enum {
   GTK_TREE_MODEL_ROW,
@@ -391,6 +405,8 @@ static void location_button_toggled_cb (GtkToggleButton *toggle,
                                        GtkFileChooserDefault *impl);
 static void location_switch_to_path_bar (GtkFileChooserDefault *impl);
 
+static void stop_loading_and_clear_list_model (GtkFileChooserDefault *impl,
+                                               gboolean remove_from_treeview);
 static void     search_stop_searching        (GtkFileChooserDefault *impl,
                                               gboolean               remove_query);
 static void     search_clear_model           (GtkFileChooserDefault *impl, 
@@ -865,15 +881,14 @@ gtk_file_chooser_default_finalize (GObject *object)
   if (impl->browse_path_bar_size_group)
     g_object_unref (impl->browse_path_bar_size_group);
 
-  load_remove_timer (impl);
-
   /* Free all the Models we have */
-  if (impl->browse_files_model)
-    g_object_unref (impl->browse_files_model);
-
+  stop_loading_and_clear_list_model (impl, FALSE);
   search_clear_model (impl, FALSE);
   recent_clear_model (impl, FALSE);
 
+  /* stopping the load above should have cleared this */
+  g_assert (impl->load_timeout_id == 0);
+
   g_free (impl->preview_display_name);
 
   g_free (impl->edited_new_text);
@@ -912,7 +927,7 @@ get_toplevel (GtkWidget *widget)
   GtkWidget *toplevel;
 
   toplevel = gtk_widget_get_toplevel (widget);
-  if (!GTK_WIDGET_TOPLEVEL (toplevel))
+  if (!gtk_widget_is_toplevel (toplevel))
     return NULL;
   else
     return GTK_WINDOW (toplevel);
@@ -1094,7 +1109,7 @@ update_preview_widget_visibility (GtkFileChooserDefault *impl)
   else
     gtk_widget_hide (impl->preview_box);
 
-  if (!GTK_WIDGET_MAPPED (impl))
+  if (!gtk_widget_get_mapped (GTK_WIDGET (impl)))
     emit_default_size_changed (impl);
 }
 
@@ -3956,7 +3971,7 @@ browse_files_key_press_event_cb (GtkWidget   *widget,
       if (window
          && widget != window->default_widget
          && !(widget == window->focus_widget &&
-              (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
+              (!window->default_widget || !gtk_widget_get_sensitive (window->default_widget))))
        {
          gtk_window_activate_default (window);
          return TRUE;
@@ -5036,7 +5051,7 @@ location_toggle_popup_handler (GtkFileChooserDefault *impl)
     }
   else if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
     {
-      if (GTK_WIDGET_HAS_FOCUS (impl->location_entry))
+      if (gtk_widget_has_focus (impl->location_entry))
         {
           location_mode_set (impl, LOCATION_MODE_PATH_BAR, TRUE);
         }
@@ -6265,12 +6280,13 @@ browse_files_select_first_row (GtkFileChooserDefault *impl)
   GtkTreeIter dummy_iter;
   GtkTreeModel *tree_model;
 
-  path = gtk_tree_path_new_from_indices (0, -1);
   tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view));
 
   if (!tree_model)
     return;
 
+  path = gtk_tree_path_new_from_indices (0, -1);
+
   /* If the list is empty, do nothing. */
   if (gtk_tree_model_get_iter (tree_model, &dummy_iter, path))
       gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), path, NULL, FALSE);
@@ -6392,7 +6408,8 @@ pending_select_files_process (GtkFileChooserDefault *impl)
        * that case, the chooser's selection should be what the caller expects,
        * as the user can't see that something else got selected.  See bug #165264.
        */
-      if (GTK_WIDGET_MAPPED (impl) && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
+      if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN &&
+          gtk_widget_get_mapped (GTK_WIDGET (impl)))
        browse_files_select_first_row (impl);
     }
 
@@ -6412,7 +6429,7 @@ show_error_on_reading_current_folder (GtkFileChooserDefault *impl, GError *error
                            NULL);
   if (info)
     {
-      msg = g_strdup (_("Could not read the contents of %s"), g_file_info_get_display_name (info));
+      msg = g_strdup_printf (_("Could not read the contents of %s"), g_file_info_get_display_name (info));
       g_object_unref (info);
     }
   else
@@ -6465,7 +6482,8 @@ browse_files_model_finished_loading_cb (GtkFileSystemModel    *model,
 }
 
 static void
-stop_loading_and_clear_list_model (GtkFileChooserDefault *impl)
+stop_loading_and_clear_list_model (GtkFileChooserDefault *impl,
+                                   gboolean remove_from_treeview)
 {
   load_remove_timer (impl); /* This changes the state to LOAD_EMPTY */
   
@@ -6475,7 +6493,8 @@ stop_loading_and_clear_list_model (GtkFileChooserDefault *impl)
       impl->browse_files_model = NULL;
     }
 
-  gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
+  if (remove_from_treeview)
+    gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
 }
 
 static char *
@@ -6489,6 +6508,11 @@ my_g_format_time_for_display (glong secs)
   gchar *locale_format = NULL;
   gchar buf[256];
   char *date_str = NULL;
+#ifdef G_OS_WIN32
+  const char *locale, *dot = NULL;
+  gint64 codepage = -1;
+  char charset[20];
+#endif
 
   time_mtime = secs;
 
@@ -6496,7 +6520,7 @@ my_g_format_time_for_display (glong secs)
   localtime_r ((time_t *) &time_mtime, &tm_mtime);
 #else
   {
-    struct tm *ptm = localtime ((time_t *) &timeval.tv_sec);
+    struct tm *ptm = localtime ((time_t *) &time_mtime);
 
     if (!ptm)
       {
@@ -6576,13 +6600,15 @@ my_g_format_time_for_display (glong secs)
   return date_str;
 }
 
-#define copy_attribute(to, from, attribute) G_STMT_START { \
-  GFileAttributeType type; \
-  gpointer value; \
-\
-  if (g_file_info_get_attribute_data (from, attribute, &type, &value, NULL)) \
-    g_file_info_set_attribute (to, attribute, type, value); \
-}G_STMT_END
+static void
+copy_attribute (GFileInfo *to, GFileInfo *from, const char *attribute)
+{
+  GFileAttributeType type;
+  gpointer value;
+
+  if (g_file_info_get_attribute_data (from, attribute, &type, &value, NULL))
+    g_file_info_set_attribute (to, attribute, type, value);
+}
 
 static void
 file_system_model_got_thumbnail (GObject *object, GAsyncResult *res, gpointer data)
@@ -6679,7 +6705,7 @@ file_system_model_set (GtkFileSystemModel *model,
                                            G_FILE_ATTRIBUTE_THUMBNAIL_PATH ","
                                            G_FILE_ATTRIBUTE_THUMBNAILING_FAILED ","
                                            G_FILE_ATTRIBUTE_STANDARD_ICON,
-                                           0,
+                                           G_FILE_QUERY_INFO_NONE,
                                            G_PRIORITY_DEFAULT,
                                            _gtk_file_system_model_get_cancellable (model),
                                            file_system_model_got_thumbnail,
@@ -6738,27 +6764,16 @@ set_list_model (GtkFileChooserDefault *impl,
 
   profile_start ("start", NULL);
 
-  stop_loading_and_clear_list_model (impl);
+  stop_loading_and_clear_list_model (impl, TRUE);
 
   set_busy_cursor (impl, TRUE);
-  gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
 
   impl->browse_files_model = 
     _gtk_file_system_model_new_for_directory (impl->current_folder,
-        MODEL_ATTRIBUTES,
-        file_system_model_set,
-        impl,
-        MODEL_COL_NUM_COLUMNS,
-        G_TYPE_STRING,
-        G_TYPE_INT64,
-        G_TYPE_LONG,
-        G_TYPE_FILE,
-        G_TYPE_STRING,
-        G_TYPE_BOOLEAN,
-        GDK_TYPE_PIXBUF,
-        G_TYPE_STRING,
-        G_TYPE_STRING,
-        PANGO_TYPE_ELLIPSIZE_MODE);
+                                             MODEL_ATTRIBUTES,
+                                             file_system_model_set,
+                                             impl,
+                                             MODEL_COLUMN_TYPES);
 
   _gtk_file_system_model_set_show_hidden (impl->browse_files_model, impl->show_hidden);
 
@@ -8016,14 +8031,14 @@ gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
 
       if (impl->preview_widget_active &&
          impl->preview_widget &&
-         GTK_WIDGET_VISIBLE (impl->preview_widget))
+         gtk_widget_get_visible (impl->preview_widget))
        {
          gtk_widget_size_request (impl->preview_box, &req);
          *default_width += PREVIEW_HBOX_SPACING + req.width;
        }
 
       if (impl->extra_widget &&
-         GTK_WIDGET_VISIBLE (impl->extra_widget))
+         gtk_widget_get_visible (impl->extra_widget))
        {
          gtk_widget_size_request (impl->extra_align, &req);
          *default_height += GTK_BOX (chooser_embed)->spacing + req.height;
@@ -8131,7 +8146,7 @@ add_custom_button_to_dialog (GtkDialog   *dialog,
   GtkWidget *button;
 
   button = gtk_button_new_with_mnemonic (mnemonic_label);
-  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+  gtk_widget_set_can_default (button, TRUE);
   gtk_button_set_image (GTK_BUTTON (button),
                        gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON));
   gtk_widget_show (button);
@@ -8906,18 +8921,7 @@ search_setup_model (GtkFileChooserDefault *impl)
 
   impl->search_model = _gtk_file_system_model_new (file_system_model_set,
                                                    impl,
-                                                   MODEL_COL_NUM_COLUMNS,
-                                                   G_TYPE_STRING, /* MODEL_COL_NAME */
-                                                   G_TYPE_INT64, /* MODEL_COL_SIZE */
-                                                   G_TYPE_LONG, /* MODEL_COL_MTIME */
-                                                   G_TYPE_FILE, /* MODEL_COL_FILE */
-                                                   G_TYPE_STRING, /* MODEL_COL_NAME_COLLATED */
-                                                   G_TYPE_BOOLEAN, /* MODEL_COL_IS_FOLDER */
-                                                   GDK_TYPE_PIXBUF, /* MODEL_COL_PIXBUF */
-                                                   G_TYPE_STRING, /* MODEL_COL_SIZE_TEXT */
-                                                   G_TYPE_STRING, /* MODEL_COL_MTIME_TEXT */
-                                                   PANGO_TYPE_ELLIPSIZE_MODE /* MODEL_COL_ELLIPSIZE */
-                                                  );
+                                                  MODEL_COLUMN_TYPES);
 
   gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model),
                                   MODEL_COL_NAME,
@@ -9085,7 +9089,7 @@ stop_operation (GtkFileChooserDefault *impl, OperationMode mode)
   switch (mode)
     {
     case OPERATION_MODE_BROWSE:
-      stop_loading_and_clear_list_model (impl);
+      stop_loading_and_clear_list_model (impl, TRUE);
       break;
 
     case OPERATION_MODE_SEARCH:
@@ -9213,18 +9217,7 @@ recent_setup_model (GtkFileChooserDefault *impl)
 
   impl->recent_model = _gtk_file_system_model_new (file_system_model_set,
                                                    impl,
-                                                   MODEL_COL_NUM_COLUMNS,
-                                                   G_TYPE_STRING, /* MODEL_COL_NAME */
-                                                   G_TYPE_INT64, /* MODEL_COL_SIZE */
-                                                   G_TYPE_LONG, /* MODEL_COL_MTIME */
-                                                   G_TYPE_FILE, /* MODEL_COL_FILE */
-                                                   G_TYPE_STRING, /* MODEL_COL_NAME_COLLATED */
-                                                   G_TYPE_BOOLEAN, /* MODEL_COL_IS_FOLDER */
-                                                   GDK_TYPE_PIXBUF, /* MODEL_COL_PIXBUF */
-                                                   G_TYPE_STRING, /* MODEL_COL_SIZE_TEXT */
-                                                   G_TYPE_STRING, /* MODEL_COL_MTIME_TEXT */
-                                                   PANGO_TYPE_ELLIPSIZE_MODE /* MODEL_COL_ELLIPSIZE */
-                                                  );
+                                                  MODEL_COLUMN_TYPES);
 
   _gtk_file_system_model_set_filter (impl->recent_model,
                                      impl->current_filter);