Merge lp:~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting into lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk

Proposed by Dariusz Gadomski
Status: Merged
Approved by: Joey Chan
Approved revision: 21
Merged at revision: 19
Proposed branch: lp:~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting
Merge into: lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk
Diff against target: 467 lines (+109/-40)
10 files modified
ArticleFullImg.qml (+4/-3)
ArticleOneImgA.qml (+4/-3)
ArticleOneImgB.qml (+4/-3)
ArticleTextA.qml (+4/-3)
ArticleTextB.qml (+4/-3)
ArticleTwoImgA.qml (+4/-3)
ListColumnDelegate.qml (+2/-2)
ListColumnView.qml (+1/-1)
addDelegate.js (+19/-19)
dateutils.js (+63/-0)
To merge this branch: bzr merge lp:~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Ubuntu Shorts Developers Pending
Review via email: mp+176051@code.launchpad.net

Commit message

Added formatting for the pubDate labels.

Description of the change

Added time formatting to Shorts.

If the article has been published less that 30 days ago
the time is expressed as number of either seconds, minutes,
hours or days ago. If the pubDate is over 30 days the time
is displayed as date using format: "MMMM Do".

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)
Revision history for this message
Joey Chan (qqworini) wrote :

Thanks for the time format tool :)

Revision history for this message
Roman Shchekin (mrqtros) wrote :

Hi, thanks :)
But I think that this tool will be totally redesigned later because of a
lot of cultures...
Just imagine problems with (for example) Arabic culture. Even direction of
text changes :)

Best Regards,
Roman.

2013/7/21 Joey Chan <email address hidden>

> Thanks for the time format tool :)
> --
>
> https://code.launchpad.net/~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting/+merge/176051
> Your team Ubuntu RSS Feed Reader Developers is requested to review the
> proposed merge of
> lp:~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting into
> lp:ubuntu-rssreader-app.
>

Revision history for this message
Dariusz Gadomski (dgadomski) wrote :

Hi,

Thanks for you opinion. Could you please explain (or provide a link to any docs) how to improve it? I have only experience with pure (no gettext) Qt/QML apps for MeeGo utilizing qsTr in both: *.qml and *.js files. I did not have any clue how to implement i18n in *.js, that's why I pass i18n object there from QML.

In case of MeeGo using an array of strings along with qsTr (like the in line 463 in the diff below) worked fine for all languages (all the culture-specific stuff was done by translators: e.g. inserting Right-To-Left characters etc.).

Do you know any examples of i18n usage in *.js files?

Thanks,
Dariusz

Revision history for this message
David Planella (dpm) wrote :

Al 21/07/13 21:17, En/na Dariusz Gadomski ha escrit:
> Hi,
>
> Thanks for you opinion. Could you please explain (or provide a link to any docs) how to improve it? I have only experience with pure (no gettext) Qt/QML apps for MeeGo utilizing qsTr in both: *.qml and *.js files. I did not have any clue how to implement i18n in *.js, that's why I pass i18n object there from QML.
>
> In case of MeeGo using an array of strings along with qsTr (like the in line 463 in the diff below) worked fine for all languages (all the culture-specific stuff was done by translators: e.g. inserting Right-To-Left characters etc.).
>
> Do you know any examples of i18n usage in *.js files?
>
> Thanks,
> Dariusz
>

Hi Dariusz,

Yeah, you can use the regular i18n.tr() functions [1] from the Ubuntu
SDK, either in QML or JS files.

You can have a look at clock, weather and other core apps for the usage
of the i18n.tr() function. Also clock and calendar have good examples of
locale-aware times and numbers.

Cheers,
David.

[1]
http://developer.ubuntu.com/api/devel/ubuntu-13.10/qml/ui-toolkit/qml-ubuntu-components0-i18n.html

Revision history for this message
David Planella (dpm) wrote :

Al 21/07/13 21:17, En/na Dariusz Gadomski ha escrit:
> Hi,
>
> Thanks for you opinion. Could you please explain (or provide a link to any docs) how to improve it? I have only experience with pure (no gettext) Qt/QML apps for MeeGo utilizing qsTr in both: *.qml and *.js files. I did not have any clue how to implement i18n in *.js, that's why I pass i18n object there from QML.
>
> In case of MeeGo using an array of strings along with qsTr (like the in line 463 in the diff below) worked fine for all languages (all the culture-specific stuff was done by translators: e.g. inserting Right-To-Left characters etc.).
>
> Do you know any examples of i18n usage in *.js files?
>
> Thanks,
> Dariusz
>

