Skip to content

Commit 0ae40b4

Browse files
committed
Better SNES Classic support, reloading last category not buggy anymore and icons
1 parent ebf2394 commit 0ae40b4

11 files changed

+54
-22
lines changed

Savestate2snes.pro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ SOURCES = main.cpp\
2121
shortcuteditdialog.cpp \
2222
handlestuffusb2snes.cpp \
2323
snesclassicstuff/desktopclient/inputdecoder.cpp \
24+
snesclassicstuff/stuffclient/stuffclient.cpp \
2425
snesclassicstatut.cpp \
2526
handlestuffsnesclassic.cpp \
2627
consoleswitcher.cpp \
2728
savestatelistview.cpp \
28-
stuffclient.cpp
29+
2930

3031
HEADERS = savestate2snesw.h \
3132
handlestuff.h \
@@ -35,11 +36,11 @@ HEADERS = savestate2snesw.h \
3536
shortcuteditdialog.h \
3637
handlestuffusb2snes.h \
3738
snesclassicstuff/desktopclient/inputdecoder.h \
39+
snesclassicstuff/stuffclient/stuffclient.h \
3840
snesclassicstatut.h \
3941
handlestuffsnesclassic.h \
4042
consoleswitcher.h \
4143
savestatelistview.h \
42-
stuffclient.h
4344

4445
FORMS = savestate2snesw.ui \
4546
usb2snesstatut.ui \

consoleswitcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "handlestuff.h"
66
#include "handlestuffsnesclassic.h"
77
#include "handlestuffusb2snes.h"
8-
#include "stuffclient.h"
8+
#include "snesclassicstuff/stuffclient/stuffclient.h"
99

1010

1111
#include <QWidget>

handlestuff.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,21 @@ bool HandleStuff::loadSaveState(QString name)
121121

