-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdialog.cpp
157 lines (136 loc) · 4.15 KB
/
dialog.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <QDir>
#include <QFile>
#include <QMessageBox>
#include "dialog.h"
#include "ui_dialog.h"
#include "wizard.h"
#include "configinifile.h"
#include "configxmlfile.h"
#include "confighelper.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
m_FoundTaigaDir = DecideStartPath();
m_Wizard.m_RegionWizard = new RegionWizard();
m_Wizard.m_RegionWizard->m_Wizard = &m_Wizard;
}
Dialog::~Dialog()
{
// del widgets here
delete ui;
}
void Dialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
bool Dialog::DecideStartPath()
{
QString sep = QDir::separator();
QString current = QDir::current().absolutePath();
QString qdirSep = "";
current.contains("/") ? qdirSep = "/" : qdirSep = "\"";
QString cur = QDir::current().absolutePath();
QStringList s = cur.split(qdirSep);
s.removeLast();
s.append("OpenSim");
s.append("OpenSim.exe");
QString releasePath = s.join(qdirSep);
QFile *r = new QFile(releasePath);
if(r->exists())
{
s.removeLast();
//ui->lineEditTaigaDir->setText(s.join(sep));
this->m_Wizard.SetTaigaPath(s.join(sep));
return true;
}
QString buildPath = ""; // figure out if we're running application from debug folder
// figure out buildPath abs path, (dont know any smarter way to do this)
QStringList split = current.split(qdirSep);
if(split.count()>2) {
split.removeLast(); // 2 folders up
split.removeLast();
buildPath = split.join(sep);
buildPath.append(sep + "bin" + sep + "OpenSim.exe");
}
//QDir buildDir(buildPath);
QString binPath = current + "/OpenSim.exe";
binPath = binPath.replace("/",sep);
QFile *file = new QFile(buildPath);
if(file->exists()){
QStringList split2 = buildPath.split(sep);
split2.removeLast();
buildPath = split2.join(sep);
this->m_Wizard.SetTaigaPath(buildPath);
return true;
}
file = new QFile(binPath);
if(file->exists()){
QStringList split2 = binPath.split(sep);
split2.removeLast();
binPath = split2.join(sep);
this->m_Wizard.SetTaigaPath(s.join(sep));
return true;
}
return false;
}
void Dialog::on_pushButton_clicked() //Region
{
m_Wizard.m_GridConfig = false;
m_Wizard.m_JoinGrid = false;
m_Wizard.m_Regions = true;
this->hide();
m_Wizard.Configure(m_FoundTaigaDir );
m_Wizard.show();
}
void Dialog::on_pushButton_2_clicked() //Grid
{
m_Wizard.m_GridConfig = true;
m_Wizard.m_JoinGrid = true;
m_Wizard.m_Regions = true;
this->hide();
m_Wizard.Configure(m_FoundTaigaDir );
m_Wizard.show();
}
void Dialog::on_pushButton_3_clicked() //Advanced
{
QDir cwd = QDir::current();
QString saveDir = ConfigHandler::SAVE_DIR.replace("/", QDir::separator());
QString location = ConfigHelper::SelectPathOrFolder(QString("Select config file"), this, cwd.absolutePath() + QDir::separator() + saveDir, openFile);
if(location!="")
{
// we need relative path
QString currentPath = cwd.absolutePath();
if(location.startsWith(currentPath))
{
location = location.mid(currentPath.length()+1);
}
else
{
location = cwd.relativeFilePath(location);
}
ConfigIniFile* loadedConf = new ConfigIniFile(location);
//ui->listWidgetRegions->clear();
m_Wizard.ClearRegions();
if(loadedConf->m_Sections.contains("ConfigData"))
{
QMap<QString,QString>* confData = loadedConf->m_Sections.value("ConfigData");
m_Wizard.m_GridConfig = confData->contains("grid");
m_Wizard.m_JoinGrid = confData->contains("sim"),
m_Wizard.m_Regions = confData->contains("regions");
}
ConfigHelper::SetConfigValuesToPage(loadedConf->m_Sections, &m_Wizard);
m_Wizard.SetDataBaseParams();
this->hide();
m_Wizard.Configure(m_FoundTaigaDir );
m_Wizard.show();
}
}