Changeset 6301


Ignore:
Timestamp:
Jul 8, 2008, 9:08:20 PM (13 years ago)
Author:
charles
Message:

(gtk) partial fix for #562: No error message when opening broken torrent file

Location:
trunk/gtk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/add-dialog.c

    r6278 r6301  
    161161        if(( torrent = tr_torrentNew( handle, data->ctor, &err )))
    162162            data->gtor = tr_torrent_new_preexisting( torrent );
     163        else
     164            addTorrentErrorDialog( GTK_WIDGET(b), err, data->filename );
    163165    }
    164166
  • trunk/gtk/tr-core.c

    r6288 r6301  
    770770    if( filename && handle )
    771771    {
     772        int err;
    772773        tr_ctor * ctor = tr_ctorNew( handle );
    773774        tr_core_apply_defaults( ctor );
    774775        tr_ctorSetPaused( ctor, TR_FORCE, !doStart );
    775         if( tr_ctorSetMetainfoFromFile( ctor, filename ) )
     776        if( tr_ctorSetMetainfoFromFile( ctor, filename ) ) {
     777            addTorrentErrorDialog( NULL, TR_EINVALID, filename );
    776778            tr_ctorFree( ctor );
    777         else if( tr_torrentParse( handle, ctor, NULL ) )
     779        } else if(( err = tr_torrentParse( handle, ctor, NULL ))) {
     780            addTorrentErrorDialog( NULL, err, filename );
    778781            tr_ctorFree( ctor );
    779         else if( doPrompt )
     782        } else if( doPrompt )
    780783            g_signal_emit( core, TR_CORE_GET_CLASS(core)->promptsig, 0, ctor );
    781784        else
  • trunk/gtk/util.c

    r6277 r6301  
    303303
    304304void
     305addTorrentErrorDialog( GtkWidget * child, int err, const char * filename )
     306{
     307    GtkWidget * w;
     308    GtkWidget * win;
     309    const char * fmt;
     310    char * secondary;
     311    switch( err ) {
     312        case TR_EINVALID: fmt = _( "The torrent file \"%s\" contains invalid data." ); break;
     313        case TR_EDUPLICATE: fmt = _( "The torrent file \"%s\" is already in use." ); break;
     314        default: fmt = _( "The torrent file \"%s\" encountered an unknown error." ); break;
     315    }
     316    secondary = g_strdup_printf( fmt, filename );
     317    win = ( !child || GTK_IS_WINDOW( child ) )
     318        ? child
     319        : gtk_widget_get_ancestor( child ? GTK_WIDGET( child ) : NULL, GTK_TYPE_WINDOW );
     320    w = gtk_message_dialog_new( GTK_WINDOW( win ),
     321                                GTK_DIALOG_DESTROY_WITH_PARENT,
     322                                GTK_MESSAGE_ERROR,
     323                                GTK_BUTTONS_CLOSE,
     324                                _( "Error opening torrent" ) );
     325    gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( w ), secondary );
     326    g_signal_connect_swapped( w, "response",
     327                              G_CALLBACK( gtk_widget_destroy ), w );
     328    gtk_widget_show_all( w );
     329    g_free( secondary );
     330}
     331
     332void
    305333errmsg( GtkWindow * wind, const char * format, ... )
    306334{
  • trunk/gtk/util.h

    r6203 r6301  
    8989                                      const char * mnemonic );
    9090
     91void addTorrentErrorDialog( GtkWidget  * window_or_child,
     92                            int          err,
     93                            const char * filename );
     94
    9195/* create an error dialog, if wind is NULL or mapped then show dialog now,
    9296   otherwise show it when wind becomes mapped */
Note: See TracChangeset for help on using the changeset viewer.