Also, I've just noticed that you're reimplementing a relative time
calculation that is already done in the Calculator app.

It might be worth looking at using just one way of calculating this.
Looking at both at a glance, yours looks simpler and cleaner, but the
calculator one handles translations and plurals for all languages.

Do you think you could have a look at unifying the two functions?

Cheers,
David.

Revision history for this message
Roman Shchekin (mrqtros) wrote :

Yep, I think we must use "strong" realization rather than a liitle bit "naive" =)

P.S. David, could your please have a look at my merge proposal? =)
I can't provide you with url, but my branch is named stable-trunk-prepare2 as you may remember.
Testing fails, I don't know why :(

22.07.13 10:23 David Planella написал(а):

Al 21/07/13 21:17, En/na Dariusz Gadomski ha escrit:
> Hi,
>
> Thanks for you opinion. Could you please explain (or provide a link to any docs) how to improve it? I have only experience with pure (no gettext) Qt/QML apps for MeeGo utilizing qsTr in both: *.qml and *.js files. I did not have any clue how to implement i18n in *.js, that's why I pass i18n object there from QML.
>
> In case of MeeGo using an array of strings along with qsTr (like the in line 463 in the diff below) worked fine for all languages (all the culture-specific stuff was done by translators: e.g. inserting Right-To-Left characters etc.).
>
> Do you know any examples of i18n usage in *.js files?
>
> Thanks,
> Dariusz
>

Also, I've just noticed that you're reimplementing a relative time
calculation that is already done in the Calculator app.

It might be worth looking at using just one way of calculating this.
Looking at both at a glance, yours looks simpler and cleaner, but the
calculator one handles translations and plurals for all languages.

Do you think you could have a look at unifying the two functions?

Cheers,
David.

--
https://code.launchpad.net/~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting/+merge/176051

Your team Ubuntu RSS Feed Reader Developers is requested to review the proposed merge of lp:~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting into lp:ubuntu-rssreader-app.

Revision history for this message
David Planella (dpm) wrote :

Al 22/07/13 08:34, En/na Roman Shchekin ha escrit:
> Yep, I think we must use "strong" realization rather than a liitle bit "naive" =)
>
> P.S. David, could your please have a look at my merge proposal? =)
> I can't provide you with url, but my branch is named stable-trunk-prepare2 as you may remember.
> Testing fails, I don't know why :(

Hi Roman,

I already commented on your other branch this morning.

Cheers,
David.

>
> 22.07.13 10:23 David Planella написал(а):
>
> Al 21/07/13 21:17, En/na Dariusz Gadomski ha escrit:
>> Hi,
>>
>> Thanks for you opinion. Could you please explain (or provide a link to any docs) how to improve it? I have only experience with pure (no gettext) Qt/QML apps for MeeGo utilizing qsTr in both: *.qml and *.js files. I did not have any clue how to implement i18n in *.js, that's why I pass i18n object there from QML.
>>
>> In case of MeeGo using an array of strings along with qsTr (like the in line 463 in the diff below) worked fine for all languages (all the culture-specific stuff was done by translators: e.g. inserting Right-To-Left characters etc.).
>>
>> Do you know any examples of i18n usage in *.js files?
>>
>> Thanks,
>> Dariusz
>>
>
> Also, I've just noticed that you're reimplementing a relative time
> calculation that is already done in the Calculator app.
>
>
> It might be worth looking at using just one way of calculating this.
> Looking at both at a glance, yours looks simpler and cleaner, but the
> calculator one handles translations and plurals for all languages.
>
>
> Do you think you could have a look at unifying the two functions?
>
>
> Cheers,
> David.
>

Revision history for this message
Dariusz Gadomski (dgadomski) wrote :

I would love to improve my proposal, but I still miss some info.

In the calculator app I can see the internationalization implemented in Storage.qml file as part of the Storage component. I wanted to have it isolated in a *.js library in rssreader. I was not able to find out how to use i18n object properly in *.js files, that is why I pass 'i18n' object form QML to JS and use it there.

David: do you think it will not work in terms of internationalization/plurals? I am refering to line 463 of the diff below:
  return i18n.tr(FORMAT_LIMITS[i].formats[0], FORMAT_LIMITS[i].formats[1], val).arg(val)
Will the translation tool catch up with such a dynamic call to i18n.tr? Please note that I provide all the information necessary for plurals handling there.

If this is not supposed to work in *.js files I can prepare a QML component implementing this behaviour and reuse it in both: the calculator and the rssreader.

Cheers,
Dariusz

Revision history for this message
Roman Shchekin (mrqtros) wrote :

