Commit 42196942 authored by Mario Sanchez Prada's avatar Mario Sanchez Prada
Browse files

Allow handling URIs instead of just local filepaths

This opens the door to loading pictures in frogr from different remote
sources, such as local samba shares, ssh or ftp servers.
parent 02d12a48
......@@ -513,11 +513,10 @@ _get_soup_message_for_upload (GFile *file,
GHashTableIter iter;
gpointer key, value;
gchar *mime_type;
gchar *filepath;
gchar *fileuri;
/* Gather needed information */
filepath = g_file_get_path (file);
fileuri = g_file_get_uri (file);
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_QUERY_INFO_NONE,
......@@ -537,17 +536,15 @@ _get_soup_message_for_upload (GFile *file,
/* Append the content of the file */
buffer = soup_buffer_new (SOUP_MEMORY_TAKE, contents, length);
fileuri = g_filename_to_uri (filepath, NULL, NULL);
soup_multipart_append_form_file (mpart, "photo", fileuri,
mime_type, buffer);
g_free (fileuri);
/* Get the associated message */
msg = soup_form_request_new_from_multipart (FLICKR_API_UPLOAD_URL, mpart);
/* Free */
soup_multipart_free (mpart);
g_free (filepath);
g_free (fileuri);
g_free (mime_type);
/* Return message */
......@@ -1592,7 +1589,7 @@ fsp_session_get_upload_status_finish (FspSession *self,
void
fsp_session_upload_async (FspSession *self,
const gchar *filepath,
const gchar *fileuri,
const gchar *title,
const gchar *description,
const gchar *tags,
......@@ -1607,7 +1604,7 @@ fsp_session_upload_async (FspSession *self,
gpointer data)
{
g_return_if_fail (FSP_IS_SESSION (self));
g_return_if_fail (filepath != NULL);
g_return_if_fail (fileuri != NULL);
FspSessionPrivate *priv = NULL;
SoupSession *soup_session = NULL;
......@@ -1650,7 +1647,7 @@ fsp_session_upload_async (FspSession *self,
up_clos->extra_params = extra_params;
/* Asynchronously load the contents of the file */
file = g_file_new_for_path (filepath);
file = g_file_new_for_uri (fileuri);
g_file_load_contents_async (file, NULL, _load_file_contents_cb, up_clos);
}
......
......@@ -127,7 +127,7 @@ fsp_session_get_upload_status_finish (FspSession *self,
void
fsp_session_upload_async (FspSession *self,
const gchar *filepath,
const gchar *fileuri,
const gchar *title,
const gchar *description,
const gchar *tags,
......
......@@ -504,7 +504,7 @@ _upload_picture (FrogrController *self, FrogrPicture *picture,
_enable_cancellable (self, TRUE);
fsp_session_upload_async (priv->session,
frogr_picture_get_filepath (picture),
frogr_picture_get_fileuri (picture),
frogr_picture_get_title (picture),
frogr_picture_get_description (picture),
frogr_picture_get_tags (picture),
......@@ -2132,10 +2132,10 @@ frogr_controller_revoke_authorization (FrogrController *self)
void
frogr_controller_load_pictures (FrogrController *self,
GSList *filepaths)
GSList *fileuris)
{
FrogrPictureLoader *fploader;
fploader = frogr_picture_loader_new (filepaths,
fploader = frogr_picture_loader_new (fileuris,
(FrogrPictureLoadedCallback) _on_picture_loaded,
(FrogrPicturesLoadedCallback) _on_pictures_loaded,
self);
......
......@@ -110,7 +110,7 @@ gboolean frogr_controller_is_authorized (FrogrController *self);
void frogr_controller_revoke_authorization (FrogrController *self);
void frogr_controller_load_pictures (FrogrController *self, GSList *filepaths);
void frogr_controller_load_pictures (FrogrController *self, GSList *fileuris);
void frogr_controller_upload_pictures (FrogrController *self);
......
......@@ -95,7 +95,7 @@ typedef struct _FrogrMainViewPrivate {
enum {
FILEPATH_COL,
FILEURI_COL,
PIXBUF_COL,
FPICTURE_COL
};
......@@ -164,7 +164,7 @@ static void _add_pictures_to_existing_set (FrogrMainView *self);
static void _add_pictures_to_group (FrogrMainView *self);
static void _edit_selected_pictures (FrogrMainView *self);
static void _remove_selected_pictures (FrogrMainView *self);
static void _load_pictures (FrogrMainView *self, GSList *filepaths);
static void _load_pictures (FrogrMainView *self, GSList *fileuris);
static void _upload_pictures (FrogrMainView *self);
static void _progress_dialog_response (GtkDialog *dialog,
......@@ -477,7 +477,7 @@ _on_icon_view_drag_data_received (GtkWidget *widget,
FrogrMainView *self = NULL;
FrogrMainViewPrivate *priv = NULL;
GdkAtom target;
GSList *filepaths_list = NULL;
GSList *fileuris_list = NULL;
const guchar *files_string = NULL;
gchar **fileuris_array = NULL;
gint i;
......@@ -500,21 +500,21 @@ _on_icon_view_drag_data_received (GtkWidget *widget,
fileuris_array = g_strsplit ((const gchar*)files_string, "\r\n", -1);
for (i = 0; fileuris_array[i]; i++)
{
gchar *filepath = g_filename_from_uri (fileuris_array[i], NULL, NULL);
if (filepath && !g_str_equal (g_strstrip (filepath), ""))
filepaths_list = g_slist_append (filepaths_list, filepath);
gchar *fileuri = g_strdup (fileuris_array[i]);
if (fileuri && !g_str_equal (g_strstrip (fileuri), ""))
fileuris_list = g_slist_append (fileuris_list, fileuri);
}
/* Load pictures */
if (filepaths_list != NULL)
_load_pictures (FROGR_MAIN_VIEW (self), filepaths_list);
if (fileuris_list != NULL)
_load_pictures (FROGR_MAIN_VIEW (self), fileuris_list);
/* Finish drag and drop */
gtk_drag_finish (context, TRUE, FALSE, time);
/* Free */
g_strfreev (fileuris_array);
g_slist_free (filepaths_list);
g_slist_free (fileuris_list);
}
void
......@@ -807,15 +807,15 @@ _add_picture_to_ui (FrogrMainView *self, FrogrPicture *picture)
FrogrMainViewPrivate *priv = FROGR_MAIN_VIEW_GET_PRIVATE (self);
GdkPixbuf *pixbuf;
GtkTreeIter iter;
const gchar *filepath;
const gchar *fileuri;
/* Add to GtkIconView */
filepath = frogr_picture_get_filepath (picture);
fileuri = frogr_picture_get_fileuri (picture);
pixbuf = frogr_picture_get_pixbuf (picture);
gtk_list_store_append (GTK_LIST_STORE (priv->tree_model), &iter);
gtk_list_store_set (GTK_LIST_STORE (priv->tree_model), &iter,
FILEPATH_COL, filepath,
FILEURI_COL, fileuri,
PIXBUF_COL, pixbuf,
FPICTURE_COL, picture,
-1);
......@@ -865,14 +865,14 @@ _add_pictures_dialog_response_cb (GtkDialog *dialog, gint response, gpointer dat
if (response == GTK_RESPONSE_ACCEPT)
{
GSList *filepaths;
GSList *fileuris;
/* Add selected pictures to icon view area */
filepaths = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (dialog));
if (filepaths != NULL)
fileuris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (dialog));
if (fileuris != NULL)
{
_load_pictures (FROGR_MAIN_VIEW (self), filepaths);
g_slist_free (filepaths);
_load_pictures (FROGR_MAIN_VIEW (self), fileuris);
g_slist_free (fileuris);
}
}
......@@ -904,6 +904,7 @@ _add_pictures_dialog (FrogrMainView *self)
gtk_file_filter_set_name (filter, "images");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (_add_pictures_dialog_response_cb), self);
......@@ -1020,10 +1021,10 @@ _remove_selected_pictures (FrogrMainView *self)
}
static void
_load_pictures (FrogrMainView *self, GSList *filepaths)
_load_pictures (FrogrMainView *self, GSList *fileuris)
{
FrogrMainViewPrivate *priv = FROGR_MAIN_VIEW_GET_PRIVATE (self);
frogr_controller_load_pictures (priv->controller, filepaths);
frogr_controller_load_pictures (priv->controller, fileuris);
}
static void
......
......@@ -50,7 +50,7 @@ struct _FrogrPictureLoaderPrivate
FrogrMainView *mainview;
FrogrConfig *config;
GSList *filepaths;
GSList *fileuris;
GSList *current;
guint index;
guint n_pictures;
......@@ -138,13 +138,13 @@ _load_next_picture (FrogrPictureLoader *self)
{
GFile *gfile = NULL;
GFileInfo *file_info;
gchar *filepath = (gchar *)priv->current->data;
gchar *fileuri = (gchar *)priv->current->data;
const gchar *mime_type;
gboolean valid_mime = FALSE;
gint i;
/* Get file info */
gfile = g_file_new_for_path (filepath);
gfile = g_file_new_for_uri (fileuri);
file_info = g_file_query_info (gfile,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_QUERY_INFO_NONE,
......@@ -161,7 +161,7 @@ _load_next_picture (FrogrPictureLoader *self)
}
}
DEBUG ("Adding file %s (%s)", filepath, mime_type);
DEBUG ("Adding file %s (%s)", fileuri, mime_type);
g_object_unref (file_info);
/* Asynchronously load the picture if mime is valid */
......@@ -220,11 +220,11 @@ _load_next_picture_cb (GObject *object,
{
GdkPixbuf *pixbuf;
GdkPixbuf *s_pixbuf;
gchar *filepath;
gchar *fileuri;
gchar *filename;
/* Gather needed information */
filepath = g_file_get_path (file);
fileuri = g_file_get_uri (file);
filename = g_file_get_basename (file);
gdk_pixbuf_loader_close (pixbuf_loader, NULL);
pixbuf = gdk_pixbuf_loader_get_pixbuf (pixbuf_loader);
......@@ -233,7 +233,7 @@ _load_next_picture_cb (GObject *object,
s_pixbuf = _get_scaled_pixbuf (pixbuf);
/* Build the FrogrPicture and set pixbuf */
fpicture = frogr_picture_new (filepath,
fpicture = frogr_picture_new (fileuri,
filename,
frogr_config_get_default_public (priv->config),
frogr_config_get_default_family (priv->config),
......@@ -249,7 +249,7 @@ _load_next_picture_cb (GObject *object,
/* Free */
g_object_unref (s_pixbuf);
g_free (filepath);
g_free (fileuri);
g_free (filename);
}
else
......@@ -329,8 +329,8 @@ _frogr_picture_loader_finalize (GObject* object)
FROGR_PICTURE_LOADER_GET_PRIVATE (object);
/* Free */
g_slist_foreach (priv->filepaths, (GFunc)g_free, NULL);
g_slist_free (priv->filepaths);
g_slist_foreach (priv->fileuris, (GFunc)g_free, NULL);
g_slist_free (priv->fileuris);
G_OBJECT_CLASS (frogr_picture_loader_parent_class)->finalize(object);
}
......@@ -360,7 +360,7 @@ frogr_picture_loader_init (FrogrPictureLoader *self)
priv->config = g_object_ref (frogr_config_get_instance ());
/* Init the rest of private data */
priv->filepaths = NULL;
priv->fileuris = NULL;
priv->current = NULL;
priv->index = -1;
priv->n_pictures = 0;
......@@ -369,7 +369,7 @@ frogr_picture_loader_init (FrogrPictureLoader *self)
/* Public API */
FrogrPictureLoader *
frogr_picture_loader_new (GSList *filepaths,
frogr_picture_loader_new (GSList *fileuris,
FrogrPictureLoadedCallback picture_loaded_cb,
FrogrPicturesLoadedCallback pictures_loaded_cb,
gpointer object)
......@@ -381,10 +381,10 @@ frogr_picture_loader_new (GSList *filepaths,
FROGR_PICTURE_LOADER_GET_PRIVATE (self);
/* Internal data */
priv->filepaths = g_slist_copy (filepaths);
priv->current = priv->filepaths;
priv->fileuris = g_slist_copy (fileuris);
priv->current = priv->fileuris;
priv->index = 0;
priv->n_pictures = g_slist_length (priv->filepaths);
priv->n_pictures = g_slist_length (priv->fileuris);
/* Callback data */
priv->picture_loaded_cb = picture_loaded_cb;
......@@ -403,7 +403,7 @@ frogr_picture_loader_load (FrogrPictureLoader *self)
FROGR_PICTURE_LOADER_GET_PRIVATE (self);
/* Check first whether there's something to load */
if (priv->filepaths == NULL)
if (priv->fileuris == NULL)
return;
/* Update status and progress */
......
......@@ -60,7 +60,7 @@ struct _FrogrPictureLoaderClass
GType frogr_picture_loader_get_type(void) G_GNUC_CONST;
FrogrPictureLoader *frogr_picture_loader_new (GSList *filepaths,
FrogrPictureLoader *frogr_picture_loader_new (GSList *fileuris,
FrogrPictureLoadedCallback picture_loaded_cb,
FrogrPicturesLoadedCallback pictures_loaded_cb,
gpointer object);
......
......@@ -36,7 +36,7 @@ typedef struct _FrogrPicturePrivate FrogrPicturePrivate;
struct _FrogrPicturePrivate
{
gchar *id;
gchar *filepath;
gchar *fileuri;
gchar *title;
gchar *description;
gchar *tags_string;
......@@ -60,7 +60,7 @@ struct _FrogrPicturePrivate
enum {
PROP_0,
PROP_ID,
PROP_FILEPATH,
PROP_FILEURI,
PROP_TITLE,
PROP_DESCRIPTION,
PROP_TAGS_STRING,
......@@ -186,8 +186,8 @@ _frogr_picture_set_property (GObject *object,
case PROP_ID:
frogr_picture_set_id (self, g_value_get_string (value));
break;
case PROP_FILEPATH:
frogr_picture_set_filepath (self, g_value_get_string (value));
case PROP_FILEURI:
frogr_picture_set_fileuri (self, g_value_get_string (value));
break;
case PROP_TITLE:
frogr_picture_set_title (self, g_value_get_string (value));
......@@ -238,8 +238,8 @@ _frogr_picture_get_property (GObject *object,
case PROP_ID:
g_value_set_string (value, priv->id);
break;
case PROP_FILEPATH:
g_value_set_string (value, priv->filepath);
case PROP_FILEURI:
g_value_set_string (value, priv->fileuri);
break;
case PROP_TITLE:
g_value_set_string (value, priv->title);
......@@ -314,7 +314,7 @@ _frogr_picture_finalize (GObject* object)
/* free strings */
g_free (priv->id);
g_free (priv->filepath);
g_free (priv->fileuri);
g_free (priv->title);
g_free (priv->description);
g_free (priv->tags_string);
......@@ -348,10 +348,10 @@ frogr_picture_class_init(FrogrPictureClass *klass)
G_PARAM_READWRITE));
g_object_class_install_property (obj_class,
PROP_FILEPATH,
g_param_spec_string ("filepath",
"filepath",
"Full filepath at disk "
PROP_FILEURI,
g_param_spec_string ("fileuri",
"fileuri",
"Full fileuri at disk "
"for the picture",
NULL,
G_PARAM_READWRITE));
......@@ -451,7 +451,7 @@ frogr_picture_init (FrogrPicture *self)
/* Default values */
priv->id = NULL;
priv->filepath = NULL;
priv->fileuri = NULL;
priv->title = NULL;
priv->description = NULL;
priv->tags_string = NULL;
......@@ -475,17 +475,17 @@ frogr_picture_init (FrogrPicture *self)
/* Public API */
FrogrPicture *
frogr_picture_new (const gchar *filepath,
frogr_picture_new (const gchar *fileuri,
const gchar *title,
gboolean public,
gboolean family,
gboolean friend)
{
g_return_val_if_fail (filepath, NULL);
g_return_val_if_fail (fileuri, NULL);
g_return_val_if_fail (title, NULL);
GObject *new = g_object_new(FROGR_TYPE_PICTURE,
"filepath", filepath,
"fileuri", fileuri,
"title", title,
"is-public", public,
"is-family", family,
......@@ -525,27 +525,27 @@ frogr_picture_set_id (FrogrPicture *self,
}
const gchar *
frogr_picture_get_filepath (FrogrPicture *self)
frogr_picture_get_fileuri (FrogrPicture *self)
{
g_return_val_if_fail(FROGR_IS_PICTURE(self), NULL);
FrogrPicturePrivate *priv =
FROGR_PICTURE_GET_PRIVATE (self);
return (const gchar *)priv->filepath;
return (const gchar *)priv->fileuri;
}
void
frogr_picture_set_filepath (FrogrPicture *self,
const gchar *filepath)
frogr_picture_set_fileuri (FrogrPicture *self,
const gchar *fileuri)
{
g_return_if_fail(FROGR_IS_PICTURE(self));
FrogrPicturePrivate *priv =
FROGR_PICTURE_GET_PRIVATE (self);
g_free (priv->filepath);
priv->filepath = g_strdup (filepath);
g_free (priv->fileuri);
priv->fileuri = g_strdup (fileuri);
}
const gchar *
......
......@@ -57,7 +57,7 @@ struct _FrogrPictureClass
GType frogr_picture_get_type(void) G_GNUC_CONST;
/* Constructor */
FrogrPicture *frogr_picture_new (const gchar *filepath,
FrogrPicture *frogr_picture_new (const gchar *fileuri,
const gchar *title,
gboolean public,
gboolean family,
......@@ -77,9 +77,9 @@ const gchar *frogr_picture_get_description (FrogrPicture *self);
void frogr_picture_set_description (FrogrPicture *self,
const gchar *description);
const gchar *frogr_picture_get_filepath (FrogrPicture *self);
void frogr_picture_set_filepath (FrogrPicture *self,
const gchar *filepath);
const gchar *frogr_picture_get_fileuri (FrogrPicture *self);
void frogr_picture_set_fileuri (FrogrPicture *self,
const gchar *fileuri);
const GSList *frogr_picture_get_tags_list (FrogrPicture *self);
const gchar *frogr_picture_get_tags (FrogrPicture *self);
......
......@@ -30,37 +30,30 @@
#include <libxml/parser.h>
static GSList *
_get_paths_list_from_array (char **paths_str, int n_paths)
_get_uris_list_from_array (char **uris_str, int n_uris)
{
GSList *filepaths = NULL;
GError *err = NULL;
GSList *fileuris = NULL;
int i = 0;
for (i = 0; i < n_paths; i++)
for (i = 0; i < n_uris; i++)
{
gchar *uri = NULL;
gchar *filepath = NULL;
gchar *fileuri = NULL;
/* Add the 'file://' schema if not present */
if (g_str_has_prefix (paths_str[i], "/"))
uri = g_strdup_printf ("file://%s", paths_str[i]);
if (g_str_has_prefix (uris_str[i], "/"))
uri = g_strdup_printf ("file://%s", uris_str[i]);
else
uri = g_strdup (paths_str[i]);
filepath = g_filename_from_uri (uri, NULL, &err);
if (err)
{
DEBUG ("Error loading picture %s: %s\n", uri, err->message);
g_error_free (err);
err = NULL;
}
else
filepaths = g_slist_append (filepaths, filepath);
uri = g_strdup (uris_str[i]);
fileuri = g_strdup (uri);
if (fileuri)
fileuris = g_slist_append (fileuris, fileuri);
g_free (uri);
}
return filepaths;
return fileuris;
}
static gboolean
......@@ -69,12 +62,12 @@ _load_pictures_on_idle (gpointer data)
g_return_val_if_fail (data, FALSE);
FrogrController *fcontroller = NULL;
GSList *filepaths = NULL;
GSList *fileuris = NULL;
fcontroller = frogr_controller_get_instance ();
filepaths = (GSList *)data;
fileuris = (GSList *)data;
frogr_controller_load_pictures (fcontroller, filepaths);
frogr_controller_load_pictures (fcontroller, fileuris);
return FALSE;
}
......@@ -83,11 +76,11 @@ int
main (int argc, char **argv)
{
FrogrController *fcontroller = NULL;
GSList *filepaths = NULL;
GSList *fileuris = NULL;
/* Check optional command line parameters */
if (argc > 1)
filepaths = _get_paths_list_from_array (&argv[1], argc - 1);
fileuris = _get_uris_list_from_array (&argv[1], argc - 1);
gtk_init (&argc, &argv);
g_set_application_name(APP_SHORTNAME);
......@@ -102,15 +95,15 @@ main (int argc, char **argv)
/* Run app (and load pictures if present) */
fcontroller = frogr_controller_get_instance ();
if (filepaths)
gdk_threads_add_idle (_load_pictures_on_idle, filepaths);
if (fileuris)
gdk_threads_add_idle (_load_pictures_on_idle, fileuris);
frogr_controller_run_app (fcontroller);
if (filepaths)
if (fileuris)
{
g_slist_foreach (filepaths, (GFunc)g_free, NULL);
g_slist_free (filepaths);
g_slist_foreach (fileuris, (GFunc)g_free, NULL);
g_slist_free (fileuris);
}
/* cleanup libxml2 library */
......
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