Skip to content

Commit

Permalink
Better SNES Classic support, reloading last category not buggy anymor…
Browse files Browse the repository at this point in the history
…e and icons
  • Loading branch information
Skarsnik committed Feb 22, 2019
1 parent ebf2394 commit 0ae40b4
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 22 deletions.
5 changes: 3 additions & 2 deletions Savestate2snes.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ SOURCES = main.cpp\
shortcuteditdialog.cpp \
handlestuffusb2snes.cpp \
snesclassicstuff/desktopclient/inputdecoder.cpp \
snesclassicstuff/stuffclient/stuffclient.cpp \
snesclassicstatut.cpp \
handlestuffsnesclassic.cpp \
consoleswitcher.cpp \
savestatelistview.cpp \
stuffclient.cpp


HEADERS = savestate2snesw.h \
handlestuff.h \
Expand All @@ -35,11 +36,11 @@ HEADERS = savestate2snesw.h \
shortcuteditdialog.h \
handlestuffusb2snes.h \
snesclassicstuff/desktopclient/inputdecoder.h \
snesclassicstuff/stuffclient/stuffclient.h \
snesclassicstatut.h \
handlestuffsnesclassic.h \
consoleswitcher.h \
savestatelistview.h \
stuffclient.h

FORMS = savestate2snesw.ui \
usb2snesstatut.ui \
Expand Down
2 changes: 1 addition & 1 deletion consoleswitcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "handlestuff.h"
#include "handlestuffsnesclassic.h"
#include "handlestuffusb2snes.h"
#include "stuffclient.h"
#include "snesclassicstuff/stuffclient/stuffclient.h"


#include <QWidget>
Expand Down
21 changes: 14 additions & 7 deletions handlestuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,21 @@ bool HandleStuff::loadSaveState(QString name)

