Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload comics view - some fixes #219

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions YACReaderLibrary/library_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,10 +1100,10 @@ void LibraryWindow::createConnections()
connect(importComicsInfoAction, SIGNAL(triggered()), this, SLOT(showImportComicsInfo()));

//properties & config
connect(propertiesDialog, SIGNAL(accepted()), navigationController, SLOT(reselectCurrentSource()));
connect(propertiesDialog, &QDialog::accepted, this, &LibraryWindow::reloadComicsView);

//comic vine
connect(comicVineDialog, SIGNAL(accepted()), navigationController, SLOT(reselectCurrentSource()), Qt::QueuedConnection);
connect(comicVineDialog, &QDialog::accepted, this, &LibraryWindow::reloadComicsView, Qt::QueuedConnection);

connect(updateLibraryAction, SIGNAL(triggered()), this, SLOT(updateLibrary()));
connect(renameLibraryAction, SIGNAL(triggered()), this, SLOT(renameLibrary()));
Expand Down Expand Up @@ -1481,6 +1481,14 @@ void LibraryWindow::reloadAfterCopyMove(const QModelIndex &mi)
enableNeededActions();
}

void LibraryWindow::reloadComicsView()
{
if (status == LibraryWindow::Searching)
setSearchFilter(lastSearchModifiers, lastSearchFilter);
else
navigationController->loadPreviousStatus(YACReaderNavigationController::LoadScope::ComicsView);
}

QModelIndex LibraryWindow::getCurrentFolderIndex()
{
if (foldersView->selectionModel()->selectedRows().length() > 0)
Expand Down Expand Up @@ -1809,7 +1817,7 @@ void LibraryWindow::checkEmptyFolder()
toggleFullScreenAction->setEnabled(true);
#endif
if (comicsModel->rowCount() == 0)
navigationController->reselectCurrentFolder();
reloadComicsView();
}
}

Expand Down Expand Up @@ -2165,12 +2173,14 @@ void LibraryWindow::toNormal()

void LibraryWindow::setSearchFilter(const YACReader::SearchModifiers modifier, QString filter)
{
lastSearchModifiers = modifier;
lastSearchFilter = filter;
if (!filter.isEmpty()) {
folderQueryResultProcessor->createModelData(modifier, filter, true);
comicQueryResultProcessor.createModelData(modifier, filter, foldersModel->getDatabase());
} else if (status == LibraryWindow::Searching) { //if no searching, then ignore this
clearSearchFilter();
navigationController->loadPreviousStatus();
navigationController->loadPreviousStatus(YACReaderNavigationController::LoadScope::ComicsViewAndSideBar);
}
}

Expand Down Expand Up @@ -2295,7 +2305,7 @@ void LibraryWindow::asignNumbers()
qint64 edited = comicsModel->asignNumbers(indexList, startingNumber);

//TODO add resorting without reloading
navigationController->loadFolderInfo(foldersModelProxy->mapToSource(foldersView->currentIndex()));
reloadComicsView();

const QModelIndex &mi = comicsModel->getIndexFromId(edited);
if (mi.isValid()) {
Expand Down Expand Up @@ -2522,11 +2532,14 @@ QModelIndexList LibraryWindow::getSelectedComics()

void LibraryWindow::deleteComics()
{
//TODO
if (!listsView->selectionModel()->selectedRows().isEmpty()) {
deleteComicsFromList();
} else {
switch (currentSourceType()) {
case YACReaderLibrarySourceContainer::None:
case YACReaderLibrarySourceContainer::Folder:
deleteComicsFromDisk();
break;
case YACReaderLibrarySourceContainer::List:
deleteComicsFromList();
break;
}
}

Expand Down Expand Up @@ -2667,3 +2680,13 @@ void LibraryWindow::updateComicsView(quint64 libraryId, const ComicDB &comic)
comicsViewsManager->updateCurrentComicView();
}
}

