mirror of
https://github.com/transmission/transmission
synced 2025-03-03 10:15:45 +00:00
(trunk, qt) #2096 "magnet links" -- Add the "Copy Magnet Link to Clipboard" feature to Qt client
This commit is contained in:
parent
c6899aa1eb
commit
31a3ed1684
7 changed files with 79 additions and 14 deletions
|
@ -155,6 +155,7 @@
|
||||||
id | number | tr_torrent
|
id | number | tr_torrent
|
||||||
isPrivate | boolean | tr_torrent
|
isPrivate | boolean | tr_torrent
|
||||||
leftUntilDone | number | tr_stat
|
leftUntilDone | number | tr_stat
|
||||||
|
magnetLink | number | n/a
|
||||||
manualAnnounceTime | number | tr_stat
|
manualAnnounceTime | number | tr_stat
|
||||||
maxConnectedPeers | number | tr_torrent
|
maxConnectedPeers | number | tr_torrent
|
||||||
metadataPercentComplete | double | tr_stat
|
metadataPercentComplete | double | tr_stat
|
||||||
|
@ -562,6 +563,7 @@
|
||||||
| | NO | torrent-get | removed arg "seeders"
|
| | NO | torrent-get | removed arg "seeders"
|
||||||
| | NO | torrent-get | removed arg "timesCompleted"
|
| | NO | torrent-get | removed arg "timesCompleted"
|
||||||
| | NO | torrent-get | removed arg "swarmSpeed"
|
| | NO | torrent-get | removed arg "swarmSpeed"
|
||||||
|
| | yes | torrent-get | new arg "magnetLink"
|
||||||
| | yes | torrent-get | new arg "metadataPercentComplete"
|
| | yes | torrent-get | new arg "metadataPercentComplete"
|
||||||
| | yes | torrent-get | new arg "trackerStats"
|
| | yes | torrent-get | new arg "trackerStats"
|
||||||
| | yes | session-set | new arg "incomplete-dir"
|
| | yes | session-set | new arg "incomplete-dir"
|
||||||
|
|
|
@ -500,6 +500,11 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key )
|
||||||
tr_bencDictAddInt( d, key, st->manualAnnounceTime );
|
tr_bencDictAddInt( d, key, st->manualAnnounceTime );
|
||||||
else if( tr_streq( key, keylen, "maxConnectedPeers" ) )
|
else if( tr_streq( key, keylen, "maxConnectedPeers" ) )
|
||||||
tr_bencDictAddInt( d, key, tr_torrentGetPeerLimit( tor ) );
|
tr_bencDictAddInt( d, key, tr_torrentGetPeerLimit( tor ) );
|
||||||
|
else if( tr_streq( key, keylen, "magnetLink" ) ) {
|
||||||
|
char * str = tr_torrentGetMagnetLink( tor );
|
||||||
|
tr_bencDictAddStr( d, key, str );
|
||||||
|
tr_free( str );
|
||||||
|
}
|
||||||
else if( tr_streq( key, keylen, "metadataPercentComplete" ) )
|
else if( tr_streq( key, keylen, "metadataPercentComplete" ) )
|
||||||
tr_bencDictAddReal( d, key, st->metadataPercentComplete );
|
tr_bencDictAddReal( d, key, st->metadataPercentComplete );
|
||||||
else if( tr_streq( key, keylen, "name" ) )
|
else if( tr_streq( key, keylen, "name" ) )
|
||||||
|
|
|
@ -159,6 +159,7 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode
|
||||||
connect( ui.action_About, SIGNAL(triggered()), myAboutDialog, SLOT(show()));
|
connect( ui.action_About, SIGNAL(triggered()), myAboutDialog, SLOT(show()));
|
||||||
connect( ui.action_Contents, SIGNAL(triggered()), this, SLOT(openHelp()));
|
connect( ui.action_Contents, SIGNAL(triggered()), this, SLOT(openHelp()));
|
||||||
connect( ui.action_OpenFolder, SIGNAL(triggered()), this, SLOT(openFolder()));
|
connect( ui.action_OpenFolder, SIGNAL(triggered()), this, SLOT(openFolder()));
|
||||||
|
connect( ui.action_CopyMagnetToClipboard, SIGNAL(triggered()), this, SLOT(copyMagnetLinkToClipboard()));
|
||||||
connect( ui.action_SetLocation, SIGNAL(triggered()), this, SLOT(setLocation()));
|
connect( ui.action_SetLocation, SIGNAL(triggered()), this, SLOT(setLocation()));
|
||||||
connect( ui.action_Properties, SIGNAL(triggered()), this, SLOT(openProperties()));
|
connect( ui.action_Properties, SIGNAL(triggered()), this, SLOT(openProperties()));
|
||||||
connect( ui.action_SessionDialog, SIGNAL(triggered()), mySessionDialog, SLOT(show()));
|
connect( ui.action_SessionDialog, SIGNAL(triggered()), mySessionDialog, SLOT(show()));
|
||||||
|
@ -166,17 +167,21 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode
|
||||||
|
|
||||||
QAction * sep2 = new QAction( this );
|
QAction * sep2 = new QAction( this );
|
||||||
sep2->setSeparator( true );
|
sep2->setSeparator( true );
|
||||||
|
QAction * sep3 = new QAction( this );
|
||||||
|
sep3->setSeparator( true );
|
||||||
|
|
||||||
// context menu
|
// context menu
|
||||||
QList<QAction*> actions;
|
QList<QAction*> actions;
|
||||||
actions << ui.action_Properties
|
actions << ui.action_Properties
|
||||||
<< ui.action_OpenFolder
|
<< ui.action_OpenFolder
|
||||||
<< ui.action_SetLocation
|
|
||||||
<< sep2
|
<< sep2
|
||||||
<< ui.action_Start
|
<< ui.action_Start
|
||||||
<< ui.action_Pause
|
|
||||||
<< ui.action_Verify
|
|
||||||
<< ui.action_Announce
|
<< ui.action_Announce
|
||||||
|
<< ui.action_Pause
|
||||||
|
<< ui.action_CopyMagnetToClipboard
|
||||||
|
<< sep3
|
||||||
|
<< ui.action_Verify
|
||||||
|
<< ui.action_SetLocation
|
||||||
<< sep
|
<< sep
|
||||||
<< ui.action_Remove
|
<< ui.action_Remove
|
||||||
<< ui.action_Delete;
|
<< ui.action_Delete;
|
||||||
|
@ -652,6 +657,13 @@ TrMainWindow :: openFolder( )
|
||||||
QDesktopServices :: openUrl( QUrl::fromLocalFile( path ) );
|
QDesktopServices :: openUrl( QUrl::fromLocalFile( path ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TrMainWindow :: copyMagnetLinkToClipboard( )
|
||||||
|
{
|
||||||
|
const int id( *getSelectedTorrents().begin() );
|
||||||
|
mySession.copyMagnetLinkToClipboard( id );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TrMainWindow :: openHelp( )
|
TrMainWindow :: openHelp( )
|
||||||
{
|
{
|
||||||
|
@ -766,6 +778,7 @@ TrMainWindow :: refreshActionSensitivity( )
|
||||||
|
|
||||||
const bool oneSelection( selected == 1 );
|
const bool oneSelection( selected == 1 );
|
||||||
ui.action_OpenFolder->setEnabled( oneSelection && mySession.isLocal( ) );
|
ui.action_OpenFolder->setEnabled( oneSelection && mySession.isLocal( ) );
|
||||||
|
ui.action_CopyMagnetToClipboard->setEnabled( oneSelection );
|
||||||
|
|
||||||
ui.action_SelectAll->setEnabled( selected < rowCount );
|
ui.action_SelectAll->setEnabled( selected < rowCount );
|
||||||
ui.action_StartAll->setEnabled( paused > 0 );
|
ui.action_StartAll->setEnabled( paused > 0 );
|
||||||
|
|
|
@ -116,6 +116,7 @@ class TrMainWindow: public QMainWindow
|
||||||
void addTorrents( const QStringList& filenames );
|
void addTorrents( const QStringList& filenames );
|
||||||
void openHelp( );
|
void openHelp( );
|
||||||
void openFolder( );
|
void openFolder( );
|
||||||
|
void copyMagnetLinkToClipboard( );
|
||||||
void setLocation( );
|
void setLocation( );
|
||||||
void openProperties( );
|
void openProperties( );
|
||||||
void toggleSpeedMode( );
|
void toggleSpeedMode( );
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>792</width>
|
<width>792</width>
|
||||||
<height>25</height>
|
<height>23</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -65,24 +65,19 @@
|
||||||
<string>&Torrent</string>
|
<string>&Torrent</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="action_Add"/>
|
|
||||||
<addaction name="action_New"/>
|
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="action_Properties"/>
|
<addaction name="action_Properties"/>
|
||||||
<addaction name="action_OpenFolder"/>
|
<addaction name="action_OpenFolder"/>
|
||||||
<addaction name="action_SetLocation"/>
|
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="action_Start"/>
|
<addaction name="action_Start"/>
|
||||||
<addaction name="action_Announce"/>
|
<addaction name="action_Announce"/>
|
||||||
<addaction name="action_Pause"/>
|
<addaction name="action_Pause"/>
|
||||||
|
<addaction name="action_CopyMagnetToClipboard"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="action_SetLocation"/>
|
||||||
<addaction name="action_Verify"/>
|
<addaction name="action_Verify"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="action_Remove"/>
|
<addaction name="action_Remove"/>
|
||||||
<addaction name="action_Delete"/>
|
<addaction name="action_Delete"/>
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="action_StartAll"/>
|
|
||||||
<addaction name="action_PauseAll"/>
|
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="action_Quit"/>
|
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuEdit">
|
<widget class="QMenu" name="menuEdit">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
@ -127,8 +122,21 @@
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="action_ReverseSortOrder"/>
|
<addaction name="action_ReverseSortOrder"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuTorrent"/>
|
<widget class="QMenu" name="menu_File">
|
||||||
|
<property name="title">
|
||||||
|
<string>&File</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="action_Add"/>
|
||||||
|
<addaction name="action_New"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="action_StartAll"/>
|
||||||
|
<addaction name="action_PauseAll"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="action_Quit"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menu_File"/>
|
||||||
<addaction name="menuEdit"/>
|
<addaction name="menuEdit"/>
|
||||||
|
<addaction name="menuTorrent"/>
|
||||||
<addaction name="menu_View"/>
|
<addaction name="menu_View"/>
|
||||||
<addaction name="menu_Help"/>
|
<addaction name="menu_Help"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -536,6 +544,11 @@
|
||||||
<string>Set &Location...</string>
|
<string>Set &Location...</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="action_CopyMagnetToClipboard">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Copy Magnet Link to Clipboard</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="application.qrc"/>
|
<include location="application.qrc"/>
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
#include <QClipboard>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
@ -48,6 +49,7 @@ namespace
|
||||||
TAG_BLOCKLIST_UPDATE,
|
TAG_BLOCKLIST_UPDATE,
|
||||||
TAG_ADD_TORRENT,
|
TAG_ADD_TORRENT,
|
||||||
TAG_PORT_TEST,
|
TAG_PORT_TEST,
|
||||||
|
TAG_MAGNET_LINK,
|
||||||
|
|
||||||
FIRST_UNIQUE_TAG
|
FIRST_UNIQUE_TAG
|
||||||
};
|
};
|
||||||
|
@ -106,6 +108,21 @@ Session :: portTest( )
|
||||||
tr_bencFree( &top );
|
tr_bencFree( &top );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Session :: copyMagnetLinkToClipboard( int torrentId )
|
||||||
|
{
|
||||||
|
tr_benc top;
|
||||||
|
tr_bencInitDict( &top, 3 );
|
||||||
|
tr_bencDictAddStr( &top, "method", "torrent-get" );
|
||||||
|
tr_bencDictAddInt( &top, "tag", TAG_MAGNET_LINK );
|
||||||
|
tr_benc * args = tr_bencDictAddDict( &top, "arguments", 2 );
|
||||||
|
tr_bencListAddInt( tr_bencDictAddList( args, "ids", 1 ), torrentId );
|
||||||
|
tr_bencListAddStr( tr_bencDictAddList( args, "fields", 1 ), "magnetLink" );
|
||||||
|
|
||||||
|
exec( &top );
|
||||||
|
tr_bencFree( &top );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Session :: updatePref( int key )
|
Session :: updatePref( int key )
|
||||||
{
|
{
|
||||||
|
@ -680,6 +697,19 @@ Session :: parseResponse( const char * json, size_t jsonLength )
|
||||||
emit portTested( (bool)isOpen );
|
emit portTested( (bool)isOpen );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case TAG_MAGNET_LINK: {
|
||||||
|
tr_benc * args;
|
||||||
|
tr_benc * torrents;
|
||||||
|
tr_benc * child;
|
||||||
|
const char * str;
|
||||||
|
if( tr_bencDictFindDict( &top, "arguments", &args )
|
||||||
|
&& tr_bencDictFindList( args, "torrents", &torrents )
|
||||||
|
&& (( child = tr_bencListChild( torrents, 0 )))
|
||||||
|
&& tr_bencDictFindStr( child, "magnetLink", &str ) )
|
||||||
|
QApplication::clipboard()->setText( str );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TAG_ADD_TORRENT:
|
case TAG_ADD_TORRENT:
|
||||||
str = "";
|
str = "";
|
||||||
if( tr_bencDictFindStr( &top, "result", &str ) && strcmp( str, "success" ) ) {
|
if( tr_bencDictFindStr( &top, "result", &str ) && strcmp( str, "success" ) ) {
|
||||||
|
|
|
@ -58,6 +58,7 @@ class Session: public QObject
|
||||||
void setBlocklistSize( int64_t i );
|
void setBlocklistSize( int64_t i );
|
||||||
void updateBlocklist( );
|
void updateBlocklist( );
|
||||||
void portTest( );
|
void portTest( );
|
||||||
|
void copyMagnetLinkToClipboard( int torrentId );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue