src/platform/qt/LibraryView.cpp (view raw)
1/* Copyright (c) 2013-2017 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "LibraryView.h"
7
8#include <mgba-util/vfs.h>
9
10#include "ConfigController.h"
11
12using namespace QGBA;
13
14LibraryView::LibraryView(QWidget* parent)
15 : QWidget(parent)
16 , m_model(ConfigController::configDir() + "/library.sqlite3")
17{
18 m_ui.setupUi(this);
19 connect(&m_model, SIGNAL(doneLoading()), this, SIGNAL(doneLoading()));
20 connect(&m_model, SIGNAL(doneLoading()), this, SLOT(resizeColumns()));
21 connect(m_ui.listing, SIGNAL(activated(const QModelIndex&)), this, SIGNAL(accepted()));
22 m_ui.listing->horizontalHeader()->setSectionsMovable(true);
23 m_ui.listing->setModel(&m_model);
24 resizeColumns();
25}
26
27void LibraryView::setDirectory(const QString& filename) {
28 m_model.loadDirectory(filename);
29 m_model.constrainBase(filename);
30}
31
32VFile* LibraryView::selectedVFile() const {
33 QModelIndex index = m_ui.listing->selectionModel()->currentIndex();
34 if (!index.isValid()) {
35 return nullptr;
36 }
37 return m_model.openVFile(index);
38}
39
40void LibraryView::resizeColumns() {
41 m_ui.listing->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
42}