mirror of
https://github.com/transmission/transmission
synced 2025-03-12 07:03:44 +00:00
(trunk) add drag-and-drop support to the "create new torrent" dialogs in the Qt and GTK+ clients
This commit is contained in:
parent
cba88707f9
commit
5182600179
3 changed files with 117 additions and 17 deletions
|
@ -32,7 +32,9 @@ typedef struct
|
||||||
{
|
{
|
||||||
char * target;
|
char * target;
|
||||||
guint progress_tag;
|
guint progress_tag;
|
||||||
|
GtkWidget * file_radio;
|
||||||
GtkWidget * file_chooser;
|
GtkWidget * file_chooser;
|
||||||
|
GtkWidget * folder_radio;
|
||||||
GtkWidget * folder_chooser;
|
GtkWidget * folder_chooser;
|
||||||
GtkWidget * pieces_lb;
|
GtkWidget * pieces_lb;
|
||||||
GtkWidget * destination_chooser;
|
GtkWidget * destination_chooser;
|
||||||
|
@ -377,6 +379,43 @@ getDefaultSavePath( void )
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_drag_data_received( GtkWidget * widget UNUSED,
|
||||||
|
GdkDragContext * drag_context UNUSED,
|
||||||
|
gint x UNUSED,
|
||||||
|
gint y UNUSED,
|
||||||
|
GtkSelectionData * selection_data,
|
||||||
|
guint info UNUSED,
|
||||||
|
guint time UNUSED,
|
||||||
|
gpointer user_data )
|
||||||
|
{
|
||||||
|
MakeMetaUI * ui = user_data;
|
||||||
|
char ** uris = gtk_selection_data_get_uris( selection_data );
|
||||||
|
|
||||||
|
if( uris && uris[0] )
|
||||||
|
{
|
||||||
|
const char * uri = uris[ 0 ];
|
||||||
|
gchar * filename = g_filename_from_uri( uri, NULL, NULL );
|
||||||
|
|
||||||
|
if( g_file_test( filename, G_FILE_TEST_IS_DIR ) )
|
||||||
|
{
|
||||||
|
/* a directory was dragged onto the dialog... */
|
||||||
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( ui->folder_radio ), TRUE );
|
||||||
|
gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( ui->folder_chooser ), filename );
|
||||||
|
}
|
||||||
|
else if( g_file_test( filename, G_FILE_TEST_IS_REGULAR ) )
|
||||||
|
{
|
||||||
|
/* a file was dragged on to the dialog... */
|
||||||
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( ui->file_radio ), TRUE );
|
||||||
|
gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( ui->file_chooser ), filename );
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free( filename );
|
||||||
|
}
|
||||||
|
|
||||||
|
g_strfreev( uris );
|
||||||
|
}
|
||||||
|
|
||||||
GtkWidget*
|
GtkWidget*
|
||||||
make_meta_ui( GtkWindow * parent, TrCore * core )
|
make_meta_ui( GtkWindow * parent, TrCore * core )
|
||||||
{
|
{
|
||||||
|
@ -415,6 +454,7 @@ make_meta_ui( GtkWindow * parent, TrCore * core )
|
||||||
g_signal_connect( l, "toggled", G_CALLBACK( onFolderToggled ), ui );
|
g_signal_connect( l, "toggled", G_CALLBACK( onFolderToggled ), ui );
|
||||||
g_signal_connect( l, "toggled", G_CALLBACK( onSourceToggled ), w );
|
g_signal_connect( l, "toggled", G_CALLBACK( onSourceToggled ), w );
|
||||||
g_signal_connect( w, "selection-changed", G_CALLBACK( onChooserChosen ), ui );
|
g_signal_connect( w, "selection-changed", G_CALLBACK( onChooserChosen ), ui );
|
||||||
|
ui->folder_radio = l;
|
||||||
ui->folder_chooser = w;
|
ui->folder_chooser = w;
|
||||||
gtk_widget_set_sensitive( GTK_WIDGET( w ), FALSE );
|
gtk_widget_set_sensitive( GTK_WIDGET( w ), FALSE );
|
||||||
hig_workarea_add_row_w( t, &row, l, w, NULL );
|
hig_workarea_add_row_w( t, &row, l, w, NULL );
|
||||||
|
@ -426,6 +466,7 @@ make_meta_ui( GtkWindow * parent, TrCore * core )
|
||||||
g_signal_connect( l, "toggled", G_CALLBACK( onFileToggled ), ui );
|
g_signal_connect( l, "toggled", G_CALLBACK( onFileToggled ), ui );
|
||||||
g_signal_connect( l, "toggled", G_CALLBACK( onSourceToggled ), w );
|
g_signal_connect( l, "toggled", G_CALLBACK( onSourceToggled ), w );
|
||||||
g_signal_connect( w, "selection-changed", G_CALLBACK( onChooserChosen ), ui );
|
g_signal_connect( w, "selection-changed", G_CALLBACK( onChooserChosen ), ui );
|
||||||
|
ui->file_radio = l;
|
||||||
ui->file_chooser = w;
|
ui->file_chooser = w;
|
||||||
hig_workarea_add_row_w( t, &row, l, w, NULL );
|
hig_workarea_add_row_w( t, &row, l, w, NULL );
|
||||||
|
|
||||||
|
@ -474,5 +515,10 @@ make_meta_ui( GtkWindow * parent, TrCore * core )
|
||||||
hig_workarea_finish( t, &row );
|
hig_workarea_finish( t, &row );
|
||||||
gtk_box_pack_start( GTK_BOX( GTK_DIALOG( d )->vbox ), t, TRUE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX( GTK_DIALOG( d )->vbox ), t, TRUE, TRUE, 0 );
|
||||||
|
|
||||||
|
gtk_drag_dest_set( d, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY );
|
||||||
|
gtk_drag_dest_add_uri_targets( d );
|
||||||
|
gtk_drag_dest_add_text_targets( d );
|
||||||
|
g_signal_connect( d, "drag-data-received", G_CALLBACK( on_drag_data_received ), ui );
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,12 +177,15 @@ MakeDialog :: onFileClicked( )
|
||||||
void
|
void
|
||||||
MakeDialog :: onFileSelected( const QStringList& list )
|
MakeDialog :: onFileSelected( const QStringList& list )
|
||||||
{
|
{
|
||||||
if( list.size() == 1 )
|
if( !list.empty( ) )
|
||||||
{
|
onFileSelected( list.front( ) );
|
||||||
myFile = list.first( );
|
}
|
||||||
myFileButton->setText( QFileInfo(myFile).fileName() );
|
void
|
||||||
onSourceChanged( );
|
MakeDialog :: onFileSelected( const QString& filename )
|
||||||
}
|
{
|
||||||
|
myFile = filename;
|
||||||
|
myFileButton->setText( QFileInfo(myFile).fileName() );
|
||||||
|
onSourceChanged( );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -197,12 +200,15 @@ MakeDialog :: onFolderClicked( )
|
||||||
void
|
void
|
||||||
MakeDialog :: onFolderSelected( const QStringList& list )
|
MakeDialog :: onFolderSelected( const QStringList& list )
|
||||||
{
|
{
|
||||||
if( list.size() == 1 )
|
if( !list.empty( ) )
|
||||||
{
|
onFolderSelected( list.front( ) );
|
||||||
myFolder = list.first();
|
}
|
||||||
myFolderButton->setText( QFileInfo(myFolder).fileName() );
|
void
|
||||||
onSourceChanged( );
|
MakeDialog :: onFolderSelected( const QString& filename )
|
||||||
}
|
{
|
||||||
|
myFolder = filename;
|
||||||
|
myFolderButton->setText( QFileInfo(myFolder).fileName() );
|
||||||
|
onSourceChanged( );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -217,11 +223,14 @@ MakeDialog :: onDestinationClicked( )
|
||||||
void
|
void
|
||||||
MakeDialog :: onDestinationSelected( const QStringList& list )
|
MakeDialog :: onDestinationSelected( const QStringList& list )
|
||||||
{
|
{
|
||||||
if( list.size() == 1 )
|
if( !list.empty( ) )
|
||||||
{
|
onDestinationSelected( list.front() );
|
||||||
myDestination = list.first( );
|
}
|
||||||
myDestinationButton->setText( QFileInfo(myDestination).fileName() );
|
void
|
||||||
}
|
MakeDialog :: onDestinationSelected( const QString& filename )
|
||||||
|
{
|
||||||
|
myDestination = filename;
|
||||||
|
myDestinationButton->setText( QFileInfo(myDestination).fileName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -306,6 +315,8 @@ MakeDialog :: MakeDialog( Session & session, QWidget * parent ):
|
||||||
mySession( session ),
|
mySession( session ),
|
||||||
myBuilder( 0 )
|
myBuilder( 0 )
|
||||||
{
|
{
|
||||||
|
setAcceptDrops( true );
|
||||||
|
|
||||||
connect( &myTimer, SIGNAL(timeout()), this, SLOT(onProgress()) );
|
connect( &myTimer, SIGNAL(timeout()), this, SLOT(onProgress()) );
|
||||||
|
|
||||||
setWindowTitle( tr( "New Torrent" ) );
|
setWindowTitle( tr( "New Torrent" ) );
|
||||||
|
@ -396,3 +407,37 @@ MakeDialog :: ~MakeDialog( )
|
||||||
if( myBuilder )
|
if( myBuilder )
|
||||||
tr_metaInfoBuilderFree( myBuilder );
|
tr_metaInfoBuilderFree( myBuilder );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
****
|
||||||
|
***/
|
||||||
|
|
||||||
|
void
|
||||||
|
MakeDialog :: dragEnterEvent( QDragEnterEvent * event )
|
||||||
|
{
|
||||||
|
const QMimeData * mime = event->mimeData( );
|
||||||
|
|
||||||
|
if( mime->urls().size() && QFile(mime->urls().front().path()).exists( ) )
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MakeDialog :: dropEvent( QDropEvent * event )
|
||||||
|
{
|
||||||
|
const QString filename = event->mimeData()->urls().front().path();
|
||||||
|
const QFileInfo fileInfo( filename );
|
||||||
|
|
||||||
|
if( fileInfo.exists( ) )
|
||||||
|
{
|
||||||
|
if( fileInfo.isDir( ) )
|
||||||
|
{
|
||||||
|
myFolderRadio->setChecked( true );
|
||||||
|
onFolderSelected( filename );
|
||||||
|
}
|
||||||
|
else // it's a file
|
||||||
|
{
|
||||||
|
myFileRadio->setChecked( true );
|
||||||
|
onFileSelected( filename );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -44,10 +44,15 @@ class MakeDialog: public QDialog
|
||||||
void onProgress( );
|
void onProgress( );
|
||||||
|
|
||||||
void onFolderClicked( );
|
void onFolderClicked( );
|
||||||
|
void onFolderSelected( const QString& );
|
||||||
void onFolderSelected( const QStringList& );
|
void onFolderSelected( const QStringList& );
|
||||||
|
|
||||||
void onFileClicked( );
|
void onFileClicked( );
|
||||||
|
void onFileSelected( const QString& );
|
||||||
void onFileSelected( const QStringList& );
|
void onFileSelected( const QStringList& );
|
||||||
|
|
||||||
void onDestinationClicked( );
|
void onDestinationClicked( );
|
||||||
|
void onDestinationSelected( const QString& );
|
||||||
void onDestinationSelected( const QStringList& );
|
void onDestinationSelected( const QStringList& );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -80,6 +85,10 @@ class MakeDialog: public QDialog
|
||||||
QDialog * myNewDialog;
|
QDialog * myNewDialog;
|
||||||
struct tr_metainfo_builder * myBuilder;
|
struct tr_metainfo_builder * myBuilder;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void dragEnterEvent( QDragEnterEvent * );
|
||||||
|
virtual void dropEvent( QDropEvent * );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MakeDialog( Session&, QWidget * parent = 0 );
|
MakeDialog( Session&, QWidget * parent = 0 );
|
||||||
~MakeDialog( );
|
~MakeDialog( );
|
||||||
|
|
Loading…
Add table
Reference in a new issue