From 156a022547a34e76c36d704f178b1e5fe98cc3cc Mon Sep 17 00:00:00 2001
From: Rakesh Pandit <rakesh@fedoraproject.org>
Date: Mon, 18 May 2009 05:59:09 +0530
Subject: [PATCH]     Initial merging: Flickr and Picasa importer and exporter work.

    New files:
       src/common/flickr.cpp
       src/common/flickr.h
       src/common/flickrconf.cpp
       src/common/flickrconf.h
       src/common/utils.cpp
       src/common/utils.h
       src/importer/flickr-import-window.cpp
       src/importer/flickr-import-window.h
       src/importer/import-tree-model.cpp
       src/importer/import-tree-model.h
       src/importer/picasaweb-source.cpp
       src/importer/picasaweb-source.h

    Modified files:
       configure.ac
       src/application/Makefile.am
       src/application/application.cpp
       src/attribute/Makefile.am
       src/common/Makefile.am
       src/database/Makefile.am
       src/exporter/Makefile.am
       src/importer/Makefile.am
       src/importer/flickr-source.cpp
       src/importer/flickr-source.h
       src/renderer/Makefile.am
       src/storage/Makefile.am
---
 configure.ac                    |    2 +
 src/application/Makefile.am     |    4 ++
 src/application/application.cpp |    5 +++
 src/attribute/Makefile.am       |    2 +
 src/common/Makefile.am          |   11 ++++++-
 src/database/Makefile.am        |    2 +
 src/exporter/Makefile.am        |    2 +
 src/importer/Makefile.am        |   10 +++++-
 src/importer/flickr-source.cpp  |   63 +++++++++++++++++++++++++++++++++++++--
 src/importer/flickr-source.h    |   14 ++++++++-
 src/renderer/Makefile.am        |    2 +
 src/storage/Makefile.am         |    2 +
 12 files changed, 113 insertions(+), 6 deletions(-)

diff --git a/configure.ac b/configure.ac
index 82a9670..9b8d7fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,7 @@ AM_PROG_LIBTOOL
 
 PKG_CHECK_MODULES(CAIROMM, [cairomm-1.0])
 PKG_CHECK_MODULES(EXIV2, [exiv2])
+PKG_CHECK_MODULES(FLICKCURL, [flickcurl])
 PKG_CHECK_MODULES(GDAMM, [libgdamm-3.0])
 PKG_CHECK_MODULES(GDL, [gdl-1.0])
 PKG_CHECK_MODULES(GIOMM, [giomm-2.4])
@@ -36,6 +37,7 @@ PKG_CHECK_MODULES(GTKMM, [gtkmm-2.4 >= 2.8])
 PKG_CHECK_MODULES(IMAGEMAGICK, [GraphicsMagick++],,
     [PKG_CHECK_MODULES(IMAGEMAGICK, [ImageMagick++])])
 
+PKG_CHECK_MODULES(LIBXML, [libxml-2.0])
 PKG_CHECK_MODULES(SIGC, [sigc++-2.0])
 
 
diff --git a/src/application/Makefile.am b/src/application/Makefile.am
index 0408bdf..09fb3bb 100644
--- a/src/application/Makefile.am
+++ b/src/application/Makefile.am
@@ -19,6 +19,7 @@ solang_LDADD = \
 	$(top_builddir)/src/attribute/libattribute.la \
 	$(top_builddir)/src/common/libcommon.la \
 	$(EXIV2_LIBS) \
+	$(FLICKCURL_LIBS) \
 	$(GTKMM_LIBS) \
 	$(CAIROMM_LIBS) \
 	$(GDAMM_LIBS) \
@@ -26,6 +27,7 @@ solang_LDADD = \
 	$(GLIBMM_LIBS) \
 	$(GDL_LIBS) \
 	$(IMAGEMAGICK_LIBS) \
+	$(LIBXML_LIBS) \
 	$(SIGC_LIBS)
 
 AM_CPPFLAGS = \
@@ -43,12 +45,14 @@ AM_CPPFLAGS = \
 	$(SOLANG_CFLAGS) \
 	$(CAIROMM_CFLAGS) \
 	$(EXIV2_CFLAGS) \
+	$(FLICKCURL_CFLAGS) \
 	$(GTKMM_CFLAGS) \
 	$(GDAMM_CFLAGS) \
 	$(GIOMM_CFLAGS) \
 	$(GLIBMM_CFLAGS) \
 	$(GDL_CFLAGS) \
 	$(IMAGEMAGICK_CFLAGS) \
