00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "DragDropListView.h"
00019
00020 #include "FileItem.h"
00021 #include "FileWindow.h"
00022 #include "RioCopy.h"
00023 #include "Events.h"
00024
00025 #include <qdragobject.h>
00026 #include <qmessagebox.h>
00027 #include <qapplication.h>
00028
00029 DragDropListView::DragDropListView( QWidget *parent,
00030 RioQt *rioQt,
00031 FileWindow *fileWindow )
00032 : QListView( parent, "DragDropListView", 0 )
00033 {
00034 this->rioQt = rioQt;
00035 this->fileWindow = fileWindow;
00036
00037 setAcceptDrops( true );
00038 viewport()->setAcceptDrops( true );
00039 }
00040
00041
00042
00043
00044
00045
00046 void DragDropListView::contentsDropEvent( QDropEvent *event )
00047 {
00048 QStringList *source;
00049 FileItem *dest;
00050 FileWindow *sourceFileWindow;
00051 QString destFileName;
00052
00053
00054 QByteArray byteArray = event->encodedData( "SelectedItems" );
00055 source = (QStringList *)byteArray.data();
00056
00057 dest = (FileItem *)currentItem();
00058
00059 if( dest == NULL )
00060 dest = fileWindow->getCurrentDir();
00061
00062
00063
00064 if( dest->isDir() )
00065 destFileName = dest->getFileName();
00066 else
00067 destFileName = fileWindow->getCurrentDir()->getFileName();
00068
00069 sourceFileWindow = ((DragDropListView *)event->source())->getFileWindow();
00070
00071
00072 if( sourceFileWindow == fileWindow )
00073 {
00074
00075
00076
00077 for( QStringList::Iterator it = source->begin();
00078 it != source->end();
00079 ++it )
00080 {
00081
00082 QString full_dest_file = destFileName + "/"
00083 + (*it).section( '/', -1 );
00084
00085 if( !fileWindow->mv( (char *)(*it).ascii(),
00086 (char *)full_dest_file.ascii(),
00087 fileWindow->getSession(),
00088 true ) )
00089 {
00090 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00091 tr( "Could not move file" ) + " " +
00092 (*it) );
00093 QApplication::postEvent( this, event );
00094 }
00095 }
00096
00097
00098
00099
00100 fileWindow->refreshDirectory( fileWindow->getCurrentDir() );
00101 }
00102 else
00103 {
00104 RioCopy *rioCopy;
00105 rioCopy = new RioCopy( rioQt,
00106 (RioExplorer *)fileWindow,
00107 sourceFileWindow->getSession(),
00108 fileWindow->getSession(),
00109 source,
00110 destFileName,
00111 fileWindow );
00112 fileWindow->appendCopy( rioCopy );
00113
00114 if( !rioCopy->doCopy() )
00115 {
00116 ShowMessageEvent *event;
00117 event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00118 tr( "There was an error with the copy!" ),
00119 tr( "Error" ) );
00120 QApplication::sendEvent( rioQt, event );
00121 delete event;
00122 }
00123
00124 fileWindow->removeCopy( rioCopy );
00125 }
00126 }
00127
00128
00129
00130
00131
00132 void DragDropListView::startDrag( void )
00133 {
00134
00135 QStringList *selected_items = getSelectedFileNames();
00136 QByteArray *byteArray = new QByteArray();
00137 byteArray->setRawData( (char *)selected_items,
00138 sizeof( QStringList * ) );
00139
00140 QStoredDrag *dragObject = new QStoredDrag( "SelectedItems", this );
00141 dragObject->setEncodedData( *byteArray );
00142 dragObject->dragCopy();
00143 }
00144
00145
00146
00147
00148 FileWindow *DragDropListView::getFileWindow( void )
00149 {
00150 return fileWindow;
00151 }
00152
00153
00154
00155
00156 QStringList *DragDropListView::getSelectedFileNames( void )
00157 {
00158 QStringList *selected_list = new QStringList();
00159 selected_list->clear();
00160
00161 QListViewItemIterator it( this );
00162 while( it.current() )
00163 {
00164 if( isSelected( it.current() ) )
00165 selected_list->append( ((FileItem *)it.current())->getFileName() );
00166
00167 it++;
00168 }
00169
00170 return selected_list;
00171 }
00172
00173
00174
00175
00176 QPtrList<FileItem> DragDropListView::getSelectedFileItems( void )
00177 {
00178 QPtrList<FileItem> selected_list;
00179 selected_list.clear();
00180
00181 QListViewItemIterator it( this );
00182 while( it.current() )
00183 {
00184 if( isSelected( it.current() ) )
00185 selected_list.append( (FileItem *)it.current() );
00186
00187 it++;
00188 }
00189
00190 return selected_list;
00191 }