Thanks!

22.07.13 10:52 David Planella написал(а):

Al 22/07/13 08:34, En/na Roman Shchekin ha escrit:
> Yep, I think we must use "strong" realization rather than a liitle bit "naive" =)
>
> P.S. David, could your please have a look at my merge proposal? =)
> I can't provide you with url, but my branch is named stable-trunk-prepare2 as you may remember.
> Testing fails, I don't know why :(

Hi Roman,

I already commented on your other branch this morning.

Cheers,
David.

>
> 22.07.13 10:23 David Planella написал(а):
>
> Al 21/07/13 21:17, En/na Dariusz Gadomski ha escrit:
>> Hi,
>>
>> Thanks for you opinion. Could you please explain (or provide a link to any docs) how to improve it? I have only experience with pure (no gettext) Qt/QML apps for MeeGo utilizing qsTr in both: *.qml and *.js files. I did not have any clue how to implement i18n in *.js, that's why I pass i18n object there from QML.
>>
>> In case of MeeGo using an array of strings along with qsTr (like the in line 463 in the diff below) worked fine for all languages (all the culture-specific stuff was done by translators: e.g. inserting Right-To-Left characters etc.).
>>
>> Do you know any examples of i18n usage in *.js files?
>>
>> Thanks,
>> Dariusz
>>
>
> Also, I've just noticed that you're reimplementing a relative time
> calculation that is already done in the Calculator app.
>
>
> It might be worth looking at using just one way of calculating this.
> Looking at both at a glance, yours looks simpler and cleaner, but the
> calculator one handles translations and plurals for all languages.
>
>
> Do you think you could have a look at unifying the two functions?
>
>
> Cheers,
> David.
>

--
https://code.launchpad.net/~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting/+merge/176051

Your team Ubuntu RSS Feed Reader Developers is requested to review the proposed merge of lp:~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting into lp:ubuntu-rssreader-app.

Revision history for this message
Joey Chan (qqworini) wrote :

u may try ".import Ubuntu.Components 0.1" in a .js file, i18n will be included

Revision history for this message
Roman Shchekin (mrqtros) wrote :

Joey is right, use ".import ..." Syntax in *.js files.

22.07.13 11:20 Joey Chan написал(а):

u may try ".import Ubuntu.Components 0.1" in a .js file, i18n will be included

--
https://code.launchpad.net/~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting/+merge/176051

Your team Ubuntu RSS Feed Reader Developers is requested to review the proposed merge of lp:~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting into lp:ubuntu-rssreader-app.

Revision history for this message
David Planella (dpm) wrote :

On Mon, Jul 22, 2013 at 9:05 AM, Dariusz Gadomski <email address hidden>wrote:

> I would love to improve my proposal, but I still miss some info.
>
> In the calculator app I can see the internationalization implemented in
> Storage.qml file as part of the Storage component. I wanted to have it
> isolated in a *.js library in rssreader. I was not able to find out how to
> use i18n object properly in *.js files, that is why I pass 'i18n' object
> form QML to JS and use it there.
>
>
I think what you're trying to do makes sense, only that I've never used the
i18n functions outside of QML files. You might want to try what Joey is
mentioning in his last comment.

> David: do you think it will not work in terms of
> internationalization/plurals? I am refering to line 463 of the diff below:
> return i18n.tr(FORMAT_LIMITS[i].formats[0],
> FORMAT_LIMITS[i].formats[1], val).arg(val)
> Will the translation tool catch up with such a dynamic call to i18n.tr?
> Please note that I provide all the information necessary for plurals
> handling there.
>
>
That's correct, I believe that'd work at runtime. However, what will not
work there are the tools that extract the translations from the code to
expose them to translators. Being more specific, I don't think xgettext
would work here, as it expects the translatable strings to be wrapped in
i18n.tr() calls.

Also note that while we want to start marking all strings for translation,
the RSS reader has not yet been set up for internationalization (which we
need to do as soon as we land some of the current big changes). I'm
mentioning this because if you want to test i18n, it might be necessary to
set it up first.

> If this is not supposed to work in *.js files I can prepare a QML
> component implementing this behaviour and reuse it in both: the calculator
> and the rssreader.
>
>
Sounds like a good idea too. Let us know how it goes.

> Cheers,
> Dariusz
> --
>
> https://code.launchpad.net/~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting/+merge/176051
> Your team Ubuntu RSS Feed Reader Developers is requested to review the
> proposed merge of
> lp:~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting into
> lp:ubuntu-rssreader-app.
>

