Commit c1741c20 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

Added ability to import from and export to 23hq.com

[bug #657269]
parent 638fa7df
......@@ -6,18 +6,19 @@ iconsdir = $(themedir)/$(size)/$(context)
icons_DATA = \
browser-mode.png \
facebook.png \
file-catalog.png \
file-library.png \
file-search.png \
flickr.png \
histogram.png \
histogram-linear.png \
histogram-logarithmic.png \
image-navigator.png \
map.png \
photobucket.png \
picasaweb.png \
site-facebook.png \
site-flickr.png \
site-photobucket.png \
site-picasaweb.png \
site-twentythree.png \
tool-adjust-colors.png \
tool-crop.png \
tool-desaturate.png \
......
......@@ -29,13 +29,26 @@
static FlickrServer www_flickr_com = {
"Flickr.com",
"Flickr",
"http://www.flickr.com",
"http://www.flickr.com/services/auth/",
"http://api.flickr.com/services/rest",
"http://api.flickr.com/services/upload/",
"8960706ee7f4151e893b11837e9c24ce",
"1ff8d1e45c873423"
"1ff8d1e45c873423",
FALSE
};
static FlickrServer www_23hq_com = {
"23",
"http://www.23hq.com",
"http://www.23hq.com/services/auth/",
"http://www.23hq.com/services/rest",
"http://www.23hq.com/services/upload/",
"8960706ee7f4151e893b11837e9c24ce",
"1ff8d1e45c873423",
TRUE
};
......@@ -63,3 +76,29 @@ gth_browser_activate_action_import_flicker (GtkAction *action,
{
dlg_import_from_flickr (&www_flickr_com, browser);
}
void
gth_browser_activate_action_export_23 (GtkAction *action,
GthBrowser *browser)
{
GList *items;
GList *file_list;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
if (file_list == NULL)
file_list = gth_file_store_get_visibles (gth_browser_get_file_store (browser));
dlg_export_to_flickr (&www_23hq_com, browser, file_list);
_g_object_list_unref (file_list);
_gtk_tree_path_list_free (items);
}
void
gth_browser_activate_action_import_23 (GtkAction *action,
GthBrowser *browser)
{
dlg_import_from_flickr (&www_23hq_com, browser);
}
......@@ -28,5 +28,7 @@
DEFINE_ACTION(gth_browser_activate_action_export_flicker)
DEFINE_ACTION(gth_browser_activate_action_import_flicker)
DEFINE_ACTION(gth_browser_activate_action_export_23)
DEFINE_ACTION(gth_browser_activate_action_import_23)
#endif /* ACTIONS_H */
......@@ -37,11 +37,13 @@ static const char *ui_info =
" <menu name='Import' action='ImportMenu'>"
" <placeholder name='Web_Services'>"
" <menuitem action='File_Import_Flicker'/>"
" <menuitem action='File_Import_23'/>"
" </placeholder>"
" </menu>"
" <menu name='Export' action='ExportMenu'>"
" <placeholder name='Web_Services'>"
" <menuitem action='File_Export_Flicker'/>"
" <menuitem action='File_Export_23'/>"
" </placeholder>"
" </menu>"
" </menu>"
......@@ -49,20 +51,29 @@ static const char *ui_info =
" <popup name='ExportPopup'>"
" <placeholder name='Web_Services'>"
" <menuitem action='File_Export_Flicker'/>"
" <menuitem action='File_Export_23'/>"
" </placeholder>"
" </popup>"
"</ui>";
static GtkActionEntry action_entries[] = {
{ "File_Import_Flicker", "flickr",
{ "File_Import_Flicker", "site-flickr",
N_("_Flickr..."), NULL,
N_("Download photos from Flickr"),
G_CALLBACK (gth_browser_activate_action_import_flicker) },
{ "File_Export_Flicker", "flickr",
{ "File_Export_Flicker", "site-flickr",
N_("_Flickr..."), NULL,
N_("Upload photos to Flickr"),
G_CALLBACK (gth_browser_activate_action_export_flicker) },
{ "File_Import_23", "site-twentythree",
N_("_23..."), NULL,
N_("Download photos from 23"),
G_CALLBACK (gth_browser_activate_action_import_23) },
{ "File_Export_23", "site-twentythree",
N_("_23..."), NULL,
N_("Upload photos to 23"),
G_CALLBACK (gth_browser_activate_action_export_23) },
};
......@@ -107,5 +118,9 @@ fl__gth_browser_construct_cb (GthBrowser *browser)
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/MenuBar/File/Export/Web_Services/File_Export_Flicker")), TRUE);
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/ExportPopup/Web_Services/File_Export_Flicker")), TRUE);
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/MenuBar/File/Import/Web_Services/File_Import_23")), TRUE);
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/MenuBar/File/Export/Web_Services/File_Export_23")), TRUE);
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/ExportPopup/Web_Services/File_Export_23")), TRUE);
g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
}
......@@ -363,24 +363,12 @@ list_photos_ready_cb (GObject *source_object,
list = NULL;
for (scan = data->photos; scan; scan = scan->next) {
FlickrPhoto *photo = scan->data;
const char *url;
GthFileData *file_data;
url = NULL;
if (photo->url_s != NULL)
url = photo->url_s;
else if (photo->url_m != NULL)
url = photo->url_m;
else if (photo->url_o != NULL)
url = photo->url_o;
if (url == NULL)
url = photo->url_sq;
if (url == NULL)
if (photo->url_o == NULL)
continue;
file_data = gth_file_data_new_for_uri (url, (photo->mime_type != NULL) ? photo->mime_type : "image/jpeg");
file_data = gth_file_data_new_for_uri (photo->url_o, (photo->mime_type != NULL) ? photo->mime_type : "image/jpeg");
g_file_info_set_file_type (file_data->info, G_FILE_TYPE_REGULAR);
g_file_info_set_size (file_data->info, FAKE_SIZE); /* set a fake size to make the progress dialog work correctly */
g_file_info_set_attribute_object (file_data->info, "flickr::object", G_OBJECT (photo));
......
......@@ -161,7 +161,7 @@ flickr_authentication_new (FlickrConnection *conn,
self->priv->conn = g_object_ref (conn);
self->priv->service = g_object_ref (service);
self->priv->cancellable = _g_object_ref (cancellable);
self->priv->accounts = flickr_accounts_load_from_file ();
self->priv->accounts = flickr_accounts_load_from_file (conn->server->name);
self->priv->account = flickr_accounts_find_default (self->priv->accounts);
self->priv->browser = browser;
self->priv->dialog = dialog;
......@@ -254,7 +254,7 @@ upload_status_ready_cb (GObject *source_object,
show_authentication_error_dialog (self, &error);
return;
}
flickr_accounts_save_to_file (self->priv->accounts, self->priv->account);
flickr_accounts_save_to_file (self->priv->conn->server->name, self->priv->accounts, self->priv->account);
g_signal_emit (self, flickr_authentication_signals[READY], 0, user);
......@@ -693,7 +693,7 @@ account_manager_dialog_response_cb (GtkDialog *dialog,
}
else
g_signal_emit (self, flickr_authentication_signals[ACCOUNTS_CHANGED], 0);
flickr_accounts_save_to_file (self->priv->accounts, self->priv->account);
flickr_accounts_save_to_file (self->priv->conn->server->name, self->priv->accounts, self->priv->account);
gtk_widget_destroy (GTK_WIDGET (dialog));
break;
......
......@@ -26,6 +26,11 @@
#include "flickr-photo.h"
struct _FlickrPhotoPrivate {
FlickrServer *server;
};
static gpointer flickr_photo_parent_class = NULL;
......@@ -49,6 +54,7 @@ static void
flickr_photo_class_init (FlickrPhotoClass *klass)
{
flickr_photo_parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (FlickrPhotoPrivate));
G_OBJECT_CLASS (klass)->finalize = flickr_photo_finalize;
}
......@@ -113,6 +119,8 @@ flickr_photo_dom_domizable_interface_init (DomDomizableIface *iface)
static void
flickr_photo_instance_init (FlickrPhoto *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, FLICKR_TYPE_PHOTO, FlickrPhotoPrivate);
self->priv->server = NULL;
}
......@@ -152,9 +160,14 @@ flickr_photo_get_type (void)
FlickrPhoto *
flickr_photo_new (void)
flickr_photo_new (FlickrServer *server)
{
return g_object_new (FLICKR_TYPE_PHOTO, NULL);
FlickrPhoto *self;
self = g_object_new (FLICKR_TYPE_PHOTO, NULL);
self->priv->server = server;
return self;
}
......@@ -198,11 +211,24 @@ flickr_photo_set_is_primary (FlickrPhoto *self,
}
static char *
flickr_get_static_url (FlickrPhoto *self,
const char *subtype)
{
if ((self->priv->server != NULL) && self->priv->server->automatic_urls)
return g_strdup_printf ("%s/%s/%s_%s%s.jpg", self->priv->server->url, self->server, self->id, self->secret, subtype);
else
return NULL;
}
void
flickr_photo_set_url_sq (FlickrPhoto *self,
const char *value)
{
_g_strset (&self->url_sq, value);
if (self->url_sq == NULL)
self->url_sq = flickr_get_static_url (self, "_sq");
}
......@@ -211,6 +237,8 @@ flickr_photo_set_url_t (FlickrPhoto *self,
const char *value)
{
_g_strset (&self->url_t, value);
if (self->url_t == NULL)
self->url_t = flickr_get_static_url (self, "_t");
}
......@@ -219,6 +247,8 @@ flickr_photo_set_url_s (FlickrPhoto *self,
const char *value)
{
_g_strset (&self->url_s, value);
if (self->url_s == NULL)
self->url_s = flickr_get_static_url (self, "_s");
}
......@@ -227,6 +257,8 @@ flickr_photo_set_url_m (FlickrPhoto *self,
const char *value)
{
_g_strset (&self->url_m, value);
if (self->url_m == NULL)
self->url_m = flickr_get_static_url (self, "_m");
}
......@@ -235,6 +267,17 @@ flickr_photo_set_url_o (FlickrPhoto *self,
const char *value)
{
_g_strset (&self->url_o, value);
if (self->url_o == NULL)
self->url_o = flickr_get_static_url (self, "");
if (self->url_o == NULL) {
if (self->url_m != NULL)
_g_strset (&self->url_o, self->url_m);
else if (self->url_s != NULL)
_g_strset (&self->url_o, self->url_s);
else if (self->url_sq != NULL)
_g_strset (&self->url_o, self->url_sq);
}
}
......
......@@ -24,6 +24,7 @@
#include <glib.h>
#include <glib-object.h>
#include "flickr-types.h"
G_BEGIN_DECLS
......@@ -62,29 +63,29 @@ struct _FlickrPhotoClass {
};
GType flickr_photo_get_type (void);
FlickrPhoto * flickr_photo_new (void);
void flickr_photo_set_id (FlickrPhoto *self,
const char *value);
void flickr_photo_set_secret (FlickrPhoto *self,
const char *value);
void flickr_photo_set_server (FlickrPhoto *self,
const char *value);
void flickr_photo_set_title (FlickrPhoto *self,
const char *value);
void flickr_photo_set_is_primary (FlickrPhoto *self,
const char *value);
void flickr_photo_set_url_sq (FlickrPhoto *self,
const char *value);
void flickr_photo_set_url_t (FlickrPhoto *self,
const char *value);
void flickr_photo_set_url_s (FlickrPhoto *self,
const char *value);
void flickr_photo_set_url_m (FlickrPhoto *self,
const char *value);
void flickr_photo_set_url_o (FlickrPhoto *self,
const char *value);
void flickr_photo_set_original_format (FlickrPhoto *self,
const char *value);
FlickrPhoto * flickr_photo_new (FlickrServer *server);
void flickr_photo_set_id (FlickrPhoto *self,
const char *value);
void flickr_photo_set_secret (FlickrPhoto *self,
const char *value);
void flickr_photo_set_server (FlickrPhoto *self,
const char *value);
void flickr_photo_set_title (FlickrPhoto *self,
const char *value);
void flickr_photo_set_is_primary (FlickrPhoto *self,
const char *value);
void flickr_photo_set_url_sq (FlickrPhoto *self,
const char *value);
void flickr_photo_set_url_t (FlickrPhoto *self,
const char *value);
void flickr_photo_set_url_s (FlickrPhoto *self,
const char *value);
void flickr_photo_set_url_m (FlickrPhoto *self,
const char *value);
void flickr_photo_set_url_o (FlickrPhoto *self,
const char *value);
void flickr_photo_set_original_format (FlickrPhoto *self,
const char *value);
G_END_DECLS
......
......@@ -1100,16 +1100,37 @@ flickr_service_list_photos_finish (FlickrService *self,
/* utilities */
/* Used for compatibility with the original Flickr uploader that used
* flickr.xml as filename */
static char *
get_server_accounts_filename (const char *server_name)
{
char *name;
char *filename;
name = g_ascii_strdown (server_name, -1);
filename = g_strconcat (name, ".xml", NULL);
g_free (name);
return filename;
}
GList *
flickr_accounts_load_from_file (void)
flickr_accounts_load_from_file (const char *server_name)
{
GList *accounts = NULL;
char *filename;
char *buffer;
char *accounts_filename;
gsize len;
DomDocument *doc;
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "flickr.xml", NULL);
accounts_filename = get_server_accounts_filename (server_name);
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", accounts_filename, NULL);
g_free (accounts_filename);
if (! g_file_get_contents (filename, &buffer, &len, NULL)) {
g_free (filename);
return NULL;
......@@ -1166,7 +1187,8 @@ flickr_accounts_find_default (GList *accounts)
void
flickr_accounts_save_to_file (GList *accounts,
flickr_accounts_save_to_file (const char *server_name,
GList *accounts,
FlickrAccount *default_account)
{
DomDocument *doc;
......@@ -1174,6 +1196,7 @@ flickr_accounts_save_to_file (GList *accounts,
GList *scan;
char *buffer;
gsize len;
char *accounts_filename;
char *filename;
GFile *file;
......@@ -1192,8 +1215,9 @@ flickr_accounts_save_to_file (GList *accounts,
dom_element_append_child (root, node);
}
gth_user_dir_make_dir_for_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "flickr.xml", NULL);
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "flickr.xml", NULL);
accounts_filename = get_server_accounts_filename (server_name);
gth_user_dir_make_dir_for_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", accounts_filename, NULL);
filename = gth_user_dir_get_file (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", accounts_filename, NULL);
file = g_file_new_for_path (filename);
buffer = dom_document_dump (doc, &len);
g_write_file (file, FALSE, G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION, buffer, len, NULL, NULL);
......@@ -1201,5 +1225,6 @@ flickr_accounts_save_to_file (GList *accounts,
g_free (buffer);
g_object_unref (file);
g_free (filename);
g_free (accounts_filename);
g_object_unref (doc);
}
......@@ -123,9 +123,10 @@ GList * flickr_service_list_photos_finish (FlickrService
/* utilities */
GList * flickr_accounts_load_from_file (void);
GList * flickr_accounts_load_from_file (const char *server_name);
FlickrAccount * flickr_accounts_find_default (GList *accounts);
void flickr_accounts_save_to_file (GList *accounts,
void flickr_accounts_save_to_file (const char *server_name,
GList *accounts,
FlickrAccount *default_account);
#endif /* FLICKR_SERVICE_H */
......@@ -55,6 +55,7 @@ typedef struct {
const char *upload_url;
const char *api_key;
const char *shared_secret;
gboolean automatic_urls;
} FlickrServer;
#endif /* FLICKR_TYPES_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment