コード例 #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);
}
コード例 #2
0
static void
startMovingNextTorrent( struct relocate_dialog_data * data )
{
    char * str;
    const int id = GPOINTER_TO_INT( data->torrent_ids->data );

    tr_torrent * tor = gtr_core_find_torrent( data->core, id );
    if( tor != NULL )
        tr_torrentSetLocation( tor, previousLocation, data->do_move, NULL, &data->done );

    data->torrent_ids = g_slist_delete_link( data->torrent_ids,
                                             data->torrent_ids );

    str = g_strdup_printf( _( "Moving \"%s\"" ), tr_torrentName( tor ) );
    gtk_message_dialog_set_markup( GTK_MESSAGE_DIALOG( data->message_dialog ), str );
    g_free( str );
}
コード例 #3
0
ファイル: dialogs.c プロジェクト: Cleiton-Floss/transmission
void
gtr_confirm_remove (GtkWindow  * parent,
                    TrCore     * core,
                    GSList     * torrent_ids,
                    gboolean     delete_files)
{
    GSList * l;
    GtkWidget * d;
    GString * primary_text;
    GString * secondary_text;
    struct delete_data * dd;
    int connected = 0;
    int incomplete = 0;
    const int count = g_slist_length (torrent_ids);

    if (!count)
        return;

    dd = g_new0 (struct delete_data, 1);
    dd->core = core;
    dd->torrent_ids = torrent_ids;
    dd->delete_files = delete_files;

    for (l=torrent_ids; l!=NULL; l=l->next)
    {
        const int id = GPOINTER_TO_INT (l->data);
        tr_torrent * tor = gtr_core_find_torrent (core, id);
        const tr_stat * stat = tr_torrentStat (tor);
        if (stat->leftUntilDone) ++incomplete;
        if (stat->peersConnected) ++connected;
    }

    primary_text = g_string_new (NULL);

    if (!delete_files)
    {
        g_string_printf (primary_text, ngettext ("Remove torrent?",
                                                 "Remove %d torrents?",
                                                 count), count);
    }
    else
    {
        g_string_printf (primary_text, ngettext ("Delete this torrent's downloaded files?",
                                                 "Delete these %d torrents' downloaded files?",
                                                 count), count);
    }

    secondary_text = g_string_new (NULL);

    if (!incomplete && !connected)
    {
        g_string_assign (secondary_text, ngettext (
                "Once removed, continuing the transfer will require the torrent file or magnet link.",
                "Once removed, continuing the transfers will require the torrent files or magnet links.",
                count));
    }
    else if (count == incomplete)
    {
        g_string_assign (secondary_text, ngettext ("This torrent has not finished downloading.",
                                                   "These torrents have not finished downloading.",
                                                   count));
    }
    else if (count == connected)
    {
        g_string_assign (secondary_text, ngettext ("This torrent is connected to peers.",
                                                   "These torrents are connected to peers.",
                                                   count));
    }
    else
    {
        if (connected)
            g_string_append (secondary_text, ngettext ("One of these torrents is connected to peers.",
                                                       "Some of these torrents are connected to peers.",
                                                       connected));
        if (connected && incomplete)
            g_string_append (secondary_text, "\n");

        if (incomplete)
            g_string_assign (secondary_text, ngettext ("One of these torrents has not finished downloading.",
                                                       "Some of these torrents have not finished downloading.",
                                                       incomplete));
    }

    d = gtk_message_dialog_new_with_markup (parent,
                                            GTK_DIALOG_DESTROY_WITH_PARENT,
                                            GTK_MESSAGE_QUESTION,
                                            GTK_BUTTONS_NONE,
                                            "<big><b>%s</b></big>",
                                            primary_text->str);
    if (secondary_text->len)
        gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (d),
                                                    "%s", secondary_text->str);
    gtk_dialog_add_buttons (GTK_DIALOG (d),
                            _("_Cancel"), GTK_RESPONSE_CANCEL,
                          (delete_files ? _("_Delete") :
                              _("_Remove")), GTK_RESPONSE_ACCEPT,
                            NULL);
    gtk_dialog_set_default_response (GTK_DIALOG (d),
                                     GTK_RESPONSE_CANCEL);
    gtk_dialog_set_alternative_button_order (GTK_DIALOG (d),
                                             GTK_RESPONSE_ACCEPT,
                                             GTK_RESPONSE_CANCEL,
                                             -1);
    g_signal_connect (d, "response", G_CALLBACK (on_remove_dialog_response), dd);
    gtk_widget_show_all (d);

    g_string_free (primary_text, TRUE);
    g_string_free (secondary_text, TRUE);
}