Revision history for this message
Dariusz Gadomski (dgadomski) wrote :

Ok, thanks. I will try to prepare a generic solution for both apps and setup i18n in rssreader to be able to test the solution.

Revision history for this message
David Planella (dpm) wrote :

Al 22/07/13 10:25, En/na Dariusz Gadomski ha escrit:
> Ok, thanks. I will try to prepare a generic solution for both apps and setup i18n in rssreader to be able to test the solution.
>

Sounds excellent, thanks Dariusz!

Essentially, what's needed to set up i18n for testing purposes is to add
this file adapted to the rss reader:

http://bazaar.launchpad.net/~ubuntu-weather-dev/ubuntu-weather-app/trunk/view/head:/po/po.pro

With it, you can run the 'make pot' rule on the command line to generate
the ubuntu-rss-reader-app.pot file. Generally, then the file is
committed and Launchpad takes care of exposing it to translators and to
create the .po files automatically, but for testing purposes you can
create a .po file manually from the .pot file.

There are two other steps required for translations to be loaded:

- Internationalization of the .desktop file adding the
  X-Ubuntu-Gettext-Domain key [1]
- Set up the Debian package to build and install the translation
  files [2]

But for manual, local testing you might not need these two.

[1]
http://bazaar.launchpad.net/~ubuntu-weather-dev/ubuntu-weather-app/trunk/view/head:/ubuntu-weather-app.desktop#L11
[2]
http://bazaar.launchpad.net/~ubuntu-weather-dev/ubuntu-weather-app/trunk/view/head:/debian/rules#L10

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ArticleFullImg.qml'
--- ArticleFullImg.qml 2013-07-14 14:14:18 +0000
+++ ArticleFullImg.qml 2013-07-21 12:57:28 +0000
@@ -1,12 +1,13 @@
1import QtQuick 2.01import QtQuick 2.0
2import Ubuntu.Components 0.12import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1 as ListItem3import Ubuntu.Components.ListItems 0.1 as ListItem
4import "dateutils.js" as DateUtils
45
5Column {6Column {
6 width: units.gu(26)7 width: units.gu(26)
7 height: units.gu(20)8 height: units.gu(20)
8 // anchors.fill: parent9 // anchors.fill: parent
9 property string rss_title: ""10 property variant rss_item
10 property variant imageArray: []11 property variant imageArray: []
11 property variant rss_model12 property variant rss_model
12 property int model_index13 property int model_index
@@ -42,7 +43,7 @@
42 Label43 Label
43 {44 {
44 id: label_title45 id: label_title
45 text: rss_title46 text: rss_item.title
46 anchors.bottom: parent.bottom47 anchors.bottom: parent.bottom
47 anchors.bottomMargin: units.gu(1)48 anchors.bottomMargin: units.gu(1)
48 anchors.horizontalCenter: parent.horizontalCenter49 anchors.horizontalCenter: parent.horizontalCenter
@@ -67,7 +68,7 @@
67 Label68 Label
68 {69 {
69 id: label_time70 id: label_time
70 text: "13 minutes ago"71 text: DateUtils.formatPostTime(rss_item.pubdate, i18n)
71 color: "black"72 color: "black"
72 fontSize: "medium"73 fontSize: "medium"
73 }74 }
7475
=== modified file 'ArticleOneImgA.qml'
--- ArticleOneImgA.qml 2013-07-14 14:14:18 +0000
+++ ArticleOneImgA.qml 2013-07-21 12:57:28 +0000
@@ -1,13 +1,14 @@
1import QtQuick 2.01import QtQuick 2.0
2import Ubuntu.Components 0.12import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1 as ListItem3import Ubuntu.Components.ListItems 0.1 as ListItem
4import "dateutils.js" as DateUtils
45
5Column {6Column {
6 id: delegate_item7 id: delegate_item
7 width: units.gu(34)8 width: units.gu(34)
8// height: units.gu(16)9// height: units.gu(16)
9// anchors.fill: parent10// anchors.fill: parent
10 property string rss_title: ""11 property variant rss_item
11 property variant imageArray: []12 property variant imageArray: []
12 property variant rss_model13 property variant rss_model
13 property int model_index14 property int model_index
@@ -21,7 +22,7 @@
21 Label22 Label
22 {23 {
23 id: label_title24 id: label_title
24 text: rss_title25 text: rss_item.title
25// anchors.horizontalCenter: parent.horizontalCenter26// anchors.horizontalCenter: parent.horizontalCenter
26 width: units.gu(14)27 width: units.gu(14)
27 wrapMode: Text.WrapAtWordBoundaryOrAnywhere28 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
@@ -72,7 +73,7 @@
72 Label73 Label
73 {74 {
74 id: label_time75 id: label_time
75 text: "13 minutes ago"76 text: DateUtils.formatPostTime(rss_item.pubdate, i18n)
76 color: "black"77 color: "black"
77 fontSize: "medium"78 fontSize: "medium"
78 horizontalAlignment: Text.AlignRight79 horizontalAlignment: Text.AlignRight
7980
=== modified file 'ArticleOneImgB.qml'
--- ArticleOneImgB.qml 2013-07-14 14:14:18 +0000
+++ ArticleOneImgB.qml 2013-07-21 12:57:28 +0000
@@ -1,13 +1,14 @@
1import QtQuick 2.01import QtQuick 2.0
2import Ubuntu.Components 0.12import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1 as ListItem3import Ubuntu.Components.ListItems 0.1 as ListItem
4import "dateutils.js" as DateUtils
45
5Column {6Column {
6 id: delegate_item7 id: delegate_item
7 width: units.gu(34)8 width: units.gu(34)
8// height: units.gu(16)9// height: units.gu(16)
9// anchors.fill: parent10// anchors.fill: parent
10 property string rss_title: ""11 property variant rss_item
11 property variant imageArray: []12 property variant imageArray: []
12 property variant rss_model13 property variant rss_model
13 property int model_index14 property int model_index
@@ -59,7 +60,7 @@
59 Label60 Label
60 {61 {
61 id: label_title62 id: label_title
62 text: rss_title63 text: rss_item.title
63// anchors.horizontalCenter: parent.horizontalCenter64// anchors.horizontalCenter: parent.horizontalCenter
64 width: units.gu(14)65 width: units.gu(14)
65 wrapMode: Text.WrapAtWordBoundaryOrAnywhere66 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
@@ -91,7 +92,7 @@
91 Label92 Label
92 {93 {
93 id: label_time94 id: label_time
94 text: "13 minutes ago"95 text: DateUtils.formatPostTime(rss_item.pubdate, i18n)
95 color: "black"96 color: "black"
96 fontSize: "medium"97 fontSize: "medium"
97 }98 }
9899
=== modified file 'ArticleTextA.qml'
--- ArticleTextA.qml 2013-07-14 14:14:18 +0000
+++ ArticleTextA.qml 2013-07-21 12:57:28 +0000
@@ -1,12 +1,13 @@
1import QtQuick 2.01import QtQuick 2.0
2import Ubuntu.Components 0.12import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1 as ListItem3import Ubuntu.Components.ListItems 0.1 as ListItem
4import "dateutils.js" as DateUtils
45
5Column {6Column {
6 width: units.gu(30)7 width: units.gu(30)
7// height: units.gu(15)8// height: units.gu(15)
8// anchors.fill: parent9// anchors.fill: parent
9 property string rss_title: ""10 property variant rss_item
10 property variant imageArray: []11 property variant imageArray: []
11 property variant rss_model12 property variant rss_model
12 property int model_index13 property int model_index
@@ -19,7 +20,7 @@
19 Label20 Label
20 {21 {
21 id: label_title22 id: label_title
22 text: rss_title23 text: rss_item.title
23// anchors.horizontalCenter: parent.horizontalCenter24// anchors.horizontalCenter: parent.horizontalCenter
24 width: units.gu(30)25 width: units.gu(30)
25 wrapMode: Text.WrapAtWordBoundaryOrAnywhere26 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
@@ -42,7 +43,7 @@
42 Label43 Label
43 {44 {
44 id: label_time45 id: label_time
45 text: "13 minutes ago"46 text: DateUtils.formatPostTime(rss_item.pubdate, i18n)
46 color: "black"47 color: "black"
47 fontSize: "medium"48 fontSize: "medium"
48 width: parent.width49 width: parent.width
4950
=== modified file 'ArticleTextB.qml'
--- ArticleTextB.qml 2013-07-14 14:14:18 +0000
+++ ArticleTextB.qml 2013-07-21 12:57:28 +0000
@@ -1,12 +1,13 @@
1import QtQuick 2.01import QtQuick 2.0
2import Ubuntu.Components 0.12import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1 as ListItem3import Ubuntu.Components.ListItems 0.1 as ListItem
4import "dateutils.js" as DateUtils
45
5Column {6Column {
6 width: units.gu(30)7 width: units.gu(30)
7// height: units.gu(15)8// height: units.gu(15)
8// anchors.fill: parent9// anchors.fill: parent
9 property string rss_title: ""10 property variant rss_item
10 property variant imageArray: []11 property variant imageArray: []
11 property variant rss_model12 property variant rss_model
12 property int model_index13 property int model_index
@@ -19,7 +20,7 @@
19 Label20 Label
20 {21 {
21 id: label_title22 id: label_title
22 text: rss_title23 text: rss_item.title
23// anchors.horizontalCenter: parent.horizontalCenter24// anchors.horizontalCenter: parent.horizontalCenter
24 width: units.gu(30)25 width: units.gu(30)
25 wrapMode: Text.WrapAtWordBoundaryOrAnywhere26 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
@@ -43,7 +44,7 @@
43 Label44 Label
44 {45 {
45 id: label_time46 id: label_time
46 text: "13 minutes ago"47 text: DateUtils.formatPostTime(rss_item.pubdate, i18n)
47 color: "black"48 color: "black"
48 fontSize: "medium"49 fontSize: "medium"
49 horizontalAlignment: Text.AlignRight50 horizontalAlignment: Text.AlignRight
5051
=== modified file 'ArticleTwoImgA.qml'
--- ArticleTwoImgA.qml 2013-07-14 14:14:18 +0000
+++ ArticleTwoImgA.qml 2013-07-21 12:57:28 +0000
@@ -1,13 +1,14 @@
1import QtQuick 2.01import QtQuick 2.0
2import Ubuntu.Components 0.12import Ubuntu.Components 0.1
3import Ubuntu.Components.ListItems 0.1 as ListItem3import Ubuntu.Components.ListItems 0.1 as ListItem
4import "dateutils.js" as DateUtils
45
5Column {6Column {
6 id: delegate_item7 id: delegate_item
7 width: units.gu(34)8 width: units.gu(34)
8// height: units.gu(30)9// height: units.gu(30)
9// anchors.fill: parent10// anchors.fill: parent
10 property string rss_title: ""11 property variant rss_item
11 property variant imageArray: []12 property variant imageArray: []
12 property variant rss_model13 property variant rss_model
13 property int model_index14 property int model_index
@@ -21,7 +22,7 @@
21 Label22 Label
22 {23 {
23 id: label_title24 id: label_title
24 text: rss_title25 text: rss_item.title
25// anchors.horizontalCenter: parent.horizontalCenter26// anchors.horizontalCenter: parent.horizontalCenter
26 width: units.gu(14)27 width: units.gu(14)
27 wrapMode: Text.WrapAtWordBoundaryOrAnywhere28 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
@@ -78,7 +79,7 @@
78 Label79 Label
79 {80 {
80 id: label_time81 id: label_time
81 text: "13 minutes ago"82 text: DateUtils.formatPostTime(rss_item.pubdate, i18n)
82 color: "black"83 color: "black"
83 fontSize: "medium"84 fontSize: "medium"
84 }85 }
8586
=== modified file 'ListColumnDelegate.qml'
--- ListColumnDelegate.qml 2013-07-14 14:14:18 +0000
+++ ListColumnDelegate.qml 2013-07-21 12:57:28 +0000
@@ -20,10 +20,10 @@
20 property real childrenMaxWidth: 020 property real childrenMaxWidth: 0
21 property int modelIndex21 property int modelIndex
2222
23 function addItem(rss_title, rss_description, model, index)23 function addItem(rss_item, model, index)
24 {24 {
25// console.log("delegate height: ", rss_item_delegate.height) ;25// console.log("delegate height: ", rss_item_delegate.height) ;
26 var newD = AddD.addDelegate(rss_title, ImgS.separate(rss_description), model, index);26 var newD = AddD.addDelegate(rss_item, ImgS.separate(rss_item.description), model, index);
27 getChildrenRect() ;27 getChildrenRect() ;
28 rss_item_delegate.width = childrenMaxWidth ;28 rss_item_delegate.width = childrenMaxWidth ;
29 console.log("childrenSumHeight, column.height: ", childrenSumHeight, rss_item_delegate.height)29 console.log("childrenSumHeight, column.height: ", childrenSumHeight, rss_item_delegate.height)
3030
=== modified file 'ListColumnView.qml'
--- ListColumnView.qml 2013-07-14 14:14:18 +0000
+++ ListColumnView.qml 2013-07-21 12:57:28 +0000
@@ -104,7 +104,7 @@
104// model++ ;104// model++ ;
105// currentIndex = model - 1 ;105// currentIndex = model - 1 ;
106 console.log("model index: ", i)106 console.log("model index: ", i)
107 while (!currentItem.addItem(tempmodel.get(i).title, tempmodel.get(i).description, tempmodel, i))107 while (!currentItem.addItem(tempmodel.get(i), tempmodel, i))
108 {108 {
109// model++ ;109// model++ ;
110 column_model.append( { "nothing": "nothing" } ) ;110 column_model.append( { "nothing": "nothing" } ) ;
111111
=== modified file 'addDelegate.js'
--- addDelegate.js 2013-07-14 14:14:18 +0000
+++ addDelegate.js 2013-07-21 12:57:28 +0000
@@ -4,7 +4,7 @@
4//var mob_component;4//var mob_component;
5//var mob_sprite;5//var mob_sprite;
66
7function addDelegate(rss_title, imageArray, model, index)7function addDelegate(rss_item, imageArray, model, index)
8{8{
9// console.log("add delegate start")9// console.log("add delegate start")
10// component = undefined ;10// component = undefined ;
@@ -23,18 +23,18 @@
23 // component = Qt.createComponent("./ArticledelegateOneImgB.qml");23 // component = Qt.createComponent("./ArticledelegateOneImgB.qml");
24 // sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray});24 // sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray});
25 // console.log("delegate BBBBB")25 // console.log("delegate BBBBB")
26 newD = delegateOneImgA (rss_title, imageArray, model, index)26 newD = delegateOneImgA (rss_item, imageArray, model, index)
27 }27 }
28 else if (rand > 70)28 else if (rand > 70)
29 {29 {
30 // component = Qt.createComponent("./ArticledelegateOneImgA.qml");30 // component = Qt.createComponent("./ArticledelegateOneImgA.qml");
31 // sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray});31 // sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray});
32 // console.log("delegate AAAAA")32 // console.log("delegate AAAAA")
33 newD = delegateOneImgB (rss_title, imageArray, model, index)33 newD = delegateOneImgB (rss_item, imageArray, model, index)
34 }34 }
35 else35 else
36 {36 {
37 newD = delegateFullImg (rss_title, imageArray, model, index)37 newD = delegateFullImg (rss_item, imageArray, model, index)
38 }38 }
3939
40 }40 }
@@ -42,16 +42,16 @@
42 {42 {
43 if (rand > 50)43 if (rand > 50)
44 {44 {
45 newD = delegateTextA (rss_title/*, imageArray*/, model, index) ;45 newD = delegateTextA (rss_item/*, imageArray*/, model, index) ;
46 }46 }
47 else47 else
48 {48 {
49 newD = delegateTextB (rss_title/*, imageArray*/, model, index) ;49 newD = delegateTextB (rss_item/*, imageArray*/, model, index) ;
50 }50 }
51 }51 }
52 else52 else
53 {53 {
54 newD = delegateTwoImgA (rss_title, imageArray, model, index)54 newD = delegateTwoImgA (rss_item, imageArray, model, index)
55 }55 }
5656
57// else if (imageArray == undefined )57// else if (imageArray == undefined )
@@ -79,12 +79,12 @@
79 return newD ;79 return newD ;
80}80}
8181
82function delegateOneImgA (rss_title, imageArray, model, index)82function delegateOneImgA (rss_item, imageArray, model, index)
83{83{
84 var component;84 var component;
85 var sprite;85 var sprite;
86 component = Qt.createComponent("./ArticleOneImgA.qml");86 component = Qt.createComponent("./ArticleOneImgA.qml");
87 sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index});87 sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index});
88// console.log("delegate AAAAA")88// console.log("delegate AAAAA")
8989
90 if (sprite == null) {90 if (sprite == null) {
@@ -95,12 +95,12 @@
95 return sprite95 return sprite
96}96}
9797
98function delegateOneImgB (rss_title, imageArray, model, index)98function delegateOneImgB (rss_item, imageArray, model, index)
99{99{
100 var component;100 var component;
101 var sprite;101 var sprite;
102 component = Qt.createComponent("./ArticleOneImgB.qml");102 component = Qt.createComponent("./ArticleOneImgB.qml");
103 sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index});103 sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index});
104// console.log("delegate BBBBB")104// console.log("delegate BBBBB")
105105
106 if (sprite == null) {106 if (sprite == null) {
@@ -111,12 +111,12 @@
111 return sprite111 return sprite
112}112}
113113
114function delegateTextA (rss_title, model, index)114function delegateTextA (rss_item, model, index)
115{115{
116 var component;116 var component;
117 var sprite;117 var sprite;
118 component = Qt.createComponent("./ArticleTextA.qml");118 component = Qt.createComponent("./ArticleTextA.qml");
119 sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "rss_model": model, "model_index": index});119 sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "rss_model": model, "model_index": index});
120// console.log("delegate CCCCC")120// console.log("delegate CCCCC")
121121
122 if (sprite == null) {122 if (sprite == null) {
@@ -127,12 +127,12 @@
127 return sprite127 return sprite
128}128}
129129
130function delegateTextB (rss_title, model, index)130function delegateTextB (rss_item, model, index)
131{131{
132 var component;132 var component;
133 var sprite;133 var sprite;
134 component = Qt.createComponent("./ArticleTextB.qml");134 component = Qt.createComponent("./ArticleTextB.qml");
135 sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "rss_model": model, "model_index": index});135 sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "rss_model": model, "model_index": index});
136// console.log("delegate CCCCC")136// console.log("delegate CCCCC")
137137
138 if (sprite == null) {138 if (sprite == null) {
@@ -143,12 +143,12 @@
143 return sprite143 return sprite
144}144}
145145
146function delegateFullImg (rss_title, imageArray, model, index)146function delegateFullImg (rss_item, imageArray, model, index)
147{147{
148 var component;148 var component;
149 var sprite;149 var sprite;
150 component = Qt.createComponent("./ArticleFullImg.qml");150 component = Qt.createComponent("./ArticleFullImg.qml");
151 sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index});151 sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index});
152// console.log("delegate DDDDD")152// console.log("delegate DDDDD")
153153
154 if (sprite == null) {154 if (sprite == null) {
@@ -159,12 +159,12 @@
159 return sprite159 return sprite
160}160}
161161
162function delegateTwoImgA (rss_title, imageArray, model, index)162function delegateTwoImgA (rss_item, imageArray, model, index)
163{163{
164 var component;164 var component;
165 var sprite;165 var sprite;
166 component = Qt.createComponent("./ArticleTwoImgA.qml");166 component = Qt.createComponent("./ArticleTwoImgA.qml");
167 sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index});167 sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index});
168168
169 if (sprite == null) {169 if (sprite == null) {
170 // Error Handling170 // Error Handling
171171
=== added file 'dateutils.js'
--- dateutils.js 1970-01-01 00:00:00 +0000
+++ dateutils.js 2013-07-21 12:57:28 +0000
@@ -0,0 +1,63 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This file is part of ubuntu-rssreader-app.
5 *
6 * ubuntu-calculator-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-calculator-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19.pragma library
20
21var SECONDS_LIMIT = 60 * 1000;
22var MINUTES_LIMIT = 60 * SECONDS_LIMIT;
23var HOURS_LIMIT = 24 * MINUTES_LIMIT;
24var DAYS_LIMIT = 30 * HOURS_LIMIT;
25
26// TODO: handle i18n
27var FORMAT_LIMITS = [
28 { "limit": SECONDS_LIMIT, "formats": ["%0 second ago", "%0 seconds ago"] },
29 { "limit": MINUTES_LIMIT, "formats": ["%0 minute ago", "%0 minutes ago"] },
30 { "limit": HOURS_LIMIT, "formats": ["%0 hour ago", "%0 hours ago"] },
31 { "limit": DAYS_LIMIT, "formats": ["%0 day ago", "%0 days ago"] },
32]
33
34// fallback if none of the above formats matched
35// TODO: handle i18n
36var DEFAULT_DATE_FORMAT = "MMM Do"
37
38function parseDate(dateAsStr) {
39 return Date.parse(dateAsStr);
40}
41
42function formatPostTime(dateAsStr, i18n) {
43 var now = new Date();
44 var then = parseDate(dateAsStr);
45 var diff = now - then;
46 var formattedDiff = formatDiff(diff, then, i18n);
47 console.log("DDD DIFF", diff, formattedDiff)
48 return formattedDiff;
49}
50
51function formatDiff(diff, then, i18n) {
52 for (var i=0; i<FORMAT_LIMITS.length; ++i) {
53 var limit = FORMAT_LIMITS[i].limit;
54 if (diff < limit) {
55 // use previous limit to calculate number of current units
56 // e.g. to calculate hours divide by MINUTES_LIMIT
57 // (because MINUTES_LIMIT is 1 hours) etc.
58 var val = Math.floor(diff / (i > 1 ? FORMAT_LIMITS[i-1].limit : SECONDS_LIMIT))
59 return i18n.tr(FORMAT_LIMITS[i].formats[0], FORMAT_LIMITS[i].formats[1], val).arg(val)
60 }
61 }
62 return then.toString(i18n.tr(DEFAULT_DATE_FORMAT))
63}

Subscribers

People subscribed via source and target branches