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

List:       kde-commits
Subject:    [declarative-plasmoids] microblog: Muchos more making-it-work
From:       Sebastian_Kügler <sebas () kde ! org>
Date:       2012-02-01 1:50:01
Message-ID: 20120201015001.0DB92A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 070a97c99038b4aef6feaf4581cc70bc623f4065 by Sebastian Kügler.
Committed on 27/01/2012 at 23:24.
Pushed by sebas into branch 'master'.

Muchos more making-it-work

- Sort timeline descending, using a SortFilterModel
- Fix authorization status display, not beautiful, but works
- Function for a friendly date display:
  We could do this much nicer using KLocale, but that would mean that
  we'd have to call the dataengine everytime we want to update the
  display, which can happen quite often for the "2 minutes ago" cases, so
  we're using a JavaScript function here, hoping that translators can
  somehow makes this work until we have QML bindings for KLocale

M  +1    -1    microblog/contents/config/main.xml
M  +12   -5    microblog/contents/ui/ComplexComponents/MessageList.qml
M  +6    -6    microblog/contents/ui/ComplexComponents/UserInfo.qml
M  +37   -5    microblog/contents/ui/main.qml
M  +29   -5    microblog/platformcontents/application/generic/ui/BasicComponents/MessageWidget.qml
 M  +2    -2    microblog/platformcontents/application/generic/ui/BasicComponents/PostingWidget.qml


http://commits.kde.org/declarative-plasmoids/070a97c99038b4aef6feaf4581cc70bc623f4065

diff --git a/microblog/contents/config/main.xml b/microblog/contents/config/main.xml
index 638b308..37015c5 100644
--- a/microblog/contents/config/main.xml
+++ b/microblog/contents/config/main.xml
@@ -8,7 +8,7 @@
   <group name="General">
     <entry name="serviceUrl" type="String">
       <label>Microblog service</label>
-      <default>https://identi.ca/api/</default>
+      <default>https://twitter.com/</default>
     </entry>
     <entry name="userName" type="String">
       <label>User name</label>
diff --git a/microblog/contents/ui/ComplexComponents/MessageList.qml \
b/microblog/contents/ui/ComplexComponents/MessageList.qml index 227d6c0..9df4e1b \
                100644
