Commit 672b643e authored by Stephan Arts's avatar Stephan Arts

Add RsttoFile object

parent 5f2070d3
......@@ -10,14 +10,14 @@ ristretto_SOURCES = \
main_window_ui.h \
main_window.c main_window.h \
wallpaper_manager.c wallpaper_manager.h \
monitor_chooser.c monitor_chooser.h \
monitor_chooser.c monitor_chooser.h \
xfce_wallpaper_manager.c xfce_wallpaper_manager.h \
gnome_wallpaper_manager.c gnome_wallpaper_manager.h \
app_menu_item.c app_menu_item.h \
thumbnail_bar.c thumbnail_bar.h \
thumbnail.c thumbnail.h \
thumbnailer.c thumbnailer.h \
marshal.c marshal.h \
marshal.c marshal.h \
file.c file.h \
main.c
ristretto_CFLAGS = \
......
/*
* Copyright (c) Stephan Arts 2011 <stephan@xfce.org>
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* 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 Library 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 <config.h>
#include <glib.h>
#include <gio/gio.h>
#include <libxfce4util/libxfce4util.h>
#include "file.h"
static void
rstto_file_init (GObject *);
static void
rstto_file_class_init (GObjectClass *);
static void
rstto_file_dispose (GObject *object);
static void
rstto_file_finalize (GObject *object);
static void
rstto_file_set_property (
GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec );
static void
rstto_file_get_property (
GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec );
static GObjectClass *parent_class = NULL;
static GList *open_files = NULL;
enum
{
PROP_0,
};
GType
rstto_file_get_type (void)
{
static GType rstto_file_type = 0;
if (!rstto_file_type)
{
static const GTypeInfo rstto_file_info =
{
sizeof (RsttoFileClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) rstto_file_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (RsttoFile),
0,
(GInstanceInitFunc) rstto_file_init,
NULL
};
rstto_file_type = g_type_register_static (
G_TYPE_OBJECT,
"RsttoFile",
&rstto_file_info,
0 );
}
return rstto_file_type;
}
struct _RsttoFilePriv
{
GFile *file;
gchar *display_name;
gchar *content_type;
};
static void
rstto_file_init (GObject *object)
{
RsttoFile *file = RSTTO_FILE (object);
file->priv = g_new0 (RsttoFilePriv, 1);
}
static void
rstto_file_class_init (GObjectClass *object_class)
{
RsttoFileClass *file_class = RSTTO_FILE_CLASS (object_class);
parent_class = g_type_class_peek_parent (file_class);
object_class->dispose = rstto_file_dispose;
object_class->finalize = rstto_file_finalize;
object_class->set_property = rstto_file_set_property;
object_class->get_property = rstto_file_get_property;
}
/**
* rstto_file_dispose:
* @object:
*
*/
static void
rstto_file_dispose (GObject *object)
{
RsttoFile *file = RSTTO_FILE (object);
if (file->priv)
{
if (file->priv->file)
{
g_object_unref (file->priv->file);
file->priv->file = NULL;
}
if (file->priv->display_name)
{
g_free (file->priv->display_name);
file->priv->display_name = NULL;
}
if (file->priv->content_type)
{
g_free (file->priv->content_type);
file->priv->content_type = NULL;
}
g_free (file->priv);
file->priv = NULL;
open_files = g_list_remove_all (open_files, file);
g_debug ("Open files: %d", g_list_length (open_files));
}
}
/**
* rstto_file_finalize:
* @object:
*
*/
static void
rstto_file_finalize (GObject *object)
{
/*RsttoFile *file = RSTTO_FILE (object);*/
}
/**
* rstto_file_new:
*
*
* Singleton
*/
RsttoFile *
rstto_file_new ( GFile *file )
{
RsttoFile *o_file = NULL;
GList *iter = open_files;
while ( NULL != iter )
{
/* Check if the file is already opened, if so
* return that one.
*/
if ( TRUE == g_file_equal (
RSTTO_FILE (iter->data)->priv->file,
file) )
{
return (RsttoFile *)iter->data;
}
iter = g_list_next (iter);
}
o_file = g_object_new (RSTTO_TYPE_FILE, NULL);
o_file->priv->file = file;
g_object_ref (file);
open_files = g_list_append (open_files, o_file);
return o_file;
}
static void
rstto_file_set_property (
GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec )
{
}
static void
rstto_file_get_property (
GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec )
{
}
GFile *
rstto_file_get_file ( RsttoFile *file )
{
return file->priv->file;
}
gboolean
rstto_file_equal ( RsttoFile *a, RsttoFile *b )
{
return g_file_equal (a->priv->file, b->priv->file);
}
const gchar *
rstto_file_get_display_name ( RsttoFile *file )
{
GFileInfo *file_info = NULL;
const gchar *display_name;
if ( NULL == file->priv->display_name )
{
file_info = g_file_query_info (
file->priv->file,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
0,
NULL,
NULL );
if ( NULL != file_info )
{
display_name = g_file_info_get_display_name (file_info);
if ( NULL != display_name )
{
file->priv->display_name = g_strdup (display_name);
}
g_object_unref (file_info);
}
}
return (const gchar *)file->priv->display_name;
}
const gchar *
rstto_file_get_path ( RsttoFile *file )
{
return g_file_get_path (file->priv->file);
}
const gchar *
rstto_file_get_uri ( RsttoFile *file )
{
return g_file_get_uri (file->priv->file);
}
const gchar *
rstto_file_get_content_type ( RsttoFile *file )
{
GFileInfo *file_info = NULL;
const gchar *content_type;
if ( NULL == file->priv->content_type )
{
file_info = g_file_query_info (
file->priv->file,
"standard::content-type",
0,
NULL,
NULL );
if ( NULL != file_info )
{
content_type = g_file_info_get_content_type (file_info);
if ( NULL != content_type )
{
file->priv->content_type = g_strdup (content_type);
}
g_object_unref (file_info);
}
}
return (const gchar *)file->priv->content_type;
}
/*
* Copyright (c) Stephan Arts 2011 <stephan@xfce.org>
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* 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 Library 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 __RISTRETTO_FILE_H__
#define __RISTRETTO_FILE_H__
G_BEGIN_DECLS
#define RSTTO_TYPE_FILE rstto_file_get_type()
#define RSTTO_FILE(obj)( \
G_TYPE_CHECK_INSTANCE_CAST ((obj), \
RSTTO_TYPE_FILE, \
RsttoFile))
#define RSTTO_IS_FILE(obj)( \
G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
RSTTO_TYPE_FILE))
#define RSTTO_FILE_CLASS(klass)( \
G_TYPE_CHECK_CLASS_CAST ((klass), \
RSTTO_TYPE_FILE, \
RsttoFileClass))
#define RSTTO_IS_FILE_CLASS(klass)( \
G_TYPE_CHECK_CLASS_TYPE ((klass), \
RSTTO_TYPE_FILE()))
typedef struct _RsttoFile RsttoFile;
typedef struct _RsttoFilePriv RsttoFilePriv;
struct _RsttoFile
{
GObject parent;
RsttoFilePriv *priv;
};
typedef struct _RsttoFileClass RsttoFileClass;
struct _RsttoFileClass
{
GObjectClass parent_class;
};
RsttoFile *
rstto_file_new ( GFile * );
GType
rstto_file_get_type ( void );
GFile *
rstto_file_get_file ( RsttoFile * );
gboolean
rstto_file_equal ( RsttoFile *, RsttoFile * );
const gchar *
rstto_file_get_display_name ( RsttoFile * );
const gchar *
rstto_file_get_path ( RsttoFile * );
const gchar *
rstto_file_get_uri ( RsttoFile * );
const gchar *
rstto_file_get_content_type ( RsttoFile * );
G_END_DECLS
#endif /* __RISTRETTO_FILE_H__ */
......@@ -25,6 +25,7 @@
#include <libexif/exif-data.h>
#include "file.h"
#include "image_list.h"
#include "settings.h"
......@@ -45,11 +46,9 @@ rstto_image_list_iter_dispose(GObject *object);
static RsttoImageListIter * rstto_image_list_iter_new ();
static gint
cb_rstto_image_list_image_name_compare_func (GFile *a, GFile *b);
cb_rstto_image_list_image_name_compare_func (RsttoFile *a, RsttoFile *b);
static gint
cb_rstto_image_list_exif_date_compare_func (GFile *a, GFile *b);
static gint
cb_rstto_image_list_file_compare_func (GFile *a, GFile *file);
cb_rstto_image_list_exif_date_compare_func (RsttoFile *a, RsttoFile *b);
static GObjectClass *parent_class = NULL;
static GObjectClass *iter_parent_class = NULL;
......@@ -72,7 +71,7 @@ enum
struct _RsttoImageListIterPriv
{
RsttoImageList *image_list;
GFile *file;
RsttoFile *file;
};
struct _RsttoImageListPriv
......@@ -183,16 +182,15 @@ rstto_image_list_new (void)
}
gboolean
rstto_image_list_add_file (RsttoImageList *image_list, GFile *file, GError **error)
rstto_image_list_add_file (RsttoImageList *image_list, RsttoFile *file, GError **error)
{
GList *image_iter = g_list_find_custom (image_list->priv->images, file, rstto_image_list_get_compare_func (image_list));
GList *image_iter = g_list_find (image_list->priv->images, file);
if (!image_iter)
{
if (file)
{
image_list->priv->images = g_list_insert_sorted (image_list->priv->images, file, rstto_image_list_get_compare_func (image_list));
g_object_ref (file);
image_list->priv->n_images++;
......@@ -233,7 +231,7 @@ rstto_image_list_get_n_images (RsttoImageList *image_list)
RsttoImageListIter *
rstto_image_list_get_iter (RsttoImageList *image_list)
{
GFile *file = NULL;
RsttoFile *file = NULL;
RsttoImageListIter *iter = NULL;
if (image_list->priv->images)
file = image_list->priv->images->data;
......@@ -247,10 +245,10 @@ rstto_image_list_get_iter (RsttoImageList *image_list)
void
rstto_image_list_remove_file (RsttoImageList *image_list, GFile *file)
rstto_image_list_remove_file (RsttoImageList *image_list, RsttoFile *file)
{
GSList *iter = NULL;
GFile *afile = NULL;
RsttoFile *afile = NULL;
if (g_list_find(image_list->priv->images, file))
{
......@@ -258,7 +256,7 @@ rstto_image_list_remove_file (RsttoImageList *image_list, GFile *file)
iter = image_list->priv->iterators;
while (iter)
{
if (g_file_equal(rstto_image_list_iter_get_file (iter->data), file))
if (rstto_file_equal(rstto_image_list_iter_get_file (iter->data), file))
{
if (rstto_image_list_iter_get_position (iter->data) == rstto_image_list_get_n_images (image_list)-1)
{
......@@ -272,7 +270,7 @@ rstto_image_list_remove_file (RsttoImageList *image_list, GFile *file)
* it's a single item list,
* and we should force the image in this iter to NULL
*/
if (g_file_equal(rstto_image_list_iter_get_file (iter->data), file))
if (rstto_file_equal(rstto_image_list_iter_get_file (iter->data), file))
{
((RsttoImageListIter *)(iter->data))->priv->file = NULL;
g_signal_emit (G_OBJECT (iter->data), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED], 0, NULL);
......@@ -283,13 +281,12 @@ rstto_image_list_remove_file (RsttoImageList *image_list, GFile *file)
image_list->priv->images = g_list_remove (image_list->priv->images, file);
iter = image_list->priv->iterators;
g_object_ref(file);
while (iter)
{
afile = rstto_image_list_iter_get_file(iter->data);
if (NULL != afile)
{
if (g_file_equal(afile, file))
if (rstto_file_equal(afile, file))
{
rstto_image_list_iter_next (iter->data);
}
......@@ -403,7 +400,7 @@ rstto_image_list_iter_dispose (GObject *object)
}
static RsttoImageListIter *
rstto_image_list_iter_new (RsttoImageList *nav, GFile *file)
rstto_image_list_iter_new (RsttoImageList *nav, RsttoFile *file)
{
RsttoImageListIter *iter;
......@@ -415,7 +412,7 @@ rstto_image_list_iter_new (RsttoImageList *nav, GFile *file)
}
gboolean
rstto_image_list_iter_find_file (RsttoImageListIter *iter, GFile *file)
rstto_image_list_iter_find_file (RsttoImageListIter *iter, RsttoFile *file)
{
gint pos = g_list_index (iter->priv->image_list->priv->images, file);
if (pos > -1)
......@@ -445,7 +442,7 @@ rstto_image_list_iter_get_position (RsttoImageListIter *iter)
return g_list_index (iter->priv->image_list->priv->images, iter->priv->file);
}
GFile *
RsttoFile *
rstto_image_list_iter_get_file (RsttoImageListIter *iter)
{
return iter->priv->file;
......@@ -599,22 +596,10 @@ rstto_image_list_set_sort_by_date (RsttoImageList *image_list)
* Return value: (see strcmp)
*/
static gint
cb_rstto_image_list_image_name_compare_func (GFile *a, GFile *b)
cb_rstto_image_list_image_name_compare_func (RsttoFile *a, RsttoFile *b)
{
GFileInfo *info_a = g_file_query_info (
a,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
0,
NULL,
NULL );
GFileInfo *info_b = g_file_query_info (
b,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
0,
NULL,
NULL );
const gchar *a_base = g_file_info_get_display_name (info_a);
const gchar *b_base = g_file_info_get_display_name (info_b);
const gchar *a_base = rstto_file_get_display_name (a);
const gchar *b_base = rstto_file_get_display_name (b);
guint ac;
guint bc;
const gchar *ap = a_base;
......@@ -678,8 +663,6 @@ cb_rstto_image_list_image_name_compare_func (GFile *a, GFile *b)
}
g_object_unref (info_a);
g_object_unref (info_b);
return result;
}
......@@ -693,12 +676,14 @@ cb_rstto_image_list_image_name_compare_func (GFile *a, GFile *b)
* Return value: (see strcmp)
*/
static gint
cb_rstto_image_list_exif_date_compare_func (GFile *a, GFile *b)
cb_rstto_image_list_exif_date_compare_func (RsttoFile *a, RsttoFile *b)
{
gint result = 0;
GFile *file_a = rstto_file_get_file (a);
GFile *file_b = rstto_file_get_file (b);
GFileInfo *file_info_a = g_file_query_info (a, "time::modified", 0, NULL, NULL);
GFileInfo *file_info_b = g_file_query_info (b, "time::modified", 0, NULL, NULL);
GFileInfo *file_info_a = g_file_query_info (file_a, "time::modified", 0, NULL, NULL);
GFileInfo *file_info_b = g_file_query_info (file_b, "time::modified", 0, NULL, NULL);
guint64 a_i = g_file_info_get_attribute_uint64(file_info_a, "time::modified");
guint64 b_i = g_file_info_get_attribute_uint64(file_info_b, "time::modified");
......
......@@ -96,7 +96,7 @@ GType rstto_image_list_get_type ();
RsttoImageList *rstto_image_list_new ();
gint rstto_image_list_get_n_images (RsttoImageList *image_list);
gboolean rstto_image_list_add_file (RsttoImageList *image_list, GFile *file, GError **);
gboolean rstto_image_list_add_file (RsttoImageList *image_list, RsttoFile *file, GError **);
GCompareFunc rstto_image_list_get_compare_func (RsttoImageList *image_list);
void rstto_image_list_set_compare_func (RsttoImageList *image_list, GCompareFunc func);
......@@ -112,7 +112,7 @@ RsttoImageListIter *rstto_image_list_get_iter (RsttoImageList *image_list);
/** Iter functions */
GType rstto_image_list_iter_get_type ();
GFile *
RsttoFile *
rstto_image_list_iter_get_file ( RsttoImageListIter *iter );
void rstto_image_list_iter_previous (RsttoImageListIter *iter);
......@@ -124,9 +124,9 @@ void rstto_image_list_iter_set_position (RsttoImageListIter *iter, gint p
void
rstto_image_list_remove_all (RsttoImageList *image_list);
void
rstto_image_list_remove_file (RsttoImageList *image_list, GFile *file);
rstto_image_list_remove_file (RsttoImageList *image_list, RsttoFile *file);
gboolean
rstto_image_list_iter_find_image (RsttoImageListIter *iter, GFile *file);
rstto_image_list_iter_find_image (RsttoImageListIter *iter, RsttoFile *file);
RsttoImageListIter *rstto_image_list_iter_clone (RsttoImageListIter *iter);
......
......@@ -23,6 +23,7 @@
#include <gio/gio.h>
#include <libexif/exif-data.h>
#include "file.h"
#include "image_viewer.h"
#include "settings.h"
#include "marshal.h"
......@@ -47,7 +48,7 @@ typedef struct _RsttoImageViewerTransaction RsttoImageViewerTransaction;
struct _RsttoImageViewerPriv
{
GFile *file;
RsttoFile *file;
RsttoSettings *settings;
GdkVisual *visual;
GdkColormap *colormap;
......@@ -103,7 +104,7 @@ struct _RsttoImageViewerPriv
struct _RsttoImageViewerTransaction
{
RsttoImageViewer *viewer;
GFile *file;
RsttoFile *file;
GCancellable *cancellable;
GdkPixbufLoader *loader;
......@@ -205,7 +206,7 @@ cb_rstto_zoom_direction_changed (
static void
rstto_image_viewer_load_image (
RsttoImageViewer *viewer,
GFile *file,
RsttoFile *file,
gdouble scale);
static void
rstto_image_viewer_transaction_free (RsttoImageViewerTransaction *tr);
......@@ -898,10 +899,11 @@ rstto_image_viewer_new (void)
* - cancellable...
*/
void
rstto_image_viewer_set_file (RsttoImageViewer *viewer,
GFile *file,
gdouble scale,
RsttoImageViewerOrientation orientation)
rstto_image_viewer_set_file (
RsttoImageViewer *viewer,
RsttoFile *file,
gdouble scale,
RsttoImageViewerOrientation orientation)
{