Commit de9d0ad7 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

Implemented create / rename / delete / cut / copy folder commands

parent db25573c
......@@ -175,7 +175,7 @@ void
gth_browser_activate_action_catalog_new (GtkAction *action,
GthBrowser *browser)
{
GFile *selected_parent;
GthFileData *selected_parent;
GFile *parent;
GthFileSource *file_source;
GFile *gio_parent;
......@@ -187,12 +187,12 @@ gth_browser_activate_action_catalog_new (GtkAction *action,
GthFileSource *file_source;
GFileInfo *info;
file_source = gth_main_get_file_source (selected_parent);
info = gth_file_source_get_file_info (file_source, selected_parent);
file_source = gth_main_get_file_source (selected_parent->file);
info = gth_file_source_get_file_info (file_source, selected_parent->file, GFILE_BASIC_ATTRIBUTES);
if (g_file_info_get_attribute_boolean (info, "gthumb::no-child"))
parent = g_file_get_parent (selected_parent);
parent = g_file_get_parent (selected_parent->file);
else
parent = g_file_dup (selected_parent);
parent = g_file_dup (selected_parent->file);
g_object_unref (info);
g_object_unref (file_source);
......@@ -202,16 +202,16 @@ gth_browser_activate_action_catalog_new (GtkAction *action,
file_source = gth_main_get_file_source (parent);
gio_parent = gth_file_source_to_gio_file (file_source, parent);
gio_file = _g_file_create_unique (gio_parent, _("New Catalog"), ".catalog", &error);
gio_file = _g_file_create_unique (gio_parent, _("untitled catalog"), ".catalog", &error);
if (gio_file != NULL) {
GFile *file;
GList *list;
GFileInfo *info;
GthFileData *file_data;
GList *file_data_list;
GFile *file;
GList *list;
GFileInfo *info;
GthFileData *file_data;
GList *file_data_list;
file = gth_catalog_file_from_gio_file (gio_file, NULL);
info = gth_file_source_get_file_info (file_source, file);
info = gth_file_source_get_file_info (file_source, file, GFILE_BASIC_ATTRIBUTES ",access::*");
file_data = gth_file_data_new (file, info);
file_data_list = g_list_prepend (NULL, file_data);
gth_folder_tree_add_children (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)), parent, file_data_list);
......@@ -242,11 +242,11 @@ void
gth_browser_activate_action_catalog_new_library (GtkAction *action,
GthBrowser *browser)
{
GFile *selected_parent;
GthFileData *selected_parent;
GFile *parent;
GthFileSource *file_source;
GFile *gio_parent;
GError *error;
GError *error = NULL;
GFile *gio_file;
selected_parent = gth_folder_tree_get_selected_or_parent (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)));
......@@ -254,12 +254,12 @@ gth_browser_activate_action_catalog_new_library (GtkAction *action,
GthFileSource *file_source;
GFileInfo *info;
file_source = gth_main_get_file_source (selected_parent);
info = gth_file_source_get_file_info (file_source, selected_parent);
file_source = gth_main_get_file_source (selected_parent->file);
info = gth_file_source_get_file_info (file_source, selected_parent->file, GFILE_BASIC_ATTRIBUTES);
if (g_file_info_get_attribute_boolean (info, "gthumb::no-child"))
parent = g_file_get_parent (selected_parent);
parent = g_file_get_parent (selected_parent->file);
else
parent = g_file_dup (selected_parent);
parent = g_file_dup (selected_parent->file);
g_object_unref (info);
g_object_unref (file_source);
......@@ -269,7 +269,7 @@ gth_browser_activate_action_catalog_new_library (GtkAction *action,
file_source = gth_main_get_file_source (parent);
gio_parent = gth_file_source_to_gio_file (file_source, parent);
gio_file = _g_directory_create_unique (gio_parent, _("New Library"), "", &error);
gio_file = _g_directory_create_unique (gio_parent, _("untitled library"), "", &error);
if (gio_file != NULL) {
GFile *file;
GList *list;
......@@ -278,7 +278,7 @@ gth_browser_activate_action_catalog_new_library (GtkAction *action,
GList *file_data_list;
file = gth_catalog_file_from_gio_file (gio_file, NULL);
info = gth_file_source_get_file_info (file_source, file);
info = gth_file_source_get_file_info (file_source, file, GFILE_BASIC_ATTRIBUTES ",access::*");
file_data = gth_file_data_new (file, info);
file_data_list = g_list_prepend (NULL, file_data);
gth_folder_tree_add_children (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)), parent, file_data_list);
......@@ -310,27 +310,26 @@ gth_browser_activate_action_catalog_remove (GtkAction *action,
GthBrowser *browser)
{
GthFolderTree *folder_tree;
GFile *file;
GthFileData *file_data;
GFile *gio_file;
GError *error = NULL;
folder_tree = GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser));
file = gth_folder_tree_get_selected (folder_tree);
gio_file = gth_main_get_gio_file (file);
file_data = gth_folder_tree_get_selected (folder_tree);
gio_file = gth_main_get_gio_file (file_data->file);
if (g_file_delete (gio_file, NULL, &error)) {
GFile *parent;
GList *files;
parent = g_file_get_parent (file);
files = g_list_prepend (NULL, g_object_ref (file));
parent = g_file_get_parent (file_data->file);
files = g_list_prepend (NULL, g_object_ref (file_data->file));
gth_monitor_folder_changed (gth_main_get_default_monitor (),
parent,
files,
GTH_MONITOR_EVENT_DELETED);
_g_object_list_unref (files);
if (parent != NULL)
g_object_unref (parent);
_g_object_unref (parent);
}
else
_gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser),
......@@ -338,7 +337,7 @@ gth_browser_activate_action_catalog_remove (GtkAction *action,
&error);
g_object_unref (gio_file);
g_object_unref (file);
g_object_unref (file_data);
}
......@@ -347,11 +346,11 @@ gth_browser_activate_action_catalog_rename (GtkAction *action,
GthBrowser *browser)
{
GthFolderTree *folder_tree;
GFile *file;
GthFileData *file_data;
folder_tree = GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser));
file = gth_folder_tree_get_selected (folder_tree);
gth_folder_tree_start_editing (folder_tree, file);
file_data = gth_folder_tree_get_selected (folder_tree);
gth_folder_tree_start_editing (folder_tree, file_data->file);
g_object_unref (file);
g_object_unref (file_data);
}
......@@ -168,7 +168,7 @@ catalogs__gth_browser_update_sensitivity_cb (GthBrowser *browser)
void
catalogs__gth_browser_folder_tree_popup_before_cb (GthBrowser *browser,
GthFileSource *file_source,
GFile *folder)
GthFileData *folder)
{
BrowserData *data;
......@@ -190,11 +190,11 @@ catalogs__gth_browser_folder_tree_popup_before_cb (GthBrowser *browser,
}
action = gtk_action_group_get_action (data->actions, "Catalog_Remove");
sensitive = folder != NULL;
sensitive = (folder != NULL) && g_file_info_get_attribute_boolean (folder->info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE);
g_object_set (action, "sensitive", sensitive, NULL);
action = gtk_action_group_get_action (data->actions, "Catalog_Rename");
sensitive = folder != NULL;
sensitive = (folder != NULL) && g_file_info_get_attribute_boolean (folder->info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME);
g_object_set (action, "sensitive", sensitive, NULL);
}
else {
......
......@@ -63,20 +63,11 @@ static GthFileData *
get_selected_catalog (DialogData *data)
{
GthFileData *file_data = NULL;
GFile *file;
file = gth_folder_tree_get_selected_or_parent (GTH_FOLDER_TREE (data->source_tree));
if (file != NULL) {
GthFileSource *file_source;
GFileInfo *info;
file_source = gth_main_get_file_source (file);
info = gth_file_source_get_file_info (file_source, file);
if (g_file_info_get_attribute_boolean (info, "gthumb::no-child"))
file_data = gth_file_data_new (file, info);
g_object_unref (info);
g_object_unref (file);
file_data = gth_folder_tree_get_selected_or_parent (GTH_FOLDER_TREE (data->source_tree));
if (! g_file_info_get_attribute_boolean (file_data->info, "gthumb::no-child")) {
_g_object_unref (file_data);
file_data = NULL;
}
return file_data;
......@@ -185,7 +176,7 @@ get_catalog_parent (GFile *selected_parent)
GFileInfo *info;
file_source = gth_main_get_file_source (selected_parent);
info = gth_file_source_get_file_info (file_source, selected_parent);
info = gth_file_source_get_file_info (file_source, selected_parent, GFILE_BASIC_ATTRIBUTES);
if ((g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) &&
! g_file_info_get_attribute_boolean (info, "gthumb::no-child"))
{
......@@ -208,7 +199,7 @@ static void
new_catalog_button_clicked_cb (GtkWidget *widget,
DialogData *data)
{
GFile *selected_parent;
GthFileData *selected_parent;
GFile *parent;
GthFileSource *file_source;
GFile *gio_parent;
......@@ -220,12 +211,12 @@ new_catalog_button_clicked_cb (GtkWidget *widget,
GthFileSource *file_source;
GFileInfo *info;
file_source = gth_main_get_file_source (selected_parent);
info = gth_file_source_get_file_info (file_source, selected_parent);
file_source = gth_main_get_file_source (selected_parent->file);
info = gth_file_source_get_file_info (file_source, selected_parent->file, GFILE_BASIC_ATTRIBUTES);
if (g_file_info_get_attribute_boolean (info, "gthumb::no-child"))
parent = g_file_get_parent (selected_parent);
parent = g_file_get_parent (selected_parent->file);
else
parent = g_file_dup (selected_parent);
parent = g_file_dup (selected_parent->file);
g_object_unref (info);
g_object_unref (file_source);
......@@ -244,7 +235,7 @@ new_catalog_button_clicked_cb (GtkWidget *widget,
GList *file_data_list;
file = gth_catalog_file_from_gio_file (gio_file, NULL);
info = gth_file_source_get_file_info (file_source, file);
info = gth_file_source_get_file_info (file_source, file, GFILE_BASIC_ATTRIBUTES);
file_data = gth_file_data_new (file, info);
file_data_list = g_list_prepend (NULL, file_data);
gth_folder_tree_add_children (GTH_FOLDER_TREE (data->source_tree), parent, file_data_list);
......@@ -275,11 +266,11 @@ static void
new_library_button_clicked_cb (GtkWidget *widget,
DialogData *data)
{
char *display_name;
GFile *selected_catalog;
GFile *parent;
GFile *new_library;
GError *error = NULL;
char *display_name;
GthFileData *selected_catalog;
GFile *parent;
GFile *new_library;
GError *error = NULL;
display_name = _gtk_request_dialog_run (GTK_WINDOW (data->dialog),
GTK_DIALOG_MODAL,
......@@ -292,7 +283,7 @@ new_library_button_clicked_cb (GtkWidget *widget,
return;
selected_catalog = gth_folder_tree_get_selected (GTH_FOLDER_TREE (data->source_tree));
parent = get_catalog_parent (selected_catalog);
parent = get_catalog_parent (selected_catalog->file);
new_library = g_file_get_child_for_display_name (parent, display_name, &error);
if ((new_library != NULL) && (strchr (display_name, '/') != NULL)) {
......
......@@ -50,7 +50,7 @@ get_entry_points (GthFileSource *file_source)
GFileInfo *info;
file = g_file_new_for_uri ("catalog:///");
info = gth_file_source_get_file_info (file_source, file);
info = gth_file_source_get_file_info (file_source, file, GFILE_BASIC_ATTRIBUTES);
list = g_list_append (list, gth_file_data_new (file, info));
g_object_unref (info);
......@@ -115,14 +115,15 @@ update_file_info (GthFileSource *file_source,
static GFileInfo *
gth_file_source_catalogs_get_file_info (GthFileSource *file_source,
GFile *file)
GFile *file,
const char *attributes)
{
GFile *gio_file;
GFileInfo *file_info;
gio_file = gth_catalog_file_to_gio_file (file);
file_info = g_file_query_info (gio_file,
"standard::display-name,standard::icon",
attributes,
G_FILE_QUERY_INFO_NONE,
NULL,
NULL);
......@@ -370,7 +371,7 @@ gth_file_source_catalogs_read_attributes (GthFileSource *file_source,
gio_files = gth_file_source_to_gio_file_list (GTH_FILE_SOURCE (catalogs), files);
g_query_info_async (gio_files,
GTH_FILE_DATA_ATTRIBUTES_WITH_FAST_CONTENT_TYPE,
GFILE_STANDARD_ATTRIBUTES_WITH_FAST_CONTENT_TYPE,
catalogs->priv->cancellable,
info_ready_cb,
data);
......
......@@ -134,20 +134,16 @@ clipboard_clear_cb (GtkClipboard *clipboard,
static void
_gth_browser_clipboard_copy_or_cut (GthBrowser *browser,
GList *file_list,
gboolean cut)
{
ClipboardData *data;
GList *items;
GList *file_list;
GtkTargetList *target_list;
GtkTargetEntry *targets;
int n_targets;
GList *scan;
int i;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
data = g_new0 (ClipboardData, 1);
data->cut = cut;
data->n_uris = g_list_length (file_list);
......@@ -172,8 +168,6 @@ _gth_browser_clipboard_copy_or_cut (GthBrowser *browser,
gtk_target_list_unref (target_list);
gtk_target_table_free (targets, n_targets);
_g_object_list_unref (file_list);
_gtk_tree_path_list_free (items);
}
......@@ -181,7 +175,15 @@ void
gth_browser_activate_action_edit_cut_files (GtkAction *action,
GthBrowser *browser)
{
_gth_browser_clipboard_copy_or_cut (browser, TRUE);
GList *items;
GList *file_list;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
_gth_browser_clipboard_copy_or_cut (browser, file_list, TRUE);
_g_object_list_unref (file_list);
_gtk_tree_path_list_free (items);
}
......@@ -189,7 +191,15 @@ void
gth_browser_activate_action_edit_copy_files (GtkAction *action,
GthBrowser *browser)
{
_gth_browser_clipboard_copy_or_cut (browser, FALSE);
GList *items;
GList *file_list;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
_gth_browser_clipboard_copy_or_cut (browser, file_list, FALSE);
_g_object_list_unref (file_list);
_gtk_tree_path_list_free (items);
}
......@@ -345,8 +355,22 @@ delete_file_permanently (GtkWindow *window,
GError *error = NULL;
files = gth_file_data_list_to_file_list (file_list);
if (! _g_delete_files (files, TRUE, &error))
if (! _g_delete_files (files, TRUE, &error)) {
_gtk_error_dialog_from_gerror_show (window, _("Could not delete the files"), &error);
}
else {
GthFileData *first;
GFile *parent;
first = files->data;
parent = g_file_get_parent (first->file);
gth_monitor_folder_changed (gth_main_get_default_monitor (),
parent,
files,
GTH_MONITOR_EVENT_DELETED);
g_object_unref (parent);
}
_g_object_list_unref (files);
}
......@@ -357,10 +381,11 @@ delete_permanently_response_cb (GtkDialog *dialog,
int response_id,
gpointer user_data)
{
GList *file_list = user_data;
GList *file_list = user_data;
if (response_id == GTK_RESPONSE_YES)
delete_file_permanently (gtk_window_get_transient_for (GTK_WINDOW (dialog)), file_list);
gtk_widget_destroy (GTK_WIDGET (dialog));
_g_object_list_unref (file_list);
}
......@@ -449,3 +474,232 @@ gth_browser_activate_action_edit_delete (GtkAction *action,
g_free (prompt);
_gtk_tree_path_list_free (items);
}
void
gth_browser_activate_action_folder_create (GtkAction *action,
GthBrowser *browser)
{
GthFileData *parent;
GthFileSource *file_source;
GError *error = NULL;
GFile *file;
parent = gth_folder_tree_get_selected_or_parent (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)));
if (parent == NULL)
return;
file_source = gth_main_get_file_source (parent->file);
file = _g_directory_create_unique (parent->file, _("untitled folder"), "", &error);
if (file != NULL) {
GList *list;
GFileInfo *info;
GthFileData *file_data;
GList *file_data_list;
info = gth_file_source_get_file_info (file_source, file, GFILE_BASIC_ATTRIBUTES ",access::*");
file_data = gth_file_data_new (file, info);
file_data_list = g_list_prepend (NULL, file_data);
gth_folder_tree_add_children (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)), parent->file, file_data_list);
gth_folder_tree_start_editing (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)), file);
list = g_list_prepend (NULL, g_object_ref (file));
gth_monitor_folder_changed (gth_main_get_default_monitor (),
parent->file,
list,
GTH_MONITOR_EVENT_CREATED);
_g_object_list_unref (list);
g_list_free (file_data_list);
g_object_unref (file_data);
g_object_unref (info);
}
else
_gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not create the folder"), &error);
_g_object_unref (file);
g_object_unref (file_source);
g_object_unref (parent);
}
void
gth_browser_activate_action_folder_rename (GtkAction *action,
GthBrowser *browser)
{
GthFileData *file_data;
file_data = gth_folder_tree_get_selected (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)));
if (file_data == NULL)
return;
gth_folder_tree_start_editing (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)), file_data->file);
g_object_unref (file_data);
}
void
gth_browser_activate_action_folder_cut (GtkAction *action,
GthBrowser *browser)
{
GthFileData *file_data;
GList *file_list;
file_data = gth_folder_tree_get_selected (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)));
if (file_data == NULL)
return;
file_list = g_list_prepend (NULL, file_data);
_gth_browser_clipboard_copy_or_cut (browser, file_list, TRUE);
g_list_free (file_list);
}
void
gth_browser_activate_action_folder_copy (GtkAction *action,
GthBrowser *browser)
{
GthFileData *file_data;
GList *file_list;
file_data = gth_folder_tree_get_selected (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)));
if (file_data == NULL)
return;
file_list = g_list_prepend (NULL, file_data);
_gth_browser_clipboard_copy_or_cut (browser, file_list, FALSE);
g_list_free (file_list);
}
void
gth_browser_activate_action_folder_paste (GtkAction *action,
GthBrowser *browser)
{
}
/* -- gth_browser_activate_action_folder_trash -- */
static void
delete_folder_permanently (GtkWindow *window,
GthFileData *file_data)
{
GList *files;
GError *error = NULL;
files = g_list_prepend (NULL, file_data->file);
if (! _g_delete_files (files, TRUE, &error)) {
_gtk_error_dialog_from_gerror_show (window, _("Could not delete the folder"), &error);
}
else {
GFile *parent;
parent = g_file_get_parent (file_data->file);
gth_monitor_folder_changed (gth_main_get_default_monitor (),
parent,
files,
GTH_MONITOR_EVENT_DELETED);
g_object_unref (parent);
}
g_list_free (files);
}
static void
delete_folder_permanently_response_cb (GtkDialog *dialog,
int response_id,
gpointer user_data)
{
GthFileData *file_data = user_data;
if (response_id == GTK_RESPONSE_YES)
delete_folder_permanently (gtk_window_get_transient_for (GTK_WINDOW (dialog)), file_data);
gtk_widget_destroy (GTK_WIDGET (dialog));
_g_object_unref (file_data);
}
void
gth_browser_activate_action_folder_trash (GtkAction *action,
GthBrowser *browser)
{
GthFileData *file_data;
GError *error = NULL;
file_data = gth_folder_tree_get_selected (GTH_FOLDER_TREE (gth_browser_get_folder_tree (browser)));
if (file_data == NULL)
return;
if (! g_file_trash (file_data->file, NULL, &error)) {
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) {
GtkWidget *d;
g_clear_error (&error);
d = _gtk_yesno_dialog_new (GTK_WINDOW (browser),
GTK_DIALOG_MODAL,
_("The folder cannot be moved to the Trash. Do you want to delete it permanently?"),
GTK_STOCK_CANCEL,
GTK_STOCK_DELETE);
g_signal_connect (d, "response", G_CALLBACK (delete_folder_permanently_response_cb), file_data);
gtk_widget_show (d);
file_data = NULL;
}
else
_gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not move the folder to the Trash"), &error);
}
else {
GFile *parent;
GList *files;
parent = g_file_get_parent (file_data->file);
files = g_list_prepend (NULL, file_data->file);
gth_monitor_folder_changed (gth_main_get_default_monitor (),
parent,
files,
GTH_MONITOR_EVENT_DELETED);
g_list_free (files);
g_object_unref (parent);
}
_g_object_unref (file_data);
}
void