[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:21:36 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=0083f90
The following commit has been merged in the master branch:
commit 0083f909db99968f1bafbdbc744bc50cfb4cc3d6
Author: Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
Date: Wed Mar 21 00:12:20 2012 +0100
Better handling when appending messages
---
lib/adium-theme-view.cpp | 131 +++++++++++++++++++++++++++++++++++------------
lib/adium-theme-view.h | 21 +++++++-
2 files changed, 117 insertions(+), 35 deletions(-)
diff --git a/lib/adium-theme-view.cpp b/lib/adium-theme-view.cpp
index 4178606..4f9d82e 100644
--- a/lib/adium-theme-view.cpp
+++ b/lib/adium-theme-view.cpp
@@ -297,17 +297,19 @@ void AdiumThemeView::addContentMessage(const AdiumThemeContentInfo &contentMessa
{
QString styleHtml;
bool consecutiveMessage = false;
+ bool willAddMoreContentObjects = false; // TODO Find out how this is used in Adium
+ bool replaceLastContent = false; // TODO use this
+
// contentMessage is const, we need a non-const one to append message classes
AdiumThemeContentInfo message(contentMessage);
if (m_lastContent.senderScreenName() == message.senderScreenName()
- && m_lastContent.type() == message.type() )
- {
- // TODO check if adding the "consecutive" class is a problem for themes
- // with disableCombineConsecutive = true
+ && m_lastContent.type() == message.type()
+ && !m_chatStyle->disableCombineConsecutive()) {
consecutiveMessage = true;
message.appendMessageClass(QLatin1String("consecutive"));
}
+
m_lastContent = message;
switch (message.type()) {
@@ -345,27 +347,29 @@ void AdiumThemeView::addContentMessage(const AdiumThemeContentInfo &contentMessa
replaceContentKeywords(styleHtml, message);
- if (consecutiveMessage && !m_chatStyle->disableCombineConsecutive()) {
- appendNextMessage(styleHtml);
- } else {
- appendNewMessage(styleHtml);
- }
+ AppendMode mode = appendMode(message,
+ consecutiveMessage,
+ willAddMoreContentObjects,
+ replaceLastContent);
+
+ appendMessage(styleHtml, mode);
}
void AdiumThemeView::addStatusMessage(const AdiumThemeStatusInfo& statusMessage)
{
QString styleHtml;
bool consecutiveMessage = false;
+ bool willAddMoreContentObjects = false; // TODO Find out how this is used in Adium
+ bool replaceLastContent = false; // TODO use this
+
// statusMessage is const, we need a non-const one to append message classes
AdiumThemeStatusInfo message(statusMessage);
- if (m_lastContent.type() == message.type())
- {
+ if (m_lastContent.type() == message.type() && !m_chatStyle->disableCombineConsecutive()) {
consecutiveMessage = true;
- // TODO check if adding the "consecutive" class is a problem for themes
- // with disableCombineConsecutive = true
message.appendMessageClass(QLatin1String("consecutive"));
}
+
m_lastContent = AdiumThemeContentInfo(statusMessage.type());
switch (message.type()) {
@@ -381,11 +385,89 @@ void AdiumThemeView::addStatusMessage(const AdiumThemeStatusInfo& statusMessage)
replaceStatusKeywords(styleHtml, message);
- if (consecutiveMessage && !m_chatStyle->disableCombineConsecutive()) {
- appendNextMessage(styleHtml);
+ AppendMode mode = appendMode(message,
+ consecutiveMessage,
+ willAddMoreContentObjects,
+ replaceLastContent);
+
+ appendMessage(styleHtml, mode);
+}
+
+QString AdiumThemeView::appendScript(AdiumThemeView::AppendMode mode)
+{
+ //by making the JS return false evaluateJavaScript is a _lot_ faster, as it has nothing to convert to QVariant.
+ //escape quotes, and merge HTML onto one line.
+ switch (mode) {
+ case AppendMessageWithScroll:
+ kDebug() << "AppendMessageWithScroll";
+ return QLatin1String("checkIfScrollToBottomIsNeeded(); appendMessage(\"%1\"); scrollToBottomIfNeeded(); false;");
+ case AppendNextMessageWithScroll:
+ kDebug() << "AppendNextMessageWithScroll";
+ return QLatin1String("checkIfScrollToBottomIsNeeded(); appendNextMessage(\"%1\"); scrollToBottomIfNeeded(); false;");
+ case AppendMessage:
+ kDebug() << "AppendMessage";
+ return QLatin1String("appendMessage(\"%1\"); false;");
+ case AppendNextMessage:
+ kDebug() << "AppendNextMessage";
+ return QLatin1String("appendNextMessage(\"%1\"); false;");
+ case AppendMessageNoScroll:
+ kDebug() << "AppendMessageNoScroll";
+ return QLatin1String("appendMessageNoScroll(\"%1\"); false;");
+ case AppendNextMessageNoScroll:
+ kDebug() << "AppendNextMessageNoScroll";
+ return QLatin1String("appendNextMessageNoScroll(\"%1\"); false;");
+ case ReplaceLastMessage:
+ kDebug() << "ReplaceLastMessage";
+ return QLatin1String("replaceLastMessage(\"%1\"); false");
+ default:
+ kWarning() << "Unhandled append mode!";
+ return QLatin1String("%1");
+ }
+}
+
+AdiumThemeView::AppendMode AdiumThemeView::appendMode(const AdiumThemeMessageInfo &message,
+ bool consecutive,
+ bool willAddMoreContentObjects, // TODO Find out how this is used in Adium
+ bool replaceLastContent)
+{
+ AdiumThemeView::AppendMode mode = AppendModeError;
+ // scripts vary by style version
+ if (!m_chatStyle->hasCustomTemplateHtml() && m_chatStyle->messageViewVersion() >= 4) {
+ // If we're using the built-in template HTML, we know that it supports our most modern scripts
+ if (replaceLastContent)
+ mode = ReplaceLastMessage;
+ else if (willAddMoreContentObjects) {
+ mode = (consecutive ? AppendNextMessageNoScroll : AppendMessageNoScroll);
+ } else {
+ mode = (consecutive ? AppendNextMessage : AppendMessage);
+ }
+ } else if (m_chatStyle->messageViewVersion() >= 3) {
+ if (willAddMoreContentObjects) {
+ mode = (consecutive ? AppendNextMessageNoScroll : AppendMessageNoScroll);
+ } else {
+ mode = (consecutive ? AppendNextMessage : AppendMessage);
+ }
+ } else if (m_chatStyle->messageViewVersion() >= 1) {
+ mode = (consecutive ? AppendNextMessage : AppendMessage);
+ } else if (m_chatStyle->hasCustomTemplateHtml() && (message.type() == AdiumThemeContentInfo::Status ||
+ message.type() == AdiumThemeContentInfo::HistoryStatus)) {
+ // Old styles with a custom template.html had Status.html files without 'insert' divs coupled
+ // with a APPEND_NEXT_MESSAGE_WITH_SCROLL script which assumes one exists.
+ mode = AppendMessageWithScroll;
} else {
- appendNewMessage(styleHtml);
+ mode = (consecutive ? AppendNextMessageWithScroll : AppendMessageWithScroll);
}
+
+ return mode;
+}
+
+void AdiumThemeView::appendMessage(QString &html, AppendMode mode)
+{
+ QString js = appendScript(mode).arg(html.replace(QLatin1Char('\'), QLatin1String("\\"))
+ .replace(QLatin1Char('\"'), QLatin1String("\\""))
+ .replace(QLatin1Char('
'), QLatin1String(""))
+ .replace(QLatin1Char('
'), QLatin1String("<br>")));
+ page()->mainFrame()->evaluateJavaScript(js);
}
void AdiumThemeView::onLinkClicked(const QUrl &url)
@@ -480,23 +562,6 @@ QString AdiumThemeView::replaceMessageKeywords(QString &htmlTemplate, const Adiu
return htmlTemplate;
}
-void AdiumThemeView::appendNewMessage(QString &html)
-{
- //by making the JS return false evaluateJavaScript is a _lot_ faster, as it has nothing to convert to QVariant.
- //escape quotes, and merge HTML onto one line.
- QString js = QString(QLatin1String("appendMessage(\"%1\");false;")).arg(html.replace(QLatin1Char('"'),
- QLatin1String("\\"")).replace(QLatin1Char('
'), QLatin1String("")));
- page()->mainFrame()->evaluateJavaScript(js);
-}
-
-void AdiumThemeView::appendNextMessage(QString &html)
-{
- QString js = QString(QLatin1String("appendNextMessage(\"%1\");false;")).arg(html.replace(QLatin1Char('"'),
- QLatin1String("\\"")).replace(QLatin1Char('
'), QLatin1String("")));
- page()->mainFrame()->evaluateJavaScript(js);
-}
-
-
//taken from Kopete code
QString AdiumThemeView::formatTime(const QString &timeFormat, const QDateTime &dateTime)
{
diff --git a/lib/adium-theme-view.h b/lib/adium-theme-view.h
index 885be8d..747a8ef 100644
--- a/lib/adium-theme-view.h
+++ b/lib/adium-theme-view.h
@@ -48,6 +48,17 @@ public:
SingleUserChat
};
+ enum AppendMode {
+ AppendModeError = 0,
+ AppendMessageWithScroll,
+ AppendNextMessageWithScroll,
+ AppendMessage,
+ AppendNextMessage,
+ AppendMessageNoScroll,
+ AppendNextMessageNoScroll,
+ ReplaceLastMessage
+ };
+
explicit AdiumThemeView(QWidget *parent = 0);
/** Loads the Theme data*/
@@ -91,6 +102,14 @@ private:
bool m_useCustomFont;
QString m_fontFamily;
int m_fontSize;
+
+ QString appendScript(AppendMode mode);
+ AppendMode appendMode(const AdiumThemeMessageInfo &message,
+ bool consecutive,
+ bool willAddMoreContentObjects,
+ bool replaceLastContent);
+ void appendMessage(QString&, AppendMode mode);
+
QString replaceHeaderKeywords(QString htmlTemplate, const AdiumThemeHeaderInfo&);
QString replaceContentKeywords(QString& htmlTemplate, const AdiumThemeContentInfo&);
QString replaceStatusKeywords(QString& htmlTemplate, const AdiumThemeStatusInfo&);
@@ -103,8 +122,6 @@ private:
bool m_displayHeader;
KAction *m_openLinkAction;
- void appendNewMessage(QString&);
- void appendNextMessage(QString&);
bool m_webInspector;
};
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list