+	$(LIBXML_LIBS) \
 	$(SIGC_CFLAGS)
 
 AM_CXXFLAGS = \
diff --git a/src/application/application.cpp b/src/application/application.cpp
index 8af11fc..32cd8f0 100644
--- a/src/application/application.cpp
+++ b/src/application/application.cpp
@@ -35,6 +35,7 @@
 #include "i-photo-source.h"
 #include "i-plugin.h"
 #include "importer.h"
+#include "picasaweb-source.h"
 #include "photo.h"
 #include "progress-observer.h"
 #include "property-manager.h"
@@ -221,6 +222,10 @@ Application::init() throw()
     IPluginPtr flickr_importer(new Importer(flickr_source, false));
     plugins_.insert(std::make_pair("flickr-importer", flickr_importer));
 
+    IPhotoSourcePtr picasaweb_source(new PicasawebSource());
+    IPluginPtr picasaweb_importer(new Importer(picasaweb_source, false));
+    plugins_.insert(std::make_pair("picasaweb-importer", picasaweb_importer));
+
     std::for_each(plugins_.begin(), plugins_.end(),
                   Initializer<IPluginPtr>(this));
 
diff --git a/src/attribute/Makefile.am b/src/attribute/Makefile.am
index e96f5cd..ad3793e 100644
--- a/src/attribute/Makefile.am
+++ b/src/attribute/Makefile.am
@@ -36,12 +36,14 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/storage \
 	$(SOLANG_CFLAGS) \
 	$(EXIV2_CFLAGS) \
+	$(FLICKCURL_CFLAGS) \
 	$(GTKMM_CFLAGS) \
 	$(GDAMM_CFLAGS) \
 	$(GIOMM_CFLAGS) \
 	$(GLIBMM_CFLAGS) \
 	$(GDL_CFLAGS) \
 	$(IMAGEMAGICK_CFLAGS) \
+	$(LIBXML_CFLAGS) \
 	$(SIGC_CFLAGS)
 
 AM_CXXFLAGS = \
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 037e168..09a2acf 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -3,6 +3,10 @@ noinst_LTLIBRARIES =	libcommon.la
 libcommon_la_SOURCES = \
 	error.cpp \
 	error.h \
+	flickr.cpp \
+	flickr.h \
+	flickrconf.cpp \
+	flickrconf.h \
 	i-photo-destination.cpp \
 	i-photo-destination.h \
 	i-photo-source.cpp \
@@ -25,7 +29,10 @@ libcommon_la_SOURCES = \
 	progress-dialog.h \
 	progress-observer.cpp \
 	progress-observer.h \
-	types.h
+	types.h \
+	utils.cpp \
+	utils.h
+
 
 AM_CPPFLAGS = \
        	-DPACKAGE_LOCALE_DIR=\"${SOLANG_LOCALE_DIR}\" \
@@ -41,12 +48,14 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/storage \
 	$(SOLANG_CFLAGS) \
 	$(EXIV2_CFLAGS) \
+	$(FLICKCURL_CFLAGS) \
 	$(GTKMM_CFLAGS) \
 	$(GDAMM_CFLAGS) \
 	$(GIOMM_CFLAGS) \
 	$(GLIBMM_CFLAGS) \
 	$(GDL_CFLAGS) \
 	$(IMAGEMAGICK_CFLAGS) \
+	$(LIBXML_CFLAGS) \
 	$(SIGC_CFLAGS)
 
 AM_CXXFLAGS = \
diff --git a/src/database/Makefile.am b/src/database/Makefile.am
index dd9a060..e4a4737 100644
--- a/src/database/Makefile.am
+++ b/src/database/Makefile.am
@@ -36,12 +36,14 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/storage \
 	$(SOLANG_CFLAGS) \
 	$(EXIV2_CFLAGS) \
+	$(FLICKCURL_CFLAGS) \
 	$(GTKMM_CFLAGS) \
 	$(GDAMM_CFLAGS) \
 	$(GIOMM_CFLAGS) \
 	$(GLIBMM_CFLAGS) \
 	$(GDL_CFLAGS) \
 	$(IMAGEMAGICK_CFLAGS) \
+	$(LIBXML_CFLAGS) \
 	$(SIGC_CFLAGS)
 
 AM_CXXFLAGS = \
