[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kopete-devel
Subject:    [kopete-devel] [PATCH v1] history plugin (4.1.1): introduce
From:       Matěj_Laitl <strohel () gmail ! com>
Date:       2008-09-28 12:48:52
Message-ID: 200809281448.52590.strohel () gmail ! com
[Download RAW message or body]

Hi,
second patch from me takes Aaron's changes for history dialog and moves it 
further. Instead of generating custom <font> tags in history HTML code, we 
generate documented HTML structure with descriptive class properties + we 
provide default stylesheet with colored output.

The stylesheet can be copied by user to it's KDEDIR and modified to it's needs. 
In future we may ship more styles and provide gui for changing them.

Note: I chose share/apps/kopete/historystyles/ as a directory for history 
stylesheets as it seems more consistent. It can be moved to 
share/apps/kopete_history/something/ should there be a need for it.

Patch generated against 4.1.1, should apply to trunk too.

Matěj Laitl

["kopete-historyplugin.patch" (text/x-patch)]

diff --git a/kopete/plugins/history/CMakeLists.txt \
b/kopete/plugins/history/CMakeLists.txt index cd21f36..3129e36 100644
--- a/kopete/plugins/history/CMakeLists.txt
+++ b/kopete/plugins/history/CMakeLists.txt
@@ -48,6 +48,7 @@ install(TARGETS kcm_kopete_history  DESTINATION \
${PLUGIN_INSTALL_DIR})  install( FILES historyconfig.kcfg  DESTINATION \
${KCFG_INSTALL_DIR})  install( FILES kopete_history.desktop  DESTINATION \
${SERVICES_INSTALL_DIR})  install( FILES historyui.rc  historychatui.rc  \
DESTINATION ${DATA_INSTALL_DIR}/kopete_history) +install( FILES default.css \
DESTINATION ${DATA_INSTALL_DIR}/kopete/historystyles)  install( FILES \
kopete_history_config.desktop  DESTINATION \
${SERVICES_INSTALL_DIR}/kconfiguredialog)  
 
diff --git a/kopete/plugins/history/default.css \
b/kopete/plugins/history/default.css new file mode 100644
index 0000000..07300c5
--- /dev/null
+++ b/kopete/plugins/history/default.css
@@ -0,0 +1,43 @@
+/**
+ * This is the default stylesheet for kopete history view.
+ * The HTML layout looks like this:
+ *
+ * <body>
+ *   <head>
+ *     <link rel='stylesheet' type='text/css' href='[path_to_this_file]' \
/> + *     <style>
+ *       .hf {
+ *         font-size: [font_size_set_in_config];
+ *         font-family: [font_from_config];
+ *         color: [color_from_config];
+ *       }
+ *     </style>";
+ *   </head>
+ *   <body class="hf">
+ *     <p class="date">Sat Sep 27 2008</p>
+ *     <p class="account">you@network.tld</p>
+ *     <p class="message outbound"><span \
class='time'>20:45:34</span>&nbsp;<span class='name'>Bob</span>: <span \
class='text'>Hi!</span></p> + *     <p class="message inbound"><span \
class='time'>20:45:34</span>&nbsp;<span class='name'>Alice</span>: <span \
class='text'>Hi Bob.</span></p> + *     <p class="account \
newaccount">second@account.org</p> + *     <p class="message \
outbound"><span class='time'>20:45:34</span>&nbsp;<span \
class='name'>Bob</span>: <span class='text'>I'm just trying my second \
account.</span></p> + *   </body>
+ * </html>
+***/
+p {
+	margin: 0; }
+.date {
+	color: #ff0000;
+	font-weight: bold; }
+.account {
+	color: #0000ff;
+	font-weight: bold; }
+.newaccount {
+	margin-top: 2em; }
+.message .time {
+	color: #808080; }
+.message .name {
+	font-weight: bold }
+.inbound .name {
+	color: #008000; }
+.outbound .name {
+	color: #000080; }
diff --git a/kopete/plugins/history/historydialog.cpp \
b/kopete/plugins/history/historydialog.cpp index 569c5b0..8946a93 100644
--- a/kopete/plugins/history/historydialog.cpp
+++ b/kopete/plugins/history/historydialog.cpp
@@ -147,8 +147,10 @@ HistoryDialog::HistoryDialog(Kopete::MetaContact *mc, \
QWidget* parent)  QTextStream( &fontSize ) << \
Kopete::AppearanceSettings::self()->chatFont().pointSize();  fontStyle = \
"<style>.hf { font-size:" + fontSize + ".0pt; font-family:" + \
Kopete::AppearanceSettings::self()->chatFont().family() + "; color: " + \
Kopete::AppearanceSettings::self()->chatTextColor().name() + "; }</style>"; \
 +	QString stylesheet = KStandardDirs::locate("appdata", \
"historystyles/default.css"); +
 	mHtmlPart->begin();
-	htmlCode = "<html><head>" + fontStyle + "</head><body \
class=\"hf\"></body></html>"; +	htmlCode = "<html><head><link \
rel='stylesheet' type='text/css' href='" + stylesheet + "' />" + fontStyle \
+ "</head><body class=\"hf\"></body></html>";  mHtmlPart->write( \
QString::fromLatin1( htmlCode.toLatin1() ) );  mHtmlPart->end();
 
@@ -329,10 +331,11 @@ void \
HistoryDialog::setMessages(QList<Kopete::Message> msgs)  \
QString::fromLatin1("ltr"));  
 	QString accountLabel;
-	QString resultHTML = "<b><font color=\"red\">" + \
msgs.front().timestamp().date().toString() + "</font></b><br/>"; +	QString \
resultHTML = msgs.front().timestamp().date().toString();  
-	DOM::HTMLElement newNode = \
mHtmlPart->document().createElement(QString::fromLatin1("span")); \
+	DOM::HTMLElement newNode = \
mHtmlPart->document().createElement(QString::fromLatin1("p"));  \
newNode.setAttribute(QString::fromLatin1("dir"), dir); \
+	newNode.setAttribute(QString::fromLatin1("class"), \
QString::fromLatin1("date"));  newNode.setInnerHTML(resultHTML);
 	mHtmlPart->htmlDocument().body().appendChild(newNode);
 
@@ -343,18 +346,22 @@ void \
HistoryDialog::setMessages(QList<Kopete::Message> msgs)  || ( \
mMainWidget->messageFilterBox->currentIndex() == 1 && msg.direction() == \
Kopete::Message::Inbound )  || ( \
mMainWidget->messageFilterBox->currentIndex() == 2 && msg.direction() == \
Kopete::Message::Outbound ) )  {
-			resultHTML.clear();
-
 			if (accountLabel.isEmpty() || accountLabel != \
msg.from()->account()->accountLabel())  // If the message's account is new, \
just specify it to the user  {
-				if (!accountLabel.isEmpty())
-					resultHTML += "<br/><br/><br/>";
-				resultHTML += "<b><font color=\"blue\">" + \
msg.from()->account()->accountLabel() + "</font></b><br/>"; +				resultHTML \
= msg.from()->account()->accountLabel(); +
+				newNode = mHtmlPart->document().createElement(QString::fromLatin1("p"));
 +				newNode.setAttribute(QString::fromLatin1("dir"), dir);
+				newNode.setAttribute(QString::fromLatin1("class"),
+				                     accountLabel.isEmpty() ? \
QString::fromLatin1("account") : QString::fromLatin1("account \
newaccount")); +				newNode.setInnerHTML(resultHTML);
+
+				mHtmlPart->htmlDocument().body().appendChild(newNode);
 			}
 			accountLabel = msg.from()->account()->accountLabel();
 
-			QString body = msg.parsedBody();
+			QString body = msg.parsedBody(); // FIXME: msg.parsedBody() adds \
unnecessary newlines  
 			if (!mMainWidget->searchLine->text().isEmpty())
 			// If there is a search, then we hightlight the keywords
@@ -372,27 +379,28 @@ void \
HistoryDialog::setMessages(QList<Kopete::Message> msgs)  name = \
msg.from()->nickName();  }
 
-			QString fontColor;
+			QString msgDirection;
 			if (msg.direction() == Kopete::Message::Outbound)
 			{
-				fontColor = Kopete::AppearanceSettings::self()->chatTextColor().dark().name();
 +				msgDirection = "outbound";
 			}
 			else
 			{
-				fontColor = Kopete::AppearanceSettings::self()->chatTextColor().light(200).name();
 +				msgDirection = "inbound";
 			}
 
-			QString messageTemplate = "<b>%1&nbsp;<font \
                color=\"%2\">%3</font></b>&nbsp;%4";
-			resultHTML += messageTemplate.arg( msg.timestamp().time().toString(),
-				fontColor, name, body );
+			QString messageTemplate = "<span class='time'>%1</span>&nbsp;<span \
class='name'>%2</span>: <span class='text'>%3</span>"; +			resultHTML = \
messageTemplate.arg( msg.timestamp().time().toString(), name, body );  
-			newNode = mHtmlPart->document().createElement(QString::fromLatin1("span"));
 +			newNode = mHtmlPart->document().createElement(QString::fromLatin1("p"));
  newNode.setAttribute(QString::fromLatin1("dir"), dir);
+			newNode.setAttribute(QString::fromLatin1("class"), \
QString::fromLatin1("message ") + msgDirection);  \
newNode.setInnerHTML(resultHTML);  
 			mHtmlPart->htmlDocument().body().appendChild(newNode);
 		}
 	}
+//	kDebug(14310) << mHtmlPart->htmlDocument().toString().string(); // \
mHtml->documentSource returns empty string..  }
 
 void HistoryDialog::slotFilterChanged(int /*index*/)



_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic