MCPcopy Create free account
hub / github.com/TeXworks/texworks / launchFile

Method launchFile

src/scripting/ScriptAPI.cpp:278–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276}
277
278QMap<QString, QVariant> ScriptAPI::launchFile(const QString& fileName) const
279{
280 QFileInfo finfo(fileName);
281 QMap<QString, QVariant> retVal;
282
283 retVal[QString::fromLatin1("status")] = SystemAccess_PermissionDenied;
284 retVal[QString::fromLatin1("message")] = QVariant();
285
286 // it's OK to "launch" a directory, as that doesn't normally execute anything
287 if (finfo.isDir() || mayExecuteSystemCommand(fileName, m_target)) {
288 if (QDesktopServices::openUrl(QUrl::fromLocalFile(fileName)))
289 retVal[QString::fromLatin1("status")] = SystemAccess_OK;
290 else {
291 retVal[QString::fromLatin1("status")] = SystemAccess_Failed;
292 retVal[QString::fromLatin1("message")] = tr("\"%1\" could not be opened.").arg(fileName);
293 }
294 }
295 else
296 retVal[QString::fromLatin1("message")] = tr("System command execution is disabled (see Preferences)");
297 return retVal;
298}
299
300//Q_INVOKABLE
301int ScriptAPI::writeFile(const QString& filename, const QString& content) const

Callers 1

launchPdf.jsFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected