~haowenl/vorg

be25739dcdcd4cead7f4f6925d0670bf674ad5c5 — Haowen Liu a month ago 7e7a49e
Video new title property
6 files changed, 51 insertions(+), 11 deletions(-)

M src/vorg-browse.c
M src/vorg-db.c
M src/vorg-db.h
M src/vorg-repo.c
M src/vorg-video.c
M src/vorg-video.h
M src/vorg-browse.c => src/vorg-browse.c +2 -1
@@ 120,7 120,8 @@ vorg_browse_widget_from_video (GObject *item,
  GtkWidget *box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
  gtk_box_append (GTK_BOX (box), GTK_WIDGET (gtk_picture_new_for_filename (
                                     vorg_video_get_thumbnail (video))));

  gtk_box_append (GTK_BOX (box),
                  GTK_WIDGET (gtk_label_new (vorg_video_get_title (video))));
  return box;
}


M src/vorg-db.c => src/vorg-db.c +6 -4
@@ 505,20 505,22 @@ vorg_db_import_file (VorgDB *self, const gchar *sha, const gchar *title,
GtkListStore *
vorg_db_get_videos (VorgDB *self)
{
  GtkListStore *store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
  const gchar *sql = "SELECT hash, ext FROM items";
  GtkListStore *store
      = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
  const gchar *sql = "SELECT hash,ext,title FROM items";
  sqlite3_stmt *stmt;
  gint rc = sqlite3_prepare (self->db, sql, 30, &stmt, NULL);
  gint rc = sqlite3_prepare (self->db, sql, 33, &stmt, NULL);
  SQLITE3_CHECK_ERROR (rc, "Prepare get videos")
  rc = sqlite3_step (stmt);
  while (rc == SQLITE_ROW)
    {
      const gchar *sha = (gchar *)sqlite3_column_text (stmt, 0);
      const gchar *ext = (gchar *)sqlite3_column_text (stmt, 1);
      const gchar *title = (gchar *)sqlite3_column_text (stmt, 2);
      GtkTreeIter iter;
      gtk_list_store_append (store, &iter);
      gtk_list_store_set (store, &iter, VORG_DB_COL_SHA, sha, VORG_DB_COL_EXT,
                          ext, -1);
                          ext, VORG_DB_COL_TITLE, title, -1);
      rc = sqlite3_step (stmt);
    }
  return store;

M src/vorg-db.h => src/vorg-db.h +1 -0
@@ 43,6 43,7 @@ enum
{
  VORG_DB_COL_SHA,
  VORG_DB_COL_EXT,
  VORG_DB_COL_TITLE,
  VORG_DB_NUM_COLS,
};


M src/vorg-repo.c => src/vorg-repo.c +4 -2
@@ 322,12 322,14 @@ vorg_repo_get_videos (VorgRepo *self)
    {
      g_autofree gchar *sha = NULL;
      g_autofree gchar *ext = NULL;
      g_autofree gchar *title = NULL;
      gtk_tree_model_get (db_result, &iter, VORG_DB_COL_SHA, &sha,
                          VORG_DB_COL_EXT, &ext, -1);
                          VORG_DB_COL_EXT, &ext, VORG_DB_COL_TITLE, &title,
                          -1);
      g_autofree gchar *path
          = vorg_store_get_path_from_sha (self->store, sha, ext);
      g_autofree gchar *thumbnail = vorg_store_get_thumbnail_from_sha (sha);
      g_autoptr (VorgVideo) video = vorg_video_new (path, thumbnail);
      g_autoptr (VorgVideo) video = vorg_video_new (path, title, thumbnail);
      g_list_store_append (result, video);
    }
  while (gtk_tree_model_iter_next (db_result, &iter));

M src/vorg-video.c => src/vorg-video.c +34 -3
@@ 23,6 23,7 @@ struct _VorgVideo
  GObject parent_instance;

  gchar *path;
  gchar *title;
  gchar *thumbnail;
};



@@ 30,6 31,7 @@ enum
{
  PROP_0,
  PROP_PATH,
  PROP_TITLE,
  PROP_THUMBNAIL,
  NUM_PROPERTIES,
};


@@ 43,15 45,16 @@ G_DEFINE_TYPE (VorgVideo, vorg_video, G_TYPE_OBJECT)
/**
 * vorg_video_new: 
 * @path: Path of the video.
 * @title: Title of the video.
 * @thumbnail: Path of the video thumbnail.
 * 
 * Returns: The created `VorgVideo`. 
 */
VorgVideo *
vorg_video_new (const gchar *path, const gchar *thumbnail)
vorg_video_new (const gchar *path, const gchar *title, const gchar *thumbnail)
{
  return g_object_new (VORG_TYPE_VIDEO, "path", path, "thumbnail", thumbnail,
                       NULL);
  return g_object_new (VORG_TYPE_VIDEO, "path", path, "title", title,
                       "thumbnail", thumbnail, NULL);
}

static void


@@ 59,6 62,7 @@ vorg_video_init (VorgVideo *self)
{
  self->path = NULL;
  self->thumbnail = NULL;
  self->title = NULL;
}

static void


@@ 82,6 86,9 @@ vorg_video_get_property (GObject *object, guint prop_id, GValue *value,
    case PROP_PATH:
      g_value_set_string (value, vorg_video_get_path (self));
      break;
    case PROP_TITLE:
      g_value_set_string (value, vorg_video_get_title (self));
      break;
    case PROP_THUMBNAIL:
      g_value_set_string (value, vorg_video_get_thumbnail (self));
      break;


@@ 102,6 109,9 @@ vorg_video_set_property (GObject *object, guint prop_id, const GValue *value,
    case PROP_PATH:
      self->path = g_strdup (g_value_get_string (value));
      break;
    case PROP_TITLE:
      self->title = g_strdup (g_value_get_string (value));
      break;
    case PROP_THUMBNAIL:
      self->thumbnail = g_strdup (g_value_get_string (value));
      break;


@@ 129,6 139,14 @@ vorg_video_class_init (VorgVideoClass *klass)
      "path", NULL, NULL, "", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);

  /**
   * VorgVideo:title: (attributes org.gtk.Property.get=vorg_video_get_title)
   * 
   * Title of the video file.
   */
  video_props[PROP_TITLE] = g_param_spec_string (
      "title", NULL, NULL, "", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);

  /**
   * VorgVideo:thumbnail: (attributes org.gtk.Property.get=vorg_video_get_thumbnail)
   * 
   * Path to the thumbnail image.


@@ 154,6 172,19 @@ vorg_video_get_path (VorgVideo *self)
}

/**
 * vorg_video_get_title: (attributes org.gtk.Method.get_property=title)
 * 
 * Gets video title.
 * 
 * Returns: (transfer full): The video title.
 */
const gchar *
vorg_video_get_title (VorgVideo *self)
{
  return self->title;
}

/**
 * vorg_video_get_thumbnail: (attributes org.gtk.Method.get_property=thumbnail) 
 * 
 * Gets thumbnail path.

M src/vorg-video.h => src/vorg-video.h +4 -1
@@ 24,8 24,11 @@

G_DECLARE_FINAL_TYPE (VorgVideo, vorg_video, VORG, VIDEO, GObject)

VorgVideo *vorg_video_new (const gchar *path, const gchar *thumbnail);
VorgVideo *vorg_video_new (const gchar *path, const gchar *title,
                           const gchar *thumbnail);

const gchar *vorg_video_get_path (VorgVideo *self);

const gchar *vorg_video_get_title (VorgVideo *self);

const gchar *vorg_video_get_thumbnail (VorgVideo *self);