From kopete-devel Sun Sep 28 12:48:52 2008 From: =?utf-8?q?Mat=C4=9Bj_Laitl?= Date: Sun, 28 Sep 2008 12:48:52 +0000 To: kopete-devel Subject: [kopete-devel] [PATCH v1] history plugin (4.1.1): introduce Message-Id: <200809281448.52590.strohel () gmail ! com> X-MARC-Message: https://marc.info/?l=kopete-devel&m=122260617026358 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_0033Idq5hEX7QT3" --Boundary-00=_0033Idq5hEX7QT3 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, second patch from me takes Aaron's changes for history dialog and moves it= =20 further. Instead of generating custom tags in history HTML code, we= =20 generate documented HTML structure with descriptive class properties + we=20 provide default stylesheet with colored output. The stylesheet can be copied by user to it's KDEDIR and modified to it's ne= eds.=20 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=20 stylesheets as it seems more consistent. It can be moved to=20 share/apps/kopete_history/something/ should there be a need for it. Patch generated against 4.1.1, should apply to trunk too. Mat=C4=9Bj Laitl --Boundary-00=_0033Idq5hEX7QT3 Content-Type: text/x-patch; charset="utf-8"; name="kopete-historyplugin.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kopete-historyplugin.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: + * + * + * + * + * "; + * + * + *

Sat Sep 27 2008

+ * + *

20:45:34 Bob: Hi!

+ *

20:45:34 Alice: Hi Bob.

+ * + *

20:45:34 Bob: I'm just trying my second account.

+ * + * +***/ +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 = ""; + QString stylesheet = KStandardDirs::locate("appdata", "historystyles/default.css"); + mHtmlPart->begin(); - htmlCode = "" + fontStyle + ""; + htmlCode = "" + fontStyle + ""; mHtmlPart->write( QString::fromLatin1( htmlCode.toLatin1() ) ); mHtmlPart->end(); @@ -329,10 +331,11 @@ void HistoryDialog::setMessages(QList msgs) QString::fromLatin1("ltr")); QString accountLabel; - QString resultHTML = "" + msgs.front().timestamp().date().toString() + "
"; + 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 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 += "


"; - resultHTML += "" + msg.from()->account()->accountLabel() + "
"; + 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 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 = "%1 %3 %4"; - resultHTML += messageTemplate.arg( msg.timestamp().time().toString(), - fontColor, name, body ); + QString messageTemplate = "%1 %2: %3"; + 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*/) --Boundary-00=_0033Idq5hEX7QT3 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kopete-devel mailing list kopete-devel@kde.org https://mail.kde.org/mailman/listinfo/kopete-devel --Boundary-00=_0033Idq5hEX7QT3--