Changeset 14349
- Timestamp:
- Dec 1, 2014, 7:24:07 PM (8 years ago)
- Location:
- trunk/qt
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/options.cc
r14225 r14349 10 10 #include <algorithm> // std::min() 11 11 12 #include <QApplication>13 12 #include <QCheckBox> 14 13 #include <QComboBox> … … 20 19 #include <QGridLayout> 21 20 #include <QLabel> 22 #include <QMessageBox>23 21 #include <QPushButton> 24 22 #include <QResizeEvent> … … 41 39 #include "torrent.h" 42 40 #include "utils.h" 43 44 /***45 ****46 ***/47 48 void49 FileAdded :: executed (int64_t tag, const QString& result, struct tr_variant * arguments)50 {51 Q_UNUSED (arguments);52 53 if (tag != myTag)54 return;55 56 if ((result == "success") && !myDelFile.isEmpty ())57 {58 QFile file (myDelFile);59 file.setPermissions (QFile::ReadOwner | QFile::WriteOwner);60 file.remove ();61 }62 63 if (result != "success")64 {65 QString text = result;66 67 for (int i=0, n=text.size (); i<n; ++i)68 if (!i || text[i-1].isSpace ())69 text[i] = text[i].toUpper ();70 71 QMessageBox::warning (QApplication::activeWindow (),72 tr ("Error Adding Torrent"),73 QString ("<p><b>%1</b></p><p>%2</p>").arg (text).arg (myName));74 }75 76 deleteLater ();77 }78 41 79 42 /*** … … 375 338 // rpc spec section 3.4 "adding a torrent" 376 339 377 const int64_t tag = mySession.getUniqueTag ();378 340 tr_variant top; 379 341 tr_variantInitDict (&top, 3); 380 tr_variantDictAddStr (&top, TR_KEY_method, "torrent-add");381 tr_variantDictAddInt (&top, TR_KEY_tag, tag);382 342 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 10)); 383 343 QString downloadDir; … … 391 351 tr_variantDictAddStr (args, TR_KEY_download_dir, downloadDir.toUtf8 ().constData ()); 392 352 393 // "metainfo"394 switch (myAdd.type)395 {396 case AddData::MAGNET:397 tr_variantDictAddStr (args, TR_KEY_filename, myAdd.magnet.toUtf8 ().constData ());398 break;399 400 case AddData::URL:401 tr_variantDictAddStr (args, TR_KEY_filename, myAdd.url.toString ().toUtf8 ().constData ());402 break;403 404 case AddData::FILENAME:405 case AddData::METAINFO: {406 const QByteArray b64 = myAdd.toBase64 ();407 tr_variantDictAddRaw (args, TR_KEY_metainfo, b64.constData (), b64.size ());408 break;409 }410 411 default:412 qWarning ("unhandled AddData.type: %d", myAdd.type);413 }414 415 353 // paused 416 354 tr_variantDictAddBool (args, TR_KEY_paused, !myStartCheck->isChecked ()); … … 451 389 } 452 390 453 // maybe delete the source .torrent 454 FileAdded * fileAdded = new FileAdded (tag, myAdd.readableName ()); 455 if (myTrashCheck->isChecked () && (myAdd.type==AddData::FILENAME)) 456 fileAdded->setFileToDelete (myAdd.filename); 457 connect (&mySession, SIGNAL (executed (int64_t,const QString&, struct tr_variant*)), 458 fileAdded, SLOT (executed (int64_t,const QString&, struct tr_variant*))); 459 460 mySession.exec (&top); 391 mySession.addTorrent (myAdd, top, myTrashCheck->isChecked ()); 461 392 462 393 tr_variantFree (&top); -
trunk/qt/options.h
r14241 r14349 10 10 #ifndef OPTIONS_DIALOG_H 11 11 #define OPTIONS_DIALOG_H 12 13 #include <iostream>14 12 15 13 #include <QDialog> … … 42 40 struct tr_variant; 43 41 } 44 45 class FileAdded: public QObject46 {47 Q_OBJECT48 49 public:50 FileAdded (int tag, const QString& name): myTag (tag), myName (name) {}51 ~FileAdded () {}52 void setFileToDelete (const QString& file) { myDelFile = file; }53 54 public slots:55 void executed (int64_t tag, const QString& result, struct tr_variant * arguments);56 57 private:58 const int64_t myTag;59 QString myName;60 QString myDelFile;61 };62 42 63 43 class Options: public QDialog -
trunk/qt/session.cc
r14225 r14349 16 16 #include <QCoreApplication> 17 17 #include <QDesktopServices> 18 #include <QFile> 18 19 #include <QMessageBox> 19 20 #include <QNetworkProxy> … … 82 83 tr_variantListAddQuark (list, key); 83 84 } 85 } 86 87 /*** 88 **** 89 ***/ 90 91 void 92 FileAdded :: executed (int64_t tag, const QString& result, struct tr_variant * arguments) 93 { 94 Q_UNUSED (arguments); 95 96 if (tag != myTag) 97 return; 98 99 if (result == "success") 100 { 101 if (!myDelFile.isEmpty ()) 102 { 103 QFile file (myDelFile); 104 file.setPermissions (QFile::ReadOwner | QFile::WriteOwner); 105 file.remove (); 106 } 107 } 108 else 109 { 110 QString text = result; 111 112 for (int i=0, n=text.size (); i<n; ++i) 113 if (!i || text[i-1].isSpace ()) 114 text[i] = text[i].toUpper (); 115 116 QMessageBox::warning (QApplication::activeWindow (), 117 tr ("Error Adding Torrent"), 118 QString ("<p><b>%1</b></p><p>%2</p>").arg (text).arg (myName)); 119 } 120 121 deleteLater (); 84 122 } 85 123 … … 1022 1060 1023 1061 void 1024 Session :: addTorrent (const AddData& addMe) 1025 { 1026 const QByteArray b64 = addMe.toBase64 (); 1027 1028 tr_variant top, *args; 1029 tr_variantInitDict (&top, 2); 1062 Session :: addTorrent (const AddData& addMe, tr_variant& top, bool trashOriginal) 1063 { 1064 assert (tr_variantDictFind (&top, TR_KEY_method) == nullptr); 1065 assert (tr_variantDictFind (&top, TR_KEY_tag) == nullptr); 1066 1030 1067 tr_variantDictAddStr (&top, TR_KEY_method, "torrent-add"); 1031 args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); 1032 tr_variantDictAddBool (args, TR_KEY_paused, !myPrefs.getBool (Prefs::START)); 1068 1069 const int64_t tag = getUniqueTag (); 1070 tr_variantDictAddInt (&top, TR_KEY_tag, tag); 1071 1072 tr_variant * args; 1073 if (!tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) 1074 args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); 1075 1076 assert (tr_variantDictFind (args, TR_KEY_filename) == nullptr); 1077 assert (tr_variantDictFind (args, TR_KEY_metainfo) == nullptr); 1078 1079 if (tr_variantDictFind (args, TR_KEY_paused) == nullptr) 1080 tr_variantDictAddBool (args, TR_KEY_paused, !myPrefs.getBool (Prefs::START)); 1033 1081 1034 1082 switch (addMe.type) … … 1044 1092 case AddData::FILENAME: /* fall-through */ 1045 1093 case AddData::METAINFO: 1046 tr_variantDictAddRaw (args, TR_KEY_metainfo, b64.constData (), b64.size ()); 1047 break; 1094 { 1095 const QByteArray b64 = addMe.toBase64 (); 1096 tr_variantDictAddRaw (args, TR_KEY_metainfo, b64.constData (), b64.size ()); 1097 break; 1098 } 1048 1099 1049 1100 default: 1050 std::cerr << "Unhandled AddData type: " << addMe.type << std::endl; 1051 break; 1052 } 1053 1054 exec (&top); 1101 qWarning() << "Unhandled AddData type: " << addMe.type; 1102 break; 1103 } 1104 1105 // maybe delete the source .torrent 1106 FileAdded * fileAdded = new FileAdded (tag, addMe.readableName ()); 1107 if (trashOriginal && addMe.type == AddData::FILENAME) 1108 fileAdded->setFileToDelete (addMe.filename); 1109 connect (this, SIGNAL (executed (int64_t, QString, struct tr_variant *)), 1110 fileAdded, SLOT (executed (int64_t, QString, struct tr_variant *))); 1111 1112 exec (&top); 1113 } 1114 1115 void 1116 Session :: addTorrent (const AddData& addMe) 1117 { 1118 tr_variant top; 1119 tr_variantInitDict (&top, 3); 1120 1121 addTorrent (addMe, top, myPrefs.getBool (Prefs::TRASH_ORIGINAL)); 1122 1055 1123 tr_variantFree (&top); 1056 1124 } -
trunk/qt/session.h
r14241 r14349 35 35 36 36 class Prefs; 37 38 class FileAdded: public QObject 39 { 40 Q_OBJECT 41 42 public: 43 FileAdded (int tag, const QString& name): myTag (tag), myName (name) {} 44 ~FileAdded () {} 45 void setFileToDelete (const QString& file) { myDelFile = file; } 46 47 public slots: 48 void executed (int64_t tag, const QString& result, struct tr_variant * arguments); 49 50 private: 51 const int64_t myTag; 52 const QString myName; 53 QString myDelFile; 54 }; 37 55 38 56 class Session: public QObject … … 102 120 void torrentSetLocation (const QSet<int>& ids, const QString& path, bool doMove); 103 121 void torrentRenamePath (const QSet<int>& ids, const QString& oldpath, const QString& newname); 122 void addTorrent (const AddData& addme, tr_variant& top, bool trashOriginal); 104 123 105 124 public slots:
Note: See TracChangeset
for help on using the changeset viewer.