[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:16:18 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=9535a74

The following commit has been merged in the master branch:
commit 9535a741d378a9372b6124bdc0c918b890144a92
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Mon Aug 23 19:24:45 2010 +0000

    Correctly replace %time% in message templates using KLocale for
    formatting
    
    svn path=/trunk/playground/network/telepathy-chat-handler/; revision=1167147
---
 lib/chatview.cpp | 40 ++++++++++++++++++++++++++++++++++++----
 lib/chatview.h   |  2 ++
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/lib/chatview.cpp b/lib/chatview.cpp
index 060a356..01f79d6 100644
--- a/lib/chatview.cpp
+++ b/lib/chatview.cpp
@@ -51,7 +51,7 @@ ChatView::ChatView(QWidget *parent) :
     QString chatStyleName = appearanceConfig.readEntry("styleName", "Renkoo.AdiumMessageStyle");
     m_chatStyle = ChatWindowStyleManager::self()->getValidStyleFromPool(chatStyleName);
 
-    if (!m_chatStyle->isValid()) {
+    if (m_chatStyle == 0 || !m_chatStyle->isValid()) {
         KMessageBox::error(this, "Failed to load a valid Kopete theme. Please make sure you run the chat window configuration program first.");
     }
 
@@ -87,7 +87,7 @@ void ChatView::initialise(const TelepathyChatInfo &chatInfo)
     } //otherwise leave as blank.
 
     templateHtml.replace("%baseRef%", m_chatStyle->getStyleBaseHref());
-    templateHtml.replace("%extraStyleCode%", ""); // FIXME once we get some font from the config file, put it here
+    templateHtml.replace("%extraStyleCode%", ""); // FIXME once we get some font/background from the config file, put it here
     templateHtml.replace("%variant%", m_variantPath);
     templateHtml.replace("%header%", headerHtml);
     templateHtml.replace("%footer%", m_chatStyle->getFooterHtml());
@@ -178,9 +178,18 @@ void ChatView::addMessage(TelepathyChatMessageInfo & message)
     styleHtml.replace("%message%", messageHtml);
     styleHtml.replace("%messageDirection%", message.messageDirection());
     styleHtml.replace("%sender%", message.senderDisplayName()); // FIXME sender is complex: not always this
-    styleHtml.replace("%time%", message.time().toString());
+    styleHtml.replace("%time%", KGlobal::locale()->formatTime(message.time().time(), true));
     styleHtml.replace("%userIconPath%", "Outgoing/buddy_icon.png");// this fallback should be done in the messageinfo
 
+    // Look for %time{X}%
+    QRegExp timeRegExp("%time\{([^}]*)\}%");
+    int pos=0;
+    while( (pos=timeRegExp.indexIn(styleHtml , pos) ) != -1 )
+    {
+            QString timeKeyword = formatTime( timeRegExp.cap(1), message.time() );
+            styleHtml.replace( pos , timeRegExp.cap(0).length() , timeKeyword );
+    }
+
     if (consecutiveMessage) {
         appendNextMessage(styleHtml);
     } else {
@@ -197,9 +206,10 @@ QString ChatView::replaceHeaderKeywords(QString htmlTemplate, const TelepathyCha
     htmlTemplate.replace("%destinationDisplayName%", info.destinationDisplayName());
     htmlTemplate.replace("%incomingIconPath%", info.incomingIconPath().toString());
     htmlTemplate.replace("%outgoingIconPath%", info.outgoingIconPath().toString());
-    htmlTemplate.replace("%timeOpened%", info.timeOpened().toString()); //FIXME use KLocale to get format.
+    htmlTemplate.replace("%timeOpened%", KGlobal::locale()->formatDateTime(info.timeOpened()));
     //FIXME time fields - remember to do both, steal the complicated one from Kopete code.
 
+
     return htmlTemplate;
 }
 
@@ -216,3 +226,25 @@ void ChatView::appendNextMessage(QString html)
     QString js = QString("appendNextMessage(\"%1\");false;").arg(html.replace('"', "\\"").replace('
', ""));
     page()->mainFrame()->evaluateJavaScript(js);
 }
+
+
+//taken from Kopete code
+QString ChatView::formatTime(const QString &_timeFormat, const QDateTime &dateTime)
+{
+        char buffer[256];
+#ifdef Q_WS_WIN
+        QString timeFormat = _timeFormat;
+        // some formats are not supported on windows (gnu extension?)
+        timeFormat = timeFormat.replace(QLatin1String("%e"), QLatin1String("%d"));
+        timeFormat = timeFormat.replace(QLatin1String("%T"), QLatin1String("%H:%M:%S"));
+#else
+        const QString timeFormat = _timeFormat;
+#endif
+        // Get current time
+        time_t timeT = dateTime.toTime_t();
+        // Convert it to local time representation.
+        struct tm* loctime = localtime (&timeT);
+        strftime (buffer, 256, timeFormat.toAscii(), loctime);
+
+        return QString(buffer);
+}
diff --git a/lib/chatview.h b/lib/chatview.h
index 2920b71..7100e12 100644
--- a/lib/chatview.h
+++ b/lib/chatview.h
@@ -60,6 +60,8 @@ private:
     QString replaceHeaderKeywords(QString htmlTemplate, const TelepathyChatInfo&);
     //QString replaceMessageKeywords(QString htmlTemplate, const TelepathyChatMessageInfo&);
 
+    QString formatTime(const QString&, const QDateTime&);
+
     TelepathyChatInfo m_chatInfo;
 
     QString lastSender;

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list