YACReaderLibrarySourceContainer::SourceType LibraryWindow::currentSourceType() const
{
if (status == LibraryWindow::Searching)
return YACReaderLibrarySourceContainer::None;
auto type = historyController->currentSourceContainer().getType();
Q_ASSERT_X(type != YACReaderLibrarySourceContainer::None, Q_FUNC_INFO,
"History controller does not store search states.");
return type;
}
9 changes: 8 additions & 1 deletion YACReaderLibrary/library_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "yacreader_global_gui.h"
#include "yacreader_libraries.h"

#include "yacreader_history_controller.h"
#include "yacreader_navigation_controller.h"
#include "comic_query_result_processor.h"
#include "folder_query_result_processor.h"
Expand Down Expand Up @@ -73,7 +74,6 @@ class QProgressDialog;
class ReadingListModel;
class ReadingListModelProxy;
class YACReaderReadingListsView;
class YACReaderHistoryController;
class EmptyLabelWidget;
class EmptySpecialListWidget;
class EmptyReadingListWidget;
Expand Down Expand Up @@ -387,6 +387,7 @@ public slots:
void updateFolder(const QModelIndex &miFolder);
QProgressDialog *newProgressDialog(const QString &label, int maxValue);
void reloadAfterCopyMove(const QModelIndex &mi);
void reloadComicsView();
QModelIndex getCurrentFolderIndex();
void enableNeededActions();
void addFolderToCurrentIndex();
Expand All @@ -412,6 +413,12 @@ public slots:
void afterLaunchTasks();

private:
//! @return The type of the current source container or SourceType::None if search mode is active.
YACReaderLibrarySourceContainer::SourceType currentSourceType() const;

YACReader::SearchModifiers lastSearchModifiers;
QString lastSearchFilter;

//fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
Qt::WindowFlags previousWindowFlags;
QPoint previousPos;
Expand Down
5 changes: 0 additions & 5 deletions YACReaderLibrary/yacreader_history_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ void YACReaderHistoryController::updateHistory(const YACReaderLibrarySourceConta
emit(enabledForward(false));
}

YACReaderLibrarySourceContainer YACReaderHistoryController::lastSourceContainer()
{
return history.last();
}

YACReaderLibrarySourceContainer YACReaderHistoryController::currentSourceContainer()
{
return history.at(currentFolderNavigation);
Expand Down
1 change: 0 additions & 1 deletion YACReaderLibrary/yacreader_history_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public slots:
void backward();
void forward();
void updateHistory(const YACReaderLibrarySourceContainer &source);
YACReaderLibrarySourceContainer lastSourceContainer();
YACReaderLibrarySourceContainer currentSourceContainer();

protected:
Expand Down
36 changes: 15 additions & 21 deletions YACReaderLibrary/yacreader_navigation_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,6 @@ void YACReaderNavigationController::reselectCurrentList()
selectedList(libraryWindow->listsView->currentIndex());
}

void YACReaderNavigationController::reselectCurrentSource()
{
if (!libraryWindow->listsView->selectionModel()->selectedRows().isEmpty()) {
reselectCurrentList();
} else {
reselectCurrentFolder();
}
}

void YACReaderNavigationController::selectedIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer)
{
//TODO NO searching allowed, just disable backward/forward actions in searching mode
Expand All @@ -218,25 +209,29 @@ void YACReaderNavigationController::selectedIndexFromHistory(const YACReaderLibr
libraryWindow->clearSearchFilter();
}

loadIndexFromHistory(sourceContainer);
loadIndexFromHistory(sourceContainer, LoadScope::ComicsViewAndSideBar);
libraryWindow->setToolbarTitle(sourceContainer.getSourceModelIndex());
}

