transmission/qt/session.h

152 lines
4.8 KiB
C
Raw Normal View History

2009-04-09 18:55:47 +00:00
/*
2009-12-05 02:19:24 +00:00
* This file Copyright (C) 2009 Mnemosyne LLC
2009-04-09 18:55:47 +00:00
*
* This file is licensed by the GPL version 2. Works owned by the
* Transmission project are granted a special exemption to clause 2(b)
* so that the bulk of its code can remain under the MIT license.
* This exemption does not extend to derived works not owned by
* the Transmission project.
*
* $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>
#include <QString>
#include <QHttp>
#include <QUrl>
#include <libtransmission/transmission.h>
#include "speed.h"
2009-04-13 18:21:22 +00:00
extern "C"
{
struct tr_benc;
}
2009-04-09 18:55:47 +00:00
class Prefs;
class Session: public QObject
{
Q_OBJECT
public:
Session( const char * configDir, Prefs& prefs );
2009-04-09 18:55:47 +00:00
~Session( );
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( );
void copyMagnetLinkToClipboard( int torrentId );
2009-04-09 18:55:47 +00:00
public:
/** returns true if the transmission session is being run inside this client */
2009-04-09 18:55:47 +00:00
bool isServer( ) const;
/** 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:
2009-04-13 18:21:22 +00:00
void updateStats( struct tr_benc * args );
void updateInfo( struct tr_benc * args );
2009-04-09 18:55:47 +00:00
void parseResponse( const char * json, size_t len );
static void localSessionCallback( tr_session *, const char *, size_t, void * );
public:
void exec( const char * request );
2009-04-13 18:21:22 +00:00
void exec( const struct tr_benc * request );
2009-04-09 18:55:47 +00:00
public:
int64_t getUniqueTag( ) { return nextUniqueTag++; }
2009-04-09 18:55:47 +00:00
private:
void sessionSet( const char * key, const QVariant& variant );
void pumpRequests( );
void sendTorrentRequest( const char * request, const QSet<int>& torrentIds );
2009-04-13 18:21:22 +00:00
static void updateStats( struct tr_benc * d, struct tr_session_stats * stats );
2009-04-09 18:55:47 +00:00
void refreshTorrents( const QSet<int>& torrentIds );
public:
void torrentSet( const QSet<int>& ids, const QString& key, bool val );
void torrentSet( const QSet<int>& ids, const QString& key, int val );
void torrentSet( const QSet<int>& ids, const QString& key, double val );
void torrentSet( const QSet<int>& ids, const QString& key, const QList<int>& val );
void torrentSetLocation( const QSet<int>& ids, const QString& path, bool doMove );
2009-04-09 18:55:47 +00:00
public slots:
void pauseTorrents( const QSet<int>& torrentIds = QSet<int>() );
void startTorrents( 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>() );
void addTorrent( QString filename );
void addTorrent( QString filename, QString localPath );
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 */
void refreshExtraStats( const QSet<int>& ids );
2009-04-09 18:55:47 +00:00
private slots:
void onRequestStarted( int id );
void onRequestFinished( int id, bool error );
signals:
void executed( int64_t tag, const QString& result, struct tr_benc * arguments );
void sourceChanged( );
2009-04-09 18:55:47 +00:00
void portTested( bool isOpen );
void statsUpdated( );
void sessionUpdated( );
void blocklistUpdated( int );
2009-04-13 18:21:22 +00:00
void torrentsUpdated( struct tr_benc * torrentList, bool completeList );
void torrentsRemoved( struct tr_benc * torrentList );
2009-04-09 18:55:47 +00:00
void dataReadProgress( );
void dataSendProgress( );
void httpAuthenticationRequired( );
2009-04-09 18:55:47 +00:00
private:
int64_t nextUniqueTag;
2009-04-09 18:55:47 +00:00
int64_t myBlocklistSize;
Prefs& myPrefs;
tr_session * mySession;
QString myConfigDir;
QString mySessionId;
2009-04-09 18:55:47 +00:00
QUrl myUrl;
QBuffer myBuffer;
QHttp myHttp;
struct tr_session_stats myStats;
struct tr_session_stats myCumulativeStats;
QString mySessionVersion;
};
#endif