Implement workaround for flatpak QFile::moveToTrash
This commit is contained in:
+5
-1
@@ -25,6 +25,7 @@ set(TENMON_SRC
|
||||
about.cpp
|
||||
database.cpp
|
||||
databaseview.cpp
|
||||
delete.cpp
|
||||
filesystemwidget.cpp
|
||||
imageinfo.cpp
|
||||
imageringlist.cpp
|
||||
@@ -63,6 +64,8 @@ elseif(APPLE)
|
||||
else()
|
||||
add_compile_definitions("__PCL_LINUX")
|
||||
set(tenmon_ICON "")
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_search_module(GIO REQUIRED gio-2.0)
|
||||
endif()
|
||||
|
||||
add_executable(tenmon WIN32 MACOSX_BUNDLE ${tenmon_ICON} ${TENMON_SRC})
|
||||
@@ -76,13 +79,14 @@ elseif(APPLE)
|
||||
target_link_directories(tenmon PRIVATE 3rdparty/lib/MacOS)
|
||||
else()
|
||||
target_link_directories(tenmon PRIVATE 3rdparty/lib/Linux)
|
||||
target_include_directories(tenmon PRIVATE ${GIO_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
target_link_libraries(tenmon Qt5::Widgets Qt5::Sql ${OpenCV_LIBS} ${GSL_LIB} ${GSLCBLAS_LIB} ${EXIF_LIB} ${FITS_LIB} ${RAW_LIB} ${WCS_LIB})
|
||||
if(APPLE)
|
||||
target_link_libraries(tenmon PCL-pxi lcms-pxi lz4-pxi RFC6234-pxi zlib-pxi "-framework CoreFoundation")
|
||||
else()
|
||||
target_link_libraries(tenmon PCL lcms lz4 RFC6234 zlib)
|
||||
target_link_libraries(tenmon PCL lcms lz4 RFC6234 zlib ${GIO_LDFLAGS})
|
||||
endif(APPLE)
|
||||
|
||||
if(LIBRAW_STATIC)
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#ifdef __linux__
|
||||
|
||||
#define QT_NO_KEYWORDS
|
||||
#include <QString>
|
||||
#include <iostream>
|
||||
#include <gio/gio.h>
|
||||
|
||||
//flatpak bug prevent to use QFile::moveToTrash
|
||||
bool moveToTrash(const QString &path)
|
||||
{
|
||||
GFile *gfile = g_file_new_for_path(path.toLocal8Bit().data());
|
||||
GError *error = nullptr;
|
||||
g_file_trash(gfile, nullptr, &error);
|
||||
if(error)std::cerr << "failed to trash file " << error->code << " " << error->message << std::endl;
|
||||
g_clear_error(&error);
|
||||
g_object_unref(gfile);
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
|
||||
bool moveToTrash(const QString &path)
|
||||
{
|
||||
return QFile::moveToTrash(path);
|
||||
}
|
||||
|
||||
#endif
|
||||
+4
-2
@@ -30,6 +30,8 @@
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
bool moveToTrash(const QString &path);
|
||||
|
||||
int MainWindow::socketPair[2] = {0, 0};
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
@@ -332,7 +334,7 @@ void MainWindow::copyOrMove(bool copy, const QString &dest)
|
||||
QProgressDialog progress(copy ? tr("Copying") : tr("Moving"), tr("Cancel"), 0, files.size(), this);
|
||||
progress.setWindowModality(Qt::WindowModal);
|
||||
progress.show();
|
||||
foreach(const QString &file, files)
|
||||
for(const QString &file : files)
|
||||
{
|
||||
bool result = false;
|
||||
QFileInfo info(file);
|
||||
@@ -571,7 +573,7 @@ void MainWindow::deleteMarked()
|
||||
if(progress.wasCanceled())
|
||||
return;
|
||||
|
||||
if(!QFile::moveToTrash(file))
|
||||
if(!moveToTrash(file))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Failed to move file to trash"), tr("Failed to move file to trash %1").arg(file));
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user