diff --git a/src/exporter/Makefile.am b/src/exporter/Makefile.am
index 86edb1c..74fe01b 100644
--- a/src/exporter/Makefile.am
+++ b/src/exporter/Makefile.am
@@ -21,12 +21,14 @@ AM_CPPFLAGS = \
 	$(SOLANG_CFLAGS) \
 	$(CAIROMM_CFLAGS) \
 	$(EXIV2_CFLAGS) \
+	$(FLICKCURL_CFLAGS) \
 	$(GTKMM_CFLAGS) \
 	$(GDAMM_CFLAGS) \
 	$(GIOMM_CFLAGS) \
 	$(GLIBMM_CFLAGS) \
 	$(GDL_CFLAGS) \
 	$(IMAGEMAGICK_CFLAGS) \
+	$(LIBXML_CFLAGS) \
 	$(SIGC_CFLAGS)
 
 AM_CXXFLAGS = \
diff --git a/src/importer/Makefile.am b/src/importer/Makefile.am
index e95761b..31b2019 100644
--- a/src/importer/Makefile.am
+++ b/src/importer/Makefile.am
@@ -3,14 +3,20 @@ noinst_LTLIBRARIES =	libimporter.la
 libimporter_la_SOURCES = \
 	directory-source.cpp \
 	directory-source.h \
+	flickr-import-window.cpp \
+	flickr-import-window.h \
 	flickr-source.cpp \
 	flickr-source.h \
+	import-tree-model.cpp \
+	import-tree-model.h \
 	importer.cpp \
 	importer-dialog.cpp \
 	importer-dialog.h \
 	importer.h \
 	photo-source.cpp \
-	photo-source.h
+	photo-source.h \
+	picasaweb-source.cpp \
+	picasaweb-source.h	
 
 AM_CPPFLAGS = \
        	-DPACKAGE_LOCALE_DIR=\"${SOLANG_LOCALE_DIR}\" \
@@ -27,12 +33,14 @@ AM_CPPFLAGS = \
 	$(SOLANG_CFLAGS) \
 	$(CAIROMM_CFLAGS) \
 	$(EXIV2_CFLAGS) \
+	$(FLICKCURL_CFLAGS) \
 	$(GTKMM_CFLAGS) \
 	$(GDAMM_CFLAGS) \
 	$(GIOMM_CFLAGS) \
 	$(GLIBMM_CFLAGS) \
 	$(GDL_CFLAGS) \
 	$(IMAGEMAGICK_CFLAGS) \
+	$(LIBXML_CFLAGS) \
 	$(SIGC_CFLAGS)
 
 AM_CXXFLAGS = \
diff --git a/src/importer/flickr-source.cpp b/src/importer/flickr-source.cpp
index f798545..a5d70a2 100644
--- a/src/importer/flickr-source.cpp
+++ b/src/importer/flickr-source.cpp
@@ -17,18 +17,24 @@
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <iostream>
 #include "config.h"
 
 #include "flickr-source.h"
