Пример #1
0
static VALUE
rbclt_model_iter_set (int argc, VALUE *argv, VALUE self)
{
    ClutterModel *model;
    int state = 0;
    GetData data;
    int i;

    if ((argc & 1))
        rb_raise (rb_eArgError, "wrong number of arguments "
                  "(paired arguments required)");

    data.iter = CLUTTER_MODEL_ITER (RVAL2GOBJ (self));
    model = clutter_model_iter_get_model (data.iter);

    for (i = 0; i < argc && state == 0; i += 2)
    {
        data.column = NUM2UINT (argv[i]);
        data.rvalue = argv[i + 1];

        memset (&data.value, 0, sizeof (data.value));

        g_value_init (&data.value, clutter_model_get_column_type (model,
                      data.column));
        rb_protect (rbclt_model_iter_do_set, (VALUE) &data, &state);
        g_value_unset (&data.value);
    }

    if (state)
        rb_jump_tag (state);

    return self;
}
Пример #2
0
static ClutterModelIter *
clutter_list_model_iter_copy (ClutterModelIter *iter)
{
  ClutterListModelIter *iter_default;
  ClutterListModelIter *iter_copy;
  ClutterModel *model;
  guint row;
 
  iter_default = CLUTTER_LIST_MODEL_ITER (iter);

  model = clutter_model_iter_get_model (iter);
  row   = clutter_model_iter_get_row (iter) - 1;

  iter_copy = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER,
                            "model", model,
                            "row", row,
                            NULL);

  /* this is safe, because the seq_iter pointer on the passed
   * iterator will be always be overwritten in ::next or ::prev
   */
  iter_copy->seq_iter = iter_default->seq_iter;

  return CLUTTER_MODEL_ITER (iter_copy);
}
Пример #3
0
static void
gmc_video_model_iter_get_value (ClutterModelIter *iter, 
                                guint             column, 
                                GValue           *value)
{
  ClutterModel *model;
  GmcVideoModelPrivate *priv_model;
  gchar *query, *string_value, *tmp;
  guint row, uint_value, sort_column;
  sqlite3_stmt *statement;
  gint error_code;
  GType type;

  model = clutter_model_iter_get_model (iter);
  row = clutter_model_iter_get_row (iter);
  priv_model = GMC_VIDEO_MODEL_GET_PRIVATE (model);

  query = g_strdup_printf ("SELECT %s FROM %s", clutter_model_get_column_name (model, column), TABLE);

  sort_column = clutter_model_get_sorting_column (model);
  if (sort_column != -1) {
    tmp = g_strdup_printf ("%s ORDER BY %s", query, clutter_model_get_column_name (model, sort_column));
    g_free (query);
    query = tmp;
  }

  tmp = g_strdup_printf ("%s LIMIT %d, 1", query, row);
  g_free (query);
  query = tmp;

  error_code = sqlite3_prepare_v2 (priv_model->sql, query, strlen (query), &statement, NULL);
  g_free (query);
  if (error_code != SQLITE_OK) {
    g_critical ("%s [prepare] : %d - %s", G_STRFUNC, error_code, sqlite3_errmsg (priv_model->sql));
    return;
  }

  error_code = sqlite3_step (statement);
  if (error_code != SQLITE_ROW) {
    g_critical ("%s [step] : %d - %s", G_STRFUNC, error_code, sqlite3_errmsg (priv_model->sql));
    return;
  }

  type = clutter_model_get_column_type (model, column);

  switch (type) {
    case G_TYPE_STRING:
      string_value = (gchar *) sqlite3_column_text (statement, 0);
      g_value_set_string (value, string_value);
      break;

    case G_TYPE_UINT:
      uint_value = sqlite3_column_int (statement, 0);
      g_value_set_uint (value, uint_value);
      break;
  }

  sqlite3_finalize (statement);
}
Пример #4
0
static void
gmc_video_model_iter_set_value (ClutterModelIter *iter, 
                                guint             column, 
                                const GValue     *value)
{
  ClutterModel *model;
  GmcVideoModelPrivate *priv_model;
  const gchar *name;
  gchar *query, *str_value;
  sqlite3_stmt *statement;
  gint error_code;
  GType type;
  GValue title_value = {0, };

  model = clutter_model_iter_get_model (iter);
  priv_model = GMC_VIDEO_MODEL_GET_PRIVATE (model);

  name = clutter_model_get_column_name (model, column);
  type = clutter_model_get_column_type (model, column);

  switch (type) {
    case G_TYPE_STRING:
      str_value = g_strdup (g_value_get_string (value));
      break;
 
    case G_TYPE_UINT:
      str_value = g_strdup_printf ("%u", g_value_get_uint (value));
      break;

    default:
      g_warning ("%s : Invalid type", G_STRFUNC);
      break;
  }

  clutter_model_iter_get_value (iter, 0, &title_value);
  query = g_strdup_printf ("UPDATE %s SET %s = '%s' WHERE Title = '%s'", TABLE, name, str_value, g_value_get_string (&title_value));

  error_code = sqlite3_prepare_v2 (priv_model->sql, query, strlen (query), &statement, NULL);
  g_free (query);
  if (error_code != SQLITE_OK) {
    g_critical ("%s [prepare] : %d - %s", G_STRFUNC, error_code, sqlite3_errmsg (priv_model->sql));
    return;
  }

  error_code = sqlite3_step (statement);
  if (error_code != SQLITE_DONE) {
    g_critical ("%s [step] : %d - %s", G_STRFUNC, error_code, sqlite3_errmsg (priv_model->sql));
    return;
  }

  sqlite3_finalize (statement);
}
Пример #5
0
static VALUE
rbclt_model_iter_get (int argc, VALUE *argv, VALUE self)
{
    ClutterModel *model;
    int state = 0;
    VALUE ret = Qnil;
    GetData data;

    data.iter = CLUTTER_MODEL_ITER (RVAL2GOBJ (self));
    model = clutter_model_iter_get_model (data.iter);

    if (argc == 1)
    {
        data.column = NUM2UINT (argv[0]);

        memset (&data.value, 0, sizeof (data.value));

        rb_protect (rbclt_model_iter_do_get, (VALUE) &data, &state);
        g_value_unset (&data.value);

        if (state == 0)
            ret = data.rvalue;
    }
    else
    {
        int i;

        ret = rb_ary_new ();

        for (i = 0; i < argc; i++)
        {
            data.column = NUM2UINT (argv[i]);

            memset (&data.value, 0, sizeof (data.value));

            rb_protect (rbclt_model_iter_do_get, (VALUE) &data, &state);
            g_value_unset (&data.value);

            if (state)
                break;

            rb_ary_push (ret, data.rvalue);
        }
    }

    if (state)
        rb_jump_tag (state);

    return ret;
}
Пример #6
0
static gboolean
clutter_list_model_iter_is_last (ClutterModelIter *iter)
{
  ClutterListModelIter *iter_default;
  ClutterModelIter *temp_iter;
  ClutterModel *model;
  GSequence *sequence;
  GSequenceIter *begin, *end;

  iter_default = CLUTTER_LIST_MODEL_ITER (iter);
  g_assert (iter_default->seq_iter != NULL);

  if (g_sequence_iter_is_end (iter_default->seq_iter))
    return TRUE;

  model = clutter_model_iter_get_model (iter);

  sequence = CLUTTER_LIST_MODEL (model)->priv->sequence;

  begin = g_sequence_get_end_iter (sequence);
  begin = g_sequence_iter_prev (begin);
  end   = iter_default->seq_iter;

  temp_iter = CLUTTER_LIST_MODEL (model)->priv->temp_iter;

  while (!g_sequence_iter_is_begin (begin))
    {
      CLUTTER_LIST_MODEL_ITER (temp_iter)->seq_iter = begin;

      if (clutter_model_filter_iter (model, temp_iter))
        {
          end = begin;
          break;
        }

      begin = g_sequence_iter_prev (begin);
    }

  /* This is because the 'end_iter' is always *after* the last valid iter.
   * Otherwise we'd have endless loops 
   */
  end = g_sequence_iter_next (end);

  return iter_default->seq_iter == end;
}
Пример #7
0
static ClutterModelIter *
clutter_list_model_iter_prev (ClutterModelIter *iter)
{
  ClutterListModelIter *iter_default;
  ClutterModelIter *temp_iter;
  ClutterModel *model;
  GSequenceIter *filter_prev;
  guint row;

  iter_default = CLUTTER_LIST_MODEL_ITER (iter);
  g_assert (iter_default->seq_iter != NULL);

  model = clutter_model_iter_get_model (iter);
  row   = clutter_model_iter_get_row (iter);

  filter_prev = g_sequence_iter_prev (iter_default->seq_iter);
  g_assert (filter_prev != NULL);

  temp_iter = CLUTTER_LIST_MODEL (model)->priv->temp_iter;

  while (!g_sequence_iter_is_begin (filter_prev))
    {
      CLUTTER_LIST_MODEL_ITER (temp_iter)->seq_iter = filter_prev;

      if (clutter_model_filter_iter (model, temp_iter))
        {
          row -= 1;
          break;
        }

      filter_prev = g_sequence_iter_prev (filter_prev);
    }

  if (g_sequence_iter_is_begin (filter_prev))
    row -= 1;

  /* update the iterator and return it */
  clutter_model_iter_set_row (CLUTTER_MODEL_ITER (iter_default), row);
  iter_default->seq_iter = filter_prev;

  return CLUTTER_MODEL_ITER (iter_default);
}
Пример #8
0
static void
print_iter (ClutterModelIter *iter,
            const gchar      *text)
{
  ClutterModel *model;
  gint i;
  gchar *string;

  model = clutter_model_iter_get_model (iter);

  clutter_model_iter_get (iter, COLUMN_FOO, &i, COLUMN_BAR, &string, -1);

  g_print ("[row:%02d]: %s: (%s: %d), (%s: %s)\n",
           clutter_model_iter_get_row (iter),
           text,
           clutter_model_get_column_name (model, COLUMN_FOO), i,
           clutter_model_get_column_name (model, COLUMN_BAR), string);

  g_free (string);
}
Пример #9
0
static ClutterModelIter *
gmc_video_model_iter_next (ClutterModelIter *iter)
{
  ClutterModel *model;
  guint row, n_rows;

  model = clutter_model_iter_get_model (iter);
  row = clutter_model_iter_get_row (iter);
  n_rows = clutter_model_get_n_rows (model);

  g_object_unref (iter);

  if (row == (n_rows - 1)) {
    return NULL;
  }
  iter = g_object_new (GMC_TYPE_VIDEO_MODEL_ITER,
                       "model", model,
                       "row", row + 1,
                       NULL);
  return iter;
}