Merge lp:~nik90/podbird/3-auto-clean-episodes into lp:podbird

Proposed by Nekhelesh Ramananthan
Status: Merged
Approved by: Michael Sheldon
Approved revision: 50
Merged at revision: 38
Proposed branch: lp:~nik90/podbird/3-auto-clean-episodes
Merge into: lp:podbird
Prerequisite: lp:~nik90/podbird/2-add-button-feedback
Diff against target: 239 lines (+154/-31)
3 files modified
app/podbird.qml (+31/-0)
app/ui/SettingsTab.qml (+79/-28)
po/com.mikeasoft.podbird.pot (+44/-3)
To merge this branch: bzr merge lp:~nik90/podbird/3-auto-clean-episodes
Reviewer Review Type Date Requested Status
Michael Sheldon Approve
Review via email: mp+252523@code.launchpad.net

Commit message

Adds a settings option to auto-remove episodes older than a certain time period (based on their published date). The clean-up is done at app-startup once per day.

Description of the change

Adds a settings option to auto-remove episodes older than a certain time period (based on their published date). The clean-up is done at app-startup once per day.

Screenie: http://imgur.com/KjNdeP1

To post a comment you must log in.
48. By Nekhelesh Ramananthan

Set default retention days to never

49. By Nekhelesh Ramananthan

Fixed listitem height

50. By Nekhelesh Ramananthan

Merged prerequisite lp:~nik90/podbird/2-add-button-feedback

Revision history for this message
Michael Sheldon (michael-sheldon) wrote :

