diff options
-rw-r--r-- | CMakeLists.txt | 84 | ||||
-rw-r--r-- | Doxyfile | 257 | ||||
-rw-r--r-- | EmuDB.cpp | 230 | ||||
-rw-r--r-- | EmuDB.h | 72 | ||||
-rw-r--r-- | EmuDBConfig.cpp | 158 | ||||
-rw-r--r-- | EmuDBConfig.h | 155 | ||||
-rw-r--r-- | Emulator.cpp | 186 | ||||
-rw-r--r-- | Emulator.h | 186 | ||||
-rw-r--r-- | EmulatorEditor.cpp | 186 | ||||
-rw-r--r-- | EmulatorEditor.h | 71 | ||||
-rw-r--r-- | Execute.cpp | 82 | ||||
-rw-r--r-- | Execute.h | 59 | ||||
-rw-r--r-- | Profile.cpp | 133 | ||||
-rw-r--r-- | Profile.h | 179 | ||||
-rw-r--r-- | Rom.cpp | 124 | ||||
-rw-r--r-- | Rom.h | 179 | ||||
-rw-r--r-- | RomEditor.cpp | 108 | ||||
-rw-r--r-- | RomEditor.h | 48 | ||||
-rw-r--r-- | RomLibrary.cpp | 54 | ||||
-rw-r--r-- | RomLibrary.h | 74 | ||||
-rw-r--r-- | RomModel.cpp | 56 | ||||
-rw-r--r-- | RomModel.h | 70 | ||||
-rw-r--r-- | RomType.cpp | 76 | ||||
-rw-r--r-- | RomType.h | 104 | ||||
-rw-r--r-- | RomTypeEditor.cpp | 89 | ||||
-rw-r--r-- | RomTypeEditor.h | 57 | ||||
-rw-r--r-- | doxygen.cmake | 34 | ||||
-rw-r--r-- | main.cpp | 55 |
28 files changed, 3166 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..64ad8d7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,84 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.4) + +PROJECT(emudb) + +FIND_PACKAGE(Qt4 REQUIRED) +INCLUDE(${QT_USE_FILE}) + +FIND_PACKAGE(KDE4 REQUIRED) + +SET(EXECUTABLE_OUTPUT_PATH + ${PROJECT_BINARY_DIR}/bin +) +SET(DOCUMENTATION_OUTPUT_PATH + ${PROJECT_BINARY_DIR}/doc +) + +INCLUDE_DIRECTORIES( + ${QT_INCLUDE_DIR} + ${KDE4_INCLUDE_DIR} + ${KDE4_INCLUDE_DIR}/KDE +) + +SET(emudb_MOC_HEADERS + EmuDB.h + Emulator.h + EmulatorEditor.h + Execute.h + Profile.h + Rom.h + RomEditor.h + RomLibrary.h + RomType.h + RomTypeEditor.h +) +QT4_WRAP_CPP(emudb_MOC_SRCS ${emudb_MOC_HEADERS}) +SET(emudb_HEADERS + EmuDBConfig.h + RomModel.h +) +SET(emudb_DEVEL + ${emudb_MOC_HEADERS} + ${emudb_HEADERS} +) +SET(emudb_SRCS + EmuDB.cpp + EmuDBConfig.cpp + Emulator.cpp + EmulatorEditor.cpp + Execute.cpp + Profile.cpp + Rom.cpp + RomEditor.cpp + RomLibrary.cpp + RomModel.cpp + RomType.cpp + RomTypeEditor.cpp + main.cpp +) + +ADD_EXECUTABLE(emudb + ${emudb_SRCS} + ${emudb_MOC_SRCS} +) +TARGET_LINK_LIBRARIES(emudb + ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY} + ${KDE4_KDECORE_LIBRARY} + ${KDE4_KDEUI_LIBRARY} + ${KDE4_KIO_LIBRARY} +) + +INCLUDE(doxygen.cmake) + +INSTALL( + TARGETS emudb + DESTINATION ${CMAKE_INSTALL_PREFIX}/bin + COMPONENT runtime +) + +INSTALL( + FILES ${emudb_DEVEL} + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME} + COMPONENT development +) diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 0000000..0a4d292 --- /dev/null +++ b/Doxyfile @@ -0,0 +1,257 @@ + # Doxyfile 1.5.6-KDevelop + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = emudb +PROJECT_NUMBER = 1 +OUTPUT_DIRECTORY = DOCUMENTATION_OUTPUT_PATH +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = PROJECT_SOURCE_DIR +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +IDL_PROPERTY_SUPPORT = YES +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +TYPEDEF_HIDES_STRUCT = NO +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_GROUP_NAMES = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = NO +SHOW_FILES = YES +SHOW_NAMESPACES = YES +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = YES +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = PROJECT_SOURCE_DIR +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.cpp \ + *.h \ +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXCLUDE_SYMBOLS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +GENERATE_DOCSET = NO +DOCSET_FEEDNAME = "Doxygen generated docs" +DOCSET_BUNDLE_ID = org.doxygen.Project +HTML_DYNAMIC_SECTIONS = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +CHM_INDEX_ENCODING = +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = NONE +TREEVIEW_WIDTH = 250 +FORMULA_FONTSIZE = 10 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = emudb.tag +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +MSCGEN_PATH = +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +DOT_FONTNAME = FreeSans +DOT_FONTPATH = +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +DOT_GRAPH_MAX_NODES = 50 +MAX_DOT_GRAPH_DEPTH = 1000 +DOT_TRANSPARENT = YES +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO diff --git a/EmuDB.cpp b/EmuDB.cpp new file mode 100644 index 0000000..b96848d --- /dev/null +++ b/EmuDB.cpp @@ -0,0 +1,230 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file EmuDB.cpp + */ + +// Header include +#include "EmuDB.h" + +// EmuDB includes +#include "EmuDBConfig.h" +#include "EmulatorEditor.h" +#include "Execute.h" +#include "Rom.h" +#include "RomEditor.h" +#include "RomModel.h" +#include "RomTypeEditor.h" + +// KDE includes +#include <KAction> +#include <KFileDialog> +#include <KMenu> +#include <KMenuBar> +#include <KPushButton> +#include <KStandardAction> +#include <KTreeWidgetSearchLine> + +// Qt includes +#include <QtCore/QFileInfo> +#include <QtGui/QHBoxLayout> +#include <QtGui/QSortFilterProxyModel> +#include <QtGui/QTreeWidget> +#include <QtGui/QVBoxLayout> + +#include <QtCore/QtDebug> + +EmuDB::EmuDB() : + m_view(new QTreeWidget) +{ + m_view->setSortingEnabled(true); + connect(m_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(execute(QTreeWidgetItem*))); + + KTreeWidgetSearchLine* search = new KTreeWidgetSearchLine; + search->setTreeWidget(m_view); + search->setClearButtonShown(true); + + KPushButton* exec = new KPushButton; + exec->setText("Execute"); + connect(exec, SIGNAL(pressed()), this, SLOT(execute())); + KPushButton* edit = new KPushButton; + edit->setText("Edit"); + connect(edit, SIGNAL(pressed()), this, SLOT(editRom())); + KPushButton* add = new KPushButton; + add->setText("Add"); + connect(add, SIGNAL(pressed()), this, SLOT(addRoms())); + KPushButton* remove = new KPushButton; + remove->setText("Remove"); + connect(remove, SIGNAL(pressed()), this, SLOT(removeRoms())); + + QWidget* buttons = new QWidget; + QHBoxLayout* bLayout = new QHBoxLayout; + bLayout->addWidget(exec); + bLayout->addWidget(edit); + bLayout->addWidget(add); + bLayout->addWidget(remove); + buttons->setLayout(bLayout); + + QWidget* widget = new QWidget; + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget(search); + layout->addWidget(m_view); + layout->addWidget(buttons); + widget->setLayout(layout); + + setCentralWidget(widget); + + RomLibrary* library = EmuDBConfig::instance()->romLibrary(); + + connect(library, SIGNAL(added()), this, SLOT(addRom())); + connect(library, SIGNAL(removed(int)), this, SLOT(removeRom(int))); + + for (int i = 0; i < library->size(); ++i) + new RomModel(m_view->invisibleRootItem(), library->rom(i)); + + m_view->setHeaderLabels(EmuDBConfig::m_headers); + setAutoSaveSettings("MainWindow", true); + + setMenuBar(new KMenuBar(this)); + KMenu* fileMenu = new KMenu("&File", this); + KAction* addFiles = new KAction("&Add files", this); + addFiles->setShortcut(Qt::CTRL + Qt::Key_A); + connect(addFiles, SIGNAL(triggered()), this, SLOT(addRoms())); + fileMenu->addAction(addFiles); + fileMenu->addSeparator(); + fileMenu->addAction(KStandardAction::quit(this, SLOT(close()), this)); + menuBar()->addMenu(fileMenu); + KMenu* editMenu = new KMenu("&Edit", this); + KAction* editEmulator = new KAction("Edit &emulators", this); + editEmulator->setShortcut(Qt::CTRL + Qt::Key_E); + connect(editEmulator, SIGNAL(triggered()), this, SLOT(editEmulators())); + editMenu->addAction(editEmulator); + KAction* editTypes = new KAction("Edit &ROM types", this); + editTypes->setShortcut(Qt::CTRL + Qt::Key_R); + connect(editTypes, SIGNAL(triggered()), this, SLOT(editRomTypes())); + editMenu->addAction(editTypes); + menuBar()->addMenu(editMenu); + menuBar()->addMenu(helpMenu()); +} + +void EmuDB::addRoms() +{ + QStringList paths = KFileDialog::getOpenFileNames(); + foreach (const QString& path, paths) + { + QFileInfo info(path); + if (info.isDir()) + addFiles(info.filePath()); + else + addFile(info.filePath()); + } +} + +void EmuDB::addFiles(const QString& path) +{ + QDir dir(path); + QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); + foreach (const QFileInfo& entry, entries) + { + if (entry.isDir()) + addFiles(entry.filePath()); + else + addFile(entry.filePath()); + } +} + +void EmuDB::addFile(const QString& path) +{ + QStringList types = EmuDBConfig::instance()->romTypes(); + RomLibrary* library = EmuDBConfig::instance()->romLibrary(); + QFileInfo info(path); + QString suffix = info.suffix(); + foreach (const QString& type, types) + { + if (EmuDBConfig::instance()->romType(type)->extensions().contains(suffix)) + { + Rom* rom = new Rom; + rom->setName(info.completeBaseName()); + rom->setPath(info.absoluteFilePath()); + rom->setType(type); + library->addRom(rom); + break; + } + } +} + +void EmuDB::editRom() +{ + RomModel* romModel = static_cast<RomModel*>(m_view->currentItem()); + if (!romModel) + return; + RomEditor* editor = new RomEditor(this, romModel->rom()); + editor->exec(); + delete editor; +} + +void EmuDB::removeRoms() +{ + QList<QTreeWidgetItem*> items = m_view->selectedItems(); + foreach (QTreeWidgetItem* item, items) + { + RomModel* romModel = static_cast<RomModel*>(item); + if (romModel) + EmuDBConfig::instance()->romLibrary()->removeRom(romModel->rom()); + } +} + +void EmuDB::execute(QTreeWidgetItem* item) +{ + RomModel* romModel = static_cast<RomModel*>(item); + if (!romModel) + return; + Execute* exec = new Execute(this, romModel->rom()); + exec->exec(); + delete exec; +} + +void EmuDB::execute() +{ + execute(m_view->currentItem()); +} + +void EmuDB::editEmulators() +{ + EmulatorEditor* editor = new EmulatorEditor(this); + editor->exec(); + delete editor; +} + +void EmuDB::editRomTypes() +{ + RomTypeEditor* editor = new RomTypeEditor(this); + editor->exec(); + delete editor; +} + +void EmuDB::addRom() +{ + RomLibrary* library = EmuDBConfig::instance()->romLibrary(); + new RomModel(m_view->invisibleRootItem(), library->rom(library->size() - 1)); +} + +void EmuDB::removeRom(const int index) +{ + delete m_view->invisibleRootItem()->takeChild(index); +} @@ -0,0 +1,72 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file EmuDB.h + */ + +#ifndef EMUDB_H +#define EMUDB_H + +// KDE includes +#include <KMainWindow> + +// Forward declarations +class QTreeWidget; +class QTreeWidgetItem; + +/** + * \class EmuDB + * \brief The main window for %EmuDB + */ +class EmuDB : public KMainWindow +{ + Q_OBJECT + + public: + /** + * \brief Default constructor. + */ + EmuDB(); + public slots: + void addRom(); + void removeRom(const int index); + + void addRoms(); + void addFiles(const QString& path); + void addFile(const QString& path); + + void editRom(); + void removeRoms(); + + void execute(QTreeWidgetItem* item); + void execute(); + + /** + * \brief Edit the emulators in the database. + */ + void editEmulators(); + + /** + * \brief Edit the ROM types in the database. + */ + void editRomTypes(); + private: + QTreeWidget* m_view; +}; + +#endif diff --git a/EmuDBConfig.cpp b/EmuDBConfig.cpp new file mode 100644 index 0000000..17b2520 --- /dev/null +++ b/EmuDBConfig.cpp @@ -0,0 +1,158 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file EmuDBConfig.cpp + */ + +// Header include +#include "EmuDBConfig.h" + +// EmuDB includes +#include "Rom.h" + +// KDE includes +#include <KConfigGroup> +#include <KGlobal> +#include <KSharedConfig> + +EmuDBConfig* EmuDBConfig::m_instance = NULL; +const char* EmuDBConfig::m_names[] = {"name", "type", "rating", "notes"}; +const QStringList EmuDBConfig::m_headers = QStringList() << "Name" << "Type" << "Rating" << "Notes"; + +EmuDBConfig* EmuDBConfig::instance() +{ + if (m_instance) + return m_instance; + return m_instance = new EmuDBConfig; +} + +void EmuDBConfig::cleanup() +{ + delete m_instance; + m_instance = NULL; +} + +bool EmuDBConfig::hasEmulator(const QString& name) const +{ + return m_emulators.contains(name); +} + +QStringList EmuDBConfig::emulators() const +{ + return m_emulators.keys(); +} + +Emulator* EmuDBConfig::emulator(const QString& name) +{ + if (m_emulators.contains(name)) + return &m_emulators[name]; + return NULL; +} + +void EmuDBConfig::addEmulator(const QString& name, const Emulator& emulator) +{ + m_emulators[name] = emulator; +} + +void EmuDBConfig::removeEmulator(const QString& name) +{ + if (m_emulators.contains(name)) + m_emulators.remove(name); +} + +RomLibrary* EmuDBConfig::romLibrary() +{ + return &m_romLibrary; +} + +bool EmuDBConfig::hasRomType(const QString& name) const +{ + return m_romTypes.contains(name); +} + +QStringList EmuDBConfig::romTypes() const +{ + return m_romTypes.keys(); +} + +RomType* EmuDBConfig::romType(const QString& name) +{ + if (m_romTypes.contains(name)) + return &m_romTypes[name]; + return NULL; +} + +void EmuDBConfig::addRomType(const QString& name, const RomType& type) +{ + m_romTypes[name] = type; +} + +void EmuDBConfig::removeRomType(const QString& name) +{ + if (m_romTypes.contains(name)) + m_romTypes.remove(name); +} + +int EmuDBConfig::columnCount() const +{ + return m_columns.count(); +} + +QString EmuDBConfig::columnHeader(const int column) const +{ + return m_headers[m_columns[column]]; +} + +const char* EmuDBConfig::columnName(const int column) const +{ + return m_names[m_columns[column]]; +} + +EmuDBConfig::EmuDBConfig() : + m_config(KGlobal::config()) +{ + m_columns << 0 << 1 << 2 << 3; + KConfigGroup emulators = m_config->group("Emulators"); + QStringList groups = emulators.groupList(); + foreach (const QString& group, groups) + addEmulator(group, Emulator(emulators.group(group))); + KConfigGroup types = m_config->group("Types"); + groups = types.groupList(); + foreach (const QString& group, groups) + addRomType(group, RomType(types.group(group))); + KConfigGroup roms = m_config->group("Library"); + groups = roms.groupList(); + foreach (const QString& group, groups) + m_romLibrary.addRom(new Rom(roms.group(group))); + if (m_config->group("EmuDB").hasKey("Columns")) + m_columns = m_config->group("EmuDB").readEntry("Columns", QList<int>()); +} + +EmuDBConfig::~EmuDBConfig() +{ + QStringList names = m_emulators.keys(); + foreach (const QString& name, names) + m_emulators[name].makeGroup(name, m_config->group("Emulators")); + names = m_romTypes.keys(); + foreach (const QString& name, names) + m_romTypes[name].makeGroup(name, m_config->group("Types")); + for (int i = 0; i < m_romLibrary.size(); ++i) + m_romLibrary.rom(i)->makeGroup(m_config->group("Library")); + m_config->group("EmuDB").writeEntry("Columns", m_columns); + m_config->sync(); +} diff --git a/EmuDBConfig.h b/EmuDBConfig.h new file mode 100644 index 0000000..107d24e --- /dev/null +++ b/EmuDBConfig.h @@ -0,0 +1,155 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file EmuDBConfig.h + */ + +#ifndef EMUDBCONFIG_H +#define EMUDBCONFIG_H + +// EmuEB includes +#include "Emulator.h" +#include "RomLibrary.h" +#include "RomType.h" + +// KDE includes +#include <KSharedConfig> + +/** + * \class EmuDBConfig + * \brief Singleton to access configuration options. + */ +class EmuDBConfig +{ + public: + /** + * \brief Used to access the configuration. + * + * \return A pointer to an instance of the configuration. + */ + static EmuDBConfig* instance(); + + /** + * \brief Cleans up the configuration. + * + * \note Call before closing the application. + */ + static void cleanup(); + + /** + * \param name The name of the emulator. + * \return Whether the emulator exists or not. + */ + bool hasEmulator(const QString& name) const; + + /** + * \return List of emulators. + */ + QStringList emulators() const; + + /** + * \param name Name of the emulator. + * \return An emulator. + */ + Emulator* emulator(const QString& name); + + /** + * \brief Add an emulator to the database. + * + * \param name The name of the emulator. + * \param emulator The emulator. + */ + void addEmulator(const QString& name, const Emulator& emulator); + + /** + * \brief Remove an emulator from the database. + * + * \param name The name of the emulator. + */ + void removeEmulator(const QString& name); + + /** + * \return A pointer to the ROM library. + */ + RomLibrary* romLibrary(); + + /** + * \param name The name of the ROM type. + * \return Whether the ROM type exists or not. + */ + bool hasRomType(const QString& name) const; + + /** + * \return List of known ROM types. + */ + QStringList romTypes() const; + + /** + * \param name Name of the ROM type. + * \return A ROM type. + */ + RomType* romType(const QString& name); + + /** + * \brief Add a ROM type to the database. + * + * \param name The name of the type. + * \param type The type. + */ + void addRomType(const QString& name, const RomType& type); + + /** + * \brief Remove a ROM type from the database. + * + * \param name The name of the type. + */ + void removeRomType(const QString& name); + + /** + * \return The number of columns in the view. + */ + int columnCount() const; + + /** + * \param column The column. + * \return The string for the header of the column. + */ + QString columnHeader(const int column) const; + + /** + * \param column The column. + * \return The name of the poroperty for the column. + */ + const char* columnName(const int column) const; + + static const char* m_names[]; + static const QStringList m_headers; + private: + EmuDBConfig(); + ~EmuDBConfig(); + + static EmuDBConfig* m_instance; + + KSharedConfigPtr m_config; + RomLibrary m_romLibrary; + QMap<QString, Emulator> m_emulators; + QMap<QString, RomType> m_romTypes; + QList<int> m_columns; +}; + +#endif diff --git a/Emulator.cpp b/Emulator.cpp new file mode 100644 index 0000000..b885988 --- /dev/null +++ b/Emulator.cpp @@ -0,0 +1,186 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file Emulator.cpp + */ + +// Header include +#include "Emulator.h" + +// EmuDB includes +#include "Rom.h" + +// KDE includes +#include <KConfigGroup> +#include <KMessageBox> + +// Qt includes +#include <QtCore/QDir> +#include <QtCore/QProcess> + +#include <QtCore/QtDebug> + +Emulator::Emulator() : + QObject(NULL) +{ +} + +Emulator::Emulator(const KConfigGroup& config) : + QObject(NULL) +{ + setCommand(config.readEntry("command", "")); + m_types = QSet<QString>::fromList(config.readEntry("types", QList<QString>())); + QStringList groups = config.group("Profiles").groupList(); + foreach (const QString& group, groups) + addProfile(group, Profile(config.group("Profiles").group(group))); +} + +Emulator::Emulator(const Emulator& rhs) : + QObject(NULL) +{ + *this = rhs; +} + +void Emulator::makeGroup(const QString& name, const KConfigGroup& parent) const +{ + KConfigGroup config(&parent, name); + config.writeEntry("command", m_command); + config.writeEntry("types", QList<QString>::fromSet(m_types)); + QStringList profileNames = m_profiles.keys(); + foreach (const QString& profileName, profileNames) + m_profiles[profileName].makeGroup(profileName, config.group("Profiles")); +} + +void Emulator::setCommand(const QString& command) +{ + m_command = command; +} + +void Emulator::addType(const QString& type) +{ + m_types.insert(type); +} + +void Emulator::removeType(const QString& type) +{ + if (m_types.contains(type)) + m_types.remove(type); +} + +void Emulator::addProfile(const QString& name, const Profile& profile) +{ + m_profiles[name] = profile; +} + +void Emulator::removeProfile(const QString& name) +{ + if (m_profiles.contains(name)) + m_profiles.remove(name); +} + +void Emulator::execute(const QString& profileName, const Rom& rom) +{ + if (!m_types.contains(rom.type())) + { + if (KMessageBox::questionYesNo(NULL, "The Rom type is not supported by the emulator. Continue anyways?", "Incompatable Rom") == KMessageBox::No) + return; + } + QProcess process; + Profile* prof = profile(profileName); + QString cmd = m_command; + if (prof) + { + qDebug("Setting Profile"); + qDebug() << cmd; + cmd.append(QString(' ').append(prof->options().join(" "))); + qDebug() << cmd; + process.setEnvironment(prof->environmentList()); + process.setWorkingDirectory(prof->workingPath()); + } + QString romPath = rom.path(); + cmd.append(QString(" \"%1\"").arg(rom.path())); + qDebug() << cmd; + process.start(cmd); + while (!process.waitForStarted()) + { + if (process.error() == QProcess::Timedout) + continue; + QString error; + QString details = process.readAll(); + switch (process.error()) + { + case QProcess::FailedToStart: + error = "Failed to start"; + break; + case QProcess::Crashed: + error = "Crashed"; + break; + case QProcess::ReadError: + error = "Read error"; + break; + case QProcess::WriteError: + error = "Write error"; + break; + default: + error = "Unknown error"; + break; + } + KMessageBox::detailedError(NULL, QString("Command executed:\n%1\nWorking Directory:\n%2\nEnvironment:\n%3").arg(cmd).arg(prof->workingPath()).arg(prof->environmentList().join("\n")), details, error, KMessageBox::Notify | KMessageBox::AllowLink); + } + qDebug() << process.readAll(); + qDebug() << "Waiting"; + process.waitForFinished(-1); + qDebug() << "Done"; +} + +QString Emulator::command() const +{ + return m_command; +} + +QSet<QString> Emulator::types() const +{ + return m_types; +} + +Emulator::ProfileMap Emulator::profiles() const +{ + return m_profiles; +} + +QStringList Emulator::profileNames() const +{ + return m_profiles.keys(); +} + +Profile* Emulator::profile(const QString& name) +{ + if (m_profiles.contains(name)) + return &m_profiles[name]; + return NULL; +} + +Emulator& Emulator::operator=(const Emulator& rhs) +{ + if (this == &rhs) + return *this; + m_command = rhs.m_command; + m_types = rhs.m_types; + m_profiles = rhs.m_profiles; + return *this; +} diff --git a/Emulator.h b/Emulator.h new file mode 100644 index 0000000..4fa0f83 --- /dev/null +++ b/Emulator.h @@ -0,0 +1,186 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file Emulator.h + */ + +#ifndef EMULATOR_H +#define EMULATOR_H + +// EmuDB includes +#include "Profile.h" + +// Qt includes +#include <QtCore/QMap> +#include <QtCore/QMetaType> +#include <QtCore/QSet> +#include <QtCore/QString> + +// Forward declarations +class Rom; + +/** + * \class Emulator + * \brief Provides information on how to run an emulator. + */ +class Emulator : public QObject +{ + Q_OBJECT + /** + * \var command + * \brief The command used to execute the emulator. + * + * \sa command + * \sa setCommand + */ + Q_PROPERTY(QString command READ command WRITE setCommand) + /** + * \var types + * \brief The types of Roms the emulator supports. + * + * \sa types + * \sa addType + * \sa removeType + */ + Q_PROPERTY(QSet<QString> types READ types) + /** + * \var profiles + * \brief Profiles for the emulator. + * + * \sa profiles + * \sa profileNames + * \sa setProfile + * \sa removeProfile + */ + Q_PROPERTY(ProfileMap profiles READ profiles) + + public: + /** + * \typedef ProfileMap + * \brief Storage type for the profiles. + */ + typedef QMap<QString, Profile> ProfileMap; + + /** + * \brief Default constructor. + */ + Emulator(); + + /** + * \brief Configuration constructor. + */ + Emulator(const KConfigGroup& config); + + /** + * \brief Copy constructor. + * + * \param rhs The profile to copy. + */ + Emulator(const Emulator& rhs); + + /** + * \brief Create a KConfigGroup for saving. + * + * \param name The name of the group. + * \param parent The parent group. + */ + void makeGroup(const QString& name, const KConfigGroup& parent) const; + + /** + * \return The command used to run the emulator. + */ + QString command() const; + + /** + * \return The systems the emulator can run. + */ + QSet<QString> types() const; + + /** + * \return All profiles for the emulator. + */ + ProfileMap profiles() const; + + /** + * \return Names of all profiles for the emulator. + */ + QStringList profileNames() const; + + /** + * \param name The name of the profile. + * \return The profile with the given name, or default if it does not exist. + */ + Profile* profile(const QString& name); + + /** + * \brief Assignment method. + * \param rhs Emulator to copy. + */ + Emulator& operator=(const Emulator& rhs); + public slots: + /** + * \brief Set the command used to run the emulator. + * + * \param command + */ + void setCommand(const QString& command); + + /** + * \brief Add a type that the emulator can run. + * + * \param type + */ + void addType(const QString& type); + + /** + * \brief Remove a type from the emulator's support. + * + * \param type + */ + void removeType(const QString& type); + + /** + * \brief Add a profile. + * + * \param name The name of the profile. + * \param profile The profile + */ + void addProfile(const QString& name, const Profile& profile); + + /** + * \brief Delete a profile for the emulator. + * + * \param name The profile to remove. + */ + void removeProfile(const QString& name); + + /** + * \brief Run the emulator. + * + * \param profileName The profile to use. + * \param rom The Rom to play. + */ + void execute(const QString& profileName, const Rom& rom); + private: + QString m_command; + QSet<QString> m_types; + ProfileMap m_profiles; +}; +Q_DECLARE_METATYPE(Emulator*) + +#endif diff --git a/EmulatorEditor.cpp b/EmulatorEditor.cpp new file mode 100644 index 0000000..defbc67 --- /dev/null +++ b/EmulatorEditor.cpp @@ -0,0 +1,186 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file EmulatorEditor.cpp + */ + +// Header include +#include "EmulatorEditor.h" + +// EmuDB includes +#include "EmuDBConfig.h" +#include "Emulator.h" + +// KDE includes +#include <KComboBox> +#include <KEditListBox> +#include <KLineEdit> +#include <KListWidget> +#include <KPushButton> +#include <KShellCompletion> + +// Qt includes +#include <QtGui/QGroupBox> +#include <QtGui/QVBoxLayout> + +EmulatorEditor::EmulatorEditor(QWidget* parent) : + KDialog(parent) +{ + setCaption("Edit Emulators"); + + KEditListBox* emulators = new KEditListBox("Emulators", this); + emulators->setButtons(KEditListBox::Add | KEditListBox::Remove); + emulators->setItems(EmuDBConfig::instance()->emulators()); + connect(emulators, SIGNAL(added(QString)), this, SLOT(addEmulator(QString))); + connect(emulators, SIGNAL(removed(QString)), this, SLOT(removeEmulator(QString))); + + m_emulators = emulators->listView(); + connect(m_emulators, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(editEmulator(QModelIndex))); + + setMainWidget(emulators); +} + +void EmulatorEditor::editEmulator(const QModelIndex& index) +{ + editEmulator(EmuDBConfig::instance()->emulator(m_emulators->model()->data(index, Qt::DisplayRole).toString())); +} + +void EmulatorEditor::editEmulator(Emulator* emulator) +{ + if (!emulator) + return; + + m_emulator = emulator; + + KDialog* dialog = new KDialog(this); + dialog->setCaption("Edit Emulator"); + + QGroupBox* commandGroup = new QGroupBox("Command"); + + KLineEdit* command = new KLineEdit(emulator->command()); + KShellCompletion* completion = new KShellCompletion; + completion->setMode(KUrlCompletion::ExeCompletion); + command->setCompletionObject(completion); + command->setAutoDeleteCompletionObject(true); + connect(command, SIGNAL(textChanged(QString)), emulator, SLOT(setCommand(QString))); + + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget(command); + commandGroup->setLayout(layout); + + KEditListBox* types = new KEditListBox("Supported Types"); + types->setButtons(KEditListBox::Add | KEditListBox::Remove); + types->setItems(QStringList::fromSet(emulator->types())); + KComboBox* typeBox = new KComboBox(false); + typeBox->addItems(EmuDBConfig::instance()->romTypes()); + types->setCustomEditor(typeBox); + connect(types, SIGNAL(added(QString)), emulator, SLOT(addType(QString))); + connect(types, SIGNAL(removed(QString)), emulator, SLOT(removeType(QString))); + + KEditListBox* profiles = new KEditListBox("Profiles"); + profiles->setButtons(KEditListBox::Add | KEditListBox::Remove); + profiles->setItems(emulator->profileNames()); + connect(profiles, SIGNAL(added(QString)), this, SLOT(addProfile(QString))); + connect(profiles, SIGNAL(removed(QString)), this, SLOT(removeProfile(QString))); + + m_profiles = profiles->listView(); + connect(m_profiles, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(editProfile(QModelIndex))); + + QWidget* widget = new QWidget(this); + layout = new QVBoxLayout; + layout->addWidget(commandGroup); + layout->addWidget(types); + layout->addWidget(profiles); + + widget->setLayout(layout); + dialog->setMainWidget(widget); + dialog->exec(); + + delete dialog; +} + +void EmulatorEditor::addEmulator(const QString& name) +{ + EmuDBConfig::instance()->addEmulator(name, Emulator()); +} + +void EmulatorEditor::removeEmulator(const QString& name) +{ + EmuDBConfig::instance()->removeEmulator(name); +} + +void EmulatorEditor::editProfile(const QModelIndex& index) +{ + editProfile(m_emulator->profile(m_profiles->model()->data(index, Qt::DisplayRole).toString())); +} + +void EmulatorEditor::editProfile(Profile* profile) +{ + if (!profile) + return; + + KDialog* dialog = new KDialog(this); + dialog->setCaption("Edit Profile"); + + QGroupBox* workingPathGroup = new QGroupBox("Working Path"); + + KLineEdit* workingPath = new KLineEdit(profile->workingPath()); + KShellCompletion* completion = new KShellCompletion; + completion->setMode(KUrlCompletion::DirCompletion); + workingPath->setCompletionObject(completion); + workingPath->setAutoDeleteCompletionObject(true); + connect(workingPath, SIGNAL(textChanged(QString)), profile, SLOT(setWorkingPath(QString))); + + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget(workingPath); + workingPathGroup->setLayout(layout); + + KEditListBox* options = new KEditListBox("Options"); + options->setButtons(KEditListBox::Add | KEditListBox::Remove); + options->setItems(profile->options()); + connect(options, SIGNAL(added(QString)), profile, SLOT(addOption(QString))); + connect(options, SIGNAL(removed(QString)), profile, SLOT(removeOption(QString))); + + KEditListBox* environment = new KEditListBox("Environment"); + environment->setButtons(KEditListBox::Add | KEditListBox::Remove); + environment->setItems(profile->environmentList()); + connect(environment, SIGNAL(added(QString)), profile, SLOT(addEnvironment(QString))); + connect(environment, SIGNAL(removed(QString)), profile, SLOT(removeEnvironment(QString))); + + QWidget* widget = new QWidget(this); + layout = new QVBoxLayout; + layout->addWidget(workingPathGroup); + layout->addWidget(options); + layout->addWidget(environment); + + widget->setLayout(layout); + dialog->setMainWidget(widget); + dialog->exec(); + + delete dialog; +} + +void EmulatorEditor::addProfile(const QString& name) +{ + m_emulator->addProfile(name, Profile()); +} + +void EmulatorEditor::removeProfile(const QString& name) +{ + m_emulator->removeProfile(name); +} diff --git a/EmulatorEditor.h b/EmulatorEditor.h new file mode 100644 index 0000000..812771c --- /dev/null +++ b/EmulatorEditor.h @@ -0,0 +1,71 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file EmulatorEditor.h + */ + +#ifndef EMULATOREDITOR_H +#define EMULATOREDITOR_H + +// KDE includes +#include <KDialog> + +// Forward declarations +class Emulator; +class Profile; +class QListView; +class QModelIndex; + +/** + * \class EmulatorEditor + * \brief Dialog to edit an emulator. + */ +class EmulatorEditor : public KDialog +{ + Q_OBJECT + + public: + /** + * \brief Constructor. + * + * \param parent The parent of the editor. + */ + EmulatorEditor(QWidget* parent); + public slots: + void editEmulator(const QModelIndex& index); + + void editEmulator(Emulator* emulator); + + void addEmulator(const QString& name); + + void removeEmulator(const QString& name); + + void editProfile(const QModelIndex& index); + + void editProfile(Profile* profile); + + void addProfile(const QString& name); + + void removeProfile(const QString& name); + private: + QListView* m_emulators; + Emulator* m_emulator; + QListView* m_profiles; +}; + +#endif diff --git a/Execute.cpp b/Execute.cpp new file mode 100644 index 0000000..182b117 --- /dev/null +++ b/Execute.cpp @@ -0,0 +1,82 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file Execute.cpp + */ + +// Header include +#include "Execute.h" + +// EmuDB includes +#include "EmuDBConfig.h" +#include "Emulator.h" +#include "Rom.h" + +// KDE includes +#include <KComboBox> + +// Qt includes +#include <QtGui/QGroupBox> +#include <QtGui/QVBoxLayout> + +Execute::Execute(QWidget* parent, Rom* rom) : + KDialog(parent), + m_rom(rom) +{ + connect(this, SIGNAL(accepted()), SLOT(execute())); + + setCaption("Execute ROM"); + + QGroupBox* emulatorGroup = new QGroupBox("Emulator"); + + m_profile = new KComboBox(false); + + m_emulator = new KComboBox(false); + connect(m_emulator, SIGNAL(currentIndexChanged(QString)), this, SLOT(emulatorChanged(QString))); + m_emulator->addItems(EmuDBConfig::instance()->emulators()); + + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget(m_emulator); + emulatorGroup->setLayout(layout); + + m_useProfile = new QGroupBox("Profile"); + m_useProfile->setCheckable(true); + + layout = new QVBoxLayout; + layout->addWidget(m_profile); + m_useProfile->setLayout(layout); + + QWidget* widget = new QWidget; + layout = new QVBoxLayout; + layout->addWidget(emulatorGroup); + layout->addWidget(m_useProfile); + widget->setLayout(layout); + + setMainWidget(widget); +} + +void Execute::emulatorChanged(const QString& emulator) +{ + m_profile->clear(); + m_profile->addItems(EmuDBConfig::instance()->emulator(emulator)->profileNames()); +} + +void Execute::execute() +{ + EmuDBConfig::instance()->emulator(m_emulator->currentText())->execute(m_useProfile->isChecked() ? m_profile->currentText() : "", *m_rom); +} diff --git a/Execute.h b/Execute.h new file mode 100644 index 0000000..ea72758 --- /dev/null +++ b/Execute.h @@ -0,0 +1,59 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file Execute.h + */ + +#ifndef EXECUTE_H +#define EXECUTE_H + +// KDE includes +#include <KDialog> + +// Forward declarations +class Rom; +class KComboBox; +class QGroupBox; + +/** + * \class Execute + * \brief Dialog to edit a ROM. + */ +class Execute : public KDialog +{ + Q_OBJECT + + public: + /** + * \brief Constructor. + * + * \param parent The parent of the editor. + */ + Execute(QWidget* parent, Rom* rom); + protected slots: + void emulatorChanged(const QString& emulator); + + void execute(); + private: + Rom* m_rom; + KComboBox* m_emulator; + QGroupBox* m_useProfile; + KComboBox* m_profile; +}; + +#endif diff --git a/Profile.cpp b/Profile.cpp new file mode 100644 index 0000000..6466f5d --- /dev/null +++ b/Profile.cpp @@ -0,0 +1,133 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file Profile.cpp + */ + +// Header include +#include "Profile.h" + +// KDE includes +#include <KConfigGroup> + +// Qt includes +#include <QtCore/QDir> + +Profile::Profile() : + QObject(NULL) +{ +} + +Profile::Profile(const KConfigGroup& config) : + QObject(NULL) +{ + setWorkingPath(config.readEntry("workingPath", ".")); + m_options = config.readEntry("options", QList<QString>()); + QStringList envList = config.readEntry("environment", QStringList()); + foreach (const QString& env, envList) + addEnvironment(env); +} + +Profile::Profile(const Profile& rhs) : + QObject(NULL) +{ + *this = rhs; +} + +void Profile::makeGroup(const QString& name, const KConfigGroup& parent) const +{ + KConfigGroup config(&parent, name); + config.writeEntry("workingPath", m_workingPath); + config.writeEntry("options", m_options); + config.writeEntry("environment", environmentList()); +} + +void Profile::setWorkingPath(const QString& workingPath) +{ + if (QDir(".").exists(workingPath)) + m_workingPath = workingPath; +} + +void Profile::addOption(const QString& option) +{ + m_options.append(option); +} + +void Profile::removeOption(const QString& option) +{ + m_options.removeOne(option); +} + +void Profile::addEnvironment(const QString& expression) +{ + const int index = expression.indexOf('='); + m_enviroment[expression.mid(0, index)] = expression.mid(index + 1); +} + +void Profile::addEnvironment(const QString& variable, const QString& value) +{ + if (!variable.contains('=')) + m_enviroment[variable] = value; +} + +void Profile::removeEnvironment(const QString& variable) +{ + if (m_enviroment.contains(variable)) + m_enviroment.remove(variable); +} + +QString Profile::workingPath() const +{ + return m_workingPath; +} + +QStringList Profile::options() const +{ + return m_options; +} + +Profile::Environment Profile::environment() const +{ + return m_enviroment; +} + +QString Profile::environmentValue(const QString& variable) const +{ + if (m_enviroment.contains(variable)) + return m_enviroment[variable]; + return QString(); +} + +QStringList Profile::environmentList() const +{ + QStringList env; + QList<QString> vars = m_enviroment.keys(); + foreach (const QString& var, vars) + env << QString("%1=%2").arg(var).arg(m_enviroment[var]); + return env; +} + +Profile& Profile::operator=(const Profile& rhs) +{ + if (this == &rhs) + return *this; + m_workingPath = rhs.m_workingPath; + m_options = rhs.m_options; + m_enviroment = rhs.m_enviroment; + return *this; +} diff --git a/Profile.h b/Profile.h new file mode 100644 index 0000000..b31d9fe --- /dev/null +++ b/Profile.h @@ -0,0 +1,179 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file Profile.h + */ + +#ifndef PROFILE_H +#define PROFILE_H + +// Qt includes +#include <QtCore/QMap> +#include <QtCore/QString> +#include <QtCore/QStringList> + +// Forward declarations +class KConfigGroup; + +/** + * \class Profile + * \brief Gives an evironment for an emulator. + */ +class Profile : public QObject +{ + Q_OBJECT + /** + * \var workingPath + * \brief The working path when executed. + * + * \sa workingPath + * \sa setWorkingPath + */ + Q_PROPERTY(QString workingPath READ workingPath WRITE setWorkingPath) + /** + * \var options + * \brief The options for the emulator. + * + * \sa options + * \sa addOption + * \sa removeOption + */ + Q_PROPERTY(QStringList options READ options) + /** + * \var environment + * \brief The environment for the emulator + * + * \sa environment + * \sa environmentValue + * \sa environmentList + */ + Q_PROPERTY(Environment environment READ environment) + + public: + /** + * \typedef Environment + * \brief Type of the environment. + */ + typedef QMap<QString, QString> Environment; + + /** + * \brief Default constructor. + */ + Profile(); + + /** + * \brief Configuration constructor. + */ + Profile(const KConfigGroup& config); + + /** + * \brief Copy constructor. + * + * \param rhs The profile to copy. + */ + Profile(const Profile& rhs); + + /** + * \brief Create a KConfigGroup for saving. + * + * \param name The name of the group. + * \param parent The parent group. + */ + void makeGroup(const QString& name, const KConfigGroup& parent) const; + + /** + * \return The working path for the profile. + */ + QString workingPath() const; + + /** + * \return A list of options for the profile. + */ + QStringList options() const; + + /** + * \return A mapping of the environment. + */ + Environment environment() const; + + /** + * \param variable The variable to get. + * \return The value of the variable. + */ + QString environmentValue(const QString& variable) const; + + /** + * \return The environment in assignment form. + */ + QStringList environmentList() const; + + /** + * \brief Assignment method. + * \param rhs Profile to copy. + */ + Profile& operator=(const Profile& rhs); + public slots: + /** + * \brief Sets the path to run the command from. + * + * \param workingPath + */ + void setWorkingPath(const QString& workingPath); + + /** + * \brief Add an option when executed. + * + * \param option + */ + void addOption(const QString& option); + + /** + * \brief Remove an option from the profile. + * + * \param option + */ + void removeOption(const QString& option); + + /** + * \brief Add an environment expression to the profile. + * + * \param expression Expression for the environment. + */ + void addEnvironment(const QString& value); + + /** + * \brief Add an environment variable to the profile. + * + * \param variable The variable to set. + * \param value The value to set it to. + */ + void addEnvironment(const QString& variable, const QString& value); + + /** + * \brief Unset an environment variable. + * + * \param variable The variable to remove. + */ + void removeEnvironment(const QString& variable); + private: + QString m_workingPath; + QStringList m_options; + Environment m_enviroment; +}; + +#endif @@ -0,0 +1,124 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file Rom.cpp + */ + +// Header include +#include "Rom.h" + +// KDE includes +#include <KConfigGroup> + +// Qt includes +#include <QtCore/QFile> + +Rom::Rom() : + QObject(NULL), + m_rating(5) +{ +} + +Rom::Rom(const KConfigGroup& config) : + QObject(NULL) +{ + setName(config.readEntry("name", "")); + setPath(config.readEntry("path", "")); + setType(config.readEntry("type", "")); + setRating(config.readEntry("rating", 5)); + setNotes(config.readEntry("notes", "")); +} + +Rom::Rom(const Rom& rhs) : + QObject(NULL) +{ + *this = rhs; +} + +void Rom::makeGroup(const KConfigGroup& parent) const +{ + KConfigGroup config(&parent, m_name); + config.writeEntry("name", m_name); + config.writeEntry("path", m_path); + config.writeEntry("type", m_type); + config.writeEntry("rating", m_rating); + config.writeEntry("notes", m_notes); +} + +void Rom::setName(const QString& name) +{ + m_name = name; +} + +void Rom::setPath(const QString& path) +{ + if (QFile::exists(path)) + m_path = path; +} + +void Rom::setType(const QString& type) +{ + m_type = type; +} + +void Rom::setRating(const int rating) +{ + if ((0 < rating) && (rating < 11)) + m_rating = rating; +} + +void Rom::setNotes(const QString& notes) +{ + m_notes = notes; +} + +QString Rom::name() const +{ + return m_name; +} + +QString Rom::path() const +{ + return m_path; +} + +QString Rom::type() const +{ + return m_type; +} + +int Rom::rating() const +{ + return m_rating; +} + +QString Rom::notes() const +{ + return m_notes; +} + +Rom& Rom::operator=(const Rom& rhs) +{ + if (this == &rhs) + return *this; + m_name = rhs.m_name; + m_path = rhs.m_path; + m_type = rhs.m_type; + m_notes = rhs.m_notes; + return *this; +} @@ -0,0 +1,179 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file Rom.h + */ + +#ifndef ROM_H +#define ROM_H + +// Qt includes +#include <QtCore/QObject> +#include <QtCore/QString> + +// Forward declarations +class KConfigGroup; + +/** + * \class Rom + * \brief Details a ROM. + */ +class Rom : public QObject +{ + Q_OBJECT + /** + * \var name + * \brief The name of the ROM. + * + * \sa name + * \sa setName + */ + Q_PROPERTY(QString name READ name WRITE setName) + /** + * \var path + * \brief The location of the ROM. + * + * \sa path + * \sa setPath + */ + Q_PROPERTY(QString path READ path WRITE setPath) + /** + * \var type + * \brief The type of the ROM. + * + * \sa type + * \sa setType + */ + Q_PROPERTY(QString type READ type WRITE setType) + /** + * \var rating + * \brief The rating of the ROM on a scale of 1-10. + * + * \sa rating + * \sa setRating + */ + Q_PROPERTY(int rating READ rating WRITE setRating) + /** + * \var notes + * \brief Notes on the ROM. + * + * \sa notes + * \sa setNotes + */ + Q_PROPERTY(QString notes READ notes WRITE setNotes) + + public: + /** + * \brief Default constructor. + */ + Rom(); + + /** + * \brief Config constructor. + */ + Rom(const KConfigGroup& config); + + /** + * \brief Copy constructor. + * + * \param rhs The ROM to copy. + */ + Rom(const Rom& rhs); + + /** + * \brief Create a KConfigGroup for saving. + * + * \param parent The parent group. + */ + void makeGroup(const KConfigGroup& parent) const; + + /** + * \return The name of the ROM. + */ + QString name() const; + + /** + * \return The location of the ROM. + */ + QString path() const; + + /** + * \return The type of the ROM. + */ + QString type() const; + + /** + * \return The rating of the ROM. + */ + int rating() const; + + /** + * \return Notes anout the ROM. + */ + QString notes() const; + + /** + * \brief Assignment method. + * + * \param rhs ROM to copy. + */ + Rom& operator=(const Rom& rhs); + public slots: + /** + * \brief Set the name of the ROM. + * + * \param name + */ + void setName(const QString& name); + + /** + * \brief Set the location of the ROM. + * + * \param path + */ + void setPath(const QString& path); + + /** + * \brief Set the type of the ROM. + * + * \param type + */ + void setType(const QString& type); + + /** + * \brief Set the rating. + * + * \param rating + */ + void setRating(const int rating); + + /** + * \brief Set the notes about the ROM. + * + * \param notes + */ + void setNotes(const QString& notes); + private: + QString m_name; + QString m_path; + QString m_type; + int m_rating; + QString m_notes; +}; + +#endif diff --git a/RomEditor.cpp b/RomEditor.cpp new file mode 100644 index 0000000..8dafb6f --- /dev/null +++ b/RomEditor.cpp @@ -0,0 +1,108 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file RomEditor.cpp + */ + +// Header include +#include "RomEditor.h" + +// EmuDB includes +#include "EmuDBConfig.h" +#include "Rom.h" + +// KDE includes +#include <KComboBox> +#include <KLineEdit> +#include <KShellCompletion> + +// Qt includes +#include <QtGui/QGroupBox> +#include <QtGui/QVBoxLayout> + +RomEditor::RomEditor(QWidget* parent, Rom* rom) : + KDialog(parent) +{ + setCaption("Edit ROM"); + + QGroupBox* nameGroup = new QGroupBox("Name"); + + KLineEdit* name = new KLineEdit(rom->name()); + connect(name, SIGNAL(textChanged(QString)), rom, SLOT(setName(QString))); + + QVBoxLayout* layout = new QVBoxLayout; + layout->addWidget(name); + nameGroup->setLayout(layout); + + QGroupBox* pathGroup = new QGroupBox("Path"); + + KLineEdit* path = new KLineEdit(rom->path()); + KShellCompletion* completion = new KShellCompletion; + completion->setMode(KUrlCompletion::FileCompletion); + path->setCompletionObject(completion); + path->setAutoDeleteCompletionObject(true); + connect(path, SIGNAL(textChanged(QString)), rom, SLOT(setPath(QString))); + + layout = new QVBoxLayout; + layout->addWidget(path); + pathGroup->setLayout(layout); + + QGroupBox* typeGroup = new QGroupBox("Type"); + + KComboBox* type = new KComboBox(false); + type->addItems(EmuDBConfig::instance()->romTypes()); + type->setCurrentIndex(type->findText(rom->type())); + connect(type, SIGNAL(currentIndexChanged(QString)), rom, SLOT(setType(QString))); + + layout = new QVBoxLayout; + layout->addWidget(type); + typeGroup->setLayout(layout); + + QGroupBox* ratingGroup = new QGroupBox("Rating"); + + QSlider* rating = new QSlider(Qt::Horizontal); + rating->setRange(1, 10); + rating->setValue(rom->rating()); + rating->setTickPosition(QSlider::TicksAbove); + rating->setTickInterval(1); + connect(rating, SIGNAL(valueChanged(int)), rom, SLOT(setRating(int))); + + layout = new QVBoxLayout; + layout->addWidget(rating); + ratingGroup->setLayout(layout); + + QGroupBox* notesGroup = new QGroupBox("Notes"); + + KLineEdit* notes = new KLineEdit(rom->notes()); + connect(notes, SIGNAL(textChanged(QString)), rom, SLOT(setNotes(QString))); + + layout = new QVBoxLayout; + layout->addWidget(notes); + notesGroup->setLayout(layout); + + QWidget* widget = new QWidget; + layout = new QVBoxLayout; + layout->addWidget(nameGroup); + layout->addWidget(pathGroup); + layout->addWidget(typeGroup); + layout->addWidget(ratingGroup); + layout->addWidget(notesGroup); + widget->setLayout(layout); + + setMainWidget(widget); +} diff --git a/RomEditor.h b/RomEditor.h new file mode 100644 index 0000000..b565ddc --- /dev/null +++ b/RomEditor.h @@ -0,0 +1,48 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file RomEditor.h + */ + +#ifndef ROMEDITOR_H +#define ROMEDITOR_H + +// KDE includes +#include <KDialog> + +// Forward declarations +class Rom; + +/** + * \class RomEditor + * \brief Dialog to edit a ROM. + */ +class RomEditor : public KDialog +{ + Q_OBJECT + + public: + /** + * \brief Constructor. + * + * \param parent The parent of the editor. + */ + RomEditor(QWidget* parent, Rom* rom); +}; + +#endif diff --git a/RomLibrary.cpp b/RomLibrary.cpp new file mode 100644 index 0000000..298ccac --- /dev/null +++ b/RomLibrary.cpp @@ -0,0 +1,54 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file RomLibrary.cpp + */ + +// Header include +#include "RomLibrary.h" + +// EmuDB includes +#include "Rom.h" + +RomLibrary::~RomLibrary() +{ + qDeleteAll(m_library); +} + +void RomLibrary::addRom(Rom* const & rom) +{ + m_library.append(rom); + emit(added()); +} + +void RomLibrary::removeRom(Rom* const & rom) +{ + const int index = m_library.indexOf(rom); + m_library.removeOne(rom); + emit(removed(index)); +} + +int RomLibrary::size() const +{ + return m_library.size(); +} + +Rom* RomLibrary::rom(const int row) +{ + return m_library[row]; +} diff --git a/RomLibrary.h b/RomLibrary.h new file mode 100644 index 0000000..115c33a --- /dev/null +++ b/RomLibrary.h @@ -0,0 +1,74 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file RomLibrary.h + */ + +#ifndef ROMLIBRARY_H +#define ROMLIBRARY_H + +// Qt includes +#include <QtCore/QObject> +#include <QtCore/QList> + +// Forward declarations +class Rom; + +/** + * \class RomLibrary + * \brief Wrapper around a QList that signals about changes. + */ +class RomLibrary : public QObject +{ + Q_OBJECT + + public: + ~RomLibrary(); + + /** + * \param rom The ROM to append to the list + */ + void addRom(Rom* const & rom); + + /** + * \param rom + */ + void removeRom(Rom* const & rom); + + /** + * \return The size of the library. + */ + int size() const; + + /** + * \param row The ROM to return. + * \return The ROM. + */ + Rom* rom(const int row); + signals: + /** + * \param index The ROM that was removed. + */ + void removed(int index); + + void added(); + private: + QList<Rom*> m_library; +}; + +#endif diff --git a/RomModel.cpp b/RomModel.cpp new file mode 100644 index 0000000..6afcd6d --- /dev/null +++ b/RomModel.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file RomModel.cpp + */ + +// Header include +#include "RomModel.h" + +// EmuDB includes +#include "EmuDBConfig.h" +#include "Rom.h" + +RomModel::RomModel(QTreeWidgetItem* parent, Rom* rom) : + QTreeWidgetItem(parent), + m_rom(rom) +{ +} + +Qt::ItemFlags RomModel::flags() const +{ + return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; +} + +void RomModel::setData(const int column, int role, const QVariant& value) +{ + if (role == Qt::EditRole) + m_rom->setProperty(EmuDBConfig::instance()->columnName(column), value); +} + +QVariant RomModel::data(const int column, int role) const +{ + if ((role == Qt::EditRole) || (role == Qt::DisplayRole)) + return m_rom->property(EmuDBConfig::instance()->columnName(column)); + return QVariant(); +} + +Rom* RomModel::rom() +{ + return m_rom; +} diff --git a/RomModel.h b/RomModel.h new file mode 100644 index 0000000..b27a2f5 --- /dev/null +++ b/RomModel.h @@ -0,0 +1,70 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file RomModel.h + */ + +#ifndef ROMMODEL_H +#define ROMMODEL_H + +// Qt includes +#include <QtGui/QTreeWidgetItem> + +// Forward declarations +class Rom; +class RomLibrary; + +/** + * \class RomModel + * \brief Model used to view the library. + */ +class RomModel : public QTreeWidgetItem +{ + public: + /** + * \brief Default constructor. + */ + RomModel(QTreeWidgetItem* parent, Rom* rom); + + /** + * \return Flags for the model. + */ + Qt::ItemFlags flags() const; + + /** + * \brief Set data in the list. + * + * \param index The index to set the data. + * \param role What part of the data to set. + * \param value The data. + */ + void setData(const int column, const int role, const QVariant& value); + + /** + * \param column The column to get the data from. + * \param role What part of the data to get. + * \return The data. + */ + QVariant data(const int column, int role = Qt::DisplayRole) const; + + Rom* rom(); + private: + Rom* m_rom; +}; + +#endif diff --git a/RomType.cpp b/RomType.cpp new file mode 100644 index 0000000..8fb2e72 --- /dev/null +++ b/RomType.cpp @@ -0,0 +1,76 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file RomType.cpp + */ + +// Header include +#include "RomType.h" + +// EmuDB includes +#include "EmuDBConfig.h" + +// KDE includes +#include <KConfigGroup> + +RomType::RomType() : + QObject(NULL) +{ +} + +RomType::RomType(const KConfigGroup& config) : + QObject(NULL) +{ + m_extensions = QSet<QString>::fromList(config.readEntry("extensions", QList<QString>())); +} + +RomType::RomType(const RomType& rhs) : + QObject(NULL) +{ + *this = rhs; +} + +void RomType::makeGroup(const QString& name, const KConfigGroup& parent) const +{ + KConfigGroup config(&parent, name); + config.writeEntry("extensions", QList<QString>::fromSet(m_extensions)); +} + +void RomType::addExtension(const QString& extension) +{ + m_extensions.insert(extension); +} + +void RomType::removeExtension(const QString& extension) +{ + if (m_extensions.contains(extension)) + m_extensions.remove(extension); +} + +QSet<QString> RomType::extensions() const +{ + return m_extensions; +} + +RomType& RomType::operator=(const RomType& rhs) +{ + if (this == &rhs) + return *this; + m_extensions = rhs.m_extensions; + return *this; +} diff --git a/RomType.h b/RomType.h new file mode 100644 index 0000000..04fbd5e --- /dev/null +++ b/RomType.h @@ -0,0 +1,104 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file RomType.h + */ + +#ifndef ROMTYPE_H +#define ROMTYPE_H + +// Qt includes +#include <QtCore/QMetaType> +#include <QtCore/QObject> +#include <QtCore/QSet> + +// Forward declarations +class KConfigGroup; + +/** + * \class RomType + * \brief Description of a ROM type. + */ +class RomType : public QObject +{ + Q_OBJECT + /** + * \var extensions + * \brief The extensions the ROMs have. + * + * \sa extensions + * \sa addExtension + * \sa removeExtension + */ + Q_PROPERTY(QSet<QString> extensions READ extensions) + + public: + /** + * \brief Default constructor. + */ + RomType(); + + /** + * \brief Config constructor. + */ + RomType(const KConfigGroup& config); + + /** + * \brief Copy constructor. + */ + RomType(const RomType& rhs); + + /** + * \brief Create a KConfigGroup for saving. + * + * \param name The name of the group. + * \param parent The parent group. + */ + void makeGroup(const QString& name, const KConfigGroup& parent) const; + + /** + * \return The set of extensions for the type. + */ + QSet<QString> extensions() const; + + /** + * \brief Assignment method. + * + * \param rhs Type to copy. + */ + RomType& operator=(const RomType& rhs); + public slots: + /** + * \brief Adds an extension the type can have. + * + * \param extension + */ + void addExtension(const QString& extension); + + /** + * \brief Remove an extension for the type. + * + * \param extension + */ + void removeExtension(const QString& extension); + private: + QSet<QString> m_extensions; +}; +Q_DECLARE_METATYPE(RomType*) + +#endif diff --git a/RomTypeEditor.cpp b/RomTypeEditor.cpp new file mode 100644 index 0000000..e2051fc --- /dev/null +++ b/RomTypeEditor.cpp @@ -0,0 +1,89 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file RomTypeEditor.cpp + */ + +// Header include +#include "RomTypeEditor.h" + +// EmuDB includes +#include "EmuDBConfig.h" +#include "RomType.h" + +// KDE includes +#include <KComboBox> +#include <KEditListBox> +#include <KListWidget> +#include <KPushButton> + +// Qt includes +#include <QtGui/QGroupBox> +#include <QtGui/QVBoxLayout> + +RomTypeEditor::RomTypeEditor(QWidget* parent) : + KDialog(parent) +{ + setCaption("Edit ROM Types"); + + KEditListBox* romTypes = new KEditListBox("ROM Types", this); + romTypes->setButtons(KEditListBox::Add | KEditListBox::Remove); + romTypes->setItems(EmuDBConfig::instance()->romTypes()); + connect(romTypes, SIGNAL(added(QString)), this, SLOT(addRomType(QString))); + connect(romTypes, SIGNAL(removed(QString)), this, SLOT(removeRomType(QString))); + + m_types = romTypes->listView(); + connect(m_types, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(editRomType(QModelIndex))); + + setMainWidget(romTypes); +} + +void RomTypeEditor::editRomType(const QModelIndex& index) +{ + editRomType(EmuDBConfig::instance()->romType(m_types->model()->data(index, Qt::DisplayRole).toString())); +} + +void RomTypeEditor::editRomType(RomType* type) +{ + if (!type) + return; + + KDialog* dialog = new KDialog(this); + dialog->setCaption("Edit ROM Type"); + + KEditListBox* extensions = new KEditListBox("Extensions", this); + extensions->setButtons(KEditListBox::Add | KEditListBox::Remove); + extensions->setItems(QStringList::fromSet(type->extensions())); + connect(extensions, SIGNAL(added(QString)), type, SLOT(addExtension(QString))); + connect(extensions, SIGNAL(removed(QString)), type, SLOT(removeExtension(QString))); + + dialog->setMainWidget(extensions); + dialog->exec(); + + delete dialog; +} + +void RomTypeEditor::addRomType(const QString& name) +{ + EmuDBConfig::instance()->addRomType(name, RomType()); +} + +void RomTypeEditor::removeRomType(const QString& name) +{ + EmuDBConfig::instance()->removeRomType(name); +} diff --git a/RomTypeEditor.h b/RomTypeEditor.h new file mode 100644 index 0000000..f3b782e --- /dev/null +++ b/RomTypeEditor.h @@ -0,0 +1,57 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file RomTypeEditor.h + */ + +#ifndef ROMTYPEEDITOR_H +#define ROMTYPEEDITOR_H + +// KDE includes +#include <KDialog> + +// Forward declarations +class RomType; +class QListView; +class QModelIndex; + +/** + * \class RomTypeEditor + * \brief Dialog to edit a ROM type. + */ +class RomTypeEditor : public KDialog +{ + Q_OBJECT + + public: + /** + * \brief Constructor. + * + * \param parent The parent of the editor. + */ + RomTypeEditor(QWidget* parent); + public slots: + void editRomType(const QModelIndex& index); + void editRomType(RomType* type); + void addRomType(const QString& name); + void removeRomType(const QString& name); + private: + QListView* m_types; +}; + +#endif diff --git a/doxygen.cmake b/doxygen.cmake new file mode 100644 index 0000000..6322475 --- /dev/null +++ b/doxygen.cmake @@ -0,0 +1,34 @@ +FIND_PACKAGE(Doxygen) + +IF(DOXYGEN_EXECUTABLE AND UNIX) + ADD_CUSTOM_COMMAND( + OUTPUT ${DOCUMENTATION_OUTPUT_PATH} + COMMAND mkdir ${DOCUMENTATION_OUTPUT_PATH} + ) + + ADD_CUSTOM_COMMAND( + OUTPUT ${DOCUMENTATION_OUTPUT_PATH}/Doxyfile + COMMAND sed ${CMAKE_SOURCE_DIR}/Doxyfile -e 's!PROJECT_SOURCE_DIR!${PROJECT_SOURCE_DIR}!' -e 's!DOCUMENTATION_OUTPUT_PATH!${DOCUMENTATION_OUTPUT_PATH}!' > Doxyfile + DEPENDS Doxyfile + DEPENDS ${DOCUMENTATION_OUTPUT_PATH} + WORKING_DIRECTORY ${DOCUMENTATION_OUTPUT_PATH} + ) + + ADD_CUSTOM_COMMAND( + OUTPUT ${DOCUMENTATION_OUTPUT_PATH}/html + COMMAND ${DOXYGEN_EXECUTABLE} + DEPENDS ${DOCUMENTATION_OUTPUT_PATH}/Doxyfile + WORKING_DIRECTORY ${DOCUMENTATION_OUTPUT_PATH} + ) + + ADD_CUSTOM_TARGET(doxygen + ALL echo + DEPENDS ${DOCUMENTATION_OUTPUT_PATH}/html + ) + + INSTALL( + DIRECTORY ${DOCUMENTATION_OUTPUT_PATH}/html + DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/${CMAKE_PROJECT_NAME}-${SIGEN_VERSION} + COMPONENT documentation + ) +ENDIF(DOXYGEN_EXECUTABLE AND UNIX) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..774a7fe --- /dev/null +++ b/main.cpp @@ -0,0 +1,55 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// EmuDB includes +#include "EmuDB.h" +#include "EmuDBConfig.h" + +// KDE includes +#include <KAboutData> +#include <KApplication> +#include <KCmdLineArgs> + +int main(int argc, char* argv[]) +{ + KAboutData about("emudb", "emudb", ki18n("EmuDB"), "0.0.1", ki18n(""), KAboutData::License_GPL_V3, ki18n("©2008 Ben Boeckel"), ki18n(""), ""); + about.setProgramName(ki18n("EmuDB")); + about.addAuthor(ki18n("Ben Boeckel"), ki18n("Lead Programmer"), "MathStuf@gmail.com", ""); + about.setBugAddress("MathStuf@gmail.com"); + about.setCopyrightStatement(ki18n("2008, Ben Boeckel")); + about.setOrganizationDomain(""); + // TODO: Need one of these... +// about.setProgramLogo(); + // TODO: And some of these... + about.setTranslator(ki18nc("NAME OF TRANSLATORS", "Your names"), ki18nc("EMAIL OF TRANSLATORS", "Your emails")); + + KCmdLineArgs::init(argc, argv, &about); + + KApplication* app = new KApplication; + + EmuDBConfig::instance(); + + EmuDB* emudb = new EmuDB; + emudb->show(); + + const int ret = app->exec(); + + EmuDBConfig::cleanup(); + delete app; + + return ret; +} |