@@ -1248,15 +1248,92 @@ locations_from_file_list (GList *file_list)
12481248 return g_list_reverse (ret );
12491249}
12501250
1251+ typedef struct {
1252+ GHashTable * original_dirs_hash ;
1253+ GtkWindow * parent_window ;
1254+ } RestoreFilesData ;
1255+
1256+ static void
1257+ ensure_dirs_task_ready_cb (GObject * _source ,
1258+ GAsyncResult * res ,
1259+ gpointer user_data )
1260+ {
1261+ NemoFile * original_dir ;
1262+ GFile * original_dir_location ;
1263+ GList * original_dirs , * files , * locations , * l ;
1264+ RestoreFilesData * data = user_data ;
1265+
1266+ original_dirs = g_hash_table_get_keys (data -> original_dirs_hash );
1267+ for (l = original_dirs ; l != NULL ; l = l -> next ) {
1268+ original_dir = NEMO_FILE (l -> data );
1269+ original_dir_location = nemo_file_get_location (original_dir );
1270+
1271+ files = g_hash_table_lookup (data -> original_dirs_hash , original_dir );
1272+ locations = locations_from_file_list (files );
1273+
1274+ nemo_file_operations_move
1275+ (locations , NULL ,
1276+ original_dir_location ,
1277+ data -> parent_window ,
1278+ NULL , NULL );
1279+
1280+ g_list_free_full (locations , g_object_unref );
1281+ g_object_unref (original_dir_location );
1282+ }
1283+
1284+ g_list_free (original_dirs );
1285+
1286+ g_hash_table_unref (data -> original_dirs_hash );
1287+ g_slice_free (RestoreFilesData , data );
1288+ }
1289+
1290+ static void
1291+ ensure_dirs_task_thread_func (GTask * task ,
1292+ gpointer source ,
1293+ gpointer task_data ,
1294+ GCancellable * cancellable )
1295+ {
1296+ RestoreFilesData * data = task_data ;
1297+ NemoFile * original_dir ;
1298+ GFile * original_dir_location ;
1299+ GList * original_dirs , * l ;
1300+
1301+ original_dirs = g_hash_table_get_keys (data -> original_dirs_hash );
1302+ for (l = original_dirs ; l != NULL ; l = l -> next ) {
1303+ original_dir = NEMO_FILE (l -> data );
1304+ original_dir_location = nemo_file_get_location (original_dir );
1305+
1306+ g_file_make_directory_with_parents (original_dir_location , cancellable , NULL );
1307+ g_object_unref (original_dir_location );
1308+ }
1309+
1310+ g_task_return_pointer (task , NULL , NULL );
1311+ }
1312+
1313+ static void
1314+ restore_files_ensure_parent_directories (GHashTable * original_dirs_hash ,
1315+ GtkWindow * parent_window )
1316+ {
1317+ RestoreFilesData * data ;
1318+ GTask * ensure_dirs_task ;
1319+
1320+ data = g_slice_new0 (RestoreFilesData );
1321+ data -> parent_window = parent_window ;
1322+ data -> original_dirs_hash = g_hash_table_ref (original_dirs_hash );
1323+
1324+ ensure_dirs_task = g_task_new (NULL , NULL , ensure_dirs_task_ready_cb , data );
1325+ g_task_set_task_data (ensure_dirs_task , data , NULL );
1326+ g_task_run_in_thread (ensure_dirs_task , ensure_dirs_task_thread_func );
1327+ g_object_unref (ensure_dirs_task );
1328+ }
1329+
12511330void
12521331nemo_restore_files_from_trash (GList * files ,
12531332 GtkWindow * parent_window )
12541333{
1255- NemoFile * file , * original_dir ;
1334+ NemoFile * file ;
12561335 GHashTable * original_dirs_hash ;
1257- GList * original_dirs , * unhandled_files ;
1258- GFile * original_dir_location ;
1259- GList * locations , * l ;
1336+ GList * unhandled_files , * l ;
12601337 char * message , * file_name ;
12611338
12621339 original_dirs_hash = nemo_trashed_files_get_original_directories (files , & unhandled_files );
@@ -1274,26 +1351,8 @@ nemo_restore_files_from_trash (GList *files,
12741351 }
12751352
12761353 if (original_dirs_hash != NULL ) {
1277- original_dirs = g_hash_table_get_keys (original_dirs_hash );
1278- for (l = original_dirs ; l != NULL ; l = l -> next ) {
1279- original_dir = NEMO_FILE (l -> data );
1280- original_dir_location = nemo_file_get_location (original_dir );
1281-
1282- files = g_hash_table_lookup (original_dirs_hash , original_dir );
1283- locations = locations_from_file_list (files );
1284-
1285- nemo_file_operations_move
1286- (locations , NULL ,
1287- original_dir_location ,
1288- parent_window ,
1289- NULL , NULL );
1290-
1291- g_list_free_full (locations , g_object_unref );
1292- g_object_unref (original_dir_location );
1293- }
1294-
1295- g_list_free (original_dirs );
1296- g_hash_table_destroy (original_dirs_hash );
1354+ restore_files_ensure_parent_directories (original_dirs_hash , parent_window );
1355+ g_hash_table_unref (original_dirs_hash );
12971356 }
12981357
12991358 nemo_file_list_unref (unhandled_files );
0 commit comments