LxBaseWin::LxBaseWin(QWidget *parent) :QWebView(parent) { _initWidget(); m_strApiName = LOMOX_API_DIALOG ; this->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing); QObject::connect(this, SIGNAL(linkClicked(const QUrl&)), this, SLOT(linkClickedAction(const QUrl&))); this->setAttribute(Qt::WA_DeleteOnClose); QNetworkAccessManager* pNetworkAccessManager = this->page()->networkAccessManager(); LxOption* pOption = lxCoreApp->getOption(); if (pOption && pNetworkAccessManager) { QString strCookies = pOption->getCookieFilePath(); LxNetWorkCookies* pCookies = new LxNetWorkCookies(strCookies, this); pNetworkAccessManager->setCookieJar(pCookies); QNetworkDiskCache *diskCache = new QNetworkDiskCache(this); QString location = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); //QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); diskCache->setCacheDirectory(location); diskCache->setMaximumCacheSize(1024);//byte pNetworkAccessManager->setCache(diskCache); pNetworkAccessManager->setNetworkAccessible(QNetworkAccessManager::Accessible); m_bLoadHrefInCurrent = pOption->getLoadHrefInCurrentChildDialog(); } QString iconName = pOption->getSystemTrayIconName(); QString iconPath = QCoreApplication::applicationDirPath() + "/" + iconName; qDebug("show path %s", iconPath.toStdString()); QIcon icon(iconPath); this->setWindowIcon(icon); }
void Agent::run() { ThreadedAssignment::commonInit(AGENT_LOGGING_NAME, NodeType::Agent); NodeList* nodeList = NodeList::getInstance(); nodeList->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer << NodeType::AvatarMixer << NodeType::VoxelServer << NodeType::ParticleServer << NodeType::ModelServer ); // figure out the URL for the script for this agent assignment QUrl scriptURL; if (_payload.isEmpty()) { scriptURL = QUrl(QString("http://%1:%2/assignment/%3") .arg(NodeList::getInstance()->getDomainHandler().getIP().toString()) .arg(DOMAIN_SERVER_HTTP_PORT) .arg(uuidStringWithoutCurlyBraces(_uuid))); } else { scriptURL = QUrl(_payload); } QNetworkAccessManager *networkManager = new QNetworkAccessManager(this); QNetworkReply *reply = networkManager->get(QNetworkRequest(scriptURL)); QNetworkDiskCache* cache = new QNetworkDiskCache(networkManager); QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation); cache->setCacheDirectory(!cachePath.isEmpty() ? cachePath : "agentCache"); networkManager->setCache(cache); qDebug() << "Downloading script at" << scriptURL.toString(); QEventLoop loop; QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); // let the AvatarData and ResourceCache classes use our QNetworkAccessManager AvatarData::setNetworkAccessManager(networkManager); ResourceCache::setNetworkAccessManager(networkManager); QString scriptContents(reply->readAll()); qDebug() << "Downloaded script:" << scriptContents; // setup an Avatar for the script to use AvatarData scriptedAvatar; // call model URL setters with empty URLs so our avatar, if user, will have the default models scriptedAvatar.setFaceModelURL(QUrl()); scriptedAvatar.setSkeletonModelURL(QUrl()); // give this AvatarData object to the script engine _scriptEngine.setAvatarData(&scriptedAvatar, "Avatar"); _scriptEngine.setAvatarHashMap(&_avatarHashMap, "AvatarList"); // register ourselves to the script engine _scriptEngine.registerGlobalObject("Agent", this); _scriptEngine.init(); // must be done before we set up the viewers _scriptEngine.registerGlobalObject("VoxelViewer", &_voxelViewer); // connect the VoxelViewer and the VoxelScriptingInterface to each other JurisdictionListener* voxelJL = _scriptEngine.getVoxelsScriptingInterface()->getJurisdictionListener(); _voxelViewer.setJurisdictionListener(voxelJL); _voxelViewer.init(); _scriptEngine.getVoxelsScriptingInterface()->setVoxelTree(_voxelViewer.getTree()); _scriptEngine.registerGlobalObject("ParticleViewer", &_particleViewer); JurisdictionListener* particleJL = _scriptEngine.getParticlesScriptingInterface()->getJurisdictionListener(); _particleViewer.setJurisdictionListener(particleJL); _particleViewer.init(); _scriptEngine.getParticlesScriptingInterface()->setParticleTree(_particleViewer.getTree()); _scriptEngine.setScriptContents(scriptContents); _scriptEngine.run(); setFinished(true); }
int main(int argc, char **argv) { qRegisterMetaType<Cache::Key>("Key"); qRegisterMetaType<Tile>("Tile"); qRegisterMetaType<qkey>("qkey"); QCoreApplication::setOrganizationName("ZTopo"); QCoreApplication::setApplicationName("ZTopo"); QApplication app(argc, argv); #if defined(Q_WS_MAC) QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus); // Mac OS specific code to find resources within a bundle CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); if (!pathPtr) { qFatal("Could not find Mac application bundle path!"); } QString rootPath = QString(pathPtr) % "/Contents/Resources/"; QByteArray rootPathArray = QString(rootPath % "proj4").toLatin1(); //qDebug("proj root '%s'\n", rootPathArray.data()); const char *path[] = { rootPathArray.data() }; pj_set_searchpath(1, (const char **)&path); CFRelease(appUrlRef); CFRelease(macPath); #elif defined(Q_WS_WIN) /* On Windows, use the proj4 subdirectory of the directory containing the application */ QString projPath = app.applicationDirPath() % "/proj4"; //qDebug() << "proj root" << projPath; const char *path[] = { QDir::toNativeSeparators(projPath).toLatin1().data() }; pj_set_searchpath(1, (const char **)&path); #endif // On other operating systems, we assume the proj4 library can find its own datum // shift grids. QSettings settings; QString cachePath = settings.value("cachePath", QDesktopServices::storageLocation(QDesktopServices::CacheLocation)).toString(); QDir::current().mkpath(cachePath); QNetworkAccessManager networkManager; QNetworkDiskCache diskCache; diskCache.setCacheDirectory(cachePath % "/meta"); diskCache.setMaximumCacheSize(maxDiskCacheSize); networkManager.setCache(&diskCache); RootData rootData(&networkManager); if (rootData.maps().size() == 0) { qFatal("No maps in root data file!"); } Map *map = rootData.maps().values()[0]; int maxMemCache = settings.value(settingMemCache, 64).toInt(); int maxDiskCache = settings.value(settingDiskCache, 200).toInt(); Cache::Cache tileCache(map, networkManager, maxMemCache, maxDiskCache, cachePath); MapRenderer renderer(map, tileCache); MainWindow *window = new MainWindow(rootData, map, &renderer, tileCache, networkManager); window->show(); if (rootData.majorVersion() > majorVersion || (rootData.majorVersion() == majorVersion && rootData.minorVersion() > minorVersion)) { QMessageBox mbox; mbox.setText("A new version of ZTopo is available."); mbox.setInformativeText(QString("A new version of ZTopo (%1.%2) is available for download. Would you like to open the ZTopo home page?").arg(rootData.majorVersion()).arg(rootData.minorVersion())); mbox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); mbox.setDefaultButton(QMessageBox::Yes); int ret = mbox.exec(); if (ret == QMessageBox::Yes) { QDesktopServices::openUrl(QUrl(rootData.homePageUrl())); } } return app.exec(); }