void QwcNewsWidget::addNewsItem(const QString &nickname, QDateTime time, const QString &text, bool insertAtTop) { QString messageText = text.trimmed(); messageText = Qt::escape(messageText); messageText = QwcMessageStyle::replaceEmoticons(messageText, m_emoticonsEnabled); messageText.replace("\n", "<br>"); QString newItem = QString("<div class=\"news_item\">" "<span class=\"news_header\">From %1 (%2):</span>" "<span class=\"news_body\">%3</span></div>") .arg(Qt::escape(nickname)) .arg(Qt::escape(time.toString())) .arg(messageText); QWebElement mainElement = newsView->page()->mainFrame()->findFirstElement("#news_items"); if (insertAtTop) { mainElement.prependInside(newItem); } else { mainElement.appendInside(newItem); } m_newsCounter++; fNewsStatus->setText(tr("%1 news article(s)").arg(m_newsCounter)); }
void tdRenderer::render(QByteArray ba) { bufreset(m_buffer); QWebElement element = m_body.findFirst(".__tmp__"); const char *data = ba.data(); uint beg = 0; size_t e = ba.size(); int prevsize = 0; int pos = m_fframe; while (beg < e) { const char *offs = data + beg; int n = td_markdown_render(m_buffer, (const uint8_t *) offs, e - beg, m_markdown); QByteArray bytes((const char *) m_buffer->data + prevsize, m_buffer->size - prevsize); m_sizes.insert(pos, n); m_indices.insert(pos++, m_index); if (m_pants) { bufreset(m_tmpbuffer); sdhtml_smartypants(m_tmpbuffer, (const uint8_t *) bytes.constData(), bytes.size()); QByteArray pants((const char *) m_tmpbuffer->data, m_tmpbuffer->size); element.appendInside(pants); } else { element.appendInside(bytes); } QWebElementCollection children = element.findAll("*"); QString klassName = "__" % QString::number(m_index++) % "__"; QWebElementCollection::const_iterator i = children.constBegin(); for (; i != children.constEnd(); ++i) { QWebElement e = *i; e.addClass(klassName); if (!e.parent().hasClass(klassName)) element.prependOutside(e.takeFromDocument()); } if (m_body.findFirst("." % klassName).isNull()) element.prependOutside("<span class=\"" % klassName % "\"></span>"); beg += n; prevsize = m_buffer->size; } element.takeFromDocument(); }
void PhysiomeModelRepositoryWindowWidget::initialize(const PhysiomeModelRepositoryWindowExposures &pExposures, const QString &pErrorMessage, const bool &pInternetConnectionAvailable) { // Initialise / keep track of some properties mExposureNames = QStringList(); mExposureDisplayed = QBoolList(); mExposureUrlId = QMap<QString, int>(); mErrorMessage = pErrorMessage; mInternetConnectionAvailable = pInternetConnectionAvailable; // Initialise our list of exposures QWebElement tbodyElement = page()->mainFrame()->documentElement().findFirst("tbody[id=exposures]"); tbodyElement.removeAllChildren(); for (int i = 0, iMax = pExposures.count(); i < iMax; ++i) { QString exposureUrl = pExposures[i].url(); QString exposureName = pExposures[i].name(); tbodyElement.appendInside("<tr id=\"exposure_"+QString::number(i)+"\">\n" " <td class=\"exposure\">\n" " <table class=\"fullWidth\">\n" " <tbody>\n" " <tr>\n" " <td class=\"fullWidth\">\n" " <ul>\n" " <li class=\"exposure\">\n" " <a href=\""+exposureUrl+"\">"+exposureName+"</a>\n" " </li>\n" " </ul>\n" " </td>\n" " <td class=\"button\">\n" " <a class=\"noHover\" href=\"cloneWorkspace|"+exposureUrl+"|"+exposureName+"\"><img class=\"button clone\"/></a>\n" " </td>\n" " <td class=\"button\">\n" " <a class=\"noHover\" href=\"showExposureFiles|"+exposureUrl+"|"+exposureName+"\"><img id=\"exposure_"+QString::number(i)+"\" class=\"button open\"/></a>\n" " </td>\n" " </tr>\n" " </tbody>\n" " </table>\n" " <ul id=\"exposureFiles_"+QString::number(i)+"\" style=\"display: none;\">\n" " </ul>\n" " </td>\n" "</tr>\n"); mExposureNames << exposureName; mExposureDisplayed << true; mExposureUrlId.insert(exposureUrl, i); } }
void PhysiomeModelRepositoryWindowWidget::addExposureFiles(const QString &pUrl, const QStringList &pExposureFiles) { // Add the given exposure files to the exposure QWebElement ulElement = page()->mainFrame()->documentElement().findFirst(QString("ul[id=exposureFiles_%1]").arg(mExposureUrlId.value(pUrl))); foreach (const QString &exposureFile, pExposureFiles) { ulElement.appendInside(QString("<li class=\"exposureFile\">" " <a href=\"%1\">%2</a>" "</li>").arg(exposureFile, QString(exposureFile).remove(QRegularExpression(".*/")))); }
void lmcMessageLog::appendPublicMessage(QString* lpszUserId, QString* lpszUserName, QString* lpszMessage, QDateTime *pTime, QFont *pFont, QColor *pColor) { QString html = QString::null; bool localUser = (lpszUserId->compare(localId) == 0); decodeMessage(lpszMessage); QString fontStyle = getFontStyle(pFont, pColor, localUser); if(lpszUserId->compare(lastId) != 0) { outStyle = !outStyle; html = outStyle ? themeData.outMsg : themeData.inMsg; // get the avatar image for this user from the cache folder QString filePath = participantAvatars.value(*lpszUserId); // if image not found, use the default avatar image for this user QString iconPath = QFile::exists(filePath) ? QUrl::fromLocalFile(filePath).toString() : "qrc"AVT_DEFAULT; html.replace("%iconpath%", iconPath); html.replace("%sender%", *lpszUserName); html.replace("%time%", getTimeString(pTime)); html.replace("%style%", fontStyle); html.replace("%message%", *lpszMessage); QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); body.appendInside(html); } else { html = outStyle ? themeData.outNextMsg : themeData.inNextMsg; html.replace("%time%", getTimeString(pTime)); html.replace("%style%", fontStyle); html.replace("%message%", *lpszMessage); QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); QWebElement last = body.lastChild(); QWebElement insert = last.findFirst("div#insert"); insert.replace(html); } hasData = true; }
void KinotifyWidget::SetData () { QString data = Theme_; data.replace ("{title}", Title_); data.replace ("{body}", Body_); if (OverridePixmap_.isNull ()) data.replace ("{imagepath}", MakeImage (ImagePath_)); else data.replace ("{imagepath}", MakeImage (OverridePixmap_)); setHtml (data); if (!ActionsNames_.isEmpty ()) { QWebElement button = page ()->mainFrame ()->documentElement ().findFirst ("form"); if (!button.isNull ()) { QStringList reversed = ActionsNames_; std::reverse (reversed.begin (), reversed.end ()); Q_FOREACH (const QString& name, reversed) button.appendInside (QString ("<input type=\"button\" id=\"%1\" value=\"%2\"" " onclick=\"Action.sendActionOnClick(id)\" />") .arg (ActionsNames_.indexOf (name)) .arg (name)); }
void MainWindow::addMessage(PattyIrcMessage *message) { QWebElement pageBody = this->ui->baseChatWindow->page()->mainFrame()->documentElement().findFirst("body"); pageBody.appendInside(message->message); }
void ChatTab::AppendMessage (Plugins::IMessage *msg) { Plugins::ICLEntry *other = qobject_cast<Plugins::ICLEntry*> (msg->OtherPart ()); if (!other && msg->OtherPart ()) { qWarning () << Q_FUNC_INFO << "message's other part doesn't implement ICLEntry" << msg->GetObject () << msg->OtherPart (); return; } if (msg->GetDirection () == Plugins::IMessage::DOut && other->GetEntryType () == Plugins::ICLEntry::ETMUC) return; QWebFrame *frame = Ui_.View_->page ()->mainFrame (); bool shouldScrollFurther = (frame->scrollBarMaximum (Qt::Vertical) == frame->scrollBarValue (Qt::Vertical)); QString body = FormatBody (msg->GetBody (), msg); QString string = QString ("%1 ") .arg (FormatDate (msg->GetDateTime (), msg)); string.append (' '); switch (msg->GetDirection ()) { case Plugins::IMessage::DIn: { switch (msg->GetMessageType ()) { case Plugins::IMessage::MTChatMessage: case Plugins::IMessage::MTMUCMessage: { QString entryName = Qt::escape (other->GetEntryName ()); entryName = FormatNickname (entryName, msg); if (body.startsWith ("/me ")) { body = body.mid (3); string.append ("*** "); string.append (entryName); string.append (' '); } else { string.append (entryName); string.append (": "); } break; } case Plugins::IMessage::MTEventMessage: string.append ("! "); break; } break; } case Plugins::IMessage::DOut: string.append (FormatNickname ("R", msg)); string.append (": "); break; } string.append (body); QWebElement elem = frame->findFirstElement ("body"); elem.appendInside (QString ("<div>%1</div").arg (string)); if (shouldScrollFurther) QTimer::singleShot (100, this, SLOT (scrollToEnd ())); }
// This function is called to display a file request message on chat box void lmcMessageLog::appendFileMessage(MessageType type, QString* lpszUserName, XmlMessage* pMessage, bool bReload) { QString htmlMsg; QString caption; QString fileId = pMessage->data(XN_FILEID); QString tempId; QString szStatus; htmlMsg = themeData.reqMsg; htmlMsg.replace("%iconpath%", "qrc"IDR_FILEMSG); FileOp fileOp = (FileOp) Helper::indexOf(FileOpNames, FO_Max, pMessage->data(XN_FILEOP)); if(type == MT_LocalFile) { tempId = "send" + fileId; caption = tr("Sending '%1' to %2."); htmlMsg.replace("%sender%", caption.arg(pMessage->data(XN_FILENAME), *lpszUserName)); htmlMsg.replace("%message%", ""); htmlMsg.replace("%fileid%", tempId); switch(fileOp) { case FO_Request: sendFileMap.insert(fileId, *pMessage); pMessage->addData(XN_TEMPID, tempId); htmlMsg.replace("%links%", "<a href='lmc://filecancel/" + fileId + "'>" + tr("Cancel") + "</a>"); break; case FO_Cancel: case FO_Accept: case FO_Decline: szStatus = getFileStatusMessage(FM_Send, fileOp); htmlMsg.replace("%links%", szStatus); break; default: return; break; } } else if(type == MT_File) { tempId = "receive" + fileId; if(autoFile) { caption = tr("%1 is sending you a file:"); htmlMsg.replace("%sender%", caption.arg(*lpszUserName)); htmlMsg.replace("%message%", pMessage->data(XN_FILENAME) + " (" + Helper::formatSize(pMessage->data(XN_FILESIZE).toLongLong()) + ")"); htmlMsg.replace("%fileid%", ""); } else { caption = tr("%1 sends you a file:"); htmlMsg.replace("%sender%", caption.arg(*lpszUserName)); htmlMsg.replace("%message%", pMessage->data(XN_FILENAME) + " (" + Helper::formatSize(pMessage->data(XN_FILESIZE).toLongLong()) + ")"); htmlMsg.replace("%fileid%", tempId); } switch(fileOp) { case FO_Request: receiveFileMap.insert(fileId, *pMessage); pMessage->addData(XN_TEMPID, tempId); if(autoFile) { htmlMsg.replace("%links%", tr("File has been accepted automatically.")); } else { htmlMsg.replace("%links%", "<a href='lmc://fileaccept/" + fileId + "'>" + tr("Accept") + "</a> " + "<a href='lmc://filedecline/" + fileId + "'>" + tr("Decline") + "</a>"); } if(autoFile && !bReload) fileOperation(fileId, "fileaccept"); break; case FO_Cancel: case FO_Accept: case FO_Decline: szStatus = getFileStatusMessage(FM_Receive, fileOp); htmlMsg.replace("%links%", szStatus); break; default: return; break; } } QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); body.appendInside(htmlMsg); }
void lmcMessageLog::appendMessageLog(QString *lpszHtml) { QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); body.appendInside(*lpszHtml); }
// Modify the en-media tag into an attachment void NoteFormatter::modifyApplicationTags(QWebElement &enmedia, QString &hash, QString appl) { if (appl.toLower() == "vnd.evernote.ink") { inkNote = true; readOnly = true; buildInkNote(enmedia, hash); return; } ResourceTable resTable(global.db); QString contextFileName; qint32 resLid = resTable.getLidByHashHex(note.guid, hash); Resource r; resTable.get(r, resLid, false); if (!r.data.isSet()) resourceError = true; else { // If we are running the formatter and we are not generating a thumbnail QString mimetype = ""; if (r.mime.isSet()) mimetype = r.mime; if (mimetype == "application/pdf" && pdfPreview && !thumbnail) { modifyPdfTags(resLid, enmedia); return; } // If we are running the formatter so we can generate a thumbnail and it is a PDF if (mimetype == "application/pdf" && pdfPreview && thumbnail) { QString printImageFile = global.fileManager.getTmpDirPath() + QString::number(resLid) +QString("-print.jpg"); QString file = global.fileManager.getDbaDirPath() + QString::number(resLid) +".pdf"; Poppler::Document *doc; doc = Poppler::Document::load(file); if (doc == NULL) return; QImage *image = new QImage(doc->page(0)->renderToImage()); image->save(printImageFile,"jpg"); delete image; enmedia.setAttribute("src", printImageFile); enmedia.removeAttribute("hash"); enmedia.removeAttribute("type"); enmedia.setOuterXml(enmedia.toOuterXml().replace("<en-media","<img")); enmedia.setOuterXml(enmedia.toOuterXml().replace("</en-media>","</img>")); return; } QString fileDetails = ""; MimeReference ref; ResourceAttributes attributes; if (r.attributes.isSet()) attributes = r.attributes; if (attributes.fileName.isSet()) fileDetails = ref.getExtensionFromMime(r.mime, fileDetails); enmedia.setAttribute("href", QString("nnres:") +global.fileManager.getDbaDirPath()+QString::number(resLid) +fileDetails); contextFileName = global.fileManager.getTmpDirPath("")+QString::number(resLid) +global.attachmentNameDelimeter + fileDetails; // Setup the context menu. This is useful if we want to do a "save as" or such contextFileName = contextFileName.replace("\\", "/"); enmedia.setAttribute("onContextMenu", "window.browserWindow.resourceContextMenu('" +contextFileName +"');"); enmedia.setAttribute("en-tag", "en-media"); enmedia.setAttribute("lid", QString::number(resLid)); enmedia.appendInside("<img/>"); QWebElement newText = enmedia.lastChild(); // Build an icon of the image QString fileExt; if (attributes.fileName.isSet()) fileExt = attributes.fileName; else fileExt = appl; QString fn; QString mime; if (attributes.fileName.isSet()) fn = attributes.fileName; if (r.mime.isSet()) mime = r.mime; fileExt = ref.getExtensionFromMime(mime, fn); QString icon = findIcon(resLid, r, fileExt); newText.setAttribute("src", "file:///"+icon); if (attributes.fileName.isSet()) newText.setAttribute("title",attributes.fileName); newText.setAttribute("en-tag", "temporary"); //Rename the tag to a <a> link enmedia.setOuterXml(enmedia.toOuterXml().replace("<en-media","<a")); enmedia.setOuterXml(enmedia.toOuterXml().replace("</en-media>","</a>")); } }
/* Modify an image tag. Basically we turn it back into a picture, write out the file, and modify the ENML */ void NoteFormatter::modifyImageTags(QWebElement &enMedia, QString &hash) { QString mimetype = enMedia.attribute("type"); qint32 resLid = 0; resLid = hashMap[hash]; QString highlightString = ""; if (resLid>0) { QLOG_TRACE() << "Getting resource"; Resource r = resourceMap[resLid]; QLOG_TRACE() << "resource retrieved"; MimeReference ref; QString filename; ResourceAttributes attributes; if (r.attributes.isSet()) attributes = r.attributes; if (attributes.fileName.isSet()) filename = attributes.fileName; QString type = ref.getExtensionFromMime(mimetype, filename); Data data; if (r.data.isSet()) data = r.data; if (data.size.isSet() && data.size > 0) { QString imgfile = "file:///"+global.fileManager.getDbDirPath(QString("dba/") +QString::number(resLid) +type); enMedia.setAttribute("src", imgfile); // Check if this is a LaTeX image ResourceAttributes attributes; if (r.attributes.isSet()) attributes = r.attributes; QString sourceUrl = ""; if (attributes.sourceURL.isSet()) sourceUrl = attributes.sourceURL; if (sourceUrl.toLower().startsWith("http://latex.codecogs.com/gif.latex?")) { enMedia.appendInside("<img/>"); QWebElement newText = enMedia.lastChild(); enMedia.setAttribute("en-tag", "en-latex"); newText.setAttribute("onMouseOver", "style.cursor='pointer'"); newText.setAttribute("title", sourceUrl); newText.setAttribute("href", "latex://"+QString::number(resLid)); } enMedia.setAttribute("onContextMenu", "window.browserWindow.imageContextMenu('" +QString::number(resLid) +"', '" +QString::number(resLid) +type +"');"); highlightString = addImageHighlight(resLid, imgfile); if (highlightString != "") enMedia.setAttribute("onload", highlightString); } } else { resourceError = true; readOnly = true; } // Reset the tags to something that WebKit will understand enMedia.setAttribute("en-tag", "en-media"); enMedia.setPlainText(""); enMedia.setAttribute("lid", QString::number(resLid)); // rename the <enmedia> tag to <img> enMedia.setOuterXml(enMedia.toOuterXml().replace("<en-media","<img")); enMedia.setOuterXml(enMedia.toOuterXml().replace("</en-media>","</img>")); }
// This function is called to display a file request message on chat box void wavrMessageLog::appendFileMessage(MessageType type, QString* lpszUserName, wavrXmlMessage* pMessage, bool bReload) { Q_UNUSED(type); QString htmlMsg; QString caption; QString fileId = pMessage->data(XML_FILEID); QString tempId; QString szStatus; QString fileType; switch(type) { case MT_File: fileType = "file"; break; case MT_Folder: fileType = "folder"; break; default: return; break; } htmlMsg = themeData.reqMsg; htmlMsg.replace("%iconpath%", "qrc"IDR_FILEMSG); FileOp fileOp = (FileOp)wavrHelper::indexOf(FileOpNames, FO_Max, pMessage->data(XML_FILEOP)); FileMode fileMode = (FileMode)wavrHelper::indexOf(FileModeNames, FM_Max, pMessage->data(XML_MODE)); if(fileMode == FM_Send) { qDebug() << "inside fmsend message"; tempId = "send" + fileId; caption = tr("Sending '%1' to %2."); htmlMsg.replace("%sender%", caption.arg(pMessage->data(XML_FILENAME), *lpszUserName)); htmlMsg.replace("%message%", ""); htmlMsg.replace("%fileid%", tempId); switch(fileOp) { case FO_Request: sendFileMap.insert(fileId, *pMessage); pMessage->addData(XML_TEMPID, tempId); htmlMsg.replace("%links%", "<a href='wavr://" + fileType + "/" + cancelOp + "/" + fileId + "'>" + tr("Cancel") + "</a>"); break; case FO_Cancel: case FO_Accept: case FO_Decline: case FO_Error: case FO_Abort: case FO_Complete: szStatus = getFileStatusMessage(FM_Send, fileOp); htmlMsg.replace("%links%", szStatus); break; default: return; break; } } else { tempId = "receive" + fileId; if(autoFile) { if(type == MT_File) caption = tr("%1 is sending you a file:"); else caption = tr("%1 is sending you a folder:"); htmlMsg.replace("%sender%", caption.arg(*lpszUserName)); htmlMsg.replace("%message%", pMessage->data(XML_FILENAME) + " (" + wavrHelper::formatSize(pMessage->data(XML_FILESIZE).toLongLong()) + ")"); htmlMsg.replace("%fileid%", ""); } else { if(type == MT_File) caption = tr("%1 sends you a file:"); else caption = tr("%1 sends you a folder:"); htmlMsg.replace("%sender%", caption.arg(*lpszUserName)); htmlMsg.replace("%message%", pMessage->data(XML_FILENAME) + " (" + wavrHelper::formatSize(pMessage->data(XML_FILESIZE).toLongLong()) + ")"); htmlMsg.replace("%fileid%", tempId); } switch(fileOp) { case FO_Request: receiveFileMap.insert(fileId, *pMessage); pMessage->addData(XML_TEMPID, tempId); if(autoFile) { htmlMsg.replace("%links%", tr("Accepted")); if(!bReload) fileOperation(fileId, acceptOp, fileType); } else { htmlMsg.replace("%links%", "<a href='wavr://" + fileType + "/" + acceptOp + "/" + fileId + "'>" + tr("Accept") + "</a> " + "<a href='wavr://" + fileType + "/" + declineOp + "/" + fileId + "'>" + tr("Decline") + "</a>"); } break; case FO_Cancel: case FO_Accept: case FO_Decline: case FO_Error: case FO_Abort: case FO_Complete: szStatus = getFileStatusMessage(FM_Receive, fileOp); htmlMsg.replace("%links%", szStatus); break; default: return; break; } } QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); body.appendInside(htmlMsg); }