diff --git a/YACReaderLibrary/db/tablemodel.cpp b/YACReaderLibrary/db/tablemodel.cpp index 62b8f1d3..0a8a3be2 100644 --- a/YACReaderLibrary/db/tablemodel.cpp +++ b/YACReaderLibrary/db/tablemodel.cpp @@ -433,4 +433,20 @@ QModelIndex TableModel::getIndexFromId(quint64 id) } return index(i,0); +} + +void TableModel::remove(ComicDB * comic, int row) +{ + beginRemoveRows(QModelIndex(),row,row); + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + DBHelper::removeFromDB(comic,db); + + removeRow(row); + delete _data.at(row); + _data.removeAt(row); + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endRemoveRows(); } \ No newline at end of file diff --git a/YACReaderLibrary/db/tablemodel.h b/YACReaderLibrary/db/tablemodel.h index 62b80960..ecd9d945 100644 --- a/YACReaderLibrary/db/tablemodel.h +++ b/YACReaderLibrary/db/tablemodel.h @@ -45,6 +45,7 @@ public: //setComicInfoForSelectedComis(QList list); -->inserta la información común para los comics seleccionados QVector setComicsRead(QList list,bool read); qint64 asignNumbers(QList list,int startingNumber); + void remove(ComicDB * comic, int row); private: void setupModelData( QSqlQuery &sqlquery); ComicDB _getComic(const QModelIndex & mi); diff --git a/YACReaderLibrary/images.qrc b/YACReaderLibrary/images.qrc index c5a2bafa..ad413386 100644 --- a/YACReaderLibrary/images.qrc +++ b/YACReaderLibrary/images.qrc @@ -70,5 +70,6 @@ ../images/readRibbon.png ../images/shownCovers.png ../images/hiddenCovers.png + ../images/trash.png \ No newline at end of file diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index fc13d04f..001357d9 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -477,6 +477,10 @@ void LibraryWindow::createActions() forceConverExtractedAction->setText(tr("Update cover")); forceConverExtractedAction->setIcon(QIcon(":/images/importCover.png")); + deleteComicsAction = new QAction(this); + deleteComicsAction->setText(tr("Delete selected comics")); + deleteComicsAction->setIcon(QIcon(":/images/trash.png")); + hideComicViewAction = new QAction(this); hideComicViewAction->setText(tr("Hide comic flow")); hideComicViewAction->setIcon(QIcon(":/images/hideComicFlow.png")); @@ -620,6 +624,10 @@ void LibraryWindow::createToolBars() editInfoToolBar->addAction(showHideMarksAction); + editInfoToolBar->addSeparator(); + + editInfoToolBar->addAction(deleteComicsAction); + editInfoToolBar->addWidget(new QToolBarStretch()); editInfoToolBar->addAction(hideComicViewAction); @@ -734,6 +742,8 @@ void LibraryWindow::createConnections() connect(editSelectedComicsAction,SIGNAL(triggered()),this,SLOT(showProperties())); connect(asignOrderActions,SIGNAL(triggered()),this,SLOT(asignNumbers())); + connect(deleteComicsAction,SIGNAL(triggered()),this,SLOT(deleteComics())); + connect(hideComicViewAction, SIGNAL(toggled(bool)),this, SLOT(hideComicFlow(bool))); } @@ -1475,4 +1485,25 @@ QModelIndexList LibraryWindow::getSelectedComics() selection = comicView->selectionModel()->selectedRows(); } return selection; +} + +void LibraryWindow::deleteComics() +{ + //TODO move this to another thread + QModelIndexList indexList = getSelectedComics(); + + QString currentComicPath; + QListIterator i(indexList); + i.toBack(); + while (i.hasPrevious()) + { + QModelIndex mi = i.previous(); + ComicDB comic = dmCV->getComic(mi); + currentComicPath = currentPath() + comic.path; + if(QFile::remove(currentComicPath)) + { + dmCV->remove(&comic,mi.row()); + comicFlow->remove(mi.row()); + } + } } \ No newline at end of file diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 18254aa3..df63ec0a 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -139,6 +139,7 @@ private: QAction * editSelectedComicsAction; QAction * asignOrderActions; QAction * forceConverExtractedAction; + QAction * deleteComicsAction; QAction * hideComicViewAction; @@ -233,6 +234,7 @@ public: void manageUpdatingError(const QString & error); void manageOpeningLibraryError(const QString & error); QModelIndexList getSelectedComics(); + void deleteComics(); }; #endif diff --git a/images/trash.png b/images/trash.png new file mode 100644 index 00000000..e4e7b075 Binary files /dev/null and b/images/trash.png differ