Skip to content

Commit 22d0e4c

Browse files
committed
Delambda-ify SettingsFragment + add AssetManager class
1 parent 866e16e commit 22d0e4c

File tree

9 files changed

+463
-383
lines changed

9 files changed

+463
-383
lines changed

src/MainWindow.cpp

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "config/ConfigContainer.h"
1414
#include "config/ConfigIO.h"
1515
#include "config/DspConfig.h"
16+
#include "data/AssetManager.h"
1617
#include "data/EelParser.h"
1718
#include "data/model/VdcDatabaseModel.h"
1819
#include "data/PresetManager.h"
@@ -233,7 +234,6 @@ MainWindow::MainWindow(bool statupInTray,
233234
DspConfig::instance().load();
234235

235236
connect(_settingsFragment->fragment(), &SettingsFragment::launchSetupWizard, this, &MainWindow::launchFirstRunSetup);
236-
connect(_settingsFragment->fragment(), &SettingsFragment::requestEelScriptExtract, this, &MainWindow::extractDefaultEelScripts);
237237
connect(_settingsFragment->fragment(), &SettingsFragment::reopenSettings, _settingsFragment, &FragmentHost<SettingsFragment*>::slideOutIn);
238238
connect(_styleHelper, &StyleHelper::iconColorChanged, _settingsFragment->fragment(), &SettingsFragment::updateButtonStyle);
239239
}
@@ -298,7 +298,7 @@ MainWindow::MainWindow(bool statupInTray,
298298
{
299299
if (AppConfig::instance().get<bool>(AppConfig::LiveprogAutoExtract))
300300
{
301-
extractDefaultEelScripts(false, false);
301+
AssetManager::instance().extractAll();
302302
}
303303
}
304304

@@ -1093,63 +1093,6 @@ void MainWindow::onConvolverWaveformEdit()
10931093
}
10941094
}
10951095

