void TestTfpconverter::otamaconvertStrong() { QFETCH(QString, htmlFileName); QFETCH(QString, olgFileName); QFETCH(QString, resultFileName); QFile htmlFile(htmlFileName); QVERIFY(htmlFile.open(QIODevice::ReadOnly | QIODevice::Text)); QTextStream tshtml(&htmlFile); tshtml.setCodec("UTF-8"); QFile olgFile(olgFileName); QVERIFY(olgFile.open(QIODevice::ReadOnly | QIODevice::Text)); QTextStream tsolg(&olgFile); tsolg.setCodec("UTF-8"); QFile resultFile(resultFileName); QVERIFY(resultFile.open(QIODevice::ReadOnly | QIODevice::Text)); QTextStream tsres(&resultFile); tsres.setCodec("UTF-8"); QString result = OtamaConverter::convertToErb(tshtml.readAll(), tsolg.readAll(), 2); QString expect = tsres.readAll(); QCOMPARE(result, expect); }
QString CampingConfig::receiptTemplate() { if (data.contains("custom_receipt") && !data["custom_receipt"].toString().isEmpty()) { return data["custom_receipt"].toString(); } else { QFile htmlFile(":/html/receipt.html"); htmlFile.open(QFile::ReadOnly); return htmlFile.readAll(); } }
void FaustgenFactory::generateSVG() { // To be sure we get a correct SVG diagram... removeSVG(); // Prepare compile options std::string error; const char* argv[64]; memset(argv, 0, 64 * sizeof(char*)); jassert(fCompileOptions.size() < 64); auto opt = 0; for (opt = 0; opt < fCompileOptions.size(); opt++) { argv[opt] = (char*) fCompileOptions.getReference(opt).toRawUTF8(); } argv[opt++] = "-svg"; argv[opt++] = "-sn"; argv[opt++] = "-sd"; if (fDrawPath != File::nonexistent) { // Generate SVG file if (!generateAuxFilesFromString(getTMPName().toStdString(), fSourceCode.toStdString(), fCompileOptions.size() + 3, argv, error)) { //TODO: if there is an error here STOP LOG("Generate SVG error : " + error); } File svgFile = getSVGFile(); if (svgFile.exists()) { #if 0 File htmlFile(fDrawPath.getFullPathName() + "/" + getSVGFolderName() + "/index.html"); htmlFile.appendText(HTML_WRAPPER); #else XmlDocument svgXML(svgFile); ScopedPointer<XmlElement> mainElement (svgXML.getDocumentElement()); mainElement->setAttribute("width", "100%"); mainElement->setAttribute("height", "100%"); mainElement->writeToFile(svgFile, String::empty); #endif } } }
void GoodsDialog::on_resourceReady(std::string res_root) { QString htmlContent; QFile htmlFile(page_name); if (!htmlFile.open(QIODevice::ReadOnly | QIODevice::Text)){ return; } QTextStream in(&htmlFile); in.setCodec("UTF-8"); htmlContent = in.readAll(); QTextDocument *document = new QTextDocument(); document->setHtml(htmlContent); ui->textBrowser->setDocument(document); }
/* * Returns valid HTML: true or false */ bool MapSettings::loadMapHtml() { // Load the settings if (m_mapJSData == "") { qWarning() << "Warning: Map JS file was empty or invalid, disabling maps."; return false; } QFile file(m_mapHtmlInPath); if ( !file.open(QFile::ReadOnly | QFile::Text) ) { qWarning() << "Warning: Unable to open Map HTML file, disabling maps."; return false; } else { QTextStream in(&file); QString inText = in.readAll(); m_mapHtmlPath = m_configDir + "/map-gen.html"; QFile htmlFile(m_mapHtmlPath); if (!htmlFile.open(QFile::WriteOnly | QFile::Text)) { qWarning() << "Warning: Could not open Generated Map HTML file for writing"; return false; } else { // Replace all the tags with their actual values // __API_KEY__ and __JS_CODE__ are directly in the HTML file, // The other tags are in the mapJSData string. m_mapHtmlData = inText.replace("__JS_CODE__", m_mapJSData); m_mapHtmlData = inText.replace("__API_KEY__", m_apiKey); m_mapHtmlData = inText.replace("__LAT__", QString::number(m_lat)); m_mapHtmlData = inText.replace("__LON__", QString::number(m_lon)); m_mapHtmlData = inText.replace("__ZOOM__", QString::number(m_zoom)); m_mapHtmlData = inText.replace("__MAP_TYPE__", m_mapType); m_mapHtmlData = inText.replace("__DISABLE_MAP_UI__", m_mapDisableUI ? "true" : "false"); QTextStream out(&htmlFile); out << m_mapHtmlData; return true; } } }
/** "Help message" dialog box */ HelpSibcoinDialog::HelpSibcoinDialog(QWidget *parent) : QDialog(parent), ui(new Ui::HelpMessageDialog) { ui->setupUi(this); GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this); QString res_name = ":/html/sibcoindesc"; QString htmlContent; QFile htmlFile(res_name); if (!htmlFile.open(QIODevice::ReadOnly | QIODevice::Text)){ return; } QTextStream in(&htmlFile); in.setCodec("UTF-8"); htmlContent = in.readAll(); // Set help message text ui->helpMessageLabel->setText(htmlContent); }
bool OtamaConverter::convert(const QString &filePath, int trimMode) const { QFile htmlFile(filePath); QFile otmFile(ViewConverter::changeFileExtension(filePath, logicFileSuffix())); QString className = ViewConverter::getViewClassName(filePath); QFile outFile(erbConverter.outputDir().filePath(className + ".cpp")); // Checks file's timestamp QFileInfo htmlFileInfo(htmlFile); QFileInfo otmFileInfo(otmFile); QFileInfo outFileInfo(outFile); if (htmlFileInfo.exists() && outFileInfo.exists()) { if (outFileInfo.lastModified() > htmlFileInfo.lastModified() && (!otmFileInfo.exists() || outFileInfo.lastModified() > otmFileInfo.lastModified())) { //printf("done %s\n", qPrintable(outFile.fileName())); return true; } else { if (outFile.remove()) { printf(" removed %s\n", qPrintable(outFile.fileName())); } } } if (!htmlFile.open(QIODevice::ReadOnly)) { qCritical("failed to read phtm file : %s", qPrintable(htmlFile.fileName())); return false; } // Otama logic reading QString otm; if (otmFile.open(QIODevice::ReadOnly)) { otm = QTextStream(&otmFile).readAll(); } QString erb = OtamaConverter::convertToErb(QTextStream(&htmlFile).readAll(), otm, trimMode); return erbConverter.convert(className, erb, trimMode); }
QUrl QtlMovieHelp::urlOf(QObject* parent, const QString& fragment) { // Name of the main help file. const QString fileName("qtlmovie-user.html"); // Search the directory where help files are stored. // Start with the application directory. const QString appDir(QtlFile::absoluteNativeFilePath(QCoreApplication::applicationDirPath())); QStringList dirs(appDir); #if defined(Q_OS_WIN) || defined(Q_OS_DARWIN) // On Windows and Mac, add the local help subdirectory. // When running the application from the build tree, also add the help // subdirectory from some level upward from the application executable. const QString toolPath(QtlFile::searchParentSubdirectory(appDir, "help")); if (!toolPath.isEmpty()) { dirs << toolPath; } #endif #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) // On UNIX, add various standard locations for help files. dirs << "/usr/share/doc/qtlmovie" << "/usr/share/help/qtlmovie" << "/usr/local/doc/qtlmovie" << "/usr/local/help/qtlmovie"; #endif // Now search the QtlMovie help file there. QString htmlFile(QtlFile::search(fileName, dirs)); if (htmlFile.isEmpty()) { // File not found. qtlError(parent, QObject::tr("Cannot find help files.\nTry to reinstall QtlMovie.")); return QUrl(); } // Find a locale variant if it exists. htmlFile = QtlTranslator::searchLocaleFile(htmlFile); // Build URL. QUrl url(QUrl::fromLocalFile(htmlFile)); if (fragment.isEmpty()) { // No "#fragment", URL is complete. return url; } // Set the "#fragment" part of the URL. url.setFragment(fragment); #if QT_VERSION < QT_VERSION_CHECK(6,0,0) // Warning: Qt bug #55300 (https://bugreports.qt.io/browse/QTBUG-55300) // When there is a fragment in a file:// URL, QDesktopServices::openUrl() // fails to set the fragment in the actual URL. This bug has been reported // for Qt 5.7.0. We do not know yet when this bug is fixed. Currently, we // assume it will be fixed in 6.0.0. // Workaround for Qt bug: We create a temporary HTML file containing // a redirect directive to the target URL. In case of error, we simply // return the URL as we built it, directly on the final target file. // Because of the Qt bug, the anchor will be ignored and the HTML file // will be opened at the beginning, which is better than nothing. // Create a temporary directory for temporary HTML files. if (_tempDir == 0) { _tempDir = new QTemporaryDir(); } // Does the temporary directory exist? if (!_tempDir->isValid()) { // Cannot create temporary files. return url; } // Temporary file name to create. const QString tempFile(_tempDir->path() + QDir::separator() + QFileInfo(htmlFile).completeBaseName() + QStringLiteral("-anchor-") + fragment + ".html"); // The file may already exist if we already accessed this page. // Create the file only if it does not exists. if (!QFile(tempFile).exists()) { // File content: HTTP redirection to target file and anchor. QStringList lines; lines << "<html><head>" << ("<meta http-equiv=\"refresh\" content=\"0;URL='" + url.toString() + "'\"/> ") << "</head><body><p>" << ("Click <a href=\"" + url.toString() + "\">here</a>.") << "</p></body></html>"; if (!QtlFile::writeTextLinesFile(tempFile, lines)) { // Error while creating the temporary file. return url; } } // Replace the URL content with the temporary file, without fragment. url = QUrl::fromLocalFile(tempFile); #endif return url; }
int main(int argc, char **argv) { QApplication application(argc, argv); application.setApplicationName("HTML Message Box"); application.setApplicationVersion("0.2.0"); QTextCodec::setCodecForLocale(QTextCodec::codecForName ("UTF8")); int windowWidth = 400; int windowHeigth = 200; int timeoutSeconds = 0; // Read command line arguments: QStringList arguments = QCoreApplication::arguments(); foreach (QString argument, arguments) { if (argument.contains("--help")) { std::cout << " " << std::endl; std::cout << qApp->applicationName().toLatin1().constData() << " version " << qApp->applicationVersion().toLatin1().constData() << std::endl; std::cout << "Executable: " << (QDir::toNativeSeparators ( QApplication::applicationFilePath()) .toLatin1().constData()) << std::endl; std::cout << "Qt version: " << QT_VERSION_STR << std::endl; std::cout << " " << std::endl; std::cout << "Usage:" << std::endl; std::cout << " htmlmsg --option=value -o=value" << std::endl; std::cout << " " << std::endl; std::cout << "Options:" << std::endl; std::cout << " --width -w " << "message width in points. Minimum: 200 points" << std::endl; std::cout << " --heigth -h " << "message heigth in points. Minimum: 200 points" << std::endl; std::cout << " --timeout -t " << "timeout in seconds. " << "Less than 3 seconds means no timeout." << std::endl; std::cout << " --help this help" << std::endl; std::cout << " " << std::endl; return 0; } if (argument.contains("--width") or argument.contains ("-w")) { if (argument.section ("=", 1, 1).toInt() > 200) { windowWidth = argument.section ("=", 1, 1).toInt(); application.setProperty("windowWidth", windowWidth); } } if (argument.contains("--heigth") or argument.contains ("-h")) { if (argument.section ("=", 1, 1).toInt() > 200) { windowHeigth = argument.section ("=", 1, 1).toInt(); application.setProperty("windowHeigth", windowHeigth); } } if (argument.contains("--timeout") or argument.contains ("-t")) { if (argument.section ("=", 1, 1).toInt() > 3) { timeoutSeconds = argument.section ("=", 1, 1).toInt(); application.setProperty("timeoutSeconds", timeoutSeconds); } } } // Message box icon: QString externalIconFilePath = application.applicationDirPath() + QDir::separator() + "htmlmsg.png"; QFile iconFile(externalIconFilePath); QPixmap icon(32, 32); if (iconFile.exists()) { // Set the external icon: icon.load(externalIconFilePath); QApplication::setWindowIcon(icon); } else { // Set the embedded icon: icon.load(":/htmlmsg.png"); QApplication::setWindowIcon(icon); } // HTML message template: QString htmlFolder = application.applicationDirPath() + QDir::separator() + "msgbox"; QString htmlFilePath = htmlFolder + QDir::separator() + "htmlmsg.html"; QFile htmlFile(htmlFilePath); QString htmlContent; if (htmlFile.exists()) { // Load the external HTML message template: QFileReader *resourceReader = new QFileReader(htmlFilePath); htmlContent = resourceReader->fileContents; htmlContent.replace("local://", QString( "file://" + htmlFolder + QDir::separator())); } else { // Load the embedded HTML message template: QFileReader *resourceReader = new QFileReader(QString(":/htmlmsg.html")); htmlContent = resourceReader->fileContents; } // Initiate the message box and load the HTML message: QView window; window.mainPage->mainFrame()->setHtml(htmlContent); // Read any initial STDIN data: if (isatty(fileno(stdin))) { window.qReadStdin(); } // Set the message box dimensions and center it on screen: window.setFixedSize (windowWidth, windowHeigth); QRect screenRect = QDesktopWidget().screen()->rect(); window.move (QPoint( screenRect.width()/2 - windowWidth/2, screenRect.height()/2 - windowHeigth/2)); // Display the message box: window.show(); // Set the message box timeout: if (timeoutSeconds > 0) { int timeoutMilliseconds = timeoutSeconds * 1000; QTimer *timer = new QTimer(); timer->singleShot (timeoutMilliseconds, &window, SLOT (qCloseApplicationSlot())); } // Set the STDIN watcher: QSocketNotifier *stdinNotifier = new QSocketNotifier(fileno(stdin), QSocketNotifier::Read); QObject::connect(stdinNotifier, SIGNAL(activated(int)), &window, SLOT(qReadStdin())); if (isatty(fileno(stdin))) { stdinNotifier->setEnabled(true); } application.exec(); }
int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Please provide one .avs file"); return 1; } QFile avsFile(argv[1]); if (!avsFile.open(QIODevice::ReadOnly)) { fprintf(stderr, "Cannot open '%s'", argv[1]); return 2; } QTextStream avsTs(&avsFile); const QFileInfo avsFInfo(avsFile); const QString filesBasePathAndName = avsFInfo.absolutePath() + QDir::separator() + avsFInfo.baseName(); QFile au3File(filesBasePathAndName + QLatin1String(".au3")); QFile htmlFile(filesBasePathAndName + QLatin1String(".html")); if (!au3File.open(QIODevice::WriteOnly) || !htmlFile.open(QIODevice::WriteOnly)) { fprintf(stderr, "Cannot create '%s'", argv[1]); return 2; } QTextStream au3Ts(&au3File); QTextStream htmlTs(&htmlFile); au3Ts << "#include <Array.au3>\n\n" "Opt(\"SendKeyDelay\", 80)\n" "HotKeySet(\"{F8}\", \"Terminate\")\n" "HotKeySet(\"{F9}\", \"TypeSnippet\")\n\n" "Local $snippetsArray[1]\n" "$snippetsLineIndex = 1\n\n" "Func Terminate()\n" " Exit 0\n" "EndFunc\n\n" "Func TypeSnippet()\n" " For $snippetPiece IN StringSplit($snippetsArray[$snippetsLineIndex], '§', 2)\n" " Send($snippetPiece)\n" " Sleep(350)\n" " Next\n" " $snippetsLineIndex = $snippetsLineIndex + 1\n" " If $snippetsLineIndex = UBound($snippetsArray) Then\n" " Exit 0\n" " EndIf\n" "EndFunc\n\n"; QString avsLine; QString hmtlLines; QStringList narrationLines; bool changedAvsFunction = false; do { avsLine = avsTs.readLine(); if (avsLine.trimmed().startsWith(narrationMarker)) { if (changedAvsFunction) { htmlTs << QLatin1String("<hr/>\n"); changedAvsFunction = false; } const int markerEnd = avsLine.indexOf(narrationMarker) + narrationMarker.length(); narrationLines << avsLine.mid(markerEnd); } else if (avsLine.trimmed().startsWith(annotationMarker)) { const int markerEnd = avsLine.indexOf(annotationMarker) + annotationMarker.length(); narrationLines << "<i><small>" << avsLine.mid(markerEnd) << "</small></i>"; } else { if (!narrationLines.isEmpty()) { htmlTs << QLatin1String("<p>\n"); htmlTs << narrationLines.join(QLatin1String("\n<br/>\n")); htmlTs << QLatin1String("\n</p>\n"); narrationLines.clear(); } } if (avsLine.trimmed().startsWith(typingMarker)) { const int markerEnd = avsLine.indexOf(typingMarker) + typingMarker.length(); au3Ts << "_ArrayAdd($snippetsArray, '" << avsLine.mid(markerEnd) << "')" << endl; } else if (avsLine.trimmed().toLower().startsWith(functionKeyword)) { changedAvsFunction = true; } } while (!avsLine.isNull()); au3Ts << "\nWhile 1\n" " Sleep(100)\n" "WEnd\n"; return 0; }