all repos — mgba @ 40e9dfcf5c3f512fa332a48d5a478329971b0aca

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