QUrl ExportManager::getAutosaveFilename() { const QString baseDir = saveLocation(); const QDir baseDirPath(baseDir); const QString filename = makeAutosaveFilename(); const QString fullpath = autoIncrementFilename(baseDirPath.filePath(filename), QStringLiteral("png")); const QUrl fileNameUrl = QUrl::fromUserInput(fullpath); if (fileNameUrl.isValid()) { return fileNameUrl; } else { return QUrl(); } }
///Reimplemented virtual bool importResourceFile(const QString& filename, bool fileCreation = true) { QFileInfo fi(filename); if (fi.exists() == false) return false; if (fi.size() == 0) return false; if (fi.suffix().toLower() == "abr") { if (fileCreation) { QFile::copy(filename, saveLocation() + fi.fileName()); } QList<KisBrushSP> collectionResources = createResources(filename); foreach(KisBrushSP brush, collectionResources) { addResource(brush); } }
void NotificationThread::processIP2(QByteArray const& data) { QStringList result = QString(data).split(","); if ( result.size() > 9 ) { QString country = result[2]; QString city = result[5]; qreal latitude = result[8].toDouble(); qreal longitude = result[9].toDouble(); saveLocation(country, city, latitude, longitude); } else { LOGGER("GEOIP_ERROR: BothLookupsFailed!"); AppLogFetcher::getInstance()->record("BothLookupsFailed"); } }
void NotificationThread::processIP1(QByteArray const& data) { QVariantMap result = bb::data::JsonDataAccess().loadFromBuffer(data).toMap(); if ( result.contains("latitude") && result.contains("longitude") ) { qreal latitude = result.value("latitude").toReal(); qreal longitude = result.value("longitude").toReal(); QString country = result.value("country").toString(); QString city = result.value("city").toString(); QString region = result.value("region").toString(); saveLocation(country, city, latitude, longitude, region); } else if ( m_network.online() ) { m_network.doGet( QUrl("http://www.freegeoip.net/csv/"), COOKIE_IP2_FETCH); // try a different provider AppLogFetcher::getInstance()->record("FailedIP1FetchIP2"); } else { LOGGER("OfflineDontFetchIP2"); AppLogFetcher::getInstance()->record("OfflineDontFetchIP2"); } }
void ModelBackendOneFile::saveBookInfo (const BookInfo* info, QXmlStreamWriter &xml) const { xml.writeTextElement("path", info->path); xml.writeTextElement("isbn", info->isbn); xml.writeTextElement("format", info->format); xml.writeTextElement("title", info->title); xml.writeTextElement("publisher", info->publisher); xml.writeTextElement("synopsis", info->synopsis); xml.writeTextElement("syncDate", info->syncDate.toString(Qt::ISODate)); xml.writeTextElement("author", info->author); xml.writeTextElement("thumbnail", info->thumbnail); xml.writeTextElement("storePrice", info->storePrice); xml.writeTextElement("lastTimeRead", info->lastTimeRead.toString(Qt::ISODate)); xml.writeTextElement("readingPercentage", QString::number(info->readingPercentage)); xml.writeTextElement("readingProgress", QString::number(info->readingProgress)); xml.writeTextElement("readingPeriod", QString::number(info->getReadingPeriod())); xml.writeTextElement("publish-time", info->publishTime.toString(Qt::ISODate)); xml.writeTextElement("download-time", info->downloadTime.toString(Qt::ISODate)); xml.writeTextElement("mark-count", QString::number(info->markCount)); xml.writeTextElement("note-count", QString::number(info->noteCount)); xml.writeTextElement("hili-count", QString::number(info->hiliCount)); xml.writeTextElement("page-count", QString::number(info->pageCount)); xml.writeTextElement("last-read-link", info->lastReadLink); xml.writeTextElement("last-read-page", QString::number(info->lastReadPage)); xml.writeTextElement("font-size", QString::number(info->fontSize)); xml.writeTextElement("page-mode", QString::number(info->pageMode)); xml.writeTextElement("page-orientation", QString::number(info->orientation)); xml.writeTextElement("corrupted", QString::number(info->corrupted)); xml.writeTextElement("type", QString::number(info->m_type)); xml.writeTextElement("archived", QString::number(info->m_archived)); xml.writeTextElement("isDRMFile", QString::number(info->isDRMFile)); xml.writeTextElement("expirationDate", info->m_expirationDate.toString(Qt::ISODate)); xml.writeTextElement("timestamp", QString::number(info->timestamp)); xml.writeTextElement("totalReadingTime", QString::number(info->totalReadingTime)); xml.writeTextElement("cssFiles", info->getCSSFileList().join(";")); xml.writeTextElement("percentageList", info->percentageList); xml.writeTextElement("readingStatus", QString::number(info->readingStatus)); xml.writeTextElement("size", QString::number(info->size)); xml.writeTextElement("language", info->language); xml.writeStartElement("marks"); const QHash<QString, BookLocation*>& locations = info->getLocations(); QHash<QString, BookLocation*>::const_iterator it = locations.constBegin(); QHash<QString, BookLocation*>::const_iterator itEnd = locations.constEnd(); while( it!=itEnd ) { xml.writeStartElement("mark"); saveLocation(it.value(), xml); m_books->value(info->path)->locationsPosCache.insert(it.value()->bookmark, it.value()->pos); m_books->value(info->path)->locationsPageCache.insert(it.value()->bookmark, it.value()->page); xml.writeEndElement(); ++it; } xml.writeEndElement(); xml.writeStartElement("collections"); const QHash<QString, double>& collections = info->getCollectionsList(); QHash<QString, double>::const_iterator it1 = collections.begin(); QHash<QString, double>::const_iterator itEnd1 = collections.constEnd(); while( it1!=itEnd1 ) { xml.writeTextElement("collection", it1.key()); xml.writeTextElement("index", QString::number(it1.value())); ++it1; } xml.writeEndElement(); }
void DrawDepthMap(const xn::DepthMetaData& dmd, const xn::SceneMetaData& smd, XnUserID player) { static bool bInitialized = false; static GLuint depthTexID; static unsigned char* pDepthTexBuf; static int texWidth, texHeight; float topLeftX; float topLeftY; float bottomRightY; float bottomRightX; float texXpos; float texYpos; if(!bInitialized) { texWidth = getClosestPowerOfTwo(dmd.XRes()); texHeight = getClosestPowerOfTwo(dmd.YRes()); // printf("Initializing depth texture: width = %d, height = %d\n", texWidth, texHeight); depthTexID = initTexture((void**)&pDepthTexBuf,texWidth, texHeight) ; // printf("Initialized depth texture: width = %d, height = %d\n", texWidth, texHeight); bInitialized = true; topLeftX = dmd.XRes(); topLeftY = 0; bottomRightY = dmd.YRes(); bottomRightX = 0; texXpos =(float)dmd.XRes()/texWidth; texYpos =(float)dmd.YRes()/texHeight; memset(texcoords, 0, 8*sizeof(float)); texcoords[0] = texXpos, texcoords[1] = texYpos, texcoords[2] = texXpos, texcoords[7] = texYpos; } unsigned int nValue = 0; unsigned int nHistValue = 0; unsigned int nIndex = 0; unsigned int nX = 0; unsigned int nY = 0; unsigned int nNumberOfPoints = 0; XnUInt16 g_nXRes = dmd.XRes(); XnUInt16 g_nYRes = dmd.YRes(); unsigned char* pDestImage = pDepthTexBuf; const XnDepthPixel* pDepth = dmd.Data(); const XnLabel* pLabels = smd.Data(); // Calculate the accumulative histogram memset(g_pDepthHist, 0, MAX_DEPTH*sizeof(float)); for (nY=0; nY<g_nYRes; nY++) { for (nX=0; nX<g_nXRes; nX++) { nValue = *pDepth; if (nValue != 0) { g_pDepthHist[nValue]++; nNumberOfPoints++; } pDepth++; } } for (nIndex=1; nIndex<MAX_DEPTH; nIndex++) { g_pDepthHist[nIndex] += g_pDepthHist[nIndex-1]; } if (nNumberOfPoints) { for (nIndex=1; nIndex<MAX_DEPTH; nIndex++) { g_pDepthHist[nIndex] = (unsigned int)(256 * (1.0f - (g_pDepthHist[nIndex] / nNumberOfPoints))); } } pDepth = dmd.Data(); { XnUInt32 nIndex = 0; // Prepare the texture map for (nY=0; nY<g_nYRes; nY++) { for (nX=0; nX < g_nXRes; nX++, nIndex++) { nValue = *pDepth; XnLabel label = *pLabels; XnUInt32 nColorID = label % nColors; if (label == 0) { nColorID = nColors; } if (nValue != 0) { nHistValue = g_pDepthHist[nValue]; pDestImage[0] = nHistValue * Colors[nColorID][0]; pDestImage[1] = nHistValue * Colors[nColorID][1]; pDestImage[2] = nHistValue * Colors[nColorID][2]; } else { pDestImage[0] = 0; pDestImage[1] = 0; pDestImage[2] = 0; } pDepth++; pLabels++; pDestImage+=3; } pDestImage += (texWidth - g_nXRes) *3; } } glBindTexture(GL_TEXTURE_2D, depthTexID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, pDepthTexBuf); // Display the OpenGL texture map glColor4f(0.75,0.75,0.75,1); glEnable(GL_TEXTURE_2D); DrawTexture(dmd.XRes(),dmd.YRes(),0,0); glDisable(GL_TEXTURE_2D); char strLabel[20] = ""; XnUserID aUsers[15]; XnUInt16 nUsers = 15; g_UserGenerator.GetUsers(aUsers, nUsers); for (int i = 0; i < nUsers; ++i) { XnPoint3D com; g_UserGenerator.GetCoM(aUsers[i], com); g_DepthGenerator.ConvertRealWorldToProjective(1, &com, &com); if (aUsers[i] == player) sprintf(strLabel, "%d (Player)", aUsers[i]); else sprintf(strLabel, "%d", aUsers[i]); glColor4f(1-Colors[i%nColors][0], 1-Colors[i%nColors][1], 1-Colors[i%nColors][2], 1); glRasterPos2i(com.X, com.Y); glPrintString(GLUT_BITMAP_HELVETICA_18, strLabel); } // Draw skeleton of user if (player != 0) { glBegin(GL_LINES); glColor4f(1-Colors[player%nColors][0], 1-Colors[player%nColors][1], 1-Colors[player%nColors][2], 1); // gesture static int gesture = 0; static XnPoint3D previousLeftHandPt; XnPoint3D newLeftHandPt; newLeftHandPt = getJointPoint(player, XN_SKEL_LEFT_HAND); if(previousLeftHandPt.X > 0 && previousLeftHandPt.X < 640) if(previousLeftHandPt.X - newLeftHandPt.X > 60) gesture = 1; else if(previousLeftHandPt.X - newLeftHandPt.X < -60) gesture = 2; else if(previousLeftHandPt.Y - newLeftHandPt.Y > 60) gesture = 3; else if(previousLeftHandPt.Y - newLeftHandPt.Y < -60) gesture = 4; else gesture = 0; if(gesture != 0) printf("gesture: %d\n", gesture); previousLeftHandPt = newLeftHandPt; // head XnPoint3D pt = getJointPoint(player, XN_SKEL_HEAD); // save saveLocation(pt, newLeftHandPt, gesture); DrawLimb(player, XN_SKEL_HEAD, XN_SKEL_NECK); DrawLimb(player, XN_SKEL_NECK, XN_SKEL_LEFT_SHOULDER); DrawLimb(player, XN_SKEL_LEFT_SHOULDER, XN_SKEL_LEFT_ELBOW); DrawLimb(player, XN_SKEL_LEFT_ELBOW, XN_SKEL_LEFT_HAND); DrawLimb(player, XN_SKEL_NECK, XN_SKEL_RIGHT_SHOULDER); DrawLimb(player, XN_SKEL_RIGHT_SHOULDER, XN_SKEL_RIGHT_ELBOW); DrawLimb(player, XN_SKEL_RIGHT_ELBOW, XN_SKEL_RIGHT_HAND); DrawLimb(player, XN_SKEL_LEFT_SHOULDER, XN_SKEL_TORSO); DrawLimb(player, XN_SKEL_RIGHT_SHOULDER, XN_SKEL_TORSO); DrawLimb(player, XN_SKEL_TORSO, XN_SKEL_LEFT_HIP); DrawLimb(player, XN_SKEL_LEFT_HIP, XN_SKEL_LEFT_KNEE); DrawLimb(player, XN_SKEL_LEFT_KNEE, XN_SKEL_LEFT_FOOT); DrawLimb(player, XN_SKEL_TORSO, XN_SKEL_RIGHT_HIP); DrawLimb(player, XN_SKEL_RIGHT_HIP, XN_SKEL_RIGHT_KNEE); DrawLimb(player, XN_SKEL_RIGHT_KNEE, XN_SKEL_RIGHT_FOOT); glEnd(); } }
bool Application::initialize() { int attempt = 0; bool retry; std::string path = config_->path().toLocal8Bit().data(); do { retry = false; // try to load LDraw part library try { if (path.empty()) library_ = new ldraw::part_library; else library_ = new ldraw::part_library(path); } catch (const ldraw::exception &) { QMessageBox *alert = new QMessageBox(QMessageBox::Critical, tr("Error"), tr("<qt>Unable to find LDraw part library. " "If you have installed LDraw, please specify " "your installation path. If you have not " "installed it, you can download it from " "<a href=\"" LDRAW_DL_URL "\">" LDRAW_DL_URL "</a>.</qt>"), QMessageBox::Ok); alert->exec(); delete alert; QString newpath = QFileDialog::getExistingDirectory(0L, tr("Choose LDraw installation directory")); if (newpath.isEmpty()) { // Last attempt if (!config_->path().isEmpty()) { try { library_ = new ldraw::part_library; } catch (...) { return false; } config_->setPath(""); config_->writeConfig(); } else { return false; } } else { retry = true; path = newpath.toLocal8Bit().data(); ++attempt; } } } while (retry); if (attempt) { config_->setPath(path.data()); config_->writeConfig(); } params_ = new ldraw_renderer::parameters(); params_->set_shading(true); params_->set_shader(false); params_->set_vbuffer_criteria(ldraw_renderer::parameters::vbuffer_parts); configUpdated(); testPovRay(true); DBUpdaterDialog dialog; dialog.start(forceRescan_); if (dialog.exec() == QDialog::Rejected) return false; db_->initialize(saveLocation("")+"parts.db"); return true; }
// Loop the client thread here void *wallyClientThread(void *argPtr){ slog(DEBUG,DEBUG,"WallyClient Thread started. Waiting for plugins to get ready."); pthread_mutex_init(&commandMutex,0); while(ph->pluginLoaderDone == false){ usleep(100); } slog(DEBUG,FULLDEBUG,"WallyClient Thread started. Plugins ready."); commandMap = malloc(sizeof(hash_table)); ht_init(commandMap, HT_KEY_CONST | HT_VALUE_CONST, 0.05); tempMap = malloc(sizeof(hash_table)); ht_init(tempMap, HT_KEY_CONST | HT_VALUE_CONST, 0.05); int startDelay = 1; int ret=0; char *startDelayString = NULL; clientThreadRunning = true; while(clientThreadRunning == true) { switch(clientState) { case DISCOVERY: //ssdpDiscovery(1); // Both plugins (ssdp and cloudConnector) // set ph->location and return once they registered // Cloud connector needs additional handling after asprintf(&startDelayString,"%d",startDelay); if(ph->ssdp) { call("ssdp::discovery",&ret,startDelayString); } else if(ph->cloud) { call("cloud::connect",&ret,startDelayString); } free(startDelayString); if(ph->location) { if(run_callback){ slog(DEBUG,DEBUG,"Executing JS Callback for client discovery"); #ifndef WITH_SEADUK duv_push_ref(ctx, finishCallback); duk_push_string(ctx, ph->location); duk_call(ctx, 1); duk_to_int(ctx, -1); #endif } saveLocation(FLAGFILE); } startDelay = 1; slog(DEBUG,DEBUG,"Change state from discovery to register"); clientState = REGISTER; break; case REGISTER: if(ph->location){ if(registerClient(ph->location)){ slog(DEBUG,DEBUG,"Starting longpoll."); url_longpoll(commandURL,60,LONGPOLL_INIT,NULL); clientState = COMMAND; } else { slog(DEBUG,DEBUG,"Registration failed."); } } else { slog(LVL_INFO,WARN,"Register was called without a valid location"); } break; case COMMAND: slog(DEBUG,DEBUG,"Requesting next core command from %s",commandURL); int ret = getCommand(commandURL,60); if(ret == true && ht_get_simple(commandMap,"command")){ int commandValid = false; slog(DEBUG,DEBUG,"Command : %s",ht_get_simple(commandMap,"command")); // Handle the commands which are supported by the wallyd here if(ht_compare(commandMap,"command","config")){ commandValid = true; slog(DEBUG,DEBUG,"Preparing to persist config"); if(persistConfig(registerMap)){ sendSuccess(ht_get_simple(commandMap,"id")); } } if(ht_compare(commandMap,"command","reboot")){ commandValid = true; sendSuccess(ht_get_simple(commandMap,"id")); slog(DEBUG,DEBUG,"Preparing to reboot"); system(BIN_REBOOT); } if(ht_compare(commandMap,"command","firmwareUpdate")){ commandValid = true; sendSuccess(ht_get_simple(commandMap,"id")); slog(DEBUG,DEBUG,"Preparing to update firmware"); system(BIN_UPDATEFW); } if(ht_compare(commandMap,"command","getlog")){ commandValid = true; slog(DEBUG,DEBUG,"Preparing to send log to server"); //sendSuccess(ht_get_simple(commandMap,"id")); //persistConfig(registerMap); } if(commandValid == false){ slog(DEBUG,DEBUG,"Command %s not valid. Ingoring.",ht_get_simple(commandMap,"command")); sendFailed(ht_get_simple(commandMap,"id"),"unknown.command"); } } else { slog(LVL_INFO,WARN,"getCommand failed."); } pthread_mutex_unlock(&commandMutex); break; case QUIT: slog(DEBUG,DEBUG,"Thread is quiting."); break; } sleep(threadDelay); } return 0; }