-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
#include <QCommandLineOption> | ||
#include <QCoreApplication> | ||
|
||
#ifdef Q_OS_WASM | ||
|
||
#include <QMap> | ||
|
||
class CommandLineParser { | ||
public: | ||
void setApplicationDescription(const QString &) {} | ||
void addHelpOption() {} | ||
void addVersionOption() {} | ||
bool addOption(const QCommandLineOption &) { return true; } | ||
void process(const QCoreApplication &); | ||
QString value(const QCommandLineOption &option) const; | ||
|
||
private: | ||
QMap<QString, QString> _values; | ||
}; | ||
|
||
|
||
#else | ||
|
||
#include <QCommandLineParser> | ||
|
||
class CommandLineParser : public QCommandLineParser { | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "commandlineparser.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "commandlineparser.h" | ||
#include <emscripten/val.h> | ||
#include <emscripten.h> | ||
|
||
|
||
void CommandLineParser::process(const QCoreApplication &) | ||
{ | ||
emscripten::val location = emscripten::val::global("location"); | ||
QString href = QString::fromStdString(location["href"].as<std::string>()); | ||
int idx = href.indexOf("?"); | ||
|
||
if (idx > 0) { | ||
QStringList params = href.mid(idx + 1).split("&"); | ||
for (auto ¶m : params) { | ||
idx = param.indexOf("="); | ||
if (idx >= 0) { | ||
_values.insert(param.mid(0, idx), param.mid(idx + 1)); | ||
qWarning() << param.mid(0, idx) << param.mid(idx + 1); | ||
} else { | ||
_values.insert(param, QString()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
QString CommandLineParser::value(const QCommandLineOption &option) const | ||
{ | ||
return _values.value(option.names().value(0)); | ||
} |