Debian Codegraph @

src/app/qml/components/AboutTroubleshooting.qml

raw
1 /*
2 * Copyright (C) 2021 UBports Foundation
3 *
4 * This file is part of Lomiri Weather App
5 *
6 * Lomiri Weather App is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * Lomiri Weather 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 import QtQuick 2.12
20 import Lomiri.Components 1.3
21 import Lomiri.Components.Popups 1.3 as UC //for Dialogs
22 import io.thp.pyotherside 1.4 //for Python
23 import Qt.labs.folderlistmodel 2.1 //for FolderListModel
24 import Qt.labs.platform 1.0 //for StandardPaths
25
26 Page {
27 id: aboutTroubeshootingPage
28
29 property url cacheDir: StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/qmlcache"
30
31 Flickable {
32 id: troubleshootingFlickable
33 clip: true
34 flickableDirection: Flickable.AutoFlickIfNeeded
35 boundsBehavior: Flickable.StopAtBounds
36
37 anchors {
38 topMargin: units.gu(2)
39 fill: parent
40 }
41
42 contentHeight: troubleshootingColumn.childrenRect.height
43
44 Column {
45 id: troubleshootingColumn
46
47 anchors {
48 top: parent.top
49 left: parent.left
50 right: parent.right
51 }
52
53 Label {
54 id: headlineLinksLabel
55 text: i18n.tr("If you encounter problems, please go through the following steps and try again:") + "\n"
56 wrapMode: Text.WordWrap
57 anchors {
58 left: parent.left
59 leftMargin: units.gu(2)
60 right: parent.right
61 rightMargin: units.gu(2)
62 }
63 }
64
65 Repeater {
66 id: listViewTroubleshooting
67
68 model: [
69 {
70 title: i18n.ctr("troubleshooting, step title","%1 Restart the app").arg("1."),
71 description: i18n.ctr("troubleshooting, description how to restart the app","Close the app, then restart it as usual."),
72 buttonText: i18n.tr("Close weather app"),
73 buttonAction: "quitAction"
74 },{
75 title: i18n.ctr("troubleshooting, step title","%1 Update the app").arg("2."),
76 description: i18n.ctr("troubleshooting, description how to update the app","Close the app, then open OpenStore app and check for updates for weather app."),
77 buttonText: i18n.tr("Close weather app"),
78 buttonAction: "quitAction"
79 },
80 {
81 title: i18n.ctr("troubleshooting, step title","%1 Reboot the device").arg("3."),
82 description: i18n.ctr("troubleshooting, description how to reboot","Press and hold the power button to raise the system dialog and select 'reboot' there. Alternatively use the same option from the system indicator."),
83 buttonText: i18n.tr("Reboot device"),
84 buttonAction: "" //"rebootAction"
85 },
86 {
87 title: i18n.ctr("troubleshooting, step title","%1 Clear the cache").arg("4."),
88 description: i18n.ctr("troubleshooting, description how to clear the cache","Clear the cache with the button below, use the app UT Tweak Tool or delete the content of the <i>~/.cache/weather.ubports</i> folder."),
89 buttonText: i18n.tr("Clear cache now"),
90 buttonAction: "clearCacheAction"
91 },
92 {
93 title: i18n.ctr("troubleshooting, step title","%1 Re-add locations").arg("5."),
94 description: i18n.ctr("troubleshooting, description how to delete the locations","Delete your locations in the locations list (see usage tab). Then add them again. Or manually delete the database in <i>~/local/share/weather.ubports</i>."),
95 buttonText: i18n.tr("Go back to main page"),
96 buttonAction: "openLocationListAction"
97 },
98 {
99 title: i18n.ctr("troubleshooting, step title","%1 Delete the apps settings").arg("6."),
100 description: i18n.ctr("troubleshooting, description how to delete the locations","Delete the apps settings either using the UT Tweak Tool or manually by deleting the config file in <i>~/.config/weather.ubports</i>."),
101 buttonText: i18n.tr("Go back to main page"),
102 buttonAction: "openLocationListAction"
103 },
104 {
105 title: i18n.ctr("troubleshooting, step title","%1 Check the log").arg("7."),
106 description: i18n.ctr("troubleshooting, description how to get the log and open an issue","If the instructions above did not solve the problem, please open an issue and provide the app log. One way to obtain the log is with Logviewer app. This app allows uploading the log to a pastebin. Provide the link to the pasted log in the error report. Another option is to manually copy the log file. It can be found under <i>~/.cache/upstart/application-click-com.ubuntu.weather_weather_VERSION.log\</i>. If no logfile for weather app is present, please temporary enable developer mode (system settings -> info -> developer mode). This will make the log persist."),
107 buttonText: "",//i18n.tr("Share log"),
108 buttonAction: "" //"openLogAction"
109 },
110 {
111 title: i18n.ctr("troubleshooting, step title","%1 Open an issue on GitLab").arg("8."),
112 description: i18n.ctr("troubleshooting, description how to open an issue","Please go to <i>https://gitlab.com/ubports/apps/weather-app/-/issues</i> and file an error report there. Please provide the following information: the version of the app, the name of your device, your release channel, a description of what you did and which problems you encountered."),
113 buttonText: i18n.tr("Open issue tracker"),
114 buttonAction: "openGitAction"
115 }
116 ]
117
118 delegate: Column {
119 id: delegateColumn
120 height: childrenRect.height
121 width: parent.width - units.gu(4)
122 spacing: units.gu(1)
123 anchors {
124 left: parent.left
125 leftMargin: units.gu(2)
126 right: parent.right
127 rightMargin: units.gu(2)
128 }
129 Label {
130 id: titleLabel
131 text: modelData.title
132 font.bold: true
133 }
134 Label {
135 id: descriptionLabel
136 visible: modelData.description != ""
137 width: parent.width
138 text: modelData.description
139 wrapMode: Text.WordWrap
140 horizontalAlignment: Text.AlignJustify
141 }
142 Button{
143 text: modelData.buttonText
144 visible: modelData.buttonAction != ""
145 color: {
146 if (modelData.buttonAction != "openGitAction" && modelData.buttonAction != "openLocationListAction") {
147 return theme.palette.normal.negative
148 } else return theme.palette.normal.activity
149 }
150 onClicked: {
151 if (modelData.buttonAction === "quitAction") {
152 Qt.quit()
153 } else if (modelData.buttonAction === "rebootAction") {
154 //currently there is no confined way to reboot the device, so this will stay unimplemented for now
155 } else if (modelData.buttonAction === "clearCacheAction") {
156 //FolderListModel ignores the supplied folder URL if it doesn't exist, and instead uses the app's CWD
157 //we *DON'T* want to delete things in the CWD
158 console.log("Cache folder model should be looking at:", aboutTroubeshootingPage.cacheDir)
159 console.log("Cache folder model is actually looking at:", folderModel.folder)
160 if (folderModel.folder !== aboutTroubeshootingPage.cacheDir) {
161 console.log("Cache directory doesn't seem to exist, nothing to delete")
162 } else {
163 //delete the cached files one by one using the python os module
164 //we could just delete the folder, but some cached files are used while the app is running
165 //by deleting files one by one there should be a write lock on used files
166 for (var i = 0; i < folderModel.count; i ++) {
167 const urlToDelete = folderModel.get (i, "fileURL").toString().replace("file://","")
168 console.log("Attempting to delete:", urlToDelete);
169 py.call('os.remove', [urlToDelete], function (result) {
170 //TODO: add error handling
171 })
172 }
173 }
174 PopupUtils.open(cacheClearedDialog)
175 } else if (modelData.buttonAction === "openLogAction") {
176 //TODO: implement log action
177 } else if (modelData.buttonAction === "openGitAction") {
178 Qt.openUrlExternally("https://gitlab.com/ubports/development/apps/lomiri-weather-app/-/issues")
179 } else if (modelData.buttonAction === "openLocationListAction") {
180 while (mainPageStack.depth > 1) {
181 mainPageStack.pop()
182 }
183 }
184 }
185 }
186 Rectangle {
187 id: delegateSpacer
188 width: parent.width
189 height: units.gu(2)
190 color: "transparent"
191 }
192 }
193 }
194 }
195 }
196
197 property string messagetext
198
199 Component {
200 id: cacheClearedDialog
201
202 UC.Dialog {
203 id: cacheDialog
204 title: i18n.tr("Cache cleared.")
205
206 Label {
207 id: messageLabel
208 text: messagetext
209 }
210
211 Button {
212 text: i18n.tr("OK")
213 onClicked: PopupUtils.close(cacheDialog)
214 }
215 }
216 }
217
218 //initiate a Python component for calls to Python commands
219 Python {
220 id: py
221
222 Component.onCompleted: {
223 //this works as the import statement in a python script
224 importModule('os', function() { console.log("DEBUG: python loaded"); });
225 }
226 }
227 //used to read all files from the apps .cache folder
228 FolderListModel {
229 id: folderModel
230 folder: aboutTroubeshootingPage.cacheDir
231 nameFilters: ["*.qmlc","*.jsc"]
232 }
233
234 }