[solang] Moved the archive creation code into the Exporter



commit 0a1b8ae7d5645bc21020551fb3bb25770d0095f8
Author: Debarshi Ray <rishi gnu org>
Date:   Sun Mar 14 03:31:06 2010 +0200

    Moved the archive creation code into the Exporter
    
    It is good to have the Exporter create the archive instead of asking
    each implementation of IPhotoDestination to do so. The archive is
    created as /tmp/Photos-<username>-<sec-since-epoch>.zip and then
    handed over to the destination.

 src/common/i-photo-destination.h       |    4 +-
 src/exporter/brasero-destination.cpp   |    6 +-
 src/exporter/brasero-destination.h     |    2 +-
 src/exporter/directory-destination.cpp |   33 +----------
 src/exporter/directory-destination.h   |    4 +-
 src/exporter/exporter.cpp              |   92 +++++++++++++++++++++++++++----
 src/exporter/exporter.h                |   10 +++-
 7 files changed, 100 insertions(+), 51 deletions(-)
---
diff --git a/src/common/i-photo-destination.h b/src/common/i-photo-destination.h
index 82f80dc..373de63 100644
--- a/src/common/i-photo-destination.h
+++ b/src/common/i-photo-destination.h
@@ -1,6 +1,6 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
 /*
- * Copyright (C) 2009 Debarshi Ray <rishi gnu org>
+ * Copyright (C) 2009, 2010 Debarshi Ray <rishi gnu org>
  * Copyright (C) 2009 Santanu Sinha <santanu sinha gmail com>
  *
  * Solang is free software: you can redistribute it and/or modify it
@@ -46,7 +46,7 @@ class IPhotoDestination :
         final(Application & application) throw() = 0;
 
         virtual void
-        export_photos_async(const PhotoSet & photos,
+        export_photos_async(const PhotoListPtr & photos,
                             const ProgressObserverPtr & observer)
                             throw() = 0;
 
diff --git a/src/exporter/brasero-destination.cpp b/src/exporter/brasero-destination.cpp
index 5dce932..c44340c 100644
--- a/src/exporter/brasero-destination.cpp
+++ b/src/exporter/brasero-destination.cpp
@@ -71,7 +71,7 @@ BraseroDestination::export_photo_async(
 
 void
 BraseroDestination::export_photos_async(
-                          const PhotoSet & photos,
+                          const PhotoListPtr & photos,
                           const ProgressObserverPtr & observer)
                           throw()
 {
@@ -92,9 +92,9 @@ BraseroDestination::export_photos_async(
         BRASERO_TRACK(braseroTrackDataCfg_),
         NULL);
 
-    PhotoSet::const_iterator it;
+    PhotoList::const_iterator it;
 
-    for (it = photos.begin(); photos.end() != it; it++)
+    for (it = photos->begin(); photos->end() != it; it++)
     {
         export_photo_async(*it, observer);
     }
diff --git a/src/exporter/brasero-destination.h b/src/exporter/brasero-destination.h
index 7e5001f..7b199e8 100644
--- a/src/exporter/brasero-destination.h
+++ b/src/exporter/brasero-destination.h
@@ -46,7 +46,7 @@ class BraseroDestination :
         final(Application & application) throw();
 
         virtual void
-        export_photos_async(const PhotoSet & photos,
+        export_photos_async(const PhotoListPtr & photos,
                             const ProgressObserverPtr & observer)
                             throw();
 
diff --git a/src/exporter/directory-destination.cpp b/src/exporter/directory-destination.cpp
index 0cf76e4..860c793 100644
--- a/src/exporter/directory-destination.cpp
+++ b/src/exporter/directory-destination.cpp
@@ -21,15 +21,12 @@
 #include "config.h"
 #endif // HAVE_CONFIG_H
 
-#include <algorithm>
-#include <iterator>
 #include <string>
 
 #include <giomm.h>
 #include <glib/gstdio.h>
 #include <glibmm/i18n.h>
 
-#include "archive-maker.h"
 #include "directory-destination.h"
 #include "i-progress-observer.h"
 #include "photo.h"
@@ -89,41 +86,17 @@ DirectoryDestination::export_photo_async(
 
 void
 DirectoryDestination::export_photos_async(
-                          const PhotoSet & photos,
+                          const PhotoListPtr & photos,
                           const ProgressObserverPtr & observer)
                           throw()
 {
     if (0 != observer)
     {
         observer->set_description(_("Exporting photos"));
-        observer->set_total(photos.size());
+        observer->set_total(photos->size());
     }
 
-    const PhotoListPtr pending(new PhotoList());
-    std::copy(photos.begin(), photos.end(),
-              std::inserter(*pending, pending->begin()));
-
-    if (true == createArchive_)
-    {
-        Glib::Date date;
-        date.set_time_current();
-
-        const std::string dest = date.format_string("%Y%m%d") + ".zip";
-        filename_ += "/";
-        filename_ += dest;
-
-        const ArchiveMakerPtr archive_maker = ArchiveMaker::create();
-        archive_maker->make_async(
-            filename_,
-            pending,
-            sigc::bind(sigc::slot<void, const ArchiveMakerPtr &>(),
-                       archive_maker),
-            observer);
-    }
-    else
-    {
-        export_photo_async(pending->back(), pending, observer);
-    }
+    export_photo_async(photos->back(), photos, observer);
 
     return;
 }
diff --git a/src/exporter/directory-destination.h b/src/exporter/directory-destination.h
index df70944..173dec6 100644
--- a/src/exporter/directory-destination.h
+++ b/src/exporter/directory-destination.h
@@ -1,6 +1,6 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
 /*
- * Copyright (C) 2009 Debarshi Ray <rishi gnu org>
+ * Copyright (C) 2009, 2010 Debarshi Ray <rishi gnu org>
  * Copyright (C) 2009 Santanu Sinha <santanu sinha gmail com>
  *
  * Solang is free software: you can redistribute it and/or modify it
@@ -43,7 +43,7 @@ class DirectoryDestination :
         final(Application & application) throw();
 
         virtual void
-        export_photos_async(const PhotoSet & photos,
+        export_photos_async(const PhotoListPtr & photos,
                             const ProgressObserverPtr & observer)
                             throw();
 
diff --git a/src/exporter/exporter.cpp b/src/exporter/exporter.cpp
index acbf842..4b863cf 100644
--- a/src/exporter/exporter.cpp
+++ b/src/exporter/exporter.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
 /*
- * Copyright (C) 2009 Debarshi Ray <rishi gnu org>
+ * Copyright (C) 2009, 2010 Debarshi Ray <rishi gnu org>
  *
  * Solang is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -20,14 +20,21 @@
 #include "config.h"
 #endif // HAVE_CONFIG_H
 
+#include <algorithm>
+#include <iterator>
+#include <sstream>
+#include <string>
+
 #include <sigc++/sigc++.h>
 
 #include "application.h"
+#include "archive-maker.h"
 //#include "directory-storage.h"
 #include "engine.h"
 #include "exporter-dialog.h"
 #include "exporter.h"
 #include "i-photo-destination.h"
+#include "photo-factory.h"
 #include "progress-observer.h"
 
 namespace Solang
@@ -167,12 +174,82 @@ Exporter::visit_renderer(SlideshowRenderer & slideshow_renderer)
 }
 
 void
+Exporter::export_photos_async(bool create_archive) throw()
+{
+    Engine & engine = application_->get_engine();
+    const PhotoSet & export_queue = engine.get_export_queue();
+
+    const PhotoListPtr photos(new PhotoList());
+    std::copy(export_queue.begin(), export_queue.end(),
+              std::inserter(*photos, photos->begin()));
+
+    const ProgressObserverPtr observer
+        = ProgressObserver<sigc::signal<void> >::create(
+              application_->get_progress_dialog());
+
+    if (true == create_archive)
+    {
+        observer->set_description(_("Creating archive"));
+        observer->set_total(photos->size());
+
+        GTimeVal time;
+        g_get_current_time(&time);
+
+        const std::string & username = Glib::get_user_name();
+        std::ostringstream sout;
+        sout << Glib::get_tmp_dir() << "/"
+             << "Photos-" << username << "-" << time.tv_sec << ".zip";
+
+        // FIXME: We need to ensure that this is unique.
+        const std::string & archive_path = sout.str();
+
+        const ArchiveMakerPtr archive_maker = ArchiveMaker::create();
+        archive_maker->make_async(
+            archive_path,
+            photos,
+            sigc::bind(
+                sigc::mem_fun(*this,
+                              &Exporter::on_archive_maker_ready),
+                archive_maker,
+                archive_path,
+                photos),
+            observer);
+    }
+    else
+    {
+        photoDestination_->export_photos_async(photos, observer);
+    }
+}
+
+void
 Exporter::on_action_photo_export() throw()
 {
     photoDestination_->init(*application_);
 }
 
 void
+Exporter::on_archive_maker_ready(const ArchiveMakerPtr &,
+                                 const std::string & archive_path,
+                                 const PhotoListPtr & photos) throw()
+{
+    photos->clear();
+
+    PhotoFactory & photo_factory = PhotoFactory::instance();
+
+    // This does not represent a photo, but we can get away with it.
+    const PhotoPtr photo  = photo_factory.create_photo(
+                                Glib::filename_to_uri(archive_path),
+                                "application/zip");
+    photos->push_back(photo);
+
+    const ProgressObserverPtr observer
+        = ProgressObserver<sigc::signal<void> >::create(
+              application_->get_progress_dialog());
+
+    photoDestination_->export_photos_async(photos, observer);
+}
+
+void
 Exporter::on_photo_destination_init_end(bool status) throw()
 {
     if (false == status)
@@ -209,18 +286,9 @@ Exporter::on_exporter_dialog_response(
 
             const bool create_archive
                            = exporter_dialog->get_create_archive();
-            photoDestination_->set_create_archive(create_archive);
 
-            Engine & engine = application_->get_engine();
-            const PhotoSet & export_queue
-                                 = engine.get_export_queue();
-
-            const ProgressObserverPtr observer
-                = ProgressObserver<sigc::signal<void> >::create(
-                      application_->get_progress_dialog());
-
-            photoDestination_->export_photos_async(export_queue,
-                                                   observer);
+            photoDestination_->set_create_archive(create_archive);
+            export_photos_async(create_archive);
             break;
         }
 
diff --git a/src/exporter/exporter.h b/src/exporter/exporter.h
index 0d3ba22..2f9ed7e 100644
--- a/src/exporter/exporter.h
+++ b/src/exporter/exporter.h
@@ -1,6 +1,6 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
 /*
- * Copyright (C) 2009 Debarshi Ray <rishi gnu org>
+ * Copyright (C) 2009, 2010 Debarshi Ray <rishi gnu org>
  *
  * Solang is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -61,9 +61,17 @@ class Exporter :
 
     protected:
         void
+        export_photos_async(bool create_archive) throw();
+
+        void
         on_action_photo_export() throw();
 
         void
+        on_archive_maker_ready(const ArchiveMakerPtr &,
+                               const std::string & archive_path,
+                               const PhotoListPtr & photos) throw();
+
+        void
         on_photo_destination_init_end(bool status) throw();
 
         void



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