Ignore:
Timestamp:
Jul 18, 2007, 5:27:45 AM (15 years ago)
Author:
charles
Message:

fold per-torrent ul/dl speed cap settings into libtransmission. synchronize gtk+ client with this change. breaks os x client.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr_torrent.c

    r2369 r2388  
    156156      g_assert(NULL == self->handle);
    157157      self->handle = g_value_get_pointer(value);
     158g_message ("setting handle...");
     159      if( self->handle ) {
     160          self->ul_cap         = tr_torrentGetMaxSpeedUL       ( self->handle );
     161          self->ul_cap_enabled = tr_torrentIsMaxSpeedEnabledUL ( self->handle );
     162          self->dl_cap         = tr_torrentGetMaxSpeedDL       ( self->handle );
     163          self->dl_cap_enabled = tr_torrentIsMaxSpeedEnabledDL ( self->handle );
     164g_message ("ul cap [%d] dl_cap [%d]", self->ul_cap, self->dl_cap );
     165      }
    158166      if(NULL != self->handle && NULL != self->dir)
    159167        tr_torrent_set_folder(self);
     
    389397  char *torrent, *hash, *dir;
    390398  gboolean paused = FALSE;
    391   gboolean ul_cap_enabled = FALSE;
    392   gboolean dl_cap_enabled = FALSE;
    393399  gboolean seeding_cap_enabled = FALSE;
    394   gint ul_cap = 0;
    395   gint dl_cap = 0;
    396400  gdouble seeding_cap = 0.0;
    397401
     
    414418      else if (!strcmp (key, "dir")) dir = val;
    415419      else if (!strcmp (key, "paused")) paused = !!data->val.i;
    416       else if (!strcmp (key, "ul-cap-speed")) ul_cap = data->val.i;
    417       else if (!strcmp (key, "ul-cap-enabled")) ul_cap_enabled = !!data->val.i;
    418       else if (!strcmp (key, "dl-cap-speed")) dl_cap = data->val.i;
    419       else if (!strcmp (key, "dl-cap-enabled")) dl_cap_enabled = !!data->val.i;
    420420      else if (!strcmp (key, "seeding-cap-ratio")) seeding_cap = (data->val.i / 100.0);
    421421      else if (!strcmp (key, "seeding-cap-enabled")) seeding_cap_enabled = !!data->val.i;
     
    453453
    454454  ret = maketorrent( handle );
    455   ret->ul_cap = ul_cap;
    456   ret->ul_cap_enabled = ul_cap_enabled;
    457   ret->dl_cap = dl_cap;
    458   ret->dl_cap_enabled = dl_cap_enabled;
    459455  ret->seeding_cap = seeding_cap;
    460456  ret->seeding_cap_enabled = seeding_cap_enabled;
     
    494490    tr_bencInitStr( tr_bencDictAdd( state, "dir" ),
    495491                    tr_torrentGetFolder( tor->handle ), -1, 1 );
    496 
    497492    tr_bencInitInt( tr_bencDictAdd( state, "paused" ),
    498493                    (refreshStat(tor)->status & TR_STATUS_INACTIVE) ? 1 : 0);
    499     tr_bencInitInt( tr_bencDictAdd( state, "ul-cap-speed" ),
    500                     tor->ul_cap );
    501     tr_bencInitInt( tr_bencDictAdd( state, "ul-cap-enabled" ),
    502                     tor->ul_cap_enabled ? 1 : 0 );
    503 
    504     tr_bencInitInt( tr_bencDictAdd( state, "dl-cap-speed" ),
    505                     tor->dl_cap );
    506     tr_bencInitInt( tr_bencDictAdd( state, "dl-cap-enabled" ),
    507                     tor->dl_cap_enabled ? 1 : 0);
    508 
    509494    tr_bencInitInt( tr_bencDictAdd( state, "seeding-cap-ratio" ),
    510495                    (int)(tor->dl_cap * 100.0)); /* two decimal places */
     
    544529}
    545530
    546 extern void tr_setUseCustomUpload( tr_torrent_t * tor, int limit );
    547 extern void tr_setUseCustomDownload( tr_torrent_t * tor, int limit );
    548 
    549 
    550 static void refresh_upload_cap ( TrTorrent *gtor ) {
    551   const int cap = gtor->ul_cap_enabled ? gtor->ul_cap : -1;
    552   g_message ("setting upload cap to %d...", cap);
    553   tr_setUseCustomUpload( gtor->handle, gtor->ul_cap_enabled );
    554   tr_setUploadLimit( gtor->handle, cap );
    555 }
    556 void
    557 tr_torrent_set_upload_cap_speed ( TrTorrent *gtor, int KiB_sec ) {
     531static void
     532refresh_upload_cap ( TrTorrent *gtor )
     533{
     534  tr_torrentEnableMaxSpeedUL( gtor->handle, gtor->ul_cap_enabled );
     535  tr_torrentSetMaxSpeedUL( gtor->handle, gtor->ul_cap );
     536}
     537void
     538tr_torrent_set_upload_cap_speed ( TrTorrent *gtor, int KiB_sec )
     539{
    558540  gtor->ul_cap = KiB_sec;
    559541  refresh_upload_cap ( gtor );
    560542}
    561543void
    562 tr_torrent_set_upload_cap_enabled ( TrTorrent *gtor, gboolean b ) {
     544tr_torrent_set_upload_cap_enabled ( TrTorrent *gtor, gboolean b )
     545{
    563546  gtor->ul_cap_enabled = b;
    564547  refresh_upload_cap ( gtor );
    565548}
    566549
    567 static void refresh_download_cap ( TrTorrent *gtor ) {
    568   const int cap = gtor->dl_cap_enabled ? gtor->dl_cap : -1;
    569   tr_setUseCustomDownload( gtor->handle, gtor->dl_cap_enabled );
    570   tr_setDownloadLimit( gtor->handle, cap );
    571 }
    572 void
    573 tr_torrent_set_download_cap_speed ( TrTorrent *gtor, int KiB_sec ) {
     550static void
     551refresh_download_cap ( TrTorrent *gtor )
     552{
     553  tr_torrentEnableMaxSpeedDL( gtor->handle, gtor->dl_cap_enabled );
     554  tr_torrentSetMaxSpeedDL( gtor->handle, gtor->dl_cap );
     555}
     556void
     557tr_torrent_set_download_cap_speed ( TrTorrent *gtor, int KiB_sec )
     558{
    574559  gtor->dl_cap = KiB_sec;
    575560  refresh_download_cap( gtor );
    576561}
    577562void
    578 tr_torrent_set_download_cap_enabled ( TrTorrent *gtor, gboolean b ) {
     563tr_torrent_set_download_cap_enabled ( TrTorrent *gtor, gboolean b )
     564{
    579565  gtor->dl_cap_enabled = b;
    580566  refresh_download_cap( gtor );
     
    582568
    583569void
    584 tr_torrent_check_seeding_cap ( TrTorrent *gtor) {
     570tr_torrent_check_seeding_cap ( TrTorrent *gtor)
     571{
    585572  const tr_stat_t * st = tr_torrent_stat( gtor );
    586573  if ((gtor->seeding_cap_enabled) && (st->ratio >= gtor->seeding_cap))
     
    588575}
    589576void
    590 tr_torrent_set_seeding_cap_ratio ( TrTorrent *gtor, gdouble ratio ) {
     577tr_torrent_set_seeding_cap_ratio ( TrTorrent *gtor, gdouble ratio )
     578{
    591579  gtor->seeding_cap = ratio;
    592580  tr_torrent_check_seeding_cap (gtor);
    593581}
    594582void
    595 tr_torrent_set_seeding_cap_enabled ( TrTorrent *gtor, gboolean b ) {
     583tr_torrent_set_seeding_cap_enabled ( TrTorrent *gtor, gboolean b )
     584{
    596585  if ((gtor->seeding_cap_enabled = b))
    597586    tr_torrent_check_seeding_cap (gtor);
Note: See TracChangeset for help on using the changeset viewer.