Bug 325095 – show a 'size' column

2008-09-18  Emmanuele Bassi  <ebassi@linux.intel.com>

	Bug 325095 – show a 'size' column

	* gtk/gtkfilechooserdefault.c:
	* gtk/gtkfilechooserprivate.h: Add a context menu item controlling
	the visibility of the file size column. This works only for the
	browse mode, and the column is not visible by default.

	* gtk/gtkfilechoosersettings.[ch]: Add a ShowSizeColumn key to the
	settings file.

svn path=/trunk/; revision=21431
This commit is contained in:
Emmanuele Bassi 2008-09-18 15:29:33 +00:00 committed by Emmanuele Bassi
parent 8bfc826f27
commit 555ef89dc3
5 changed files with 130 additions and 38 deletions

View File

@ -1,3 +1,15 @@
2008-09-18 Emmanuele Bassi <ebassi@linux.intel.com>
Bug 325095 show a 'size' column
* gtk/gtkfilechooserdefault.c:
* gtk/gtkfilechooserprivate.h: Add a context menu item controlling
the visibility of the file size column. This works only for the
browse mode, and the column is not visible by default.
* gtk/gtkfilechoosersettings.[ch]: Add a ShowSizeColumn key to the
settings file.
2008-09-18 Dominic Lachowicz <domlachowicz@gmail.com> 2008-09-18 Dominic Lachowicz <domlachowicz@gmail.com>
* modules/engines/ms-windows/*: Revert most of previous patch, as it didn't work as expected; * modules/engines/ms-windows/*: Revert most of previous patch, as it didn't work as expected;

View File

@ -407,13 +407,11 @@ static void list_name_data_func (GtkTreeViewColumn *tree_column,
GtkTreeModel *tree_model, GtkTreeModel *tree_model,
GtkTreeIter *iter, GtkTreeIter *iter,
gpointer data); gpointer data);
#if 0
static void list_size_data_func (GtkTreeViewColumn *tree_column, static void list_size_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell, GtkCellRenderer *cell,
GtkTreeModel *tree_model, GtkTreeModel *tree_model,
GtkTreeIter *iter, GtkTreeIter *iter,
gpointer data); gpointer data);
#endif
static void list_mtime_data_func (GtkTreeViewColumn *tree_column, static void list_mtime_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell, GtkCellRenderer *cell,
GtkTreeModel *tree_model, GtkTreeModel *tree_model,
@ -794,6 +792,7 @@ _gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
impl->use_preview_label = TRUE; impl->use_preview_label = TRUE;
impl->select_multiple = FALSE; impl->select_multiple = FALSE;
impl->show_hidden = FALSE; impl->show_hidden = FALSE;
impl->show_size_column = FALSE;
impl->icon_size = FALLBACK_ICON_SIZE; impl->icon_size = FALLBACK_ICON_SIZE;
impl->load_state = LOAD_EMPTY; impl->load_state = LOAD_EMPTY;
impl->reload_state = RELOAD_EMPTY; impl->reload_state = RELOAD_EMPTY;
@ -4094,6 +4093,18 @@ show_hidden_toggled_cb (GtkCheckMenuItem *item,
NULL); NULL);
} }
/* Callback used when the "Show Size Column" menu item is toggled */
static void
show_size_column_toggled_cb (GtkCheckMenuItem *item,
GtkFileChooserDefault *impl)
{
impl->show_size_column = gtk_check_menu_item_get_active (item);
if (impl->list_size_column)
gtk_tree_view_column_set_visible (impl->list_size_column,
impl->show_size_column);
}
/* Shows an error dialog about not being able to select a dragged file */ /* Shows an error dialog about not being able to select a dragged file */
static void static void
error_selecting_dragged_file_dialog (GtkFileChooserDefault *impl, error_selecting_dragged_file_dialog (GtkFileChooserDefault *impl,
@ -4297,6 +4308,13 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl)
G_CALLBACK (show_hidden_toggled_cb), impl); G_CALLBACK (show_hidden_toggled_cb), impl);
gtk_widget_show (item); gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
item = gtk_check_menu_item_new_with_mnemonic (_("Show _Size Column"));
impl->browse_files_popup_menu_size_column_item = item;
g_signal_connect (item, "toggled",
G_CALLBACK (show_size_column_toggled_cb), impl);
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
} }
/* Updates the popup menu for the file list, creating it if necessary */ /* Updates the popup menu for the file list, creating it if necessary */
@ -4311,12 +4329,21 @@ file_list_update_popup_menu (GtkFileChooserDefault *impl)
* bookmarks_check_add_sensitivity() * bookmarks_check_add_sensitivity()
*/ */
/* 'Show Hidden Files' */
g_signal_handlers_block_by_func (impl->browse_files_popup_menu_hidden_files_item, g_signal_handlers_block_by_func (impl->browse_files_popup_menu_hidden_files_item,
G_CALLBACK (show_hidden_toggled_cb), impl); G_CALLBACK (show_hidden_toggled_cb), impl);
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_hidden_files_item), gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_hidden_files_item),
impl->show_hidden); impl->show_hidden);
g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_hidden_files_item, g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_hidden_files_item,
G_CALLBACK (show_hidden_toggled_cb), impl); G_CALLBACK (show_hidden_toggled_cb), impl);
/* 'Show Size Column' */
g_signal_handlers_block_by_func (impl->browse_files_popup_menu_size_column_item,
G_CALLBACK (show_size_column_toggled_cb), impl);
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_size_column_item),
impl->show_size_column);
g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_size_column_item,
G_CALLBACK (show_size_column_toggled_cb), impl);
} }
static void static void
@ -4410,15 +4437,16 @@ list_button_press_event_cb (GtkWidget *widget,
static void static void
file_list_set_sort_column_ids (GtkFileChooserDefault *impl) file_list_set_sort_column_ids (GtkFileChooserDefault *impl)
{ {
int name_id, mtime_id; int name_id, mtime_id, size_id;
name_id = mtime_id = 0; name_id = mtime_id = size_id = 0;
switch (impl->operation_mode) switch (impl->operation_mode)
{ {
case OPERATION_MODE_BROWSE: case OPERATION_MODE_BROWSE:
name_id = FILE_LIST_COL_NAME; name_id = FILE_LIST_COL_NAME;
mtime_id = FILE_LIST_COL_MTIME; mtime_id = FILE_LIST_COL_MTIME;
size_id = FILE_LIST_COL_SIZE;
break; break;
case OPERATION_MODE_SEARCH: case OPERATION_MODE_SEARCH:
name_id = SEARCH_MODEL_COL_FILE; name_id = SEARCH_MODEL_COL_FILE;
@ -4432,6 +4460,7 @@ file_list_set_sort_column_ids (GtkFileChooserDefault *impl)
gtk_tree_view_column_set_sort_column_id (impl->list_name_column, name_id); gtk_tree_view_column_set_sort_column_id (impl->list_name_column, name_id);
gtk_tree_view_column_set_sort_column_id (impl->list_mtime_column, mtime_id); gtk_tree_view_column_set_sort_column_id (impl->list_mtime_column, mtime_id);
gtk_tree_view_column_set_sort_column_id (impl->list_size_column, size_id);
} }
static gboolean static gboolean
@ -4604,7 +4633,7 @@ create_file_list (GtkFileChooserDefault *impl)
list_name_data_func, impl, NULL); list_name_data_func, impl, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), impl->list_name_column); gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), impl->list_name_column);
#if 0
/* Size column */ /* Size column */
column = gtk_tree_view_column_new (); column = gtk_tree_view_column_new ();
@ -4616,7 +4645,7 @@ create_file_list (GtkFileChooserDefault *impl)
list_size_data_func, impl, NULL); list_size_data_func, impl, NULL);
gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_SIZE); gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_SIZE);
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column); gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column);
#endif impl->list_size_column = column;
/* Modification time column */ /* Modification time column */
@ -5949,12 +5978,14 @@ settings_load (GtkFileChooserDefault *impl)
LocationMode location_mode; LocationMode location_mode;
gboolean show_hidden; gboolean show_hidden;
gboolean expand_folders; gboolean expand_folders;
gboolean show_size_column;
settings = _gtk_file_chooser_settings_new (); settings = _gtk_file_chooser_settings_new ();
location_mode = _gtk_file_chooser_settings_get_location_mode (settings); location_mode = _gtk_file_chooser_settings_get_location_mode (settings);
show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings); show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings);
expand_folders = _gtk_file_chooser_settings_get_expand_folders (settings); expand_folders = _gtk_file_chooser_settings_get_expand_folders (settings);
show_size_column = _gtk_file_chooser_settings_get_show_size_column (settings);
g_object_unref (settings); g_object_unref (settings);
@ -5963,6 +5994,9 @@ settings_load (GtkFileChooserDefault *impl)
impl->expand_folders = expand_folders; impl->expand_folders = expand_folders;
if (impl->save_expander) if (impl->save_expander)
gtk_expander_set_expanded (GTK_EXPANDER (impl->save_expander), expand_folders); gtk_expander_set_expanded (GTK_EXPANDER (impl->save_expander), expand_folders);
impl->show_size_column = show_size_column;
if (impl->list_size_column)
gtk_tree_view_column_set_visible (impl->list_size_column, show_size_column);
} }
static void static void
@ -8856,6 +8890,8 @@ search_switch_to_browse_mode (GtkFileChooserDefault *impl)
gtk_widget_show (impl->location_entry_box); gtk_widget_show (impl->location_entry_box);
} }
gtk_tree_view_column_set_visible (impl->list_size_column, impl->show_size_column);
impl->operation_mode = OPERATION_MODE_BROWSE; impl->operation_mode = OPERATION_MODE_BROWSE;
file_list_set_sort_column_ids (impl); file_list_set_sort_column_ids (impl);
@ -9215,6 +9251,9 @@ search_setup_widgets (GtkFileChooserDefault *impl)
gtk_widget_hide (impl->browse_path_bar); gtk_widget_hide (impl->browse_path_bar);
gtk_widget_hide (impl->browse_new_folder_button); gtk_widget_hide (impl->browse_new_folder_button);
/* hide the file size column if it's visible */
gtk_tree_view_column_set_visible (impl->list_size_column, FALSE);
/* Box for search widgets */ /* Box for search widgets */
gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->search_hbox, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->search_hbox, TRUE, TRUE, 0);
gtk_widget_show_all (impl->search_hbox); gtk_widget_show_all (impl->search_hbox);
@ -9367,6 +9406,8 @@ recent_switch_to_browse_mode (GtkFileChooserDefault *impl)
gtk_widget_show (impl->location_entry_box); gtk_widget_show (impl->location_entry_box);
} }
gtk_tree_view_column_set_visible (impl->list_size_column, impl->show_size_column);
impl->operation_mode = OPERATION_MODE_BROWSE; impl->operation_mode = OPERATION_MODE_BROWSE;
file_list_set_sort_column_ids (impl); file_list_set_sort_column_ids (impl);
@ -9930,6 +9971,10 @@ recent_activate (GtkFileChooserDefault *impl)
} }
recent_hide_entry (impl); recent_hide_entry (impl);
/* hide the file size column if it's visible */
gtk_tree_view_column_set_visible (impl->list_size_column, FALSE);
file_list_set_sort_column_ids (impl); file_list_set_sort_column_ids (impl);
recent_start_loading (impl); recent_start_loading (impl);
} }
@ -10804,7 +10849,6 @@ list_name_data_func (GtkTreeViewColumn *tree_column,
NULL); NULL);
} }
#if 0
static void static void
list_size_data_func (GtkTreeViewColumn *tree_column, list_size_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell, GtkCellRenderer *cell,
@ -10813,10 +10857,17 @@ list_size_data_func (GtkTreeViewColumn *tree_column,
gpointer data) gpointer data)
{ {
GtkFileChooserDefault *impl = data; GtkFileChooserDefault *impl = data;
GFileInfo *info = get_list_file_info (impl, iter); GFileInfo *info;
gint64 size; goffset size;
gchar *str; gchar *str;
gboolean sensitive = TRUE; gboolean sensitive;
if (impl->operation_mode == OPERATION_MODE_SEARCH ||
impl->operation_mode == OPERATION_MODE_RECENT)
return;
info = get_list_file_info (impl, iter);
sensitive = TRUE;
if (!info || g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) if (!info || g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
{ {
@ -10827,18 +10878,9 @@ list_size_data_func (GtkTreeViewColumn *tree_column,
return; return;
} }
size = gtk_file_info_get_size (info); size = g_file_info_get_size (info);
#if 0 str = g_format_size_for_display (size);
if (size < (gint64)1024)
str = g_strdup_printf (g_dngettext (GETTEXT_DOMAIN, "%d byte", "%d bytes", (gint)size), (gint)size);
else if (size < (gint64)1024*1024)
str = g_strdup_printf (_("%.1f KB"), size / (1024.));
else if (size < (gint64)1024*1024*1024)
str = g_strdup_printf (_("%.1f MB"), size / (1024.*1024.));
else
str = g_strdup_printf (_("%.1f GB"), size / (1024.*1024.*1024.));
#endif
str = g_strdup_printf ("%" G_GINT64_FORMAT, size);
if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER || if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
sensitive = FALSE; sensitive = FALSE;
@ -10851,7 +10893,6 @@ list_size_data_func (GtkTreeViewColumn *tree_column,
g_free (str); g_free (str);
} }
#endif
/* Tree column data callback for the file list; fetches the mtime of a file */ /* Tree column data callback for the file list; fetches the mtime of a file */
static void static void

View File

@ -178,6 +178,7 @@ struct _GtkFileChooserDefault
GtkWidget *browse_files_popup_menu; GtkWidget *browse_files_popup_menu;
GtkWidget *browse_files_popup_menu_add_shortcut_item; GtkWidget *browse_files_popup_menu_add_shortcut_item;
GtkWidget *browse_files_popup_menu_hidden_files_item; GtkWidget *browse_files_popup_menu_hidden_files_item;
GtkWidget *browse_files_popup_menu_size_column_item;
GtkWidget *browse_new_folder_button; GtkWidget *browse_new_folder_button;
GtkWidget *browse_path_bar_hbox; GtkWidget *browse_path_bar_hbox;
GtkWidget *browse_path_bar; GtkWidget *browse_path_bar;
@ -267,6 +268,7 @@ struct _GtkFileChooserDefault
GtkTreeViewColumn *list_name_column; GtkTreeViewColumn *list_name_column;
GtkCellRenderer *list_name_renderer; GtkCellRenderer *list_name_renderer;
GtkTreeViewColumn *list_mtime_column; GtkTreeViewColumn *list_mtime_column;
GtkTreeViewColumn *list_size_column;
GSource *edited_idle; GSource *edited_idle;
char *edited_new_text; char *edited_new_text;
@ -298,6 +300,7 @@ struct _GtkFileChooserDefault
guint has_desktop : 1; guint has_desktop : 1;
guint has_search : 1; guint has_search : 1;
guint has_recent : 1; guint has_recent : 1;
guint show_size_column : 1;
#if 0 #if 0
guint shortcuts_drag_outside : 1; guint shortcuts_drag_outside : 1;

View File

@ -41,6 +41,7 @@
#define LOCATION_MODE_KEY "LocationMode" #define LOCATION_MODE_KEY "LocationMode"
#define SHOW_HIDDEN_KEY "ShowHidden" #define SHOW_HIDDEN_KEY "ShowHidden"
#define EXPAND_FOLDERS_KEY "ExpandFolders" #define EXPAND_FOLDERS_KEY "ExpandFolders"
#define SHOW_SIZE_COLUMN_KEY "ShowSizeColumn"
#define MODE_PATH_BAR "path-bar" #define MODE_PATH_BAR "path-bar"
#define MODE_FILENAME_ENTRY "filename-entry" #define MODE_FILENAME_ENTRY "filename-entry"
@ -59,6 +60,22 @@ get_config_filename (void)
return g_build_filename (g_get_user_config_dir (), "gtk-2.0", "gtkfilechooser.ini", NULL); return g_build_filename (g_get_user_config_dir (), "gtk-2.0", "gtkfilechooser.ini", NULL);
} }
static void
warn_if_invalid_key_and_clear_error (const gchar *key,
GError **error)
{
if (error && *error)
{
if ((*error)->domain == G_KEY_FILE_ERROR &&
(*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND)
g_warning ("Failed to read '%s' setting in filechooser settings: %s",
key,
(*error)->message);
g_clear_error (error);
}
}
static void static void
ensure_settings_read (GtkFileChooserSettings *settings) ensure_settings_read (GtkFileChooserSettings *settings)
{ {
@ -108,25 +125,24 @@ ensure_settings_read (GtkFileChooserSettings *settings)
value = g_key_file_get_boolean (key_file, SETTINGS_GROUP, value = g_key_file_get_boolean (key_file, SETTINGS_GROUP,
SHOW_HIDDEN_KEY, &error); SHOW_HIDDEN_KEY, &error);
if (error) if (error)
{ warn_if_invalid_key_and_clear_error (SHOW_HIDDEN_KEY, &error);
g_warning ("Failed to read show-hidden setting in filechooser settings: %s",
error->message);
g_clear_error (&error);
}
else else
settings->show_hidden = value != FALSE; settings->show_hidden = value != FALSE;
value = g_key_file_get_boolean (key_file, SETTINGS_GROUP, value = g_key_file_get_boolean (key_file, SETTINGS_GROUP,
EXPAND_FOLDERS_KEY, &error); EXPAND_FOLDERS_KEY, &error);
if (error) if (error)
{ warn_if_invalid_key_and_clear_error (EXPAND_FOLDERS_KEY, &error);
g_warning ("Failed to read expand-folders setting in filechooser settings: %s",
error->message);
g_clear_error (&error);
}
else else
settings->expand_folders = value != FALSE; settings->expand_folders = value != FALSE;
value = g_key_file_get_boolean (key_file, SETTINGS_GROUP,
SHOW_SIZE_COLUMN_KEY, &error);
if (error)
warn_if_invalid_key_and_clear_error (SHOW_SIZE_COLUMN_KEY, &error);
else
settings->show_size_column = value != FALSE;
out: out:
g_key_file_free (key_file); g_key_file_free (key_file);
@ -148,6 +164,7 @@ _gtk_file_chooser_settings_init (GtkFileChooserSettings *settings)
settings->location_mode = LOCATION_MODE_PATH_BAR; settings->location_mode = LOCATION_MODE_PATH_BAR;
settings->show_hidden = FALSE; settings->show_hidden = FALSE;
settings->expand_folders = FALSE; settings->expand_folders = FALSE;
settings->show_size_column = FALSE;
} }
GtkFileChooserSettings * GtkFileChooserSettings *
@ -191,6 +208,20 @@ _gtk_file_chooser_settings_get_expand_folders (GtkFileChooserSettings *settings)
return settings->expand_folders; return settings->expand_folders;
} }
void
_gtk_file_chooser_settings_set_show_size_column (GtkFileChooserSettings *settings,
gboolean show_column)
{
settings->show_size_column = show_column != FALSE;
}
gboolean
_gtk_file_chooser_settings_get_show_size_column (GtkFileChooserSettings *settings)
{
ensure_settings_read (settings);
return settings->show_size_column;
}
void void
_gtk_file_chooser_settings_set_expand_folders (GtkFileChooserSettings *settings, _gtk_file_chooser_settings_set_expand_folders (GtkFileChooserSettings *settings,
gboolean expand_folders) gboolean expand_folders)
@ -238,6 +269,8 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
SHOW_HIDDEN_KEY, settings->show_hidden); SHOW_HIDDEN_KEY, settings->show_hidden);
g_key_file_set_boolean (key_file, SETTINGS_GROUP, g_key_file_set_boolean (key_file, SETTINGS_GROUP,
EXPAND_FOLDERS_KEY, settings->expand_folders); EXPAND_FOLDERS_KEY, settings->expand_folders);
g_key_file_set_boolean (key_file, SETTINGS_GROUP,
SHOW_SIZE_COLUMN_KEY, settings->show_size_column);
contents = g_key_file_to_data (key_file, &len, error); contents = g_key_file_to_data (key_file, &len, error);
g_key_file_free (key_file); g_key_file_free (key_file);

View File

@ -38,11 +38,10 @@ struct _GtkFileChooserSettings
LocationMode location_mode; LocationMode location_mode;
guint settings_read : 1; guint settings_read : 1;
guint show_hidden : 1;
guint show_hidden : 1; guint show_size_column : 1;
guint expand_folders : 1;
guint expand_folders : 1;
}; };
struct _GtkFileChooserSettingsClass struct _GtkFileChooserSettingsClass
@ -66,6 +65,10 @@ gboolean _gtk_file_chooser_settings_get_expand_folders (GtkFileChooserSettings *
void _gtk_file_chooser_settings_set_expand_folders (GtkFileChooserSettings *settings, void _gtk_file_chooser_settings_set_expand_folders (GtkFileChooserSettings *settings,
gboolean expand_folders); gboolean expand_folders);
gboolean _gtk_file_chooser_settings_get_show_size_column (GtkFileChooserSettings *settings);
void _gtk_file_chooser_settings_set_show_size_column (GtkFileChooserSettings *settings,
gboolean show_column);
gboolean _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, gboolean _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
GError **error); GError **error);