[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:20:47 UTC 2016


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

The following commit has been merged in the master branch:
commit 4a827aad07d45beb10852a2c4fceb953ccfee2a1
Author: Lasath Fernando <kde at lasath.org>
Date:   Sun Nov 13 00:14:30 2011 +1100

    Tidied code
---
 lib/chat-window-style.cpp                 | 314 +++++++++++++++---------------
 lib/conversation-model.cpp                | 160 +++++++--------
 lib/conversation-watcher.cpp              |  98 +++++++---
 lib/conversation-watcher.h                |  15 +-
 lib/conversation.cpp                      |  28 +--
 lib/conversation.h                        |   9 +-
 lib/{conversation.cpp => qml-plugins.cpp} |  37 +---
 lib/{conversation.cpp => qml-plugins.h}   |  35 +---
 lib/qmldir                                |   1 +
 plasmoid/CMakeLists.txt                   |   1 +
 plasmoid/contents/ui/main.qml             |  19 ++
 plasmoid/metadata.desktop                 |  23 +++
 12 files changed, 398 insertions(+), 342 deletions(-)

diff --git a/lib/chat-window-style.cpp b/lib/chat-window-style.cpp
index 7b770cf..1666b42 100644
--- a/lib/chat-window-style.cpp
+++ b/lib/chat-window-style.cpp
@@ -45,40 +45,40 @@ public:
     QHash<QString, bool> compactVariants;
 };
 
-ChatWindowStyle::ChatWindowStyle(const QString &styleId, StyleBuildMode styleBuildMode)
-    : QObject(), d(new Private)
+ChatWindowStyle::ChatWindowStyle ( const QString &styleId, StyleBuildMode styleBuildMode )
+        : QObject(), d ( new Private )
 {
-    init(styleId, styleBuildMode);
+    init ( styleId, styleBuildMode );
 }
 
-ChatWindowStyle::ChatWindowStyle(const QString &styleId, const QString &variantPath,
-                                 StyleBuildMode styleBuildMode)
-    : QObject(), d(new Private)
+ChatWindowStyle::ChatWindowStyle ( const QString &styleId, const QString &variantPath,
+                                   StyleBuildMode styleBuildMode )
+        : QObject(), d ( new Private )
 {
-    Q_UNUSED(variantPath);
-    init(styleId, styleBuildMode);
+    Q_UNUSED ( variantPath );
+    init ( styleId, styleBuildMode );
 }
 
