Example #1
0
static VALUE
rbclt_model_iter_is_last (VALUE self)
{
    ClutterModelIter *iter = CLUTTER_MODEL_ITER (RVAL2GOBJ (self));

    return clutter_model_iter_is_last (iter) ? Qtrue : Qfalse;
}
Example #2
0
static VALUE
rbclt_model_iter_dup (VALUE self)
{
    ClutterModelIter *iter = CLUTTER_MODEL_ITER (RVAL2GOBJ (self));

    return GOBJ2RVALU (clutter_model_iter_copy (iter));
}
Example #3
0
static VALUE
rbclt_model_filter_iter (VALUE self, VALUE iter)
{
    return clutter_model_filter_iter (CLUTTER_MODEL (RVAL2GOBJ (self)),
                                      CLUTTER_MODEL_ITER (RVAL2GOBJ (iter)))
           ? Qtrue : Qfalse;
}
Example #4
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;
}
Example #5
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);
}
Example #6
0
static VALUE
rbclt_model_iter_prev (VALUE self)
{
    ClutterModelIter *iter = CLUTTER_MODEL_ITER (RVAL2GOBJ (self));
    ClutterModelIter *iter_copy = clutter_model_iter_copy (iter);

    return rbclt_model_iter_prev_bang (GOBJ2RVALU (iter_copy));
}
Example #7
0
static VALUE
rbclt_model_iter_prev_bang (VALUE self)
{
    ClutterModelIter *iter = CLUTTER_MODEL_ITER (RVAL2GOBJ (self));

    clutter_model_iter_prev (iter);

    return self;
}
Example #8
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);
}
Example #9
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;
}
Example #10
0
static ClutterModelIter *
clutter_list_model_insert_row (ClutterModel *model,
                               gint          index_)
{
  ClutterListModel *model_default = CLUTTER_LIST_MODEL (model);
  GSequence *sequence = model_default->priv->sequence;
  ClutterListModelIter *retval;
  guint n_columns, i, pos;
  GValueArray *array;
  GSequenceIter *seq_iter;

  n_columns = clutter_model_get_n_columns (model);
  array = g_value_array_new (n_columns);

  for (i = 0; i < n_columns; i++)
    {
      GValue *value = NULL;

      g_value_array_append (array, NULL);

      value = g_value_array_get_nth (array, i);
      g_value_init (value, clutter_model_get_column_type (model, i));
    }

  if (index_ < 0)
    {
      seq_iter = g_sequence_append (sequence, array);
      pos = g_sequence_get_length (sequence) - 1;
    }
  else if (index_ == 0)
    {
      seq_iter = g_sequence_prepend (sequence, array);
      pos = 0;
    }
  else
    {
      seq_iter = g_sequence_get_iter_at_pos (sequence, index_);
      seq_iter = g_sequence_insert_before (seq_iter, array);
      pos = index_;
    }

  retval = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER,
                         "model", model,
                         "row", pos,
                         NULL);
  retval->seq_iter = seq_iter;

  return CLUTTER_MODEL_ITER (retval);
}
Example #11
0
static ClutterModelIter *
gmc_video_model_get_iter_at_row (ClutterModel *model,
                                 guint         row)
{
  GmcVideoModelPrivate *priv;
  GmcVideoModelIter *iter;
  gchar *query, *tmp;
  gint column;
  sqlite3_stmt *statement;
  gint error_code;

  priv = GMC_VIDEO_MODEL_GET_PRIVATE (model);

  query = g_strdup_printf ("SELECT Title FROM %s", TABLE);

  column = clutter_model_get_sorting_column (model);
  if (column != -1) {
    tmp = g_strdup_printf ("%s ORDER BY %s", query, clutter_model_get_column_name (model, 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->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->sql));
    return 0;
  }

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

  sqlite3_finalize (statement);

  iter = g_object_new (GMC_TYPE_VIDEO_MODEL_ITER,
                       "model", model,
                       "row", row,
                       NULL);

  return CLUTTER_MODEL_ITER (iter);
}
Example #12
0
static ClutterModelIter *
gmc_video_model_insert_row (ClutterModel *model,
                            gint          index)
{
  GmcVideoModelIter *iter;
  GmcVideoModelPrivate *priv;
  sqlite3_stmt *statement;
  guint n_rows;
  gint error_code;
  gchar *query;

  priv = GMC_VIDEO_MODEL_GET_PRIVATE (model);

  n_rows = clutter_model_get_n_rows (model);

  query = g_strdup_printf ("INSERT INTO %s (Title) VALUES ('_')", TABLE);

  error_code = sqlite3_prepare_v2 (priv->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->sql));
    return 0;
  }
  
  error_code = sqlite3_step (statement);
  if (error_code != SQLITE_DONE) {
    g_critical ("%s [step] : %d - %s", G_STRFUNC, error_code, sqlite3_errmsg (priv->sql));
    return 0;
  }

  sqlite3_finalize (statement);

  iter = g_object_new (GMC_TYPE_VIDEO_MODEL_ITER,
                       "model", model,
                       "row", n_rows,
                       NULL);

  return CLUTTER_MODEL_ITER (iter);
}
Example #13
0
static ClutterModelIter *
clutter_list_model_get_iter_at_row (ClutterModel *model,
                                    guint         row)
{
  ClutterListModel *model_default = CLUTTER_LIST_MODEL (model);
  GSequence *sequence = model_default->priv->sequence;
  gint seq_length = g_sequence_get_length (sequence);
  ClutterListModelIter *retval;

  if (row >= seq_length)
    return NULL;

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

  /* short-circuit in case we don't have a filter in place */
  if (!clutter_model_get_filter_set (model))
    {
      retval->seq_iter = g_sequence_get_iter_at_pos (sequence, row);

      return CLUTTER_MODEL_ITER (retval);
    }

  if (row == 0)
    {
      GSequenceIter *filter_next;
      gboolean row_found = FALSE;

      filter_next = g_sequence_get_begin_iter (sequence);
      g_assert (filter_next != NULL);

      while (!g_sequence_iter_is_end (filter_next))
        {
          retval->seq_iter = filter_next;

          if (clutter_model_filter_iter (model, CLUTTER_MODEL_ITER (retval)))
            {
              /* We've found a row that is valid under the filter */
              row_found = TRUE;
              break;
            }

          filter_next = g_sequence_iter_next (filter_next);
        }

      /* Everything has been filtered -> there is no first row */
      if (!row_found)
        {
          g_object_unref (retval);
          return NULL;
        }
    }
  else
    {
      GSequenceIter *filter_prev;

      filter_prev = g_sequence_get_end_iter (sequence);
      g_assert (filter_prev != NULL);

      filter_prev = g_sequence_iter_prev (filter_prev);

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

          if (clutter_model_filter_iter (model, CLUTTER_MODEL_ITER (retval)))
            break;

          filter_prev = g_sequence_iter_prev (filter_prev);
        }
    }

  return CLUTTER_MODEL_ITER (retval);
}