void HandleStuff::findCategory(Category* parent, QDir dir)
{
QFileInfoList listDir = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
QFileInfoList listDir = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach(QFileInfo fi, listDir)
{
if (fi.fileName() == "ScreenShots")
continue;
if (fi.baseName() == "icon")
Category* newCat = new Category();
QDir catDir(fi.absoluteFilePath());
foreach (QFileInfo catFi, catDir.entryInfoList(QDir::Files))
{
sDebug() << parent->path << "Has icon" << fi.absoluteFilePath();
parent->icon = QIcon(fi.absoluteFilePath());
if (catFi.baseName() == "icon")
{
sDebug() << "Category" << fi.baseName() << "Has icon";
newCat->icon = QIcon(catFi.absoluteFilePath());
}
}
if (!fi.isDir())
continue;
Category* newCat = new Category();
newCat->name = fi.baseName();
newCat->path = fi.absoluteFilePath();
newCat->parent = parent;
Expand Down Expand Up @@ -347,6 +349,11 @@ bool HandleStuff::deleteSaveState(int row)
return true;
}

void HandleStuff::setCategoryIcon(QString categoryPath, QString iconPath)
{
categoriesByPath[categoryPath]->icon = QIcon(iconPath);
}

QPixmap HandleStuff::getScreenshot(QString name)
{
QFile saveFile(catLoaded->path + "/" + name + ".svt");
Expand Down
1 change: 1 addition & 0 deletions handlestuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class HandleStuff
void changeStateOrder(int from, int to);
bool loadSaveState(QString name);
bool deleteSaveState(int row);
void setCategoryIcon(QString categoryPath, QString iconPath);

QPixmap getScreenshot(QString name);
QString getScreenshotPath(QString name);
Expand Down
2 changes: 1 addition & 1 deletion handlestuffsnesclassic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define HANDLESTUFFSNESCLASSIC_H

#include "handlestuff.h"
#include "stuffclient.h"
#include "snesclassicstuff/stuffclient/stuffclient.h"

class HandleStuffSnesClassic : public HandleStuff
{
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int main(int argc, char *argv[])
QTranslator translator;
QString locale = QLocale::system().name().split('_').first();
translator.load(a.applicationDirPath() + "/i18n/savestate2snes_" + locale + ".qm");
QApplication::setApplicationVersion("0.5.2");
QApplication::setApplicationVersion("0.5.3");
a.installTranslator(&translator);
if (!settings.contains("lastSaveStateDir"))
{
Expand Down
23 changes: 20 additions & 3 deletions savestate2snesw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ Savestate2snesw::Savestate2snesw(QWidget *parent) :
{
sDebug() << "Attempting to load the last categoryloaded" << m_settings->value("lastCategoryLoaded").toString();
QStandardItem* repRoot = repStateModel->invisibleRootItem();
QStandardItem* catFound = NULL;
QStandardItem* catFound = nullptr;

if (repRoot != NULL)
if (repRoot != nullptr)
{
if (repRoot->hasChildren())
{
Expand All @@ -129,9 +129,10 @@ Savestate2snesw::Savestate2snesw(QWidget *parent) :
}
}
}
if (catFound != NULL)
if (catFound != nullptr)
{
ui->categoryTreeView->expand(repStateModel->indexFromItem(catFound));
ui->categoryTreeView->setCurrentIndex(catFound->index());
loadCategory(catFound);
}

Expand Down Expand Up @@ -261,6 +262,7 @@ void Savestate2snesw::createMenus()
categoryMenu->addAction(ui->actionRemoveCategory);
categoryMenu->addAction(ui->actionAddSubCategory);
categoryMenu->addAction(ui->actionAddCategory);
categoryMenu->addAction(ui->actionCategorySetIcon);
}


Expand Down Expand Up @@ -686,3 +688,18 @@ void Savestate2snesw::on_actionSave_a_savestate_triggered()
if (ui->saveSaveStatePushButton->isEnabled())
on_saveSaveStatePushButton_clicked();
}

void Savestate2snesw::on_actionCategorySetIcon_triggered()
{
const QString& catName = repStateModel->itemFromIndex(ui->categoryTreeView->currentIndex())->text();
const QString& catPath = repStateModel->itemFromIndex(ui->categoryTreeView->currentIndex())->data(MyRolePath).toString();
QString fileName = QFileDialog::getOpenFileName(this, QString(tr("Select an icon for %1")).arg(catName), QString(), tr("Image Files (*.png *.jpg *.bmp)"));
if (fileName.isEmpty())
return;
QFileInfo fi(fileName);
QString newName = catPath + "/icon." + fi.suffix();
sDebug() << "Setting icon for cat : " << newName;
QFile::copy(fileName, newName);
handleStuff->setCategoryIcon(catPath, newName);
repStateModel->itemFromIndex(ui->categoryTreeView->currentIndex())->setIcon(QIcon(newName));
}
2 changes: 2 additions & 0 deletions savestate2snesw.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ private slots:

void on_actionSave_a_savestate_triggered();

void on_actionCategorySetIcon_triggered();

private:
Ui::Savestate2snesw *ui;
QStandardItemModel* saveStateModel;
Expand Down
5 changes: 5 additions & 0 deletions savestate2snesw.ui
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,11 @@
<string>F7</string>
</property>
</action>
<action name="actionCategorySetIcon">
<property name="text">
<string>Set Icon</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
11 changes: 5 additions & 6 deletions snesclassicstatut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QLoggingCategory>
#include <QThread>

#define CLOVERSAVESTATEPATH "/tmp/savestate2snes.svt"

Q_LOGGING_CATEGORY(log_SNESClassicstatut, "SNESClassicStatut")

Expand Down Expand Up @@ -99,6 +98,10 @@ void SNESClassicStatut::start()
timer.start(2000);
}

#define CLOVERSAVESTATEPATH "/tmp/savestate2snes.svt"
#define CLOVERROLLBACKPATH "/tmp/rollback/"
#define SCREENSHOTPATH "/tmp/savestate2snes.png"

void SNESClassicStatut::onCanoeStarted()
{
QByteArray ba = controlCo->waitForCommand("ps | grep canoe | grep -v grep");
Expand All @@ -113,7 +116,7 @@ void SNESClassicStatut::onCanoeStarted()
ui->romNameLabel->setText(canoeArgs.at(canoeArgs.indexOf("-rom") + 1));
timer.stop();
ui->iniButton->setEnabled(true);
if (canoeArgs.indexOf(CLOVERSAVESTATEPATH))
if (canoeArgs.indexOf(CLOVERSAVESTATEPATH) != -1)
{
emit readyForSaveState();
ui->coStatusLabel->setPixmap(QPixmap(":/snesclassic status button green.png"));
Expand All @@ -139,10 +142,6 @@ void SNESClassicStatut::onClientDisconnected()
}


#define CLOVERSAVESTATEPATH "/tmp/savestate2snes.svt"
#define CLOVERROLLBACKPATH "/tmp/rollback/"
#define SCREENSHOTPATH "/tmp/savestate2snes.png"

void SNESClassicStatut::on_iniButton_clicked()
{
if (!firstCanoeRun.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion snesclassicstatut.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <QTimer>
#include <QWidget>

#include "stuffclient.h"
#include "snesclassicstuff/stuffclient/stuffclient.h"

namespace Ui {
class SNESClassicStatut;
Expand Down

0 comments on commit 0ae40b4

Please sign in to comment.