From 0ed9e65f65d622f7e3ac9d41843012f8d71837a3 Mon Sep 17 00:00:00 2001
From: Rakesh Pandit <rakesh@fedorapeople.org>
Date: Mon, 18 May 2009 09:30:40 +0530
Subject: [PATCH] Added missing files for picasa and flicker importer and exporter.

---
 src/common/flickr.cpp                 |  286 +++++++++++++++++++++++++++++++++
 src/common/flickr.h                   |   99 ++++++++++++
 src/common/flickrconf.cpp             |   42 +++++
 src/common/flickrconf.h               |   38 +++++
 src/common/utils.cpp                  |   55 +++++++
 src/common/utils.h                    |   32 ++++
 src/importer/flickr-import-window.cpp |  148 +++++++++++++++++
 src/importer/flickr-import-window.h   |   60 +++++++
 src/importer/import-tree-model.cpp    |  113 +++++++++++++
 src/importer/import-tree-model.h      |   56 +++++++
 src/importer/picasaweb-source.cpp     |  178 ++++++++++++++++++++
 src/importer/picasaweb-source.h       |  126 +++++++++++++++
 12 files changed, 1233 insertions(+), 0 deletions(-)
 create mode 100644 src/common/flickr.cpp
 create mode 100644 src/common/flickr.h
 create mode 100644 src/common/flickrconf.cpp
 create mode 100644 src/common/flickrconf.h
 create mode 100644 src/common/utils.cpp
 create mode 100644 src/common/utils.h
 create mode 100644 src/importer/flickr-import-window.cpp
 create mode 100644 src/importer/flickr-import-window.h
 create mode 100644 src/importer/import-tree-model.cpp
 create mode 100644 src/importer/import-tree-model.h
 create mode 100644 src/importer/picasaweb-source.cpp
 create mode 100644 src/importer/picasaweb-source.h

