Skip to content

Commit 209d333

Browse files
committed
alpha 0.99 - alpha 0.XX stable release
1 parent 6567812 commit 209d333

9 files changed

+162
-99
lines changed

res_scripts/commands.txt

+1-1
Large diffs are not rendered by default.

src_base/commandparameter.cpp

+129-85
Original file line numberDiff line numberDiff line change
@@ -4,136 +4,180 @@
44

55
CommandParameter::CommandParameter(QObject *parent, QString i_argString) : QObject(parent), m_string(i_argString)
66
{
7-
isRequired = false;
8-
isOptional = false;
9-
isLong = false;
10-
isVarArg = false;
11-
isSwitch = false;
12-
parse();
7+
isRequired = false;
8+
isOptional = false;
9+
isLong = false;
10+
isVarArg = false;
11+
isSwitch = false;
12+
isRequiredLong = false;
13+
parse();
1314
}
1415

1516
QStringList CommandParameter::find_captures(QString regexString)
1617
{
17-
QRegExp rx(regexString);
18+
QRegExp rx(regexString);
1819

19-
QStringList list;
20-
int pos = 0;
20+
QStringList list;
21+
int pos = 0;
2122

22-
while ((pos = rx.indexIn(m_string, pos)) != -1) {
23-
list << rx.cap(1);
24-
pos += rx.matchedLength();
23+
while ((pos = rx.indexIn(m_string, pos)) != -1) {
24+
list << rx.cap(1);
25+
pos += rx.matchedLength();
2526
}
26-
return list;
27+
return list;
2728
}
2829

2930
QString CommandParameter::html()
3031
{
31-
QString rv;
32-
if (isRequired) {
33-
rv = QString("<input type='text' name='%1' class='w3-input w3-rest w3-border-red wp-parameter' required>").arg(parameterIndex);
32+
QString rv;
33+
34+
if (isRequired) {
35+
rv = QString("<input type='text' name='%1' class='w3-input w3-rest w3-border-red wp-parameter' required>").arg(parameterIndex);
36+
}
37+
if (isOptional) {
38+
rv = QString("<input type='text' name='%1' class='w3-input w3-rest w3-border-blue wp-parameter'>").arg(parameterIndex);
3439
}
35-
if (isOptional) {
36-
rv = QString("<input type='text' name='%1' class='w3-input w3-rest w3-border-blue wp-parameter'>").arg(parameterIndex);
40+
41+
if (isSwitch) {
42+
rv = QString("<input type='checkbox' name='%1' class='w3-checkbox w3-rest w3-large wp-parameter'>").arg(parameterIndex);
3743
}
38-
if (isSwitch) {
39-
rv = QString("<input type='checkbox' name='%1' class='w3-checkbox w3-rest w3-large wp-parameter'>").arg(parameterIndex);
44+
if (isLong) {
45+
flagValue.remove("&");
46+
flagValue.remove(">");
47+
flagValue.remove("<");
48+
flagValue.remove("--");
49+
flagValue.remove("\"");
50+
flagValue.remove("[");
51+
flagValue.remove("]");
52+
flagValue.remove("}");
53+
flagValue.remove("{");
54+
flagValue.remove("\\n");
55+
flagValue.remove(" ");
56+
flagValue.remove(QChar(QChar::LineFeed));
57+
flagValue.remove(QChar(QChar::CarriageReturn));
58+
flagValue.remove(QChar(QChar::LineSeparator));
59+
60+
rv = QString("<input type='text' name='%1' class=' w3-input w3-rest w3-large wp-parameter' placeholder='%2'>").arg(parameterIndex).arg(flagValue);
4061
}
41-
if (isLong) {
42-
flagValue.remove("&");
43-
flagValue.remove(">");
44-
flagValue.remove("<");
45-
flagValue.remove("--");
46-
flagValue.remove("\"");
47-
flagValue.remove("[");
48-
flagValue.remove("]");
49-
flagValue.remove("}");
50-
flagValue.remove("{");
51-
flagValue.remove("\\n");
52-
flagValue.remove(" ");
53-
flagValue.remove(QChar(QChar::LineFeed));
54-
flagValue.remove(QChar(QChar::CarriageReturn));
55-
flagValue.remove(QChar(QChar::LineSeparator));
56-
57-
rv = QString("<input type='text' name='%1' class=' w3-input w3-rest w3-large wp-parameter' placeholder='%2'>").arg(parameterIndex).arg(flagValue);
62+
63+
if (isRequiredLong) {
64+
flagValue.remove("&");
65+
flagValue.remove(">");
66+
flagValue.remove("<");
67+
flagValue.remove("--");
68+
flagValue.remove("\"");
69+
flagValue.remove("[");
70+
flagValue.remove("]");
71+
flagValue.remove("}");
72+
flagValue.remove("{");
73+
flagValue.remove("\\n");
74+
flagValue.remove(" ");
75+
flagValue.remove(QChar(QChar::LineFeed));
76+
flagValue.remove(QChar(QChar::CarriageReturn));
77+
flagValue.remove(QChar(QChar::LineSeparator));
78+
79+
rv = QString("<input type='text' name='%1' class=' w3-input w3-rest w3-large wp-parameter' placeholder='%2' required>").arg(parameterIndex).arg(flagValue);
5880
}
5981

60-
return rv;
82+
return rv;
6183

6284
}
6385

6486
QString CommandParameter::toString()
6587
{
66-
QString rv;
67-
if ((isOptional == true) || (isRequired == true)) {
88+
QString rv;
89+
if (isRequiredLong == true) {
90+
if (parameterValue.toString().length() > 0) {
91+
return QString("--%1=%2").arg(flagProperty).arg(parameterValue.toString());
92+
} else {
93+
return "";
94+
}
95+
}
6896

69-
return this->parameterValue.toString();
97+
if ((isOptional == true) || (isRequired == true)) {
98+
99+
return this->parameterValue.toString();
70100

71101
}
72-
if (isSwitch == true) {
73-
if (this->parameterValue.toBool() == true) {
74-
return QString("--%1").arg(this->flagProperty);
102+
103+
if (isSwitch == true) {
104+
if (this->parameterValue.toBool() == true) {
105+
return QString("--%1").arg(this->flagProperty);
75106
} else {
76-
return " ";
107+
return " ";
77108
}
78109
}
79-
if (isLong == true) {
80-
if (parameterValue.toString().length() > 0) {
81-
return QString("--%1=%2").arg(flagProperty).arg(parameterValue.toString());
110+
if (isLong == true) {
111+
if (parameterValue.toString().length() > 0) {
112+
return QString("--%1=%2").arg(flagProperty).arg(parameterValue.toString());
82113
} else {
83-
return "";
114+
return "";
84115
}
85116
}
86117

87-
return " ";
118+
return " ";
88119
}
89120

90121
void CommandParameter::parse()
91122
{
92-
QStringList optionalFlags;
93-
optionalFlags << this->find_captures("(\\[\\-\\-\\S+\\=<\\S+\\>\\]\\B)");
94-
if (optionalFlags.count() == 0) {
95-
QStringList required;
96-
97-
required << this->find_captures("(\\<\\S+\\>\\B)");
98-
if (required.count() == 0) {
99-
QStringList optional;
100-
optional << this->find_captures("(\\[\\[^\\>\\<]+\\]\\B)");
101-
if (optional.count() == 0) {
102-
// qDebug() << "Switch" << m_string;
103-
104-
isSwitch = true;
105-
flagProperty = m_string;
106-
if (flagProperty.length() > 2) {
107-
flagProperty.remove(0, 3);
123+
QStringList requiredFlags;
124+
requiredFlags << this->find_captures("(\\-\\-\\S+\\=<\\S+\\>\\B)");
125+
if (requiredFlags.count() == 0) {
126+
QStringList optionalFlags;
127+
optionalFlags << this->find_captures("(\\[\\-\\-\\S+\\=<\\S+\\>\\]\\B)");
128+
if (optionalFlags.count() == 0) {
129+
QStringList required;
130+
131+
required << this->find_captures("(\\<\\S+\\>\\B)");
132+
if (required.count() == 0) {
133+
QStringList optional;
134+
optional << this->find_captures("(\\[\\[^\\>\\<]+\\]\\B)");
135+
if (optional.count() == 0) {
136+
qDebug() << "Switch" << m_string;
137+
138+
isSwitch = true;
139+
flagProperty = m_string;
140+
if (flagProperty.length() > 2) {
141+
flagProperty.remove(0, 3);
142+
}
143+
144+
145+
} else {
146+
qDebug() << "optional" << optional.first();
147+
isOptional = true;
148+
m_string = optional.first();
149+
flagProperty = "";
108150
}
109-
110-
111151
} else {
112-
// qDebug() << "optional" << optional.first();
113-
isOptional = true;
114-
m_string = optional.first();
115-
flagProperty = "";
152+
qDebug() << "requiured" << required.first();
153+
isRequired = true;
154+
m_string = required.first();
155+
flagProperty = "";
116156
}
117157
} else {
118-
// qDebug() << "requiured" << required.first();
119-
isRequired = true;
120-
m_string = required.first();
121-
flagProperty = "";
158+
qDebug() << "optional flag" << optionalFlags.first();
159+
m_string = optionalFlags.first();
160+
flagProperty = m_string.split("=").first();
161+
if (flagProperty.length() > 3) {
162+
flagProperty.remove(0, 3);
163+
}
164+
flagValue = m_string.split("=").last();
165+
isLong = true;
122166
}
123167
} else {
124-
// qDebug() << "optional flag" << optionalFlags.first();
125-
m_string = optionalFlags.first();
126-
flagProperty = m_string.split("=").first();
127-
if (flagProperty.length() > 3) {
128-
flagProperty.remove(0, 3);
168+
qDebug() << "required flag" << requiredFlags.first();
169+
m_string = requiredFlags.first();
170+
flagProperty = m_string.split("=").first();
171+
if (flagProperty.length() > 3) {
172+
flagProperty.remove(0, 2);
129173
}
130-
flagValue = m_string.split("=").last();
131-
isLong = true;
132-
}
174+
flagValue = m_string.split("=").last();
175+
isRequiredLong = true;
133176

177+
}
134178
}
135179

136180
void CommandParameter::set_value(QVariant val)
137181
{
138-
this->parameterValue = val;
182+
this->parameterValue = val;
139183
}

src_base/commandparameter.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class CommandParameter : public QObject
1515
bool isVarArg;
1616
bool isSwitch;
1717
int parameterIndex;
18+
bool isRequiredLong;
1819
QString m_string;
1920
QStringList find_captures(QString regexString);
2021

@@ -31,4 +32,4 @@ void set_value(QVariant val);
3132

3233
};
3334

34-
#endif // COMMANDPARAMETER_H
35+
#endif // COMMANDPARAMETER_H

src_base/submodule.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <QThread>
1111
Submodule::Submodule(QObject *parent) : QObject(parent)
1212
{
13-
13+
this->currentCommand = nullptr;
1414
}
1515
// Synopsis Parser
1616
// [value] (\[\S+\]\B)
@@ -83,4 +83,4 @@ void Submodule::add_command(QString i_name, QString i_desc, QString i_synopsis)
8383
commands[newIdx] = new_command;
8484

8585

86-
}
86+
}

src_interfaces/clientinteraction.cpp

+17-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ QVariant ClientInteraction::set_current_command(QString i_command)
171171
QString newStr = QString("{\"name\":\"%1\",\"type\":\"%2\",\"html\":\"%3\"}").arg(param->m_string).arg(paramType).arg(param->html());
172172
rv.append(newStr);
173173
}
174-
if ((param->isSwitch) || (param->isLong)) {
174+
if ((param->isSwitch) || (param->isLong) || (param->isRequiredLong)) {
175175

176176
param->flagProperty.remove("&");
177177
param->flagProperty.remove(">");
@@ -220,11 +220,12 @@ QVariant ClientInteraction::execute()
220220
if (this->currentSubmodule != nullptr) {
221221
rv.append(currentSubmodule->toString());
222222
}
223-
this->processLauncher = new ProcessLauncherThread("wp", (QStringList() << rv.split(" ")), "internal");
223+
if (websiteController->currentWebsite == "./tmp") { return QVariant::fromValue(QString("Error. please select a website to execute command for")); }
224+
this->processLauncher = new ProcessLauncherThread("wp", (QStringList() << rv.split(" ", QString::SkipEmptyParts)), "internal");
224225
QByteArray output;
225-
output.append(processLauncher->run_internal_script("wp", (QStringList() << rv.split(" "))));
226+
output.append(processLauncher->run_internal_script("wp", (QStringList() << QString("--path=%1").arg(websiteController->currentWebsite) << rv.split(" ", QString::SkipEmptyParts))));
226227

227-
// qDebug() << output;
228+
qDebug() << output;
228229
return QVariant::fromValue(output);
229230

230231
//return QVariant::fromValue(rv);
@@ -296,3 +297,15 @@ void ClientInteraction::set_parameter_value(int paramidx, QVariant val)
296297
}
297298
}
298299
}
300+
301+
bool ClientInteraction::set_current_site(QString sitename)
302+
{
303+
if( websiteController->websites.keys().contains(sitename)) {
304+
this->websiteController->currentWebsite = websiteController->websites.value(sitename);
305+
return true;
306+
} else {
307+
this->websiteController->currentWebsite = websiteController->websites.value("./tmp");
308+
return false;
309+
}
310+
return false;
311+
}

src_interfaces/clientinteraction.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ClientInteraction : public QObject
3232
Q_INVOKABLE QVariant add_site(QString i_name, QString i_path);
3333
WebsiteController* websiteController;
3434
Q_INVOKABLE QVariant websites();
35+
Q_INVOKABLE bool set_current_site(QString sitename);
3536
signals:
3637
void requireLogin();
3738
void LoginSuccessful();

src_interfaces/websitecontroller.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010

1111
WebsiteController::WebsiteController(QObject *parent, DatabaseController *i_db) : QObject(parent), db(i_db)
1212
{
13+
this->currentWebsite = "./tmp";
1314
QVector<QVector<QString> > rv(db->executeSelectQuery("WEBSITES", (QStringList() << "NAME" << "PATH"), QString("")));
1415
QVectorIterator<QVector<QString > > i(rv);
1516
while (i.hasNext()) {
1617
QVector<QString> rowData(i.next());
1718
qDebug() << rowData;
1819
this->websites[rowData.at(0)] = rowData.at(1);
20+
1921
}
2022

2123
}

src_interfaces/websitecontroller.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ class WebsiteController : public QObject
1212
explicit WebsiteController(QObject *parent = nullptr, DatabaseController* i_db = nullptr);
1313
// to be implemented if expanding later
1414
//QHash<int, Website*> websites;
15+
// Website* new_website;
16+
// Website* currentWebsite;
1517

18+
QString currentWebsite;
1619
QHash<QString, QString> websites;
1720

18-
Website* new_website;
19-
Website* currentWebsite;
21+
2022
DatabaseController* db;
2123
signals:
2224

0 commit comments

Comments
 (0)