Looks good :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/podbird.qml'
2--- app/podbird.qml 2015-03-27 15:38:51 +0000
3+++ app/podbird.qml 2015-03-27 15:38:51 +0000
4@@ -45,6 +45,16 @@
5 downloader.cancel();
6 }
7
8+ Component.onCompleted: {
9+ var today = new Date()
10+ // Only perform cleanup of old episodes once a day
11+ if (Math.floor((today - settings.lastCheck)/86400000) >= 1 && settings.retentionDays !== -1) {
12+ console.log("[LOG]: Starting cleanup of old episodes..")
13+ cleanUp(today, settings.retentionDays)
14+ settings.lastCheck = today
15+ }
16+ }
17+
18 property string currentName
19 property string currentArtist
20 property string currentImage
21@@ -61,6 +71,8 @@
22 property var settings: Settings {
23 // Set "Light.qml" as the default theme
24 property string themeName: "Light.qml"
25+ property int retentionDays: -1
26+ property var lastCheck: new Date()
27 }
28
29 FileManager {
30@@ -175,4 +187,23 @@
31 }
32 }
33 }
34+
35+ function cleanUp(today, retentionDays) {
36+ var dayToMs = 86400000; //1 * 24 * 60 * 60 * 1000
37+ var db = Podcasts.init()
38+ db.transaction(function (tx) {
39+ var rs = tx.executeSql("SELECT rowid, * FROM Podcast ORDER BY name ASC");
40+ for(var i = 0; i < rs.rows.length; i++) {
41+ var podcast = rs.rows.item(i);
42+ var rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE podcast=?", [rs.rows.item(i).rowid]);
43+ for (var j=0; j< rs2.rows.length; j++) {
44+ var diff = Math.floor((today - rs2.rows.item(j).published)/dayToMs)
45+ if (rs2.rows.item(j).downloadedfile && diff > retentionDays) {
46+ fileManager.deleteFile(rs2.rows.item(j).downloadedfile)
47+ tx.executeSql("UPDATE Episode SET downloadedfile = NULL WHERE guid = ?", [rs2.rows.item(j).guid]);
48+ }
49+ }
50+ }
51+ });
52+ }
53 }
54
55=== modified file 'app/ui/SettingsTab.qml'
56--- app/ui/SettingsTab.qml 2015-03-27 15:38:51 +0000
57+++ app/ui/SettingsTab.qml 2015-03-27 15:38:51 +0000
58@@ -30,35 +30,86 @@
59
60 ListModel {
61 id: themeModel
62- ListElement { name: "Light"; file: "Light.qml" }
63- ListElement { name: "Dark"; file: "Dark.qml" }
64- }
65-
66- ExpandableListItem {
67- id: themeSetting
68-
69- model: themeModel
70- text: i18n.tr("Theme")
71- subText: podbird.settings.themeName.split(".qml")[0]
72-
73- delegate: ListItem.Standard {
74- text: model.name
75-
76- onClicked: {
77- var themeElement = model.file
78- podbird.settings.themeName = themeElement
79- podbird.themeManager.source = themeElement
80- themeSetting.expanded = false
81+ Component.onCompleted: initialize()
82+ function initialize() {
83+ themeModel.append({ name: i18n.tr("Light"), file: "Light.qml" })
84+ themeModel.append({ name: i18n.tr("Dark"), file: "Dark.qml" })
85+ }
86+ }
87+
88+ ListModel {
89+ id: cleanupModel
90+ Component.onCompleted: initialize()
91+ function initialize() {
92+ cleanupModel.append({ name: i18n.tr("Never"), value: -1 })
93+ cleanupModel.append({ name: i18n.tr("7 days"), value: 7 })
94+ cleanupModel.append({ name: i18n.tr("31 days"), value: 31 })
95+ cleanupModel.append({ name: i18n.tr("90 days"), value: 90 })
96+ cleanupModel.append({ name: i18n.tr("180 days"), value: 180 })
97+ cleanupModel.append({ name: i18n.tr("360 days"), value: 360 })
98+ }
99+ }
100+
101+ Column {
102+ id: settingsColumn
103+
104+ anchors.fill: parent
105+
106+ ExpandableListItem {
107+ id: themeSetting
108+
109+ model: themeModel
110+ text: i18n.tr("Theme")
111+ subText: podbird.settings.themeName.split(".qml")[0]
112+
113+ delegate: ListItem.Standard {
114+ text: model.name
115+
116+ onClicked: {
117+ var themeElement = model.file
118+ podbird.settings.themeName = themeElement
119+ podbird.themeManager.source = themeElement
120+ themeSetting.expanded = false
121+ }
122+
123+ Icon {
124+ width: units.gu(2)
125+ height: width
126+ name: "ok"
127+ visible: podbird.settings.themeName === model.file
128+ anchors.right: parent.right
129+ anchors.rightMargin: units.gu(2)
130+ anchors.verticalCenter: parent.verticalCenter
131+ }
132 }
133-
134- Icon {
135- width: units.gu(2)
136- height: width
137- name: "ok"
138- visible: podbird.settings.themeName === model.file
139- anchors.right: parent.right
140- anchors.rightMargin: units.gu(2)
141- anchors.verticalCenter: parent.verticalCenter
142+ }
143+
144+ ExpandableListItem {
145+ id: cleanupSetting
146+
147+ listViewHeight: units.gu(36)
148+ model: cleanupModel
149+ text: i18n.tr("Remove episodes older than")
150+ subText: podbird.settings.retentionDays === -1 ? i18n.tr("Never")
151+ : i18n.tr("%1 days").arg(podbird.settings.retentionDays)
152+
153+ delegate: ListItem.Standard {
154+ text: model.name
155+
156+ onClicked: {
157+ podbird.settings.retentionDays = model.value
158+ cleanupSetting.expanded = false
159+ }
160+
161+ Icon {
162+ width: units.gu(2)
163+ height: width
164+ name: "ok"
165+ visible: podbird.settings.retentionDays === model.value
166+ anchors.right: parent.right
167+ anchors.rightMargin: units.gu(2)
168+ anchors.verticalCenter: parent.verticalCenter
169+ }
170 }
171 }
172 }
173
174=== modified file 'po/com.mikeasoft.podbird.pot'
175--- po/com.mikeasoft.podbird.pot 2015-03-27 15:38:51 +0000
176+++ po/com.mikeasoft.podbird.pot 2015-03-27 15:38:51 +0000
177@@ -8,7 +8,7 @@
178 msgstr ""
179 "Project-Id-Version: \n"
180 "Report-Msgid-Bugs-To: \n"
181-"POT-Creation-Date: 2015-03-27 16:30+0100\n"
182+"POT-Creation-Date: 2015-03-27 16:34+0100\n"
183 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
184 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
185 "Language-Team: LANGUAGE <LL@li.org>\n"
186@@ -164,10 +164,51 @@
187 msgid "Settings"
188 msgstr ""
189
190-#: ../app/ui/SettingsTab.qml:41
191+#: ../app/ui/SettingsTab.qml:35
192+msgid "Light"
193+msgstr ""
194+
195+#: ../app/ui/SettingsTab.qml:36
196+msgid "Dark"
197+msgstr ""
198+
199+#: ../app/ui/SettingsTab.qml:44 ../app/ui/SettingsTab.qml:93
200+msgid "Never"
201+msgstr ""
202+
203+#: ../app/ui/SettingsTab.qml:45
204+msgid "7 days"
205+msgstr ""
206+
207+#: ../app/ui/SettingsTab.qml:46
208+msgid "31 days"
209+msgstr ""
210+
211+#: ../app/ui/SettingsTab.qml:47
212+msgid "90 days"
213+msgstr ""
214+
215+#: ../app/ui/SettingsTab.qml:48
216+msgid "180 days"
217+msgstr ""
218+
219+#: ../app/ui/SettingsTab.qml:49
220+msgid "360 days"
221+msgstr ""
222+
223+#: ../app/ui/SettingsTab.qml:62
224 msgid "Theme"
225 msgstr ""
226
227-#: /home/krnekhelesh/Documents/Ubuntu-Projects/MP-Reviews/builddir/build-2-add-button-feedback-UbuntuSDK_for_armhf_GCC_ubuntu_sdk_14_10_utopic-Default/po/Podbird.desktop.in.h:1
228+#: ../app/ui/SettingsTab.qml:92
229+msgid "Remove episodes older than"
230+msgstr ""
231+
232+#: ../app/ui/SettingsTab.qml:94
233+#, qt-format
234+msgid "%1 days"
235+msgstr ""
236+
237+#: /home/krnekhelesh/Documents/Ubuntu-Projects/MP-Reviews/builddir/build-3-auto-clean-episodes-UbuntuSDK_for_armhf_GCC_ubuntu_sdk_14_10_utopic-Default/po/Podbird.desktop.in.h:1
238 msgid "Podbird"
239 msgstr ""

Subscribers

People subscribed via source and target branches