Add copy marked file to directory
This commit is contained in:
@@ -65,6 +65,20 @@ bool Database::isMarked(const QString &filename)
|
||||
return m_isMarkedQuery.next();
|
||||
}
|
||||
|
||||
QStringList Database::getMarkedFiles()
|
||||
{
|
||||
QSqlQuery markedFiles("SELECT * from files", m_database);
|
||||
|
||||
QStringList files;
|
||||
while(markedFiles.next())
|
||||
{
|
||||
files << markedFiles.value("file").toString();
|
||||
}
|
||||
|
||||
qDebug() << files.size();
|
||||
return files;
|
||||
}
|
||||
|
||||
bool Database::checkError()
|
||||
{
|
||||
QSqlError error = m_database.lastError();
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
bool mark(const QString &filename);
|
||||
bool unmark(const QString &filename);
|
||||
bool isMarked(const QString &filename);
|
||||
QStringList getMarkedFiles();
|
||||
protected:
|
||||
bool checkError();
|
||||
};
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressDialog>
|
||||
#include <QDebug>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/btrfs.h>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
|
||||
loading(false),
|
||||
@@ -24,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
|
||||
|
||||
QMenu *fileMenu = new QMenu(tr("File"), this);
|
||||
fileMenu->addAction(tr("Open"), this, SLOT(openFile()), QKeySequence("Ctrl+O"));
|
||||
fileMenu->addAction(tr("Copy marked files"), this, SLOT(copyMarked()));
|
||||
fileMenu->addAction(tr("Exit"), this, SLOT(close()));
|
||||
menuBar()->addMenu(fileMenu);
|
||||
|
||||
@@ -141,6 +146,43 @@ void MainWindow::unmarkAndNext()
|
||||
m_ringList->increment();
|
||||
}
|
||||
|
||||
void MainWindow::copyMarked()
|
||||
{
|
||||
QString dest = QFileDialog::getExistingDirectory(this, tr("Select destination"));
|
||||
QDir dir(dest);
|
||||
if(!dest.isEmpty() && dir.exists())
|
||||
{
|
||||
int i = 0;
|
||||
QStringList files = m_database->getMarkedFiles();
|
||||
QProgressDialog progress(tr("Copying"), tr("Cancel"), 0, files.size(), this);
|
||||
progress.setWindowModality(Qt::WindowModal);
|
||||
progress.show();
|
||||
foreach(const QString &file, files)
|
||||
{
|
||||
QFileInfo info(file);
|
||||
QFile srcFile(file);
|
||||
QFile dstFile(dir.absoluteFilePath(info.fileName()));
|
||||
|
||||
if(dstFile.exists())
|
||||
continue;
|
||||
|
||||
if(progress.wasCanceled())
|
||||
break;
|
||||
|
||||
srcFile.open(QIODevice::ReadOnly);
|
||||
dstFile.open(QIODevice::WriteOnly);
|
||||
if(ioctl(dstFile.handle(), BTRFS_IOC_CLONE, srcFile.handle()) < 0)
|
||||
{
|
||||
dstFile.remove();
|
||||
dstFile.close();
|
||||
qDebug() << dstFile.fileName();
|
||||
srcFile.copy(dstFile.fileName());
|
||||
}
|
||||
progress.setValue(i++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateWindowTitle()
|
||||
{
|
||||
ImagePtr ptr = m_ringList->currentImage();
|
||||
|
||||
@@ -28,6 +28,7 @@ protected slots:
|
||||
void unmarkImage();
|
||||
void markAndNext();
|
||||
void unmarkAndNext();
|
||||
void copyMarked();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
Reference in New Issue
Block a user