[gnome-photos/wip/rishi/collection: 54/54] app: import



commit 969f91cd5d41358053d01da3524a3fa9ec3b2cd6
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Feb 3 13:05:50 2018 +0100

    app: import

 src/photos-application.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 7030fd18..2101ee53 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -1042,14 +1042,63 @@ photos_application_get_state (PhotosSearchContext *context)
 static void
 photos_application_import (PhotosApplication *self)
 {
+  g_autoptr (GDateTime) date_created_latest = NULL;
+  g_autoptr (GFile) import_sub_dir = NULL;
+  GList *files;
+  GList *l;
+  GList *selection;
   GMount *mount;
   PhotosSource *source;
+  const gchar *pictures_path;
+  g_autofree gchar *date_created_latest_str = NULL;
+  g_autofree gchar *import_sub_path = NULL;
+  gint64 ctime_latest = -1;
 
   source = PHOTOS_SOURCE (photos_base_manager_get_active_object (self->state->src_mngr));
   g_return_if_fail (PHOTOS_IS_SOURCE (source));
 
   mount = photos_source_get_mount (source);
   g_return_if_fail (G_IS_MOUNT (mount));
+
+  g_return_if_fail (photos_utils_get_selection_mode ());
+
+  selection = photos_selection_controller_get_selection (self->sel_cntrlr);
+  g_return_if_fail (selection != NULL);
+
+  for (l = selection; l != NULL; l = l->next)
+    {
+      g_autoptr (GFile) file = NULL;
+      PhotosBaseItem *item;
+      const gchar *uri;
+      const gchar *urn = (gchar *) l->data;
+      gint64 ctime;
+
+      item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->state->item_mngr, urn));
+
+      ctime = photos_base_item_get_date_created (item);
+      if (ctime < 0)
+        ctime = photos_base_item_get_mtime (item);
+
+      if (ctime > ctime_latest)
+        ctime_latest = ctime;
+
+      uri = photos_base_item_get_uri (item);
+      file = g_file_new_for_uri (uri);
+      files = g_list_prepend (files, g_object_ref (file));
+    }
+
+  pictures_path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
+  export_path = g_build_filename (pictures_path, PHOTOS_IMPORT_SUBPATH, NULL);
+
+  date_created_latest = g_date_time_new_from_unix_local (ctime_latest);
+
+  /* Translators: this is the default sub-directory where photos will
+   * be imported.
+   */
+  date_created_latest_str = g_date_time_format (date_created_latest, _("%-d %B %Y"));
+
+  import_sub_path = g_build_filename (pictures_path, PHOTOS_IMPORT_SUBPATH, date_created_latest_str, NULL);
+  import_sub_dir = g_file_new_for_path (import_sub_path);
 }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]