Changeset 4180


Ignore:
Timestamp:
Dec 15, 2007, 10:24:16 PM (15 years ago)
Author:
charles
Message:

add a port tester to the gtk+ client, similar to the one in the mac client, but using m0k.org/PortCheck.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr_prefs.c

    r4159 r4180  
    1313#include <glib/gi18n.h>
    1414#include <gtk/gtk.h>
     15#include <third-party/miniupnp/miniwget.h>
    1516#include <libtransmission/transmission.h>
    1617#include "conf.h"
     
    204205}
    205206
     207static gpointer
     208test_port( gpointer l )
     209{
     210    GObject * o = G_OBJECT( l );
     211    GtkSpinButton * spin = GTK_SPIN_BUTTON( g_object_get_data( o, "tr-port-spin" ) );
     212
     213    const int port = gtk_spin_button_get_value_as_int( spin );
     214    int isOpen;
     215    int size;
     216    char * text;
     217    char url[256];
     218
     219    g_usleep( G_USEC_PER_SEC * 3 ); /* give portmapping time to kick in */
     220    snprintf( url, sizeof(url), "http://transmission.m0k.org/PortCheck.php?port=%d", port );
     221    text = miniwget( url, &size );
     222    g_message(" got len %d, [%*.*s]", size, size, size, text );
     223    isOpen = text && *text=='1';
     224    gtk_label_set_markup( GTK_LABEL(l), isOpen ? _("Port is <b>open</b>") : _("Port is <b>closed</b>") );
     225
     226    return NULL;
     227}
     228
     229static void
     230testing_port_cb( GtkWidget * unused UNUSED, gpointer l )
     231{
     232    gtk_label_set_markup( GTK_LABEL(l), _( "<i>Testing port...</i>" ) );
     233    g_thread_create( test_port, l, FALSE, NULL );
     234}
     235
    206236GtkWidget *
    207237tr_prefs_dialog_new( GObject * core, GtkWindow * parent )
     
    212242    GtkWidget * w, * w2;
    213243    GtkWidget * l;
     244    GtkWidget * h;
    214245    GtkWidget * d;
     246    GtkTooltips * tips;
     247
     248    tips = gtk_tooltips_new( );
    215249
    216250    d = gtk_dialog_new_with_buttons( _("Preferences"), parent,
     
    264298    hig_workarea_add_section_spacer (t, row, 2);
    265299       
    266         s = _("_Automatic Port Mapping via NAT-PMP or UPnP");
     300        s = _("_Automatically map port" );
    267301        w = new_check_button( s, PREF_KEY_NAT, core );
    268302        hig_workarea_add_wide_control( t, &row, w );
    269 
    270         w = new_spin_button( PREF_KEY_PORT, core, 1, INT_MAX );
    271         l = hig_workarea_add_row( t, &row, _("Listening _Port"), w, NULL );
     303        gtk_tooltips_set_tip( GTK_TOOLTIPS( tips ), w, _( "NAT traversal uses either NAT-PMP or UPnP" ), NULL );
     304
     305        h = gtk_hbox_new( FALSE, GUI_PAD );
     306        w2 = new_spin_button( PREF_KEY_PORT, core, 1, INT_MAX );
     307        gtk_box_pack_start( GTK_BOX(h), w2, FALSE, FALSE, 0 );
     308        l = gtk_label_new( NULL );
     309        gtk_misc_set_alignment( GTK_MISC(l), 0.0f, 0.5f );
     310        gtk_box_pack_start( GTK_BOX(h), l, FALSE, FALSE, 0 );
     311        hig_workarea_add_row( t, &row, _("Incoming TCP _Port"), h, w );
     312
     313        g_object_set_data( G_OBJECT(l), "tr-port-spin", w2 );
     314        g_object_set_data( G_OBJECT(l), "tr-core", core );
     315        testing_port_cb( NULL, l );
     316
     317        g_signal_connect( w, "toggled", G_CALLBACK(toggled_cb), l );
     318        g_signal_connect( w2, "value-changed", G_CALLBACK(testing_port_cb), l );
    272319
    273320    hig_workarea_add_section_divider( t, &row );
Note: See TracChangeset for help on using the changeset viewer.