all repos — mgba @ 0d6efaa3dc3ab5a19b0a2e7a0d93fad50a53e324

mGBA Game Boy Advance Emulator

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
32void LibraryView::addDirectory(const QString& filename) {
33	m_model.loadDirectory(filename);
34}
35
36VFile* LibraryView::selectedVFile() const {
37	QModelIndex index = m_ui.listing->selectionModel()->currentIndex();
38	if (!index.isValid()) {
39		return nullptr;
40	}
41	return m_model.openVFile(index);
42}
43
44QPair<QString, QString> LibraryView::selectedPath() const {
45	QModelIndex index = m_ui.listing->selectionModel()->currentIndex();
46	if (!index.isValid()) {
47		return qMakePair(QString(), QString());
48	}
49	return qMakePair(m_model.filename(index), m_model.location(index));
50}
51
52void  LibraryView::resizeColumns() {
53	m_ui.listing->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
54}