Compare commits

...

5 Commits

Author SHA1 Message Date
tasgoon 32a7a6fc1d revamping creation 2016-07-02 00:50:24 -04:00
tasgoon db5b1f37d5 simplified main page 2016-05-29 22:45:20 -04:00
tasgoon db61fd3ad9 it saves now 2016-05-17 18:11:35 -04:00
tasgoon ca05bbce4d data storage work 2016-05-16 23:28:44 -04:00
tasgoon a2a8b332d8 config management, etc. 2016-05-16 17:42:05 -04:00
18 changed files with 297 additions and 53 deletions

View File

@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT += core gui webkitwidgets network
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@ -17,12 +17,16 @@ SOURCES += main.cpp\
mainwindow.cpp \
profile.cpp \
profilemanager.cpp \
createdialog.cpp
createdialog.cpp \
processui.cpp \
datamanager.cpp
HEADERS += mainwindow.h \
profile.h \
profilemanager.h \
createdialog.h
createdialog.h \
processui.h \
datamanager.h
FORMS += mainwindow.ui \
createdialog.ui

View File

@ -6,11 +6,11 @@ CreateDialog::CreateDialog(QWidget *parent) :
ui(new Ui::CreateDialog)
{
ui->setupUi(this);
ui->statusLayout->setContentsMargins(0, w0, 0, 0);
connect(&nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(loadVersionList(QNetworkReply*)));
QUrl url("https://api.github.com/repos/minetest/minetest/releases");
qDebug() << "Url: " << url.toString();
QNetworkRequest request(url);
qDebug() << "Url: " << MINETEST_URL.toString();
QNetworkRequest request(MINETEST_URL);
nam.get(request);
}
@ -22,16 +22,15 @@ CreateDialog::~CreateDialog()
void CreateDialog::loadVersionList(QNetworkReply *reply)
{
qDebug() << "Reply code: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug() << "Redirection url: " << reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
qDebug() << "Data size: " << reply->size();
QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
QJsonArray array = document.array();
qDebug() << "Array size: " << array.size();
qDebug() << "Versions: " << array.size();
for (int i = 0; i < array.size(); i++)
ui->versionList->addItem(array.at(i).toObject().value("tag_name").toString());
reply->deleteLater();
ui->buttonBox->setEnabled(true);
}
void CreateDialog::newProfile(ProfileManager *manager)
@ -40,6 +39,6 @@ void CreateDialog::newProfile(ProfileManager *manager)
if (dialog.exec() != QDialog::Accepted)
return;
manager->addProfile(Profile(dialog.ui->nameBox->text(), dialog.ui->versionList->currentText()));
qDebug() << "Profile name:" << dialog.ui->nameBox->text() << ", version:" << dialog.ui->versionList->currentText() << "added.";
if (!manager->addProfile(Profile(dialog.ui->nameBox->text(), dialog.ui->versionList->currentText())))
QMessageBox::critical(0, "Error", "A profile with the same name already exists.");
}

View File

@ -9,6 +9,7 @@
#include <QJsonDocument>
#include <QJsonArray>
#include <QEventLoop>
#include <QMessageBox>
#include "profilemanager.h"
namespace Ui {
@ -29,6 +30,8 @@ private:
Ui::CreateDialog *ui;
QNetworkAccessManager nam;
QUrl MINETEST_URL = QUrl("https://api.github.com/repos/minetest/minetest/releases");
private slots:
void loadVersionList(QNetworkReply*);
};

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>379</width>
<height>98</height>
<height>130</height>
</rect>
</property>
<property name="sizePolicy">
@ -23,28 +23,31 @@
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QLineEdit" name="nameBox"/>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Version:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="versionList"/>
</item>
<item row="2" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -53,6 +56,22 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="textVisible">
<bool>true</bool>
</property>
<property name="format">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

52
datamanager.cpp Normal file
View File

