28 #include <QMetaProperty> 29 #include <QApplication> 31 #include <QXmlResultItems> 76 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" 78 "xmlns=\"http://zuble.org/schema/zuble/settings\"\n" 79 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" 80 "xsi:schemaLocation=\"http://zuble.org/schema/zuble/settings zublesettings01.xsd\">\n" 81 "<organization>zuble.org</organization>\n" 82 "<name>Zuble</name>\n" 84 " <setgroup xml:id=\"zuble\">\n" 85 " <name>Zuble Settings</name>\n" 89 " <setting xml:id=\"enable-zuble-logging\" group=\"zuble\">\n" 90 " <name>Enable Zuble Logging</name> " 91 " <type>bool</type>\n" 92 " <default>true</default>\n" 94 " <state value=\"false\">Disabled</state>\n" 95 " <state value=\"true\">Enabled</state>\n" 97 " <desc>Redirects Qt log messages to Zuble's log manager.</desc>\n" 99 " <setting xml:id=\"log-profile-path\" group=\"zuble\">\n" 100 " <name>Log Profile</name>\n" 101 " <type>string</type>\n" 102 " <default>data://log-profiles/default-log-profile.json</default>\n" 103 " <desc>The log profile controls the Zuble application's current logging behavior.</desc>\n" 105 " <setting xml:id=\"sync-log-profile\" group=\"zuble\">\n" 106 " <name>Sync Log Profile To Settings</name> " 107 " <type>bool</type>\n" 108 " <default>true</default>\n" 110 " <state value=\"false\">Disabled</state>\n" 111 " <state value=\"true\">Enabled</state>\n" 113 " <desc>Current log settings will be synchronized with the log profile.</desc>\n" 115 " <setting xml:id=\"log-output-dir\" group=\"zuble\">\n" 116 " <name>Log Output Directory</name>\n" 117 " <type>string</type>\n" 118 " <default>data://log</default>\n" 119 " <desc>Directory where log files will be saved.</desc>\n" 130 zDebug() <<
"ZApplication::ZApplication";
137 zDebug() <<
"ZApplication::zInit";
159 bool usingDefault =
false;
161 if(!QFile::exists(settingSrcPath))
163 zDebug() <<
"Can't find app settings metadata file: " << settingSrcPath;
168 initSettingsMetaPath =
resolvePath(initSettingsMetaPath,
false);
170 QFile initMetafile(initSettingsMetaPath);
172 if(!initMetafile.exists())
174 zDebug() <<
"Creating default app settings metadata file...";
178 QDir dataDir(dataPath);
180 if(!dataDir.exists())
182 zDebug() <<
"Creating Zuble data directory: " << dataDir.path();
184 if(!dataDir.mkpath(dataPath))
186 zCritical() <<
"Can't create Zuble data directory";
188 zCritical() <<
"ABORTING settings initialization!";
194 bool fileOK = initMetafile.open(QIODevice::WriteOnly);
198 zDebug() <<
"Can't initialize settings metafile: " 199 << initSettingsMetaPath
200 <<
" error message = " 201 << initMetafile.errorString();
203 zCritical() <<
"ABORTING settings initialization!";
209 qint64 bytesWritten =
212 if(bytesWritten == -1)
214 zDebug() <<
"Can't initialize settings metafile: " 215 << initSettingsMetaPath
216 <<
" error message = " 217 << initMetafile.errorString();
219 zCritical() <<
"ABORTING settings initialization!";
225 initMetafile.close();
229 zDebug() <<
"Using default settings metafile: " 230 << initSettingsMetaPath;
232 settingSrcPath = initSettingsMetaPath;
236 zDebug() <<
"Using application settings metafile: " << settingSrcPath;
251 const QString& prefix,
254 bool includeUrlScheme)
256 if(path.length() < prefix.length())
260 else if(path.startsWith(prefix))
265 return root + path.mid(prefix.length());
271 return root + path.mid(prefix.length());
281 bool includeUrlScheme)
301 QString homePath(QDir::homePath() +
"/");
331 const int ixC = path.indexOf(
':');
336 const int ixS = path.indexOf(
'/');
341 ret = path.left(ixS+1);
350 const int ixC = path.indexOf(
':');
355 const int ixS = path.indexOf(
'/');
360 const int pathSize = path.length() - ixS - 1;
363 ret = path.right(pathSize);
370 const int ixC = path.indexOf(
':');
375 const int ixS = path.indexOf(
'/');
387 QString orgName = QCoreApplication::organizationName();
389 if(orgName.isEmpty())
391 return QDir::homePath() +
"/." 398 return QDir::homePath() +
"/." 403 return QDir::homePath() +
"/." 411 QVariant path(qApp->property(
"org_zuble_appRootPath"));
414 return path.toString();
416 return QString(
"%1/").arg(QCoreApplication::applicationDirPath());
421 QVariant path(qApp->property(
"org_zuble_appMainQmlPath"));
424 return path.toString();
426 return QString(
"%1/%2").arg(
getRootPath()).arg(
"main.qml");
432 QVariant name(qApp->property(
"org_zuble_appName"));
435 return name.toString();
437 return QString(qApp->applicationName());
442 QString orgName = QCoreApplication::organizationName();
444 if(!orgName.isEmpty())
457 retValue = QCoreApplication::applicationDirPath();
460 retValue = QCoreApplication::applicationFilePath();
463 retValue = QCoreApplication::applicationName();
466 retValue = QCoreApplication::applicationPid();
469 retValue = QCoreApplication::applicationVersion();
472 retValue = QCoreApplication::arguments();
475 retValue = QCoreApplication::libraryPaths();
480 zThreadErr.raiseError(
"ZApplication::getAppData - invalid data key: " + tag);
493 sprintf(threadID,
"<null object>");
497 QThread* pThread =
object->thread();
498 sprintf(threadID,
"%p", pThread);
508 QThread* pThread = QThread::currentThread();
509 sprintf(threadID,
"%p", pThread);
553 QMetaObject::invokeMethod(
this,
"addThreadApp",
554 Qt::QueuedConnection,
555 Q_ARG(
ZblApp*, appObject));
577 QMetaObject::invokeMethod(
this,
"removeThreadApp",
578 Qt::BlockingQueuedConnection,
579 Q_ARG(
ZblApp*, appObject));
static const QString m_settingMetadataInitName
Name of default settings metadata file in user's home directory, created if no metadata file found in...
static const QString m_defaultSettingsID
The Zuble application settings application name.
static ZTextFeed m_status
The main application status text feed.
static QString getAppName()
Obtains the name of the Zuble application.
static QString getPathScheme(const QString &path)
Obtains the scheme part of a URL path.
static void debugCompareThreadAddress(const char *label, QObject *obj)
Sends both current thread address and object's thread address to qDebug.
static const QString m_settingMetadataFileName
Name of default settings metadata file in Zuble application directory.
void removeThreadApp(ZblApp *appObject)
Removes the specified ZblApp object from the list of running thread applications. ...
This class provides a means of directing a text stream to listeners.
static const QString m_fileUrlPrefix
URL scheme used to specify local file location: "file://".
#define ZBL_REGISTER_LOGGED_OBJECT
static const QString m_dataPathPrefix
URL scheme used to specify user's Zuble data directory location: "data://".
static QString getDataPath()
Obtains the canonical path to the Zuble application's data directory.
static QString getOrganization()
Obtains the organization of the Zuble application.
static const QString m_defaultApplication
The Zuble application default application name.
static const QString m_appPathPrefix
URL scheme used to specify Zuble app directory location: "zbl://".
static const QString m_resourcePathPrefix
URL scheme used to specify Qt binary resource location: "qrc://".
static const QString m_defaultOrganization
The Zuble application default organization name, "zuble".
static QString getMainQmlPath()
Obtains the canonical path to the Zuble application's main QML file.
static const QString m_homePathPrefix
URL scheme used to specify user's home directory location: "home://".
static const QString m_defaultZubleAppSettings
Settings metadata to use when no other settings data can be found.
static void debugCurrentThreadAddress(const char *label)
Sends current thread address to qDebug.
Q_INVOKABLE QVariant getAppData(int tag)
Obtains application object data for background threads.
void addThreadApp(ZblApp *appObject)
Adds the specified ZblApp object to the list of running thread applications.
#define ZBL_SLOT_BEGIN_TRY
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
#define zThreadErr
where does this show up?
bool initDefaultApplicationSettings()
Checks the Zuble application directory for a settings metafile and uses it if found. Otherwise checks for a default settings metafile, creates a default metafile if that doesn't exist, and uses the default metafile instead.
ZTextFeed & zStatus()
Obtains Zuble's main status text feed. Output text sent to this feed is broadcast to all Zuble status...
The primary QML API to the Zuble plugin library. Zuble applications access this object through the ja...
static QString getObjectThreadAddress(QObject *object)
Returns the human-readable memory address of the specified object's thread.
static QString resolvePath(const QString &path, bool includeUrlScheme=true)
Converts relative file paths into canonical file paths. Paths prefixed with prefix are mapped relativ...
bool inObjectThread(const QObject &object)
Zuble's Singleton Application Object.
ZApplication(QObject *parent=nullptr)
Don't construct this. Use zInit and zInstance instead.
static QString getCurrentThreadAddress()
Returns the human-readable memory address of the current thread.
static void debugObjectThreadAddress(const char *label, QObject *obj)
Sends object's thread address to qDebug.
static QString getRootPath()
Obtains the canonical path to the Zuble application's root directory.
bool zInit()
Initializes the application settings from information in the Zuble application's settings metadata fi...
static QList< ZblApp * > m_zappObjects
static bool insertBundle(const QString &id, const QString &metaPath, QSettings::Scope scope=QSettings::UserScope, const QString organization=QString(), const QString application=QString())
Adds the specified settings bundle to the settings repository.
static void debugGuiThreadAddress(const char *label)
Sends QApplication's thread address to qDebug.
#define ZBL_SLOT_END_RETURN(return_success, return_failed, facility, code, error_message)
static bool hasPathScheme(const QString &path)
Determines if a URL contains a scheme.
static QString removePathScheme(const QString &path)
Removes the scheme part from a URL path.