]> granicus.if.org Git - transmission/commitdiff
(trunk, qt) #2096 "magnet links" -- Add the "Copy Magnet Link to Clipboard" feature...
authorCharles Kerr <charles@transmissionbt.com>
Thu, 3 Dec 2009 15:23:43 +0000 (15:23 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Thu, 3 Dec 2009 15:23:43 +0000 (15:23 +0000)
doc/rpc-spec.txt
libtransmission/rpcimpl.c
qt/mainwin.cc
qt/mainwin.h
qt/mainwin.ui
qt/session.cc
qt/session.h

index 35059edd8db8d564d85a3249faafcf2c6fa0cf87..51d43823d2bcbed9a3d4ff5a3044abeacf6f44d5 100644 (file)
    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
          |         |        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"
index ed0d81fc490d7684b35f06350f543ee631da972c..76f8d709cb772fbb426940812e07cbc8467bc3e5 100644 (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" ) )
index e1ee32a98af0a775d9622d877ba6429ae6fa8aa5..2b67d3d97ded5b074bc0a4a91f28c22ba5cda790 100644 (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_Announce
             << ui.action_Pause
+            << ui.action_CopyMagnetToClipboard
+            << sep3
             << ui.action_Verify
-            << ui.action_Announce
+            << 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 );
index 66f4b3b58ffa11092f79ab854e0d98fbff618d4d..b5437d0e3bf5574a66a8eb9777d9b6c825339488 100644 (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( );
index 5a118f75a2fa031b2516eeafafcbb04b9de1dbb2..4300b3812d5437e50d3509704d2964a25640c726 100644 (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">
      <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">
     <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>
     <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"/>
index b0f5903a62e58fe6077d06530f0e93329e0930ab..d130c52217e66f4a4defa274946cf0f87a43daf0 100644 (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" ) ) {
index dfac8979a2020a4c9bb562e47efe7d0b44c3b903..bc9e6972a5170a97128e355a2c9d6bea58f2c88a 100644 (file)
@@ -58,6 +58,7 @@ class Session: public QObject
         void setBlocklistSize( int64_t i );
         void updateBlocklist( );
         void portTest( );
+        void copyMagnetLinkToClipboard( int torrentId );
 
     public: