From b447d4c329e9179ca4080940808c13e6e430f1f0 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 16 Apr 2017 02:56:47 -0500 Subject: [PATCH] Add Nostalgia Studio profile option --- src/studio/main.cpp | 27 +++++++++++++++++++++++---- src/studio/mainwindow.cpp | 8 ++++---- src/studio/mainwindow.hpp | 15 ++++++++++++++- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/studio/main.cpp b/src/studio/main.cpp index 652f88d9..913dec4e 100644 --- a/src/studio/main.cpp +++ b/src/studio/main.cpp @@ -7,14 +7,33 @@ */ #include -#include "studio/mainwindow.hpp" +#include +#include +#include +#include "json/json.hpp" +#include "mainwindow.hpp" using namespace nostalgia::studio; +using namespace ox::clargs; -int main(int argc, char **argv) { - QApplication app(argc, argv); +int main(int argc, char **args) { + ClArgs clargs(argc, (const char**) args); + QString argProfilePath = clargs.getString("profile").c_str(); - MainWindow w; + NostalgiaStudioProfile config; + + // load in config file + QFile file(argProfilePath); + if (file.exists()) { + file.open(QIODevice::ReadOnly); + QTextStream in(&file); + read(in.readAll(), &config); + } + + QApplication app(argc, args); + app.setApplicationName(config.app_name); + + MainWindow w(config); w.show(); return app.exec(); diff --git a/src/studio/mainwindow.cpp b/src/studio/mainwindow.cpp index 04bcaabf..97702c5e 100644 --- a/src/studio/mainwindow.cpp +++ b/src/studio/mainwindow.cpp @@ -8,21 +8,21 @@ #include #include -#include "studio/mainwindow.hpp" +#include "mainwindow.hpp" namespace nostalgia { namespace studio { -MainWindow::MainWindow(QWidget *parent) { +MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) { auto screenSize = QApplication::desktop()->screenGeometry(); - // set window to 70% of screen width, and center it + // set window to 70% of screen width, and center NostalgiaStudioProfile auto sizePct = 0.7; resize(screenSize.width() * sizePct, screenSize.height() * sizePct); move(-x(), -y()); move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2); - setWindowTitle("Nostalgia Studio"); + setWindowTitle(config.app_name); } MainWindow::~MainWindow() { diff --git a/src/studio/mainwindow.hpp b/src/studio/mainwindow.hpp index 7be3c5f1..bdb2f2fc 100644 --- a/src/studio/mainwindow.hpp +++ b/src/studio/mainwindow.hpp @@ -7,6 +7,7 @@ */ #pragma once +#include #include #include #include @@ -15,6 +16,18 @@ namespace nostalgia { namespace studio { +struct NostalgiaStudioProfile { + QString app_name; +}; + +template +int ioOp(T *io, NostalgiaStudioProfile *obj) { + ox::Error err = 0; + err |= io->op("app_name", &obj->app_name); + return err; +} + + class MainWindow: public QMainWindow { Q_OBJECT public: @@ -25,7 +38,7 @@ class MainWindow: public QMainWindow { QString m_projectPath; public: - explicit MainWindow(QWidget *parent = 0); + MainWindow(NostalgiaStudioProfile config, QWidget *parent = 0); virtual ~MainWindow(); void openProject(QString);