Commit 34b64f3a authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

use GFile instead of 'char *'

parent de08f40a
......@@ -76,7 +76,7 @@ open_file_response_cb (GtkWidget *w,
GtkWidget *file_sel)
{
FrWindow *window = NULL;
char *uri;
GFile *file;
if ((response == GTK_RESPONSE_CANCEL) || (response == GTK_RESPONSE_DELETE_EVENT)) {
gtk_widget_destroy (file_sel);
......@@ -84,9 +84,9 @@ open_file_response_cb (GtkWidget *w,
}
window = g_object_get_data (G_OBJECT (file_sel), "fr_window");
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (file_sel));
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (file_sel));
if ((window == NULL) || (uri == NULL))
if ((window == NULL) || (file == NULL))
return;
if (fr_window_archive_is_present (window))
......@@ -95,9 +95,9 @@ open_file_response_cb (GtkWidget *w,
"archive_loaded",
G_CALLBACK (window_archive_loaded_cb),
file_sel);
fr_window_archive_open (window, uri, GTK_WINDOW (file_sel));
fr_window_archive_open (window, file, GTK_WINDOW (file_sel));
g_free (uri);
g_object_unref (file);
}
......@@ -118,7 +118,7 @@ activate_action_open (GtkAction *action,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (file_sel), GTK_RESPONSE_OK);
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (file_sel), FALSE);
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (file_sel), fr_window_get_open_default_dir (window));
gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (file_sel), fr_window_get_open_default_dir (window), NULL);
_gtk_dialog_add_to_window_group (GTK_DIALOG (file_sel));
gtk_window_set_modal (GTK_WINDOW (file_sel), TRUE);
......
......@@ -57,44 +57,50 @@ file_sel_response_cb (GtkWidget *widget,
{
GtkFileChooser *file_sel = GTK_FILE_CHOOSER (widget);
FrWindow *window = data->window;
char *current_folder;
char *uri;
GFile *current_folder;
GFile *file;
gboolean update;
GSList *selections, *iter;
GList *item_list = NULL;
GList *file_list = NULL;
current_folder = gtk_file_chooser_get_current_folder_uri (file_sel);
uri = gtk_file_chooser_get_uri (file_sel);
current_folder = gtk_file_chooser_get_current_folder_file (file_sel);
file = gtk_file_chooser_get_file (file_sel);
if (current_folder != NULL) {
g_settings_set_string (data->settings, PREF_ADD_CURRENT_FOLDER, current_folder);
char *uri = g_file_get_uri (current_folder);
g_settings_set_string (data->settings, PREF_ADD_CURRENT_FOLDER, uri);
fr_window_set_add_default_dir (window, current_folder);
g_free (uri);
}
if (uri != NULL) {
if (file != NULL) {
char *uri = g_file_get_uri (file);
g_settings_set_string (data->settings, PREF_ADD_FILENAME, uri);
g_free (uri);
}
if ((response == GTK_RESPONSE_CANCEL) || (response == GTK_RESPONSE_DELETE_EVENT)) {
gtk_widget_destroy (data->dialog);
g_free (current_folder);
_g_object_unref (current_folder);
_g_object_unref (file);
return TRUE;
}
if (response == GTK_RESPONSE_HELP) {
_gtk_show_help_dialog (GTK_WINDOW (data->dialog), "archive-edit");
g_free (current_folder);
_g_object_unref (current_folder);
_g_object_unref (file);
return TRUE;
}
/* check folder permissions. */
if (_g_uri_query_is_dir (current_folder) && ! _g_uri_check_permissions (current_folder, R_OK)) {
if (_g_file_query_is_dir (current_folder) && ! _g_file_check_permissions (current_folder, R_OK)) {
GtkWidget *d;
char *utf8_path;
utf8_path = g_filename_display_name (current_folder);
utf8_path = g_file_get_parse_name (current_folder);
d = _gtk_error_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_MODAL,
NULL,
......@@ -116,16 +122,17 @@ file_sel_response_cb (GtkWidget *widget,
selections = gtk_file_chooser_get_uris (file_sel);
for (iter = selections; iter != NULL; iter = iter->next) {
char *uri = iter->data;
item_list = g_list_prepend (item_list, g_file_new_for_uri (uri));
file_list = g_list_prepend (file_list, g_file_new_for_uri (uri));
}
if (item_list != NULL)
fr_window_archive_add_files (window, item_list, update);
if (file_list != NULL)
fr_window_archive_add_files (window, file_list, current_folder, update);
_g_file_list_free (item_list);
_g_file_list_free (file_list);
g_slist_foreach (selections, (GFunc) g_free, NULL);
g_slist_free (selections);
g_free (current_folder);
_g_object_unref (current_folder);
_g_object_unref (file);
gtk_widget_destroy (data->dialog);
......@@ -178,7 +185,7 @@ add_files_cb (GtkWidget *widget,
folder = g_settings_get_string (data->settings, PREF_ADD_CURRENT_FOLDER);
if ((folder == NULL) || (strcmp (folder, "") == 0))
folder = g_strdup (fr_window_get_add_default_dir (data->window));
folder = g_file_get_uri (fr_window_get_add_default_dir (data->window));
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (file_sel), folder);
g_free (folder);
......
......@@ -90,14 +90,13 @@ file_sel_response_cb (GtkWidget *widget,
{
GtkFileChooser *file_sel = GTK_FILE_CHOOSER (widget);
FrWindow *window = data->window;
char *selected_folder;
GFile *selected_folder;
gboolean update, follow_links;
const char *include_files;
const char *exclude_files;
const char *exclude_folders;
char *dest_dir;
char *local_filename;
char *folder_basename;
dlg_add_folder_save_last_options (data);
......@@ -111,15 +110,15 @@ file_sel_response_cb (GtkWidget *widget,
return TRUE;
}
selected_folder = gtk_file_chooser_get_uri (file_sel);
selected_folder = gtk_file_chooser_get_file (file_sel);
/* check folder permissions. */
if (! _g_uri_check_permissions (selected_folder, R_OK)) {
if (! _g_file_check_permissions (selected_folder, R_OK)) {
GtkWidget *d;
char *utf8_path;
utf8_path = g_filename_display_name (selected_folder);
utf8_path = g_file_get_parse_name (selected_folder);
d = _gtk_error_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_MODAL,
......@@ -131,7 +130,7 @@ file_sel_response_cb (GtkWidget *widget,
gtk_widget_destroy (GTK_WIDGET (d));
g_free (utf8_path);
g_free (selected_folder);
g_object_unref (selected_folder);
return FALSE;
}
......@@ -151,23 +150,23 @@ file_sel_response_cb (GtkWidget *widget,
if (utf8_only_spaces (exclude_folders))
exclude_folders = NULL;
local_filename = g_filename_from_uri (selected_folder, NULL, NULL);
dest_dir = _g_uri_build (fr_window_get_current_location (window),
_g_path_get_file_name (local_filename),
NULL);
fr_window_archive_add_with_wildcard (window,
include_files,
exclude_files,
exclude_folders,
selected_folder,
dest_dir,
update,
follow_links);
g_free (local_filename);
folder_basename = g_file_get_basename (selected_folder);
dest_dir = g_build_filename (fr_window_get_current_location (window),
folder_basename,
NULL);
fr_window_archive_add_with_filter (window,
selected_folder,
include_files,
exclude_files,
exclude_folders,
dest_dir,
update,
follow_links);
g_free (dest_dir);
g_free (selected_folder);
g_free (folder_basename);
g_object_unref (selected_folder);
gtk_widget_destroy (data->dialog);
......@@ -353,7 +352,7 @@ add_folder_cb (GtkWidget *widget,
G_CALLBACK (file_sel_response_cb),
data);
gtk_window_set_modal (GTK_WINDOW (file_sel),TRUE);
gtk_window_set_modal (GTK_WINDOW (file_sel), TRUE);
gtk_widget_show (file_sel);
}
......@@ -366,27 +365,27 @@ dlg_add_folder_save_last_used_options (DialogData *data,
const char *options_path)
{
g_free (data->last_options);
data->last_options = g_strdup (_g_path_get_file_name (options_path));
data->last_options = g_strdup (_g_path_get_basename (options_path));
}
static void
sync_widgets_with_options (DialogData *data,
const char *base_dir,
const char *filename,
GFile *directory,
GFile *file,
const char *include_files,
const char *exclude_files,
const char *exclude_folders,
gboolean update,
gboolean no_symlinks)
{
if ((base_dir == NULL) || (strcmp (base_dir, "") == 0))
base_dir = fr_window_get_add_default_dir (data->window);
if (directory == NULL)
directory = fr_window_get_add_default_dir (data->window);
if ((filename != NULL) && (strcmp (filename, base_dir) != 0))
gtk_file_chooser_select_uri (GTK_FILE_CHOOSER (data->dialog), filename);
if ((file != NULL) && ! g_file_equal (file, directory))
gtk_file_chooser_select_file (GTK_FILE_CHOOSER (data->dialog), file, NULL);
else
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (data->dialog), base_dir);
gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (data->dialog), directory, NULL);
if (include_files != NULL)
gtk_entry_set_text (GTK_ENTRY (data->include_files_entry), include_files);
......@@ -403,14 +402,22 @@ static void
clear_options_activate_cb (GtkMenuItem *menu_item,
DialogData *data)
{
GFile *folder;
GFile *file;
folder = gtk_file_chooser_get_current_folder_file (GTK_FILE_CHOOSER (data->dialog));
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (data->dialog));
sync_widgets_with_options (data,
gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (data->dialog)),
gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (data->dialog)),
folder,
file,
"",
"",
"",
FALSE,
FALSE);
_g_object_unref (folder);
_g_object_unref (file);
}
......@@ -430,6 +437,8 @@ dlg_add_folder_load_options (DialogData *data,
char *exclude_folders = NULL;
gboolean update;
gboolean no_symlinks;
GFile *folder;
GFile *file;
options_dir = _g_file_new_user_config_subdir (ADD_FOLDER_OPTIONS_DIR, TRUE);
options_file = g_file_get_child (options_dir, name);
......@@ -446,7 +455,9 @@ dlg_add_folder_load_options (DialogData *data,
}
base_dir = g_key_file_get_string (key_file, "Options", "base_dir", NULL);
folder = g_file_new_for_uri (base_dir);
filename = g_key_file_get_string (key_file, "Options", "filename", NULL);
file = g_file_new_for_uri (filename);
include_files = g_key_file_get_string (key_file, "Options", "include_files", NULL);
exclude_files = g_key_file_get_string (key_file, "Options", "exclude_files", NULL);
exclude_folders = g_key_file_get_string (key_file, "Options", "exclude_folders", NULL);
......@@ -454,8 +465,8 @@ dlg_add_folder_load_options (DialogData *data,
no_symlinks = g_key_file_get_boolean (key_file, "Options", "no_symlinks", NULL);
sync_widgets_with_options (data,
base_dir,
filename,
folder,
file,
include_files,
exclude_files,
exclude_folders,
......@@ -464,6 +475,8 @@ dlg_add_folder_load_options (DialogData *data,
dlg_add_folder_save_last_used_options (data, file_path);
_g_object_unref (file);
_g_object_unref (folder);
g_free (base_dir);
g_free (filename);
g_free (include_files);
......@@ -488,9 +501,13 @@ dlg_add_folder_load_last_options (DialogData *data)
char *exclude_folders = NULL;
gboolean update;
gboolean no_symlinks;
GFile *folder;
GFile *file;
base_dir = g_settings_get_string (data->settings, PREF_ADD_CURRENT_FOLDER);
folder = g_file_new_for_uri (base_dir);
filename = g_settings_get_string (data->settings, PREF_ADD_FILENAME);
file = g_file_new_for_uri (filename);
include_files = g_settings_get_string (data->settings, PREF_ADD_INCLUDE_FILES);
exclude_files = g_settings_get_string (data->settings, PREF_ADD_EXCLUDE_FILES);
exclude_folders = g_settings_get_string (data->settings, PREF_ADD_EXCLUDE_FOLDERS);
......@@ -498,14 +515,16 @@ dlg_add_folder_load_last_options (DialogData *data)
no_symlinks = g_settings_get_boolean (data->settings, PREF_ADD_NO_SYMLINKS);
sync_widgets_with_options (data,
base_dir,
filename,
folder,
file,
include_files,
exclude_files,
exclude_folders,
update,
no_symlinks);
_g_object_unref (file);
_g_object_unref (folder);
g_free (base_dir);
g_free (filename);
g_free (include_files);
......@@ -555,6 +574,7 @@ dlg_add_folder_save_current_options (DialogData *data,
gboolean update;
gboolean no_symlinks;
GKeyFile *key_file;
GFile *base_dir_file;
get_options_from_widgets (data,
&base_dir,
......@@ -565,7 +585,9 @@ dlg_add_folder_save_current_options (DialogData *data,
&update,
&no_symlinks);
fr_window_set_add_default_dir (data->window, base_dir);
base_dir_file = g_file_new_for_uri (base_dir);
fr_window_set_add_default_dir (data->window, base_dir_file);
g_object_unref (base_dir_file);
key_file = g_key_file_new ();
g_key_file_set_string (key_file, "Options", "base_dir", base_dir);
......
......@@ -93,6 +93,7 @@ dlg_ask_password__common (FrWindow *window,
FrPasswordType pwd_type)
{
DialogData *data;
GFile *file;
char *filename;
char *message;
......@@ -113,9 +114,10 @@ dlg_ask_password__common (FrWindow *window,
/* Set widgets data. */
if (data->pwd_type == FR_PASSWORD_TYPE_MAIN)
filename = _g_uri_display_basename (fr_window_get_archive_uri (window));
file = fr_window_get_archive_file (window);
else if (data->pwd_type == FR_PASSWORD_TYPE_PASTE_FROM)
filename = _g_uri_display_basename (fr_window_get_paste_archive_uri (window));
file = fr_window_get_archive_file_for_paste (window);
filename = _g_file_get_display_basename (file);
/* Translators: %s is a filename */
message = g_strdup_printf (_("Password required for \"%s\""), filename);
gtk_label_set_label (GTK_LABEL (_gtk_builder_get_widget (data->builder, "title_label")), message);
......
......@@ -135,8 +135,8 @@ add_clicked_cb (GtkWidget *widget,
{
FrWindow *window = data->window;
char *archive_name;
char *archive_dir;
char *archive_file;
GFile *archive_folder;
GFile *archive_file;
char *tmp;
const char *archive_ext;
const char *mime_type;
......@@ -189,14 +189,13 @@ add_clicked_cb (GtkWidget *widget,
/* Check directory existence. */
archive_dir = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (GET_WIDGET ("a_location_filechooserbutton")));
if (archive_dir == NULL) {
g_free (archive_dir);
archive_folder = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (GET_WIDGET ("a_location_filechooserbutton")));
if (archive_folder == NULL) {
g_free (archive_name);
return;
}
if (! _g_uri_check_permissions (archive_dir, R_OK|W_OK|X_OK)) {
if (! _g_file_check_permissions (archive_folder, R_OK|W_OK|X_OK)) {
GtkWidget *d;
d = _gtk_error_dialog_new (GTK_WINDOW (window),
......@@ -208,18 +207,18 @@ add_clicked_cb (GtkWidget *widget,
gtk_dialog_run (GTK_DIALOG (d));
gtk_widget_destroy (GTK_WIDGET (d));
g_free (archive_dir);
g_object_unref (archive_folder);
g_free (archive_name);
return;
}
if (! _g_uri_query_is_dir (archive_dir)) {
if (! _g_file_query_is_dir (archive_folder)) {
GtkWidget *d;
int r;
char *folder_name;
char *msg;
folder_name = g_filename_display_name (archive_dir);
folder_name = _g_file_get_display_basename (archive_folder);
msg = g_strdup_printf (_("Destination folder \"%s\" does not exist.\n\nDo you want to create it?"), folder_name);
g_free (folder_name);
......@@ -241,7 +240,7 @@ add_clicked_cb (GtkWidget *widget,
do_not_add = (r != GTK_RESPONSE_YES);
}
if (! do_not_add && ! _g_uri_ensure_dir_exists (archive_dir, 0755, &error)) {
if (! do_not_add && ! _g_file_make_directory_tree (archive_folder, 0755, &error)) {
GtkWidget *d;
d = _gtk_error_dialog_new (GTK_WINDOW (window),
......@@ -254,7 +253,7 @@ add_clicked_cb (GtkWidget *widget,
gtk_widget_destroy (GTK_WIDGET (d));
g_error_free (error);
g_free (archive_dir);
g_object_unref (archive_folder);
g_free (archive_name);
return;
}
......@@ -273,7 +272,7 @@ add_clicked_cb (GtkWidget *widget,
gtk_dialog_run (GTK_DIALOG (d));
gtk_widget_destroy (GTK_WIDGET (d));
g_free (archive_dir);
g_object_unref (archive_folder);
g_free (archive_name);
return;
......@@ -287,9 +286,9 @@ add_clicked_cb (GtkWidget *widget,
tmp = archive_name;
archive_name = g_strconcat (tmp, archive_ext, NULL);
g_free (tmp);
archive_file = g_strconcat (archive_dir, "/", archive_name, NULL);
archive_file = g_file_get_child_for_display_name (archive_folder, archive_name, NULL);
if (_g_uri_query_is_dir (archive_file)) {
if (_g_file_query_is_dir (archive_file)) {
GtkWidget *d;
d = _gtk_error_dialog_new (GTK_WINDOW (window),
......@@ -302,13 +301,13 @@ add_clicked_cb (GtkWidget *widget,
gtk_widget_destroy (GTK_WIDGET (d));
g_free (archive_name);
g_free (archive_dir);
g_free (archive_file);
g_object_unref (archive_folder);
g_object_unref (archive_file);
return;
}
if (_g_uri_query_exists (archive_file)) {
if (g_file_query_exists (archive_file, NULL)) {
GtkWidget *d;
int r;
......@@ -326,23 +325,18 @@ add_clicked_cb (GtkWidget *widget,
gtk_widget_destroy (GTK_WIDGET (d));
if (r == GTK_RESPONSE_YES) {
GFile *file;
GError *err = NULL;
file = g_file_new_for_uri (archive_file);
g_file_delete (file, NULL, &err);
g_file_delete (archive_file, NULL, &err);
if (err != NULL) {
g_warning ("Failed to delete file %s: %s",
archive_file,
err->message);
g_warning ("Failed to delete file: %s", err->message);
g_clear_error (&err);
}
g_object_unref (file);
}
else {
g_free (archive_name);
g_free (archive_dir);
g_free (archive_file);
g_object_unref (archive_folder);
g_object_unref (archive_file);
return;
}
}
......@@ -353,8 +347,8 @@ add_clicked_cb (GtkWidget *widget,
fr_window_create_archive_and_continue (window, archive_file, mime_type, NULL);
g_free (archive_name);
g_free (archive_dir);
g_free (archive_file);
g_object_unref (archive_folder);
g_object_unref (archive_file);
}
......@@ -477,8 +471,8 @@ dlg_batch_add_files (FrWindow *window,
GtkSizeGroup *size_group;
char *automatic_name = NULL;
char *default_ext;
const char *first_filename;
char *parent;
GFile *first_file;
GFile *parent;
int i;
if (file_list == NULL)
......@@ -495,7 +489,7 @@ dlg_batch_add_files (FrWindow *window,
data->window = window;
data->file_list = file_list;
data->single_file = ((file_list->next == NULL) && _g_uri_query_is_file ((char*) file_list->data));
data->single_file = ((file_list->next == NULL) && _g_file_query_is_file (G_FILE (file_list->data)));
data->add_clicked = FALSE;
/* Set widgets data. */
......@@ -511,27 +505,23 @@ dlg_batch_add_files (FrWindow *window,
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("a_encrypt_header_checkbutton")), g_settings_get_boolean (data->settings_general, PREF_GENERAL_ENCRYPT_HEADER));
gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("a_volume_spinbutton")), (double) g_settings_get_int (data->settings, PREF_BATCH_ADD_VOLUME_SIZE) / MEGABYTE);
first_filename = (char*) file_list->data;
parent = _g_path_remove_level (first_filename);
first_file = G_FILE (file_list->data);
parent = g_file_get_parent (first_file);
if (file_list->next == NULL)
automatic_name = g_uri_unescape_string (_g_path_get_file_name ((char*) file_list->data), NULL);
else {
automatic_name = g_uri_unescape_string (_g_path_get_file_name (parent), NULL);
if ((automatic_name == NULL) || (automatic_name[0] == '\0')) {
g_free (automatic_name);
automatic_name = g_uri_unescape_string (_g_path_get_file_name (first_filename), NULL);
}
}
automatic_name = g_file_get_basename (first_file);
else
automatic_name = g_file_get_basename (parent);
_gtk_entry_set_filename_text (GTK_ENTRY (GET_WIDGET ("a_add_to_entry")), automatic_name);
g_free (automatic_name);
if (_g_uri_check_permissions (parent, R_OK | W_OK))
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (GET_WIDGET ("a_location_filechooserbutton")), parent);
if (_g_file_check_permissions (parent, R_OK | W_OK))
gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (GET_WIDGET ("a_location_filechooserbutton")), parent, NULL);
else
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (GET_WIDGET ("a_location_filechooserbutton")), _g_uri_get_home ());
g_free (parent);
gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (GET_WIDGET ("a_location_filechooserbutton")), _g_file_get_home (), NULL);
g_object_unref (parent);
/* archive type combobox */
......
......@@ -74,7 +74,7 @@ extract_cb (GtkWidget *w,
{
FrWindow *window = data->window;
gboolean do_not_extract = FALSE;
char *extract_to_dir;
GFile *destination;
gboolean overwrite;
gboolean skip_newer;
gboolean selected_files;
......@@ -88,18 +88,18 @@ extract_cb (GtkWidget *w,
/* collect extraction options. */
extract_to_dir = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (data->dialog));
destination = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (data->dialog));
/* check directory existence. */
if (! _g_uri_query_is_dir (extract_to_dir)) {
if (! _g_file_query_is_dir (destination)) {
if (! ForceDirectoryCreation) {
GtkWidget *d;
int r;
char *folder_name;
char *msg;
folder_name = g_filename_display_name (extract_to_dir);
folder_name = _g_file_get_display_basename (destination);