+#include "flickr-import-window.h"
 #include "progress-observer.h"
 
 namespace Solang
 {
 
 FlickrSource::FlickrSource() throw() :
-    PhotoSource(),
-    comboBoxEntry_()
+    PhotoSource()
 {
+	button_.set_label("Confirm on flickr!");
+	button_.signal_clicked().connect( sigc::mem_fun(*this,
+		&FlickrSource::on_button_confirm_flickr) );
+
+	set_authurl_confirmed(false);
 }
 
 FlickrSource::~FlickrSource() throw()
@@ -66,10 +72,61 @@ FlickrSource::import(const IStoragePtr & storage, const TagList &tags,
     return import(files, storage, tags, db, observer);
 }
 
+void
+FlickrSource::on_button_confirm_flickr() throw()
+{
+	flickcurl_photos_list* list = NULL;
+	FlickrImportWindow flickr_window;
+	flickr::dictionary uri_dic;
+	flickr::dictionary title_dic;
+	std::vector<std::string> id_list;
+
+	if (!is_authurl_confirmed()) {
+		std::string url;
+
+		std::string browser = "firefox ";
+		//std::string browser = "firefox ";
+
+		url = flickr_web_gallery.get_auth_url("read");
+		std::cout << url << std::endl;
+		std::string cmd = browser + "'" + url + "'"; 
+
+		system(cmd.c_str());
+		button_.set_label("Click after confirmation!");
+		set_authurl_confirmed(true);
+
+		return;
+	}
+
+	// Adding pictures without any set
+	flickr_web_gallery.get_auth_token();
+	list = flickr_web_gallery.get_photo_list_not_in_any_set();
+	flickr_web_gallery.return_photo_list(list);
+	uri_dic = flickr_web_gallery.get_thumbnail_uri_from_photo_list(list);
+	title_dic = flickr_web_gallery.get_title_from_photo_list(list);
+	id_list = flickr_web_gallery.get_id_from_photo_list(list);
+	flickr_window.make_imported_tree_per_set(id_list, title_dic, "No Set");
+
+	// Adding all sets
+	flickcurl_photoset** photo_set = flickr_web_gallery.get_photosets_list();
+	for(int i=0; photo_set[i]; i++) {
+		list = flickr_web_gallery.get_photo_list_in_set(photo_set[i]->id);
+		flickr_web_gallery.return_photo_list(list);
+		uri_dic = flickr_web_gallery.get_thumbnail_uri_from_photo_list(list);
+		title_dic = flickr_web_gallery.get_title_from_photo_list(list);
+		id_list = flickr_web_gallery.get_id_from_photo_list(list);
+		flickr_window.make_imported_tree_per_set(id_list, title_dic, std::string(photo_set[i]->title));
+	}
+
+	flickr_window.run();
+
+	return;
+}
+
 Gtk::Widget &
 FlickrSource::get_browser() throw()
 {
-    return comboBoxEntry_;
+    return button_;
 }
 
 Glib::ustring
diff --git a/src/importer/flickr-source.h b/src/importer/flickr-source.h
index d3a8c67..cacc74b 100644
--- a/src/importer/flickr-source.h
+++ b/src/importer/flickr-source.h
@@ -23,6 +23,7 @@
 #include <glibmm.h>
 #include <gtkmm.h>
 
+#include "flickr.h"
 #include "photo-source.h"
 
 namespace Solang
@@ -63,10 +64,21 @@ public:
     virtual Gtk::StockID
     get_stock_id() const throw();
 
+	bool
+		is_authurl_confirmed() const throw() {return url_confirmed;}
+
 protected:
-    Gtk::ComboBoxEntry comboBoxEntry_;
+    Gtk::Button button_;
+	flickr::flickr flickr_web_gallery;
 
 private:
+	virtual void
+		on_button_confirm_flickr() throw();
+
+	void
+		set_authurl_confirmed(bool value) throw() {url_confirmed = value;}
+
+	bool url_confirmed;
 };
 
 } // namespace Solang
diff --git a/src/renderer/Makefile.am b/src/renderer/Makefile.am
index 397c67a..620ff41 100644
--- a/src/renderer/Makefile.am
+++ b/src/renderer/Makefile.am
@@ -31,12 +31,14 @@ AM_CPPFLAGS = \
 	$(SOLANG_CFLAGS) \
 	$(CAIROMM_CFLAGS) \
 	$(EXIV2_CFLAGS) \
+	$(FLICKCURL_CFLAGS) \
 	$(GTKMM_CFLAGS) \
 	$(GDAMM_CFLAGS) \
 	$(GIOMM_CFLAGS) \
 	$(GLIBMM_CFLAGS) \
 	$(GDL_CFLAGS) \
 	$(IMAGEMAGICK_CFLAGS) \
+	$(LIBXML_CFLAGS) \
 	$(SIGC_CFLAGS)
 
 AM_CXXFLAGS = \
diff --git a/src/storage/Makefile.am b/src/storage/Makefile.am
index d2b219e..cde7eeb 100644
--- a/src/storage/Makefile.am
+++ b/src/storage/Makefile.am
@@ -22,12 +22,14 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/storage \
 	$(SOLANG_CFLAGS) \
 	$(EXIV2_CFLAGS) \
+	$(FLICKCURL_CFLAGS) \
 	$(GTKMM_CFLAGS) \
 	$(GDAMM_CFLAGS) \
 	$(GIOMM_CFLAGS) \
 	$(GLIBMM_CFLAGS) \
 	$(GDL_CFLAGS) \
 	$(IMAGEMAGICK_CFLAGS) \
+	$(LIBXML_CFLAGS) \
 	$(SIGC_CFLAGS)
 
 AM_CXXFLAGS = \
-- 
1.6.0.6

