Changeset 11082


Ignore:
Timestamp:
Jul 31, 2010, 11:11:05 PM (12 years ago)
Author:
charles
Message:

(trunk qt) #3465 "add drag-and-drop support for adding torrents/magnets" -- added.

Location:
trunk/qt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/mainwin.cc

    r11076 r11082  
    1414#include <iostream>
    1515
    16 #include <QCheckBox>
    17 #include <QCloseEvent>
    18 #include <QDesktopServices>
    19 #include <QFileDialog>
    20 #include <QHBoxLayout>
    21 #include <QInputDialog>
    22 #include <QLabel>
    23 #include <QMessageBox>
    24 #include <QSignalMapper>
    25 #include <QSize>
    26 #include <QStyle>
    27 #include <QSystemTrayIcon>
    28 #include <QUrl>
     16#include <QtGui>
    2917
    3018#include <libtransmission/transmission.h>
     
    3321
    3422#include "about.h"
     23#include "app.h"
    3524#include "details.h"
    3625#include "filterbar.h"
     
    10493    myNetworkTimer( this )
    10594{
     95    setAcceptDrops( true );
     96
    10697    QAction * sep = new QAction( this );
    10798    sep->setSeparator( true );
     
    12301221    mySessionDialog->show( );
    12311222}
     1223
     1224/***
     1225****
     1226***/
     1227
     1228void
     1229TrMainWindow :: dragEnterEvent( QDragEnterEvent * event )
     1230{
     1231    const QMimeData * mime = event->mimeData( );
     1232
     1233    if( mime->hasFormat("application/x-bittorrent")
     1234            || mime->text().trimmed().endsWith(".torrent", Qt::CaseInsensitive) )
     1235        event->acceptProposedAction();
     1236}
     1237
     1238void
     1239TrMainWindow :: dropEvent( QDropEvent * event )
     1240{
     1241    QString key = event->mimeData()->text().trimmed();
     1242
     1243    const QUrl url( key );
     1244    if( url.scheme() == "file" )
     1245        key = QUrl::fromPercentEncoding( url.path().toUtf8( ) );
     1246
     1247    dynamic_cast<MyApp*>(QApplication::instance())->addTorrent( key );
     1248}
  • trunk/qt/mainwin.h

    r11072 r11082  
    182182        TrMainWindow( Session&, Prefs&, TorrentModel&, bool minized );
    183183        virtual ~TrMainWindow( );
     184
     185    protected:
     186        virtual void dragEnterEvent( QDragEnterEvent * );
     187        virtual void dropEvent( QDropEvent * );
    184188};
    185189
Note: See TracChangeset for help on using the changeset viewer.