void InternetServerPlatform::readVariables( QDomNode node ) { Logging::logInfo( this, "readVariables()" ); if( node.isNull() ) return; QDomNode variable = node.firstChild(); while( false == variable.isNull() ) { if( QDomNode::CommentNode != variable.nodeType() ) { QString variableName = variable.nodeName(); if( _variableList.contains(variableName) ) continue; QString variableValue = variable.attributes().namedItem("value").nodeValue(); replaceVariables( variableValue ); _variableList.insert( variableName, variableValue ); Logging::logInfo( this, QString("%1 = %2").arg(variableName).arg(variableValue) ); variable = variable.nextSibling(); } } }
QVariant PackageManagerCoreData::value(const QString &key, const QVariant &_default) const { if (key == scTargetDir) { QString dir = m_variables.value(key); if (dir.isEmpty()) dir = replaceVariables(m_settings.value(key, _default).toString()); #ifdef Q_OS_WIN return QInstaller::normalizePathName(dir); #else if (dir.startsWith(QLatin1String("~/"))) return QDir::home().absoluteFilePath(dir.mid(2)); return dir; #endif } #ifdef Q_OS_WIN if (!m_variables.contains(key)) { static const QRegExp regex(QLatin1String("\\\\|/")); const QString filename = key.section(regex, 0, -2); const QString regKey = key.section(regex, -1); const QSettingsWrapper registry(filename, QSettingsWrapper::NativeFormat); if (!filename.isEmpty() && !regKey.isEmpty() && registry.contains(regKey)) return registry.value(regKey).toString(); } #endif if (m_variables.contains(key)) return m_variables.value(key); return m_settings.value(key, _default); }
bool awx_decision::isTrue() { awx_string temp = replaceVariables(bedingung , *variables); //cout << temp << endl; bool tempbool = ausdruck(temp); //cout <<"#" << temp << " == " << tempbool << "#" << endl; return tempbool; }
void InternetServerPlatform::readMood( QDomNode moodNode, Mood& mood ) { Logging::logInfo( this, "readMood()" ); if( moodNode.isNull() ) return; QString active = moodNode.attributes().namedItem("active").nodeValue(); QDomNode node = Dom::getChildNodeByName( moodNode, active ); if( false == node.isNull() ) { if( "business" == active ) { mood._active = Mood::Business; mood._business._explanatoryPage = node.attributes().namedItem("explanatoryPage").nodeValue(); replaceVariables( mood._business._explanatoryPage ); } else if( "hacker" == active ) { mood._active = Mood::Hacker; mood._hacker._folderToStoreInfoFiles = node.attributes().namedItem("folderToStoreInfoFiles").nodeValue(); mood._hacker._explanatoryPage = node.attributes().namedItem("explanatoryPage").nodeValue(); replaceVariables( mood._hacker._folderToStoreInfoFiles ); replaceVariables( mood._hacker._explanatoryPage ); } else if( "hole" == active ) { mood._active = Mood::Hole; Logging::logInfo( this, "active mood: Mood::Hole" ); } else if( "brutal" == active ) { mood._active = Mood::Brutal; mood._brutal._countPerSecond = node.attributes().namedItem("countPerSecond").nodeValue().toInt(); mood._brutal._countPerMinute = node.attributes().namedItem("countPerMinute").nodeValue().toInt(); mood._brutal._totalCount = node.attributes().namedItem("totalCount").nodeValue().toInt(); mood._brutal._scriptForFirewall = node.attributes().namedItem("scriptForFirewall").nodeValue(); mood._brutal._runWith = node.attributes().namedItem("runWith").nodeValue(); replaceVariables( mood._brutal._scriptForFirewall ); replaceVariables( mood._brutal._runWith ); } } }
qreal PdfElementImage::paint(QPainter *painter) { qreal x = toQReal(_attributes.value("x", "0")); qreal y = toQReal(_attributes.value("y", "0")) + _offsetY; qreal w = toQReal(_attributes.value("width", "0")); qreal h = toQReal(_attributes.value("height", "0")); if (w > 0 && h > 0) { painter->setPen(Qt::NoPen); painter->setBrush(Qt::NoBrush); QRectF box(QPointF(x, y), QSizeF(w, h)); QImage picture; // Get the variable defined in the attribute "file" QString var = _attributes.value("file", ""); bool drawn = FALSE; // No variable found, the attribute "file" might point to an imagefile if (_variables->value(var, "").isEmpty()) { // Load the image (or default image) and print it QList<QString> images = replaceVariables(var); QString img; for (int i = 0; i < images.size(); i++) { img = QString("/").prepend(_templatePath).append(images.at(i)); if (picture.load(img)) { painter->drawImage( box, picture, QRectF(picture.rect()) ); drawn = TRUE; break; } } } else { // if an attribute exists with the addition "_file" the string in the attribute should be iinterpreted as a file, otherwise as SVG-Content bool imageIsFile = _variables->contains(var) && !_variables->value(var.append("_file"), "").isEmpty(); // Try to render a normal pixel image or as an SVG Image / Content QSvgRenderer svg; if (imageIsFile && picture.load(_variables->value(var))) { painter->drawImage( box, picture, QRectF(picture.rect()) ); drawn = TRUE; } else if ( (imageIsFile && svg.load( _variables->value(var) )) || (!imageIsFile && svg.load( _variables->value(var).toUtf8() )) ) { svg.render(painter, box); drawn = TRUE; } } // If the Image isn't drawn, show the default one if (!drawn) { showDefaultImage(painter, box); } } return bottom(); }
PackageManagerCoreData::PackageManagerCoreData(const QHash<QString, QString> &variables) { m_variables = variables; setDynamicPredefinedVariables(); // Set some common variables that may used e.g. as placeholder in some of the settings variables or // in a script or... m_variables.insert(scTargetConfigurationFile, QLatin1String("components.xml")); m_variables.insert(QLatin1String("InstallerDirPath"), QCoreApplication::applicationDirPath()); m_variables.insert(QLatin1String("InstallerFilePath"), QCoreApplication::applicationFilePath()); #ifdef Q_OS_WIN m_variables.insert(QLatin1String("os"), QLatin1String("win")); #elif defined(Q_OS_OSX) m_variables.insert(QLatin1String("os"), QLatin1String("mac")); #elif defined(Q_OS_LINUX) m_variables.insert(QLatin1String("os"), QLatin1String("x11")); #else // TODO: add more platforms as needed... #endif m_settings = Settings::fromFileAndPrefix(QLatin1String(":/metadata/installer-config/config.xml"), QLatin1String(":/metadata/installer-config/"), Settings::RelaxedParseMode); // fill the variables defined in the settings m_variables.insert(QLatin1String("ProductName"), m_settings.applicationName()); m_variables.insert(QLatin1String("ProductVersion"), m_settings.version()); m_variables.insert(scTitle, m_settings.title()); m_variables.insert(scPublisher, m_settings.publisher()); m_variables.insert(QLatin1String("Url"), m_settings.url()); m_variables.insert(scStartMenuDir, m_settings.startMenuDir()); m_variables.insert(scTargetConfigurationFile, m_settings.configurationFileName()); m_variables.insert(QLatin1String("LogoPixmap"), m_settings.logo()); m_variables.insert(QLatin1String("WatermarkPixmap"), m_settings.watermark()); m_variables.insert(QLatin1String("BannerPixmap"), m_settings.banner()); const QString description = m_settings.runProgramDescription(); if (!description.isEmpty()) m_variables.insert(scRunProgramDescription, description); m_variables.insert(scTargetDir, replaceVariables(m_settings.targetDir())); m_variables.insert(scRemoveTargetDir, replaceVariables(m_settings.removeTargetDir())); }
void PdfElementImage::showDefaultImage(QPainter *painter, QRectF box) { QSvgRenderer svg; QImage picture; QString img; QList<QString> images = replaceVariables(_attributes.value("default", "")); // Try to load the image as SVG and after as a pixel graphic for (int i = 0; i < images.size(); i++) { img = QString("/").prepend(_templatePath).append( images.at(i) ); if (svg.load(img)) { painter->setPen(Qt::NoPen); svg.render(painter, box); break; } else if (picture.load( img )) { painter->drawImage( box, picture, QRectF(picture.rect()) ); break; } } }
PackageManagerCoreData::PackageManagerCoreData(const QHash<QString, QString> &variables) { m_variables = variables; // Set some common variables that may used e.g. as placeholder in some of the settings variables or // in a script or... m_variables.insert(QLatin1String("rootDir"), QDir::rootPath()); m_variables.insert(QLatin1String("homeDir"), QDir::homePath()); m_variables.insert(QLatin1String("RootDir"), QDir::rootPath()); m_variables.insert(QLatin1String("HomeDir"), QDir::homePath()); m_variables.insert(scTargetConfigurationFile, QLatin1String("components.xml")); m_variables.insert(QLatin1String("InstallerDirPath"), QCoreApplication::applicationDirPath()); m_variables.insert(QLatin1String("InstallerFilePath"), QCoreApplication::applicationFilePath()); QString dir = QLatin1String("/opt"); #ifdef Q_OS_WIN TCHAR buffer[MAX_PATH + 1] = { 0 }; SHGetFolderPath(0, CSIDL_PROGRAM_FILES, 0, 0, buffer); dir = QString::fromWCharArray(buffer); #elif defined (Q_OS_MAC) # if QT_VERSION < 0x050000 dir = QDesktopServices::storageLocation(QDesktopServices::ApplicationsLocation); # else dir = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).value(0); # endif #endif m_variables.insert(QLatin1String("ApplicationsDir"), dir); #ifdef Q_OS_WIN m_variables.insert(QLatin1String("os"), QLatin1String("win")); #elif defined(Q_OS_MAC) m_variables.insert(QLatin1String("os"), QLatin1String("mac")); #elif defined(Q_OS_LINUX) m_variables.insert(QLatin1String("os"), QLatin1String("x11")); #elif defined(Q_OS_QWS) m_variables.insert(QLatin1String("os"), QLatin1String("Qtopia")); #else // TODO: add more platforms as needed... #endif #ifdef Q_OS_WIN QSettingsWrapper user(QLatin1String("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\" "CurrentVersion\\Explorer\\User Shell Folders"), QSettingsWrapper::NativeFormat); QSettingsWrapper system(QLatin1String("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\" "CurrentVersion\\Explorer\\Shell Folders"), QSettingsWrapper::NativeFormat); const QString programs = user.value(QLatin1String("Programs"), QString()).toString(); const QString allPrograms = system.value(QLatin1String("Common Programs"), QString()).toString(); QString desktop; if (m_variables.value(QLatin1String("AllUsers")) == scTrue) { desktop = system.value(QLatin1String("Desktop")).toString(); } else { desktop = user.value(QLatin1String("Desktop")).toString(); } m_variables.insert(QLatin1String("DesktopDir"), replaceWindowsEnvironmentVariables(desktop)); m_variables.insert(QLatin1String("UserStartMenuProgramsPath"), replaceWindowsEnvironmentVariables(programs)); m_variables.insert(QLatin1String("AllUsersStartMenuProgramsPath"), replaceWindowsEnvironmentVariables(allPrograms)); #endif try { m_settings = Settings::fromFileAndPrefix(QLatin1String(":/metadata/installer-config/config.xml"), QLatin1String(":/metadata/installer-config/"), Settings::RelaxedParseMode); } catch (const Error &e) { // TODO: try better error handling qCritical("Could not parse Config: %s", qPrintable(e.message())); return; } // fill the variables defined in the settings m_variables.insert(QLatin1String("ProductName"), m_settings.applicationName()); m_variables.insert(QLatin1String("ProductVersion"), m_settings.applicationVersion()); m_variables.insert(scTitle, m_settings.title()); m_variables.insert(scPublisher, m_settings.publisher()); m_variables.insert(QLatin1String("Url"), m_settings.url()); m_variables.insert(scStartMenuDir, m_settings.startMenuDir()); m_variables.insert(scTargetConfigurationFile, m_settings.configurationFileName()); m_variables.insert(QLatin1String("LogoPixmap"), m_settings.logo()); m_variables.insert(QLatin1String("WatermarkPixmap"), m_settings.watermark()); m_variables.insert(QLatin1String("BannerPixmap"), m_settings.banner()); const QString description = m_settings.runProgramDescription(); if (!description.isEmpty()) m_variables.insert(scRunProgramDescription, description); m_variables.insert(scTargetDir, replaceVariables(m_settings.targetDir())); m_variables.insert(scRunProgram, replaceVariables(m_settings.runProgram())); m_variables.insert(scRunProgramArguments, replaceVariables(m_settings.runProgramArguments())); m_variables.insert(scRemoveTargetDir, replaceVariables(m_settings.removeTargetDir())); }
void App::Login() { struct passwd *pw; pid_t pid; pw = LoginPanel->GetInput()->GetPasswdStruct(); if(pw == 0) return; // Create new process pid = fork(); if(pid == 0) { // Login process starts here SwitchUser Su(pw, &cfg, DisplayName); string session = LoginPanel->getSession(); string loginCommand = cfg.getOption("login_cmd"); replaceVariables(loginCommand, SESSION_VAR, session); replaceVariables(loginCommand, THEME_VAR, themeName); string sessStart = cfg.getOption("sessionstart_cmd"); if (sessStart != "") { replaceVariables(sessStart, USER_VAR, pw->pw_name); system(sessStart.c_str()); } Su.Login(loginCommand.c_str()); exit(OK_EXIT); } #ifndef XNEST_DEBUG CloseLog(); #endif // Wait until user is logging out (login process terminates) pid_t wpid = -1; int status; while (wpid != pid) { wpid = wait(&status); } if (WIFEXITED(status) && WEXITSTATUS(status)) { LoginPanel->Message("Failed to execute login command"); } else { string sessStop = cfg.getOption("sessionstop_cmd"); if (sessStop != "") { replaceVariables(sessStop, USER_VAR, pw->pw_name); system(sessStop.c_str()); } } // Close all clients KillAllClients(False); KillAllClients(True); // Send HUP signal to clientgroup killpg(pid, SIGHUP); // Send TERM signal to clientgroup, if error send KILL if(killpg(pid, SIGTERM)) killpg(pid, SIGKILL); HideCursor(); #ifndef XNEST_DEBUG // Re-activate log file OpenLog(); #endif }
void RpmBuildPlugin::build(RpmBuildPlugin::Type buildType) { if (currentReleaseInfo == nullptr) return; //no release ich choosen //get info about this release BuildProcess *buildProcess = findBuildProcess(currentReleaseInfo); if (buildProcess != nullptr) //there is an info about build? { //if it's running then stop it if (buildProcess->isRunning()) //running? { buildProcess->stop(); return; } } QString homePath = getenv("HOME"); if (Settings::instance()->getEnvType() == Settings::External) homePath = "/root"; const ProjectInfo *projectInfo = currentReleaseInfo->getProjectInfo(); const QString releasePath = currentReleaseInfo->getReleasePath(); const ReleaseInfo::VersionList &localVersions = *currentReleaseInfo->getLocalVersions(); const QString specFile = homePath + "/rpmbuild/SPECS/" + projectInfo->getName() + ".spec"; const QString specSrc = releasePath + "/" + projectInfo->getName() + ".spec"; const QString specDst = SandboxProcess::decoratePath(specFile); debug(DebugLevel::Info) << QString("copying %1 to %2").arg(specSrc).arg(specDst); //skopiuj plik spec do SPECS (po uzupełnieniach) QFile src(specSrc); QFile dst(specDst); src.open(QIODevice::ReadOnly); dst.open(QIODevice::WriteOnly); //prepare hash of constants and variables QHash<QString, QString> list; List constants = getListOfConstants(currentReleaseInfo); List variables = getListOfVariables(currentReleaseInfo); append(list, constants); append(list, solveVariables(variables, constants)); while (src.atEnd() == false) { const QString line = replaceVariables( src.readLine(), list ); dst.write(line.toUtf8()); } src.close(); dst.close(); //skopiuj źródła foreach(ProjectVersion pV, localVersions) { debug(DebugLevel::Info) << QString("copying %1 to %2").arg(pV.getLocalFile().absoluteFilePath()) .arg(SandboxProcess::decoratePath(homePath + "/rpmbuild/SOURCES/") + pV.getLocalFile().fileName()); QFile::copy(pV.getLocalFile().absoluteFilePath(), SandboxProcess::decoratePath( homePath + "/rpmbuild/SOURCES/" + pV.getLocalFile().fileName()) ); }
RpmBuildPlugin::Hash RpmBuildPlugin::solveVariables(const List &variables, //variables to solve const List &constants //constants (solved) ) const { Hash hash; append(hash, constants); //fill list of solved constants/variables with constants std::function<bool(const Pair &var)> resolveVariable; resolveVariable = [&](const Pair &var) -> bool { auto error = [&](const QString &variable, const QString &value, const QString &message) { debug(DebugLevel::Error) << "Could not resolve variable \"" << variable << "\"" << "with value \"" << value << "\"" << ". Error message: " << message; }; assert(hash.contains(var.first) == false); //check first char of value if (var.second.size() == 0) hash[var.first] = var.second; else { const char operation = var.second[0].toAscii() ; switch (operation) { case '=': //just use variable's value hash[var.first] = replaceVariables(var.second.mid(1), hash); //do not use first char which is '=' break; case 'r': //regexp { //Format for this operation: // "r:expression:regexp:result" // ie: "r:abc:a(.*):_%1_" will return "_bc_". (%1 is equivalent of \1) // This operation is +- equivalent of: // echo $expression | sed -e "s/$regexp/$result/" // Instead of ":" as separator, any other char may be used. const QString value = var.second.mid(1); //all chars except 1. char const size_t size = value.size(); if (size >= sizeof(":::")) //minimal regexp is: ":::" { const QString solvedValue = replaceVariables(value, hash); //replace all variables with theirs values const char splitter = solvedValue[0].toAscii(); //use first char as splitter //do splitting const QStringList regexpParts = solvedValue.mid(1).split(splitter); //ommit first ':' //we are expecting 3 parts if (regexpParts.size() == 3) { QRegExp regexp(regexpParts[1]); //second part is a pattern if (regexp.exactMatch(regexpParts[0])) //enter string to be matched (first part) { //now try to commit matched expression to result const QStringList captured = regexp.capturedTexts(); //list of captured texts "(.*)" QString result = regexpParts[2]; for (int i = 1; i < captured.size(); i++) { //this operation will replace each "%n" in result part of regexp with corresponding captured text. //This is why we use %n instead of \n, as %n is used by QString algorithms to replace args result = result.arg(captured[i]); } hash[var.first] = result; } else error(var.first, var.second, "Could not match regular expression."); } else error(var.first, var.second, QString("Variable's value should consist of 3 parts, but %1 were found.") .arg(regexpParts.size())); } else error(var.first, var.second, "Variable's value is too short even for simples regular expression."); } break; default: debug(DebugLevel::Error) << "unknown variable operator: \"" << operation << "\""; break; } } return true; }; for (const Pair &var: variables) { //try to resolve value if (hash.contains(var.first) == false) //not resolved yet? resolveVariable(var); } return hash; }
void CGenerator::writeRep(const char * source, FILE * fWrite) { std::string strWrite; replaceVariables(source, strWrite); fputs(strWrite.c_str(), fWrite); }