2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TR_APP_SESSION_H
|
|
|
|
#define TR_APP_SESSION_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QBuffer>
|
|
|
|
#include <QFileInfoList>
|
2010-06-16 02:58:44 +00:00
|
|
|
#include <QNetworkAccessManager>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QString>
|
2013-01-20 01:31:58 +00:00
|
|
|
#include <QStringList>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QUrl>
|
|
|
|
|
2010-07-27 19:43:32 +00:00
|
|
|
class QStringList;
|
|
|
|
|
2010-08-01 18:55:04 +00:00
|
|
|
class AddData;
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2012-12-22 20:35:19 +00:00
|
|
|
#include <libtransmission/quark.h>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2009-04-13 18:21:22 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2010-12-31 19:44:51 +00:00
|
|
|
struct evbuffer;
|
2012-12-14 04:34:42 +00:00
|
|
|
struct tr_variant;
|
2009-04-13 18:21:22 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
class Prefs;
|
|
|
|
|
|
|
|
class Session: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2009-05-03 17:37:39 +00:00
|
|
|
Session( const char * configDir, Prefs& prefs );
|
2009-04-09 18:55:47 +00:00
|
|
|
~Session( );
|
|
|
|
|
2009-05-03 17:37:39 +00:00
|
|
|
public:
|
|
|
|
void stop( );
|
|
|
|
void restart( );
|
|
|
|
|
|
|
|
private:
|
|
|
|
void start( );
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
public:
|
|
|
|
const QUrl& getRemoteUrl( ) const { return myUrl; }
|
|
|
|
const struct tr_session_stats& getStats( ) const { return myStats; }
|
|
|
|
const struct tr_session_stats& getCumulativeStats( ) const { return myCumulativeStats; }
|
|
|
|
const QString& sessionVersion( ) const { return mySessionVersion; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
int64_t blocklistSize( ) const { return myBlocklistSize; }
|
|
|
|
void setBlocklistSize( int64_t i );
|
|
|
|
void updateBlocklist( );
|
|
|
|
void portTest( );
|
2009-12-03 15:23:43 +00:00
|
|
|
void copyMagnetLinkToClipboard( int torrentId );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
public:
|
2009-05-06 13:46:10 +00:00
|
|
|
|
|
|
|
/** returns true if the transmission session is being run inside this client */
|
2009-04-09 18:55:47 +00:00
|
|
|
bool isServer( ) const;
|
|
|
|
|
2009-05-06 13:46:10 +00:00
|
|
|
/** returns true if isServer() is true or if the remote address is the localhost */
|
|
|
|
bool isLocal( ) const;
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
private:
|
2012-12-14 04:34:42 +00:00
|
|
|
void updateStats( struct tr_variant * args );
|
|
|
|
void updateInfo( struct tr_variant * args );
|
2009-04-09 18:55:47 +00:00
|
|
|
void parseResponse( const char * json, size_t len );
|
2010-12-31 19:44:51 +00:00
|
|
|
static void localSessionCallback( tr_session *, struct evbuffer *, void * );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
public:
|
2010-06-16 02:58:44 +00:00
|
|
|
void exec( const char * json );
|
2012-12-14 04:34:42 +00:00
|
|
|
void exec( const struct tr_variant * request );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2009-05-15 02:05:07 +00:00
|
|
|
public:
|
|
|
|
int64_t getUniqueTag( ) { return nextUniqueTag++; }
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
private:
|
2012-12-22 20:35:19 +00:00
|
|
|
void sessionSet( const tr_quark key, const QVariant& variant );
|
2009-04-09 18:55:47 +00:00
|
|
|
void pumpRequests( );
|
|
|
|
void sendTorrentRequest( const char * request, const QSet<int>& torrentIds );
|
2012-12-14 04:34:42 +00:00
|
|
|
static void updateStats( struct tr_variant * d, struct tr_session_stats * stats );
|
2009-04-09 18:55:47 +00:00
|
|
|
void refreshTorrents( const QSet<int>& torrentIds );
|
2010-08-04 13:56:52 +00:00
|
|
|
QNetworkAccessManager * networkAccessManager( );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
public:
|
2012-12-22 20:35:19 +00:00
|
|
|
void torrentSet( const QSet<int>& ids, const tr_quark key, bool val );
|
|
|
|
void torrentSet( const QSet<int>& ids, const tr_quark key, int val );
|
|
|
|
void torrentSet( const QSet<int>& ids, const tr_quark key, double val );
|
|
|
|
void torrentSet( const QSet<int>& ids, const tr_quark key, const QList<int>& val );
|
|
|
|
void torrentSet( const QSet<int>& ids, const tr_quark key, const QStringList& val );
|
|
|
|
void torrentSet( const QSet<int>& ids, const tr_quark key, const QPair<int,QString>& val);
|
2009-05-13 15:54:04 +00:00
|
|
|
void torrentSetLocation( const QSet<int>& ids, const QString& path, bool doMove );
|
2013-01-20 01:31:58 +00:00
|
|
|
void torrentRenamePath( const QSet<int>& ids, const QString& oldpath, const QString& newname );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
public slots:
|
2009-05-03 17:37:39 +00:00
|
|
|
void pauseTorrents( const QSet<int>& torrentIds = QSet<int>() );
|
|
|
|
void startTorrents( const QSet<int>& torrentIds = QSet<int>() );
|
2011-08-01 22:24:24 +00:00
|
|
|
void startTorrentsNow( const QSet<int>& torrentIds = QSet<int>() );
|
|
|
|
void queueMoveTop( const QSet<int>& torrentIds = QSet<int>() );
|
|
|
|
void queueMoveUp( const QSet<int>& torrentIds = QSet<int>() );
|
|
|
|
void queueMoveDown( const QSet<int>& torrentIds = QSet<int>() );
|
|
|
|
void queueMoveBottom( const QSet<int>& torrentIds = QSet<int>() );
|
2009-04-09 18:55:47 +00:00
|
|
|
void refreshSessionInfo( );
|
|
|
|
void refreshSessionStats( );
|
|
|
|
void refreshActiveTorrents( );
|
|
|
|
void refreshAllTorrents( );
|
|
|
|
void initTorrents( const QSet<int>& ids = QSet<int>() );
|
2010-08-01 18:55:04 +00:00
|
|
|
void addNewlyCreatedTorrent( const QString& filename, const QString& localPath );
|
|
|
|
void addTorrent( const AddData& addme );
|
2009-04-09 18:55:47 +00:00
|
|
|
void removeTorrents( const QSet<int>& torrentIds, bool deleteFiles=false );
|
|
|
|
void verifyTorrents( const QSet<int>& torrentIds );
|
|
|
|
void reannounceTorrents( const QSet<int>& torrentIds );
|
|
|
|
void launchWebInterface( );
|
|
|
|
void updatePref( int key );
|
|
|
|
|
|
|
|
/** request a refresh for statistics, including the ones only used by the properties dialog, for a specific torrent */
|
2009-04-18 23:18:28 +00:00
|
|
|
void refreshExtraStats( const QSet<int>& ids );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
private slots:
|
2010-06-16 02:58:44 +00:00
|
|
|
void onFinished( QNetworkReply * reply );
|
2013-01-25 05:43:22 +00:00
|
|
|
void onResponseReceived (const QByteArray& json);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
signals:
|
2013-01-25 05:43:22 +00:00
|
|
|
void responseReceived (const QByteArray& json);
|
2012-12-14 04:34:42 +00:00
|
|
|
void executed( int64_t tag, const QString& result, struct tr_variant * arguments );
|
2009-05-03 17:37:39 +00:00
|
|
|
void sourceChanged( );
|
2009-04-09 18:55:47 +00:00
|
|
|
void portTested( bool isOpen );
|
|
|
|
void statsUpdated( );
|
|
|
|
void sessionUpdated( );
|
|
|
|
void blocklistUpdated( int );
|
2012-12-14 04:34:42 +00:00
|
|
|
void torrentsUpdated( struct tr_variant * torrentList, bool completeList );
|
|
|
|
void torrentsRemoved( struct tr_variant * torrentList );
|
2009-04-09 18:55:47 +00:00
|
|
|
void dataReadProgress( );
|
|
|
|
void dataSendProgress( );
|
2009-05-03 22:00:56 +00:00
|
|
|
void httpAuthenticationRequired( );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
private:
|
2009-05-15 02:05:07 +00:00
|
|
|
int64_t nextUniqueTag;
|
2009-04-09 18:55:47 +00:00
|
|
|
int64_t myBlocklistSize;
|
|
|
|
Prefs& myPrefs;
|
|
|
|
tr_session * mySession;
|
2009-05-03 17:37:39 +00:00
|
|
|
QString myConfigDir;
|
2009-05-08 14:56:11 +00:00
|
|
|
QString mySessionId;
|
2013-01-20 01:31:58 +00:00
|
|
|
QStringList myIdleJSON;
|
2009-04-09 18:55:47 +00:00
|
|
|
QUrl myUrl;
|
2010-08-04 13:56:52 +00:00
|
|
|
QNetworkAccessManager * myNAM;
|
2009-04-09 18:55:47 +00:00
|
|
|
struct tr_session_stats myStats;
|
|
|
|
struct tr_session_stats myCumulativeStats;
|
|
|
|
QString mySessionVersion;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|