122122
void HandleStuff::findCategory(Category* parent, QDir dir)
123123
{
124-
QFileInfoList listDir = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
124+
QFileInfoList listDir = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
125125
foreach(QFileInfo fi, listDir)
126126
{
127127
if (fi.fileName() == "ScreenShots")
128128
continue;
129-
if (fi.baseName() == "icon")
129+
Category* newCat = new Category();
130+
QDir catDir(fi.absoluteFilePath());
131+
foreach (QFileInfo catFi, catDir.entryInfoList(QDir::Files))
130132
{
131-
sDebug() << parent->path << "Has icon" << fi.absoluteFilePath();
132-
parent->icon = QIcon(fi.absoluteFilePath());
133+
if (catFi.baseName() == "icon")
134+
{
135+
sDebug() << "Category" << fi.baseName() << "Has icon";
136+
newCat->icon = QIcon(catFi.absoluteFilePath());
137+
}
133138
}
134-
if (!fi.isDir())
135-
continue;
136-
Category* newCat = new Category();
137139
newCat->name = fi.baseName();
138140
newCat->path = fi.absoluteFilePath();
139141
newCat->parent = parent;
@@ -347,6 +349,11 @@ bool HandleStuff::deleteSaveState(int row)
347349
return true;
348350
}
349351

352+
void HandleStuff::setCategoryIcon(QString categoryPath, QString iconPath)
353+
{
354+
categoriesByPath[categoryPath]->icon = QIcon(iconPath);
355+
}
356+
350357
QPixmap HandleStuff::getScreenshot(QString name)
351358
{
352359
QFile saveFile(catLoaded->path + "/" + name + ".svt");

handlestuff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class HandleStuff
5656
void changeStateOrder(int from, int to);
5757
bool loadSaveState(QString name);
5858
bool deleteSaveState(int row);
59+
void setCategoryIcon(QString categoryPath, QString iconPath);
5960

6061
QPixmap getScreenshot(QString name);
6162
QString getScreenshotPath(QString name);

handlestuffsnesclassic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define HANDLESTUFFSNESCLASSIC_H
33

44
#include "handlestuff.h"
5-
#include "stuffclient.h"
5+
#include "snesclassicstuff/stuffclient/stuffclient.h"
66

77
class HandleStuffSnesClassic : public HandleStuff
88
{

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
101101
QTranslator translator;
102102
QString locale = QLocale::system().name().split('_').first();
103103
translator.load(a.applicationDirPath() + "/i18n/savestate2snes_" + locale + ".qm");
104-
QApplication::setApplicationVersion("0.5.2");
104+
QApplication::setApplicationVersion("0.5.3");
105105
a.installTranslator(&translator);
106106
if (!settings.contains("lastSaveStateDir"))
107107
{

savestate2snesw.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ Savestate2snesw::Savestate2snesw(QWidget *parent) :
111111
{
112112
sDebug() << "Attempting to load the last categoryloaded" << m_settings->value("lastCategoryLoaded").toString();
113113
QStandardItem* repRoot = repStateModel->invisibleRootItem();
114-
QStandardItem* catFound = NULL;
114+
QStandardItem* catFound = nullptr;
115115

116-
if (repRoot != NULL)
116+
if (repRoot != nullptr)
117117
{
118118
if (repRoot->hasChildren())
119119
{
@@ -129,9 +129,10 @@ Savestate2snesw::Savestate2snesw(QWidget *parent) :
129129
}
130130
}
131131
}
132-
if (catFound != NULL)
132+
if (catFound != nullptr)
133133
{
134134
ui->categoryTreeView->expand(repStateModel->indexFromItem(catFound));
135+
ui->categoryTreeView->setCurrentIndex(catFound->index());
135136
loadCategory(catFound);
136137
}
137138

@@ -261,6 +262,7 @@ void Savestate2snesw::createMenus()
261262
categoryMenu->addAction(ui->actionRemoveCategory);
262263
categoryMenu->addAction(ui->actionAddSubCategory);
263264
categoryMenu->addAction(ui->actionAddCategory);
265+
categoryMenu->addAction(ui->actionCategorySetIcon);
264266
}
265267

266268

@@ -686,3 +688,18 @@ void Savestate2snesw::on_actionSave_a_savestate_triggered()
686688
if (ui->saveSaveStatePushButton->isEnabled())
687689
on_saveSaveStatePushButton_clicked();
688690
}
691+
692+
void Savestate2snesw::on_actionCategorySetIcon_triggered()
693+
{
694+
const QString& catName = repStateModel->itemFromIndex(ui->categoryTreeView->currentIndex())->text();
695+
const QString& catPath = repStateModel->itemFromIndex(ui->categoryTreeView->currentIndex())->data(MyRolePath).toString();
696+
QString fileName = QFileDialog::getOpenFileName(this, QString(tr("Select an icon for %1")).arg(catName), QString(), tr("Image Files (*.png *.jpg *.bmp)"));
697+
if (fileName.isEmpty())
698+
return;
699+
QFileInfo fi(fileName);
700+
QString newName = catPath + "/icon." + fi.suffix();
701+
sDebug() << "Setting icon for cat : " << newName;
702+
QFile::copy(fileName, newName);
703+
handleStuff->setCategoryIcon(catPath, newName);
704+
repStateModel->itemFromIndex(ui->categoryTreeView->currentIndex())->setIcon(QIcon(newName));
705+
}

savestate2snesw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ private slots:
9090

9191
void on_actionSave_a_savestate_triggered();
9292

93+
void on_actionCategorySetIcon_triggered();
94+
9395
private:
9496
Ui::Savestate2snesw *ui;
9597
QStandardItemModel* saveStateModel;

savestate2snesw.ui

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,11 @@
603603
<string>F7</string>
604604
</property>
605605
</action>
606+
<action name="actionCategorySetIcon">
607+
<property name="text">
608+
<string>Set Icon</string>
609+
</property>
610+
</action>
606611
</widget>
607612
<layoutdefault spacing="6" margin="11"/>
608613
<customwidgets>

snesclassicstatut.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <QLoggingCategory>
55
#include <QThread>
66

7-
#define CLOVERSAVESTATEPATH "/tmp/savestate2snes.svt"
87

98
Q_LOGGING_CATEGORY(log_SNESClassicstatut, "SNESClassicStatut")
109

@@ -99,6 +98,10 @@ void SNESClassicStatut::start()
9998
timer.start(2000);
10099
}
101100

101+
#define CLOVERSAVESTATEPATH "/tmp/savestate2snes.svt"
102+
#define CLOVERROLLBACKPATH "/tmp/rollback/"
103+
#define SCREENSHOTPATH "/tmp/savestate2snes.png"
104+
102105
void SNESClassicStatut::onCanoeStarted()
103106
{
104107
QByteArray ba = controlCo->waitForCommand("ps | grep canoe | grep -v grep");
@@ -113,7 +116,7 @@ void SNESClassicStatut::onCanoeStarted()
113116
ui->romNameLabel->setText(canoeArgs.at(canoeArgs.indexOf("-rom") + 1));
114117
timer.stop();
115118
ui->iniButton->setEnabled(true);
116-
if (canoeArgs.indexOf(CLOVERSAVESTATEPATH))
119+
if (canoeArgs.indexOf(CLOVERSAVESTATEPATH) != -1)
117120
{
118121
emit readyForSaveState();
119122
ui->coStatusLabel->setPixmap(QPixmap(":/snesclassic status button green.png"));
@@ -139,10 +142,6 @@ void SNESClassicStatut::onClientDisconnected()
139142
}
140143

141144

142-
#define CLOVERSAVESTATEPATH "/tmp/savestate2snes.svt"
143-
#define CLOVERROLLBACKPATH "/tmp/rollback/"
144-
#define SCREENSHOTPATH "/tmp/savestate2snes.png"
145-
146145
void SNESClassicStatut::on_iniButton_clicked()
147146
{
148147
if (!firstCanoeRun.isEmpty())

0 commit comments

Comments
 (0)