Skip to content

Commit bcddaee

Browse files
committed
Fix temp clipboard path
Fixes bad global temp path for clipboard cut/paste. Ref: #197
1 parent 0a42f22 commit bcddaee

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

fm/src/actiontriggers.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,14 @@ void MainWindow::cutFile() {
421421
modelList->addCutItems(fileList);
422422

423423
// Save a temp file to allow pasting in a different instance
424-
QFile tempFile(QDir::tempPath() + QString("/%1.temp").arg(APP));
425-
tempFile.open(QIODevice::WriteOnly);
426-
QDataStream out(&tempFile);
427-
out << fileList;
428-
tempFile.close();
424+
const QString clipboardFile = Common::getTempClipboardFile();
425+
if (!clipboardFile.isEmpty()) {
426+
QFile tempFile(clipboardFile);
427+
tempFile.open(QIODevice::WriteOnly);
428+
QDataStream out(&tempFile);
429+
out << fileList;
430+
tempFile.close();
431+
}
429432

430433
QApplication::clipboard()->setMimeData(modelView->mimeData(selList));
431434

fm/src/mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ void MainWindow::pasteClipboard() {
958958
else { newPath = pathEdit->itemText(0); }
959959

960960
// Check list of files that are to be cut
961-
QFile tempFile(QDir::tempPath() + "/" + APP + ".temp");
961+
QFile tempFile(Common::getTempClipboardFile());
962962
if (tempFile.exists()) {
963963
tempFile.open(QIODevice::ReadOnly);
964964
QDataStream out(&tempFile);

libfm/common.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,21 @@ QString Common::hasThumbnail(const QString &filename)
679679
}
680680
return QString();
681681
}
682+
683+
QString Common::getTempPath()
684+
{
685+
const QString path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
686+
qDebug() << "Temp folder" << path;
687+
QDir dir(path);
688+
if (!dir.exists()) {
689+
if (!dir.mkpath(path)) { return QString(); }
690+
}
691+
return path;
692+
}
693+
694+
QString Common::getTempClipboardFile()
695+
{
696+
const QString path = getTempPath();
697+
if (path.isEmpty()) { return QString(); }
698+
return QString("%1/clipboard.tmp").arg(path);
699+
}

libfm/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class Common
104104
static QString getXdgCacheHome();
105105
static QString getThumbnailHash(const QString &filename);
106106
static QString hasThumbnail(const QString &filename);
107+
static QString getTempPath();
108+
static QString getTempClipboardFile();
107109
};
108110

109111
#endif // COMMON_H

libfm/mymodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ void myModel::addCutItems(QStringList files)
14801480
void myModel::clearCutItems()
14811481
{
14821482
cutItems.clear();
1483-
QFile(QDir::tempPath() + QString("/%1.temp").arg(APP)).remove();
1483+
QFile temp(Common::getTempClipboardFile());
1484+
if (temp.exists()) { temp.remove(); }
14841485
}
14851486

0 commit comments

Comments
 (0)