[sushi] Revert "Use G_DECLARE_FINAL_TYPE for private lib types"
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sushi] Revert "Use G_DECLARE_FINAL_TYPE for private lib types"
- Date: Mon, 17 Jun 2019 23:19:48 +0000 (UTC)
commit 202946a80e0c593434507a3501fc931200c6d518
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Jun 17 16:17:23 2019 -0700
Revert "Use G_DECLARE_FINAL_TYPE for private lib types"
For some reason this causes the app to crash under certain
circumstances.
Until that's debugged, let's revert this.
This reverts commit 44846026499dd917294dbd486aa4e789f3dd91d1.
meson.build | 4 +-
src/libsushi/sushi-cover-art.c | 102 +++++++------
src/libsushi/sushi-cover-art.h | 25 +++-
src/libsushi/sushi-file-loader.c | 172 ++++++++++++----------
src/libsushi/sushi-file-loader.h | 26 +++-
src/libsushi/sushi-pdf-loader.c | 82 ++++++-----
src/libsushi/sushi-pdf-loader.h | 26 +++-
src/libsushi/sushi-sound-player.c | 298 +++++++++++++++++++++++---------------
src/libsushi/sushi-sound-player.h | 26 +++-
9 files changed, 471 insertions(+), 290 deletions(-)
---
diff --git a/meson.build b/meson.build
index 7e84632..bdccf35 100644
--- a/meson.build
+++ b/meson.build
@@ -10,9 +10,9 @@ evince_document_dep = dependency('evince-document-3.0')
evince_view_dep = dependency('evince-view-3.0')
freetype_dep = dependency('freetype2')
gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>=2.23.0')
-gio_unix_dep = dependency('gio-unix-2.0', version: '>=2.44.0')
+gio_unix_dep = dependency('gio-unix-2.0', version: '>=2.29.14')
gjs_dep = dependency('gjs-1.0', version: '>=1.38.0')
-glib_dep = dependency('glib-2.0', version: '>=2.44.0')
+glib_dep = dependency('glib-2.0', version: '>=2.29.14')
gstreamer_dep = dependency('gstreamer-1.0')
gstreamer_audio_dep = dependency('gstreamer-audio-1.0')
gstreamer_base_dep = dependency('gstreamer-base-1.0')
diff --git a/src/libsushi/sushi-cover-art.c b/src/libsushi/sushi-cover-art.c
index 0b0ff63..0785176 100644
--- a/src/libsushi/sushi-cover-art.c
+++ b/src/libsushi/sushi-cover-art.c
@@ -28,7 +28,17 @@
#include <musicbrainz5/mb5_c.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
-struct _SushiCoverArtFetcher {
+G_DEFINE_TYPE (SushiCoverArtFetcher, sushi_cover_art_fetcher, G_TYPE_OBJECT);
+
+#define SUSHI_COVER_ART_FETCHER_GET_PRIVATE(obj)\
+ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SUSHI_TYPE_COVER_ART_FETCHER, SushiCoverArtFetcherPrivate))
+
+enum {
+ PROP_COVER = 1,
+ PROP_TAGLIST,
+};
+
+struct _SushiCoverArtFetcherPrivate {
GdkPixbuf *cover;
GstTagList *taglist;
@@ -37,13 +47,6 @@ struct _SushiCoverArtFetcher {
GInputStream *input_stream;
};
-G_DEFINE_TYPE (SushiCoverArtFetcher, sushi_cover_art_fetcher, G_TYPE_OBJECT)
-
-enum {
- PROP_COVER = 1,
- PROP_TAGLIST,
-};
-
#define AMAZON_IMAGE_FORMAT "http://images.amazon.com/images/P/%s.01.LZZZZZZZ.jpg"
static void sushi_cover_art_fetcher_set_taglist (SushiCoverArtFetcher *self,
@@ -59,18 +62,18 @@ static void try_read_from_file (SushiCoverArtFetcher *self,
static void
sushi_cover_art_fetcher_dispose (GObject *object)
{
- SushiCoverArtFetcher *self = SUSHI_COVER_ART_FETCHER (object);
+ SushiCoverArtFetcherPrivate *priv = SUSHI_COVER_ART_FETCHER_GET_PRIVATE (object);
- g_clear_object (&self->cover);
- g_clear_object (&self->input_stream);
+ g_clear_object (&priv->cover);
+ g_clear_object (&priv->input_stream);
- if (self->taglist != NULL) {
- gst_tag_list_free (self->taglist);
- self->taglist = NULL;
+ if (priv->taglist != NULL) {
+ gst_tag_list_free (priv->taglist);
+ priv->taglist = NULL;
}
- g_free (self->asin);
- self->asin = NULL;
+ g_free (priv->asin);
+ priv->asin = NULL;
G_OBJECT_CLASS (sushi_cover_art_fetcher_parent_class)->dispose (object);
}
@@ -82,13 +85,14 @@ sushi_cover_art_fetcher_get_property (GObject *gobject,
GParamSpec *pspec)
{
SushiCoverArtFetcher *self = SUSHI_COVER_ART_FETCHER (gobject);
+ SushiCoverArtFetcherPrivate *priv = SUSHI_COVER_ART_FETCHER_GET_PRIVATE (self);
switch (prop_id) {
case PROP_COVER:
- g_value_set_object (value, self->cover);
+ g_value_set_object (value, priv->cover);
break;
case PROP_TAGLIST:
- g_value_set_boxed (value, self->taglist);
+ g_value_set_boxed (value, priv->taglist);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
@@ -117,6 +121,7 @@ sushi_cover_art_fetcher_set_property (GObject *gobject,
static void
sushi_cover_art_fetcher_init (SushiCoverArtFetcher *self)
{
+ self->priv = SUSHI_COVER_ART_FETCHER_GET_PRIVATE (self);
}
static void
@@ -145,6 +150,8 @@ sushi_cover_art_fetcher_class_init (SushiCoverArtFetcherClass *klass)
"Current file tags",
GST_TYPE_TAG_LIST,
G_PARAM_READWRITE));
+
+ g_type_class_add_private (klass, sizeof (SushiCoverArtFetcherPrivate));
}
typedef struct {
@@ -272,7 +279,7 @@ get_gfile_for_amazon (SushiCoverArtFetcher *self)
GFile *retval;
gchar *uri;
- uri = g_strdup_printf (AMAZON_IMAGE_FORMAT, self->asin);
+ uri = g_strdup_printf (AMAZON_IMAGE_FORMAT, self->priv->asin);
retval = g_file_new_for_uri (uri);
g_free (uri);
@@ -290,7 +297,7 @@ get_gfile_for_cache (SushiCoverArtFetcher *self)
"sushi", NULL);
g_mkdir_with_parents (cache_path, 0700);
- filename = g_strdup_printf ("%s.jpg", self->asin);
+ filename = g_strdup_printf ("%s.jpg", self->priv->asin);
path = g_build_filename (cache_path, filename, NULL);
retval = g_file_new_for_path (path);
@@ -338,11 +345,11 @@ cache_replace_ready_cb (GObject *source,
return;
}
- g_seekable_seek (G_SEEKABLE (self->input_stream), 0, G_SEEK_SET,
+ g_seekable_seek (G_SEEKABLE (self->priv->input_stream), 0, G_SEEK_SET,
NULL, NULL);
g_output_stream_splice_async (G_OUTPUT_STREAM (cache_stream),
- self->input_stream,
+ self->priv->input_stream,
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
G_PRIORITY_DEFAULT,
@@ -358,6 +365,7 @@ pixbuf_from_stream_async_cb (GObject *source,
gpointer user_data)
{
SushiCoverArtFetcher *self = user_data;
+ SushiCoverArtFetcherPrivate *priv = SUSHI_COVER_ART_FETCHER_GET_PRIVATE (self);
GError *error = NULL;
GdkPixbuf *pix;
GFile *file, *cache_file;
@@ -365,8 +373,8 @@ pixbuf_from_stream_async_cb (GObject *source,
pix = gdk_pixbuf_new_from_stream_finish (res, &error);
if (error != NULL) {
- if (!self->tried_cache) {
- self->tried_cache = TRUE;
+ if (!self->priv->tried_cache) {
+ self->priv->tried_cache = TRUE;
file = get_gfile_for_amazon (self);
try_read_from_file (self, file);
@@ -380,10 +388,10 @@ pixbuf_from_stream_async_cb (GObject *source,
return;
}
- self->cover = pix;
+ priv->cover = pix;
g_object_notify (G_OBJECT (self), "cover");
- if (self->tried_cache) {
+ if (self->priv->tried_cache) {
/* the pixbuf has been loaded. if we didn't hit the cache,
* save it now.
*/
@@ -406,6 +414,7 @@ read_async_ready_cb (GObject *source,
gpointer user_data)
{
SushiCoverArtFetcher *self = user_data;
+ SushiCoverArtFetcherPrivate *priv = SUSHI_COVER_ART_FETCHER_GET_PRIVATE (self);
GFileInputStream *stream;
GError *error = NULL;
GFile *file;
@@ -414,8 +423,8 @@ read_async_ready_cb (GObject *source,
res, &error);
if (error != NULL) {
- if (!self->tried_cache) {
- self->tried_cache = TRUE;
+ if (!self->priv->tried_cache) {
+ self->priv->tried_cache = TRUE;
file = get_gfile_for_amazon (self);
try_read_from_file (self, file);
@@ -429,8 +438,8 @@ read_async_ready_cb (GObject *source,
return;
}
- self->input_stream = G_INPUT_STREAM (stream);
- gdk_pixbuf_new_from_stream_async (self->input_stream, NULL,
+ priv->input_stream = G_INPUT_STREAM (stream);
+ gdk_pixbuf_new_from_stream_async (priv->input_stream, NULL,
pixbuf_from_stream_async_cb, self);
}
@@ -457,7 +466,7 @@ cache_file_query_info_cb (GObject *source,
res, &error);
if (error != NULL) {
- self->tried_cache = TRUE;
+ self->priv->tried_cache = TRUE;
file = get_gfile_for_amazon (self);
g_error_free (error);
} else {
@@ -479,7 +488,7 @@ amazon_cover_uri_async_ready_cb (GObject *source,
GError *error = NULL;
GFile *file;
- self->asin = sushi_cover_art_fetcher_get_uri_for_track_finish
+ self->priv->asin = sushi_cover_art_fetcher_get_uri_for_track_finish
(self, res, &error);
if (error != NULL) {
@@ -503,12 +512,13 @@ amazon_cover_uri_async_ready_cb (GObject *source,
static void
try_fetch_from_amazon (SushiCoverArtFetcher *self)
{
+ SushiCoverArtFetcherPrivate *priv = SUSHI_COVER_ART_FETCHER_GET_PRIVATE (self);
gchar *artist = NULL;
gchar *album = NULL;
- gst_tag_list_get_string (self->taglist,
+ gst_tag_list_get_string (priv->taglist,
GST_TAG_ARTIST, &artist);
- gst_tag_list_get_string (self->taglist,
+ gst_tag_list_get_string (priv->taglist,
GST_TAG_ALBUM, &album);
if (artist == NULL &&
@@ -636,15 +646,17 @@ totem_gst_tag_list_get_cover (GstTagList *tag_list)
static void
try_fetch_from_tags (SushiCoverArtFetcher *self)
{
- if (self->taglist == NULL)
+ SushiCoverArtFetcherPrivate *priv = SUSHI_COVER_ART_FETCHER_GET_PRIVATE (self);
+
+ if (priv->taglist == NULL)
return;
- if (self->cover != NULL)
- g_clear_object (&self->cover);
+ if (priv->cover != NULL)
+ g_clear_object (&priv->cover);
- self->cover = totem_gst_tag_list_get_cover (self->taglist);
+ priv->cover = totem_gst_tag_list_get_cover (priv->taglist);
- if (self->cover != NULL)
+ if (priv->cover != NULL)
g_object_notify (G_OBJECT (self), "cover");
else
try_fetch_from_amazon (self);
@@ -654,14 +666,16 @@ static void
sushi_cover_art_fetcher_set_taglist (SushiCoverArtFetcher *self,
GstTagList *taglist)
{
- g_clear_object (&self->cover);
+ SushiCoverArtFetcherPrivate *priv = SUSHI_COVER_ART_FETCHER_GET_PRIVATE (self);
+
+ g_clear_object (&priv->cover);
- if (self->taglist != NULL) {
- gst_tag_list_free (self->taglist);
- self->taglist = NULL;
+ if (priv->taglist != NULL) {
+ gst_tag_list_free (priv->taglist);
+ priv->taglist = NULL;
}
- self->taglist = gst_tag_list_copy (taglist);
+ priv->taglist = gst_tag_list_copy (taglist);
try_fetch_from_tags (self);
}
diff --git a/src/libsushi/sushi-cover-art.h b/src/libsushi/sushi-cover-art.h
index 2fd7394..07c7205 100644
--- a/src/libsushi/sushi-cover-art.h
+++ b/src/libsushi/sushi-cover-art.h
@@ -31,9 +31,30 @@
G_BEGIN_DECLS
-#define SUSHI_TYPE_COVER_ART_FETCHER sushi_cover_art_fetcher_get_type ()
-G_DECLARE_FINAL_TYPE (SushiCoverArtFetcher, sushi_cover_art_fetcher, SUSHI, COVER_ART_FETCHER, GObject)
+#define SUSHI_TYPE_COVER_ART_FETCHER (sushi_cover_art_fetcher_get_type ())
+#define SUSHI_COVER_ART_FETCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
SUSHI_TYPE_COVER_ART_FETCHER, SushiCoverArtFetcher))
+#define SUSHI_IS_COVER_ART_FETCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
SUSHI_TYPE_COVER_ART_FETCHER))
+#define SUSHI_COVER_ART_FETCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
SUSHI_TYPE_COVER_ART_FETCHER, SushiCoverArtFetcherClass))
+#define SUSHI_IS_COVER_ART_FETCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
SUSHI_TYPE_COVER_ART_FETCHER))
+#define SUSHI_COVER_ART_FETCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
SUSHI_TYPE_COVER_ART_FETCHER, SushiCoverArtFetcherClass))
+typedef struct _SushiCoverArtFetcher SushiCoverArtFetcher;
+typedef struct _SushiCoverArtFetcherPrivate SushiCoverArtFetcherPrivate;
+typedef struct _SushiCoverArtFetcherClass SushiCoverArtFetcherClass;
+
+struct _SushiCoverArtFetcher
+{
+ GObject parent_instance;
+
+ SushiCoverArtFetcherPrivate *priv;
+};
+
+struct _SushiCoverArtFetcherClass
+{
+ GObjectClass parent_class;
+};
+
+GType sushi_cover_art_fetcher_get_type (void) G_GNUC_CONST;
SushiCoverArtFetcher* sushi_cover_art_fetcher_new (GstTagList *taglist);
G_END_DECLS
diff --git a/src/libsushi/sushi-file-loader.c b/src/libsushi/sushi-file-loader.c
index e6fcbbd..5602384 100644
--- a/src/libsushi/sushi-file-loader.c
+++ b/src/libsushi/sushi-file-loader.c
@@ -46,24 +46,7 @@
#define NOTIFICATION_TIMEOUT 300
-struct _SushiFileLoader {
- GFile *file;
- GFileInfo *info;
-
- GCancellable *cancellable;
-
- gint file_items;
- gint directory_items;
- gint unreadable_items;
-
- goffset total_size;
-
- gboolean loading;
-
- guint size_notify_timeout_id;
-};
-
-G_DEFINE_TYPE (SushiFileLoader, sushi_file_loader, G_TYPE_OBJECT)
+G_DEFINE_TYPE (SushiFileLoader, sushi_file_loader, G_TYPE_OBJECT);
enum {
PROP_NAME = 1,
@@ -88,6 +71,23 @@ typedef struct {
} DeepCountState;
+struct _SushiFileLoaderPrivate {
+ GFile *file;
+ GFileInfo *info;
+
+ GCancellable *cancellable;
+
+ gint file_items;
+ gint directory_items;
+ gint unreadable_items;
+
+ goffset total_size;
+
+ gboolean loading;
+
+ guint size_notify_timeout_id;
+};
+
#define DIRECTORY_LOAD_ITEMS_PER_CALLBACK 100
static void deep_count_load (DeepCountState *state,
@@ -98,7 +98,7 @@ size_notify_timeout_cb (gpointer user_data)
{
SushiFileLoader *self = user_data;
- self->size_notify_timeout_id = 0;
+ self->priv->size_notify_timeout_id = 0;
g_object_notify (G_OBJECT (self), "size");
@@ -108,11 +108,12 @@ size_notify_timeout_cb (gpointer user_data)
static void
queue_size_notify (SushiFileLoader *self)
{
- if (self->size_notify_timeout_id != 0)
+ if (self->priv->size_notify_timeout_id != 0)
return;
- self->size_notify_timeout_id = g_timeout_add (NOTIFICATION_TIMEOUT,
- size_notify_timeout_cb, self);
+ self->priv->size_notify_timeout_id =
+ g_timeout_add (NOTIFICATION_TIMEOUT,
+ size_notify_timeout_cb, self);
}
/* adapted from nautilus/libnautilus-private/nautilus-directory-async.c */
@@ -158,7 +159,7 @@ deep_count_one (DeepCountState *state,
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
/* count the directory */
- state->self->directory_items += 1;
+ state->self->priv->directory_items += 1;
/* record the fact that we have to descend into this directory */
subdir = g_file_get_child (state->file, g_file_info_get_name (info));
@@ -166,19 +167,19 @@ deep_count_one (DeepCountState *state,
g_list_prepend (state->deep_count_subdirectories, subdir);
} else {
/* even non-regular files count as files */
- state->self->file_items += 1;
+ state->self->priv->file_items += 1;
}
/* count the size */
if (!is_seen_inode &&
g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
- state->self->total_size += g_file_info_get_size (info);
+ state->self->priv->total_size += g_file_info_get_size (info);
}
static void
deep_count_state_free (DeepCountState *state)
{
- state->self->loading = FALSE;
+ state->self->priv->loading = FALSE;
if (state->enumerator) {
if (!g_file_enumerator_is_closed (state->enumerator))
@@ -188,7 +189,7 @@ deep_count_state_free (DeepCountState *state)
g_object_unref (state->enumerator);
}
- g_cancellable_reset (state->self->cancellable);
+ g_cancellable_reset (state->self->priv->cancellable);
g_clear_object (&state->file);
g_list_free_full (state->deep_count_subdirectories, g_object_unref);
@@ -227,11 +228,13 @@ deep_count_more_files_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- DeepCountState *state = user_data;
+ DeepCountState *state;
GList *files, *l;
GFileInfo *info;
- if (g_cancellable_is_cancelled (state->self->cancellable)) {
+ state = user_data;
+
+ if (g_cancellable_is_cancelled (state->self->priv->cancellable)) {
deep_count_state_free (state);
return;
}
@@ -255,7 +258,7 @@ deep_count_more_files_callback (GObject *source_object,
g_file_enumerator_next_files_async (state->enumerator,
DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
G_PRIORITY_DEFAULT,
- state->self->cancellable,
+ state->self->priv->cancellable,
deep_count_more_files_callback,
state);
}
@@ -268,10 +271,12 @@ deep_count_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- DeepCountState *state = user_data;
+ DeepCountState *state;
GFileEnumerator *enumerator;
- if (g_cancellable_is_cancelled (state->self->cancellable)) {
+ state = user_data;
+
+ if (g_cancellable_is_cancelled (state->self->priv->cancellable)) {
deep_count_state_free (state);
return;
}
@@ -280,14 +285,14 @@ deep_count_callback (GObject *source_object,
res, NULL);
if (enumerator == NULL) {
- state->self->unreadable_items += 1;
+ state->self->priv->unreadable_items += 1;
deep_count_next_dir (state);
} else {
state->enumerator = enumerator;
g_file_enumerator_next_files_async (state->enumerator,
DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
G_PRIORITY_LOW,
- state->self->cancellable,
+ state->self->priv->cancellable,
deep_count_more_files_callback,
state);
}
@@ -297,12 +302,13 @@ static void
deep_count_load (DeepCountState *state,
GFile *file)
{
- state->self->file = g_object_ref (file);
+ state->file = g_object_ref (file);
+
g_file_enumerate_children_async (state->file,
DEEP_COUNT_ATTRS,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, /* flags */
G_PRIORITY_LOW, /* prio */
- state->self->cancellable,
+ state->self->priv->cancellable,
deep_count_callback,
state);
}
@@ -317,7 +323,7 @@ deep_count_start (SushiFileLoader *self)
state->seen_deep_count_inodes = g_hash_table_new (g_int64_hash,
g_int64_equal);
- deep_count_load (state, state->self->file);
+ deep_count_load (state, self->priv->file);
}
static void
@@ -334,10 +340,10 @@ query_info_async_ready_cb (GObject *source,
if (error != NULL) {
- if (!g_cancellable_is_cancelled (self->cancellable)) {
+ if (!g_cancellable_is_cancelled (self->priv->cancellable)) {
gchar *uri;
- uri = g_file_get_uri (self->file);
+ uri = g_file_get_uri (self->priv->file);
g_warning ("Unable to query info for file %s: %s", uri, error->message);
g_free (uri);
@@ -348,7 +354,7 @@ query_info_async_ready_cb (GObject *source,
return;
}
- self->info = info;
+ self->priv->info = info;
g_object_notify (G_OBJECT (self), "icon");
g_object_notify (G_OBJECT (self), "name");
@@ -357,7 +363,7 @@ query_info_async_ready_cb (GObject *source,
g_object_notify (G_OBJECT (self), "file-type");
if (g_file_info_get_file_type (info) != G_FILE_TYPE_DIRECTORY) {
- self->loading = FALSE;
+ self->priv->loading = FALSE;
g_object_notify (G_OBJECT (self), "size");
} else {
deep_count_start (self);
@@ -367,12 +373,13 @@ query_info_async_ready_cb (GObject *source,
static void
start_loading_file (SushiFileLoader *self)
{
- self->loading = TRUE;
- g_file_query_info_async (self->file,
+ self->priv->loading = TRUE;
+
+ g_file_query_info_async (self->priv->file,
LOADER_ATTRS,
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
- self->cancellable,
+ self->priv->cancellable,
query_info_async_ready_cb,
self);
}
@@ -381,10 +388,10 @@ static void
sushi_file_loader_set_file (SushiFileLoader *self,
GFile *file)
{
- g_clear_object (&self->file);
- g_clear_object (&self->info);
+ g_clear_object (&self->priv->file);
+ g_clear_object (&self->priv->info);
- self->file = g_object_ref (file);
+ self->priv->file = g_object_ref (file);
start_loading_file (self);
}
@@ -393,17 +400,17 @@ sushi_file_loader_dispose (GObject *object)
{
SushiFileLoader *self = SUSHI_FILE_LOADER (object);
- g_clear_object (&self->file);
- g_clear_object (&self->info);
+ g_clear_object (&self->priv->file);
+ g_clear_object (&self->priv->info);
- if (self->cancellable != NULL) {
- g_cancellable_cancel (self->cancellable);
- g_clear_object (&self->cancellable);
+ if (self->priv->cancellable != NULL) {
+ g_cancellable_cancel (self->priv->cancellable);
+ g_clear_object (&self->priv->cancellable);
}
- if (self->size_notify_timeout_id != 0) {
- g_source_remove (self->size_notify_timeout_id);
- self->size_notify_timeout_id = 0;
+ if (self->priv->size_notify_timeout_id != 0) {
+ g_source_remove (self->priv->size_notify_timeout_id);
+ self->priv->size_notify_timeout_id = 0;
}
G_OBJECT_CLASS (sushi_file_loader_parent_class)->dispose (object);
@@ -431,7 +438,7 @@ sushi_file_loader_get_property (GObject *object,
g_value_set_object (value, sushi_file_loader_get_icon (self));
break;
case PROP_FILE:
- g_value_set_object (value, self->file);
+ g_value_set_object (value, self->priv->file);
break;
case PROP_CONTENT_TYPE:
g_value_take_string (value, sushi_file_loader_get_content_type_string (self));
@@ -517,14 +524,20 @@ sushi_file_loader_class_init (SushiFileLoaderClass *klass)
G_TYPE_ICON,
G_PARAM_READABLE);
+ g_type_class_add_private (klass, sizeof (SushiFileLoaderPrivate));
g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
}
static void
sushi_file_loader_init (SushiFileLoader *self)
{
- self->cancellable = g_cancellable_new ();
- self->total_size = -1;
+ self->priv =
+ G_TYPE_INSTANCE_GET_PRIVATE (self,
+ SUSHI_TYPE_FILE_LOADER,
+ SushiFileLoaderPrivate);
+
+ self->priv->cancellable = g_cancellable_new ();
+ self->priv->total_size = -1;
}
SushiFileLoader *
@@ -544,10 +557,10 @@ sushi_file_loader_new (GFile *file)
gchar *
sushi_file_loader_get_display_name (SushiFileLoader *self)
{
- if (self->info == NULL)
+ if (self->priv->info == NULL)
return NULL;
- return g_strdup (g_file_info_get_display_name (self->info));
+ return g_strdup (g_file_info_get_display_name (self->priv->info));
}
/**
@@ -559,10 +572,10 @@ sushi_file_loader_get_display_name (SushiFileLoader *self)
GIcon *
sushi_file_loader_get_icon (SushiFileLoader *self)
{
- if (self->info == NULL)
+ if (self->priv->info == NULL)
return NULL;
- return g_file_info_get_icon (self->info);
+ return g_file_info_get_icon (self->priv->info);
}
/**
@@ -576,19 +589,19 @@ sushi_file_loader_get_size_string (SushiFileLoader *self)
{
goffset size;
- if (self->info == NULL)
+ if (self->priv->info == NULL)
return NULL;
- if (g_file_info_get_file_type (self->info) != G_FILE_TYPE_DIRECTORY) {
- size = g_file_info_get_size (self->info);
+ if (g_file_info_get_file_type (self->priv->info) != G_FILE_TYPE_DIRECTORY) {
+ size = g_file_info_get_size (self->priv->info);
return g_format_size (size);
}
- if (self->total_size != -1) {
+ if (self->priv->total_size != -1) {
gchar *str, *size_str, *retval;
const gchar *items_str;
- size = self->total_size;
+ size = self->priv->total_size;
/* FIXME: we prolly could also use directory_items and unreadable_items
* somehow.
@@ -596,8 +609,8 @@ sushi_file_loader_get_size_string (SushiFileLoader *self)
items_str = g_dngettext (GETTEXT_PACKAGE,
"%d item",
"%d items",
- self->file_items + self->directory_items);
- str = g_strdup_printf (items_str, self->file_items + self->directory_items);
+ self->priv->file_items + self->priv->directory_items);
+ str = g_strdup_printf (items_str, self->priv->file_items + self->priv->directory_items);
size_str = g_format_size (size);
retval = g_strconcat (size_str, ", ", str, NULL);
@@ -605,7 +618,7 @@ sushi_file_loader_get_size_string (SushiFileLoader *self)
g_free (size_str);
return retval;
- } else if (!self->loading) {
+ } else if (!self->priv->loading) {
return g_strdup (_("Empty Folder"));
}
@@ -615,7 +628,7 @@ sushi_file_loader_get_size_string (SushiFileLoader *self)
gboolean
sushi_file_loader_get_loading (SushiFileLoader *self)
{
- return self->loading;
+ return self->priv->loading;
}
/**
@@ -631,10 +644,10 @@ sushi_file_loader_get_date_string (SushiFileLoader *self)
GDateTime *date;
gchar *retval;
- if (self->info == NULL)
+ if (self->priv->info == NULL)
return NULL;
- g_file_info_get_modification_time (self->info,
+ g_file_info_get_modification_time (self->priv->info,
&timeval);
date = g_date_time_new_from_timeval_local (&timeval);
@@ -654,10 +667,10 @@ sushi_file_loader_get_date_string (SushiFileLoader *self)
gchar *
sushi_file_loader_get_content_type_string (SushiFileLoader *self)
{
- if (self->info == NULL)
+ if (self->priv->info == NULL)
return NULL;
- return g_content_type_get_description (g_file_info_get_content_type (self->info));
+ return g_content_type_get_description (g_file_info_get_content_type (self->priv->info));
}
/**
@@ -669,14 +682,17 @@ sushi_file_loader_get_content_type_string (SushiFileLoader *self)
GFileType
sushi_file_loader_get_file_type (SushiFileLoader *self)
{
- if (self->info == NULL)
+ if (self->priv->info == NULL)
return G_FILE_TYPE_UNKNOWN;
- return g_file_info_get_file_type (self->info);
+ return g_file_info_get_file_type (self->priv->info);
}
void
sushi_file_loader_stop (SushiFileLoader *self)
{
- g_cancellable_cancel (self->cancellable);
+ if (self->priv->cancellable == NULL)
+ return;
+
+ g_cancellable_cancel (self->priv->cancellable);
}
diff --git a/src/libsushi/sushi-file-loader.h b/src/libsushi/sushi-file-loader.h
index 71a381c..b883a5c 100644
--- a/src/libsushi/sushi-file-loader.h
+++ b/src/libsushi/sushi-file-loader.h
@@ -31,8 +31,30 @@
G_BEGIN_DECLS
-#define SUSHI_TYPE_FILE_LOADER sushi_file_loader_get_type ()
-G_DECLARE_FINAL_TYPE (SushiFileLoader, sushi_file_loader, SUSHI, FILE_LOADER, GObject)
+#define SUSHI_TYPE_FILE_LOADER (sushi_file_loader_get_type ())
+#define SUSHI_FILE_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SUSHI_TYPE_FILE_LOADER,
SushiFileLoader))
+#define SUSHI_IS_FILE_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SUSHI_TYPE_FILE_LOADER))
+#define SUSHI_FILE_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SUSHI_TYPE_FILE_LOADER,
SushiFileLoaderClass))
+#define SUSHI_IS_FILE_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SUSHI_TYPE_FILE_LOADER))
+#define SUSHI_FILE_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SUSHI_TYPE_FILE_LOADER,
SushiFileLoaderClass))
+
+typedef struct _SushiFileLoader SushiFileLoader;
+typedef struct _SushiFileLoaderPrivate SushiFileLoaderPrivate;
+typedef struct _SushiFileLoaderClass SushiFileLoaderClass;
+
+struct _SushiFileLoader
+{
+ GObject parent_instance;
+
+ SushiFileLoaderPrivate *priv;
+};
+
+struct _SushiFileLoaderClass
+{
+ GObjectClass parent_class;
+};
+
+GType sushi_file_loader_get_type (void) G_GNUC_CONST;
SushiFileLoader *sushi_file_loader_new (GFile *file);
diff --git a/src/libsushi/sushi-pdf-loader.c b/src/libsushi/sushi-pdf-loader.c
index c80ba49..508f63d 100644
--- a/src/libsushi/sushi-pdf-loader.c
+++ b/src/libsushi/sushi-pdf-loader.c
@@ -31,7 +31,16 @@
#include <glib/gstdio.h>
#include <gdk/gdkx.h>
-struct _SushiPdfLoader {
+G_DEFINE_TYPE (SushiPdfLoader, sushi_pdf_loader, G_TYPE_OBJECT);
+
+enum {
+ PROP_DOCUMENT = 1,
+ PROP_URI
+};
+
+static void load_libreoffice (SushiPdfLoader *self);
+
+struct _SushiPdfLoaderPrivate {
EvDocument *document;
gchar *uri;
gchar *pdf_path;
@@ -41,15 +50,6 @@ struct _SushiPdfLoader {
GPid libreoffice_pid;
};
-G_DEFINE_TYPE (SushiPdfLoader, sushi_pdf_loader, G_TYPE_OBJECT)
-
-enum {
- PROP_DOCUMENT = 1,
- PROP_URI
-};
-
-static void load_libreoffice (SushiPdfLoader *self);
-
static void
load_job_done (EvJob *job,
gpointer user_data)
@@ -63,7 +63,7 @@ load_job_done (EvJob *job,
return;
}
- self->document = g_object_ref (job->document);
+ self->priv->document = g_object_ref (job->document);
g_object_unref (job);
g_object_notify (G_OBJECT (self), "document");
@@ -145,9 +145,9 @@ libreoffice_child_watch_cb (GPid pid,
gchar *uri;
g_spawn_close_pid (pid);
- self->libreoffice_pid = -1;
+ self->priv->libreoffice_pid = -1;
- file = g_file_new_for_path (self->pdf_path);
+ file = g_file_new_for_path (self->priv->pdf_path);
uri = g_file_get_uri (file);
load_pdf (self, uri);
@@ -166,10 +166,10 @@ check_libreoffice_flatpak (SushiPdfLoader *self,
gint exit_status = -1;
GError *error = NULL;
- if (self->checked_libreoffice_flatpak)
- return self->have_libreoffice_flatpak;
+ if (self->priv->checked_libreoffice_flatpak)
+ return self->priv->have_libreoffice_flatpak;
- self->checked_libreoffice_flatpak = TRUE;
+ self->priv->checked_libreoffice_flatpak = TRUE;
ret = g_spawn_sync (NULL, (gchar **) check_argv, NULL,
G_SPAWN_DEFAULT |
@@ -183,7 +183,7 @@ check_libreoffice_flatpak (SushiPdfLoader *self,
GError *child_error = NULL;
if (g_spawn_check_exit_status (exit_status, &child_error)) {
g_debug ("Found LibreOffice flatpak!");
- self->have_libreoffice_flatpak = TRUE;
+ self->priv->have_libreoffice_flatpak = TRUE;
} else {
g_debug ("LibreOffice flatpak not found, flatpak info returned %i (%s)",
exit_status, child_error->message);
@@ -195,7 +195,7 @@ check_libreoffice_flatpak (SushiPdfLoader *self,
g_clear_error (&error);
}
- return self->have_libreoffice_flatpak;
+ return self->priv->have_libreoffice_flatpak;
}
static void
@@ -224,7 +224,7 @@ load_libreoffice (SushiPdfLoader *self)
}
}
- file = g_file_new_for_uri (self->uri);
+ file = g_file_new_for_uri (self->priv->uri);
doc_path = g_file_get_path (file);
doc_name = g_file_get_basename (file);
g_object_unref (file);
@@ -237,7 +237,7 @@ load_libreoffice (SushiPdfLoader *self)
g_free (doc_name);
pdf_dir = g_build_filename (g_get_user_cache_dir (), "sushi", NULL);
- self->pdf_path = g_build_filename (pdf_dir, tmp_name, NULL);
+ self->priv->pdf_path = g_build_filename (pdf_dir, tmp_name, NULL);
g_mkdir_with_parents (pdf_dir, 0700);
g_free (tmp_name);
@@ -308,7 +308,7 @@ load_libreoffice (SushiPdfLoader *self)
}
g_child_watch_add (pid, libreoffice_child_watch_cb, self);
- self->libreoffice_pid = pid;
+ self->priv->libreoffice_pid = pid;
}
static gboolean
@@ -346,7 +346,7 @@ query_info_ready_cb (GObject *obj,
if (error != NULL) {
g_warning ("Unable to query the mimetype of %s: %s",
- self->uri, error->message);
+ self->priv->uri, error->message);
g_error_free (error);
return;
@@ -355,7 +355,7 @@ query_info_ready_cb (GObject *obj,
content_type = g_file_info_get_content_type (info);
if (content_type_is_native (content_type))
- load_pdf (self, self->uri);
+ load_pdf (self, self->priv->uri);
else
load_libreoffice (self);
@@ -367,7 +367,7 @@ start_loading_document (SushiPdfLoader *self)
{
GFile *file;
- file = g_file_new_for_uri (self->uri);
+ file = g_file_new_for_uri (self->priv->uri);
g_file_query_info_async (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_QUERY_INFO_NONE,
@@ -383,10 +383,10 @@ static void
sushi_pdf_loader_set_uri (SushiPdfLoader *self,
const gchar *uri)
{
- g_clear_object (&self->document);
- g_free (self->uri);
+ g_clear_object (&self->priv->document);
+ g_free (self->priv->uri);
- self->uri = g_strdup (uri);
+ self->priv->uri = g_strdup (uri);
start_loading_document (self);
}
@@ -395,18 +395,18 @@ sushi_pdf_loader_dispose (GObject *object)
{
SushiPdfLoader *self = SUSHI_PDF_LOADER (object);
- if (self->pdf_path) {
- g_unlink (self->pdf_path);
- g_free (self->pdf_path);
+ if (self->priv->pdf_path) {
+ g_unlink (self->priv->pdf_path);
+ g_free (self->priv->pdf_path);
}
- if (self->libreoffice_pid != -1) {
- kill (self->libreoffice_pid, SIGKILL);
- self->libreoffice_pid = -1;
+ if (self->priv->libreoffice_pid != -1) {
+ kill (self->priv->libreoffice_pid, SIGKILL);
+ self->priv->libreoffice_pid = -1;
}
- g_clear_object (&self->document);
- g_free (self->uri);
+ g_clear_object (&self->priv->document);
+ g_free (self->priv->uri);
G_OBJECT_CLASS (sushi_pdf_loader_parent_class)->dispose (object);
}
@@ -421,10 +421,10 @@ sushi_pdf_loader_get_property (GObject *object,
switch (prop_id) {
case PROP_DOCUMENT:
- g_value_set_object (value, self->document);
+ g_value_set_object (value, self->priv->document);
break;
case PROP_URI:
- g_value_set_string (value, self->uri);
+ g_value_set_string (value, self->priv->uri);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -477,12 +477,18 @@ sushi_pdf_loader_class_init (SushiPdfLoaderClass *klass)
"The URI to load",
NULL,
G_PARAM_READWRITE));
+
+ g_type_class_add_private (klass, sizeof (SushiPdfLoaderPrivate));
}
static void
sushi_pdf_loader_init (SushiPdfLoader *self)
{
- self->libreoffice_pid = -1;
+ self->priv =
+ G_TYPE_INSTANCE_GET_PRIVATE (self,
+ SUSHI_TYPE_PDF_LOADER,
+ SushiPdfLoaderPrivate);
+ self->priv->libreoffice_pid = -1;
}
SushiPdfLoader *
diff --git a/src/libsushi/sushi-pdf-loader.h b/src/libsushi/sushi-pdf-loader.h
index b484df6..3a5fc70 100644
--- a/src/libsushi/sushi-pdf-loader.h
+++ b/src/libsushi/sushi-pdf-loader.h
@@ -30,8 +30,30 @@
G_BEGIN_DECLS
-#define SUSHI_TYPE_PDF_LOADER sushi_pdf_loader_get_type ()
-G_DECLARE_FINAL_TYPE (SushiPdfLoader, sushi_pdf_loader, SUSHI, PDF_LOADER, GObject)
+#define SUSHI_TYPE_PDF_LOADER (sushi_pdf_loader_get_type ())
+#define SUSHI_PDF_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SUSHI_TYPE_PDF_LOADER,
SushiPdfLoader))
+#define SUSHI_IS_PDF_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SUSHI_TYPE_PDF_LOADER))
+#define SUSHI_PDF_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SUSHI_TYPE_PDF_LOADER,
SushiPdfLoaderClass))
+#define SUSHI_IS_PDF_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SUSHI_TYPE_PDF_LOADER))
+#define SUSHI_PDF_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SUSHI_TYPE_PDF_LOADER,
SushiPdfLoaderClass))
+
+typedef struct _SushiPdfLoader SushiPdfLoader;
+typedef struct _SushiPdfLoaderPrivate SushiPdfLoaderPrivate;
+typedef struct _SushiPdfLoaderClass SushiPdfLoaderClass;
+
+struct _SushiPdfLoader
+{
+ GObject parent_instance;
+
+ SushiPdfLoaderPrivate *priv;
+};
+
+struct _SushiPdfLoaderClass
+{
+ GObjectClass parent_class;
+};
+
+GType sushi_pdf_loader_get_type (void) G_GNUC_CONST;
SushiPdfLoader *sushi_pdf_loader_new (const gchar *uri);
diff --git a/src/libsushi/sushi-sound-player.c b/src/libsushi/sushi-sound-player.c
index af9e251..18db6a2 100644
--- a/src/libsushi/sushi-sound-player.c
+++ b/src/libsushi/sushi-sound-player.c
@@ -32,7 +32,27 @@
#include "sushi-enum-types.h"
#include "sushi-sound-player.h"
-struct _SushiSoundPlayer {
+G_DEFINE_TYPE (SushiSoundPlayer, sushi_sound_player, G_TYPE_OBJECT);
+
+#define SUSHI_SOUND_PLAYER_GET_PRIVATE(obj) \
+(G_TYPE_INSTANCE_GET_PRIVATE ((obj), SUSHI_TYPE_SOUND_PLAYER, SushiSoundPlayerPrivate))
+
+#define TICK_TIMEOUT 0.5
+
+enum
+{
+ PROP_0,
+
+ PROP_PLAYING,
+ PROP_STATE,
+ PROP_PROGRESS,
+ PROP_DURATION,
+ PROP_URI,
+ PROP_TAGLIST
+};
+
+struct _SushiSoundPlayerPrivate
+{
GstElement *pipeline;
GstBus *bus;
SushiSoundPlayerState state;
@@ -50,22 +70,6 @@ struct _SushiSoundPlayer {
guint in_seek : 1;
};
-G_DEFINE_TYPE (SushiSoundPlayer, sushi_sound_player, G_TYPE_OBJECT)
-
-#define TICK_TIMEOUT 0.5
-
-enum
-{
- PROP_0,
-
- PROP_PLAYING,
- PROP_STATE,
- PROP_PROGRESS,
- PROP_DURATION,
- PROP_URI,
- PROP_TAGLIST
-};
-
static void sushi_sound_player_destroy_pipeline (SushiSoundPlayer *player);
static gboolean sushi_sound_player_ensure_pipeline (SushiSoundPlayer *player);
@@ -73,12 +77,16 @@ static void
sushi_sound_player_set_state (SushiSoundPlayer *player,
SushiSoundPlayerState state)
{
+ SushiSoundPlayerPrivate *priv;
+
g_return_if_fail (SUSHI_IS_SOUND_PLAYER (player));
- if (player->state == state)
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (priv->state == state)
return;
- player->state = state;
+ priv->state = state;
g_object_notify (G_OBJECT (player), "state");
}
@@ -87,21 +95,23 @@ sushi_sound_player_set_state (SushiSoundPlayer *player,
static void
sushi_sound_player_destroy_discoverer (SushiSoundPlayer *player)
{
- if (player->discoverer == NULL)
+ SushiSoundPlayerPrivate *priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (priv->discoverer == NULL)
return;
- if (player->taglist != NULL) {
- gst_tag_list_free (player->taglist);
- player->taglist = NULL;
+ if (priv->taglist != NULL) {
+ gst_tag_list_free (priv->taglist);
+ priv->taglist = NULL;
}
- gst_discoverer_stop (player->discoverer);
- gst_object_unref (player->discoverer);
- player->discoverer = NULL;
+ gst_discoverer_stop (priv->discoverer);
+ gst_object_unref (priv->discoverer);
+ priv->discoverer = NULL;
g_object_notify (G_OBJECT (player), "taglist");
- g_clear_object (&player->taglist);
+ g_clear_object (&priv->taglist);
}
static void
@@ -111,8 +121,11 @@ discoverer_discovered_cb (GstDiscoverer *disco,
gpointer user_data)
{
SushiSoundPlayer *player = user_data;
+ SushiSoundPlayerPrivate *priv;
const GstTagList *taglist;
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
if (error != NULL)
return;
@@ -120,7 +133,7 @@ discoverer_discovered_cb (GstDiscoverer *disco,
if (taglist)
{
- player->taglist = gst_tag_list_copy (taglist);
+ priv->taglist = gst_tag_list_copy (taglist);
g_object_notify (G_OBJECT (player), "taglist");
}
}
@@ -128,19 +141,22 @@ discoverer_discovered_cb (GstDiscoverer *disco,
static gboolean
sushi_sound_player_ensure_discoverer (SushiSoundPlayer *player)
{
- if (player->discoverer)
+ SushiSoundPlayerPrivate *priv;
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (priv->discoverer)
return TRUE;
- player->discoverer = gst_discoverer_new (GST_SECOND * 60,
+ priv->discoverer = gst_discoverer_new (GST_SECOND * 60,
NULL);
- if (player->discoverer == NULL)
+ if (priv->discoverer == NULL)
return FALSE;
- g_signal_connect (player->discoverer, "discovered",
+ g_signal_connect (priv->discoverer, "discovered",
G_CALLBACK (discoverer_discovered_cb), player);
- gst_discoverer_start (player->discoverer);
- gst_discoverer_discover_uri_async (player->discoverer, player->uri);
+ gst_discoverer_start (priv->discoverer);
+ gst_discoverer_discover_uri_async (priv->discoverer, priv->uri);
return TRUE;
}
@@ -149,18 +165,22 @@ static void
sushi_sound_player_set_uri (SushiSoundPlayer *player,
const char *uri)
{
+ SushiSoundPlayerPrivate *priv;
+
g_return_if_fail (SUSHI_IS_SOUND_PLAYER (player));
- if (!g_strcmp0 (player->uri, uri))
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (!g_strcmp0 (priv->uri, uri))
return;
- g_free (player->uri);
- player->uri = g_strdup (uri);
+ g_free (priv->uri);
+ priv->uri = g_strdup (uri);
- if (player->pipeline)
+ if (priv->pipeline)
sushi_sound_player_destroy_pipeline (player);
- if (player->discoverer)
+ if (priv->discoverer)
sushi_sound_player_destroy_discoverer (player);
sushi_sound_player_ensure_pipeline (player);
@@ -173,31 +193,34 @@ static void
sushi_sound_player_set_progress (SushiSoundPlayer *player,
gdouble progress)
{
+ SushiSoundPlayerPrivate *priv;
GstState pending;
GstQuery *duration_q;
gint64 position;
- if (!player->pipeline)
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (!priv->pipeline)
return;
- player->target_progress = progress;
+ priv->target_progress = progress;
- if (player->in_seek)
+ if (priv->in_seek)
{
- player->stacked_progress = progress;
+ priv->stacked_progress = progress;
return;
}
- gst_element_get_state (player->pipeline, &player->stacked_state, &pending, 0);
+ gst_element_get_state (priv->pipeline, &priv->stacked_state, &pending, 0);
if (pending)
- player->stacked_state = pending;
+ priv->stacked_state = pending;
- gst_element_set_state (player->pipeline, GST_STATE_PAUSED);
+ gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
duration_q = gst_query_new_duration (GST_FORMAT_TIME);
- if (gst_element_query (player->pipeline, duration_q))
+ if (gst_element_query (priv->pipeline, duration_q))
{
gint64 duration = 0;
@@ -210,7 +233,7 @@ sushi_sound_player_set_progress (SushiSoundPlayer *player,
gst_query_unref (duration_q);
- gst_element_seek (player->pipeline,
+ gst_element_seek (priv->pipeline,
1.0,
GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH,
@@ -218,29 +241,32 @@ sushi_sound_player_set_progress (SushiSoundPlayer *player,
position,
GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
- player->in_seek = TRUE;
- player->stacked_progress = 0.0;
+ priv->in_seek = TRUE;
+ priv->stacked_progress = 0.0;
}
static gdouble
sushi_sound_player_get_progress (SushiSoundPlayer *player)
{
+ SushiSoundPlayerPrivate *priv;
GstQuery *position_q, *duration_q;
gdouble progress;
- if (!player->pipeline)
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (!priv->pipeline)
return 0.0;
- if (player->in_seek)
+ if (priv->in_seek)
{
- return player->target_progress;
+ return priv->target_progress;
}
position_q = gst_query_new_position (GST_FORMAT_TIME);
duration_q = gst_query_new_duration (GST_FORMAT_TIME);
- if (gst_element_query (player->pipeline, position_q) &&
- gst_element_query (player->pipeline, duration_q))
+ if (gst_element_query (priv->pipeline, position_q) &&
+ gst_element_query (priv->pipeline, duration_q))
{
gint64 position, duration;
@@ -263,19 +289,22 @@ sushi_sound_player_get_progress (SushiSoundPlayer *player)
static void
sushi_sound_player_query_duration (SushiSoundPlayer *player)
{
+ SushiSoundPlayerPrivate *priv;
gdouble new_duration, difference;
gint64 duration;
- if (!gst_element_query_duration (player->pipeline, GST_FORMAT_TIME, &duration))
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (!gst_element_query_duration (priv->pipeline, GST_FORMAT_TIME, &duration))
return;
new_duration = (gdouble) duration / GST_SECOND;
- difference = ABS (player->duration - new_duration);
+ difference = ABS (priv->duration - new_duration);
if (difference > 1e-3)
{
- player->duration = new_duration;
+ priv->duration = new_duration;
if (difference > 1.0)
g_object_notify (G_OBJECT (player), "duration");
@@ -285,13 +314,16 @@ sushi_sound_player_query_duration (SushiSoundPlayer *player)
static void
sushi_sound_player_reset_pipeline (SushiSoundPlayer *player)
{
+ SushiSoundPlayerPrivate *priv;
GstState state, pending;
GstMessage *msg;
- if (!player->pipeline)
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (!priv->pipeline)
return;
- gst_element_get_state (player->pipeline, &state, &pending, 0);
+ gst_element_get_state (priv->pipeline, &state, &pending, 0);
if (state == GST_STATE_NULL && pending == GST_STATE_VOID_PENDING)
{
@@ -299,17 +331,17 @@ sushi_sound_player_reset_pipeline (SushiSoundPlayer *player)
}
else if (state == GST_STATE_NULL && pending != GST_STATE_VOID_PENDING)
{
- gst_element_set_state (player->pipeline, GST_STATE_NULL);
+ gst_element_set_state (priv->pipeline, GST_STATE_NULL);
return;
}
- gst_element_set_state (player->pipeline, GST_STATE_READY);
- gst_element_get_state (player->pipeline, NULL, NULL, -1);
+ gst_element_set_state (priv->pipeline, GST_STATE_READY);
+ gst_element_get_state (priv->pipeline, NULL, NULL, -1);
- while ((msg = gst_bus_pop (player->bus)))
- gst_bus_async_signal_func (player->bus, msg, NULL);
+ while ((msg = gst_bus_pop (priv->bus)))
+ gst_bus_async_signal_func (priv->bus, msg, NULL);
- gst_element_set_state (player->pipeline, GST_STATE_NULL);
+ gst_element_set_state (priv->pipeline, GST_STATE_NULL);
g_object_notify (G_OBJECT (player), "duration");
g_object_notify (G_OBJECT (player), "progress");
@@ -318,27 +350,31 @@ sushi_sound_player_reset_pipeline (SushiSoundPlayer *player)
static void
sushi_sound_player_destroy_pipeline (SushiSoundPlayer *player)
{
- if (player->bus)
+ SushiSoundPlayerPrivate *priv;
+
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (priv->bus)
{
- gst_bus_set_flushing (player->bus, TRUE);
- gst_bus_remove_signal_watch (player->bus);
+ gst_bus_set_flushing (priv->bus, TRUE);
+ gst_bus_remove_signal_watch (priv->bus);
- gst_object_unref (player->bus);
- player->bus = NULL;
+ gst_object_unref (priv->bus);
+ priv->bus = NULL;
}
- if (player->pipeline)
+ if (priv->pipeline)
{
- gst_element_set_state (player->pipeline, GST_STATE_NULL);
+ gst_element_set_state (priv->pipeline, GST_STATE_NULL);
- gst_object_unref (player->pipeline);
- player->pipeline = NULL;
+ gst_object_unref (priv->pipeline);
+ priv->pipeline = NULL;
}
- if (player->tick_timeout_id != 0)
+ if (priv->tick_timeout_id != 0)
{
- g_source_remove (player->tick_timeout_id);
- player->tick_timeout_id = 0;
+ g_source_remove (priv->tick_timeout_id);
+ priv->tick_timeout_id = 0;
}
g_object_notify (G_OBJECT (player), "duration");
@@ -360,11 +396,14 @@ sushi_sound_player_on_state_changed (GstBus *bus,
GstMessage *msg,
SushiSoundPlayer *player)
{
+ SushiSoundPlayerPrivate *priv;
GstState state, old_state;
g_return_if_fail (SUSHI_IS_SOUND_PLAYER (player));
- if (msg->src != GST_OBJECT (player->pipeline))
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (msg->src != GST_OBJECT (priv->pipeline))
return;
gst_message_parse_state_changed (msg, &old_state, &state, NULL);
@@ -377,9 +416,9 @@ sushi_sound_player_on_state_changed (GstBus *bus,
case GST_STATE_PLAYING:
sushi_sound_player_set_state (player, SUSHI_SOUND_PLAYER_STATE_PLAYING);
- if (player->tick_timeout_id == 0)
+ if (priv->tick_timeout_id == 0)
{
- player->tick_timeout_id =
+ priv->tick_timeout_id =
g_timeout_add (TICK_TIMEOUT * 1000,
sushi_sound_player_tick_timeout,
player);
@@ -390,10 +429,10 @@ sushi_sound_player_on_state_changed (GstBus *bus,
case GST_STATE_PAUSED:
sushi_sound_player_set_state (player, SUSHI_SOUND_PLAYER_STATE_IDLE);
- if (player->tick_timeout_id != 0)
+ if (priv->tick_timeout_id != 0)
{
- g_source_remove (player->tick_timeout_id);
- player->tick_timeout_id = 0;
+ g_source_remove (priv->tick_timeout_id);
+ priv->tick_timeout_id = 0;
}
break;
@@ -428,16 +467,20 @@ sushi_sound_player_on_async_done (GstBus *bus,
GstMessage *msg,
SushiSoundPlayer *player)
{
- if (player->in_seek)
+ SushiSoundPlayerPrivate *priv;
+
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (priv->in_seek)
{
g_object_notify (G_OBJECT (player), "progress");
- player->in_seek = FALSE;
- gst_element_set_state (player->pipeline, player->stacked_state);
+ priv->in_seek = FALSE;
+ gst_element_set_state (priv->pipeline, priv->stacked_state);
- if (player->stacked_progress)
+ if (priv->stacked_progress)
{
- sushi_sound_player_set_progress (player, player->stacked_progress);
+ sushi_sound_player_set_progress (player, priv->stacked_progress);
}
}
}
@@ -460,13 +503,16 @@ sushi_sound_player_on_duration (GstBus *bus,
static gboolean
sushi_sound_player_ensure_pipeline (SushiSoundPlayer *player)
{
+ SushiSoundPlayerPrivate *priv;
GError *error;
gchar *pipeline_desc;
- if (player->pipeline)
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (priv->pipeline)
return TRUE;
- if (player->uri == NULL)
+ if (priv->uri == NULL)
{
sushi_sound_player_set_state (player, SUSHI_SOUND_PLAYER_STATE_ERROR);
return FALSE;
@@ -475,62 +521,62 @@ sushi_sound_player_ensure_pipeline (SushiSoundPlayer *player)
error = NULL;
pipeline_desc = g_strdup_printf("playbin uri=\"%s\"",
- player->uri);
+ priv->uri);
- player->pipeline = gst_parse_launch (pipeline_desc, &error);
+ priv->pipeline = gst_parse_launch (pipeline_desc, &error);
g_free (pipeline_desc);
if (error)
{
g_error_free (error);
- player->pipeline = NULL;
+ priv->pipeline = NULL;
sushi_sound_player_set_state (player, SUSHI_SOUND_PLAYER_STATE_ERROR);
return FALSE;
}
- if (!gst_element_set_state (player->pipeline, GST_STATE_READY))
+ if (!gst_element_set_state (priv->pipeline, GST_STATE_READY))
{
- g_object_unref (player->pipeline);
- player->pipeline = NULL;
+ g_object_unref (priv->pipeline);
+ priv->pipeline = NULL;
sushi_sound_player_set_state (player, SUSHI_SOUND_PLAYER_STATE_ERROR);
return FALSE;
}
- player->bus = gst_element_get_bus (player->pipeline);
+ priv->bus = gst_element_get_bus (priv->pipeline);
- gst_bus_add_signal_watch (player->bus);
+ gst_bus_add_signal_watch (priv->bus);
- g_signal_connect (player->bus,
+ g_signal_connect (priv->bus,
"message::state-changed",
G_CALLBACK (sushi_sound_player_on_state_changed),
player);
- g_signal_connect (player->bus,
+ g_signal_connect (priv->bus,
"message::error",
G_CALLBACK (sushi_sound_player_on_error),
player);
- g_signal_connect (player->bus,
+ g_signal_connect (priv->bus,
"message::eos",
G_CALLBACK (sushi_sound_player_on_eos),
player);
- g_signal_connect (player->bus,
+ g_signal_connect (priv->bus,
"message::async-done",
G_CALLBACK (sushi_sound_player_on_async_done),
player);
- g_signal_connect (player->bus,
+ g_signal_connect (priv->bus,
"message::duration",
G_CALLBACK (sushi_sound_player_on_duration),
player);
/* Pause pipeline so that the file duration becomes
* available as soon as possible */
- gst_element_set_state (player->pipeline, GST_STATE_PAUSED);
+ gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
return TRUE;
}
@@ -539,17 +585,20 @@ void
sushi_sound_player_set_playing (SushiSoundPlayer *player,
gboolean playing)
{
+ SushiSoundPlayerPrivate *priv;
GstState state;
g_return_if_fail (SUSHI_IS_SOUND_PLAYER (player));
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
if (playing)
state = GST_STATE_PLAYING;
else
state = GST_STATE_PAUSED;
if (sushi_sound_player_ensure_pipeline (player))
- gst_element_set_state (player->pipeline, state);
+ gst_element_set_state (priv->pipeline, state);
g_object_notify (G_OBJECT (player), "playing");
g_object_notify (G_OBJECT (player), "progress");
@@ -558,15 +607,18 @@ sushi_sound_player_set_playing (SushiSoundPlayer *player,
static gboolean
sushi_sound_player_get_playing (SushiSoundPlayer *player)
{
+ SushiSoundPlayerPrivate *priv;
GstState state, pending;
gboolean playing;
g_return_val_if_fail (SUSHI_IS_SOUND_PLAYER (player), FALSE);
- if (!player->pipeline)
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ if (!priv->pipeline)
return FALSE;
- gst_element_get_state (player->pipeline, &state, &pending, 0);
+ gst_element_get_state (priv->pipeline, &state, &pending, 0);
if (pending)
playing = (pending == GST_STATE_PLAYING);
@@ -598,8 +650,10 @@ sushi_sound_player_get_property (GObject *gobject,
GParamSpec *pspec)
{
SushiSoundPlayer *player;
+ SushiSoundPlayerPrivate *priv;
player = SUSHI_SOUND_PLAYER (gobject);
+ priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
switch (prop_id)
{
@@ -609,7 +663,7 @@ sushi_sound_player_get_property (GObject *gobject,
break;
case PROP_STATE:
- g_value_set_enum (value, player->state);
+ g_value_set_enum (value, priv->state);
break;
case PROP_PROGRESS:
@@ -618,15 +672,15 @@ sushi_sound_player_get_property (GObject *gobject,
break;
case PROP_DURATION:
- g_value_set_double (value, player->duration);
+ g_value_set_double (value, priv->duration);
break;
case PROP_URI:
- g_value_set_string (value, player->uri);
+ g_value_set_string (value, priv->uri);
break;
case PROP_TAGLIST:
- g_value_set_boxed (value, player->taglist);
+ g_value_set_boxed (value, priv->taglist);
break;
default:
@@ -671,6 +725,8 @@ sushi_sound_player_class_init (SushiSoundPlayerClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ g_type_class_add_private (klass, sizeof (SushiSoundPlayerPrivate));
+
gobject_class->get_property = sushi_sound_player_get_property;
gobject_class->set_property = sushi_sound_player_set_property;
gobject_class->dispose = sushi_sound_player_dispose;
@@ -740,12 +796,14 @@ sushi_sound_player_class_init (SushiSoundPlayerClass *klass)
static void
sushi_sound_player_init (SushiSoundPlayer *player)
{
- player->state = SUSHI_SOUND_PLAYER_STATE_UNKNOWN;
- player->playing = FALSE;
- player->uri = NULL;
- player->pipeline = NULL;
- player->bus = NULL;
- player->stacked_progress = 0.0;
- player->duration = 0.0;
- player->tick_timeout_id = 0;
+ player->priv = SUSHI_SOUND_PLAYER_GET_PRIVATE (player);
+
+ player->priv->state = SUSHI_SOUND_PLAYER_STATE_UNKNOWN;
+ player->priv->playing = FALSE;
+ player->priv->uri = NULL;
+ player->priv->pipeline = NULL;
+ player->priv->bus = NULL;
+ player->priv->stacked_progress = 0.0;
+ player->priv->duration = 0.0;
+ player->priv->tick_timeout_id = 0;
}
diff --git a/src/libsushi/sushi-sound-player.h b/src/libsushi/sushi-sound-player.h
index 88de628..12d578d 100644
--- a/src/libsushi/sushi-sound-player.h
+++ b/src/libsushi/sushi-sound-player.h
@@ -30,8 +30,16 @@
G_BEGIN_DECLS
-#define SUSHI_TYPE_SOUND_PLAYER sushi_sound_player_get_type ()
-G_DECLARE_FINAL_TYPE (SushiSoundPlayer, sushi_sound_player, SUSHI, SOUND_PLAYER, GObject)
+#define SUSHI_TYPE_SOUND_PLAYER (sushi_sound_player_get_type ())
+#define SUSHI_SOUND_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SUSHI_TYPE_SOUND_PLAYER,
SushiSoundPlayer))
+#define SUSHI_IS_SOUND_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SUSHI_TYPE_SOUND_PLAYER))
+#define SUSHI_SOUND_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SUSHI_TYPE_SOUND_PLAYER,
SushiSoundPlayerClass))
+#define SUSHI_IS_SOUND_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SUSHI_TYPE_SOUND_PLAYER))
+#define SUSHI_SOUND_PLAYER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SUSHI_TYPE_SOUND_PLAYER,
SushiSoundPlayerClass))
+
+typedef struct _SushiSoundPlayer SushiSoundPlayer;
+typedef struct _SushiSoundPlayerPrivate SushiSoundPlayerPrivate;
+typedef struct _SushiSoundPlayerClass SushiSoundPlayerClass;
typedef enum
{
@@ -42,6 +50,20 @@ typedef enum
SUSHI_SOUND_PLAYER_STATE_ERROR = 4
} SushiSoundPlayerState;
+struct _SushiSoundPlayer
+{
+ GObject parent_instance;
+
+ SushiSoundPlayerPrivate *priv;
+};
+
+struct _SushiSoundPlayerClass
+{
+ GObjectClass parent_class;
+};
+
+GType sushi_sound_player_get_type (void) G_GNUC_CONST;
+
G_END_DECLS
#endif /* __SUSHI_SOUND_PLAYER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]