-void ChatWindowStyle::init(const QString &styleId, StyleBuildMode styleBuildMode)
+void ChatWindowStyle::init ( const QString &styleId, StyleBuildMode styleBuildMode )
 {
-    QStringList styleDirs = KGlobal::dirs()->findDirs("data",
-        QString(QLatin1String("ktelepathy/styles/%1/Contents/Resources/")).arg(styleId)
-    );
+    QStringList styleDirs = KGlobal::dirs()->findDirs ( "data",
+                            QString ( QLatin1String ( "ktelepathy/styles/%1/Contents/Resources/" ) ).arg ( styleId )
+                                                      );
 
-    if (styleDirs.isEmpty()) {
+    if ( styleDirs.isEmpty() ) {
         kDebug() << "Failed to find style" << styleId;
         return;
     }
     d->styleId = styleId;
-    if (styleDirs.count() > 1) {
+    if ( styleDirs.count() > 1 ) {
         kDebug() << "found several styles with the same name. using first";
     }
-    d->baseHref = styleDirs.at(0);
+    d->baseHref = styleDirs.at ( 0 );
     kDebug() << "Using style:" << d->baseHref;
     readStyleFiles();
-    if (styleBuildMode & StyleBuildNormal) {
+    if ( styleBuildMode & StyleBuildNormal ) {
         listVariants();
-        if(d->defaultVariantName.isEmpty() && !d->variantsList.isEmpty()) {
+        if ( d->defaultVariantName.isEmpty() && !d->variantsList.isEmpty() ) {
             d->defaultVariantName = d->variantsList.keys().first();
         }
     }
@@ -93,21 +93,21 @@ ChatWindowStyle::~ChatWindowStyle()
 bool ChatWindowStyle::isValid() const
 {
     kDebug();
-    bool statusHtml = !content(Status).isEmpty();
-    bool fileTransferIncomingHtml = !content(FileTransferIncoming).isEmpty();
-    bool nextIncomingHtml = !content(IncomingNext).isEmpty();
-    bool incomingHtml = !content(Incoming).isEmpty();
-    bool nextOutgoingHtml = !content(OutgoingNext).isEmpty();
-    bool outgoingHtml = !content(Outgoing).isEmpty();
+    bool statusHtml = !content ( Status ).isEmpty();
+    bool fileTransferIncomingHtml = !content ( FileTransferIncoming ).isEmpty();
+    bool nextIncomingHtml = !content ( IncomingNext ).isEmpty();
+    bool incomingHtml = !content ( Incoming ).isEmpty();
+    bool nextOutgoingHtml = !content ( OutgoingNext ).isEmpty();
+    bool outgoingHtml = !content ( Outgoing ).isEmpty();
 
-    return (statusHtml && fileTransferIncomingHtml && nextIncomingHtml
-            && incomingHtml && nextOutgoingHtml  && outgoingHtml);
+    return ( statusHtml && fileTransferIncomingHtml && nextIncomingHtml
+             && incomingHtml && nextOutgoingHtml  && outgoingHtml );
 }
 
 ChatWindowStyle::StyleVariants ChatWindowStyle::getVariants()
 {
     // If the variantList is empty, list available variants.
-    if (d->variantsList.isEmpty()) {
+    if ( d->variantsList.isEmpty() ) {
         listVariants();
     }
     return d->variantsList;
@@ -141,164 +141,163 @@ QString ChatWindowStyle::getStyleBaseHref() const
 
 bool ChatWindowStyle::hasHeader() const
 {
-    return ! content(Header).isEmpty();
+    return ! content ( Header ).isEmpty();
 }
 
 QString ChatWindowStyle::getTemplateHtml() const
 {
-    return content(Template);
+    return content ( Template );
 }
 
 QString ChatWindowStyle::getHeaderHtml() const
 {
-    return content(Header);
+    return content ( Header );
 }
 
 QString ChatWindowStyle::getFooterHtml() const
 {
-    return content(Footer);
+    return content ( Footer );
 }
 
 QString ChatWindowStyle::getIncomingHtml() const
 {
-    return content(Incoming);
+    return content ( Incoming );
 }
 
 QString ChatWindowStyle::getNextIncomingHtml() const
 {
-    return content(IncomingNext);
+    return content ( IncomingNext );
 }
 
 QString ChatWindowStyle::getOutgoingHtml() const
 {
-    return content(Outgoing);
+    return content ( Outgoing );
 }
 
 QString ChatWindowStyle::getNextOutgoingHtml() const
 {
-    return content(OutgoingNext);
+    return content ( OutgoingNext );
 }
 
 QString ChatWindowStyle::getStatusHtml() const
 {
-    return content(Status);
+    return content ( Status );
 }
 
 QString ChatWindowStyle::getHistoryIncomingHtml() const
 {
-    return content(HistoryIncoming);
+    return content ( HistoryIncoming );
 }
 
 QString ChatWindowStyle::getHistoryNextIncomingHtml() const
 {
-    return content(HistoryIncomingNext);
+    return content ( HistoryIncomingNext );
 }
 
 QString ChatWindowStyle::getHistoryOutgoingHtml() const
 {
-    return content(HistoryOutgoing);
+    return content ( HistoryOutgoing );
 }
 
 QString ChatWindowStyle::getHistoryNextOutgoingHtml() const
 {
-    return content(HistoryOutgoingNext);
+    return content ( HistoryOutgoingNext );
 }
 
 QString ChatWindowStyle::getActionIncomingHtml() const
 {
-    return content(ActionIncoming);
+    return content ( ActionIncoming );
 }
 
 QString ChatWindowStyle::getActionOutgoingHtml() const
 {
-    return content(ActionOutgoing);
+    return content ( ActionOutgoing );
 }
 
 QString ChatWindowStyle::getFileTransferIncomingHtml() const
 {
-    return content(FileTransferIncoming);
+    return content ( FileTransferIncoming );
 }
 
 QString ChatWindowStyle::getVoiceClipIncomingHtml() const
 {
-    return content(VoiceClipIncoming);
+    return content ( VoiceClipIncoming );
 }
 
 QString ChatWindowStyle::getOutgoingStateSendingHtml() const
 {
-    return content(OutgoingStateSending);
+    return content ( OutgoingStateSending );
 }
 
 QString ChatWindowStyle::getOutgoingStateSentHtml() const
 {
-    return content(OutgoingStateSent);
+    return content ( OutgoingStateSent );
 }
 
 QString ChatWindowStyle::getOutgoingStateErrorHtml() const
 {
-    return content(OutgoingStateError);
+    return content ( OutgoingStateError );
 }
 
 QString ChatWindowStyle::getOutgoingStateUnknownHtml() const
 {
-    return content(OutgoingStateUnknown);
+    return content ( OutgoingStateUnknown );
 }
 
 bool ChatWindowStyle::hasActionTemplate() const
 {
-    return (!content(ActionIncoming).isEmpty() && !content(ActionOutgoing).isEmpty());
+    return ( !content ( ActionIncoming ).isEmpty() && !content ( ActionOutgoing ).isEmpty() );
 }
 
 void ChatWindowStyle::listVariants()
 {
-    QString variantDirPath = d->baseHref + QString::fromUtf8("Variants/");
-    QDir variantDir(variantDirPath);
+    QString variantDirPath = d->baseHref + QString::fromUtf8 ( "Variants/" );
+    QDir variantDir ( variantDirPath );
 
-    QStringList variantList = variantDir.entryList(QStringList(QLatin1String("*.css")));
+    QStringList variantList = variantDir.entryList ( QStringList ( QLatin1String ( "*.css" ) ) );
     QStringList::ConstIterator it, itEnd = variantList.constEnd();
-    QLatin1String compactVersionPrefix("_compact_");
-    for (it = variantList.constBegin(); it != itEnd; ++it) {
+    QLatin1String compactVersionPrefix ( "_compact_" );
+    for ( it = variantList.constBegin(); it != itEnd; ++it ) {
         QString variantName = *it, variantPath;
         // Retrieve only the file name.
-        variantName = variantName.left(variantName.lastIndexOf(QLatin1String(".")));
-        if (variantName.startsWith(compactVersionPrefix)) {
-            if (variantName == compactVersionPrefix) {
-                d->compactVariants.insert(QLatin1String(""), true);
+        variantName = variantName.left ( variantName.lastIndexOf ( QLatin1String ( "." ) ) );
+        if ( variantName.startsWith ( compactVersionPrefix ) ) {
+            if ( variantName == compactVersionPrefix ) {
+                d->compactVariants.insert ( QLatin1String ( "" ), true );
             }
             continue;
         }
         QString compactVersionFilename = *it;
-        QString compactVersionPath = variantDirPath + compactVersionFilename.prepend(compactVersionPrefix);
-        if (QFile::exists(compactVersionPath)) {
-            d->compactVariants.insert(variantName, true);
+        QString compactVersionPath = variantDirPath + compactVersionFilename.prepend ( compactVersionPrefix );
+        if ( QFile::exists ( compactVersionPath ) ) {
+            d->compactVariants.insert ( variantName, true );
         }
         // variantPath is relative to baseHref.
-        variantPath = QString(QLatin1String("Variants/%1")).arg(*it);
-        d->variantsList.insert(variantName, variantPath);
+        variantPath = QString ( QLatin1String ( "Variants/%1" ) ).arg ( *it );
+        d->variantsList.insert ( variantName, variantPath );
     }
 }
 
-void ChatWindowStyle::setContent(InternalIdentifier id, const QString& content)
+void ChatWindowStyle::setContent ( InternalIdentifier id, const QString& content )
 {
-    d->templateContents.insert( id, content );
+    d->templateContents.insert ( id, content );
 }
 
-QString ChatWindowStyle::content(InternalIdentifier id) const
+QString ChatWindowStyle::content ( InternalIdentifier id ) const
 {
-    return d->templateContents.value( id );
+    return d->templateContents.value ( id );
 }
 
-void ChatWindowStyle::inheritContent(InternalIdentifier subType, InternalIdentifier superType)
+void ChatWindowStyle::inheritContent ( InternalIdentifier subType, InternalIdentifier superType )
 {
-    if (content(subType).isEmpty()) {
-        setContent(subType, content(superType));
+    if ( content ( subType ).isEmpty() ) {
+        setContent ( subType, content ( superType ) );
     }
 }
 
 
 void ChatWindowStyle::readStyleFiles()
 {
-    // load style info
     QString infoPlistFile = d->baseHref + QLatin1String("../Info.plist");
     ChatStylePlistFileReader plistReader(infoPlistFile);
     d->defaultVariantName = plistReader.defaultVariant();
@@ -307,48 +306,48 @@ void ChatWindowStyle::readStyleFiles()
 
     // specify the files for the identifiers
     QHash<InternalIdentifier, QLatin1String> templateFiles;
-    templateFiles.insert(Template, QLatin1String("Template.html"));
-    templateFiles.insert(Status, QLatin1String("Status.html"));
+    templateFiles.insert ( Template, QLatin1String ( "Template.html" ) );
+    templateFiles.insert ( Status, QLatin1String ( "Status.html" ) );
 
-    templateFiles.insert(Header, QLatin1String("Header.html"));
-    templateFiles.insert(Footer, QLatin1String("Footer.html"));
+    templateFiles.insert ( Header, QLatin1String ( "Header.html" ) );
+    templateFiles.insert ( Footer, QLatin1String ( "Footer.html" ) );
 
-    templateFiles.insert(Incoming, QLatin1String("Incoming/Content.html"));
-    templateFiles.insert(IncomingNext, QLatin1String("Incoming/NextContent.html"));
-    templateFiles.insert(Outgoing, QLatin1String("Outgoing/Content.html"));
-    templateFiles.insert(OutgoingNext, QLatin1String("Outgoing/NextContent.html"));
+    templateFiles.insert ( Incoming, QLatin1String ( "Incoming/Content.html" ) );
+    templateFiles.insert ( IncomingNext, QLatin1String ( "Incoming/NextContent.html" ) );
+    templateFiles.insert ( Outgoing, QLatin1String ( "Outgoing/Content.html" ) );
+    templateFiles.insert ( OutgoingNext, QLatin1String ( "Outgoing/NextContent.html" ) );
 
-    templateFiles.insert(HistoryIncoming, QLatin1String("Incoming/Context.html"));
-    templateFiles.insert(HistoryIncomingNext, QLatin1String("Incoming/NextContext.html"));
-    templateFiles.insert(HistoryOutgoing, QLatin1String("Outgoing/Context.html"));
-    templateFiles.insert(HistoryOutgoingNext, QLatin1String("Outgoing/NextContext.html"));
+    templateFiles.insert ( HistoryIncoming, QLatin1String ( "Incoming/Context.html" ) );
+    templateFiles.insert ( HistoryIncomingNext, QLatin1String ( "Incoming/NextContext.html" ) );
+    templateFiles.insert ( HistoryOutgoing, QLatin1String ( "Outgoing/Context.html" ) );
+    templateFiles.insert ( HistoryOutgoingNext, QLatin1String ( "Outgoing/NextContext.html" ) );
 
-    templateFiles.insert(ActionIncoming, QLatin1String("Incoming/Action.html"));
-    templateFiles.insert(ActionOutgoing, QLatin1String("Outgoing/Action.html"));
+    templateFiles.insert ( ActionIncoming, QLatin1String ( "Incoming/Action.html" ) );
+    templateFiles.insert ( ActionOutgoing, QLatin1String ( "Outgoing/Action.html" ) );
 
-    templateFiles.insert(FileTransferIncoming, QLatin1String("Incoming/FileTransferRequest.html"));
-    templateFiles.insert(VoiceClipIncoming, QLatin1String("Incoming/voiceClipRequest.html"));
+    templateFiles.insert ( FileTransferIncoming, QLatin1String ( "Incoming/FileTransferRequest.html" ) );
+    templateFiles.insert ( VoiceClipIncoming, QLatin1String ( "Incoming/voiceClipRequest.html" ) );
 
-    templateFiles.insert(OutgoingStateUnknown, QLatin1String("Outgoing/StateUnknown.html"));
-    templateFiles.insert(OutgoingStateSending, QLatin1String("Outgoing/StateSending.html"));
-    templateFiles.insert(OutgoingStateSent, QLatin1String("Outgoing/StateSent.html"));
-    templateFiles.insert(OutgoingStateError, QLatin1String("Outgoing/StateError.html"));
+    templateFiles.insert ( OutgoingStateUnknown, QLatin1String ( "Outgoing/StateUnknown.html" ) );
+    templateFiles.insert ( OutgoingStateSending, QLatin1String ( "Outgoing/StateSending.html" ) );
+    templateFiles.insert ( OutgoingStateSent, QLatin1String ( "Outgoing/StateSent.html" ) );
+    templateFiles.insert ( OutgoingStateError, QLatin1String ( "Outgoing/StateError.html" ) );
 
 
     // load all files
     QFile fileAccess;
-    Q_FOREACH(const QLatin1String &fileName, templateFiles) {
+    Q_FOREACH ( const QLatin1String &fileName, templateFiles ) {
         QString path = d->baseHref + fileName;
         // Load template file
-        if (QFile::exists(path)) {
-            fileAccess.setFileName(path);
-            fileAccess.open(QIODevice::ReadOnly);
-            QTextStream headerStream(&fileAccess);
-            headerStream.setCodec(QTextCodec::codecForName("UTF-8"));
+        if ( QFile::exists ( path ) ) {
+            fileAccess.setFileName ( path );
+            fileAccess.open ( QIODevice::ReadOnly );
+            QTextStream headerStream ( &fileAccess );
+            headerStream.setCodec ( QTextCodec::codecForName ( "UTF-8" ) );
             QString data = headerStream.readAll();
-            if(!data.isEmpty()) {
+            if ( !data.isEmpty() ) {
                 //kDebug() << fileName << "was found!";
-                setContent( templateFiles.key(fileName), data);
+                setContent ( templateFiles.key ( fileName ), data );
             } else {
                 kDebug() << fileName << "was not found!";
             }
@@ -358,28 +357,27 @@ void ChatWindowStyle::readStyleFiles()
     }
 
     // basic fallbacks
-    inheritContent(IncomingNext, Incoming);
+    inheritContent ( IncomingNext, Incoming );
 
-    inheritContent(Outgoing, Incoming);
-    inheritContent(OutgoingNext, Outgoing);
+    inheritContent ( Outgoing, Incoming );
+    inheritContent ( OutgoingNext, Outgoing );
 
-    inheritContent(HistoryIncoming, Incoming);
-    inheritContent(HistoryIncomingNext, HistoryIncoming);
+    inheritContent ( HistoryIncoming, Incoming );
+    inheritContent ( HistoryIncomingNext, HistoryIncoming );
 
-    inheritContent(HistoryOutgoing, HistoryIncoming);
-    inheritContent(HistoryOutgoingNext, HistoryIncomingNext);
+    inheritContent ( HistoryOutgoing, HistoryIncoming );
+    inheritContent ( HistoryOutgoingNext, HistoryIncomingNext );
 
     // Load template file fallback
-    if (content(Template).isEmpty())
-    {
-        QString templateFileName(KGlobal::dirs()->findResource("data", QLatin1String("ktelepathy/template.html")));
-
-        if (! templateFileName.isEmpty() && QFile::exists(templateFileName)) {
-            fileAccess.setFileName(templateFileName);
-            fileAccess.open(QIODevice::ReadOnly);
-            QTextStream headerStream(&fileAccess);
-            headerStream.setCodec(QTextCodec::codecForName("UTF-8"));
-            setContent(Template, headerStream.readAll());
+    if ( content ( Template ).isEmpty() ) {
+        QString templateFileName ( KGlobal::dirs()->findResource ( "data", QLatin1String ( "ktelepathy/template.html" ) ) );
+
+        if ( ! templateFileName.isEmpty() && QFile::exists ( templateFileName ) ) {
+            fileAccess.setFileName ( templateFileName );
+            fileAccess.open ( QIODevice::ReadOnly );
+            QTextStream headerStream ( &fileAccess );
+            headerStream.setCodec ( QTextCodec::codecForName ( "UTF-8" ) );
+            setContent ( Template, headerStream.readAll() );
             fileAccess.close();
         }
     }
@@ -387,45 +385,45 @@ void ChatWindowStyle::readStyleFiles()
     //FIXME: do we have anything like this in telepathy?!
 
     // make sure file transfers are displayed correctly
-    if (content(FileTransferIncoming).isEmpty() ||
-            (!content(FileTransferIncoming).contains(QLatin1String("saveFileHandlerId")) &&
-             !content(FileTransferIncoming).contains(QLatin1String("saveFileAsHandlerId")))) {   // Create default html
-        QString message = QString(QLatin1String("%message%
"
-                                  "<div>
"
-                                  " <div style=\"width:37px; float:left;\">
"
-                                  "  <img src=\"%fileIconPath%\" style=\"width:32px; height:32px; vertical-align:middle;\" />
"
-                                  " </div>
"
-                                  " <div>
"
-                                  "  <span><b>%fileName%</b> (%fileSize%)</span><br>
"
-                                  "  <span>
"
-                                  "   <input id=\"%saveFileAsHandlerId%\" type=\"button\" value=\"%1\">
"
-                                  "   <input id=\"%cancelRequestHandlerId%\" type=\"button\" value=\"%2\">
"
-                                  "  </span>
"
-                                  " </div>
"
-                                  "</div>"))
-                          .arg(i18n("Download"), i18n("Cancel"));
-        QString incoming = content(Incoming);
-        setContent(FileTransferIncoming, incoming.replace(QLatin1String("%message%"), message));
+    if ( content ( FileTransferIncoming ).isEmpty() ||
+            ( !content ( FileTransferIncoming ).contains ( QLatin1String ( "saveFileHandlerId" ) ) &&
+              !content ( FileTransferIncoming ).contains ( QLatin1String ( "saveFileAsHandlerId" ) ) ) ) {   // Create default html
+        QString message = QString ( QLatin1String ( "%message%
"
+                                    "<div>
"
+                                    " <div style=\"width:37px; float:left;\">
"
+                                    "  <img src=\"%fileIconPath%\" style=\"width:32px; height:32px; vertical-align:middle;\" />
"
+                                    " </div>
"
+                                    " <div>
"
+                                    "  <span><b>%fileName%</b> (%fileSize%)</span><br>
"
+                                    "  <span>
"
+                                    "   <input id=\"%saveFileAsHandlerId%\" type=\"button\" value=\"%1\">
"
+                                    "   <input id=\"%cancelRequestHandlerId%\" type=\"button\" value=\"%2\">
"
+                                    "  </span>
"
+                                    " </div>
"
+                                    "</div>" ) )
+                          .arg ( i18n ( "Download" ), i18n ( "Cancel" ) );
+        QString incoming = content ( Incoming );
+        setContent ( FileTransferIncoming, incoming.replace ( QLatin1String ( "%message%" ), message ) );
     }
 
     // make sure VoiceClip is displayed correctly
-    if (content(VoiceClipIncoming).isEmpty() ||
-            (!content(VoiceClipIncoming).contains(QLatin1String("playVoiceHandlerId")) &&
-             !content(VoiceClipIncoming).contains(QLatin1String("saveAsVoiceHandlerId")))) {   // Create default html
-        QString message = QString(QLatin1String("%message%
"
-                                  "<div>
"
-                                  " <div style=\"width:37px; float:left;\">
"
-                                  "  <img src=\"%fileIconPath%\" style=\"width:32px; height:32px; vertical-align:middle;\" />
"
-                                  " </div>
"
-                                  " <div>
"
-                                  "  <span>
"
-                                  "   <input id=\"%playVoiceHandlerId%\" type=\"button\" value=\"%1\">
"
-                                  "   <input id=\"%saveAsVoiceHandlerId%\" type=\"button\" value=\"%2\">
"
-                                  "  </span>
"
-                                  " </div>
"
-                                  "</div>"))
-                          .arg(i18n("Play"), i18n("Save as"));
-        setContent(VoiceClipIncoming, content(Incoming).replace(QLatin1String("%message%"), message));
+    if ( content ( VoiceClipIncoming ).isEmpty() ||
+            ( !content ( VoiceClipIncoming ).contains ( QLatin1String ( "playVoiceHandlerId" ) ) &&
+              !content ( VoiceClipIncoming ).contains ( QLatin1String ( "saveAsVoiceHandlerId" ) ) ) ) {   // Create default html
+        QString message = QString ( QLatin1String ( "%message%
"
+                                    "<div>
"
+                                    " <div style=\"width:37px; float:left;\">
"
+                                    "  <img src=\"%fileIconPath%\" style=\"width:32px; height:32px; vertical-align:middle;\" />
"
+                                    " </div>
"
+                                    " <div>
"
+                                    "  <span>
"
+                                    "   <input id=\"%playVoiceHandlerId%\" type=\"button\" value=\"%1\">
"
+                                    "   <input id=\"%saveAsVoiceHandlerId%\" type=\"button\" value=\"%2\">
"
+                                    "  </span>
"
+                                    " </div>
"
+                                    "</div>" ) )
+                          .arg ( i18n ( "Play" ), i18n ( "Save as" ) );
+        setContent ( VoiceClipIncoming, content ( Incoming ).replace ( QLatin1String ( "%message%" ), message ) );
     }
 }
 
@@ -436,20 +434,20 @@ void ChatWindowStyle::reload()
     listVariants();
 }
 
-bool ChatWindowStyle::hasCompact(const QString & styleVariant) const
+bool ChatWindowStyle::hasCompact ( const QString & styleVariant ) const
 {
-    if (d->compactVariants.contains(styleVariant)) {
-        return d->compactVariants.value(styleVariant);
+    if ( d->compactVariants.contains ( styleVariant ) ) {
+        return d->compactVariants.value ( styleVariant );
     }
     return false;
 }
 
-QString ChatWindowStyle::compact(const QString & styleVariant) const
+QString ChatWindowStyle::compact ( const QString & styleVariant ) const
 {
     QString compacted = styleVariant;
-    if (styleVariant.isEmpty()) {
-        return QLatin1String("Variants/_compact_.css");
+    if ( styleVariant.isEmpty() ) {
+        return QLatin1String ( "Variants/_compact_.css" );
     } else {
-        return compacted.insert(compacted.lastIndexOf(QLatin1Char('/')) + 1, QLatin1String("_compact_"));
+        return compacted.insert ( compacted.lastIndexOf ( QLatin1Char ( '/' ) ) + 1, QLatin1String ( "_compact_" ) );
     }
 }
diff --git a/lib/conversation-model.cpp b/lib/conversation-model.cpp
index 025af1d..0c6f003 100644
--- a/lib/conversation-model.cpp
+++ b/lib/conversation-model.cpp
@@ -25,12 +25,12 @@
 
 class MessageItem {
 public:
-	QString user;
-	QString text;
-	QDateTime time;
+    QString user;
+    QString text;
+    QDateTime time;
 
-	//FIXME : replace with Tp::ChannelTextMessageType
-	enum MessageType {
+    //FIXME : replace with Tp::ChannelTextMessageType
+    enum MessageType {
         Incoming,
         Outgoing,
         Status
@@ -39,121 +39,121 @@ public:
 
 class ConversationModel::ConversationModelPrivate {
 public:
-	Tp::TextChannelPtr textChannel;
-	QList<MessageItem> messages;
+    Tp::TextChannelPtr textChannel;
+    QList<MessageItem> messages;
 };
 
 ConversationModel::ConversationModel(QObject* parent):
-	QAbstractListModel(parent),
-	d(new ConversationModelPrivate)
+    QAbstractListModel(parent),
+    d(new ConversationModelPrivate)
 {
 }
 
 Tp::TextChannelPtr ConversationModel::textChannel()
 {
-	return d->textChannel;
+    return d->textChannel;
 }
 
 void ConversationModel::setupChannelSignals(Tp::TextChannelPtr channel)
 {
-	QObject::connect(channel.constData(),
-					 SIGNAL(messageReceived(Tp::ReceivedMessage)),
-					 SLOT(messageReceived(Tp::ReceivedMessage)));
-	QObject::connect(channel.constData(),
-					 SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
-					 SLOT(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
+    QObject::connect(channel.constData(),
+                    SIGNAL(messageReceived(Tp::ReceivedMessage)),
+                    SLOT(messageReceived(Tp::ReceivedMessage)));
+    QObject::connect(channel.constData(),
+                    SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
+                    SLOT(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
 }
 
 void ConversationModel::setTextChannel(Tp::TextChannelPtr channel)
 {
-	setupChannelSignals(channel);
-	if(d->textChannel) {
-		removeChannelSignals(channel);
-	}
+    setupChannelSignals(channel);
+    if(d->textChannel) {
+        removeChannelSignals(channel);
+    }
 
-	d->textChannel = channel;	//NOTE : is it necessary to delete the old one?
+    d->textChannel = channel;
 
-	textChannelChanged(channel);
+    textChannelChanged(channel);
 }
 
 void ConversationModel::onMessageReceived(Tp::ReceivedMessage message)
 {
-	beginInsertRows(QModelIndex(), d->messages.count(), d->messages.count());
+    beginInsertRows(QModelIndex(), d->messages.count(), d->messages.count());
 
-	MessageItem newMessage = {
-		message.sender()->alias(),
-		message.text(),
-		message.sent(),
-		MessageItem::Incoming
-	};
+    MessageItem newMessage = {
+        message.sender()->alias(),
+        message.text(),
+        message.sent(),
+        MessageItem::Incoming
+    };
 
-	d->messages.append(newMessage);
-	endInsertRows();
+    d->messages.append(newMessage);
+    endInsertRows();
 }
 
 void ConversationModel::onMessageSent(Tp::Message message, Tp::MessageSendingFlags flags, QString token)
 {
-	Q_UNUSED(flags);
-	Q_UNUSED(token);
-	beginInsertRows(QModelIndex(), d->messages.count(), d->messages.count());
-
-	MessageItem newMessage = {
-		tr("Me"),
-		message.text(),
-		message.sent(),
-		MessageItem::Outgoing
-	};
-
-	d->messages.append(newMessage);
-	endInsertRows();
+    Q_UNUSED(flags);
+    Q_UNUSED(token);
+    beginInsertRows(QModelIndex(), d->messages.count(), d->messages.count());
+
+    MessageItem newMessage = {
+        tr("Me"),   //FIXME : use actual nickname from Tp::AccountPtr
+        message.text(),
+        message.sent(),
+        MessageItem::Outgoing
+    };
+
+    d->messages.append(newMessage);
+    endInsertRows();
 }
 
 QVariant ConversationModel::data(const QModelIndex& index, int role) const
 {
-	QVariant result;
-
-	if(!index.isValid()) {
-		kError() << "Attempting to access data at invalid index (" << index << ")";
-	} else {
-		MessageItem* requestedData = &d->messages[index.row()];
-
-		switch(role) {
-			case UserRole:
-				result = requestedData->user;
-				break;
-			case TextRole:
-				result = requestedData->text;
-				break;
-			case TypeRole:
-				result = requestedData->type;
-				break;
-			case TimeRole:
-				result = requestedData->time;
-				break;
-		};
-	}
-
-	return result;
+    QVariant result;
+
+    if(!index.isValid()) {
+        kError() << "Attempting to access data at invalid index (" << index << ")";
+    } else {
+        MessageItem* requestedData = &d->messages[index.row()];
+
+        switch(role) {
+            case UserRole:
+                result = requestedData->user;
+                break;
+            case TextRole:
+                result = requestedData->text;
+                break;
+            case TypeRole:
+                result = requestedData->type;
+                break;
+            case TimeRole:
+                result = requestedData->time;
+                break;
+        };
+    }
+
+    return result;
 }
 
 int ConversationModel::rowCount(const QModelIndex& parent) const
 {
-	Q_UNUSED(parent);
-	return d->messages.count();
+    Q_UNUSED(parent);
+    return d->messages.count();
 }
 
 void ConversationModel::removeChannelSignals(Tp::TextChannelPtr channel)
 {
-	QObject::disconnect(channel.constData(),
-						SIGNAL(messageReceived(Tp::ReceivedMessage)),
-						this,
-						SLOT(onMessageReceived(Tp::ReceivedMessage))
-					   );
-	QObject::disconnect(channel.constData(),
-						SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
-						this,
-						SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString))
-					   );
+    QObject::disconnect(channel.constData(),
+                        SIGNAL(messageReceived(Tp::ReceivedMessage)),
+                        this,
+                        SLOT(onMessageReceived(Tp::ReceivedMessage))
+                    );
+    QObject::disconnect(channel.constData(),
+                        SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
+                        this,
+                        SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString))
+                    );
 }
 
 #include "moc_conversation-model.cpp"
diff --git a/lib/conversation-watcher.cpp b/lib/conversation-watcher.cpp
index 03e1f6e..bb3ef38 100644
--- a/lib/conversation-watcher.cpp
+++ b/lib/conversation-watcher.cpp
@@ -25,6 +25,7 @@
 #include <TelepathyQt4/ChannelClassSpec>
 #include <TelepathyQt4/TextChannel>
 #include "conversation.h"
+#include <TelepathyQt4/ClientRegistrar>
 
 
 static inline Tp::ChannelClassSpecList channelClassList()
@@ -34,40 +35,87 @@ static inline Tp::ChannelClassSpecList channelClassList()
                                       << Tp::ChannelClassSpec::textChatroom();
 }
 
-ConversationWatcher::ConversationWatcher() :
-	AbstractClientObserver(channelClassList())
+class ConversationWatcher::ConversationClientObserver :
+    public Tp::AbstractClientObserver
 {
-	kDebug();
-	qFatal("Derp!");
-	*(int*)0=0;
-}
+public:
+    virtual void observeChannels(
+        const Tp::MethodInvocationContextPtr<>& context,
+        const Tp::AccountPtr& account,
+        const Tp::ConnectionPtr& connection,
+        const QList< Tp::ChannelPtr >& channels,
+        const Tp::ChannelDispatchOperationPtr& dispatchOperation,
+        const QList< Tp::ChannelRequestPtr >& requestsSatisfied,
+        const Tp::AbstractClientObserver::ObserverInfo& observerInfo)
+    {
+        kDebug();
+
+        Tp::TextChannelPtr textChannel;
+        Q_FOREACH(const Tp::ChannelPtr & channel, channels) {
+            textChannel = Tp::TextChannelPtr::dynamicCast(channel);
+            if (textChannel) {
+                break;
+            }
+        }
 
-void ConversationWatcher::observeChannels(const Tp::MethodInvocationContextPtr<>& context,
-										  const Tp::AccountPtr& account,
-										  const Tp::ConnectionPtr& connection,
-										  const QList< Tp::ChannelPtr >& channels,
-										  const Tp::ChannelDispatchOperationPtr& dispatchOperation,
-										  const QList< Tp::ChannelRequestPtr >& requestsSatisfied,
-										  const Tp::AbstractClientObserver::ObserverInfo& observerInfo)
-{
-    kDebug();
+        Q_ASSERT(textChannel);
 
-    Tp::TextChannelPtr textChannel;
-    Q_FOREACH(const Tp::ChannelPtr & channel, channels) {
-        textChannel = Tp::TextChannelPtr::dynamicCast(channel);
-        if (textChannel) {
-            break;
-        }
+        Conversation con(textChannel, account);
+        m_parent->newConversation(&con);
     }
 
-    Q_ASSERT(textChannel);
+    ConversationClientObserver(ConversationWatcher *parent) :
+        AbstractClientObserver(channelClassList()),
+        m_parent(parent)
+    {
+    }
 
-	Conversation con(textChannel, account);
-	newConversation(con);
+    ConversationWatcher *m_parent;
+    Tp::ClientRegistrarPtr registrar;
+};
+
+ConversationWatcher::ConversationWatcher() :
+    d(new ConversationClientObserver(this))
+{
+    kDebug();
+    Tp::registerTypes();
+    Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(),
+                                                                      Tp::Account::FeatureCore);
+
+    Tp::ConnectionFactoryPtr  connectionFactory = Tp::ConnectionFactory::create(
+        QDBusConnection::sessionBus(),
+        Tp::Features() << Tp::Connection::FeatureSelfContact
+                       << Tp::Connection::FeatureCore
+    );
+
+    Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
+    channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);
+
+    Tp::Features textFeatures = Tp::Features() << Tp::TextChannel::FeatureMessageQueue
+                                               << Tp::TextChannel::FeatureMessageSentSignal
+                                               << Tp::TextChannel::FeatureChatState
+                                               << Tp::TextChannel::FeatureMessageCapabilities;
+    channelFactory->addFeaturesForTextChats(textFeatures);
+    channelFactory->addFeaturesForTextChatrooms(textFeatures);
+
+    Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(
+        Tp::Features() << Tp::Contact::FeatureAlias
+                       << Tp::Contact::FeatureAvatarToken
+                       << Tp::Contact::FeatureAvatarData
+                       << Tp::Contact::FeatureCapabilities
+                       << Tp::Contact::FeatureSimplePresence
+    );
+
+    d->registrar = Tp::ClientRegistrar::create(accountFactory, connectionFactory,
+                                               channelFactory, contactFactory);
+
+    d->registrar->registerClient(d, QLatin1String("KDE.TextUi.ConversationWatcher"));
 }
 
+
+
 ConversationWatcher::~ConversationWatcher()
 {
 }
 
-#include "moc_conversation-watcher.cpp"
\ No newline at end of file
+#include "moc_conversation-watcher.cpp"
diff --git a/lib/conversation-watcher.h b/lib/conversation-watcher.h
index 4364a41..3ea80c0 100644
--- a/lib/conversation-watcher.h
+++ b/lib/conversation-watcher.h
@@ -26,24 +26,19 @@
 
 class Conversation;
 
-class KDE_TELEPATHY_CHAT_EXPORT ConversationWatcher : public QObject, public Tp::AbstractClientObserver 
+class KDE_TELEPATHY_CHAT_EXPORT ConversationWatcher : public QObject
 {
 Q_OBJECT
 
 public:
-    virtual void observeChannels(const Tp::MethodInvocationContextPtr<>& context,
-								 const Tp::AccountPtr& account,
-								 const Tp::ConnectionPtr& connection,
-								 const QList< Tp::ChannelPtr >& channels,
-								 const Tp::ChannelDispatchOperationPtr& dispatchOperation,
-								 const QList< Tp::ChannelRequestPtr >& requestsSatisfied,
-								 const Tp::AbstractClientObserver::ObserverInfo& observerInfo
-								);
     ConversationWatcher();
     ~ConversationWatcher();
 
 Q_SIGNALS:
-	void newConversation(Conversation&);
+	void newConversation(Conversation *con);
+private:
+	class ConversationClientObserver;
+	Tp::SharedPtr<ConversationClientObserver> d;
 };
 
 #endif // CONVERSATION_WATCHER_H
diff --git a/lib/conversation.cpp b/lib/conversation.cpp
index f4a67c8..d38dd0e 100644
--- a/lib/conversation.cpp
+++ b/lib/conversation.cpp
@@ -19,33 +19,39 @@
 
 
 #include "conversation.h"
-
 #include "conversation-model.h"
 
 #include <TelepathyQt4/TextChannel>
+#include <KDebug>
 
-class Conversation::ConversationPrivate {
+class Conversation::ConversationPrivate
+{
 public:
-	ConversationModel* model;
-	Tp::AccountPtr account;
+    ConversationModel* model;
+    Tp::AccountPtr account;
 };
 
-Conversation::Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account) :
-	d(new ConversationPrivate)
+Conversation::Conversation ( Tp::TextChannelPtr channel, Tp::AccountPtr account ) :
+        d ( new ConversationPrivate )
 {
-	d->model = new ConversationModel();
-	d->model->setTextChannel(channel);
+    d->model = new ConversationModel();
+    d->model->setTextChannel ( channel );
 
-	d->account = account;
+    d->account = account;
+}
+
+Conversation::Conversation ( QObject* parent ) : QObject ( parent )
+{
+    kError() << "Conversation should not be created directly. Use ConversationWater instead.";
 }
 
 const ConversationModel* Conversation::model() const
 {
-	return d->model;
+    return d->model;
 }
 
 Conversation::~Conversation()
 {
-	delete d->model;
+    delete d->model;
 }
 
diff --git a/lib/conversation.h b/lib/conversation.h
index bb7b40c..56de377 100644
--- a/lib/conversation.h
+++ b/lib/conversation.h
@@ -36,16 +36,17 @@ Q_PROPERTY(const ConversationModel* model READ model NOTIFY modelChanged)
 
 public:
     Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account);
+    Conversation(QObject* parent = 0);
     virtual ~Conversation();
 
-	const ConversationModel* model() const;
+    const ConversationModel* model() const;
 
 Q_SIGNALS:
-	void modelChanged(ConversationModel* newModel);
+    void modelChanged(ConversationModel* newModel);
 
 private:
-	class ConversationPrivate;
-	ConversationPrivate *d;
+    class ConversationPrivate;
+    ConversationPrivate *d;
 };
 
 #endif // CONVERSATION_H
diff --git a/lib/conversation.cpp b/lib/qml-plugins.cpp
similarity index 60%
copy from lib/conversation.cpp
copy to lib/qml-plugins.cpp
index f4a67c8..cd19578 100644
--- a/lib/conversation.cpp
+++ b/lib/qml-plugins.cpp
@@ -1,6 +1,6 @@
 /*
     <one line to give the library's name and an idea of what it does.>
-    Copyright (C) 2011  Lasath Fernando <kde at lasath.org>
+    Copyright (C) 2011  <copyright holder> <email>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -18,34 +18,17 @@
 */
 
 
-#include "conversation.h"
-
-#include "conversation-model.h"
-
-#include <TelepathyQt4/TextChannel>
-
-class Conversation::ConversationPrivate {
-public:
-	ConversationModel* model;
-	Tp::AccountPtr account;
-};
-
-Conversation::Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account) :
-	d(new ConversationPrivate)
-{
-	d->model = new ConversationModel();
-	d->model->setTextChannel(channel);
+#include "qml-plugins.h"
 
-	d->account = account;
-}
-
-const ConversationModel* Conversation::model() const
-{
-	return d->model;
-}
+#include <QtDeclarative/QDeclarativeItem>
+#include "conversation.h"
+#include "conversation-watcher.h"
 
-Conversation::~Conversation()
+void QmlPlugins::registerTypes ( const char* uri )
 {
-	delete d->model;
+    qmlRegisterType<ConversationWatcher> ( uri, 0, 1, "ConversationWatcher" );
+    qmlRegisterType<Conversation>(uri, 0, 1, "Conversation");
+    qmlRegisterType<ConversationModel> ( uri, 0, 1, "ConversationModel" );
 }
 
+Q_EXPORT_PLUGIN2 ( conversation, QmlPlugins );
diff --git a/lib/conversation.cpp b/lib/qml-plugins.h
similarity index 59%
copy from lib/conversation.cpp
copy to lib/qml-plugins.h
index f4a67c8..cc8c2b2 100644
--- a/lib/conversation.cpp
+++ b/lib/qml-plugins.h
@@ -1,6 +1,6 @@
 /*
     <one line to give the library's name and an idea of what it does.>
-    Copyright (C) 2011  Lasath Fernando <kde at lasath.org>
+    Copyright (C) 2011  <copyright holder> <email>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -18,34 +18,15 @@
 */
 
 
-#include "conversation.h"
+#ifndef QML_PLUGINS_H
+#define QML_PLUGINS_H
 
-#include "conversation-model.h"
+#include <QtDeclarative/QDeclarativeExtensionPlugin>
 
-#include <TelepathyQt4/TextChannel>
-
-class Conversation::ConversationPrivate {
+class QmlPlugins : public QDeclarativeExtensionPlugin
+{
 public:
-	ConversationModel* model;
-	Tp::AccountPtr account;
+    virtual void registerTypes(const char* uri);
 };
 
-Conversation::Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account) :
-	d(new ConversationPrivate)
-{
-	d->model = new ConversationModel();
-	d->model->setTextChannel(channel);
-
-	d->account = account;
-}
-
-const ConversationModel* Conversation::model() const
-{
-	return d->model;
-}
-
-Conversation::~Conversation()
-{
-	delete d->model;
-}
-
+#endif // QML_PLUGINS_H
diff --git a/lib/qmldir b/lib/qmldir
new file mode 100644
index 0000000..deff477
--- /dev/null
+++ b/lib/qmldir
@@ -0,0 +1 @@
+plugin declarativeplugins
\ No newline at end of file
diff --git a/plasmoid/CMakeLists.txt b/plasmoid/CMakeLists.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/plasmoid/CMakeLists.txt
@@ -0,0 +1 @@
+
diff --git a/plasmoid/contents/ui/main.qml b/plasmoid/contents/ui/main.qml
new file mode 100644
index 0000000..2b9c184
--- /dev/null
+++ b/plasmoid/contents/ui/main.qml
@@ -0,0 +1,19 @@
+import Qt 4.7
+import org.kde.telepathy.declarativeplugins 0.1 as KTelepathy
+
+Item {
+    id:main
+
+    ListView {
+        id: view
+        anchors.fill: parent
+    }
+
+    KTelepathy.ConversationWatcher {
+        id:watcher
+        onNewConversation: {
+            console.log("SOMETHINGAHPPENDED!");
+            console.log(con.model);
+        }
+    }
+}
\ No newline at end of file
diff --git a/plasmoid/metadata.desktop b/plasmoid/metadata.desktop
new file mode 100644
index 0000000..6b0c002
--- /dev/null
+++ b/plasmoid/metadata.desktop
@@ -0,0 +1,23 @@
+[Desktop Entry]
+Name=Chat Widget Mockup
+Comment=This is sort of me learning QML, you can have a conversation with a hardcoded contact
+Icon=kde-telepathy
+
+X-Plasma-API=declarativeappletscript
+X-Plasma-MainScript=ui/main.qml
+X-Plasma-DefaultSize=300,200
+# X-Plasma-RequiredExtensions=LaunchApp
+
+X-KDE-PluginInfo-Author=Frederik Gladhorn
+X-KDE-PluginInfo-Email=gladhorn at kde.org
+X-KDE-PluginInfo-Website=http://plasma.kde.org/
+X-KDE-PluginInfo-Category=Examples
+X-KDE-PluginInfo-Name=org.kde.telepathy.chat
+X-KDE-PluginInfo-Version=0.0
+
+X-KDE-PluginInfo-Depends=
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=true
+#X-KDE-ServiceTypes=Plasma/PopupApplet
+X-KDE-ServiceTypes=Plasma/Applet
+Type=Service
\ No newline at end of file

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list