[kde-doc-english] [trojita/addressbook] src/Gui: GUI: refactor address rendering into a special function

Jan Kundrát jkt at flaska.net
Fri May 24 15:35:54 UTC 2013


Git commit aaa8a78d8d2521e6076cce8aad4d55a8f10d02c6 by Jan Kundrát.
Committed on 24/05/2013 at 13:00.
Pushed by jkt into branch 'addressbook'.

GUI: refactor address rendering into a special function

M  +17   -6    src/Gui/EnvelopeView.cpp
M  +8    -0    src/Gui/EnvelopeView.h

http://commits.kde.org/trojita/aaa8a78d8d2521e6076cce8aad4d55a8f10d02c6

diff --git a/src/Gui/EnvelopeView.cpp b/src/Gui/EnvelopeView.cpp
index c88ac82..7042ac5 100644
--- a/src/Gui/EnvelopeView.cpp
+++ b/src/Gui/EnvelopeView.cpp
@@ -54,6 +54,17 @@ void EnvelopeView::setMessage(const QModelIndex &index)
     setText(headerText(index));
 }
 
+/** @short Return a HTML representation of the address list */
+QString EnvelopeView::htmlizeAddresses(const QList<Imap::Message::MailAddress> &addresses)
+{
+    Q_ASSERT(!addresses.isEmpty());
+    QStringList buf;
+    Q_FOREACH(const Imap::Message::MailAddress &addr, addresses) {
+        buf << addr.prettyName(Imap::Message::MailAddress::FORMAT_CLICKABLE);
+    }
+    return buf.join(QLatin1String(", "));
+}
+
 QString EnvelopeView::headerText(const QModelIndex &index)
 {
     if (!index.isValid())
@@ -63,11 +74,11 @@ QString EnvelopeView::headerText(const QModelIndex &index)
 
     QString res;
     if (!e.from.isEmpty())
-        res += tr("<b>From:</b> %1<br/>").arg(Imap::Message::MailAddress::prettyList(e.from, Imap::Message::MailAddress::FORMAT_CLICKABLE));
+        res += tr("<b>From:</b> %1<br/>").arg(htmlizeAddresses(e.from));
     if (!e.sender.isEmpty() && e.sender != e.from)
-        res += tr("<b>Sender:</b> %1<br/>").arg(Imap::Message::MailAddress::prettyList(e.sender, Imap::Message::MailAddress::FORMAT_CLICKABLE));
+        res += tr("<b>Sender:</b> %1<br/>").arg(htmlizeAddresses(e.sender));
     if (!e.replyTo.isEmpty() && e.replyTo != e.from)
-        res += tr("<b>Reply-To:</b> %1<br/>").arg(Imap::Message::MailAddress::prettyList(e.replyTo, Imap::Message::MailAddress::FORMAT_CLICKABLE));
+        res += tr("<b>Reply-To:</b> %1<br/>").arg(htmlizeAddresses(e.replyTo));
     QVariantList headerListPost = index.data(Imap::Mailbox::RoleMessageHeaderListPost).toList();
     if (!headerListPost.isEmpty()) {
         QStringList buf;
@@ -95,11 +106,11 @@ QString EnvelopeView::headerText(const QModelIndex &index)
         res += tr("<b>List-Post:</b> %1<br/>").arg(buf.join(tr(", ")));
     }
     if (!e.to.isEmpty())
-        res += tr("<b>To:</b> %1<br/>").arg(Imap::Message::MailAddress::prettyList(e.to, Imap::Message::MailAddress::FORMAT_CLICKABLE));
+        res += tr("<b>To:</b> %1<br/>").arg(htmlizeAddresses(e.to));
     if (!e.cc.isEmpty())
-        res += tr("<b>Cc:</b> %1<br/>").arg(Imap::Message::MailAddress::prettyList(e.cc, Imap::Message::MailAddress::FORMAT_CLICKABLE));
+        res += tr("<b>Cc:</b> %1<br/>").arg(htmlizeAddresses(e.cc));
     if (!e.bcc.isEmpty())
-        res += tr("<b>Bcc:</b> %1<br/>").arg(Imap::Message::MailAddress::prettyList(e.bcc, Imap::Message::MailAddress::FORMAT_CLICKABLE));
+        res += tr("<b>Bcc:</b> %1<br/>").arg(htmlizeAddresses(e.bcc));
 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
     res += tr("<b>Subject:</b> %1").arg(Qt::escape(e.subject));
 #else
diff --git a/src/Gui/EnvelopeView.h b/src/Gui/EnvelopeView.h
index 142eb81..1ae4651 100644
--- a/src/Gui/EnvelopeView.h
+++ b/src/Gui/EnvelopeView.h
@@ -25,6 +25,12 @@
 #include <QModelIndex>
 #include <QLabel>
 
+namespace Imap {
+namespace Message {
+class MailAddress;
+}
+}
+
 namespace Gui {
 
 class MessageView;
@@ -46,6 +52,8 @@ private slots:
 private:
     QString headerText(const QModelIndex &index);
 
+    QString htmlizeAddresses(const QList<Imap::Message::MailAddress> &addresses);
+
     EnvelopeView(const EnvelopeView &); // don't implement
     EnvelopeView &operator=(const EnvelopeView &); // don't implement
 };



More information about the kde-doc-english mailing list