Skip to content

Commit

Permalink
Added a first launch dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarsnik committed Dec 17, 2017
1 parent ed1e015 commit a84703a
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 5 deletions.
9 changes: 6 additions & 3 deletions Savestate2snes.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ SOURCES += main.cpp\
savestate2snesw.cpp \
handlestuff.cpp \
usb2snes.cpp \
usb2snesstatut.cpp
usb2snesstatut.cpp \
firsttimedialog.cpp

HEADERS += savestate2snesw.h \
handlestuff.h \
usb2snes.h \
usb2snesstatut.h
usb2snesstatut.h \
firsttimedialog.h

FORMS += savestate2snesw.ui \
usb2snesstatut.ui
usb2snesstatut.ui \
firsttimedialog.ui

RC_FILE = savestate2snes.rc

Expand Down
43 changes: 43 additions & 0 deletions firsttimedialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "firsttimedialog.h"
#include "ui_firsttimedialog.h"

#include <QFileDialog>
#include <QStandardPaths>

FirstTimeDialog::FirstTimeDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::FirstTimeDialog)
{
ui->setupUi(this);
savePath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/" + "Savestates";
ui->directoryPathLabel->setText(savePath);
ui->pushButton->setIcon(style()->standardPixmap(QStyle::SP_DialogOpenButton));
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
pathChanged = false;
}

FirstTimeDialog::~FirstTimeDialog()
{
delete ui;
}

void FirstTimeDialog::on_pushButton_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Savestates directory"), QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), QFileDialog::ShowDirsOnly);
if (dir.isEmpty())
return;
pathChanged = true;
savePath = dir;
ui->directoryPathLabel->setText(dir);
}

void FirstTimeDialog::on_buttonBox_accepted()
{
if (!pathChanged)
QDir("/").mkdir(savePath);
}

void FirstTimeDialog::on_versionsCheckBox_toggled(bool checked)
{
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(checked);
}
31 changes: 31 additions & 0 deletions firsttimedialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef FIRSTTIMEDIALOG_H
#define FIRSTTIMEDIALOG_H

#include <QDialog>

namespace Ui {
class FirstTimeDialog;
}

class FirstTimeDialog : public QDialog
{
Q_OBJECT

public:
explicit FirstTimeDialog(QWidget *parent = 0);
~FirstTimeDialog();
QString savePath;

private slots:
void on_pushButton_clicked();

void on_buttonBox_accepted();

void on_versionsCheckBox_toggled(bool checked);

private:
Ui::FirstTimeDialog *ui;
bool pathChanged;
};

#endif // FIRSTTIMEDIALOG_H
252 changes: 252 additions & 0 deletions firsttimedialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FirstTimeDialog</class>
<widget class="QDialog" name="FirstTimeDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>408</width>
<height>330</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;Welcome to savestate2snes first launch dialog&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Before using it be sure to validate these steps :</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="versionsCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;I have the USB2snes firmware version 5 or highter&lt;br/&gt;I have the USB2snes client version 5.1 or highter&lt;br/&gt; You can found it at &lt;a href=&quot;https://github.com/RedGuyyyy/sd2snes/releases&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;USB2snes last release&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Choose a Directory to store your savestates</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="directoryPathLabel">
<property name="text">
<string>Directory path</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>FirstTimeDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>FirstTimeDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
9 changes: 9 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "savestate2snesw.h"
#include <QApplication>
#include <QMessageBox>
#include "firsttimedialog.h"

static QTextStream logfile;
static QTextStream cout(stdout);
Expand Down Expand Up @@ -60,6 +61,14 @@ int main(int argc, char *argv[])
logfile.setDevice(&mlog);
if (mlog.open(QIODevice::WriteOnly | QIODevice::Text))
qInstallMessageHandler(myMessageOutput);
QSettings settings("skarsnik.nyo.fr", "SaveState2SNES");
if (!settings.contains("lastSaveStateDir"))
{
FirstTimeDialog diag;
if (diag.exec() == QDialog::Rejected)
return 1;
settings.setValue("lastSaveStateDir", diag.savePath);
}
Savestate2snesw w;
w.show();

Expand Down
1 change: 0 additions & 1 deletion savestate2snesw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <QFileDialog>
#include "savestate2snesw.h"
#include "ui_savestate2snesw.h"
#include <QtSerialPort/QSerialPortInfo>

Savestate2snesw::Savestate2snesw(QWidget *parent) :
QMainWindow(parent),
Expand Down
9 changes: 8 additions & 1 deletion savestate2snesw.ui
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="gameComboBox"/>
<widget class="QComboBox" name="gameComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newGamePushButton">
Expand Down

0 comments on commit a84703a

Please sign in to comment.