24 #include <QCoreApplication> 25 #include <QQmlApplicationEngine> 26 #include <QPluginLoader> 38 void addImportPath(
const QString& prefix,
const QString& path, QQmlEngine* engine);
39 void addPath(
const QString& prefix,
const QString& path, QStringList& pathList);
52 int main(
int argc,
char *argv[])
58 if(argc < 2 || !strcmp(argv[1],
"-h"))
63 else if(!strcmp(argv[1],
"-l"))
68 else if(!strcmp(argv[1],
"-p"))
74 QString scriptName(argv[1]);
78 QCoreApplication a(argc, argv);
80 QQmlApplicationEngine* engine =
new QQmlApplicationEngine(&a);
82 engine->installExtensions(QJSEngine::AllExtensions);
84 QString installPrefix;
86 installPrefix = QCoreApplication::applicationDirPath();
87 installPrefix +=
"/../";
88 installPrefix = QDir::cleanPath(installPrefix);
89 QString zAppDirPath = installPrefix +
"/apps";
91 qWarning(
"Install prefix: %s", installPrefix.toUtf8().constData());
92 qWarning(
"Zuble app directory: %s", zAppDirPath.toUtf8().constData());
99 addPath(installPrefix,
"/lib", libPaths);
102 QCoreApplication::setLibraryPaths(libPaths);
103 engine->setPluginPathList(libPaths);
105 engine->addImportPath(
"qrc:/");
109 qDebug(
"Dumping library paths...");
110 libPaths = QCoreApplication::libraryPaths();
113 qDebug(
"Dumping plugin paths...");
114 libPaths = engine->pluginPathList();
119 engine->load(filePath);
121 qDebug() <<
"Returned from engine->load()";
123 int status = a.exec();
125 qDebug(
"Returned from exec() with value: %d", status);
130 void addImportPath(
const QString& prefix,
const QString& path, QQmlEngine* engine)
132 QString tempPath(
"%1%2");
133 tempPath = tempPath.arg(prefix).arg(path);
135 qDebug(
"Adding import path: %s", tempPath.toUtf8().constData());
137 engine->addImportPath(tempPath);
140 void addPath(
const QString& prefix,
const QString& path, QStringList& pathList)
142 QString tempPath(
"%1%2");
143 tempPath = tempPath.arg(prefix).arg(path);
145 qDebug(
"Adding path: %s", tempPath.toUtf8().constData());
147 pathList.append(tempPath);
152 const int len = list.length();
154 for(
int i=0; i < len; i++)
156 qDebug(
"path: %s", list.at(i).toUtf8().constData() );
176 qDebug(
"Loading Zuble core plugin resources...");
180 static const QString corePluginName =
"libzblcore";
182 QPluginLoader loader;
184 loader.setFileName(corePluginName);
188 qWarning() <<
"zub failed to load core plugin: " << loader.errorString();
198 qWarning() <<
"Zuble core ERROR, core plugin doesn't implement ZResourceEdifyIF";
207 qWarning() <<
"Zuble FAILED to locate and register core binary " 221 QString path(getenv(
envPathName.toUtf8().constData()));
225 qWarning() <<
"ERROR: No ZUB_PATH environment variable specified. " 226 "This should contain a list of directories for " 227 <<
zubName <<
" to search for QML files.";
232 QString fullName(scriptName);
234 if(fullName.lastIndexOf(
extension) != fullName.size() - 4)
242 qDebug() <<
"resolveProgramName, name: " << fullName;
243 qDebug() <<
"resolveProgramName, path: " << path;
248 for(
int i=0; i<folders.size(); i++)
250 qDebug() <<
"folder: " << folders.at(i) << endl;
252 dir.setPath(folders.at(i));
257 if(dir.exists(fullName))
259 QFileInfo info = QFileInfo(dir, fullName);
260 fullPath = info.absoluteFilePath();
261 if(!info.isExecutable())
263 qWarning() <<
zubName <<
": ERROR - File is not executable: " 265 qWarning() <<
zubName <<
": You must set file permissions to \"executable\" for file: " 273 qWarning() <<
zubName <<
": ERROR - Script file not found: " 282 cout <<
zubName.toUtf8().constData()
283 <<
": Listing Zuble scripts..." << endl;
293 dir.setNameFilters(filters);
294 dir.setFilter(QDir::Executable | QDir::Files);
299 for(
int i=0; i<folders.size(); i++)
301 cout << folders.at(i).toUtf8().constData() <<
":" << endl;
303 dir.setPath(folders.at(i));
309 QStringList files = dir.entryList();
311 for(
int i=0; i<files.count(); i++)
313 QString name = files.at(i);
315 int extIndex = name.lastIndexOf(ext);
317 name = name.left(extIndex);
319 cout << name.toUtf8().constData() << endl;
328 if(folders.isEmpty())
330 qWarning() <<
zubName <<
"WARNING: ZUB_PATH environment variable contains no directories" 331 " to search for QML files";
341 QString path(getenv(
envPathName.toUtf8().constData()));
345 qWarning() <<
"ERROR: No ZUB_PATH environment variable specified. " 346 "This should contain a list of directories for " 347 <<
zubName <<
" to search for QML files.";
358 cout <<
zubName.toUtf8().constData() <<
" script path: " 365 cout <<
zubName.toUtf8().constData() <<
" usage: " << endl;
366 cout <<
" " <<
zubName.toUtf8().constData() <<
" <script-file>" << endl;
367 cout <<
" Loads and runs the non-gui QML script named <script-file>.qml" << endl;
368 cout <<
" on the path defined by environment variable ZUB_PATH." << endl;
369 cout <<
" " <<
zubName.toUtf8().constData() <<
" -l" << endl;
370 cout <<
" Lists QML scripts found on paths defined by ZUB_PATH environment variable." << endl;
371 cout <<
" Script files must have \".qml\" extension and executable permission." << endl;
372 cout <<
" " <<
zubName.toUtf8().constData() <<
" -h" << endl;
373 cout <<
" Prints this help message." << endl << endl;
static QString envPathName("ZUB_PATH")
QString findScriptPath(const QString &name)
void addImportPath(const QString &prefix, const QString &path, QQmlEngine *engine)
virtual bool mapPluginResources(const char *fileName, bool qmlRegister)=0
static QString extension("qml")
void addPath(const QString &prefix, const QString &path, QStringList &pathList)
QStringList getPathList()
void dumpPathList(const QStringList &list)
static QChar pathSeparator(':')
int main(int argc, char *argv[])
This interface allows Qt applications to access Zuble's platform-independent binary resource manageme...