summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/progressloggergui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/progressloggergui.cpp')
-rw-r--r--utils/rbutilqt/progressloggergui.cpp186
1 files changed, 186 insertions, 0 deletions
diff --git a/utils/rbutilqt/progressloggergui.cpp b/utils/rbutilqt/progressloggergui.cpp
new file mode 100644
index 0000000000..37e0908ae0
--- /dev/null
+++ b/utils/rbutilqt/progressloggergui.cpp
@@ -0,0 +1,186 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Dominik Wenger
10 *
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
13 *
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
16 *
17 ****************************************************************************/
18
19#include <QFileDialog>
20#include "progressloggergui.h"
21
22#include "sysinfo.h"
23#include "systrace.h"
24
25ProgressLoggerGui::ProgressLoggerGui(QWidget* parent): ProgressloggerInterface(parent)
26{
27 downloadProgress = new QDialog(parent);
28 downloadProgress->setModal(true);
29 dp.setupUi(downloadProgress);
30 dp.listProgress->setAlternatingRowColors(true);
31 dp.saveLog->hide();
32 connect(dp.saveLog,SIGNAL(clicked()),this,SLOT(saveErrorLog()));
33 setRunning();
34}
35
36void ProgressLoggerGui::addItem(const QString &text, int flag)
37{
38 QListWidgetItem* item = new QListWidgetItem(text);
39
40 switch(flag)
41 {
42 case LOGNOICON:
43 break;
44 case LOGOK:
45 item->setIcon(QIcon(":/icons/go-next.svg"));
46 break;
47 case LOGINFO:
48 item->setIcon(QIcon(":/icons/dialog-information.svg"));
49 break;
50 case LOGWARNING:
51 item->setIcon(QIcon(":/icons/dialog-warning.svg"));
52 break;
53 case LOGERROR:
54 item->setIcon(QIcon(":/icons/dialog-error.svg"));
55 dp.saveLog->show();
56 break;
57 }
58
59 dp.listProgress->addItem(item);
60 dp.listProgress->scrollToItem(item);
61}
62
63void ProgressLoggerGui::setProgress(int value, int max)
64{
65 // set maximum first to avoid setting a value outside of the max range.
66 // If the current value is outside of the valid range QProgressBar
67 // calls reset() internally.
68 setProgressMax(max);
69 setProgressValue(value);
70}
71
72
73void ProgressLoggerGui::setProgressValue(int value)
74{
75 dp.progressBar->setValue(value);
76}
77
78void ProgressLoggerGui::setProgressMax(int max)
79{
80 dp.progressBar->setMaximum(max);
81}
82
83int ProgressLoggerGui::getProgressMax()
84{
85 return dp.progressBar->maximum();
86}
87
88void ProgressLoggerGui::setProgressVisible(bool b)
89{
90 dp.progressBar->setVisible(b);
91}
92
93
94/** Set logger into "running" state -- the reporting process is still running.
95 * Display "Abort" and emit the aborted() signal on button press.
96 */
97void ProgressLoggerGui::setRunning()
98{
99 dp.buttonAbort->setText(tr("&Abort"));
100 dp.buttonAbort->setIcon(QIcon(QString::fromUtf8(":/icons/process-stop.svg")));
101
102 // make sure to not close the window on button press.
103 disconnect(dp.buttonAbort, SIGNAL(clicked()), downloadProgress, SLOT(close()));
104 // emit aborted() once button is pressed but not closed().
105 disconnect(dp.buttonAbort, SIGNAL(clicked()), this, SIGNAL(closed()));
106 connect(dp.buttonAbort, SIGNAL(clicked()), this, SIGNAL(aborted()));
107
108}
109
110
111/** Set logger into "finished" state -- the reporting process is finished.
112 * Display "Ok". Don't emit aborted() as there is nothing running left.
113 * Close logger on button press and emit closed().
114 */
115void ProgressLoggerGui::setFinished()
116{
117 dp.buttonAbort->setText(tr("&Ok"));
118 dp.buttonAbort->setIcon(QIcon(QString::fromUtf8(":/icons/go-next.svg")));
119
120 // close the window on button press.
121 connect(dp.buttonAbort, SIGNAL(clicked()), downloadProgress, SLOT(close()));
122 // emit closed() once button is pressed but not aborted().
123 disconnect(dp.buttonAbort, SIGNAL(clicked()), this, SIGNAL(aborted()));
124 connect(dp.buttonAbort, SIGNAL(clicked()), this, SIGNAL(closed()));
125}
126
127
128void ProgressLoggerGui::close()
129{
130 downloadProgress->close();
131}
132
133void ProgressLoggerGui::show()
134{
135 downloadProgress->show();
136}
137
138void ProgressLoggerGui::saveErrorLog()
139{
140 QString filename = QFileDialog::getSaveFileName(downloadProgress,
141 tr("Save system trace log"), QDir::homePath(), "*.log");
142 if(filename.isEmpty())
143 return;
144
145 QFile file(filename);
146 if(!file.open(QIODevice::WriteOnly))
147 return;
148
149 //Logger texts
150 QString loggerTexts = "\n*********************************************\n"
151 "*************** Logger *******************\n"
152 "*********************************************\n";
153
154 file.write(loggerTexts.toUtf8(), loggerTexts.size());
155
156
157 int i=0;
158 loggerTexts = "";
159 while(dp.listProgress->item(i) != nullptr)
160 {
161 loggerTexts.append(dp.listProgress->item(i)->text());
162 loggerTexts.append("\n");
163 i++;
164 }
165 file.write(loggerTexts.toUtf8(), loggerTexts.size());
166
167 //systeminfo
168 QString info = "\n*********************************************\n"
169 "************ SYSTEMINFO *******************\n"
170 "*********************************************\n";
171
172 file.write(info.toUtf8(), info.size());
173 info = Sysinfo::getInfo(Sysinfo::InfoText);
174 file.write(info.toUtf8(), info.size());
175
176 // trace
177 QString trace = "\n*********************************************\n"
178 "*********** TRACE **************************\n"
179 "*********************************************\n";
180 file.write(trace.toUtf8(), trace.size());
181 trace = SysTrace::getTrace();
182 file.write(trace.toUtf8(), trace.size());
183
184 file.close();
185}
186