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; }
const char* BepdfApplication::GetVersion(BString &version) { version = "?.?.?"; if (be_app == NULL) { return version.String(); } app_info info; if (be_app->GetAppInfo(&info) != B_OK) { return version.String(); } BFile file(&info.ref, B_READ_ONLY); if (file.InitCheck() != B_OK) { return version.String(); } BAppFileInfo appFileInfo(&file); version_info appVersion; if (appFileInfo.GetVersionInfo(&appVersion, B_APP_VERSION_KIND) != B_OK) { return version.String(); } BString variety = B_TRANSLATE("Unknown"); switch (appVersion.variety) { case 0: variety = B_TRANSLATE("Development"); break; case 1: variety = B_TRANSLATE("Alpha"); break; case 2: variety = B_TRANSLATE("Beta"); break; case 3: variety = B_TRANSLATE("Gamma"); break; case 4: variety = B_TRANSLATE("Golden Master"); break; case 5: if (appVersion.internal == 0) { // hide variety variety = ""; } else { variety = B_TRANSLATE("Final"); } break; }; version = ""; version << appVersion.major << "." << appVersion.middle << "." << appVersion.minor << " " << variety; if (appVersion.internal != 0) { version << " "<< appVersion.internal; } return version.String(); }
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; } } }
MNotificationManager::MNotificationManager() : proxy("com.meego.core.MNotificationManager", "/notificationmanager", QDBusConnection::sessionBus()), userId(0) { if (!QCoreApplication::instance()) { qWarning("QCoreApplication instance should be created before creating notifications"); return; } if (!QDir::root().exists(DATA_PATH) && !QDir::root().mkpath(DATA_PATH)) { return; } QFileInfo appFileInfo(QCoreApplication::applicationFilePath()); MFileDataStore userIdStore(DATA_PATH + appFileInfo.fileName() + ".data"); if (!userIdStore.isReadable()) { return; } QString appId = QString("id/") + appFileInfo.fileName(); // Check if a userId for an application with this name already exists if (userIdStore.contains(appId)) { userId = userIdStore.value(appId).toUInt(); } else { if (!userIdStore.isWritable()) { return; } // Fetch a new id from the notification manager over DBus userId = proxy.notificationUserId(); userIdStore.createValue(appId, userId); } qDBusRegisterMetaType<MNotification>(); qDBusRegisterMetaType<MNotificationGroup>(); qDBusRegisterMetaType<QList<MNotification> >(); qDBusRegisterMetaType<QList<MNotificationGroup> >(); }
int main(int argc, char *argv[]) { QByteArray key("k04LbM3wLGa97rVm30Kyhas"); QByteArray salt("013oPQLbplrz39g2oJElNyPQ20ms7H5v"); QApplication app(argc, argv); QApplication::setStyle("plastique"); Q_INIT_RESOURCE(marbles); _engine = new MaEngine(); _engine->setEncryptKey(key); _engine->setEncryptSalt(salt); QString applicationDirPath(QCoreApplication::applicationDirPath()); QFileInfo appFileInfo(QCoreApplication::applicationFilePath()); const QString appFileName(appFileInfo.fileName()); QString configPath; #if defined(Q_WS_MAC) int pos = applicationDirPath.indexOf(QObject::tr("/%1.app/Contents/MacOS").arg(appFileName)); if (pos > 0) { applicationDirPath.append("/../Resources"); } #endif // defined(Q_WS_MAC) configPath = QObject::tr("%1/%2.xml").arg(applicationDirPath).arg(appFileName); QFileInfo fi(configPath); if (fi.exists()) _engine->loadConfig(fi.absoluteFilePath()); _mainWindow = new MaMainWindow(); QObject::connect(_engine, SIGNAL(openedStore()), _mainWindow, SLOT(onOpenedStore())); _mainWindow->show(); if (!_engine->lastOpenedStoreLocation().isEmpty()) _engine->openStore(_engine->lastOpenedStoreLocation()); else _mainWindow->onOpenStore(); // _engine->store()->setPassword("skyout"); /* QString text("this is a test string."); QByteArray btext(text.toAscii()); QByteArray key("THIS IS THE KEY"); QByteArray salt; MaStore::encrypt(btext, key, salt); qDebug() << "text (encrypted)" << btext << ", salt=" << salt; MaStore::encrypt(btext, key, salt); qDebug() << "text (clear)" << btext << ", salt=" << salt; return 0; */ int res = app.exec(); _engine->onShuttingDown(); delete _engine; return res; }
bool SearchForSignatureEntryList::CanOpenWithFilter(const Model* appModel, const BMessage* entriesToOpen, const entry_ref* preferredApp) { ThrowOnAssert(appModel != NULL); if (!appModel->IsExecutable() || !appModel->Node()) { // weed out non-executable #if xDEBUG BPath path; BEntry entry(appModel->EntryRef()); entry.GetPath(&path); PRINT(("filtering out %s- not executable \n", path.Path())); #endif return false; } if (strcasecmp(appModel->MimeType(), B_APP_MIME_TYPE) != 0) { // filter out pe containers on PPC etc. return false; } BFile* file = dynamic_cast<BFile*>(appModel->Node()); ASSERT(file != NULL); char signature[B_MIME_TYPE_LENGTH]; if (GetAppSignatureFromAttr(file, signature) == B_OK && strcasecmp(signature, kTrackerSignature) == 0) { // special case the Tracker - make sure only the running copy is // in the list app_info trackerInfo; if (*appModel->EntryRef() != trackerInfo.ref) { // this is an inactive copy of the Tracker, remove it #if xDEBUG BPath path1; BPath path2; BEntry entry(appModel->EntryRef()); entry.GetPath(&path1); BEntry entry2(&trackerInfo.ref); entry2.GetPath(&path2); PRINT(("filtering out %s, sig %s, active Tracker at %s, " "result %s, refName %s\n", path1.Path(), signature, path2.Path(), strerror(be_roster->GetActiveAppInfo(&trackerInfo)), trackerInfo.ref.name)); #endif return false; } } if (FSInTrashDir(appModel->EntryRef())) return false; if (ShowAllApplications()) { // don't check for these if we didn't look for every single app // to not slow filtering down uint32 flags; BAppFileInfo appFileInfo(dynamic_cast<BFile*>(appModel->Node())); if (appFileInfo.GetAppFlags(&flags) != B_OK) return false; if ((flags & B_BACKGROUND_APP) || (flags & B_ARGV_ONLY)) return false; if (!signature[0]) // weed out apps with empty signatures return false; } int32 relation = Relation(entriesToOpen, appModel, preferredApp, 0); if (relation == kNoRelation && !ShowAllApplications()) { #if xDEBUG BPath path; BEntry entry(appModel->EntryRef()); entry.GetPath(&path); PRINT(("filtering out %s, does not handle any of opened files\n", path.Path())); #endif return false; } if (relation != kNoRelation && relation != kSuperhandler && !fGenericFilesOnly) { // we hit at least one app that is not a superhandler and // handles the document fFoundOneNonSuperHandler = true; } return true; }
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; }