(trunk, qt) #2096 "magnet links" -- Add the "Copy Magnet Link to Clipboard" feature to Qt client

This commit is contained in:
Charles Kerr 2009-12-03 15:23:43 +00:00
parent c6899aa1eb
commit 31a3ed1684
7 changed files with 79 additions and 14 deletions

View File

@ -155,6 +155,7 @@
id | number | tr_torrent
isPrivate | boolean | tr_torrent
leftUntilDone | number | tr_stat
magnetLink | number | n/a
manualAnnounceTime | number | tr_stat
maxConnectedPeers | number | tr_torrent
metadataPercentComplete | double | tr_stat
@ -562,6 +563,7 @@
| | NO | torrent-get | removed arg "seeders"
| | NO | torrent-get | removed arg "timesCompleted"
| | NO | torrent-get | removed arg "swarmSpeed"
| | yes | torrent-get | new arg "magnetLink"
| | yes | torrent-get | new arg "metadataPercentComplete"
| | yes | torrent-get | new arg "trackerStats"
| | yes | session-set | new arg "incomplete-dir"

View File

@ -500,6 +500,11 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key )
tr_bencDictAddInt( d, key, st->manualAnnounceTime );
else if( tr_streq( key, keylen, "maxConnectedPeers" ) )
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" ) )
tr_bencDictAddReal( d, key, st->metadataPercentComplete );
else if( tr_streq( key, keylen, "name" ) )

View File

@ -159,6 +159,7 @@ TrMainWindow :: TrMainWindow( Session& session, Prefs& prefs, TorrentModel& mode
connect( ui.action_About, SIGNAL(triggered()), myAboutDialog, SLOT(show()));
connect( ui.action_Contents, SIGNAL(triggered()), this, SLOT(openHelp()));
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_Properties, SIGNAL(triggered()), this, SLOT(openProperties()));
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 );
sep2->setSeparator( true );
QAction * sep3 = new QAction( this );
sep3->setSeparator( true );
// context menu
QList<QAction*> actions;
actions << ui.action_Properties
<< ui.action_OpenFolder
<< ui.action_SetLocation
<< sep2
<< ui.action_Start
<< ui.action_Pause
<< ui.action_Verify
<< ui.action_Announce
<< ui.action_Pause
<< ui.action_CopyMagnetToClipboard
<< sep3
<< ui.action_Verify
<< ui.action_SetLocation
<< sep
<< ui.action_Remove
<< ui.action_Delete;
@ -652,6 +657,13 @@ TrMainWindow :: openFolder( )
QDesktopServices :: openUrl( QUrl::fromLocalFile( path ) );
}
void
TrMainWindow :: copyMagnetLinkToClipboard( )
{
const int id( *getSelectedTorrents().begin() );
mySession.copyMagnetLinkToClipboard( id );
}
void
TrMainWindow :: openHelp( )
{
@ -766,6 +778,7 @@ TrMainWindow :: refreshActionSensitivity( )
const bool oneSelection( selected == 1 );
ui.action_OpenFolder->setEnabled( oneSelection && mySession.isLocal( ) );
ui.action_CopyMagnetToClipboard->setEnabled( oneSelection );
ui.action_SelectAll->setEnabled( selected < rowCount );
ui.action_StartAll->setEnabled( paused > 0 );

View File

@ -116,6 +116,7 @@ class TrMainWindow: public QMainWindow
void addTorrents( const QStringList& filenames );
void openHelp( );
void openFolder( );
void copyMagnetLinkToClipboard( );
void setLocation( );
void openProperties( );
void toggleSpeedMode( );

View File

@ -51,7 +51,7 @@
<x>0</x>
<y>0</y>
<width>792</width>
<height>25</height>
<height>23</height>
</rect>
</property>
<property name="sizePolicy">
@ -65,24 +65,19 @@
<string>&amp;Torrent</string>
</property>
<addaction name="separator"/>
<addaction name="action_Add"/>
<addaction name="action_New"/>
<addaction name="separator"/>
<addaction name="action_Properties"/>
<addaction name="action_OpenFolder"/>
<addaction name="action_SetLocation"/>
<addaction name="separator"/>
<addaction name="action_Start"/>
<addaction name="action_Announce"/>
<addaction name="action_Pause"/>
<addaction name="action_CopyMagnetToClipboard"/>
<addaction name="separator"/>
<addaction name="action_SetLocation"/>
<addaction name="action_Verify"/>
<addaction name="separator"/>
<addaction name="action_Remove"/>
<addaction name="action_Delete"/>
<addaction name="separator"/>
<addaction name="action_StartAll"/>
<addaction name="action_PauseAll"/>
<addaction name="separator"/>
<addaction name="action_Quit"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
@ -127,8 +122,21 @@
<addaction name="separator"/>
<addaction name="action_ReverseSortOrder"/>
</widget>
<addaction name="menuTorrent"/>
<widget class="QMenu" name="menu_File">
<property name="title">
<string>&amp;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="menuTorrent"/>
<addaction name="menu_View"/>
<addaction name="menu_Help"/>
</widget>
@ -536,6 +544,11 @@
<string>Set &amp;Location...</string>
</property>
</action>
<action name="action_CopyMagnetToClipboard">
<property name="text">
<string>&amp;Copy Magnet Link to Clipboard</string>
</property>
</action>
</widget>
<resources>
<include location="application.qrc"/>

View File

@ -15,6 +15,7 @@
#include <QApplication>
#include <QByteArray>
#include <QClipboard>
#include <QCoreApplication>
#include <QDesktopServices>
#include <QMessageBox>
@ -48,6 +49,7 @@ namespace
TAG_BLOCKLIST_UPDATE,
TAG_ADD_TORRENT,
TAG_PORT_TEST,
TAG_MAGNET_LINK,
FIRST_UNIQUE_TAG
};
@ -106,6 +108,21 @@ Session :: portTest( )
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
Session :: updatePref( int key )
{
@ -680,6 +697,19 @@ Session :: parseResponse( const char * json, size_t jsonLength )
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:
str = "";
if( tr_bencDictFindStr( &top, "result", &str ) && strcmp( str, "success" ) ) {

View File

@ -58,6 +58,7 @@ class Session: public QObject
void setBlocklistSize( int64_t i );
void updateBlocklist( );
void portTest( );
void copyMagnetLinkToClipboard( int torrentId );
public: