WATC Movie: Several fixes
authorSimón Pena <spenap@gmail.com>
Mon, 17 May 2010 15:24:10 +0000 (17:24 +0200)
committerSimón Pena <spenap@gmail.com>
Mon, 17 May 2010 15:44:13 +0000 (17:44 +0200)
* The WATC Movie builds right now.

* Stingers support didn't work with the enums unregistered. The property
is an integer, now, but the limits are still checked.

* Year support is added: if the services sends a year, it is parsed
and stored

* The print method doesn't show "null" when there's no year.

src/mvs-watc-movie.c
src/mvs-watc-movie.h

index 5cdc9f5..3de9021 100644 (file)
@@ -16,6 +16,8 @@
  *
  */
 
+#include <string.h>
+
 #include "mvs-watc-movie.h"
 
 G_DEFINE_TYPE (MvsWatcMovie, mvs_watc_movie, G_TYPE_OBJECT)
@@ -24,6 +26,7 @@ enum {
         PROP_0,
         PROP_NAME,
         PROP_STINGERS,
+        PROP_YEAR,
 };
 
 #define GET_PRIVATE(o) \
@@ -31,7 +34,8 @@ enum {
 
 struct _MvsWatcMoviePrivate {
         gchar *name;
-        MvsStingers stingers;
+        int stingers;
+        gchar *year;
 };
 
 static void
@@ -47,7 +51,10 @@ mvs_watc_movie_get_property (GObject *object, guint property_id,
         case PROP_STINGERS:
                 g_value_set_enum (value, self->priv->stingers);
                 break;
-       default:
+        case PROP_YEAR:
+                g_value_set_string (value, self->priv->year);
+                break;
+        default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         }
 }
@@ -63,7 +70,10 @@ mvs_watc_movie_set_property (GObject *object, guint property_id,
                 mvs_watc_movie_set_name (self, g_value_get_string (value));
                 break;
         case PROP_STINGERS:
-                mvs_watc_movie_set_stingers (self, g_value_get_enum (value));
+                mvs_watc_movie_set_stingers (self, g_value_get_int (value));
+                break;
+        case PROP_YEAR:
+                mvs_watc_movie_set_year (self, g_value_get_string (value));
                 break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -76,6 +86,7 @@ mvs_watc_movie_finalize (GObject *object)
         MvsWatcMovie *self = MVS_WATC_MOVIE (object);
 
         g_free (self->priv->name);
+        g_free (self->priv->year);
 
         G_OBJECT_CLASS (mvs_watc_movie_parent_class)->finalize (object);
 }
@@ -100,11 +111,19 @@ mvs_watc_movie_class_init (MvsWatcMovieClass *klass)
 
         g_object_class_install_property
                 (object_class, PROP_STINGERS,
-                 g_param_spec_enum ("stingers", "Movie stingers",
+                 g_param_spec_int ("stingers", "Movie stingers",
                                  "Tells if movie has stingers",
-                                 G_TYPE_ENUM,
+                                 0,
+                                 MVS_STINGERS_LAST,
                                  MVS_STINGERS_UNKNOWN,
                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+        g_object_class_install_property
+                (object_class, PROP_YEAR,
+                 g_param_spec_string ("year", "Movie year",
+                                 "The movie year",
+                                 NULL,
+                                 G_PARAM_READWRITE));
 }
 
 static void
@@ -114,25 +133,46 @@ mvs_watc_movie_init (MvsWatcMovie *self)
 
         self->priv->name = NULL;
         self->priv->stingers = MVS_STINGERS_UNKNOWN;
+        self->priv->year = NULL;
 }
 
 MvsWatcMovie*
 mvs_watc_movie_new (const gchar *raw_name)
 {
         MvsWatcMovie *instance = g_object_new (MVS_TYPE_WATC_MOVIE, NULL);
+        int len = strlen (raw_name);
 
         /* The raw name comes with the format
-         * $(MOVIE_NAME) $(YEAR)$(STINGERS) */
+         * $(MOVIE_NAME) $(YEAR)$(STINGERS)
+         *
+         * If stingers are present, actual length is len-1.
+         * If date is present, actual length is len-6
+         * */
 
-        if (g_str_has_suffix (raw_name, "*"))
+        if (g_str_has_suffix (raw_name, "*")) {
                 instance->priv->stingers = MVS_STINGERS_YES;
-        else if (g_str_has_suffix (raw_name, "?"))
+                len--;
+        }
+        else if (g_str_has_suffix (raw_name, "?")) {
                 instance->priv->stingers = MVS_STINGERS_UNKNOWN;
+                len--;
+        }
         else
                 instance->priv->stingers = MVS_STINGERS_NO;
 
-        mvs_watc_movie_set_name (instance, raw_name);
+        if (raw_name[len-1] == ')') {
+                len = len -6;
+
+                gchar *year = g_strndup (raw_name + len +1, 4);
+                mvs_watc_movie_set_year (instance, year);
+                g_free (year);
+        }
+
+        gchar *name = g_strndup (raw_name, len);
 
+        mvs_watc_movie_set_name (instance, name);
+
+        g_free (name);
         return instance;
 }
 
@@ -149,7 +189,7 @@ mvs_watc_movie_set_name (MvsWatcMovie *self, const gchar *name)
 }
 
 gboolean
