Example #1
0
/**
 * When the source .torrent file is deleted
 * (such as, if it was a temp file that a web browser passed to us),
 * gtk invokes this callback and `filename' will be NULL.
 * The `filename' tests here are to prevent us from losing the current
 * metadata when that happens.
 */
static void
sourceChanged (GtkFileChooserButton * b, gpointer gdata)
{
  struct OpenData * o = gdata;
  char * filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (b));

  /* maybe instantiate a torrent */
  if (filename || !o->tor)
    {
      int err = 0;
      int new_file = 0;
      int duplicate_id = 0;
      tr_torrent * torrent;

      if (filename && (!o->filename || !tr_is_same_file (filename, o->filename)))
        {
          g_free (o->filename);
          o->filename = g_strdup (filename);
          tr_ctorSetMetainfoFromFile (o->ctor, o->filename);
          new_file = 1;
        }

      tr_ctorSetDownloadDir (o->ctor, TR_FORCE, o->downloadDir);
      tr_ctorSetPaused (o->ctor, TR_FORCE, TRUE);
      tr_ctorSetDeleteSource (o->ctor, FALSE);

      if ((torrent = tr_torrentNew (o->ctor, &err, &duplicate_id)))
        {
          removeOldTorrent (o);
          o->tor = torrent;
        }
      else if (new_file)
        {
          tr_torrent * tor;

          if (duplicate_id)
            tor = gtr_core_find_torrent (o->core, duplicate_id);
          else
            tor = NULL;

          gtr_add_torrent_error_dialog (GTK_WIDGET (b), err, tor, o->filename);
        }

      updateTorrent (o);
    }

  g_free (filename);
}
Example #2
0
static void
tr_core_apply_defaults( tr_ctor * ctor )
{
    if( tr_ctorGetPaused( ctor, TR_FORCE, NULL ) )
        tr_ctorSetPaused( ctor, TR_FORCE, !gtr_pref_flag_get( TR_PREFS_KEY_START ) );

    if( tr_ctorGetDeleteSource( ctor, NULL ) )
        tr_ctorSetDeleteSource( ctor,
                               gtr_pref_flag_get( TR_PREFS_KEY_TRASH_ORIGINAL ) );

    if( tr_ctorGetPeerLimit( ctor, TR_FORCE, NULL ) )
        tr_ctorSetPeerLimit( ctor, TR_FORCE,
                             gtr_pref_int_get( TR_PREFS_KEY_PEER_LIMIT_TORRENT ) );

    if( tr_ctorGetDownloadDir( ctor, TR_FORCE, NULL ) )
    {
        const char * path = gtr_pref_string_get( TR_PREFS_KEY_DOWNLOAD_DIR );
        tr_ctorSetDownloadDir( ctor, TR_FORCE, path );
    }
}
Example #3
0
/**
 * When the source .torrent file is deleted
 * (such as, if it was a temp file that a web browser passed to us),
 * gtk invokes this callback and `filename' will be NULL.
 * The `filename' tests here are to prevent us from losing the current
 * metadata when that happens.
 */
static void
sourceChanged( GtkFileChooserButton * b, gpointer gdata )
{
    struct OpenData * data = gdata;
    char * filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( b ) );

    /* maybe instantiate a torrent */
    if( filename || !data->gtor )
    {
        int err = 0;
        int new_file = 0;
        tr_torrent * torrent;

        if( filename && ( !data->filename || !tr_is_same_file( filename, data->filename ) ) )
        {
            g_free( data->filename );
            data->filename = g_strdup( filename );
            tr_ctorSetMetainfoFromFile( data->ctor, data->filename );
            new_file = 1;
        }

        tr_ctorSetDownloadDir( data->ctor, TR_FORCE, data->downloadDir );
        tr_ctorSetPaused( data->ctor, TR_FORCE, TRUE );
        tr_ctorSetDeleteSource( data->ctor, FALSE );

        if( ( torrent = tr_torrentNew( data->ctor, &err ) ) )
        {
            removeOldTorrent( data );
            data->gtor = tr_torrent_new_preexisting( torrent );
        }
        else if( new_file )
        {
            gtr_add_torrent_error_dialog( GTK_WIDGET( b ), err, data->filename );
        }

        updateTorrent( data );
    }

    g_free( filename );
}