-
Notifications
You must be signed in to change notification settings - Fork 7
/
macroeditor.cpp
134 lines (95 loc) · 3.26 KB
/
macroeditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "macroeditor.h"
#include "ui_macroeditor.h"
#include "editmacro.h"
#include <QSettings>
#include <QDir>
#include <QTextStream>
#include <QDebug>
#include "gamemacro.h"
MacroEditor::MacroEditor(QWidget *parent) :
QDialog(parent),
ui(new Ui::MacroEditor) {
ui->setupUi(this);
connect(ui->pushButton_edit, SIGNAL(clicked()), this, SLOT(editCurrentSelectedMacro()));
connect(ui->comboBox_accounts, SIGNAL(currentTextChanged(QString)), this, SLOT(accountChanged(QString)));
connect(ui->listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(macroDoubleClicked(QListWidgetItem*)));
loadAccounts();
}
MacroEditor::~MacroEditor() {
delete ui;
}
void MacroEditor::accountChanged(QString account) {
ui->listWidget->clear();
loadMacros(account);
}
void MacroEditor::macroDoubleClicked(QListWidgetItem* item) {
GameMacro* macro = dynamic_cast<GameMacro*>(item);
if (macro == NULL)
return;
editCurrentSelectedMacro();
}
void MacroEditor::loadAccounts() {
QSettings settings;
QString folder = settings.value("swg_folder").toString();
QDir profilesFolder(folder + "/profiles");
if (!profilesFolder.exists())
return;
QStringList accounts = profilesFolder.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
if (accounts.size() <= 0)
return;
for (int i = 0; i < accounts.size(); ++i) {
ui->comboBox_accounts->addItem(accounts.at(i));
}
// loadMacros(accounts.at(0));
}
void MacroEditor::loadMacros(const QString& account) {
QSettings settings;
QString folder = settings.value("swg_folder").toString();
QFile file(folder + "/profiles/" + account + "/macros.txt");
if (!file.exists())
return;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "loadMacros(account) file.open failed";
return;
}
QStringList macros = loadMacroNames(file);
QMap<int, GameMacro*>::iterator i;
for (i = gameMacros.begin(); i != gameMacros.end(); ++i) {
//cout << i.key() << ": " << i.value() << endl;
GameMacro* macro = i.value();
ui->listWidget->addItem(macro);
}
}
QStringList MacroEditor::loadMacroNames(QFile& macrosFile) {
QStringList names;
QTextStream stream(¯osFile);
if (!stream.atEnd()) {
QString version = stream.readLine();
if (!version.contains("version: 0000")) {
qDebug() << "invalid macros.txt format";
return names;
}
}
while (!stream.atEnd()) {
QString line = stream.readLine();
GameMacro* macro = new GameMacro();
//connect(macro, SIGNAL())
if (!macro->parseMacro(line)) {
delete macro;
continue;
}
names.append(macro->getName());
gameMacros.insert(macro->getId(), macro);
}
return names;
}
void MacroEditor::editCurrentSelectedMacro() {
int idx = ui->listWidget->currentRow();
if (idx < 0)
return;
GameMacro* macro = dynamic_cast<GameMacro*>(ui->listWidget->currentItem());
if (macro != NULL) {
EditMacro dialog(macro, this);
dialog.exec();
}
}