-mvs_watc_movie_set_stingers (MvsWatcMovie *self, MvsStingers stingers)
+mvs_watc_movie_set_stingers (MvsWatcMovie *self, int stingers)
 {
         g_return_val_if_fail (MVS_IS_WATC_MOVIE (self), FALSE);
         g_return_val_if_fail (stingers == MVS_STINGERS_UNKNOWN ||
@@ -169,7 +209,7 @@ mvs_watc_movie_get_name (MvsWatcMovie *self)
         return self->priv->name;
 }
 
-MvsStingers
+int
 mvs_watc_movie_get_stingers (MvsWatcMovie *self)
 {
         g_return_val_if_fail (MVS_IS_WATC_MOVIE (self), FALSE);
@@ -192,4 +232,22 @@ mvs_watc_movie_print (MvsWatcMovie *self)
 
         g_print ("[Name]: %s\n", self->priv->name);
         g_print ("[Stingers]: %s\n", has_stingers);
+        g_print ("[Year]: %s\n",
+                 self->priv->year ? self->priv->year : " - ");
+}
+
+gboolean
+mvs_watc_movie_set_year (MvsWatcMovie *self, const gchar *year)
+{
+        g_return_val_if_fail (MVS_IS_WATC_MOVIE (self), FALSE);
+
+        g_free (self->priv->year);
+
+        self->priv->year = g_strdup (year);
+}
+
+const gchar*
+mvs_watc_movie_get_year (MvsWatcMovie *self)
+{
+        return self->priv->year;
 }
index 7bf7e3b..940231f 100644 (file)
 
 G_BEGIN_DECLS
 
-typedef enum {
+enum {
         MVS_STINGERS_UNKNOWN,
         MVS_STINGERS_YES,
-        MVS_STINGERS_NO
-} MvsStingers;
+        MVS_STINGERS_NO,
+        MVS_STINGERS_LAST
+};
 
 #define MVS_TYPE_WATC_MOVIE mvs_watc_movie_get_type()
 #define MVS_WATC_MOVIE(obj) \
@@ -55,6 +56,7 @@ typedef struct {
 } MvsWatcMovieClass;
 
 GType mvs_watc_movie_get_type (void);
+
 MvsWatcMovie* mvs_watc_movie_new (const gchar *raw_name);
 
 gboolean
@@ -64,11 +66,17 @@ const gchar*
 mvs_watch_movie_get_name (MvsWatcMovie *self);
 
 gboolean
-mvs_watc_movie_set_stingers (MvsWatcMovie *self, MvsStingers stingers);
+mvs_watc_movie_set_stingers (MvsWatcMovie *self, int stingers);
 
-MvsStingers
+gint
 mvs_watch_movie_get_stingers (MvsWatcMovie *self);
 
+gboolean
+mvs_watc_movie_set_year (MvsWatcMovie *self, const gchar *year);
+
+const gchar*
+mvs_watc_movie_get_year (MvsWatcMovie *self);
+
 void
 mvs_watch_movie_print (MvsWatcMovie *self);