Changeset 920 for trunk/gtk


Ignore:
Timestamp:
Sep 25, 2006, 6:37:45 PM (15 years ago)
Author:
joshe
Message:

Merge nat-traversal branch to trunk.

Location:
trunk/gtk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/conf.c

    r760 r920  
    359359  GError *err;
    360360  char *datastr;
    361   size_t len;
     361  int len;
    362362  gsize written;
    363363
  • trunk/gtk/conf.h

    r804 r920  
    6060#define PREF_ADDIPC             "add-behavior-ipc"
    6161#define PREF_MSGLEVEL           "message-level"
     62#define PREF_NAT                "use-nat-traversal"
    6263
    6364#endif /* TG_CONF_H */
  • trunk/gtk/dialogs.c

    r804 r920  
    4242#define DEF_UPLIMIT             20
    4343#define DEF_USEUPLIMIT          TRUE
     44#define DEF_NAT                 TRUE
    4445
    4546struct prefdata {
     
    171172   GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    172173   GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
    173   const unsigned int rowcount = 8;
     174  const unsigned int rowcount = 9;
    174175  GtkWidget *table = gtk_table_new(rowcount, 2, FALSE);
    175176  GtkWidget *portnum = gtk_spin_button_new_with_range(1, 0xffff, 1);
     177  GtkWidget *natcheck = gtk_check_button_new_with_mnemonic(
     178    _("Use NAT _Traversal (NAT-PMP and UPnP)"));
    176179  GtkWidget *dirstr = gtk_file_chooser_button_new(
    177180    _("Choose a download directory"),
     
    197200  GtkTreeIter iter;
    198201  GtkCellRenderer *rend;
     202  gboolean boolval;
     203  int intval;
    199204
    200205  g_free(title);
     
    207212
    208213  data->prefwidgets = makeglist(portnum, lim[0].on, lim[0].num, lim[1].on,
    209     lim[1].num, dirstr, addstd, addipc, NULL);
     214    lim[1].num, dirstr, addstd, addipc, natcheck, NULL);
    210215  data->parent = parent;
    211216  data->back = back;
     
    252257  gtk_table_attach_defaults(GTK_TABLE(table), label,           0, 1, RN(ii));
    253258  gtk_table_attach_defaults(GTK_TABLE(table), portnum,         1, 2, RN(ii));
     259  ii++;
     260
     261  /* NAT traversal checkbox */
     262  intval = tr_natTraversalStatus(tr_backend_handle(back));
     263  boolval = !TR_NAT_TRAVERSAL_IS_DISABLED( intval );
     264  setupprefwidget(natcheck, PREF_NAT, boolval);
     265  gtk_table_attach_defaults(GTK_TABLE(table), natcheck,        0, 2, RN(ii));
    254266  ii++;
    255267
     
    341353    }
    342354
     355    applyprefs(data->back);
    343356    /* XXX would be nice to have errno strings, are they printed to stdout? */
    344 
    345     tr_setBindPort(tr_backend_handle(data->back),
    346                    strtol(cf_getpref(PREF_PORT), NULL, 10));
    347     setlimit(data->back);
    348357  }
    349358
     
    353362
    354363void
    355 setlimit(TrBackend *back) {
     364applyprefs(TrBackend *back) {
    356365  struct { void (*func)(tr_handle_t*, int);
    357366    const char *use; const char *num; gboolean defuse; long def; } lim[] = {
     
    362371  };
    363372  const char *pref;
    364   unsigned int ii;
     373  int ii;
    365374  tr_handle_t *tr = tr_backend_handle(back);
    366 
    367   for(ii = 0; ii < ALEN(lim); ii++) {
     375  gboolean boolval;
     376
     377  /* set upload and download limits */
     378  for(ii = 0; ii < (int)ALEN(lim); ii++) {
    368379    pref = cf_getpref(lim[ii].use);
    369380    if(!(NULL == pref ? lim[ii].defuse : strbool(pref)))
     
    374385    }
    375386  }
     387
     388  /* set the listening port */
     389  if(NULL != (pref = cf_getpref(PREF_PORT)) &&
     390     0 < (ii = strtol(pref, NULL, 10)) && 0xffff >= ii)
     391    tr_setBindPort(tr, ii);
     392
     393  /* enable/disable NAT traversal */
     394  boolval = (NULL == (pref = cf_getpref(PREF_NAT)) ? DEF_NAT : strbool(pref));
     395  if( boolval )
     396    tr_natTraversalEnable(tr);
     397  else
     398    tr_natTraversalDisable(tr);
    376399}
    377400
  • trunk/gtk/dialogs.h

    r804 r920  
    3333makeprefwindow(GtkWindow *parent, TrBackend *back);
    3434
    35 /* set the upload limit based on saved prefs */
     35/* set various things based on saved prefs */
    3636void
    37 setlimit(TrBackend *back);
     37applyprefs(TrBackend *back);
    3838
    3939/* show the "add a torrent" dialog */
  • trunk/gtk/ipc.c

    r760 r920  
    264264send_msg(struct constate *con, const char *name, benc_val_t *val) {
    265265  char *buf;
    266   size_t used, total;
     266  int used, total;
    267267  benc_val_t dict;
    268268  char stupid;
  • trunk/gtk/main.c

    r918 r920  
    178178  TrBackend *back;
    179179  benc_val_t *state;
    180   const char *pref;
    181   long intval;
    182180  GList *argfiles;
    183181  gboolean didinit, didlock;
     
    234232      back = tr_backend_new();
    235233
    236       /* set the upload limit */
    237       setlimit(back);
    238 
    239       /* set the listening port */
    240       if(NULL != (pref = cf_getpref(PREF_PORT)) &&
    241          0 < (intval = strtol(pref, NULL, 10)) && 0xffff >= intval)
    242         tr_setBindPort(tr_backend_handle(back), intval);
     234      /* apply a few prefs */
     235      applyprefs(back);
    243236
    244237      makewind(mainwind, back, state, argfiles);
     
    524517  tr_backend_stop_torrents(data->back);
    525518
     519  /* shut down nat traversal */
     520  tr_natTraversalDisable(tr_backend_handle(data->back));
     521
    526522  /* set things up to wait for torrents to stop */
    527523  edata = g_new0(struct exitdata, 1);
     
    545541exitcheck(gpointer gdata) {
    546542  struct exitdata *data = gdata;
    547 
    548   /* keep going if we still have torrents and haven't hit the exit timeout */
    549   if(time(NULL) - data->started < TRACKER_EXIT_TIMEOUT &&
    550      !tr_backend_torrents_stopped(data->cbdata->back)) {
     543  int natstat = tr_natTraversalStatus(tr_backend_handle(data->cbdata->back));
     544
     545  /* keep going if we haven't hit the exit timeout and
     546     we either have torrents left or nat traversal is stopping */
     547  if( time( NULL ) - data->started < TRACKER_EXIT_TIMEOUT &&
     548      ( !tr_backend_torrents_stopped( data->cbdata->back ) &&
     549        TR_NAT_TRAVERSAL_DISABLED != natstat ) ) {
    551550    updatemodel(data->cbdata);
    552551    return TRUE;
Note: See TracChangeset for help on using the changeset viewer.