From 8c496ec89327c73ee6e2cb9a61476002b2150192 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 23 Sep 2015 14:18:49 -0400 Subject: Clean up the file transfer systems a bit in lumina-fm: 1) When copying/cutting files, also place a copy of the file list into the standard text/uri-list mimetype (with the local file URL syntax: file://) - This allows the files to be seen by other applications (if supported) 2) Also update the drag/drop functionality to use the standard text/uri-list format for all drag/drop operations. This allows movement of files between apps (such as moving a local file into a web-based file paste site). --- lumina-fm/FODialog.cpp | 10 ++++ lumina-fm/MainUI.cpp | 6 +++ lumina-fm/widgets/DDListWidgets.h | 106 +++++++++++++++++++++----------------- 3 files changed, 74 insertions(+), 48 deletions(-) (limited to 'lumina-fm') 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; infiles.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 urilist; //Also assemble a URI list for cros-app compat (no copy/cut distinguishing) for(int i=0; iclear(); 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 urilist; //Also assemble a URI list for cros-app compat (no copy/cut distinguishing) for(int i=0; iclear(); 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 #include #include +#include //============== // LIST WIDGET @@ -51,47 +52,42 @@ protected: void startDrag(Qt::DropActions act){ QList items = this->selectedItems(); if(items.length()<1){ return; } - QStringList info; - for(int i=0; iwhatsThis(); } + QList urilist; + for(int i=0; iwhatsThis().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 items = this->selectedItems(); if(items.length()<1){ return; } - QStringList info; - for(int i=0; iwhatsThis(0); } + QList urilist; + for(int i=0; iwhatsThis(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){ -- cgit