diff options
-rw-r--r-- | lumina-fm/FODialog.cpp | 10 | ||||
-rw-r--r-- | lumina-fm/MainUI.cpp | 6 | ||||
-rw-r--r-- | lumina-fm/widgets/DDListWidgets.h | 106 |
3 files changed, 74 insertions, 48 deletions
diff --git a/lumina-fm/FODialog.cpp b/lumina-fm/FODialog.cpp index 4f4ca838..5d20e3be 100644 --- a/lumina-fm/FODialog.cpp +++ b/lumina-fm/FODialog.cpp @@ -108,6 +108,16 @@ bool FODialog::MoveFiles(QStringList oldPaths, QStringList newPaths){ bool FODialog::CheckOverwrite(){ bool ok = true; + //Quick check that a file is not supposed to be moved/copied/restored onto itself + if(!Worker->isRM){ + for(int i=0; i<Worker->nfiles.length(); i++){ + if(Worker->nfiles[i] == Worker->ofiles[i]){ + //duplicate - remove it from the queue + Worker->nfiles.removeAt(i); Worker->ofiles.removeAt(i); + i--; + } + } + } if(!Worker->isRM && Worker->overwrite==-1){ //Check if the new files already exist, and prompt for action QStringList existing; diff --git a/lumina-fm/MainUI.cpp b/lumina-fm/MainUI.cpp index 061a9758..dbffdfc7 100644 --- a/lumina-fm/MainUI.cpp +++ b/lumina-fm/MainUI.cpp @@ -641,13 +641,16 @@ void MainUI::CutFiles(QStringList list){ qDebug() << "Cut Files:" << list; if(list.isEmpty()){ return; } //nothing selected //Format the data string + QList<QUrl> urilist; //Also assemble a URI list for cros-app compat (no copy/cut distinguishing) for(int i=0; i<list.length(); i++){ + urilist << QUrl::fromLocalFile(list[i]); list[i] = list[i].prepend("cut::::"); } //Now save that data to the global clipboard QMimeData *dat = new QMimeData; dat->clear(); dat->setData("x-special/lumina-copied-files", list.join("\n").toLocal8Bit()); + dat->setUrls(urilist); //the text/uri-list mimetype - built in Qt conversion/use QApplication::clipboard()->clear(); QApplication::clipboard()->setMimeData(dat); //Update all the buttons to account for clipboard change @@ -658,13 +661,16 @@ void MainUI::CopyFiles(QStringList list){ qDebug() << "Copy Files:" << list; if(list.isEmpty()){ return; } //nothing selected //Format the data string + QList<QUrl> urilist; //Also assemble a URI list for cros-app compat (no copy/cut distinguishing) for(int i=0; i<list.length(); i++){ + urilist << QUrl::fromLocalFile(list[i]); list[i] = list[i].prepend("copy::::"); } //Now save that data to the global clipboard QMimeData *dat = new QMimeData; dat->clear(); dat->setData("x-special/lumina-copied-files", list.join("\n").toLocal8Bit()); + dat->setUrls(urilist); //the text/uri-list mimetype - built in Qt conversion/use QApplication::clipboard()->clear(); QApplication::clipboard()->setMimeData(dat); //Update all the buttons to account for clipboard change diff --git a/lumina-fm/widgets/DDListWidgets.h b/lumina-fm/widgets/DDListWidgets.h index 2d885192..67b54b4d 100644 --- a/lumina-fm/widgets/DDListWidgets.h +++ b/lumina-fm/widgets/DDListWidgets.h @@ -21,6 +21,7 @@ #include <QFileInfo> #include <QDebug> #include <QMouseEvent> +#include <QUrl> //============== // LIST WIDGET @@ -51,47 +52,42 @@ protected: void startDrag(Qt::DropActions act){ QList<QListWidgetItem*> items = this->selectedItems(); if(items.length()<1){ return; } - QStringList info; - for(int i=0; i<items.length(); i++){ info << items[i]->whatsThis(); } + QList<QUrl> urilist; + for(int i=0; i<items.length(); i++){ + urilist << QUrl::fromLocalFile(items[i]->whatsThis().section("::::",1,100)); + } //Create the mime data QMimeData *mime = new QMimeData; - mime->setData(MIME,info.join("\n").toLocal8Bit()); + mime->setUrls(urilist); //Create the drag structure QDrag *drag = new QDrag(this); drag->setMimeData(mime); - drag->exec(act | Qt::MoveAction | Qt::CopyAction); + /*if(info.first().section("::::",0,0)=="cut"){ + drag->exec(act | Qt::MoveAction); + }else{*/ + drag->exec(act | Qt::CopyAction); + //} } void dragEnterEvent(QDragEnterEvent *ev){ //qDebug() << "Drag Enter Event:" << ev->mimeData()->hasFormat(MIME); - if(ev->mimeData()->hasFormat(MIME) && !this->whatsThis().isEmpty() ){ - //qDebug() << "Accepted:" << ev->mimeData()->data(MIME); - if(QString(ev->mimeData()->data(MIME)).section("::::",0,0)=="cut"){ - ev->setDropAction(Qt::MoveAction); - }else{ - ev->setDropAction(Qt::CopyAction); - } - ev->accept(); //allow this to be dropped here + if(ev->mimeData()->hasUrls() && !this->whatsThis().isEmpty() ){ + ev->acceptProposedAction(); //allow this to be dropped here + }else{ + ev->ignore(); } } void dragMoveEvent(QDragMoveEvent *ev){ - //qDebug() << "Drag Move Event:" << ev->mimeData()->hasFormat(MIME); - if(ev->mimeData()->hasFormat(MIME) && !this->whatsThis().isEmpty()){ - //qDebug() << "Accepted:" << ev->mimeData()->data(MIME); - if(QString(ev->mimeData()->data(MIME)).section("::::",0,0)=="cut"){ - ev->setDropAction(Qt::MoveAction); - }else{ - ev->setDropAction(Qt::CopyAction); - } - ev->accept(); //allow this to be dropped here + if(ev->mimeData()->hasUrls() && !this->whatsThis().isEmpty() ){ + ev->acceptProposedAction(); //allow this to be dropped here }else{ ev->ignore(); - } + } } void dropEvent(QDropEvent *ev){ - if(this->whatsThis().isEmpty()){ ev->ignore(); return; } //not supported + if(this->whatsThis().isEmpty() || !ev->mimeData()->hasUrls() ){ ev->ignore(); return; } //not supported //qDebug() << "Drop Event:"; ev->accept(); //handled here QString dirpath = this->whatsThis(); @@ -103,8 +99,16 @@ protected: dirpath = info.absoluteFilePath(); } } + //Now turn the input urls into local file paths + QStringList files; + foreach(const QUrl &url, ev->mimeData()->urls()){ + const QString filepath = url.toLocalFile(); + //If the target file is modifiable, assume a move - otherwise copy + if(QFileInfo(filepath).isWritable()){ files << "cut::::"+filepath; } + else{ files << "copy::::"+filepath; } + } //qDebug() << "Drop Event:" << dirpath; - emit DataDropped( dirpath, QString(ev->mimeData()->data(MIME)).split("\n") ); + emit DataDropped( dirpath, files ); } void mouseReleaseEvent(QMouseEvent *ev){ @@ -150,45 +154,42 @@ protected: void startDrag(Qt::DropActions act){ QList<QTreeWidgetItem*> items = this->selectedItems(); if(items.length()<1){ return; } - QStringList info; - for(int i=0; i<items.length(); i++){ info << items[i]->whatsThis(0); } + QList<QUrl> urilist; + for(int i=0; i<items.length(); i++){ + urilist << QUrl::fromLocalFile(items[i]->whatsThis(0).section("::::",1,100)); + } //Create the mime data QMimeData *mime = new QMimeData; - mime->setData(MIME,info.join("\n").toLocal8Bit()); + mime->setUrls(urilist); //Create the drag structure QDrag *drag = new QDrag(this); drag->setMimeData(mime); - drag->exec(act | Qt::MoveAction | Qt::CopyAction); + /*if(info.first().section("::::",0,0)=="cut"){ + drag->exec(act | Qt::MoveAction); + }else{*/ + drag->exec(act | Qt::CopyAction| Qt::MoveAction); + //} } void dragEnterEvent(QDragEnterEvent *ev){ //qDebug() << "Drag Enter Event:" << ev->mimeData()->hasFormat(MIME); - if(ev->mimeData()->hasFormat(MIME) && !this->whatsThis().isEmpty() ){ - //qDebug() << "Accepted:" << ev->mimeData()->data(MIME); - if(QString(ev->mimeData()->data(MIME)).section("::::",0,0)=="cut"){ - ev->setDropAction(Qt::MoveAction); - }else{ - ev->setDropAction(Qt::CopyAction); - } - ev->accept(); //allow this to be dropped here + if(ev->mimeData()->hasUrls() && !this->whatsThis().isEmpty() ){ + ev->acceptProposedAction(); //allow this to be dropped here + }else{ + ev->ignore(); } } void dragMoveEvent(QDragMoveEvent *ev){ - //qDebug() << "Drag Move Event:" << ev->mimeData()->hasFormat(MIME); - if(ev->mimeData()->hasFormat(MIME) && !this->whatsThis().isEmpty()){ - //qDebug() << "Accepted:" << ev->mimeData()->data(MIME); - if(QString(ev->mimeData()->data(MIME)).section("::::",0,0)=="cut"){ - ev->setDropAction(Qt::MoveAction); - }else{ - ev->setDropAction(Qt::CopyAction); - } - ev->accept(); //allow this to be dropped here - } + if(ev->mimeData()->hasUrls() && !this->whatsThis().isEmpty() ){ + ev->acceptProposedAction(); //allow this to be dropped here + }else{ + ev->ignore(); + } } void dropEvent(QDropEvent *ev){ - if(this->whatsThis().isEmpty()){ return; } //not supported + if(this->whatsThis().isEmpty() || !ev->mimeData()->hasUrls() ){ ev->ignore(); return; } //not supported ev->accept(); //handled here QString dirpath = this->whatsThis(); //See if the item under the drop point is a directory or not @@ -200,7 +201,16 @@ protected: } } //qDebug() << "Drop Event:" << dirpath; - emit DataDropped( dirpath, QString(ev->mimeData()->data(MIME)).split("\n") ); + //Now turn the input urls into local file paths + QStringList files; + foreach(const QUrl &url, ev->mimeData()->urls()){ + const QString filepath = url.toLocalFile(); + //If the target file is modifiable, assume a move - otherwise copy + if(QFileInfo(filepath).isWritable()){ files << "cut::::"+filepath; } + else{ files << "copy::::"+filepath; } + } + //qDebug() << "Drop Event:" << dirpath; + emit DataDropped( dirpath, files ); } void mouseReleaseEvent(QMouseEvent *ev){ |