@ -0,0 +1,52 @@
#include "datamanager.h"
#include <QDebug>
DataManager::DataManager(QString filename)
{
file = new QFile(filename);
if (file->exists() && file->size() > 0) {
file->open(QIODevice::ReadOnly);
jsonObject = QJsonDocument::fromJson(file->readAll()).object();
file->close();
}
else {
jsonObject = QJsonObject();
}
}
void DataManager::loadProfiles() {
if (jsonObject["instances"].isArray()) {
QJsonArray profileArray = jsonObject["instances"].toArray();
qDebug() << profileArray.size() << " profiles to be loaded.";
for (int i = 0; i < profileArray.size(); i++) {
manager->addProfile(Profile::fromJson(profileArray.at(i)));
}
}
qDebug() << manager->profiles.size() << "profiles loaded.";
}
void DataManager::saveProfiles()
{
QJsonArray profileArray = QJsonArray();
for (Profile profile : manager->profiles) {
profileArray.append(profile.toJson());
qDebug() << profile.getName() << "saved.";
}
jsonObject["instances"] = profileArray;
qDebug("Saved profiles");
save();
}
void DataManager::save()
{
file->open(QIODevice::WriteOnly | QIODevice::Truncate);
QJsonDocument document;
document.setObject(jsonObject);
file->write(document.toJson());
file->close();
qDebug("Saved");
}

34
datamanager.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef DATAMANAGER_H
#define DATAMANAGER_H
#include "profilemanager.h"
#include <QString>
#include <QFile>
#include <QDir>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
const QJsonObject DEFAULT_OBJECT
{
{"instances", QJsonArray()}
};
//QString DEFAULT_PATH = QDir::homePath() + "/.minetest/minetestlauncher.conf";
class DataManager
{
public:
DataManager(QString);
inline void setManager(ProfileManager *mgr) { manager = mgr; }
void loadProfiles();
void saveProfiles();
void save();
private:
ProfileManager *manager;
QJsonObject jsonObject;
QFile *file;
};
#endif // DATAMANAGER_H

View File

@ -8,6 +8,15 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
connect(ui->createBtn, SIGNAL(clicked()), this, SLOT(newProfile()));
connect(ui->deleteBtn, SIGNAL(clicked()), this, SLOT(deleteSelected()));
connect(ui->playBtn, SIGNAL(clicked()), this, SLOT(playSelected()));
QFont font;
font.setPointSize(32);
ui->greetingText->setFont(font);
dataManager->setManager(profileManager);
dataManager->loadProfiles();
profileManager->refreshList(ui->comboBox);
}
MainWindow::~MainWindow()
@ -17,12 +26,19 @@ MainWindow::~MainWindow()
void MainWindow::newProfile()
{
CreateDialog::newProfile(manager);
manager->refreshList(ui->comboBox);
CreateDialog::newProfile(profileManager);
profileManager->refreshList(ui->comboBox);
dataManager->saveProfiles();
}
void MainWindow::deleteSelected()
{
manager->deleteByName(ui->comboBox->currentText());
manager->refreshList(ui->comboBox);
profileManager->deleteByName(ui->comboBox->currentText());
profileManager->refreshList(ui->comboBox);
dataManager->saveProfiles();
}
void MainWindow::playSelected()
{
profileManager->getByName(ui->comboBox->currentText()).play(ui->tabWidget);
}

View File

@ -2,7 +2,10 @@
#define MAINWINDOW_H
#include <QMainWindow>
#include <QFile>
#include <QDir>
#include "createdialog.h"
#include "datamanager.h"
namespace Ui {
class MainWindow;
@ -19,10 +22,12 @@ public:
private slots:
void newProfile();
void deleteSelected();
void playSelected();
private:
Ui::MainWindow *ui;
ProfileManager *manager = new ProfileManager();
DataManager *dataManager = new DataManager(QDir::homePath() + "/.minetest/minetestlauncher.conf");
ProfileManager *profileManager = new ProfileManager();
};
#endif // MAINWINDOW_H

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1099</width>
<height>626</height>
<width>783</width>
<height>496</height>
</rect>
</property>
<property name="windowTitle">
@ -17,15 +17,36 @@
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QWebView" name="webView">
<property name="url">
<url>
<string>http://dev.minetest.net/index.php?title=Changelog&amp;printable=yes#0.4.12_.E2.86.92_0.4.13</string>
</url>
<widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>2</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<widget class="QWidget" name="mainTab">
<attribute name="title">
<string>Main</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="greetingText">
<property name="text">
<string>Welcome to the Minetest Launcher!</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget">
<layout class="QHBoxLayout" name="horizontalLayout">
@ -93,8 +114,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1099</width>
<height>19</height>
<width>783</width>
<height>21</height>
</rect>
</property>
</widget>
@ -109,13 +130,6 @@
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKitWidgets/QWebView</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

28
processui.cpp Normal file
View File

