all repos — mgba @ 45844301f6d628654f3b61450b25735dad18bd65

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#include "GBAApp.h"
12
13using namespace QGBA;
14
15LibraryView::LibraryView(QWidget* parent)
16	: QWidget(parent)
17	, m_model(ConfigController::configDir() + "/library.sqlite3")
18{
19	m_ui.setupUi(this);
20	m_model.attachGameDB(GBAApp::app()->gameDB());
21	connect(&m_model, SIGNAL(doneLoading()), this, SIGNAL(doneLoading()));
22	connect(&m_model, SIGNAL(doneLoading()), this, SLOT(resizeColumns()));
23	connect(m_ui.listing, SIGNAL(activated(const QModelIndex&)), this, SIGNAL(accepted()));
24	m_ui.listing->horizontalHeader()->setSectionsMovable(true);
25	m_ui.listing->setModel(&m_model);
26	m_ui.listing->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
27	resizeColumns();
28}
29
30void LibraryView::setDirectory(const QString& filename) {
31	m_model.loadDirectory(filename);
32	m_model.constrainBase(filename);
33}
34
35void LibraryView::addDirectory(const QString& filename) {
36	m_model.loadDirectory(filename);
37}
38
39VFile* LibraryView::selectedVFile() const {
40	QModelIndex index = m_ui.listing->selectionModel()->currentIndex();
41	if (!index.isValid()) {
42		return nullptr;
43	}
44	return m_model.openVFile(index);
45}
46
47QPair<QString, QString> LibraryView::selectedPath() const {
48	QModelIndex index = m_ui.listing->selectionModel()->currentIndex();
49	if (!index.isValid()) {
50		return qMakePair(QString(), QString());
51	}
52	return qMakePair(m_model.filename(index), m_model.location(index));
53}
54
55void  LibraryView::resizeColumns() {
56	m_ui.listing->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
57}