mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added support for deleting folders
This commit is contained in:
parent
e6620a46ed
commit
a8ef8d07f1
@ -1,13 +1,16 @@
|
||||
#include "comics_remover.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
|
||||
ComicsRemover::ComicsRemover(QModelIndexList & il, QList<QString> & ps, QObject *parent) :
|
||||
QThread(parent),indexList(il), paths(ps)
|
||||
#include "QsLog.h"
|
||||
|
||||
ComicsRemover::ComicsRemover(QModelIndexList & il, QList<QString> & ps, QObject *parent)
|
||||
:QObject(parent),indexList(il), paths(ps)
|
||||
{
|
||||
}
|
||||
|
||||
void ComicsRemover::run()
|
||||
void ComicsRemover::process()
|
||||
{
|
||||
QString currentComicPath;
|
||||
QListIterator<QModelIndex> i(indexList);
|
||||
@ -27,3 +30,34 @@ void ComicsRemover::run()
|
||||
|
||||
emit finished();
|
||||
}
|
||||
|
||||
|
||||
FoldersRemover::FoldersRemover(QModelIndexList &il, QList<QString> &ps, QObject *parent)
|
||||
:QObject(parent),indexList(il), paths(ps)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoldersRemover::process()
|
||||
{
|
||||
QString currentFolderPath;
|
||||
QListIterator<QModelIndex> i(indexList);
|
||||
QListIterator<QString> i2(paths);
|
||||
i.toBack();
|
||||
i2.toBack();
|
||||
|
||||
QLOG_DEBUG() << "Deleting folders" << paths.at(0);
|
||||
|
||||
while (i.hasPrevious() && i2.hasPrevious())
|
||||
{
|
||||
QModelIndex mi = i.previous();
|
||||
currentFolderPath = i2.previous();
|
||||
QDir d(currentFolderPath);
|
||||
if(d.removeRecursively() || !d.exists()) //the folder is in the DB but no in the drive...
|
||||
emit remove(mi);
|
||||
else
|
||||
emit removeError();
|
||||
}
|
||||
|
||||
emit finished();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <QModelIndex>
|
||||
#include <comic_db.h>
|
||||
|
||||
class ComicsRemover : public QThread
|
||||
class ComicsRemover : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -17,12 +17,31 @@ signals:
|
||||
void removeError();
|
||||
void finished();
|
||||
|
||||
private:
|
||||
void run();
|
||||
public slots:
|
||||
void process();
|
||||
|
||||
private:
|
||||
QModelIndexList indexList;
|
||||
QList<QString> paths;
|
||||
};
|
||||
|
||||
class FoldersRemover : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FoldersRemover(QModelIndexList & indexList, QList<QString> & paths, QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
void remove(QModelIndex);
|
||||
void removeError();
|
||||
void finished();
|
||||
|
||||
public slots:
|
||||
void process();
|
||||
|
||||
private:
|
||||
QModelIndexList indexList;
|
||||
QList<QString> paths;
|
||||
};
|
||||
|
||||
#endif // COMICS_REMOVER_H
|
||||
|
@ -68,6 +68,11 @@ void TreeItem::setData(int column, const QVariant & value)
|
||||
itemData[column] = value;
|
||||
}
|
||||
|
||||
void TreeItem::removeChild(int childIndex)
|
||||
{
|
||||
childItems.removeAt(childIndex);
|
||||
}
|
||||
|
||||
void TreeItem::clearChildren()
|
||||
{
|
||||
qDeleteAll(childItems);
|
||||
|
@ -65,6 +65,7 @@ public:
|
||||
QList<QString> comicNames;
|
||||
TreeItem * originalItem;
|
||||
void setData(int column, const QVariant &value);
|
||||
void removeChild(int childIndex);
|
||||
void clearChildren();
|
||||
QList<TreeItem*> children();
|
||||
private:
|
||||
|
@ -621,3 +621,22 @@ void TreeModel::fetchMoreFromDB(const QModelIndex &parent)
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
}
|
||||
|
||||
void TreeModel::deleteFolder(const QModelIndex &mi)
|
||||
{
|
||||
beginRemoveRows(mi.parent(),mi.row(),mi.row());
|
||||
|
||||
TreeItem * item = static_cast<TreeItem*>(mi.internalPointer());
|
||||
|
||||
TreeItem * parent = item->parent();
|
||||
parent->removeChild(mi.row());
|
||||
|
||||
Folder f;
|
||||
f.setId(item->id);
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
DBHelper::removeFromDB(&f,db);
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
|
||||
endRemoveRows();
|
||||
}
|
||||
|
@ -96,6 +96,9 @@ public:
|
||||
Completed = 3
|
||||
};//id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, name TEXT NOT NULL, path TEXT NOT NULL
|
||||
|
||||
public slots:
|
||||
void deleteFolder(const QModelIndex & mi);
|
||||
|
||||
private:
|
||||
void setupModelData( QSqlQuery &sqlquery, TreeItem *parent);
|
||||
void updateFolderModelData( QSqlQuery &sqlquery, TreeItem *parent);
|
||||
|
@ -20,6 +20,8 @@
|
||||
<file>../images/grid_to_flow.gif</file>
|
||||
<file>../images/empty_folder.png</file>
|
||||
<file>../images/empty_search.png</file>
|
||||
<file>../images/addNew_sidebar.png</file>
|
||||
<file>../images/delete_sidebar.png</file>
|
||||
<file alias="images/iconSearch.png">../images/iconSearchNew.png</file>
|
||||
<file alias="images/clearSearch.png">../images/clearSearchNew.png</file>
|
||||
</qresource>
|
||||
|
@ -189,6 +189,9 @@ void LibraryWindow::doLayout()
|
||||
librariesTitle->addAction(openLibraryAction);
|
||||
librariesTitle->addSpacing(3);
|
||||
|
||||
foldersTitle->addAction(addFolderAction);
|
||||
foldersTitle->addAction(deleteFolderAction);
|
||||
foldersTitle->addSepartor();
|
||||
foldersTitle->addAction(setRootIndexAction);
|
||||
foldersTitle->addAction(expandAllNodesAction);
|
||||
foldersTitle->addAction(colapseAllNodesAction);
|
||||
@ -319,6 +322,8 @@ void LibraryWindow::setUpShortcutsManagement()
|
||||
|
||||
editShortcutsDialog->addActionsGroup("Folders",QIcon(":/images/shortcuts_group_folders.png"),
|
||||
tmpList = QList<QAction *>()
|
||||
<< addFolderAction
|
||||
<< deleteFolderAction
|
||||
<< setRootIndexAction
|
||||
<< expandAllNodesAction
|
||||
<< colapseAllNodesAction
|
||||
@ -524,6 +529,18 @@ void LibraryWindow::createActions()
|
||||
icoHelpButton.addPixmap(QPixmap(":/images/main_toolbar/help.png"), QIcon::Normal);
|
||||
helpAboutAction->setIcon(icoHelpButton);
|
||||
|
||||
addFolderAction = new QAction(tr("Add new folder"), this);
|
||||
addFolderAction->setData(ADD_FOLDER_ACTION_YL);
|
||||
addFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ADD_FOLDER_ACTION_YL));
|
||||
addFolderAction->setToolTip(tr("Add new folder to the current library"));
|
||||
addFolderAction->setIcon(QIcon(":/images/addNew_sidebar.png"));
|
||||
|
||||
deleteFolderAction = new QAction(tr("Delete folder"), this);
|
||||
deleteFolderAction->setData(REMOVE_FOLDER_ACTION_YL);
|
||||
deleteFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(REMOVE_FOLDER_ACTION_YL));
|
||||
deleteFolderAction->setToolTip(tr("Delete current folder from disk"));
|
||||
deleteFolderAction->setIcon(QIcon(":/images/delete_sidebar.png"));
|
||||
|
||||
setRootIndexAction = new QAction(this);
|
||||
setRootIndexAction->setData(SET_ROOT_INDEX_ACTION_YL);
|
||||
setRootIndexAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_ROOT_INDEX_ACTION_YL));
|
||||
@ -858,6 +875,10 @@ void LibraryWindow::createMenus()
|
||||
comicsView->setItemActions(itemActions);
|
||||
comicsView->setViewActions(viewActions);
|
||||
|
||||
foldersView->addAction(addFolderAction);
|
||||
foldersView->addAction(deleteFolderAction);
|
||||
YACReader::addSperator(foldersView);
|
||||
|
||||
foldersView->addAction(openContainingFolderAction);
|
||||
foldersView->addAction(updateFolderAction);
|
||||
YACReader::addSperator(foldersView);
|
||||
@ -1016,6 +1037,8 @@ void LibraryWindow::createConnections()
|
||||
connect(removeLibraryAction,SIGNAL(triggered()),this,SLOT(removeLibrary()));
|
||||
connect(openComicAction,SIGNAL(triggered()),this,SLOT(openComic()));
|
||||
connect(helpAboutAction,SIGNAL(triggered()),had,SLOT(show()));
|
||||
connect(addFolderAction,SIGNAL(triggered()),this,SLOT(addFolderToCurrentIndex()));
|
||||
connect(deleteFolderAction,SIGNAL(triggered()),this,SLOT(deleteSelectedFolder()));
|
||||
connect(setRootIndexAction,SIGNAL(triggered()),this,SLOT(setRootIndex()));
|
||||
connect(expandAllNodesAction,SIGNAL(triggered()),foldersView,SLOT(expandAll()));
|
||||
connect(colapseAllNodesAction,SIGNAL(triggered()),foldersView,SLOT(collapseAll()));
|
||||
@ -1446,6 +1469,65 @@ void LibraryWindow::enableNeededActions()
|
||||
|
||||
}
|
||||
|
||||
void LibraryWindow::addFolderToCurrentIndex()
|
||||
{
|
||||
QModelIndex currentIndex = getCurrentFolderIndex();
|
||||
|
||||
bool ok;
|
||||
QString text = QInputDialog::getText(this, tr("Add new folder"),
|
||||
tr("Folder name:"), QLineEdit::Normal,
|
||||
"", &ok);
|
||||
if (ok && !text.isEmpty())
|
||||
QLOG_INFO() << text;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void LibraryWindow::deleteSelectedFolder()
|
||||
{
|
||||
QModelIndex currentIndex = getCurrentFolderIndex();
|
||||
|
||||
if(!currentIndex.isValid())
|
||||
QMessageBox::information(this,tr("No folder selected"), tr("Please, select a folder first"));
|
||||
else
|
||||
{
|
||||
int ret = QMessageBox::question(this,tr("Delete folder"),tr("The selected folder and all its contents will be deleted from your disk. Are you sure?"),QMessageBox::Yes,QMessageBox::No);
|
||||
|
||||
if(ret == QMessageBox::Yes)
|
||||
{
|
||||
//no folders multiselection by now
|
||||
QModelIndexList indexList;
|
||||
indexList << currentIndex;
|
||||
|
||||
QList<QString> paths;
|
||||
paths << QDir::cleanPath(currentPath()+foldersModel->getFolderPath(currentIndex));
|
||||
|
||||
FoldersRemover * remover = new FoldersRemover(indexList,paths);
|
||||
|
||||
QThread * thread = NULL;
|
||||
|
||||
thread = new QThread(this);
|
||||
|
||||
remover->moveToThread(thread);
|
||||
|
||||
connect(thread, SIGNAL(started()), remover, SLOT(process()));
|
||||
connect(remover, SIGNAL(remove(QModelIndex)), foldersModel, SLOT(deleteFolder(QModelIndex)));
|
||||
connect(remover, SIGNAL(removeError()),this,SLOT(errorDeletingFolder()));
|
||||
connect(remover, SIGNAL(finished()),this,SLOT(reloadCovers()));
|
||||
connect(remover, SIGNAL(finished()), remover, SLOT(deleteLater()));
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
|
||||
if(thread != NULL)
|
||||
thread->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryWindow::errorDeletingFolder()
|
||||
{
|
||||
QMessageBox::critical(this,tr("Unable to delete"),tr("There was an issue trying to delete the selected folders. Please, check for write permissions and be sure that any applications are using these folders or any of the contained files."));
|
||||
}
|
||||
|
||||
void LibraryWindow::selectSubfolder(const QModelIndex &mi, int child)
|
||||
{
|
||||
QModelIndex dest = foldersModel->index(child,0,mi);
|
||||
@ -2236,20 +2318,26 @@ void LibraryWindow::deleteComics()
|
||||
}
|
||||
|
||||
ComicsRemover * remover = new ComicsRemover(indexList,paths);
|
||||
QThread * thread = NULL;
|
||||
|
||||
thread = new QThread(this);
|
||||
|
||||
remover->moveToThread(thread);
|
||||
|
||||
//comicsView->showDeleteProgress();
|
||||
comicsModel->startTransaction();
|
||||
|
||||
connect(thread, SIGNAL(started()), remover, SLOT(process()));
|
||||
connect(remover, SIGNAL(remove(int)), comicsModel, SLOT(remove(int)));
|
||||
connect(remover,SIGNAL(removeError()),this,SLOT(setRemoveError()));
|
||||
connect(remover, SIGNAL(removeError()),this,SLOT(setRemoveError()));
|
||||
connect(remover, SIGNAL(finished()), comicsModel, SLOT(finishTransaction()));
|
||||
//connect(remover, SIGNAL(finished()), comicsView, SLOT(hideDeleteProgress()));
|
||||
connect(remover, SIGNAL(finished()),this,SLOT(checkEmptyFolder()));
|
||||
connect(remover, SIGNAL(finished()),this,SLOT(checkRemoveError()));
|
||||
|
||||
connect(remover, SIGNAL(finished()),this,SLOT(checkEmptyFolder()));
|
||||
connect(remover, SIGNAL(finished()),this,SLOT(checkRemoveError()));
|
||||
connect(remover, SIGNAL(finished()), remover, SLOT(deleteLater()));
|
||||
//connect(remover, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
|
||||
remover->start();
|
||||
if(thread != NULL)
|
||||
thread->start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,6 +147,9 @@ private:
|
||||
//QAction * socialAction;
|
||||
|
||||
//tree actions
|
||||
QAction * addFolderAction;
|
||||
QAction * deleteFolderAction;
|
||||
//--
|
||||
QAction * setRootIndexAction;
|
||||
QAction * expandAllNodesAction;
|
||||
QAction * colapseAllNodesAction;
|
||||
@ -339,6 +342,9 @@ public slots:
|
||||
void reloadAfterCopyMove();
|
||||
QModelIndex getCurrentFolderIndex();
|
||||
void enableNeededActions();
|
||||
void addFolderToCurrentIndex();
|
||||
void deleteSelectedFolder();
|
||||
void errorDeletingFolder();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -65,7 +65,7 @@ YACReaderTitledToolBar::YACReaderTitledToolBar(const QString & title, QWidget *p
|
||||
mainLayout->setSpacing(0);
|
||||
|
||||
QString styleSheet = "QWidget {border:0px;}";
|
||||
setStyleSheet(styleSheet);
|
||||
setStyleSheet(styleSheet);
|
||||
|
||||
nameLabel = new DropShadowLabel(this);
|
||||
nameLabel->setText(title);
|
||||
@ -108,5 +108,18 @@ void YACReaderTitledToolBar::addSpacing(int spacing)
|
||||
{
|
||||
QHBoxLayout * mainLayout = dynamic_cast<QHBoxLayout *>(layout());
|
||||
|
||||
mainLayout->addSpacing(spacing);
|
||||
mainLayout->addSpacing(spacing);
|
||||
}
|
||||
|
||||
void YACReaderTitledToolBar::addSepartor()
|
||||
{
|
||||
QHBoxLayout * mainLayout = dynamic_cast<QHBoxLayout *>(layout());
|
||||
|
||||
QWidget * w = new QWidget(this);
|
||||
w->setFixedSize(1,14);
|
||||
w->setStyleSheet("QWidget {background-color:#6F6F6F;}");
|
||||
|
||||
mainLayout->addSpacing(10);
|
||||
mainLayout->addWidget(w);
|
||||
mainLayout->addSpacing(10);
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ signals:
|
||||
public slots:
|
||||
void addAction(QAction * action);
|
||||
void addSpacing(int space);
|
||||
void addSepartor();
|
||||
private:
|
||||
DropShadowLabel * nameLabel;
|
||||
};
|
||||
|
BIN
images/addNew_sidebar.png
Normal file
BIN
images/addNew_sidebar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 212 B |
BIN
images/delete_sidebar.png
Normal file
BIN
images/delete_sidebar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 396 B |
@ -73,6 +73,8 @@ public:
|
||||
#define GET_INFO_ACTION_YL "GET_INFO_ACTION_YL"
|
||||
#define SHOW_EDIT_SHORTCUTS_ACTION_YL "SHOW_EDIT_SHORTCUTS_ACTION_YL"
|
||||
#define UPDATE_CURRENT_FOLDER_ACTION_YL "UPDATE_CURRENT_FOLDER_ACTION_YL"
|
||||
#define ADD_FOLDER_ACTION_YL "ADD_FOLDER_ACTION_YL"
|
||||
#define REMOVE_FOLDER_ACTION_YL "REMOVE_FOLDER_ACTION_YL"
|
||||
//COMMANDS YACReaderLibrary
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user