Changeset 14405


Ignore:
Timestamp:
Dec 27, 2014, 8:03:10 PM (7 years ago)
Author:
mikedld
Message:

Factor RPC logic out from session (Qt client)

Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/variant.c

    r14327 r14405  
    683683  tr_variant * child = tr_variantDictAdd (dict, key);
    684684  tr_variantInitDict (child, reserve_count);
     685  return child;
     686}
     687
     688tr_variant *
     689tr_variantDictSteal (tr_variant       * dict,
     690                     const tr_quark     key,
     691                     tr_variant       * value)
     692{
     693  tr_variant * child = tr_variantDictAdd (dict, key);
     694  *child = *value;
     695  child->key = key;
     696  tr_variantInit (value, value->type);
    685697  return child;
    686698}
  • trunk/libtransmission/variant.h

    r14241 r14405  
    367367                                        size_t             reserve_count);
    368368
     369tr_variant * tr_variantDictSteal       (tr_variant       * dict,
     370                                        const tr_quark     key,
     371                                        tr_variant       * value);
     372
    369373tr_variant * tr_variantDictAddRaw      (tr_variant       * dict,
    370374                                        const tr_quark     key,
  • trunk/qt/CMakeLists.txt

    r14400 r14405  
    4545    prefs.cc
    4646    relocate.cc
     47    rpc-client.cc
    4748    session-dialog.cc
    4849    session.cc
     
    8283    prefs.h
    8384    relocate.h
     85    rpc-client.h
    8486    session-dialog.h
    8587    session.h
  • trunk/qt/freespace-label.cc

    r14403 r14405  
    6868    return;
    6969
    70   const int64_t tag = mySession->getUniqueTag ();
    71   const QByteArray myPathUtf8 = myPath.toUtf8 ();
     70  tr_variant args;
     71  tr_variantInitDict (&args, 1);
     72  tr_variantDictAddStr (&args, TR_KEY_path, myPath.toUtf8 ().constData());
    7273
    73   myTag = tag;
    74   tr_variant top;
    75   tr_variantInitDict (&top, 3);
    76   tr_variantDictAddStr (&top, TR_KEY_method, "free-space");
    77   tr_variantDictAddInt (&top, TR_KEY_tag, tag);
    78   tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 1);
    79   tr_variantDictAddStr (args, TR_KEY_path, myPathUtf8.constData());
    80   mySession->exec (&top);
    81   tr_variantFree (&top);
     74  myTag = mySession->getUniqueTag ();
     75  mySession->exec ("free-space", &args, myTag);
    8276}
    8377
  • trunk/qt/options.cc

    r14404 r14405  
    340340  // rpc spec section 3.4 "adding a torrent"
    341341
    342   tr_variant top;
    343   tr_variantInitDict (&top, 3);
    344   tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 10));
     342  tr_variant args;
     343  tr_variantInitDict (&args, 10);
    345344  QString downloadDir;
    346345
     
    351350    downloadDir = myDestinationEdit->text ();
    352351
    353   tr_variantDictAddStr (args, TR_KEY_download_dir, downloadDir.toUtf8 ().constData ());
     352  tr_variantDictAddStr (&args, TR_KEY_download_dir, downloadDir.toUtf8 ().constData ());
    354353
    355354  // paused
    356   tr_variantDictAddBool (args, TR_KEY_paused, !myStartCheck->isChecked ());
     355  tr_variantDictAddBool (&args, TR_KEY_paused, !myStartCheck->isChecked ());
    357356
    358357  // priority
    359358  const int index = myPriorityCombo->currentIndex ();
    360359  const int priority = myPriorityCombo->itemData (index).toInt ();
    361   tr_variantDictAddInt (args, TR_KEY_bandwidthPriority, priority);
     360  tr_variantDictAddInt (&args, TR_KEY_bandwidthPriority, priority);
    362361
    363362  // files-unwanted
     
    365364  if (count > 0)
    366365    {
    367       tr_variant * l = tr_variantDictAddList (args, TR_KEY_files_unwanted, count);
     366      tr_variant * l = tr_variantDictAddList (&args, TR_KEY_files_unwanted, count);
    368367      for (int i=0, n=myWanted.size (); i<n; ++i)
    369368        if (myWanted.at (i) == false)
     
    375374  if (count > 0)
    376375    {
    377       tr_variant * l = tr_variantDictAddList (args, TR_KEY_priority_low, count);
     376      tr_variant * l = tr_variantDictAddList (&args, TR_KEY_priority_low, count);
    378377      for (int i=0, n=myPriorities.size (); i<n; ++i)
    379378        if (myPriorities.at (i) == TR_PRI_LOW)
     
    385384  if (count > 0)
    386385    {
    387       tr_variant * l = tr_variantDictAddList (args, TR_KEY_priority_high, count);
     386      tr_variant * l = tr_variantDictAddList (&args, TR_KEY_priority_high, count);
    388387      for (int i=0, n=myPriorities.size (); i<n; ++i)
    389388        if (myPriorities.at (i) == TR_PRI_HIGH)
     
    391390    }
    392391
    393   mySession.addTorrent (myAdd, top, myTrashCheck->isChecked ());
    394 
    395   tr_variantFree (&top);
     392  mySession.addTorrent (myAdd, &args, myTrashCheck->isChecked ());
     393
    396394  deleteLater ();
    397395}
  • trunk/qt/qtr.pro

    r14400 r14405  
    7373           prefs-dialog.cc \
    7474           relocate.cc \
     75           rpc-client.cc \
    7576           session.cc \
    7677           session-dialog.cc \
  • trunk/qt/session.cc

    r14404 r14405  
    1919#include <QFileInfo>
    2020#include <QMessageBox>
    21 #include <QNetworkProxy>
    22 #include <QNetworkProxyFactory>
    23 #include <QNetworkReply>
    24 #include <QNetworkRequest>
    25 #include <QSet>
    26 #include <QStringList>
    2721#include <QStyle>
    2822#include <QTextStream>
    2923
    30 #include <curl/curl.h>
    31 
    32 #include <event2/buffer.h>
    33 
    3424#include <libtransmission/transmission.h>
    35 #include <libtransmission/rpcimpl.h>
    3625#include <libtransmission/utils.h> // tr_free
    3726#include <libtransmission/variant.h>
    38 #include <libtransmission/version.h> // LONG_VERSION
    39 #include <libtransmission/web.h>
    4027
    4128#include "add-data.h"
     
    4532#include "torrent.h"
    4633#include "utils.h"
    47 
    48 // #define DEBUG_HTTP
    4934
    5035namespace
     
    140125Session::sessionSet (const tr_quark key, const QVariant& value)
    141126{
    142   tr_variant top;
    143   tr_variantInitDict (&top, 2);
    144   tr_variantDictAddStr (&top, TR_KEY_method, "session-set");
    145   tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 1));
     127  tr_variant args;
     128  tr_variantInitDict (&args, 1);
    146129  switch (value.type ())
    147130    {
    148       case QVariant::Bool:   tr_variantDictAddBool (args, key, value.toBool ()); break;
    149       case QVariant::Int:    tr_variantDictAddInt (args, key, value.toInt ()); break;
    150       case QVariant::Double: tr_variantDictAddReal (args, key, value.toDouble ()); break;
    151       case QVariant::String: tr_variantDictAddStr (args, key, value.toString ().toUtf8 ().constData ()); break;
     131      case QVariant::Bool:   tr_variantDictAddBool (&args, key, value.toBool ()); break;
     132      case QVariant::Int:    tr_variantDictAddInt (&args, key, value.toInt ()); break;
     133      case QVariant::Double: tr_variantDictAddReal (&args, key, value.toDouble ()); break;
     134      case QVariant::String: tr_variantDictAddStr (&args, key, value.toString ().toUtf8 ().constData ()); break;
    152135      default:               assert ("unknown type");
    153136    }
    154   exec (&top);
    155   tr_variantFree (&top);
     137
     138  exec ("session-set", &args);
    156139}
    157140
     
    159142Session::portTest ()
    160143{
    161   tr_variant top;
    162   tr_variantInitDict (&top, 2);
    163   tr_variantDictAddStr (&top, TR_KEY_method, "port-test");
    164   tr_variantDictAddInt (&top, TR_KEY_tag, TAG_PORT_TEST);
    165   exec (&top);
    166   tr_variantFree (&top);
     144  exec ("port-test", nullptr, TAG_PORT_TEST);
    167145}
    168146
     
    170148Session::copyMagnetLinkToClipboard (int torrentId)
    171149{
    172   tr_variant top;
    173   tr_variantInitDict (&top, 3);
    174   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get);
    175   tr_variantDictAddInt (&top, TR_KEY_tag, TAG_MAGNET_LINK);
    176   tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
    177   tr_variantListAddInt (tr_variantDictAddList (args, TR_KEY_ids, 1), torrentId);
    178   tr_variantListAddStr (tr_variantDictAddList (args, TR_KEY_fields, 1), "magnetLink");
    179   exec (&top);
    180   tr_variantFree (&top);
     150  tr_variant args;
     151  tr_variantInitDict (&args, 2);
     152  tr_variantListAddInt (tr_variantDictAddList (&args, TR_KEY_ids, 1), torrentId);
     153  tr_variantListAddStr (tr_variantDictAddList (&args, TR_KEY_fields, 1), "magnetLink");
     154
     155  exec (TR_KEY_torrent_get, &args, TAG_MAGNET_LINK);
    181156}
    182157
     
    304279  myPrefs (prefs),
    305280  mySession (0),
    306   myConfigDir (QString::fromUtf8 (configDir)),
    307   myNAM (0)
     281  myConfigDir (QString::fromUtf8 (configDir))
    308282{
    309283  myStats.ratio = TR_RATIO_NA;
     
    317291  connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (updatePref (int)));
    318292
    319   connect (this, SIGNAL (responseReceived (QByteArray)),
    320            this, SLOT (onResponseReceived (QByteArray)));
     293  connect (&myRpc, SIGNAL (executed (int64_t, QString, tr_variant *)), this, SLOT (responseReceived (int64_t, QString, tr_variant *)));
     294
     295  connect (&myRpc, SIGNAL (httpAuthenticationRequired ()), this, SIGNAL (httpAuthenticationRequired ()));
     296  connect (&myRpc, SIGNAL (dataReadProgress ()), this, SIGNAL (dataReadProgress ()));
     297  connect (&myRpc, SIGNAL (dataSendProgress ()), this, SIGNAL (dataSendProgress ()));
     298  connect (&myRpc, SIGNAL (error (QNetworkReply::NetworkError)), this, SIGNAL (error (QNetworkReply::NetworkError)));
     299  connect (&myRpc, SIGNAL (errorMessage (QString)), this, SIGNAL (errorMessage (QString)));
    321300}
    322301
     
    324303{
    325304    stop ();
    326 }
    327 
    328 QNetworkAccessManager *
    329 Session::networkAccessManager ()
    330 {
    331   if (myNAM == 0)
    332     {
    333       myNAM = new QNetworkAccessManager;
    334 
    335       connect (myNAM, SIGNAL (finished (QNetworkReply*)),
    336                this, SLOT (onFinished (QNetworkReply*)));
    337 
    338       connect (myNAM, SIGNAL (authenticationRequired (QNetworkReply*,QAuthenticator*)),
    339                 this, SIGNAL (httpAuthenticationRequired ()));
    340     }
    341 
    342   return myNAM;
    343305}
    344306
     
    350312Session::stop ()
    351313{
    352   if (myNAM != 0)
    353     {
    354       myNAM->deleteLater ();
    355       myNAM = 0;
    356     }
    357 
    358     myUrl.clear ();
     314  myRpc.stop ();
    359315
    360316  if (mySession)
     
    387343          url.setPassword (myPrefs.get<QString> (Prefs::SESSION_REMOTE_PASSWORD));
    388344        }
    389       myUrl = url;
     345
     346      myRpc.start (url);
    390347    }
    391348  else
     
    397354      tr_variantFree (&settings);
    398355
     356      myRpc.start (mySession);
     357
    399358      tr_ctor * ctor = tr_ctorNew (mySession);
    400359      int torrentCount;
     
    416375Session::isLocal () const
    417376{
    418   if (mySession != 0)
    419     return true;
    420 
    421   if (myUrl.host () == "127.0.0.1")
    422     return true;
    423 
    424   if (!myUrl.host ().compare ("localhost", Qt::CaseInsensitive))
    425     return true;
    426 
    427   return false;
     377  return myRpc.isLocal ();
    428378}
    429379
     
    434384namespace
    435385{
    436   tr_variant *
    437   buildRequest (const char * method, tr_variant& top, int tag=-1)
    438   {
    439     tr_variantInitDict (&top, 3);
    440     tr_variantDictAddStr (&top, TR_KEY_method, method);
    441 
    442     if (tag >= 0)
    443       tr_variantDictAddInt (&top, TR_KEY_tag, tag);
    444 
    445     return tr_variantDictAddDict (&top, TR_KEY_arguments, 0);
    446   }
    447 
    448386  void
    449387  addOptionalIds (tr_variant * args, const QSet<int>& ids)
     
    461399Session::torrentSet (const QSet<int>& ids, const tr_quark key, double value)
    462400{
    463   tr_variant top;
    464   tr_variantInitDict (&top, 2);
    465   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set);
    466   tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
    467   tr_variantDictAddReal (args, key, value);
    468   addOptionalIds (args, ids);
    469   exec (&top);
    470   tr_variantFree (&top);
     401  tr_variant args;
     402  tr_variantInitDict (&args, 2);
     403  tr_variantDictAddReal (&args, key, value);
     404  addOptionalIds (&args, ids);
     405
     406  exec (TR_KEY_torrent_set, &args);
    471407}
    472408
     
    474410Session::torrentSet (const QSet<int>& ids, const tr_quark key, int value)
    475411{
    476   tr_variant top;
    477   tr_variantInitDict (&top, 2);
    478   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set);
    479   tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
    480   tr_variantDictAddInt (args, key, value);
    481   addOptionalIds (args, ids);
    482   exec (&top);
    483   tr_variantFree (&top);
     412  tr_variant args;
     413  tr_variantInitDict (&args, 2);
     414  tr_variantDictAddInt (&args, key, value);
     415  addOptionalIds (&args, ids);
     416
     417  exec (TR_KEY_torrent_set, &args);
    484418}
    485419
     
    487421Session::torrentSet (const QSet<int>& ids, const tr_quark key, bool value)
    488422{
    489   tr_variant top;
    490   tr_variantInitDict (&top, 2);
    491   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set);
    492   tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
    493   tr_variantDictAddBool (args, key, value);
    494   addOptionalIds (args, ids);
    495   exec (&top);
    496   tr_variantFree (&top);
     423  tr_variant args;
     424  tr_variantInitDict (&args, 2);
     425  tr_variantDictAddBool (&args, key, value);
     426  addOptionalIds (&args, ids);
     427
     428  exec (TR_KEY_torrent_set, &args);
    497429}
    498430
     
    500432Session::torrentSet (const QSet<int>& ids, const tr_quark key, const QStringList& value)
    501433{
    502   tr_variant top;
    503   tr_variantInitDict (&top, 2);
    504   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set);
    505   tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
    506   addOptionalIds (args, ids);
    507   tr_variant * list (tr_variantDictAddList (args, key, value.size ()));
    508   foreach (const QString str, value)
     434  tr_variant args;
     435  tr_variantInitDict (&args, 2);
     436  addOptionalIds (&args, ids);
     437  tr_variant * list (tr_variantDictAddList (&args, key, value.size ()));
     438  foreach (const QString& str, value)
    509439    tr_variantListAddStr (list, str.toUtf8 ().constData ());
    510   exec (&top);
    511   tr_variantFree (&top);
     440
     441  exec(TR_KEY_torrent_set, &args);
    512442}
    513443
     
    515445Session::torrentSet (const QSet<int>& ids, const tr_quark key, const QList<int>& value)
    516446{
    517   tr_variant top;
    518   tr_variantInitDict (&top, 2);
    519   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set);
    520   tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2));
    521   addOptionalIds (args, ids);
    522   tr_variant * list (tr_variantDictAddList (args, key, value.size ()));
     447  tr_variant args;
     448  tr_variantInitDict (&args, 2);
     449  addOptionalIds (&args, ids);
     450  tr_variant * list (tr_variantDictAddList (&args, key, value.size ()));
    523451  foreach (int i, value)
    524452    tr_variantListAddInt (list, i);
    525   exec (&top);
    526   tr_variantFree (&top);
     453
     454  exec (TR_KEY_torrent_set, &args);
    527455}
    528456
     
    530458Session::torrentSet (const QSet<int>& ids, const tr_quark key, const QPair<int,QString>& value)
    531459{
    532   tr_variant top;
    533   tr_variantInitDict (&top, 2);
    534   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set);
    535   tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2));
    536   addOptionalIds (args, ids);
    537   tr_variant * list (tr_variantDictAddList (args, key, 2));
     460  tr_variant args;
     461  tr_variantInitDict (&args, 2);
     462  addOptionalIds (&args, ids);
     463  tr_variant * list (tr_variantDictAddList (&args, key, 2));
    538464  tr_variantListAddInt (list, value.first);
    539465  tr_variantListAddStr (list, value.second.toUtf8 ().constData ());
    540   exec (&top);
    541   tr_variantFree (&top);
     466
     467  exec (TR_KEY_torrent_set, &args);
    542468}
    543469
     
    545471Session::torrentSetLocation (const QSet<int>& ids, const QString& location, bool doMove)
    546472{
    547   tr_variant top;
    548   tr_variantInitDict (&top, 2);
    549   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set_location);
    550   tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 3));
    551   addOptionalIds (args, ids);
    552   tr_variantDictAddStr (args, TR_KEY_location, location.toUtf8 ().constData ());
    553   tr_variantDictAddBool (args, TR_KEY_move, doMove);
    554   exec (&top);
    555   tr_variantFree (&top);
     473  tr_variant args;
     474  tr_variantInitDict (&args, 3);
     475  addOptionalIds (&args, ids);
     476  tr_variantDictAddStr (&args, TR_KEY_location, location.toUtf8 ().constData ());
     477  tr_variantDictAddBool (&args, TR_KEY_move, doMove);
     478
     479  exec (TR_KEY_torrent_set_location, &args);
    556480}
    557481
     
    559483Session::torrentRenamePath (const QSet<int>& ids, const QString& oldpath, const QString& newname)
    560484{
    561   tr_variant top;
    562   tr_variantInitDict (&top, 2);
    563   tr_variantDictAddStr (&top, TR_KEY_method, "torrent-rename-path");
    564   tr_variantDictAddInt (&top, TR_KEY_tag, TAG_RENAME_PATH);
    565   tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 3));
    566   addOptionalIds (args, ids);
    567   tr_variantDictAddStr (args, TR_KEY_path, oldpath.toUtf8 ().constData ());
    568   tr_variantDictAddStr (args, TR_KEY_name, newname.toUtf8 ().constData ());
    569   exec (&top);
    570   tr_variantFree (&top);
     485  tr_variant args;
     486  tr_variantInitDict (&args, 2);
     487  addOptionalIds (&args, ids);
     488  tr_variantDictAddStr (&args, TR_KEY_path, oldpath.toUtf8 ().constData ());
     489  tr_variantDictAddStr (&args, TR_KEY_name, newname.toUtf8 ().constData ());
     490
     491  exec ("torrent-rename-path", &args, TAG_RENAME_PATH);
    571492}
    572493
     
    580501  else
    581502    {
    582       tr_variant top;
    583       tr_variantInitDict (&top, 3);
    584       tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get);
    585       tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SOME_TORRENTS);
    586       tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2));
    587       addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ());
    588       addOptionalIds (args, ids);
    589       exec (&top);
    590       tr_variantFree (&top);
     503      tr_variant args;
     504      tr_variantInitDict (&args, 2);
     505      addList (tr_variantDictAddList (&args, TR_KEY_fields, 0), getStatKeys ());
     506      addOptionalIds (&args, ids);
     507
     508      exec (TR_KEY_torrent_get, &args, TAG_SOME_TORRENTS);
    591509    }
    592510}
     
    595513Session::refreshExtraStats (const QSet<int>& ids)
    596514{
    597   tr_variant top;
    598   tr_variantInitDict (&top, 3);
    599   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get);
    600   tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SOME_TORRENTS);
    601   tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2));
    602   addOptionalIds (args, ids);
    603   addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys () + getExtraStatKeys ());
    604   exec (&top);
    605   tr_variantFree (&top);
     515  tr_variant args;
     516  tr_variantInitDict (&args, 3);
     517  addOptionalIds (&args, ids);
     518  addList (tr_variantDictAddList (&args, TR_KEY_fields, 0), getStatKeys () + getExtraStatKeys ());
     519
     520  exec (TR_KEY_torrent_get, &args, TAG_SOME_TORRENTS);
    606521}
    607522
     
    609524Session::sendTorrentRequest (const char * request, const QSet<int>& ids)
    610525{
    611   tr_variant top;
    612 
    613   tr_variant * args (buildRequest (request, top));
    614   addOptionalIds (args, ids);
    615   exec (&top);
    616   tr_variantFree (&top);
     526  tr_variant args;
     527  tr_variantInitDict (&args, 1);
     528  addOptionalIds (&args, ids);
     529
     530  exec (request, &args);
    617531
    618532  refreshTorrents (ids);
     
    630544Session::refreshActiveTorrents ()
    631545{
    632   tr_variant top;
    633   tr_variantInitDict (&top, 3);
    634   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get);
    635   tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SOME_TORRENTS);
    636   tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2));
    637   tr_variantDictAddStr (args, TR_KEY_ids, "recently-active");
    638   addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ());
    639   exec (&top);
    640   tr_variantFree (&top);
     546  tr_variant args;
     547  tr_variantInitDict (&args, 2);
     548  tr_variantDictAddStr (&args, TR_KEY_ids, "recently-active");
     549  addList (tr_variantDictAddList (&args, TR_KEY_fields, 0), getStatKeys ());
     550
     551  exec (TR_KEY_torrent_get, &args, TAG_SOME_TORRENTS);
    641552}
    642553
     
    644555Session::refreshAllTorrents ()
    645556{
    646   tr_variant top;
    647   tr_variantInitDict (&top, 3);
    648   tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get);
    649   tr_variantDictAddInt (&top, TR_KEY_tag, TAG_ALL_TORRENTS);
    650   tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 1));
    651   addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ());
    652   exec (&top);
    653   tr_variantFree (&top);
     557  tr_variant args;
     558  tr_variantInitDict (&args, 1);
     559  addList (tr_variantDictAddList (&args, TR_KEY_fields, 0), getStatKeys ());
     560
     561  exec (TR_KEY_torrent_get, &args, TAG_ALL_TORRENTS);
    654562}
    655563
     
    657565Session::initTorrents (const QSet<int>& ids)
    658566{
    659   tr_variant top;
    660   const int tag (ids.isEmpty () ? TAG_ALL_TORRENTS : TAG_SOME_TORRENTS);
    661   tr_variant * args (buildRequest ("torrent-get", top, tag));
    662   addOptionalIds (args, ids);
    663   addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ()+getInfoKeys ());
    664   exec (&top);
    665   tr_variantFree (&top);
     567  tr_variant args;
     568  tr_variantInitDict (&args, 2);
     569  addOptionalIds (&args, ids);
     570  addList (tr_variantDictAddList (&args, TR_KEY_fields, 0), getStatKeys ()+getInfoKeys ());
     571
     572  exec ("torrent-get", &args, ids.isEmpty () ? TAG_ALL_TORRENTS : TAG_SOME_TORRENTS);
    666573}
    667574
     
    669576Session::refreshSessionStats ()
    670577{
    671   tr_variant top;
    672   tr_variantInitDict (&top, 2);
    673   tr_variantDictAddStr (&top, TR_KEY_method, "session-stats");
    674   tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SESSION_STATS);
    675   exec (&top);
    676   tr_variantFree (&top);
     578  exec ("session-stats", nullptr, TAG_SESSION_STATS);
    677579}
    678580
     
    680582Session::refreshSessionInfo ()
    681583{
    682   tr_variant top;
    683   tr_variantInitDict (&top, 2);
    684   tr_variantDictAddStr (&top, TR_KEY_method, "session-get");
    685   tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SESSION_INFO);
    686   exec (&top);
    687   tr_variantFree (&top);
     584  exec ("session-get", nullptr, TAG_SESSION_INFO);
    688585}
    689586
     
    691588Session::updateBlocklist ()
    692589{
    693   tr_variant top;
    694   tr_variantInitDict (&top, 2);
    695   tr_variantDictAddStr (&top, TR_KEY_method, "blocklist-update");
    696   tr_variantDictAddInt (&top, TR_KEY_tag, TAG_BLOCKLIST_UPDATE);
    697   exec (&top);
    698   tr_variantFree (&top);
     590  exec ("blocklist-update", nullptr, TAG_BLOCKLIST_UPDATE);
    699591}
    700592
     
    704596
    705597void
    706 Session::exec (const tr_variant * request)
    707 {
    708   char * str = tr_variantToStr (request, TR_VARIANT_FMT_JSON_LEAN, NULL);
    709   exec (str);
    710   tr_free (str);
    711 }
    712 
    713 void
    714 Session::localSessionCallback (tr_session * s, evbuffer * json, void * vself)
    715 {
    716   Q_UNUSED (s);
    717 
    718   Session * self = static_cast<Session*> (vself);
    719 
    720   /* this callback is invoked in the libtransmission thread, so we don't want
    721      to process the response here... let's push it over to the Qt thread. */
    722   self->responseReceived (QByteArray (reinterpret_cast<const char *> (evbuffer_pullup (json, -1)),
    723                                       static_cast<int> (evbuffer_get_length (json))));
    724 }
    725 
    726 #define REQUEST_DATA_PROPERTY_KEY "requestData"
    727 
    728 void
    729 Session::exec (const char * json)
    730 {
    731   if (mySession )
    732     {
    733       tr_rpc_request_exec_json (mySession, json, strlen (json), localSessionCallback, this);
    734     }
    735   else if (!myUrl.isEmpty ())
    736     {
    737       QNetworkRequest request;
    738       request.setUrl (myUrl);
    739       request.setRawHeader ("User-Agent", (qApp->applicationName () + "/" + LONG_VERSION_STRING).toUtf8 ());
    740       request.setRawHeader ("Content-Type", "application/json; charset=UTF-8");
    741 
    742       if (!mySessionId.isEmpty ())
    743         request.setRawHeader (TR_RPC_SESSION_ID_HEADER, mySessionId.toUtf8 ());
    744 
    745       const QByteArray requestData (json);
    746       QNetworkReply * reply = networkAccessManager ()->post (request, requestData);
    747       reply->setProperty (REQUEST_DATA_PROPERTY_KEY, requestData);
    748       connect (reply, SIGNAL (downloadProgress (qint64,qint64)), this, SIGNAL (dataReadProgress ()));
    749       connect (reply, SIGNAL (uploadProgress (qint64,qint64)), this, SIGNAL (dataSendProgress ()));
    750       connect (reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SIGNAL(error(QNetworkReply::NetworkError)));
    751 
    752 #ifdef DEBUG_HTTP
    753       std::cerr << "sending " << "POST " << qPrintable (myUrl.path ()) << std::endl;
    754       foreach (QByteArray b, request.rawHeaderList ())
    755         std::cerr << b.constData ()
    756                   << ": "
    757                   << request.rawHeader (b).constData ()
    758                   << std::endl;
    759       std::cerr << "Body:\n" << json << std::endl;
    760 #endif
    761     }
    762 }
    763 
    764 void
    765 Session::onFinished (QNetworkReply * reply)
    766 {
    767 #ifdef DEBUG_HTTP
    768     std::cerr << "http response header: " << std::endl;
    769     foreach (QByteArray b, reply->rawHeaderList ())
    770         std::cerr << b.constData ()
    771                   << ": "
    772                   << reply->rawHeader (b).constData ()
    773                   << std::endl;
    774     std::cerr << "json:\n" << reply->peek (reply->bytesAvailable ()).constData () << std::endl;
    775 #endif
    776 
    777     if ( (reply->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt () == 409)
    778         && (reply->hasRawHeader (TR_RPC_SESSION_ID_HEADER)))
    779     {
    780         // we got a 409 telling us our session id has expired.
    781         // update it and resubmit the request.
    782         mySessionId = QString::fromUtf8 (reply->rawHeader (TR_RPC_SESSION_ID_HEADER));
    783         exec (reply->property (REQUEST_DATA_PROPERTY_KEY).toByteArray ().constData ());
    784     }
    785     else if (reply->error () != QNetworkReply::NoError)
    786     {
    787         emit (errorMessage(reply->errorString ()));
    788     }
    789     else
    790     {
    791         const QByteArray response (reply->readAll ());
    792         const char * json (response.constData ());
    793         int jsonLength (response.size ());
    794         if (jsonLength>0 && json[jsonLength-1] == '\n') --jsonLength;
    795         parseResponse (json, jsonLength);
    796         emit (error(QNetworkReply::NoError));
    797     }
    798 
    799     reply->deleteLater ();
    800 }
    801 
    802 void
    803 Session::onResponseReceived (const QByteArray& utf8)
    804 {
    805   parseResponse (utf8.constData (), utf8.length ());
    806 }
    807 
    808 void
    809 Session::parseResponse (const char * json, size_t jsonLength)
    810 {
    811     tr_variant top;
    812     const int err (tr_variantFromJson (&top, json, jsonLength));
    813     if (!err)
    814     {
    815         int64_t tag = -1;
    816         const char * result = NULL;
    817         tr_variant * args = NULL;
    818 
    819         tr_variantDictFindInt (&top, TR_KEY_tag, &tag);
    820         tr_variantDictFindStr (&top, TR_KEY_result, &result, NULL);
    821         tr_variantDictFindDict (&top, TR_KEY_arguments, &args);
    822 
    823         emit executed (tag, result, args);
    824 
    825         tr_variant * torrents;
    826         const char * str;
    827 
    828         if (tr_variantDictFindInt (&top, TR_KEY_tag, &tag))
    829         {
    830             switch (tag)
     598Session::exec (tr_quark method, tr_variant * args, int64_t tag)
     599{
     600  myRpc.exec (method, args, tag);
     601}
     602
     603void
     604Session::exec (const char* method, tr_variant * args, int64_t tag)
     605{
     606  myRpc.exec (method, args, tag);
     607}
     608
     609void
     610Session::responseReceived (int64_t tag, const QString& result, tr_variant * args)
     611{
     612  emit executed (tag, result, args);
     613
     614  if (tag < 0)
     615    return;
     616
     617  switch (tag)
     618    {
     619      case TAG_SOME_TORRENTS:
     620      case TAG_ALL_TORRENTS:
     621        if (args != nullptr)
     622          {
     623            tr_variant * torrents;
     624            if (tr_variantDictFindList (args, TR_KEY_torrents, &torrents))
     625                emit torrentsUpdated (torrents, tag==TAG_ALL_TORRENTS);
     626            if (tr_variantDictFindList (args, TR_KEY_removed, &torrents))
     627                emit torrentsRemoved (torrents);
     628          }
     629        break;
     630
     631      case TAG_SESSION_STATS:
     632        if (args != nullptr)
     633          updateStats (args);
     634        break;
     635
     636      case TAG_SESSION_INFO:
     637        if (args != nullptr)
     638          updateInfo (args);
     639        break;
     640
     641      case TAG_BLOCKLIST_UPDATE:
     642        {
     643          int64_t intVal = 0;
     644          if (args != nullptr)
    831645            {
    832                 case TAG_SOME_TORRENTS:
    833                 case TAG_ALL_TORRENTS:
    834                     if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) {
    835                         if (tr_variantDictFindList (args, TR_KEY_torrents, &torrents))
    836                             emit torrentsUpdated (torrents, tag==TAG_ALL_TORRENTS);
    837                         if (tr_variantDictFindList (args, TR_KEY_removed, &torrents))
    838                             emit torrentsRemoved (torrents);
    839                     }
    840                     break;
    841 
    842                 case TAG_SESSION_STATS:
    843                     if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args))
    844                         updateStats (args);
    845                     break;
    846 
    847                 case TAG_SESSION_INFO:
    848                     if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args))
    849                         updateInfo (args);
    850                     break;
    851 
    852                 case TAG_BLOCKLIST_UPDATE: {
    853                     int64_t intVal = 0;
    854                     if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args))
    855                         if (tr_variantDictFindInt (args, TR_KEY_blocklist_size, &intVal))
    856                             setBlocklistSize (intVal);
    857                     break;
    858                 }
    859 
    860                 case TAG_RENAME_PATH:
    861                   {
    862                     int64_t id = 0;
    863                     const char * result = 0;
    864                     if (tr_variantDictFindStr (&top, TR_KEY_result, &result, 0) && strcmp (result, "success"))
    865                       {
    866                         const char * path = "";
    867                         const char * name = "";
    868                         tr_variantDictFindStr (args, TR_KEY_path, &path, 0);
    869                         tr_variantDictFindStr (args, TR_KEY_name, &name, 0);
    870                         const QString title = tr ("Error Renaming Path");
    871                         const QString text = tr ("<p><b>Unable to rename \"%1\" as \"%2\": %3.</b></p> <p>Please correct the errors and try again.</p>").arg (path).arg (name).arg (result);
    872                         QMessageBox * d = new QMessageBox (QMessageBox::Information, title, text,
    873                                                            QMessageBox::Close,
    874                                                            qApp->activeWindow ());
    875                         connect (d, SIGNAL (rejected ()), d, SLOT (deleteLater ()));
    876                         d->show ();
    877                       }
    878                     else if (tr_variantDictFindInt (args, TR_KEY_id, &id) && id)
    879                       {
    880                         // let's get the updated file list
    881                         char * req = tr_strdup_printf ("{ \"arguments\": { \"fields\": [ \"fileStats\", \"files\", \"id\", \"name\" ], \"ids\": %d }, \"method\": \"torrent-get\", \"tag\": %d }",
    882                                                        static_cast<int> (id),
    883                                                        static_cast<int> (TAG_SOME_TORRENTS));
    884                         exec (req);
    885                         tr_free (req);
    886                       }
    887 
    888                     break;
    889                 }
    890 
    891                 case TAG_PORT_TEST: {
    892                     bool isOpen = false;
    893                     if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args))
    894                         tr_variantDictFindBool (args, TR_KEY_port_is_open, &isOpen);
    895                     emit portTested (isOpen);
    896                     break;
    897                 }
    898 
    899                 case TAG_MAGNET_LINK: {
    900                     tr_variant * args;
    901                     tr_variant * torrents;
    902                     tr_variant * child;
    903                     const char * str;
    904                     if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)
    905                         && tr_variantDictFindList (args, TR_KEY_torrents, &torrents)
    906                         && ( (child = tr_variantListChild (torrents, 0)))
    907                         && tr_variantDictFindStr (child, TR_KEY_magnetLink, &str, NULL))
    908                             qApp->clipboard ()->setText (str);
    909                     break;
    910                 }
    911 
    912                 case TAG_ADD_TORRENT:
    913                     str = "";
    914                     if (tr_variantDictFindStr (&top, TR_KEY_result, &str, NULL) && strcmp (str, "success")) {
    915                         QMessageBox * d = new QMessageBox (QMessageBox::Information,
    916                                                            tr ("Add Torrent"),
    917                                                            QString::fromUtf8 (str),
    918                                                            QMessageBox::Close,
    919                                                            qApp->activeWindow ());
    920                         connect (d, SIGNAL (rejected ()), d, SLOT (deleteLater ()));
    921                         d->show ();
    922                     }
    923                     break;
    924 
    925                 default:
    926                     break;
     646              if (tr_variantDictFindInt (args, TR_KEY_blocklist_size, &intVal))
     647                setBlocklistSize (intVal);
    927648            }
    928         }
    929         tr_variantFree (&top);
     649          break;
     650        }
     651
     652      case TAG_RENAME_PATH:
     653        {
     654          int64_t id = 0;
     655          if (result != QLatin1String ("success"))
     656            {
     657              const char * path = "";
     658              const char * name = "";
     659              tr_variantDictFindStr (args, TR_KEY_path, &path, 0);
     660              tr_variantDictFindStr (args, TR_KEY_name, &name, 0);
     661              const QString title = tr ("Error Renaming Path");
     662              const QString text = tr ("<p><b>Unable to rename \"%1\" as \"%2\": %3.</b></p> <p>Please correct the errors and try again.</p>").arg (path).arg (name).arg (result);
     663              QMessageBox * d = new QMessageBox (QMessageBox::Information, title, text,
     664                                                 QMessageBox::Close,
     665                                                 qApp->activeWindow ());
     666              connect (d, SIGNAL (rejected ()), d, SLOT (deleteLater ()));
     667              d->show ();
     668            }
     669          else if (tr_variantDictFindInt (args, TR_KEY_id, &id) && id)
     670            {
     671              tr_variant args;
     672              tr_variantInitDict (&args, 2);
     673              tr_variantDictAddInt (&args, TR_KEY_ids, id);
     674              addList (tr_variantDictAddList (&args, TR_KEY_fields, 0),
     675                       KeyList () << TR_KEY_fileStats << TR_KEY_files << TR_KEY_id << TR_KEY_name);
     676              exec ("torrent-get", &args, TAG_SOME_TORRENTS);
     677            }
     678
     679          break;
     680      }
     681
     682      case TAG_PORT_TEST:
     683        {
     684          bool isOpen = false;
     685          if (args != nullptr)
     686            tr_variantDictFindBool (args, TR_KEY_port_is_open, &isOpen);
     687          emit portTested (isOpen);
     688          break;
     689        }
     690
     691      case TAG_MAGNET_LINK:
     692        {
     693          tr_variant * torrents;
     694          tr_variant * child;
     695          const char * str;
     696          if (args != nullptr
     697              && tr_variantDictFindList (args, TR_KEY_torrents, &torrents)
     698              && ( (child = tr_variantListChild (torrents, 0)))
     699              && tr_variantDictFindStr (child, TR_KEY_magnetLink, &str, NULL))
     700            qApp->clipboard ()->setText (str);
     701          break;
     702        }
     703
     704      case TAG_ADD_TORRENT:
     705        {
     706          const char * str = "";
     707          if (result != QLatin1String ("success"))
     708            {
     709              QMessageBox * d = new QMessageBox (QMessageBox::Information,
     710                                                 tr ("Add Torrent"),
     711                                                 QString::fromUtf8 (str),
     712                                                 QMessageBox::Close,
     713                                                 qApp->activeWindow ());
     714              connect (d, SIGNAL (rejected ()), d, SLOT (deleteLater ()));
     715              d->show ();
     716            }
     717          break;
     718        }
    930719    }
    931720}
     
    1071860
    1072861void
    1073 Session::addTorrent (const AddData& addMe, tr_variant& top, bool trashOriginal)
    1074 {
    1075   assert (tr_variantDictFind (&top, TR_KEY_method) == nullptr);
    1076   assert (tr_variantDictFind (&top, TR_KEY_tag) == nullptr);
    1077 
    1078   tr_variantDictAddStr (&top, TR_KEY_method, "torrent-add");
    1079 
    1080   const int64_t tag = getUniqueTag ();
    1081   tr_variantDictAddInt (&top, TR_KEY_tag, tag);
    1082 
    1083   tr_variant * args;
    1084   if (!tr_variantDictFindDict (&top, TR_KEY_arguments, &args))
    1085     args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
    1086 
     862Session::addTorrent (const AddData& addMe, tr_variant * args, bool trashOriginal)
     863{
    1087864  assert (tr_variantDictFind (args, TR_KEY_filename) == nullptr);
    1088865  assert (tr_variantDictFind (args, TR_KEY_metainfo) == nullptr);
     
    1113890        break;
    1114891    }
     892
     893  const int64_t tag = getUniqueTag ();
    1115894
    1116895  // maybe delete the source .torrent
     
    1121900           fileAdded, SLOT (executed (int64_t, QString, tr_variant *)));
    1122901
    1123   exec (&top);
     902  exec ("torrent-add", args, tag);
    1124903}
    1125904
     
    1127906Session::addTorrent (const AddData& addMe)
    1128907{
    1129   tr_variant top;
    1130   tr_variantInitDict (&top, 3);
    1131 
    1132   addTorrent (addMe, top, myPrefs.getBool (Prefs::TRASH_ORIGINAL));
    1133 
    1134   tr_variantFree (&top);
     908  tr_variant args;
     909  tr_variantInitDict (&args, 3);
     910
     911  addTorrent (addMe, &args, myPrefs.getBool (Prefs::TRASH_ORIGINAL));
    1135912}
    1136913
     
    1139916{
    1140917  const QByteArray b64 = AddData (filename).toBase64 ();
    1141   const QByteArray localPathUtf8 = localPath.toUtf8 ();
    1142 
    1143   tr_variant top, *args;
    1144   tr_variantInitDict (&top, 2);
    1145   tr_variantDictAddStr (&top, TR_KEY_method, "torrent-add");
    1146   args = tr_variantDictAddDict (&top, TR_KEY_arguments, 3);
    1147   tr_variantDictAddStr (args, TR_KEY_download_dir, localPathUtf8.constData ());
    1148   tr_variantDictAddBool (args, TR_KEY_paused, !myPrefs.getBool (Prefs::START));
    1149   tr_variantDictAddRaw (args, TR_KEY_metainfo, b64.constData (), b64.size ());
    1150   exec (&top);
    1151   tr_variantFree (&top);
     918
     919  tr_variant args;
     920  tr_variantInitDict (&args, 3);
     921  tr_variantDictAddStr (&args, TR_KEY_download_dir, localPath.toUtf8 ().constData ());
     922  tr_variantDictAddBool (&args, TR_KEY_paused, !myPrefs.getBool (Prefs::START));
     923  tr_variantDictAddRaw (&args, TR_KEY_metainfo, b64.constData (), b64.size ());
     924
     925  exec ("torrent-add", &args);
    1152926}
    1153927
     
    1157931  if (!ids.isEmpty ())
    1158932    {
    1159       tr_variant top, *args;
    1160       tr_variantInitDict (&top, 2);
    1161       tr_variantDictAddStr (&top, TR_KEY_method, "torrent-remove");
    1162       args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
    1163       addOptionalIds (args, ids);
    1164       tr_variantDictAddInt (args, TR_KEY_delete_local_data, deleteFiles);
    1165       exec (&top);
    1166       tr_variantFree (&top);
     933      tr_variant args;
     934      tr_variantInitDict (&args, 2);
     935      addOptionalIds (&args, ids);
     936      tr_variantDictAddInt (&args, TR_KEY_delete_local_data, deleteFiles);
     937
     938      exec ("torrent-remove", &args);
    1167939    }
    1168940}
     
    1173945  if (!ids.isEmpty ())
    1174946    {
    1175       tr_variant top, *args;
    1176       tr_variantInitDict (&top, 2);
    1177       tr_variantDictAddStr (&top, TR_KEY_method, "torrent-verify");
    1178       args = tr_variantDictAddDict (&top, TR_KEY_arguments, 1);
    1179       addOptionalIds (args, ids);
    1180       exec (&top);
    1181       tr_variantFree (&top);
     947      tr_variant args;
     948      tr_variantInitDict (&args, 1);
     949      addOptionalIds (&args, ids);
     950
     951      exec ("torrent-verify", &args);
    1182952    }
    1183953}
     
    1188958  if (!ids.isEmpty ())
    1189959    {
    1190       tr_variant top, *args;
    1191       tr_variantInitDict (&top, 2);
    1192       tr_variantDictAddStr (&top, TR_KEY_method, "torrent-reannounce");
    1193       args = tr_variantDictAddDict (&top, TR_KEY_arguments, 1);
    1194       addOptionalIds (args, ids);
    1195       exec (&top);
    1196       tr_variantFree (&top);
     960      tr_variant args;
     961      tr_variantInitDict (&args, 1);
     962      addOptionalIds (&args, ids);
     963
     964      exec ("torrent-reannounce", &args);
    1197965    }
    1198966}
     
    1209977  if (!mySession) // remote session
    1210978    {
    1211       url = myUrl;
     979      url = myRpc.url ();
    1212980      url.setPath ("/transmission/web/");
    1213981    }
  • trunk/qt/session.h

    r14380 r14405  
    1313#include <QObject>
    1414#include <QSet>
    15 #include <QBuffer>
    16 #include <QFileInfoList>
    17 #include <QNetworkAccessManager>
    1815#include <QString>
    1916#include <QStringList>
    20 #include <QUrl>
    21 #include <QNetworkReply>
    22 
    23 class QStringList;
    24 
    25 class AddData;
    2617
    2718#include <libtransmission/transmission.h>
    2819#include <libtransmission/quark.h>
    2920
     21#include "rpc-client.h"
     22
     23class AddData;
     24class Prefs;
     25
    3026extern "C"
    3127{
    32   struct evbuffer;
    3328  struct tr_variant;
    3429}
    35 
    36 class Prefs;
    3730
    3831class FileAdded: public QObject
     
    4134
    4235  public:
    43     FileAdded (int tag, const QString& name): myTag (tag), myName (name) {}
     36    FileAdded (int64_t tag, const QString& name): myTag (tag), myName (name) {}
    4437    ~FileAdded () {}
    4538    void setFileToDelete (const QString& file) { myDelFile = file; }
     
    7063
    7164  public:
    72     const QUrl& getRemoteUrl () const { return myUrl; }
     65    const QUrl& getRemoteUrl () const { return myRpc.url (); }
    7366    const tr_session_stats& getStats () const { return myStats; }
    7467    const tr_session_stats& getCumulativeStats () const { return myCumulativeStats; }
     
    9386    void updateStats (tr_variant * args);
    9487    void updateInfo (tr_variant * args);
    95     void parseResponse (const char * json, size_t len);
    96     static void localSessionCallback (tr_session *, evbuffer *, void *);
    9788
    9889  public:
    99     void exec (const char * json);
    100     void exec (const tr_variant * request);
     90    void exec (tr_quark method, tr_variant * args, int64_t tag = -1);
     91    void exec (const char* method, tr_variant * args, int64_t tag = -1);
    10192
    10293  public:
     
    109100    static void updateStats (tr_variant * d, tr_session_stats * stats);
    110101    void refreshTorrents (const QSet<int>& torrentIds);
    111     QNetworkAccessManager * networkAccessManager ();
    112102
    113103  public:
     
    120110    void torrentSetLocation (const QSet<int>& ids, const QString& path, bool doMove);
    121111    void torrentRenamePath (const QSet<int>& ids, const QString& oldpath, const QString& newname);
    122     void addTorrent (const AddData& addme, tr_variant& top, bool trashOriginal);
     112    void addTorrent (const AddData& addme, tr_variant * top, bool trashOriginal);
    123113
    124114  public slots:
     
    147137
    148138  private slots:
    149     void onFinished (QNetworkReply * reply);
    150     void onResponseReceived (const QByteArray& json);
     139    void responseReceived (int64_t tag, const QString& result, tr_variant * args);
    151140
    152141  signals:
    153     void responseReceived (const QByteArray& json);
    154142    void executed (int64_t tag, const QString& result, tr_variant * arguments);
    155143    void sourceChanged ();
     
    172160    tr_session * mySession;
    173161    QString myConfigDir;
    174     QString mySessionId;
    175162    QStringList myIdleJSON;
    176     QUrl myUrl;
    177     QNetworkAccessManager * myNAM;
    178163    tr_session_stats myStats;
    179164    tr_session_stats myCumulativeStats;
    180165    QString mySessionVersion;
     166    RpcClient myRpc;
    181167};
    182168
    183169#endif
    184 
Note: See TracChangeset for help on using the changeset viewer.