--- a/microblog/contents/ui/ComplexComponents/MessageList.qml
+++ b/microblog/contents/ui/ComplexComponents/MessageList.qml
@@ -28,7 +28,7 @@ ListView {
     clip: true
     snapMode: ListView.SnapToItem
     spacing: 2
-    cacheBuffer: 5
+    //cacheBuffer: 500
 
     signal itemClicked(variant item)
 
@@ -41,6 +41,7 @@ ListView {
         microblogSource.connectSource(source)
         timer.running = true
     }
+
     Timer {
         id: timer
         repeat: false
@@ -54,12 +55,18 @@ ListView {
         }
     }
 
-    model: PlasmaCore.DataModel {
-        dataSource: microblogSource
-        sourceFilter: entryList.source
-        keyRoleFilter: "[\\d]*"
+    model: PlasmaCore.SortFilterModel {
+        id: sortModel
+        sortRole: "Date"
+        sortOrder: "DescendingOrder"
+        sourceModel: PlasmaCore.DataModel {
+            dataSource: microblogSource
+            sourceFilter: entryList.source
+            keyRoleFilter: "[\\d]*"
+        }
     }
 
+    
     delegate: MessageWidget {
         id: messageWidget
         width: entryList.width
diff --git a/microblog/contents/ui/ComplexComponents/UserInfo.qml \
b/microblog/contents/ui/ComplexComponents/UserInfo.qml index 198a2de..5dc9458 100644
--- a/microblog/contents/ui/ComplexComponents/UserInfo.qml
+++ b/microblog/contents/ui/ComplexComponents/UserInfo.qml
@@ -109,8 +109,8 @@ PlasmaCore.FrameSvgItem {
 
     onSourceChanged: {
         if (url == "" || login == "") {
-            print("Invalid source: " + source);
-            print(" UserInfo: " + login, url, source);
+            //print("Invalid source: " + source);
+            //print(" UserInfo: " + login, url, source);
             //login = "sebas";
             //url = "https://identi.ca/api/"
         }
@@ -120,10 +120,10 @@ PlasmaCore.FrameSvgItem {
         realNameLabel.text = "";
         descriptonLabel.text = "";
         if (userSource.data[source]) {
-            print(" moving " + source);
+            //print(" moving " + source);
             updateData(userSource.data[source]);
         } else {
-            print(" connnecting " + source);
+            //print(" connnecting " + source);
             userSource.connectSource(source);
         }
         //timer.running = true
@@ -185,11 +185,11 @@ r;
 
     onLoginChanged: {
         source = timelineType+":"+login+"@"+url
-        print("onLoginChanged: " + source);
+        //print("onLoginChanged: " + source);
         //userSource.connectSource(source);
     }
     Component.onCompleted: {
         login = userName
-        print(" user info loaded: " + login + source);
+        //print(" user info loaded: " + login + source);
     }
 }
diff --git a/microblog/contents/ui/main.qml b/microblog/contents/ui/main.qml
index cc27489..ac36512 100644
--- a/microblog/contents/ui/main.qml
+++ b/microblog/contents/ui/main.qml
@@ -19,6 +19,7 @@
 
 import QtQuick 1.1
 import org.kde.plasma.core 0.1 as PlasmaCore
+import org.kde.plasma.components 0.1 as PlasmaComponents
 import org.kde.qtextracomponents 0.1 as QtExtraComponents
 
 import "plasmapackage:/code/logic.js" as Logic
@@ -29,8 +30,8 @@ Item {
     width: 200
     height: 300
 
-    property string serviceUrl: "https://identi.ca/api/"
-    property string userName: "sebas" // FIXME: remove until config doesn't get \
nuked all the time +    property string serviceUrl: "https://twitter.com/"
+    property string userName: "PlasmaActive" // FIXME: remove until config doesn't \
get nuked all the time  property string password
 
     signal replyAsked(string id, string message)
@@ -51,7 +52,7 @@ Item {
         var u = plasmoid.readConfig("userName")
         var p = plasmoid.readConfig("password")
         var s = serviceUrl = plasmoid.readConfig("serviceUrl")
-        print( "XXX Read user and password from config: " + u + ":" + p);
+//         print( "XXX Read user and password from config: " + u + ":" + p);
 
         if (u) {
             userName = u;
@@ -64,8 +65,8 @@ Item {
             serviceUrl = plasmoid.readConfig("serviceUrl")
             imageSource.connectSource("UserImages:"+serviceUrl)
         } else {
-            serviceUrl = "https://identi.ca/api/"
-            //serviceUrl = "https://twitter.com/"
+            //serviceUrl = "https://identi.ca/api/"
+            serviceUrl = "https://twitter.com/"
         }
         if (serviceUrl && userName) {
             microblogSource.connectSource("TimelineWithFriends:"+userName+"@"+serviceUrl)
 @@ -105,6 +106,11 @@ Item {
         }
     }
 
+    onServiceUrlChanged: {
+        print("C O N N E C T E D");
+        statusSource.connectSource("Status:"+serviceUrl);
+    }
+
     PlasmaCore.DataSource {
         id: imageSource
         engine: "microblog"
@@ -122,7 +128,33 @@ Item {
         interval: 0
     }
 
+    PlasmaCore.DataSource {
+        id: statusSource
+        engine: "microblog"
+        interval: 0
+        onDataChanged: {
+            if (statusSource.data["Status:"+serviceUrl]) {
+                print(" status: " + statusSource.data);
+                authStatusLabel.text = \
statusSource.data["Status:"+serviceUrl]["Authorization"]; +            } else {
+                authStatusLabel.text = "Unknown status"
+            }
+        }
+        Component.onCompleted: statusSource.connectSource("Status:"+serviceUrl);
+
+    }
+
     MainWidget {
         anchors.fill: main
     }
+
+    PlasmaComponents.Label {
+        id: authStatusLabel
+        width: 300
+        height: 48
+        //text: statusSource.data["Status:https://twitter.com/"]["Authorization"]
+        //text: "Status:" + \
statusSource.data["Status:https://twitter.com/"]["Authorization"] +        text: \
"Status..." +        anchors { left: parent.left; right: parent.right; }
+    }
 }
diff --git a/microblog/platformcontents/application/generic/ui/BasicComponents/MessageWidget.qml \
b/microblog/platformcontents/application/generic/ui/BasicComponents/MessageWidget.qml \
                index c416ebd..e3fd892 100644
--- a/microblog/platformcontents/application/generic/ui/BasicComponents/MessageWidget.qml
                
+++ b/microblog/platformcontents/application/generic/ui/BasicComponents/MessageWidget.qml
 @@ -83,12 +83,36 @@ ListItem {
         opacity: 0.3
         font.pointSize: theme.smallestFont.pointSize
         styleColor: theme.backgroundColor
-        text: {
-            var d = new Date(dateTime);
-            dout = Qt.formatDateTime(d, "hh:mm");
-            return i18n("at %1", dout);
-        }
+        text: friendlyDate(dateTime);
     }
 
     Item { height: 12; anchors.top: bodyText.bottom; z: -1 }
+
+    function friendlyDate(date) {
+//         print(" - - - - - - - - - - - - - - - -");
+        var d = new Date(date);
+        var now = new Date();
+//         print("Now is: " + now);
+//         print("  d is: " + d);
+        var dout = Qt.formatDateTime(d, "hh:mm");
+        var ago = (now - d) / 1000;
+        var output = "";
+//         print(" NOW: " + now.getTime());
+//         print("   D: " + d.getTime());
+//         print(" AGO: " + ago);
+        if (ago < 60) {
+            output = i18n("%1 seconds ago", ago);
+        } else if (ago < 3600) {
+            output = i18n("%1 minutes ago", Math.round(ago/60));
+        } else if (ago < 84600) {
+            output = i18n("%1 hours ago", Math.round(ago/3600));
+        } else {
+            output = i18n("%1 days ago", Math.round(ago/86400));
+            //output = Qt.formatDateTime(d, "hh:mm");
+        }
+//         print(" Date Conversion: ", dateTime, "->", output);
+        //print("     ago sec:" + ago + output);
+        //return i18n("at %1", dout);
+        return output;
+    }
 }
diff --git a/microblog/platformcontents/application/generic/ui/BasicComponents/PostingWidget.qml \
b/microblog/platformcontents/application/generic/ui/BasicComponents/PostingWidget.qml \
                index 5587033..bfc0099 100644
--- a/microblog/platformcontents/application/generic/ui/BasicComponents/PostingWidget.qml
                
+++ b/microblog/platformcontents/application/generic/ui/BasicComponents/PostingWidget.qml
 @@ -51,9 +51,9 @@ Item {
         Avatar {
             id: profileIcon
             height: 32
-            anchors.top: postWidget.top
-            anchors.verticalCenter: postTextEdit.verticalCenter
             width: height
+            anchors.left: postWidget.left
+            anchors.verticalCenter: postTextEdit.verticalCenter
             userId: userName
         }
 //         PlasmaComponents.Label {


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

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