Core: Add library clear function
Vicki Pfau vi@endrift.com
Tue, 20 Jun 2017 21:36:53 -0700
8 files changed,
31 insertions(+),
3 deletions(-)
M
include/mgba/core/library.h
→
include/mgba/core/library.h
@@ -36,6 +36,7 @@
struct VDir; struct VFile; void mLibraryLoadDirectory(struct mLibrary* library, const char* base); +void mLibraryClear(struct mLibrary* library); size_t mLibraryCount(struct mLibrary* library, const struct mLibraryEntry* constraints); size_t mLibraryGetEntries(struct mLibrary* library, struct mLibraryListing* out, size_t numEntries, size_t offset, const struct mLibraryEntry* constraints);
M
src/core/library.c
→
src/core/library.c
@@ -339,6 +339,16 @@ sqlite3_bind_text(library->deletePath, 1, entry->filename, -1, SQLITE_TRANSIENT);
sqlite3_step(library->insertPath); } +void mLibraryClear(struct mLibrary* library) { + int result = sqlite3_exec(library->db, + " BEGIN TRANSACTION;" + "\n DELETE FROM roots;" + "\n DELETE FROM roms;" + "\n DELETE FROM paths;" + "\n COMMIT;" + "\n VACUUM;", NULL, NULL, NULL); +} + size_t mLibraryCount(struct mLibrary* library, const struct mLibraryEntry* constraints) { sqlite3_clear_bindings(library->count); sqlite3_reset(library->count);
M
src/platform/qt/SettingsView.cpp
→
src/platform/qt/SettingsView.cpp
@@ -89,6 +89,7 @@ m_ui.patchSameDir->setChecked(false);
m_ui.patchPath->setText(path); } }); + connect(m_ui.clearCache, &QAbstractButton::pressed, this, &SettingsView::libraryCleared); // TODO: Move to reloadConfig() QVariant audioDriver = m_controller->getQtOption("audioDriver");
M
src/platform/qt/SettingsView.h
→
src/platform/qt/SettingsView.h
@@ -29,6 +29,7 @@ void biosLoaded(int platform, const QString&);
void audioDriverChanged(); void displayDriverChanged(); void pathsChanged(); + void libraryCleared(); private slots: void selectBios(QLineEdit*);
M
src/platform/qt/SettingsView.ui
→
src/platform/qt/SettingsView.ui
@@ -431,9 +431,6 @@ </widget>
</item> <item row="2" column="1"> <widget class="QPushButton" name="clearCache"> - <property name="enabled"> - <bool>false</bool> - </property> <property name="text"> <string>Clear cache</string> </property>
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -460,6 +460,7 @@ connect(settingsWindow, &SettingsView::biosLoaded, m_controller, &GameController::loadBIOS);
connect(settingsWindow, &SettingsView::audioDriverChanged, m_controller, &GameController::reloadAudioDriver); connect(settingsWindow, &SettingsView::displayDriverChanged, this, &Window::mustRestart); connect(settingsWindow, &SettingsView::pathsChanged, this, &Window::reloadConfig); + connect(settingsWindow, &SettingsView::libraryCleared, m_libraryView, &LibraryController::clear); openView(settingsWindow); }
M
src/platform/qt/library/LibraryController.cpp
→
src/platform/qt/library/LibraryController.cpp
@@ -130,6 +130,20 @@ m_library = nullptr;
m_loaderThread.start(); } +void LibraryController::clear() { + if (!m_library) { + if (!m_loaderThread.isRunning() && m_loaderThread.m_library) { + m_library = m_loaderThread.m_library; + m_loaderThread.m_library = nullptr; + } else { + return; + } + } + + mLibraryClear(m_library); + refresh(); +} + void LibraryController::refresh() { if (!m_library) { if (!m_loaderThread.isRunning() && m_loaderThread.m_library) {
M
src/platform/qt/library/LibraryController.h
→
src/platform/qt/library/LibraryController.h
@@ -100,6 +100,9 @@ void selectLastBootedGame();
void addDirectory(const QString& dir); +public slots: + void clear(); + signals: void startGame(); void doneLoading();