Пример #1
0
bool QmlCommerce::openApp(const QString& itemHref) {
    QUrl appHref(itemHref);

    // Read from the file to know what .html or .qml document to open
    QFile appFile(_appsPath + "/" + appHref.fileName());
    if (!appFile.open(QIODevice::ReadOnly)) {
        qCDebug(commerce) << "Couldn't open local .app.json file:" << appFile;
        return false;
    }
    QJsonDocument appFileJsonDocument = QJsonDocument::fromJson(appFile.readAll());
    QJsonObject appFileJsonObject = appFileJsonDocument.object();
    QString homeUrl = appFileJsonObject["homeURL"].toString();

    auto tablet = dynamic_cast<TabletProxy*>(
        DependencyManager::get<TabletScriptingInterface>()->getTablet("com.highfidelity.interface.tablet.system"));
    if (homeUrl.contains(".qml", Qt::CaseInsensitive)) {
        tablet->loadQMLSource(homeUrl);
    } else if (homeUrl.contains(".html", Qt::CaseInsensitive)) {
        tablet->gotoWebScreen(homeUrl);
    } else {
        qCDebug(commerce) << "Attempted to open unknown type of homeURL!";
        return false;
    }

    DependencyManager::get<HMDScriptingInterface>()->openTablet();

    return true;
}
Пример #2
0
QString QmlCommerce::getInstalledApps() {
    QString installedAppsFromMarketplace;
    QStringList runningScripts = DependencyManager::get<ScriptEngines>()->getRunningScripts();

    QDir directory(_appsPath);
    QStringList apps = directory.entryList(QStringList("*.app.json"));
    foreach(QString appFileName, apps) {
        installedAppsFromMarketplace += appFileName;
        installedAppsFromMarketplace += ",";
        QFile appFile(_appsPath + appFileName);
        if (appFile.open(QIODevice::ReadOnly)) {
            QJsonDocument appFileJsonDocument = QJsonDocument::fromJson(appFile.readAll());

            appFile.close();

            QJsonObject appFileJsonObject = appFileJsonDocument.object();
            QString scriptURL = appFileJsonObject["scriptURL"].toString();

            // If the script .app.json is on the user's local disk but the associated script isn't running
            // for some reason, start that script again.
            if (!runningScripts.contains(scriptURL)) {
                if ((DependencyManager::get<ScriptEngines>()->loadScript(scriptURL.trimmed())).isNull()) {
                    qCDebug(commerce) << "Couldn't start script while checking installed apps.";
                }
            }
        } else {
            qCDebug(commerce) << "Couldn't open local .app.json file for reading.";
        }
    }
Пример #3
0
bool QmlCommerce::uninstallApp(const QString& itemHref) {
    QUrl appHref(itemHref);

    // Read from the file to know what .js script to stop
    QFile appFile(_appsPath + "/" + appHref.fileName());
    if (!appFile.open(QIODevice::ReadOnly)) {
        qCDebug(commerce)
            << "Couldn't open local .app.json file for deletion. Cannot continue with app uninstallation. App filename is:"
            << appHref.fileName();
        return false;
    }
    QJsonDocument appFileJsonDocument = QJsonDocument::fromJson(appFile.readAll());
    QJsonObject appFileJsonObject = appFileJsonDocument.object();
    QString scriptUrl = appFileJsonObject["scriptURL"].toString();

    if (!DependencyManager::get<ScriptEngines>()->stopScript(scriptUrl.trimmed(), false)) {
        qCWarning(commerce) << "Couldn't stop script during app uninstall. Continuing anyway.";
    }

    // Delete the .app.json from the filesystem
    // remove() closes the file first.
    if (!appFile.remove()) {
        qCWarning(commerce) << "Couldn't delete local .app.json file during app uninstall. Continuing anyway. App filename is:"
                            << appHref.fileName();
    }

    QFileInfo appFileInfo(appFile);
    emit appUninstalled(appFileInfo.baseName());
    return true;
}
Пример #4
0
bool DrawElement::load(QString path)
{
    QFile appFile(path);
    if(!appFile.exists())
        return false;
    //lastPath = path; //@BUG@09/09/NicolasFix
    appFile.open(QFile::ReadOnly);
    this->load(&appFile, path, VERSION);
    appFile.close();

}
Пример #5
0
TIconMenu::TIconMenu(BMenu* menu) : BMenuItem(menu), bounds(0.0, 0.0, 15.0, 15.0), iconLabel(NULL)
{
	app_info info;
	if (be_app->GetAppInfo(&info) == B_NO_ERROR) {
		BFile appFile(&(info.ref), O_RDONLY);
		BAppFileInfo appFileInfo(&appFile);

		iconLabel = new BBitmap(bounds, kIconColorSpace);

		if (appFileInfo.GetIcon(iconLabel, B_MINI_ICON) != B_NO_ERROR) {
			delete iconLabel;
			iconLabel = NULL;
		}
	}
}
Пример #6
0
QString QmlCommerce::getInstalledApps(const QString& justInstalledAppID) {
    QString installedAppsFromMarketplace;
    QStringList runningScripts = DependencyManager::get<ScriptEngines>()->getRunningScripts();

    QDir directory(_appsPath);
    QStringList apps = directory.entryList(QStringList("*.app.json"));
    foreach (QString appFileName, apps) {
        // If we were supplied a "justInstalledAppID" argument, that means we're entering this function
        // to get the new list of installed apps immediately after installing an app.
        // In that case, the app we installed may not yet have its associated script running -
        // that task is asynchronous and takes a nonzero amount of time. This is especially true
        // for apps that are not in Interface's script cache.
        // Thus, we protect against deleting the .app.json from the user's disk (below)
        // by skipping that check for the app we just installed.
        if ((justInstalledAppID != "") && ((justInstalledAppID + ".app.json") == appFileName)) {
            installedAppsFromMarketplace += appFileName + ",";
            continue;
        }

        QFile appFile(_appsPath + appFileName);
        if (appFile.open(QIODevice::ReadOnly)) {
            QJsonDocument appFileJsonDocument = QJsonDocument::fromJson(appFile.readAll());

            appFile.close();

            QJsonObject appFileJsonObject = appFileJsonDocument.object();
            QString scriptURL = appFileJsonObject["scriptURL"].toString();

            // If the script .app.json is on the user's local disk but the associated script isn't running
            // for some reason (i.e. the user stopped it from Running Scripts),
            // delete the .app.json from the user's local disk.
            if (!runningScripts.contains(scriptURL)) {
                if (!appFile.remove()) {
                    qCWarning(commerce) << "Couldn't delete local .app.json file (app's script isn't running). App filename is:"
                                        << appFileName;
                }
            } else {
                installedAppsFromMarketplace += appFileName;
                installedAppsFromMarketplace += ",";
            }
        } else {
            qCDebug(commerce) << "Couldn't open local .app.json file for reading.";
        }
    }

    return installedAppsFromMarketplace;
}
Пример #7
0
static const BString*
SetDefaultAppForOneType(const BString* element, void* castToEntryRef)
{
	const entry_ref* appRef = (const entry_ref*)castToEntryRef;

	// set entry as default handler for one mime string
	BMimeType mime(element->String());
	if (!mime.IsInstalled())
		return 0;

	// first set it's app signature as the preferred type
	BFile appFile(appRef, O_RDONLY);
	if (appFile.InitCheck() != B_OK)
		return 0;

	char appSignature[B_MIME_TYPE_LENGTH];
	if (GetAppSignatureFromAttr(&appFile, appSignature) != B_OK)
		return 0;

	if (mime.SetPreferredApp(appSignature) != B_OK)
		return 0;

	// set the app hint on the metamime for this signature
	mime.SetTo(appSignature);
#if xDEBUG
	status_t result =
#endif
	mime.SetAppHint(appRef);

#if xDEBUG
	BEntry debugEntry(appRef);
	BPath debugPath;
	debugEntry.GetPath(&debugPath);

	PRINT(("setting %s, sig %s as default app for %s, result %s\n",
		debugPath.Path(), appSignature, element->String(), strerror(result)));
#endif

	return 0;
}
Пример #8
0
BBitmap* MainWindow::ResourceVectorToBitmap(const char *resName, float iconSize)
{
	BResources res;
	size_t size;
	app_info appInfo;

	be_app->GetAppInfo(&appInfo);
	BFile appFile(&appInfo.ref, B_READ_ONLY);
	res.SetTo(&appFile);
	BBitmap *aBmp = NULL;
	const uint8* iconData = (const uint8*) res.LoadResource('VICN', resName, &size);

	if (size > 0 ) {
		aBmp = new BBitmap (BRect(0,0, iconSize, iconSize), 0, B_RGBA32);
		status_t result = BIconUtils::GetVectorIcon(iconData, size, aBmp);
		if (result != B_OK) {
			delete aBmp;
			aBmp = NULL;
		}
	}
	return aBmp;
}
Пример #9
0
bool QmlCommerce::installApp(const QString& itemHref, const bool& alsoOpenImmediately) {
    if (!QDir(_appsPath).exists()) {
        if (!QDir().mkdir(_appsPath)) {
            qCDebug(commerce) << "Couldn't make _appsPath directory.";
            return false;
        }
    }

    QUrl appHref(itemHref);

    auto request =
        DependencyManager::get<ResourceManager>()->createResourceRequest(this, appHref, true, -1, "QmlCommerce::installApp");

    if (!request) {
        qCDebug(commerce) << "Couldn't create resource request for app.";
        return false;
    }

    connect(request, &ResourceRequest::finished, this, [=]() {
        if (request->getResult() != ResourceRequest::Success) {
            qCDebug(commerce) << "Failed to get .app.json file from remote.";
            return false;
        }

        // Copy the .app.json to the apps directory inside %AppData%/High Fidelity/Interface
        auto requestData = request->getData();
        QFile appFile(_appsPath + "/" + appHref.fileName());
        if (!appFile.open(QIODevice::WriteOnly)) {
            qCDebug(commerce) << "Couldn't open local .app.json file for creation.";
            return false;
        }
        if (appFile.write(requestData) == -1) {
            qCDebug(commerce) << "Couldn't write to local .app.json file.";
            return false;
        }
        // Close the file
        appFile.close();

        // Read from the returned datastream to know what .js to add to Running Scripts
        QJsonDocument appFileJsonDocument = QJsonDocument::fromJson(requestData);
        QJsonObject appFileJsonObject = appFileJsonDocument.object();
        QString scriptUrl = appFileJsonObject["scriptURL"].toString();

        // Don't try to re-load (install) a script if it's already running
        QStringList runningScripts = DependencyManager::get<ScriptEngines>()->getRunningScripts();
        if (!runningScripts.contains(scriptUrl)) {
            if ((DependencyManager::get<ScriptEngines>()->loadScript(scriptUrl.trimmed())).isNull()) {
                qCDebug(commerce) << "Couldn't load script.";
                return false;
            }

            QFileInfo appFileInfo(appFile);
            emit appInstalled(appFileInfo.baseName());
        }

        if (alsoOpenImmediately) {
            QmlCommerce::openApp(itemHref);
        }

        return true;
    });
    request->send();
    return true;
}