diff --git a/src/common/flickr.cpp b/src/common/flickr.cpp
new file mode 100644
index 0000000..c27733a
--- /dev/null
+++ b/src/common/flickr.cpp
@@ -0,0 +1,286 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * flickr.cpp
+ * Copyright (C) 2009 Rakesh Pandit <rakesh@fedoraproject.org>
+ * 
+ * main-window.cpp is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * main-window.cpp is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <fstream>
+#include <cstring>
+
+#include <flickcurl.h>
+
+#include "flickr.h"
+#include "flickrconf.h"
+#include "utils.h"
+
+namespace flickr {
+
+class NoFrobException : public std::runtime_error {
+public:
+    NoFrobException() :
+		std::runtime_error("Not able to get frob from flickr!")
+			{ }
+};
+
+class NoAuthTokenException : public std::runtime_error {
+public:
+    NoAuthTokenException() :
+		std::runtime_error("Not able to get auth token from flickr!")
+			{ }
+};
+
+class FlickcurlException : public std::runtime_error {
+public:
+	FlickcurlException(std::string str) :
+		std::runtime_error(str)
+			{ }
+};
+
+flickr::flickr() throw()
+{
+	frob = "";
+	auth_token = "";
+
+	fc = NULL;
+	initialize_flickr_api();
+	get_frob();
+}
+
+flickr::~flickr() throw()
+{
+	close_flickr_api();
+}
+
+void
+flickr::get_auth_token() throw()
+{
+	char * c_auth_token;
+	c_auth_token = flickcurl_auth_getToken(fc, frob.c_str());
+
+	if (c_auth_token)
+		auth_token = std::string(c_auth_token);
+	else
+		throw NoAuthTokenException();
+
+	flickcurl_set_auth_token(fc, auth_token.c_str());
+	return;	
+}
+
+bool
+flickr::check_auth_done() throw()
+{
+	if (flickcurl_auth_checkToken(fc, auth_token.c_str()))
+		return true;
+	return false;
+}
+
+flickcurl_upload_status*
+flickr::upload_photo(flickcurl_upload_params params) throw()
+{
+	return flickcurl_photos_upload_params(fc, &params);
+}
+
+flickcurl_photos_list*
+flickr::get_photo_list_not_in_any_set() throw()
+{
+	flickcurl_photos_list_params list_params;
+	flickcurl_photos_list* list = NULL;
+	flickcurl_photos_list_params_init(&list_params);
+	list = flickcurl_photos_getNotInSet_params(fc,
+												   -1,
+												   -1,
+												   NULL,
+												   NULL,
+												   -1,
+												   &list_params
+												   );
+	return list;
+}
+
+flickcurl_photos_list*
+flickr::get_photo_list_in_set(const char* photoset_id) throw()
+{
+	flickcurl_photos_list* list=NULL;
+	flickcurl_photos_list_params list_params;
+	flickcurl_photos_list_params_init(&list_params);
+	list = flickcurl_photosets_getPhotos_params(fc, photoset_id,
+													 -1,
+													 &list_params);
+
+	return list;
+}
+
+flickcurl_photoset**
+flickr::get_photosets_list() throw()
+{
+	flickcurl_photoset** photoset_list=NULL;
+	const char* user_id=NULL;
+	photoset_list = flickcurl_photosets_getList(fc, user_id);
+	return photoset_list;
+}
+
+//std::vector<std::string>
+dictionary
+flickr::get_thumbnail_uri_from_photo_list(flickcurl_photos_list* photo_list) throw()
+{
+	int i = 0;
+	//std::vector<std::string> uri_list;
+	dictionary uri_dic;
+	char *uri;
+
+	for(i=0; photo_list->photos[i]; i++) {
+		uri = flickcurl_photo_as_source_uri(photo_list->photos[i], 's');
+		//uri_list.push_back(std::string(uri));
+		uri_dic[photo_list->photos[i]->id] = std::string(uri);
+	}
+
+	return uri_dic;
+}
+
+dictionary
+flickr::get_title_from_photo_list(flickcurl_photos_list* photo_list) throw()
+{
+	int i = 0;
+	dictionary title_dic;
+	char *title;
+
+	for(i=0; photo_list->photos[i]; i++) {
+		title = photo_list->photos[i]->fields[PHOTO_FIELD_title].string;
+		title_dic[photo_list->photos[i]->id] = std::string(title);
+	}
+
+	return title_dic;
+}
+
+std::vector<std::string>
+flickr::get_id_from_photo_list(flickcurl_photos_list* photo_list) throw()
+{
+	int i = 0;
+	std::vector<std::string> id_list;
+
+	for(i=0; photo_list->photos[i]; i++) {
+		id_list.push_back(std::string(photo_list->photos[i]->id));
+	}
+
+	return id_list;
+}
+
+// Debugging Api - Will be removed later
+void
+flickr::return_photo_list(flickcurl_photos_list* photo_list) throw()
+{
+	int i = 0;
+	int field_type;
+	char* uri;
+
+	for(i=0; photo_list->photos[i]; i++) {
+		uri = flickcurl_photo_as_source_uri(photo_list->photos[i], 's');
+		std::cout << i << "    :    " << photo_list->photos[i]->id << "     "<< uri <<std::endl;
+		for(field_type=0; field_type <= PHOTO_FIELD_LAST; field_type++) {
+			flickcurl_field_value_type datatype=photo_list->photos[i]->fields[field_type].type;
+
+			if(datatype != VALUE_TYPE_NONE)
+				fprintf(stdout, "%s with %s '%s' / %d\n",
+						flickcurl_get_photo_field_label((flickcurl_photo_field_type)field_type),
+						flickcurl_get_field_value_type_label(datatype),
+						photo_list->photos[i]->fields[field_type].string,
+						photo_list->photos[i]->fields[field_type].integer);
+
+		}
+	}
+	return;
+}
+
+std::string
+flickr::get_auth_url(std::string permission) throw()
+{
+	dictionary req_vars;
+	std::string api_key = flickrconf::getApiKey();
+	std::string perms = permission;
+
+	req_vars["api_key"] = api_key;
+	req_vars["perms"] = perms;
+	req_vars["frob"] = frob;
+
+	std::string base_url = flickrconf::getAuthPrefix();
+	return get_signed_url(base_url, req_vars);
+}
+
+void
+flickr::close_flickr_api() throw()
+{
+	flickcurl_free(fc);
+	flickcurl_finish();	
+}
+
+static void
+my_message_handler(void* user_data, const char *message)
+{
+	std::string msg(message);
+	std::string errormsg = "flickr api: ERROR: " + msg;
+	// close_flickr_api();
+	throw FlickcurlException(errormsg);
+}
+
+void
+flickr::initialize_flickr_api() throw()
+{
+	// Get frob using flickcurl.
+	flickcurl_init();
+	fc = flickcurl_new();
+	flickcurl_set_error_handler(fc, my_message_handler, NULL);	
+}
+
+void
+flickr::get_frob() throw()
+{
+		char *cfrob;
+
+		std::string shared_key = flickrconf::getSharedKey();
+		std::string api_key = flickrconf::getApiKey();
+
+		flickcurl_set_api_key(fc, api_key.c_str());
+		flickcurl_set_shared_secret(fc, shared_key.c_str());
+		cfrob = flickcurl_auth_getFrob(fc);
+
+		if (cfrob)
+			frob = std::string(cfrob);
+		else
+			throw NoFrobException();
+
+		return;
+}
+
+std::string
+flickr::get_signed_url(const std::string base_url, dictionary req_vars) throw()
+{
+	std::string shared_key = flickrconf::getSharedKey();
+	std::string signature(shared_key);
+	std::string auth_url(base_url);
+
+	for (dictionary::const_iterator i = req_vars.begin(); i != req_vars.end(); i++) {
+		signature += i->first + i->second;
+		auth_url += i->first + "=" + i->second + "&";
+	}
+
+	auth_url += "api_sig=" + utils::md5sum(signature);
+	return auth_url;	
+}
+
+};
diff --git a/src/common/flickr.h b/src/common/flickr.h
new file mode 100644
index 0000000..6199063
--- /dev/null
+++ b/src/common/flickr.h
@@ -0,0 +1,99 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * flickr.h
+ * Copyright (C) 2009 Rakesh Pandit <rakesh@fedoraproject.org>
+ * 
+ * main-window.cpp is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * main-window.cpp is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef FLICKR_H
+#define FLICKR_H
+
+#include <iostream>
+#include <map>
+#include <vector>
+#include <flickcurl.h>
+
+namespace flickr {
+
+typedef std::map<std::string, std::string> dictionary;
+
+class flickr {
+public:
+	flickr() throw();
+
+	virtual
+		~flickr() throw();
+
+	std::string
+		get_auth_url(std::string permission) throw();
+
+	bool
+		check_auth_done() throw();
+
+	flickcurl_upload_status*
+		upload_photo(flickcurl_upload_params params) throw();
+
+	flickcurl_photos_list*
+		get_photo_list_not_in_any_set() throw();
+
+	flickcurl_photos_list*
+		get_photo_list_in_set(const char* photoset_id) throw();
+
+	// Debugging Api - Will be removed later
+	//	std::vector<dictionary>
+	void
+		return_photo_list(flickcurl_photos_list* photo_list) throw();
+
+	void
+		get_auth_token() throw();
+
+	dictionary
+		get_thumbnail_uri_from_photo_list(flickcurl_photos_list* photo_list) throw();
+
+	dictionary
+		get_title_from_photo_list(flickcurl_photos_list* photo_list) throw();
+
+	std::vector<std::string>
+		get_id_from_photo_list(flickcurl_photos_list* photo_list) throw();
+
+	
+	flickcurl_photoset**
+		get_photosets_list() throw();
+
+private:
+	std::string frob;
+	std::string auth_token;
+	flickcurl *fc;
+
+	void
+		close_flickr_api() throw();
+
+	// Remove it once memory leark in case of crash is fixed.
+	//	void
+	//		my_message_handler(void* user_data, const char *message);
+
+	void
+		initialize_flickr_api() throw();
+
+	void
+		get_frob() throw();
+
+	std::string
+		get_signed_url(const std::string base_url, dictionary req_vars) throw();
+};
+
+};
+
+#endif
diff --git a/src/common/flickrconf.cpp b/src/common/flickrconf.cpp
new file mode 100644
index 0000000..ebf0a8f
--- /dev/null
+++ b/src/common/flickrconf.cpp
@@ -0,0 +1,42 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * flickrconf.cpp
+ * Copyright (C) 2009 Rakesh Pandit <rakesh@fedoraproject.org>
+ * 
+ * main-window.cpp is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * main-window.cpp is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// TODO: Figure out how to use these keys!
+
+#include "flickrconf.h"
+
+namespace flickrconf {
+
+	std::string getSharedKey() {
+		// Confirm keys from [rakesh]
+		std::string shared_key = "abcdefghijklmnop";
+		return shared_key;
+	}
+
+	std::string getApiKey() {
+		// Confirm keys from [rakesh]
+		std::string api_key = "asdfsa;flsadfjklsafdlksaflksdfld";
+		return api_key;
+	}
+
+	std::string getAuthPrefix() {
+		std::string prefix = "http://www.flickr.com/services/auth/?";
+		return prefix;
+	}
+};
diff --git a/src/common/flickrconf.h b/src/common/flickrconf.h
new file mode 100644
index 0000000..9549d4f
--- /dev/null
+++ b/src/common/flickrconf.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * flickrconf.h
+ * Copyright (C) 2009 Rakesh Pandit <rakesh@fedoraproject.org>
+ * 
+ * main-window.cpp is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * main-window.cpp is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef FLICKR_CONF_H
+#define FLICKR_CONF_H
+
+#include <string>
+
+namespace flickrconf {
+
+	// Returns shared key.
+	std::string getSharedKey();
+
+	// Returns shared API keyyeah
+	std::string getApiKey();
+
+	// Return flickr URL
+	std::string getAuthPrefix();
+
+};
+
+#endif
diff --git a/src/common/utils.cpp b/src/common/utils.cpp
new file mode 100644
index 0000000..4d7cafe
--- /dev/null
+++ b/src/common/utils.cpp
@@ -0,0 +1,55 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * utils.cpp
+ * Copyright (C) 2009 Rakesh Pandit <rakesh@fedoraproject.org>
+ * 
+ * main-window.cpp is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * main-window.cpp is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "utils.h"
+
+#include <string>
+#include <stdexcept>
+
+#include <cstdio>
+#include <cstdlib>
+
+namespace utils {
+
+	std::string md5sum(std::string str) {
+
+		std::string cmd = "echo -n " + str + " | md5sum -t";
+		FILE* pfd = popen(cmd.c_str(), "r");
+		std::string sum, result;
+
+		if (pfd == 0) {
+			throw std::runtime_error("md5sum sum could not be calculated" \
+									 " using coreutils command.");
+		}
+
+		while(!feof(pfd)) {
+			char buf[1024] = {0};
+
+			if ( fgets(buf, sizeof(buf), pfd) > 0 ) {
+				result.append(std::string(buf));
+			}
+
+		}
+		pclose(pfd);
+
+		// Remove last 4 non-sum characters from result string.
+		sum = result.substr(0, result.length() - 4);
+		return sum;
+	}
+};
diff --git a/src/common/utils.h b/src/common/utils.h
new file mode 100644
index 0000000..07d631f
--- /dev/null
+++ b/src/common/utils.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * utils.h
+ * Copyright (C) 2009 Rakesh Pandit <rakesh@fedoraproject.org>
+ * 
+ * main-window.cpp is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * main-window.cpp is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_H
+#define UTILS_H
+
+#include <string>
+
+namespace utils {
+
+	// Returns shared key.
+	std::string md5sum(std::string);
+
+};
+
+#endif
diff --git a/src/importer/flickr-import-window.cpp b/src/importer/flickr-import-window.cpp
new file mode 100644
index 0000000..ded32c0
--- /dev/null
+++ b/src/importer/flickr-import-window.cpp
@@ -0,0 +1,148 @@
+//$Id: examplewindow.cc 836 2007-05-09 03:02:38Z jjongsma $ -*- c++ -*-
+
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <iostream>
+#include "flickr-import-window.h"
+
+FlickrImportWindow::FlickrImportWindow()
+: m_Button_Quit(Gtk::Stock::QUIT)
+{
+  set_title("Select images to import: ");
+  set_border_width(5);
+  set_default_size(400, 200);
+
+  pm_VBox = (Gtk::VBox * const )get_vbox();
+
+  //Add the TreeView, inside a ScrolledWindow, with the button underneath:
+  m_ScrolledWindow.add(m_TreeView);
+
+  //Only show the scrollbars when they are necessary:
+  m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+
+  pm_VBox->pack_start(m_ScrolledWindow);
+
+  m_Button_Import.set_label("Import");
+  m_Button_Quit.set_label("Cancel");
+  m_Button_Import.signal_clicked().connect( sigc::mem_fun(*this,
+    &FlickrImportWindow::on_button_import) );
+
+
+  pm_VBox->pack_start(m_ButtonBox, Gtk::PACK_SHRINK);
+  m_ButtonBox.pack_start(m_Button_Quit, Gtk::PACK_SHRINK);
+  m_ButtonBox.pack_start(m_Button_Import, Gtk::PACK_SHRINK);
+
+  m_ButtonBox.set_border_width(5);
+  m_ButtonBox.set_layout(Gtk::BUTTONBOX_END);
+  m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this,
+              &FlickrImportWindow::on_button_quit) );
+
+  //Create the Tree model:
+  //Use our derived model, which overrides some Gtk::TreeDragDest and
+  //Gtk::TreeDragSource virtual functions:
+  //The columns are declared in the overridden TreeModel.
+  m_refTreeModel = ImportTreeModel::create();
+  m_TreeView.set_model(m_refTreeModel);
+
+  //Enable Drag-and-Drop of TreeView rows:
+  m_TreeView.enable_model_drag_source();
+  m_TreeView.enable_model_drag_dest();
+
+  //Fill the TreeView's model
+//   Gtk::TreeModel::Row row = *(m_refTreeModel->append());
+//   row[m_refTreeModel->m_Columns.m_col_id] = 1;
+//   row[m_refTreeModel->m_Columns.m_col_name] = "Abc1";
+//   row[m_refTreeModel->m_Columns.m_col_draggable] = true;
+//   row[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;
+
+//   Gtk::TreeModel::Row childrow = *(m_refTreeModel->append(row.children()));
+//   childrow[m_refTreeModel->m_Columns.m_col_id] = 11;
+//   childrow[m_refTreeModel->m_Columns.m_col_name] = "Abc2";
+//   childrow[m_refTreeModel->m_Columns.m_col_draggable] = true;
+//   childrow[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;
+
+//   childrow = *(m_refTreeModel->append(row.children()));
+//   childrow[m_refTreeModel->m_Columns.m_col_id] = 12;
+//   childrow[m_refTreeModel->m_Columns.m_col_name] = "Abc3";
+//   childrow[m_refTreeModel->m_Columns.m_col_draggable] = true;
+//   childrow[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;
+
+//   row = *(m_refTreeModel->append());
+//   row[m_refTreeModel->m_Columns.m_col_id] = 2;
+//   row[m_refTreeModel->m_Columns.m_col_name] = "Abc3";
+//   row[m_refTreeModel->m_Columns.m_col_draggable] = true;
+//   row[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;
+
+//   row = *(m_refTreeModel->append());
+//   row[m_refTreeModel->m_Columns.m_col_id] = 3;
+//   row[m_refTreeModel->m_Columns.m_col_name] = "Abc4";
+//   row[m_refTreeModel->m_Columns.m_col_draggable] = true;
+//   row[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;
+
+//   childrow = *(m_refTreeModel->append(row.children()));
+//   childrow[m_refTreeModel->m_Columns.m_col_id] = 31;
+//   childrow[m_refTreeModel->m_Columns.m_col_name] = "Abc5";
+//   childrow[m_refTreeModel->m_Columns.m_col_draggable] = true;
+//   childrow[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;
+
+  //Add the TreeView's view columns:
+  m_TreeView.append_column("S. no.", m_refTreeModel->m_Columns.m_col_id);
+  m_TreeView.append_column("Title", m_refTreeModel->m_Columns.m_col_name);
+  //  m_TreeView.append_column_editable("Draggable",
+  //      m_refTreeModel->m_Columns.m_col_draggable);
+  //  m_TreeView.append_column_editable("Receives Drags",
+  //          m_refTreeModel->m_Columns.m_col_receivesdrags);
+
+  show_all_children();
+}
+
+FlickrImportWindow::~FlickrImportWindow()
+{
+}
+
+void FlickrImportWindow::on_button_quit()
+{
+  hide();
+}
+
+void
+FlickrImportWindow::on_button_import() throw()
+{
+}
+
+void
+FlickrImportWindow::make_imported_tree_per_set(std::vector<std::string> id_list, \
+						  dictionary title_dic, \
+						  std::string set_name) throw()
+{
+  int count = 0;
+  Gtk::TreeModel::Row row = *(m_refTreeModel->append());
+  row[m_refTreeModel->m_Columns.m_col_id] = 1;
+  row[m_refTreeModel->m_Columns.m_col_name] = set_name.c_str();
+  row[m_refTreeModel->m_Columns.m_col_draggable] = false;
+  row[m_refTreeModel->m_Columns.m_col_receivesdrags] = true;
+
+  for(std::vector<std::string>::iterator it = id_list.begin(); it!=id_list.end(); ++it) {
+    count++;
+    Gtk::TreeModel::Row childrow = *(m_refTreeModel->append(row.children()));
+    childrow[m_refTreeModel->m_Columns.m_col_id] = count;
+    childrow[m_refTreeModel->m_Columns.m_col_name] = title_dic[(*it)].c_str();
+    childrow[m_refTreeModel->m_Columns.m_col_draggable] = true;
+    childrow[m_refTreeModel->m_Columns.m_col_receivesdrags] = false;
+  }
+
+}
diff --git a/src/importer/flickr-import-window.h b/src/importer/flickr-import-window.h
new file mode 100644
index 0000000..6b168e9
--- /dev/null
+++ b/src/importer/flickr-import-window.h
@@ -0,0 +1,60 @@
+//$Id: examplewindow.h 705 2006-07-19 02:55:32Z jjongsma $ -*- c++ -*-
+
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Sofware Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef GTKMM_EXAMPLEWINDOW_H
+#define GTKMM_EXAMPLEWINDOW_H
+
+#include <gtkmm.h>
+#include <flickcurl.h>
+#include "import-tree-model.h"
+
+typedef std::map<std::string, std::string> dictionary;
+
+class FlickrImportWindow :
+  public Gtk::Dialog
+{
+public:
+  FlickrImportWindow();
+  virtual ~FlickrImportWindow();
+
+  void
+  make_imported_tree_per_set(std::vector<std::string> id_list, dictionary title_dic, \
+				std::string set_name) throw();
+
+protected:
+  //Signal handlers:
+  virtual void on_button_quit();
+
+
+  //Child widgets:
+  Gtk::VBox* pm_VBox;
+
+  Gtk::ScrolledWindow m_ScrolledWindow;
+  Gtk::TreeView m_TreeView;
+  Glib::RefPtr<ImportTreeModel> m_refTreeModel;
+
+  Gtk::HButtonBox m_ButtonBox;
+  Gtk::Button m_Button_Quit;
+  Gtk::Button m_Button_Import;
+
+  virtual void
+  on_button_import() throw();
+
+};
+
+#endif //GTKMM_EXAMPLEWINDOW_H
diff --git a/src/importer/import-tree-model.cpp b/src/importer/import-tree-model.cpp
new file mode 100644
index 0000000..49ef638
--- /dev/null
+++ b/src/importer/import-tree-model.cpp
@@ -0,0 +1,113 @@
+//$Id: treemodel_dnd.cc 836 2007-05-09 03:02:38Z jjongsma $ -*- c++ -*-
+
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "import-tree-model.h"
+#include <iostream>
+
+ImportTreeModel::ImportTreeModel()
+{
+  //We can't just call Gtk::TreeModel(m_Columns) in the initializer list
+  //because m_Columns does not exist when the base class constructor runs.
+  //And we can't have a static m_Columns instance, because that would be
+  //instantiated before the gtkmm type system.
+  //So, we use this method, which should only be used just after creation:
+  set_column_types(m_Columns);
+}
+
+Glib::RefPtr<ImportTreeModel> ImportTreeModel::create()
+{
+  return Glib::RefPtr<ImportTreeModel>( new ImportTreeModel() );
+}
+
+bool
+ImportTreeModel::row_draggable_vfunc(const Gtk::TreeModel::Path& path) const
+{
+  // Make the value of the "draggable" column determine whether this row can
+  // be dragged:
+
+  //TODO: Add a const version of get_iter to TreeModel:
+  ImportTreeModel* unconstThis = const_cast<ImportTreeModel*>(this);
+  const_iterator iter = unconstThis->get_iter(path);
+  //const_iterator iter = get_iter(path);
+  if(iter)
+  {
+    Row row = *iter;
+    bool is_draggable = row[m_Columns.m_col_draggable];
+    return is_draggable;
+  }
+
+#ifdef GLIBMM_VFUNCS_ENABLED
+  return Gtk::TreeStore::row_draggable_vfunc(path);
+#else
+  return false;
+#endif
+}
+
+bool
+ImportTreeModel::row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest,
+        const Gtk::SelectionData& selection_data) const
+{
+  //Make the value of the "receives drags" column determine whether a row can be
+  //dragged into it:
+
+  //dest is the path that the row would have after it has been dropped:
+  //But in this case we are more interested in the parent row:
+  Gtk::TreeModel::Path dest_parent = dest;
+  bool dest_is_not_top_level = dest_parent.up();
+  if(!dest_is_not_top_level || dest_parent.empty())
+  {
+    //The user wants to move something to the top-level.
+    //Let's always allow that.
+  }
+  else
+  {
+    //Get an iterator for the row at this path:
+    //We must unconst this. This should not be necessary with a future version
+    //of gtkmm.
+    //TODO: Add a const version of get_iter to TreeModel:
+    ImportTreeModel* unconstThis = const_cast<ImportTreeModel*>(this);
+    const_iterator iter_dest_parent = unconstThis->get_iter(dest_parent);
+    //const_iterator iter_dest_parent = get_iter(dest);
+    if(iter_dest_parent)
+    {
+      Row row = *iter_dest_parent;
+      bool receives_drags = row[m_Columns.m_col_receivesdrags];
+      return receives_drags;
+    }
+  }
+
+  //You could also examine the row being dragged (via selection_data)
+  //if you must look at both rows to see whether a drop should be allowed.
+  //You could use
+  //TODO: Add const version of get_from_selection_data(): Glib::RefPtr<const
+  //Gtk::TreeModel> refThis = Glib::RefPtr<const Gtk::TreeModel>(this);
+  //
+  //Glib::RefPtr<Gtk::TreeModel> refThis =
+  //Glib::RefPtr<Gtk::TreeModel>(const_cast<ImportTreeModel*>(this));
+  //refThis->reference(); //, true /* take_copy */)
+  //Gtk::TreeModel::Path path_dragged_row;
+  //Gtk::TreeModel::Path::get_from_selection_data(selection_data, refThis,
+  //path_dragged_row);
+
+#ifdef GLIBMM_VFUNCS_ENABLED
+  return Gtk::TreeStore::row_drop_possible_vfunc(dest, selection_data);
+#else
+  return false;
+#endif
+}
+
diff --git a/src/importer/import-tree-model.h b/src/importer/import-tree-model.h
new file mode 100644
index 0000000..e54ea5e
--- /dev/null
+++ b/src/importer/import-tree-model.h
@@ -0,0 +1,56 @@
+//$Id: treemodel_dnd.h 852 2007-06-10 09:12:36Z murrayc $ -*- c++ -*-
+
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef GTKMM_EXAMPLE_TREEMODEL_DND_H
+#define GTKMM_EXAMPLE_TREEMODEL_DND_H
+
+#include <gtkmm.h>
+
+class ImportTreeModel : public Gtk::TreeStore
+{
+protected:
+  ImportTreeModel();
+
+public:
+
+  //Tree model columns:
+  class ModelColumns : public Gtk::TreeModel::ColumnRecord
+  {
+  public:
+
+    ModelColumns()
+    { add(m_col_id); add(m_col_name); add(m_col_draggable); add(m_col_receivesdrags); }
+
+    Gtk::TreeModelColumn<int> m_col_id;
+    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
+    Gtk::TreeModelColumn<bool> m_col_draggable;
+    Gtk::TreeModelColumn<bool> m_col_receivesdrags;
+  };
+
+  ModelColumns m_Columns;
+
+  static Glib::RefPtr<ImportTreeModel> create();
+
+protected:
+  //Overridden virtual functions:
+  virtual bool row_draggable_vfunc(const Gtk::TreeModel::Path& path) const;
+  virtual bool row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest, const Gtk::SelectionData& selection_data) const;
+  
+};
+
+#endif //GTKMM_EXAMPLE_TREEMODEL_DND_H
diff --git a/src/importer/picasaweb-source.cpp b/src/importer/picasaweb-source.cpp
new file mode 100644
index 0000000..0135cc5
--- /dev/null
+++ b/src/importer/picasaweb-source.cpp
@@ -0,0 +1,178 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * picasaweb-source.cpp
+ * Copyright (C) Debarshi Ray 2009 <rishi@gnu.org>
+ * 
+ * picasaweb-source.cpp is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * picasaweb-source.cpp is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+
+#include "config.h"
+#include "picasaweb-source.h"
+#include "progress-observer.h"
+
+namespace Solang
+{
+
+AuthWindow::AuthWindow() throw() :
+	auth_table(3, 2, true),
+	button_cancel(Gtk::Stock::QUIT),
+	button_ok(Gtk::Stock::OK),
+	la_username("Username:"),
+	la_password("Password:")
+{
+	auth_done = false;
+
+	en_username.set_editable(true);
+	en_password.set_editable(true);
+
+	set_title("Authentication Picasaweb");
+
+	Gtk::VBox * const dialog_vbox = get_vbox();
+	dialog_vbox->pack_start(auth_table);
+
+	auth_table.attach(la_username, 0, 1, 0, 1);
+	auth_table.attach(en_username, 1, 2, 0, 1);
+	auth_table.attach(la_password, 0, 1, 1, 2);
+	auth_table.attach(en_password, 1, 2, 1, 2);
+	auth_table.attach(button_cancel, 0, 1, 2, 3);
+	auth_table.attach(button_ok, 1, 2, 2, 3);
+
+	button_cancel.signal_clicked().connect( sigc::mem_fun(*this,
+		&AuthWindow::on_button_cancel) );
+
+	button_ok.signal_clicked().connect( sigc::mem_fun(*this,
+		&AuthWindow::on_button_ok) );
+
+	en_password.set_visibility(false);
+
+	show_all_children();
+}
+
+AuthWindow::~AuthWindow() throw()
+{
+}
+
+void
+AuthWindow::on_button_cancel() throw()
+{
+	
+	hide();
+}
+
+void
+AuthWindow::on_button_ok() throw()
+{
+	username = en_username.get_text();
+	password = en_password.get_text();
+	auth_done = true;
+	hide();
+}
+
+PicasawebSource::PicasawebSource() throw() :
+    PhotoSource(),
+    button_()
+{
+	button_.set_label("Authenticate");
+	button_.signal_clicked().connect( sigc::mem_fun(*this,
+		&PicasawebSource::on_button_clicked_authentication) );
+
+	set_authurl_confirmed(false);
+	set_auth_info(false);
+}
+
+PicasawebSource::~PicasawebSource() throw()
+{
+}
+
+PhotoPtr
+PicasawebSource::import(const PhotoPtr & photo,
+                     const IStoragePtr & storage,
+                     const TagList & tag, Database & db,
+                     const ProgressObserverPtr & observer) throw()
+{
+	return PhotoPtr(photo);
+}
+
+PhotoList
+PicasawebSource::import(const PhotoList & photos,
+                     const IStoragePtr & storage,
+                     const TagList & tag, Database & db,
+                     const ProgressObserverPtr & observer) throw()
+{
+    observer->set_num_events(photos.size());
+    observer->set_event_description("Importing photos");
+
+	PhotoList imported_photos;
+    return imported_photos;
+}
+
+PhotoList
+PicasawebSource::import(const IStoragePtr & storage, const TagList & tag,
+                     Database & db,
+                     const ProgressObserverPtr & observer) throw()
+{
+    PhotoList files;
+    return import(files, storage, tag, db, observer);
+}
+
+void
+PicasawebSource::on_button_clicked_authentication() throw()
+{
+
+	if(is_auth_info_present()) {
+		button_.set_label("Confirmed!");
+		return;
+	}
+
+	AuthWindow auth_window;
+	auth_window.run();
+
+	if (auth_window.is_auth_done()) {
+		picasaweb_user = auth_window.username;
+		picasaweb_passwd = auth_window.password;
+
+		set_auth_info(true);
+		button_.set_label("Confirm via Picasaweb!");
+	}
+
+	return;
+}
+
+Gtk::Widget &
+PicasawebSource::get_browser() throw()
+{
+    return button_;
+}
+
+Glib::ustring
+PicasawebSource::get_label() const throw()
+{
+    return Glib::ustring("_Picasa...");
+}
+
+Glib::ustring
+PicasawebSource::get_name() const throw()
+{
+    return Glib::ustring("Picasaweb");
+}
+
+Gtk::StockID
+PicasawebSource::get_stock_id() const throw()
+{
+    return Gtk::StockID();
+}
+
+} // namespace Solang
diff --git a/src/importer/picasaweb-source.h b/src/importer/picasaweb-source.h
new file mode 100644
index 0000000..30a9aa0
--- /dev/null
+++ b/src/importer/picasaweb-source.h
@@ -0,0 +1,126 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * picasaweb-source.h
+ * Copyright (C) Debarshi Ray 2009 <rishi@gnu.org>
+ * 
+ * picasaweb-source.h is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * picasaweb-source.h is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SOLANG_PICASAWEB_SOURCE_H
+#define SOLANG_PICASAWEB_SOURCE_H
+
+#include <glibmm.h>
+#include <gtkmm.h>
+
+#include "photo-source.h"
+
+namespace Solang
+{
+
+class AuthWindow: 
+	public Gtk::Dialog
+{
+public:
+	AuthWindow() throw();
+	virtual
+		~AuthWindow() throw();
+	bool
+		is_auth_done() throw() {return auth_done;}
+protected:
+	// Signal handlers
+	virtual void
+		on_button_cancel() throw();
+
+	Gtk::Table auth_table;
+	Gtk::Button button_cancel, button_ok;
+	Gtk::Entry en_username, en_password;
+	Gtk::Label la_username, la_password;
+private:
+	std::string username;
+	std::string password;
+	bool auth_done;
+
+	virtual void
+		on_button_ok() throw();
+
+	// To share authentication info
+	friend class PicasawebSource;
+};
+
+class PicasawebSource :
+    public PhotoSource, public Gtk::Window
+{
+public:
+    PicasawebSource() throw();
+
+    virtual
+    ~PicasawebSource() throw();
+
+    virtual PhotoPtr
+    import(const PhotoPtr & photo, const IStoragePtr & storage,
+           const TagList & tag, Database & db,
+           const ProgressObserverPtr & observer) throw();
+
+    virtual PhotoList
+    import(const PhotoList & photos, const IStoragePtr & storage,
+           const TagList & tag, Database & db,
+           const ProgressObserverPtr & observer) throw();
+
+    virtual PhotoList
+    import(const IStoragePtr & storage, const TagList & tag,
+           Database & db, const ProgressObserverPtr & observer) throw();
+
+    virtual Widget &
+    get_browser() throw();
+
+    virtual Glib::ustring
+    get_label() const throw();
+
+    virtual Glib::ustring
+    get_name() const throw();
+
+    virtual Gtk::StockID
+    get_stock_id() const throw();
+
+	bool
+		is_authurl_confirmed() const throw() {return url_confirmed;}
+
+	bool
+		is_auth_info_present() const throw() {return auth_info;}
+
+protected:
+	Gtk::Button button_;
+
+private:
+	virtual void
+		on_button_clicked_authentication() throw();
+
+	void
+		set_authurl_confirmed(bool value) throw() {url_confirmed = value;}
+
+	void
+		set_auth_info(bool value) throw() {auth_info = value;}
+
+	std::string picasaweb_user;
+	std::string picasaweb_passwd;
+	std::string picasaweb_auth_url;
+
+	bool auth_info;
+	bool url_confirmed;
+	std::string url;
+};
+
+} // namespace Solang
+
+#endif // SOLANG_PICASAWEB_SOURCE_H
-- 
1.6.0.6

