Merge lp:~dgadomski/ubuntu-rssreader-app/shorts-pubdate-formatting into lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk
- shorts-pubdate-formatting
- Merge into trunk
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 | ||||
Related bugs: |
|
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".
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
Joey Chan (qqworini) wrote : | # |
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:/
> 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.
>
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
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://
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.
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-
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:/
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.
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-
> 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.
>
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 internationaliz
David: do you think it will not work in terms of internationaliz
return i18n.tr(
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
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-
> 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:/
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.
Joey Chan (qqworini) wrote : | # |
u may try ".import Ubuntu.Components 0.1" in a .js file, i18n will be included
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:/
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.
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 internationaliz
> 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
> internationaliz
> return i18n.tr(
> FORMAT_
> 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 internationaliz
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:/
> 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.
>
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.
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://
With it, you can run the 'make pot' rule on the command line to generate
the ubuntu-
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:
- Internationaliz
X-Ubuntu-
- 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://
[2]
http://
Preview Diff
1 | === modified file 'ArticleFullImg.qml' |
2 | --- ArticleFullImg.qml 2013-07-14 14:14:18 +0000 |
3 | +++ ArticleFullImg.qml 2013-07-21 12:57:28 +0000 |
4 | @@ -1,12 +1,13 @@ |
5 | import QtQuick 2.0 |
6 | import Ubuntu.Components 0.1 |
7 | import Ubuntu.Components.ListItems 0.1 as ListItem |
8 | +import "dateutils.js" as DateUtils |
9 | |
10 | Column { |
11 | width: units.gu(26) |
12 | height: units.gu(20) |
13 | // anchors.fill: parent |
14 | - property string rss_title: "" |
15 | + property variant rss_item |
16 | property variant imageArray: [] |
17 | property variant rss_model |
18 | property int model_index |
19 | @@ -42,7 +43,7 @@ |
20 | Label |
21 | { |
22 | id: label_title |
23 | - text: rss_title |
24 | + text: rss_item.title |
25 | anchors.bottom: parent.bottom |
26 | anchors.bottomMargin: units.gu(1) |
27 | anchors.horizontalCenter: parent.horizontalCenter |
28 | @@ -67,7 +68,7 @@ |
29 | Label |
30 | { |
31 | id: label_time |
32 | - text: "13 minutes ago" |
33 | + text: DateUtils.formatPostTime(rss_item.pubdate, i18n) |
34 | color: "black" |
35 | fontSize: "medium" |
36 | } |
37 | |
38 | === modified file 'ArticleOneImgA.qml' |
39 | --- ArticleOneImgA.qml 2013-07-14 14:14:18 +0000 |
40 | +++ ArticleOneImgA.qml 2013-07-21 12:57:28 +0000 |
41 | @@ -1,13 +1,14 @@ |
42 | import QtQuick 2.0 |
43 | import Ubuntu.Components 0.1 |
44 | import Ubuntu.Components.ListItems 0.1 as ListItem |
45 | +import "dateutils.js" as DateUtils |
46 | |
47 | Column { |
48 | id: delegate_item |
49 | width: units.gu(34) |
50 | // height: units.gu(16) |
51 | // anchors.fill: parent |
52 | - property string rss_title: "" |
53 | + property variant rss_item |
54 | property variant imageArray: [] |
55 | property variant rss_model |
56 | property int model_index |
57 | @@ -21,7 +22,7 @@ |
58 | Label |
59 | { |
60 | id: label_title |
61 | - text: rss_title |
62 | + text: rss_item.title |
63 | // anchors.horizontalCenter: parent.horizontalCenter |
64 | width: units.gu(14) |
65 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
66 | @@ -72,7 +73,7 @@ |
67 | Label |
68 | { |
69 | id: label_time |
70 | - text: "13 minutes ago" |
71 | + text: DateUtils.formatPostTime(rss_item.pubdate, i18n) |
72 | color: "black" |
73 | fontSize: "medium" |
74 | horizontalAlignment: Text.AlignRight |
75 | |
76 | === modified file 'ArticleOneImgB.qml' |
77 | --- ArticleOneImgB.qml 2013-07-14 14:14:18 +0000 |
78 | +++ ArticleOneImgB.qml 2013-07-21 12:57:28 +0000 |
79 | @@ -1,13 +1,14 @@ |
80 | import QtQuick 2.0 |
81 | import Ubuntu.Components 0.1 |
82 | import Ubuntu.Components.ListItems 0.1 as ListItem |
83 | +import "dateutils.js" as DateUtils |
84 | |
85 | Column { |
86 | id: delegate_item |
87 | width: units.gu(34) |
88 | // height: units.gu(16) |
89 | // anchors.fill: parent |
90 | - property string rss_title: "" |
91 | + property variant rss_item |
92 | property variant imageArray: [] |
93 | property variant rss_model |
94 | property int model_index |
95 | @@ -59,7 +60,7 @@ |
96 | Label |
97 | { |
98 | id: label_title |
99 | - text: rss_title |
100 | + text: rss_item.title |
101 | // anchors.horizontalCenter: parent.horizontalCenter |
102 | width: units.gu(14) |
103 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
104 | @@ -91,7 +92,7 @@ |
105 | Label |
106 | { |
107 | id: label_time |
108 | - text: "13 minutes ago" |
109 | + text: DateUtils.formatPostTime(rss_item.pubdate, i18n) |
110 | color: "black" |
111 | fontSize: "medium" |
112 | } |
113 | |
114 | === modified file 'ArticleTextA.qml' |
115 | --- ArticleTextA.qml 2013-07-14 14:14:18 +0000 |
116 | +++ ArticleTextA.qml 2013-07-21 12:57:28 +0000 |
117 | @@ -1,12 +1,13 @@ |
118 | import QtQuick 2.0 |
119 | import Ubuntu.Components 0.1 |
120 | import Ubuntu.Components.ListItems 0.1 as ListItem |
121 | +import "dateutils.js" as DateUtils |
122 | |
123 | Column { |
124 | width: units.gu(30) |
125 | // height: units.gu(15) |
126 | // anchors.fill: parent |
127 | - property string rss_title: "" |
128 | + property variant rss_item |
129 | property variant imageArray: [] |
130 | property variant rss_model |
131 | property int model_index |
132 | @@ -19,7 +20,7 @@ |
133 | Label |
134 | { |
135 | id: label_title |
136 | - text: rss_title |
137 | + text: rss_item.title |
138 | // anchors.horizontalCenter: parent.horizontalCenter |
139 | width: units.gu(30) |
140 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
141 | @@ -42,7 +43,7 @@ |
142 | Label |
143 | { |
144 | id: label_time |
145 | - text: "13 minutes ago" |
146 | + text: DateUtils.formatPostTime(rss_item.pubdate, i18n) |
147 | color: "black" |
148 | fontSize: "medium" |
149 | width: parent.width |
150 | |
151 | === modified file 'ArticleTextB.qml' |
152 | --- ArticleTextB.qml 2013-07-14 14:14:18 +0000 |
153 | +++ ArticleTextB.qml 2013-07-21 12:57:28 +0000 |
154 | @@ -1,12 +1,13 @@ |
155 | import QtQuick 2.0 |
156 | import Ubuntu.Components 0.1 |
157 | import Ubuntu.Components.ListItems 0.1 as ListItem |
158 | +import "dateutils.js" as DateUtils |
159 | |
160 | Column { |
161 | width: units.gu(30) |
162 | // height: units.gu(15) |
163 | // anchors.fill: parent |
164 | - property string rss_title: "" |
165 | + property variant rss_item |
166 | property variant imageArray: [] |
167 | property variant rss_model |
168 | property int model_index |
169 | @@ -19,7 +20,7 @@ |
170 | Label |
171 | { |
172 | id: label_title |
173 | - text: rss_title |
174 | + text: rss_item.title |
175 | // anchors.horizontalCenter: parent.horizontalCenter |
176 | width: units.gu(30) |
177 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
178 | @@ -43,7 +44,7 @@ |
179 | Label |
180 | { |
181 | id: label_time |
182 | - text: "13 minutes ago" |
183 | + text: DateUtils.formatPostTime(rss_item.pubdate, i18n) |
184 | color: "black" |
185 | fontSize: "medium" |
186 | horizontalAlignment: Text.AlignRight |
187 | |
188 | === modified file 'ArticleTwoImgA.qml' |
189 | --- ArticleTwoImgA.qml 2013-07-14 14:14:18 +0000 |
190 | +++ ArticleTwoImgA.qml 2013-07-21 12:57:28 +0000 |
191 | @@ -1,13 +1,14 @@ |
192 | import QtQuick 2.0 |
193 | import Ubuntu.Components 0.1 |
194 | import Ubuntu.Components.ListItems 0.1 as ListItem |
195 | +import "dateutils.js" as DateUtils |
196 | |
197 | Column { |
198 | id: delegate_item |
199 | width: units.gu(34) |
200 | // height: units.gu(30) |
201 | // anchors.fill: parent |
202 | - property string rss_title: "" |
203 | + property variant rss_item |
204 | property variant imageArray: [] |
205 | property variant rss_model |
206 | property int model_index |
207 | @@ -21,7 +22,7 @@ |
208 | Label |
209 | { |
210 | id: label_title |
211 | - text: rss_title |
212 | + text: rss_item.title |
213 | // anchors.horizontalCenter: parent.horizontalCenter |
214 | width: units.gu(14) |
215 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
216 | @@ -78,7 +79,7 @@ |
217 | Label |
218 | { |
219 | id: label_time |
220 | - text: "13 minutes ago" |
221 | + text: DateUtils.formatPostTime(rss_item.pubdate, i18n) |
222 | color: "black" |
223 | fontSize: "medium" |
224 | } |
225 | |
226 | === modified file 'ListColumnDelegate.qml' |
227 | --- ListColumnDelegate.qml 2013-07-14 14:14:18 +0000 |
228 | +++ ListColumnDelegate.qml 2013-07-21 12:57:28 +0000 |
229 | @@ -20,10 +20,10 @@ |
230 | property real childrenMaxWidth: 0 |
231 | property int modelIndex |
232 | |
233 | - function addItem(rss_title, rss_description, model, index) |
234 | + function addItem(rss_item, model, index) |
235 | { |
236 | // console.log("delegate height: ", rss_item_delegate.height) ; |
237 | - var newD = AddD.addDelegate(rss_title, ImgS.separate(rss_description), model, index); |
238 | + var newD = AddD.addDelegate(rss_item, ImgS.separate(rss_item.description), model, index); |
239 | getChildrenRect() ; |
240 | rss_item_delegate.width = childrenMaxWidth ; |
241 | console.log("childrenSumHeight, column.height: ", childrenSumHeight, rss_item_delegate.height) |
242 | |
243 | === modified file 'ListColumnView.qml' |
244 | --- ListColumnView.qml 2013-07-14 14:14:18 +0000 |
245 | +++ ListColumnView.qml 2013-07-21 12:57:28 +0000 |
246 | @@ -104,7 +104,7 @@ |
247 | // model++ ; |
248 | // currentIndex = model - 1 ; |
249 | console.log("model index: ", i) |
250 | - while (!currentItem.addItem(tempmodel.get(i).title, tempmodel.get(i).description, tempmodel, i)) |
251 | + while (!currentItem.addItem(tempmodel.get(i), tempmodel, i)) |
252 | { |
253 | // model++ ; |
254 | column_model.append( { "nothing": "nothing" } ) ; |
255 | |
256 | === modified file 'addDelegate.js' |
257 | --- addDelegate.js 2013-07-14 14:14:18 +0000 |
258 | +++ addDelegate.js 2013-07-21 12:57:28 +0000 |
259 | @@ -4,7 +4,7 @@ |
260 | //var mob_component; |
261 | //var mob_sprite; |
262 | |
263 | -function addDelegate(rss_title, imageArray, model, index) |
264 | +function addDelegate(rss_item, imageArray, model, index) |
265 | { |
266 | // console.log("add delegate start") |
267 | // component = undefined ; |
268 | @@ -23,18 +23,18 @@ |
269 | // component = Qt.createComponent("./ArticledelegateOneImgB.qml"); |
270 | // sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray}); |
271 | // console.log("delegate BBBBB") |
272 | - newD = delegateOneImgA (rss_title, imageArray, model, index) |
273 | + newD = delegateOneImgA (rss_item, imageArray, model, index) |
274 | } |
275 | else if (rand > 70) |
276 | { |
277 | // component = Qt.createComponent("./ArticledelegateOneImgA.qml"); |
278 | // sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray}); |
279 | // console.log("delegate AAAAA") |
280 | - newD = delegateOneImgB (rss_title, imageArray, model, index) |
281 | + newD = delegateOneImgB (rss_item, imageArray, model, index) |
282 | } |
283 | else |
284 | { |
285 | - newD = delegateFullImg (rss_title, imageArray, model, index) |
286 | + newD = delegateFullImg (rss_item, imageArray, model, index) |
287 | } |
288 | |
289 | } |
290 | @@ -42,16 +42,16 @@ |
291 | { |
292 | if (rand > 50) |
293 | { |
294 | - newD = delegateTextA (rss_title/*, imageArray*/, model, index) ; |
295 | + newD = delegateTextA (rss_item/*, imageArray*/, model, index) ; |
296 | } |
297 | else |
298 | { |
299 | - newD = delegateTextB (rss_title/*, imageArray*/, model, index) ; |
300 | + newD = delegateTextB (rss_item/*, imageArray*/, model, index) ; |
301 | } |
302 | } |
303 | else |
304 | { |
305 | - newD = delegateTwoImgA (rss_title, imageArray, model, index) |
306 | + newD = delegateTwoImgA (rss_item, imageArray, model, index) |
307 | } |
308 | |
309 | // else if (imageArray == undefined ) |
310 | @@ -79,12 +79,12 @@ |
311 | return newD ; |
312 | } |
313 | |
314 | -function delegateOneImgA (rss_title, imageArray, model, index) |
315 | +function delegateOneImgA (rss_item, imageArray, model, index) |
316 | { |
317 | var component; |
318 | var sprite; |
319 | component = Qt.createComponent("./ArticleOneImgA.qml"); |
320 | - sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
321 | + sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
322 | // console.log("delegate AAAAA") |
323 | |
324 | if (sprite == null) { |
325 | @@ -95,12 +95,12 @@ |
326 | return sprite |
327 | } |
328 | |
329 | -function delegateOneImgB (rss_title, imageArray, model, index) |
330 | +function delegateOneImgB (rss_item, imageArray, model, index) |
331 | { |
332 | var component; |
333 | var sprite; |
334 | component = Qt.createComponent("./ArticleOneImgB.qml"); |
335 | - sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
336 | + sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
337 | // console.log("delegate BBBBB") |
338 | |
339 | if (sprite == null) { |
340 | @@ -111,12 +111,12 @@ |
341 | return sprite |
342 | } |
343 | |
344 | -function delegateTextA (rss_title, model, index) |
345 | +function delegateTextA (rss_item, model, index) |
346 | { |
347 | var component; |
348 | var sprite; |
349 | component = Qt.createComponent("./ArticleTextA.qml"); |
350 | - sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "rss_model": model, "model_index": index}); |
351 | + sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "rss_model": model, "model_index": index}); |
352 | // console.log("delegate CCCCC") |
353 | |
354 | if (sprite == null) { |
355 | @@ -127,12 +127,12 @@ |
356 | return sprite |
357 | } |
358 | |
359 | -function delegateTextB (rss_title, model, index) |
360 | +function delegateTextB (rss_item, model, index) |
361 | { |
362 | var component; |
363 | var sprite; |
364 | component = Qt.createComponent("./ArticleTextB.qml"); |
365 | - sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "rss_model": model, "model_index": index}); |
366 | + sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "rss_model": model, "model_index": index}); |
367 | // console.log("delegate CCCCC") |
368 | |
369 | if (sprite == null) { |
370 | @@ -143,12 +143,12 @@ |
371 | return sprite |
372 | } |
373 | |
374 | -function delegateFullImg (rss_title, imageArray, model, index) |
375 | +function delegateFullImg (rss_item, imageArray, model, index) |
376 | { |
377 | var component; |
378 | var sprite; |
379 | component = Qt.createComponent("./ArticleFullImg.qml"); |
380 | - sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
381 | + sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
382 | // console.log("delegate DDDDD") |
383 | |
384 | if (sprite == null) { |
385 | @@ -159,12 +159,12 @@ |
386 | return sprite |
387 | } |
388 | |
389 | -function delegateTwoImgA (rss_title, imageArray, model, index) |
390 | +function delegateTwoImgA (rss_item, imageArray, model, index) |
391 | { |
392 | var component; |
393 | var sprite; |
394 | component = Qt.createComponent("./ArticleTwoImgA.qml"); |
395 | - sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
396 | + sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
397 | |
398 | if (sprite == null) { |
399 | // Error Handling |
400 | |
401 | === added file 'dateutils.js' |
402 | --- dateutils.js 1970-01-01 00:00:00 +0000 |
403 | +++ dateutils.js 2013-07-21 12:57:28 +0000 |
404 | @@ -0,0 +1,63 @@ |
405 | +/* |
406 | + * Copyright 2013 Canonical Ltd. |
407 | + * |
408 | + * This file is part of ubuntu-rssreader-app. |
409 | + * |
410 | + * ubuntu-calculator-app is free software; you can redistribute it and/or modify |
411 | + * it under the terms of the GNU General Public License as published by |
412 | + * the Free Software Foundation; version 3. |
413 | + * |
414 | + * ubuntu-calculator-app is distributed in the hope that it will be useful, |
415 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
416 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
417 | + * GNU General Public License for more details. |
418 | + * |
419 | + * You should have received a copy of the GNU General Public License |
420 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
421 | + */ |
422 | + |
423 | +.pragma library |
424 | + |
425 | +var SECONDS_LIMIT = 60 * 1000; |
426 | +var MINUTES_LIMIT = 60 * SECONDS_LIMIT; |
427 | +var HOURS_LIMIT = 24 * MINUTES_LIMIT; |
428 | +var DAYS_LIMIT = 30 * HOURS_LIMIT; |
429 | + |
430 | +// TODO: handle i18n |
431 | +var FORMAT_LIMITS = [ |
432 | + { "limit": SECONDS_LIMIT, "formats": ["%0 second ago", "%0 seconds ago"] }, |
433 | + { "limit": MINUTES_LIMIT, "formats": ["%0 minute ago", "%0 minutes ago"] }, |
434 | + { "limit": HOURS_LIMIT, "formats": ["%0 hour ago", "%0 hours ago"] }, |
435 | + { "limit": DAYS_LIMIT, "formats": ["%0 day ago", "%0 days ago"] }, |
436 | +] |
437 | + |
438 | +// fallback if none of the above formats matched |
439 | +// TODO: handle i18n |
440 | +var DEFAULT_DATE_FORMAT = "MMM Do" |
441 | + |
442 | +function parseDate(dateAsStr) { |
443 | + return Date.parse(dateAsStr); |
444 | +} |
445 | + |
446 | +function formatPostTime(dateAsStr, i18n) { |
447 | + var now = new Date(); |
448 | + var then = parseDate(dateAsStr); |
449 | + var diff = now - then; |
450 | + var formattedDiff = formatDiff(diff, then, i18n); |
451 | + console.log("DDD DIFF", diff, formattedDiff) |
452 | + return formattedDiff; |
453 | +} |
454 | + |
455 | +function formatDiff(diff, then, i18n) { |
456 | + for (var i=0; i<FORMAT_LIMITS.length; ++i) { |
457 | + var limit = FORMAT_LIMITS[i].limit; |
458 | + if (diff < limit) { |
459 | + // use previous limit to calculate number of current units |
460 | + // e.g. to calculate hours divide by MINUTES_LIMIT |
461 | + // (because MINUTES_LIMIT is 1 hours) etc. |
462 | + var val = Math.floor(diff / (i > 1 ? FORMAT_LIMITS[i-1].limit : SECONDS_LIMIT)) |
463 | + return i18n.tr(FORMAT_LIMITS[i].formats[0], FORMAT_LIMITS[i].formats[1], val).arg(val) |
464 | + } |
465 | + } |
466 | + return then.toString(i18n.tr(DEFAULT_DATE_FORMAT)) |
467 | +} |
Thanks for the time format tool :)