@ -0,0 +1,28 @@
#include "processui.h"
ProcessUi::ProcessUi(QWidget* parent, QString cmd)
: QTextEdit()
{
command = cmd;
setReadOnly(true);
process = new QProcess(this);
connect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(readStdOutput()));
connect(process,SIGNAL(error(QProcess::ProcessError)),this,SLOT(readError()));
}
void ProcessUi::start()
{
append("Executing: " + command);
process->start(command);
}
void ProcessUi::readStdOutput()
{
append(process->readAllStandardOutput());
}
void ProcessUi::readError()
{
append("An Error Occured! Error Code is: " + QString::number(process->error()));
}

24
processui.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef PROCESSUI_H
#define PROCESSUI_H
#include <QProcess>
#include <QTextEdit>
#include <QString>
class ProcessUi : public QTextEdit
{
Q_OBJECT
public:
ProcessUi(QWidget* parent, QString cmd);
void start();
private slots:
void readStdOutput();
void readError();
private:
QString command;
QProcess* process;
};
#endif // PROCESSUI_H

View File

@ -6,12 +6,42 @@ Profile::Profile(QString n, QString v)
version = v;
}
Profile Profile::fromJson(QJsonObject obj)
Profile Profile::fromJson(QJsonValue val)
{
QJsonObject obj = val.toObject();
return Profile(obj.value("name").toString(), obj.value("version").toString());
}
QJsonObject Profile::toJson()
{
QJsonObject object;
object.insert("name", name);
object.insert("version", version);
return object;
}
QDir Profile::getPath()
{
return QDir(prefix.filePath(name));
}
void Profile::play(QTabWidget *widget)
{
QString cmd = "/bin/bash -c \"/home/myself/Code/C++/MinetestLauncher/scripts/linux.sh create %1 %2\"";
ProcessUi* process = new ProcessUi(widget, cmd.arg(name, version));
widget->addTab(process, name);
process->start();
widget->setCurrentIndex(widget->indexOf(process));
}
void Profile::build()
{
#ifdef _WIN32
#else
#endif
}
void Profile::start()
{
}

View File

@ -4,6 +4,8 @@
#include <QString>
#include <QDir>
#include <QJsonObject>
#include <QTabWidget>
#include "processui.h"
using namespace std;
@ -11,13 +13,19 @@ class Profile
{
public:
Profile(QString, QString);
static Profile fromJson(QJsonObject);
static Profile fromJson(QJsonValue);
QJsonObject toJson();
QDir getPath();
QString getName() { return name; }
QString getVersion() { return version; }
void play(QTabWidget*);
private:
void build();
void start();
bool created = false;
QDir prefix = QDir(QDir::home().filePath(".minetest"));
QString name, version;
};

View File

@ -2,14 +2,20 @@
ProfileManager::ProfileManager()
{
}
Profile ProfileManager::getByName(QString name)
{
for (Profile profile : profiles) {
if (profile.getName() == name) return profile;
}
}
bool ProfileManager::addProfile(Profile profile)
{
for (Profile p : profiles)
if (p.getName() == profile.getName())
return false;
for (Profile p : profiles) {
if (p.getName() == profile.getName()) return false;
}
profiles.push_back(profile);
return true;
@ -17,12 +23,13 @@ bool ProfileManager::addProfile(Profile profile)
bool ProfileManager::deleteByName(QString name)
{
for (int i = 0; i < profiles.size(); i++)
for (int i = 0; i < profiles.size(); i++) {
if (profiles[i].getName() == name)
{
profiles.erase(profiles.begin() + i);
return true;
}
}
return false;
}

View File

@ -11,6 +11,7 @@ class ProfileManager
{
public:
ProfileManager();
Profile getByName(QString);
bool addProfile(Profile);
bool deleteByName(QString);
void refreshList(QComboBox*);

View File

@ -1 +1,6 @@
<RCC/>
<RCC>
<qresource prefix="/">
<file>scripts/linux.sh</file>
<file>scripts/windows.vbs</file>
</qresource>
</RCC>

View File

@ -50,21 +50,16 @@ install () {
}
case $1 in
help)
echo "list - list all current installed instances"
echo "create - create a new Minetest instance"
echo "play - play an instance"
;;
list)
ls -1 ~/.minetest/instances
;;
create)
VERSION=$3
libs
install
cd ..
./bin/minetest
;;
play)
cd $TARGET
./bin/minetest
;;
esac

0
scripts/windows.vbs Normal file
View File