Add support for deleting videos

.. but only deletes references and db entry
.. we do not delete from the filesystem -- need to add a dialog
   to ask the user to confirm deleting the file from disk.
This commit is contained in:
Mark Liversedge
2013-03-07 15:23:43 +00:00
parent 0104c32440
commit bc191cc5fb
6 changed files with 68 additions and 0 deletions

View File

@@ -196,6 +196,17 @@ Library::importFiles(MainWindow *mainWindow, QStringList files)
}
}
void
Library::removeRef(MainWindow *mainWindow, QString ref)
{
// remove a previous reference
int index = refs.indexOf(ref);
if (index >= 0) {
refs.removeAt(index);
LibraryParser::serialize(mainWindow->home);
}
}
//
// SEARCHDIALOG -- user select paths and files and run a search
//

View File

@@ -41,6 +41,7 @@ class Library : QObject
static void initialise(QDir); // init
static Library *findLibrary(QString);
static void importFiles(MainWindow *mainWindow, QStringList files);
void removeRef(MainWindow *mainWindow, QString ref);
};
extern QList<Library *> libraries; // keep track of all Library search paths for all users

View File

@@ -350,6 +350,17 @@ bool TrainDB::importWorkout(QString pathname, ErgFile *ergFile)
return rc;
}
bool TrainDB::deleteVideo(QString pathname)
{
QSqlQuery query(dbconn);
QDateTime timestamp = QDateTime::currentDateTime();
// zap the current row - if there is one
query.prepare("DELETE FROM videos WHERE filepath = ?;");
query.addBindValue(pathname);
return query.exec();
}
bool TrainDB::importVideo(QString pathname)
{
QSqlQuery query(dbconn);

View File

@@ -54,6 +54,7 @@ class TrainDB : public QObject
bool deleteWorkout(QString pathname);
bool importVideo(QString pathname);
bool deleteVideo(QString pathname);
// drop and recreate tables
void rebuildDB();

View File

@@ -52,6 +52,7 @@
#include <math.h> // isnan and isinf
#include "TrainDB.h"
#include "Library.h"
TrainTool::TrainTool(MainWindow *parent, const QDir &home) : GcWindow(parent), home(home), main(parent)
{
@@ -461,6 +462,15 @@ TrainTool::mediaPopup()
connect(import, SIGNAL(triggered(void)), main, SLOT(importWorkout(void)));
connect(scan, SIGNAL(triggered(void)), main, SLOT(manageLibrary(void)));
QModelIndex current = mediaTree->currentIndex();
QModelIndex target = vsortModel->mapToSource(current);
QString filename = videoModel->data(videoModel->index(target.row(), 0), Qt::DisplayRole).toString();
if (QFileInfo(filename).exists()) {
QAction *del = new QAction(tr("Delete selected video"), workoutTree);
menu.addAction(del);
connect(del, SIGNAL(triggered(void)), this, SLOT(deleteVideos(void)));
}
// execute the menu
menu.exec(trainSplitter->mapToGlobal(QPoint(mediaItem->pos().x()+mediaItem->width()-20,
mediaItem->pos().y())));
@@ -654,6 +664,39 @@ TrainTool::listWorkoutFiles(const QDir &dir) const
return dir.entryList(filters, QDir::Files, QDir::Name);
}
void
TrainTool::deleteVideos()
{
QModelIndex current = mediaTree->currentIndex();
QModelIndex target = vsortModel->mapToSource(current);
QString filename = videoModel->data(videoModel->index(target.row(), 0), Qt::DisplayRole).toString();
if (QFileInfo(filename).exists()) {
// are you sure?
QMessageBox msgBox;
msgBox.setText(tr("Are you sure you want to delete this video?"));
msgBox.setInformativeText(filename);
QPushButton *deleteButton = msgBox.addButton(tr("Delete"),QMessageBox::YesRole);
msgBox.setStandardButtons(QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
if(msgBox.clickedButton() != deleteButton) return;
// delete from disk
//XXX QFile(filename).remove(); // lets not for now..
// remove any reference (from drag and drop)
Library *l = Library::findLibrary("Media Library");
if (l) l->removeRef(main, filename);
// delete from DB
trainDB->startLUW();
trainDB->deleteVideo(filename);
trainDB->endLUW();
}
}
void
TrainTool::deleteWorkouts()
{

View File

@@ -135,6 +135,7 @@ class TrainTool : public GcWindow
public slots:
void configChanged();
void deleteWorkouts(); // deletes selected workouts
void deleteVideos(); // deletes selected workouts
void Start(); // when start button is pressed
void Pause(); // when Paude is pressed