QVariant WizWebEngineView::ExecuteScriptFile(QString fileName) { QString script; if (!WizLoadUnicodeTextFromFile(fileName, script)) { return QVariant(); } return ExecuteScript(script); }
bool CWizIndexBase::CheckTable(const QString& strTableName) { if (m_db.tableExists(strTableName)) return true; // create table if not exist CString strFileName = WizPathAddBackslash2(WizGetResourcesPath() + "sql") + strTableName.toLower() + ".sql"; CString strSQL; if (!WizLoadUnicodeTextFromFile(strFileName, strSQL)) return false; return ExecSQL(strSQL); }
QWebEngineProfile* createWebEngineProfile(const WizWebEngineViewInjectObjects& objects, QObject* parent) { if (objects.empty()) return nullptr; // QWebEngineProfile *profile = new QWebEngineProfile("WizNoteWebEngineProfile", parent); // QString jsWebChannelFileName = Utils::WizPathResolve::resourcesPath() + "files/webengine/wizwebchannel.js"; QString jsWebChannel; WizLoadUnicodeTextFromFile(jsWebChannelFileName, jsWebChannel); // QString initFileName = Utils::WizPathResolve::resourcesPath() + "files/webengine/wizwebengineviewinit.js"; QString jsInit; WizLoadUnicodeTextFromFile(initFileName, jsInit); // CWizStdStringArray names; for (auto inject : objects) { names.push_back("\"" + inject.name + "\""); } // CString objectNames; WizStringArrayToText(names, objectNames, ", "); // jsInit.replace("__objectNames__", objectNames); // QString jsAll = jsWebChannel + "\n" + jsInit; // { QWebEngineScript script; script.setSourceCode(jsAll); script.setName("qwebchannel.js"); script.setWorldId(QWebEngineScript::MainWorld); script.setInjectionPoint(QWebEngineScript::DocumentCreation); script.setRunsOnSubFrames(true); profile->scripts()->insert(script); } // return profile; }
void WizWebEngineView::innerLoadFinished(bool ret) { // if (ret) { if (m_server && m_server->isListening() && m_clientWrapper && m_channel) { QString jsWebChannel ; if (WizLoadTextFromResource(":/qtwebchannel/qwebchannel.js", jsWebChannel)) { page()->runJavaScript(jsWebChannel, [=](const QVariant&){ // QString initFileName = Utils::WizPathResolve::resourcesPath() + "files/webengine/wizwebengineviewinit.js"; QString jsInit; WizLoadUnicodeTextFromFile(initFileName, jsInit); // QString port = QString::asprintf("%d", int(m_server->serverPort())); // jsInit.replace("__port__", port).replace("__objectNames__", m_objectNames); // page()->runJavaScript(jsInit, [=](const QVariant&){ // emit loadFinishedEx(ret); // }); }); } else { qDebug() << "Can't load wen channel.js"; emit loadFinishedEx(ret); } } } else { emit loadFinishedEx(ret); } }
bool WizKMCombineDocumentsToHtmlFile(WizDatabaseManager& dbMgr, const CWizDocumentDataArray& arrayDocument, QString splitter, bool addTitle, QString& strResultFileName, CWizDocumentAttachmentDataArray& arrayAttachment, QString& strError) { QString strTempPath = Utils::WizPathResolve::tempPath() + WizGenGUIDLowerCaseLetterOnly() + "/"; ::WizEnsurePathExists(strTempPath); // CWizStdStringArray htmls; // size_t nCount = arrayDocument.size(); for (size_t i = 0; i < nCount; i++) { WIZDOCUMENTDATA doc = arrayDocument[i]; // WizDatabase& db = dbMgr.db(doc.strKbGUID); if (!db.isDocumentDownloaded(doc.strGUID)) { strError = QObject::tr("Note has not been downloaded"); return false; } // if (!db.documentToHtmlFile(doc, strTempPath)) { strError = QObject::tr("Failed to get note data"); return false; } // QString htmlFileName = strTempPath + "index.html"; if (!QFileInfo::exists(htmlFileName)) { strError = QObject::tr("Failed to get note data"); return false; } // QString html; if (!WizLoadUnicodeTextFromFile(htmlFileName, html)) { strError = QObject::tr("Failed to read note data"); return false; } // htmls.push_back(html); // CWizDocumentAttachmentDataArray atts; db.getDocumentAttachments(doc.strGUID, atts); for (WIZDOCUMENTATTACHMENTDATA att : atts) { if (!db.isAttachmentDownloaded(att.strGUID)) { strError = QObject::tr("Note attachment %1 has not been downloaded").arg(att.strName); return false; } // arrayAttachment.push_back(att); } } // CString strAllHTML; // for (size_t i = 0; i < nCount; i++) { CString html = htmls[i]; WIZDOCUMENTDATA doc = arrayDocument[i]; if (-1 != WizStrStrI_Pos(html, CString(_T("<frameset")))) { strError = QObject::tr("Cannot combine html because html contains frame set"); return false; } // CString strTitle = doc.strTitle; WizOleDateTime t = doc.tCreated; CString strDate = t.toLocalLongDate(); // if (addTitle) { CString strInfoHtml = WizFormatString2(_T("<h2>%1 (%2)</h2>"), strTitle, strDate); ::WizHTMLInsertTextBeforeBody(strInfoHtml, html); } // if (!WizCombineHtmlText(strAllHTML, html)) { strError = QObject::tr("Cannot combine html"); return false; } // if (i < nCount - 1) { if (!splitter.isEmpty()) { WizCombineHtmlText(strAllHTML, splitter); } } } // strResultFileName = strTempPath + "index.html"; // bool ret = ::WizSaveUnicodeTextToUtf8File(strResultFileName, strAllHTML); if (!ret) { strError = QObject::tr("Cannot save note html"); return false; } return true; }