Skip to content

Commit

Permalink
Merge 7ed5af0 into 1132497
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Nov 22, 2018
2 parents 1132497 + 7ed5af0 commit c89f261
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
34 changes: 1 addition & 33 deletions src/plugins/miscellaneous/Core/src/centralwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,41 +1548,9 @@ void CentralWidget::dragMoveEvent(QDragMoveEvent *pEvent)

void CentralWidget::dropEvent(QDropEvent *pEvent)
{
// Retrieve the name of the various files that have been dropped

QList<QUrl> urlList = pEvent->mimeData()->urls();
QStringList fileNames;

for (int i = 0, iMax = urlList.count(); i < iMax; ++i)
{
QString fileName = urlList[i].toLocalFile();
QFileInfo fileInfo = fileName;

if (fileInfo.isFile()) {
if (fileInfo.isSymLink()) {
// We are dropping a symbolic link, so retrieve its target and
// check that it exists, and if it does then add it

fileName = fileInfo.symLinkTarget();

if (QFile::exists(fileName))
fileNames << fileName;
} else {
// We are dropping a file, so we can just add it

fileNames << fileName;
}
}
}

// fileNames may contain duplicates (in case we dropped some symbolic
// links), so remove them

fileNames.removeDuplicates();

// Open the various files

openFiles(fileNames);
openFiles(droppedFileNames(pEvent));

// Accept the proposed action for the event

Expand Down
41 changes: 41 additions & 0 deletions src/plugins/miscellaneous/Core/src/corecliutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QChar>
#include <QCryptographicHash>
#include <QDir>
#include <QDropEvent>
#include <QIODevice>
#include <QLocale>
#include <QMap>
#include <QMimeData>
#include <QNetworkAccessManager>
#include <QNetworkInterface>
#include <QNetworkReply>
Expand Down Expand Up @@ -926,6 +928,45 @@ QStringList filters(const FileTypeInterfaces &pFileTypeInterfaces,

//==============================================================================

QStringList droppedFileNames(QDropEvent *pEvent)
{
// Retrieve the name of the various files that have been dropped

QStringList res = QStringList();
QList<QUrl> urls = pEvent->mimeData()->urls();

for (int i = 0, iMax = urls.count(); i < iMax; ++i)
{
QString fileName = urls[i].toLocalFile();
QFileInfo fileInfo = fileName;

if (fileInfo.isFile()) {
if (fileInfo.isSymLink()) {
// We are dropping a symbolic link, so retrieve its target and
// check that it exists, and if it does then add it

fileName = fileInfo.symLinkTarget();

if (QFile::exists(fileName))
res << fileName;
} else {
// We are dropping a file, so we can just add it

res << fileName;
}
}
}

// There may be duplicates (in case we dropped some symbolic links), so
// remove them

res.removeDuplicates();

return res;
}

//==============================================================================

} // namespace Core
} // namespace OpenCOR

Expand Down
3 changes: 3 additions & 0 deletions src/plugins/miscellaneous/Core/src/corecliutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ QVariantList CORE_EXPORT qIntListToVariantList(const QIntList &pIntList);

//==============================================================================

class QDropEvent;
class QNetworkReply;

//==============================================================================
Expand Down Expand Up @@ -168,6 +169,8 @@ QStringList CORE_EXPORT filters(const FileTypeInterfaces &pFileTypeInterfaces);
QStringList CORE_EXPORT filters(const FileTypeInterfaces &pFileTypeInterfaces,
const QString &pMimeType);

QStringList CORE_EXPORT droppedFileNames(QDropEvent *pEvent);

//==============================================================================

} // namespace Core
Expand Down

0 comments on commit c89f261

Please sign in to comment.