DragDropListView Class Reference

#include <DragDropListView.h>

Public Member Functions

 DragDropListView (QWidget *, RioQt *, FileWindow *)
QPtrList< FileItemgetSelectedFileItems (void)
 Returns the FileItems selected in this listview.
FileWindowgetFileWindow (void)
 Returns the FileWindow.
void appendCopy (RioCopy *)
void removeCopy (RioCopy *)

Protected Member Functions

void contentsDropEvent (QDropEvent *)
 Handles the drop event Copy an item between two distinct FileWindow Move an item inside a RIOFileWindow.
QStringList * getSelectedFileNames (void)
 Returns the name of the FileItems selected in this listview.
void startDrag (void)
 Starts a drag action Packs the selected FileItems inside the dragged object.

Protected Attributes

RioQtrioQt
FileWindowfileWindow

Detailed Description

Definition at line 28 of file DragDropListView.h.


Constructor & Destructor Documentation

DragDropListView::DragDropListView ( QWidget *  parent,
RioQt rioQt,
FileWindow fileWindow 
)

Definition at line 29 of file DragDropListView.cpp.

00032                  : QListView( parent, "DragDropListView", 0 )
00033 {
00034     this->rioQt      = rioQt;
00035     this->fileWindow = fileWindow;
00036 
00037     setAcceptDrops( true );
00038     viewport()->setAcceptDrops( true );
00039 }


Member Function Documentation

void DragDropListView::appendCopy ( RioCopy  ) 
void DragDropListView::contentsDropEvent ( QDropEvent *  event  )  [protected]

Handles the drop event Copy an item between two distinct FileWindow Move an item inside a RIOFileWindow.

Definition at line 46 of file DragDropListView.cpp.

00047 {
00048     QStringList *source;
00049     FileItem    *dest;
00050     FileWindow  *sourceFileWindow;
00051     QString      destFileName;
00052 
00053     // Decode dragged data
00054     QByteArray byteArray = event->encodedData( "SelectedItems" );
00055     source = (QStringList *)byteArray.data();
00056 
00057     dest = (FileItem *)currentItem();
00058     // User dropped a blank area, will copy the the current directory
00059     if( dest == NULL )
00060         dest = fileWindow->getCurrentDir();
00061 
00062     // If dest is a directory, will copy to it
00063     // Otherwise, will copy to the current directory
00064     if( dest->isDir() )
00065         destFileName = dest->getFileName();
00066     else
00067         destFileName = fileWindow->getCurrentDir()->getFileName();
00068 
00069     sourceFileWindow = ((DragDropListView *)event->source())->getFileWindow();
00070 
00071     // Drop in the same FileWindow
00072     if( sourceFileWindow == fileWindow )
00073     {
00074         // Move all selected files to another location
00075         // in the current RIO server
00076         
00077             for( QStringList::Iterator it = source->begin();
00078                  it != source->end();
00079                  ++it )
00080             {
00081                 // Append filename to destination directory
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             // Refresh directory contents
00098             // This is not necessary in the copy case, since RioCopy object
00099             // will do it for us
00100             fileWindow->refreshDirectory( fileWindow->getCurrentDir() );
00101     }
00102     else     // Drop in another FileWindow
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 }

FileWindow * DragDropListView::getFileWindow ( void   ) 

Returns the FileWindow.

Definition at line 148 of file DragDropListView.cpp.

00149 {
00150     return fileWindow;
00151 }

QPtrList< FileItem > DragDropListView::getSelectedFileItems ( void   ) 

Returns the FileItems selected in this listview.

Definition at line 176 of file DragDropListView.cpp.

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 }

QStringList * DragDropListView::getSelectedFileNames ( void   )  [protected]

Returns the name of the FileItems selected in this listview.

Definition at line 156 of file DragDropListView.cpp.

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 }

void DragDropListView::removeCopy ( RioCopy  ) 
void DragDropListView::startDrag ( void   )  [protected]

Starts a drag action Packs the selected FileItems inside the dragged object.

Definition at line 132 of file DragDropListView.cpp.

00133 {
00134     // Storing data
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 }


Field Documentation

Definition at line 34 of file DragDropListView.h.

Definition at line 33 of file DragDropListView.h.


The documentation for this class was generated from the following files:
Generated on Wed Jul 4 16:03:34 2012 for RIO by  doxygen 1.6.3