Example #1
0
static gboolean
spun_cb_idle (gpointer spin)
{
    gboolean keep_waiting = TRUE;
    GObject * o = G_OBJECT (spin);
    struct spin_idle_data * data = g_object_get_data (o, IDLE_DATA);

    /* has the user stopped making changes? */
    if (g_timer_elapsed (data->last_change, NULL) > 0.33f)
    {
        /* update the core */
        const tr_quark key = GPOINTER_TO_INT (g_object_get_data (o, PREF_KEY));

        if (data->isDouble)
        {
            const double value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin));
            gtr_core_set_pref_double (TR_CORE (data->core), key, value);
        }
        else
        {
            const int value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin));
            gtr_core_set_pref_int (TR_CORE (data->core), key, value);
        }

        /* cleanup */
        g_object_set_data (o, IDLE_DATA, NULL);
        keep_waiting = FALSE;
        g_object_unref (G_OBJECT (o));
    }

    return keep_waiting;
}
Example #2
0
static void
toggled_cb (GtkToggleButton * w,
            gpointer          core)
{
    const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (w), PREF_KEY));
    const gboolean flag = gtk_toggle_button_get_active (w);

    gtr_core_set_pref_bool (TR_CORE (core), key, flag);
}
Example #3
0
static void
toggled_cb( GtkToggleButton * w,
            gpointer          core )
{
    const char *   key = g_object_get_data( G_OBJECT( w ), PREF_KEY );
    const gboolean flag = gtk_toggle_button_get_active( w );

    tr_core_set_pref_bool( TR_CORE( core ), key, flag );
}
Example #4
0
static void
core_finalize (GObject * o)
{
  TrCore * core = TR_CORE (o);

  g_string_chunk_free (core->priv->string_chunk);

  G_OBJECT_CLASS (tr_core_parent_class)->finalize (o);
}
Example #5
0
static void
core_dispose (GObject * o)
{
  TrCore * core = TR_CORE (o);

  if (core->priv->sorted_model != NULL)
    {
      g_object_unref (core->priv->sorted_model);
      core->priv->sorted_model = NULL;
      core->priv->raw_model = NULL;
    }

  G_OBJECT_CLASS (tr_core_parent_class)->dispose (o);
}
Example #6
0
static void
tr_core_dispose( GObject * obj )
{
    TrCore * core = TR_CORE( obj );

    if( !isDisposed( core ) )
    {
        GObjectClass * parent;

        core->priv = NULL;

        parent = g_type_class_peek( g_type_parent( TR_CORE_TYPE ) );
        parent->dispose( obj );
    }
}
Example #7
0
static gboolean
core_watchdir_idle (gpointer gcore)
{
  GSList * l;
  GSList * changing = NULL;
  GSList * unchanging = NULL;
  TrCore * core = TR_CORE (gcore);
  const time_t now = tr_time ();
  struct TrCorePrivate * p = core->priv;

  /* separate the files into two lists: changing and unchanging */
  for (l=p->monitor_files; l!=NULL; l=l->next)
    {
      GFile * file = l->data;
      const time_t mtime = get_file_mtime (file);
      if (mtime + 2 >= now)
        changing = g_slist_prepend (changing, file);
      else
        unchanging = g_slist_prepend (unchanging, file);
    }

  /* add the files that have stopped changing */
  if (unchanging != NULL)
    {
      const gboolean do_start = gtr_pref_flag_get (TR_KEY_start_added_torrents);
      const gboolean do_prompt = gtr_pref_flag_get (TR_KEY_show_options_window);

      core->priv->adding_from_watch_dir = TRUE;
      gtr_core_add_files (core, unchanging, do_start, do_prompt, TRUE);
      g_slist_foreach (unchanging, (GFunc)rename_torrent_and_unref_file, NULL);
      g_slist_free (unchanging);
      core->priv->adding_from_watch_dir = FALSE;
    }

  /* keep monitoring the ones that are still changing */
  g_slist_free (p->monitor_files);
  p->monitor_files = changing;

  /* if monitor_files is nonempty, keep checking every second */
  if (core->priv->monitor_files)
    return G_SOURCE_CONTINUE;
  core->priv->monitor_idle_tag = 0;
  return G_SOURCE_REMOVE;
}
Example #8
0
static gboolean
watchFolderIdle( gpointer gcore )
{
    GSList * l;
    GSList * addme = NULL;
    GSList * monitor_files = NULL;
    TrCore * core = TR_CORE( gcore );
    const time_t now = time( NULL );
    struct TrCorePrivate * p = core->priv;

    /* of the monitor_files, make a list of those that haven't
     * changed lately, since they should be ready to add */
    for( l=p->monitor_files; l!=NULL; l=l->next ) {
        struct watchdir_file * f = l->data;
        watchdir_file_update_mtime( f );
        if( f->mtime + 2 >= now )
            monitor_files = g_slist_prepend( monitor_files, f );
        else {
            addme = g_slist_prepend( addme, g_strdup( f->filename ) );
            watchdir_file_free( f );
        }
    }

    /* add the torrents from that list */
    core->priv->adding_from_watch_dir = TRUE;
    tr_core_add_list_defaults( core, addme, TRUE );
    core->priv->adding_from_watch_dir = FALSE;

    /* update the monitor_files list */
    g_slist_free( p->monitor_files );
    p->monitor_files = monitor_files;

    /* if monitor_files is nonempty, keep checking every second */
    if( core->priv->monitor_files )
        return TRUE;
    core->priv->monitor_idle_tag = 0;
    return FALSE;

}