void YACReaderNavigationController::loadIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer)
void YACReaderNavigationController::loadIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer, LoadScope scope)
{
QModelIndex sourceMI = sourceContainer.getSourceModelIndex();
switch (sourceContainer.getType()) {
case YACReaderLibrarySourceContainer::Folder: {
QModelIndex mi = libraryWindow->foldersModelProxy->mapFromSource(sourceMI);
libraryWindow->foldersView->scrollTo(mi, QAbstractItemView::PositionAtTop);
libraryWindow->foldersView->setCurrentIndex(mi);
if (scope == LoadScope::ComicsViewAndSideBar) {
QModelIndex mi = libraryWindow->foldersModelProxy->mapFromSource(sourceMI);
libraryWindow->foldersView->scrollTo(mi, QAbstractItemView::PositionAtTop);
libraryWindow->foldersView->setCurrentIndex(mi);
}
loadFolderInfo(sourceMI);
break;
}
case YACReaderLibrarySourceContainer::List: {
QModelIndex mi = libraryWindow->listsModelProxy->mapFromSource(sourceMI);
libraryWindow->listsView->scrollTo(mi, QAbstractItemView::PositionAtTop);
libraryWindow->listsView->setCurrentIndex(mi);
if (scope == LoadScope::ComicsViewAndSideBar) {
QModelIndex mi = libraryWindow->listsModelProxy->mapFromSource(sourceMI);
libraryWindow->listsView->scrollTo(mi, QAbstractItemView::PositionAtTop);
libraryWindow->listsView->setCurrentIndex(mi);
}
loadListInfo(sourceMI);
break;
}
Expand All @@ -261,10 +256,9 @@ void YACReaderNavigationController::loadEmptyFolderInfo(const QModelIndex &model
comicsViewsManager->emptyFolderWidget->setSubfolders(modelIndex, subfolders);
}

void YACReaderNavigationController::loadPreviousStatus()
void YACReaderNavigationController::loadPreviousStatus(LoadScope scope)
{
YACReaderLibrarySourceContainer sourceContainer = libraryWindow->historyController->currentSourceContainer();
loadIndexFromHistory(sourceContainer);
loadIndexFromHistory(libraryWindow->historyController->currentSourceContainer(), scope);
}

void YACReaderNavigationController::setupConnections()
Expand All @@ -273,7 +267,7 @@ void YACReaderNavigationController::setupConnections()
connect(libraryWindow->listsView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectedList(QModelIndex)));
connect(libraryWindow->historyController, SIGNAL(modelIndexSelected(YACReaderLibrarySourceContainer)), this, SLOT(selectedIndexFromHistory(YACReaderLibrarySourceContainer)));
connect(comicsViewsManager->emptyFolderWidget, SIGNAL(subfolderSelected(QModelIndex, int)), this, SLOT(selectSubfolder(QModelIndex, int)));
connect(libraryWindow->comicsModel, SIGNAL(isEmpty()), this, SLOT(reselectCurrentSource()));
connect(libraryWindow->comicsModel, &ComicModel::isEmpty, libraryWindow, &LibraryWindow::reloadComicsView);
}

qulonglong YACReaderNavigationController::folderModelIndexToID(const QModelIndex &mi)
Expand Down
13 changes: 6 additions & 7 deletions YACReaderLibrary/yacreader_navigation_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class YACReaderNavigationController : public QObject
public:
explicit YACReaderNavigationController(LibraryWindow *parent, YACReaderComicsViewsManager *comicsViewsManager);

signals:
enum class LoadScope {
ComicsView,
ComicsViewAndSideBar
};
void loadPreviousStatus(LoadScope scope);
void loadIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer, LoadScope scope);

public slots:
//info origins
Expand All @@ -22,12 +27,8 @@ public slots:
//reading lists
void selectedList(const QModelIndex &mi);
void reselectCurrentList();

void reselectCurrentSource();

//history navigation
void selectedIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer);
void loadIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer);
//empty subfolder
void selectSubfolder(const QModelIndex &sourceMI, int child);

Expand All @@ -39,8 +40,6 @@ public slots:
void loadLabelInfo(const QModelIndex &modelIndex);
void loadReadingListInfo(const QModelIndex &modelIndex);

void loadPreviousStatus();

private:
void setupConnections();
LibraryWindow *libraryWindow;
Expand Down