示例#1
0
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;
}
示例#2
0
bool PhpWebView::findElementByCoord(QWebElement & root, QPoint & point, QList<WebElementStruct> & list)
{
	QWebElement child = root.lastChild();
	bool isfind = false;
	while (!child.isNull())
	{
		if (findElementByCoord(child, point, list))
			isfind = true;
		child = child.previousSibling();
	}

	QString display = root.styleProperty("display", QWebElement::ComputedStyle);
	if (display != "none" && root.geometry().contains(point) && !isfind)
	{
		list.append(createWebElementStruct(root, list.count()));
		return true;
	}
	else
		return false;
}
示例#3
0
void widget_view::slot_add_data(QString data)
{
	QWebElement doc = page()->mainFrame()->documentElement();
	doc.lastChild().appendInside(data);
}
示例#4
0
// 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>"));
    }
}
示例#5
0
/* 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>"));
}