1096-
// Liveprog
1097-
int MainWindow::extractDefaultEelScripts(bool allowOverride,
1098-
bool user)
1099-
{
1100-
QDirIterator it(":/assets/liveprog", QDirIterator::NoIteratorFlags);
1101-
int i = 0;
1102-
1103-
while (it.hasNext())
1104-
{
1105-
QFile eel(it.next());
1106-
QString name = QFileInfo(eel).fileName();
1107-
QString newpath = AppConfig::instance().getLiveprogPath() + "/" + name;
1108-
1109-
if (QFile(newpath).exists() && !allowOverride)
1110-
{
1111-
continue;
1112-
}
1113-
1114-
if(!QDir(AppConfig::instance().getLiveprogPath()).exists())
1115-
{
1116-
QDir().mkpath(AppConfig::instance().getLiveprogPath());
1117-
}
1118-
1119-
QFile file(newpath);
1120-
1121-
if (eel.open(QIODevice::ReadOnly | QIODevice::Text) &&
1122-
file.open(QIODevice::WriteOnly | QIODevice::Text))
1123-
{
1124-
QTextStream stream(&file);
1125-
stream << eel.readAll();
1126-
file.close();
1127-
eel.close();
1128-
}
1129-
1130-
i++;
1131-
}
1132-
1133-
if (i > 0)
1134-
{
1135-
Log::debug(QString("MainWindow::extractDefaultEelScripts: %1 default eel files extracted").arg(i));
1136-
}
1137-
1138-
if (user)
1139-
{
1140-
if (i > 0)
1141-
{
1142-
QMessageBox::information(this, "Extract scripts", QString("%1 script(s) have been restored").arg(i));
1143-
}
1144-
else
1145-
{
1146-
QMessageBox::information(this, "Extract scripts", QString("No scripts have been extracted"));
1147-
}
1148-
}
1149-
1150-
return i;
1151-
}
1152-
11531096
// EQ
11541097
void MainWindow::setEq(const QVector<double> &data)
11551098
{

src/MainWindow.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public slots:
7070
void onResetRequested();
7171
void onRelinkRequested();
7272
void raiseWindow();
73-
int extractDefaultEelScripts(bool allowOverride, bool user);
7473
void launchFirstRunSetup();
7574

7675
private slots:

src/config/AppConfig.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,17 @@ class AppConfig :
126126
bool isAppBlocked(const QString& name) const;
127127

128128
#define DEFINE_USER_PATH(name,key) \
129-
QString get##name##Path() const \
129+
QString get##name##Path(QString subdir = "") const \
130130
{ \
131131
QString current = chopFirstLastChar(get<QString>(key)); \
132132
if (!QDir(current).exists()) \
133133
{ \
134134
QDir().mkpath(current); \
135135
} \
136+
if(!subdir.isEmpty()) \
137+
{ \
138+
return QString("%1/%2").arg(current).arg(subdir); \
139+
} \
136140
return current; \
137141
} \
138142
void set##name##Path(const QString& newVal) \

src/data/AssetManager.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include "AssetManager.h"
2+
3+
#include "config/AppConfig.h"
4+
5+
#include <QDirIterator>
6+
#include <QTextStream>
7+
8+
AssetManager::AssetManager(QObject *parent)
9+
: QObject{parent}
10+
{
11+
12+
}
13+
14+
int AssetManager::extractGroup(AssetType type, bool allowOverride)
15+
{
16+
QString internalPath;
17+
QString externalPath;
18+
switch(type)
19+
{
20+
case AssetManager::AT_IR:
21+
internalPath = ":/assets/irs";
22+
externalPath = AppConfig::instance().getIrsPath();
23+
break;
24+
case AssetManager::AT_VDC:
25+
internalPath = ":/assets/vdc";
26+
externalPath = AppConfig::instance().getVdcPath();
27+
break;
28+
case AssetManager::AT_LIVEPROG:
29+
internalPath = ":/assets/liveprog";
30+
externalPath = AppConfig::instance().getLiveprogPath();
31+
break;
32+
}
33+
34+
if(!QDir(externalPath).exists())
35+
{
36+
QDir().mkpath(externalPath);
37+
}
38+
39+
QDirIterator it(internalPath, QDirIterator::NoIteratorFlags);
40+
int i = 0;
41+
while (it.hasNext())
42+
{
43+
QFile sourceFile(it.next());
44+
QFile targetFile(externalPath + QDir::separator() + QFileInfo(sourceFile).fileName());
45+
46+
if (targetFile.exists() && !allowOverride)
47+
{
48+
continue;
49+
}
50+
51+
if (sourceFile.open(QIODevice::ReadOnly | QIODevice::Text) &&
52+
targetFile.open(QIODevice::WriteOnly | QIODevice::Text))
53+
{
54+
QTextStream stream(&targetFile);
55+
stream << targetFile.readAll();
56+
targetFile.close();
57+
}
58+
59+
i++;
60+
}
61+
62+
if (i > 0)
63+
{
64+
Log::debug(QString("AssetManager::extractGroup: %1 assets extracted (type %2)").arg(i).arg(type));
65+
}
66+
67+
return i;
68+
}
69+
70+
int AssetManager::extractAll(bool force)
71+
{
72+
int i = 0;
73+
i += extractGroup(AT_IR, true);
74+
i += extractGroup(AT_VDC, true);
75+
i += extractGroup(AT_LIVEPROG, force ? true : false);
76+
return i;
77+
}
78+

src/data/AssetManager.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef ASSETMANAGER_H
2+
#define ASSETMANAGER_H
3+
4+
#include <QObject>
5+
6+
class AssetManager : public QObject
7+
{
8+
Q_OBJECT
9+
public:
10+
static AssetManager &instance()
11+
{
12+
static AssetManager _instance;
13+
return _instance;
14+
}
15+
16+
enum AssetType
17+
{
18+
AT_IR,
19+
AT_VDC,
20+
AT_LIVEPROG
21+
};
22+
23+
AssetManager(AssetManager const &) = delete;
24+
AssetManager(QObject* parent = nullptr);
25+
26+
int extractGroup(AssetType type, bool allowOverride);
27+
28+
public slots:
29+
int extractAll(bool force = false);
30+
31+
};
32+
33+
#endif // ASSETMANAGER_H

0 commit comments

Comments
 (0)