1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "progressloggergui.h"
25 ProgressLoggerGui::ProgressLoggerGui(QWidget
* parent
): ProgressloggerInterface(parent
)
27 downloadProgress
= new QDialog(parent
);
28 downloadProgress
->setModal(true);
29 dp
.setupUi(downloadProgress
);
30 dp
.listProgress
->setAlternatingRowColors(true);
32 connect(dp
.saveLog
,SIGNAL(clicked()),this,SLOT(saveErrorLog()));
36 void ProgressLoggerGui::addItem(const QString
&text
)
38 addItem(text
, LOGNOICON
);
41 void ProgressLoggerGui::addItem(const QString
&text
, int flag
)
43 QListWidgetItem
* item
= new QListWidgetItem(text
);
50 item
->setIcon(QIcon(":/icons/go-next.png"));
53 item
->setIcon(QIcon(":/icons/dialog-information.png"));
56 item
->setIcon(QIcon(":/icons/dialog-warning.png"));
59 item
->setIcon(QIcon(":/icons/dialog-error.png"));
64 dp
.listProgress
->addItem(item
);
65 dp
.listProgress
->scrollToItem(item
);
68 void ProgressLoggerGui::setProgress(int value
, int max
)
70 // set maximum first to avoid setting a value outside of the max range.
71 // If the current value is outside of the valid range QProgressBar
72 // calls reset() internally.
74 setProgressValue(value
);
78 void ProgressLoggerGui::setProgressValue(int value
)
80 dp
.progressBar
->setValue(value
);
83 void ProgressLoggerGui::setProgressMax(int max
)
85 dp
.progressBar
->setMaximum(max
);
88 int ProgressLoggerGui::getProgressMax()
90 return dp
.progressBar
->maximum();
93 void ProgressLoggerGui::setProgressVisible(bool b
)
95 dp
.progressBar
->setVisible(b
);
99 /** Set logger into "running" state -- the reporting process is still running.
100 * Display "Abort" and emit the aborted() signal on button press.
102 void ProgressLoggerGui::setRunning()
104 dp
.buttonAbort
->setText(tr("&Abort"));
105 dp
.buttonAbort
->setIcon(QIcon(QString::fromUtf8(":/icons/process-stop.png")));
107 // make sure to not close the window on button press.
108 disconnect(dp
.buttonAbort
, SIGNAL(clicked()), downloadProgress
, SLOT(close()));
109 // emit aborted() once button is pressed but not closed().
110 disconnect(dp
.buttonAbort
, SIGNAL(clicked()), this, SIGNAL(closed()));
111 connect(dp
.buttonAbort
, SIGNAL(clicked()), this, SIGNAL(aborted()));
116 /** Set logger into "finished" state -- the reporting process is finished.
117 * Display "Ok". Don't emit aborted() as there is nothing running left.
118 * Close logger on button press and emit closed().
120 void ProgressLoggerGui::setFinished()
122 dp
.buttonAbort
->setText(tr("&Ok"));
123 dp
.buttonAbort
->setIcon(QIcon(QString::fromUtf8(":/icons/go-next.png")));
125 // close the window on button press.
126 connect(dp
.buttonAbort
, SIGNAL(clicked()), downloadProgress
, SLOT(close()));
127 // emit closed() once button is pressed but not aborted().
128 disconnect(dp
.buttonAbort
, SIGNAL(clicked()), this, SIGNAL(aborted()));
129 connect(dp
.buttonAbort
, SIGNAL(clicked()), this, SIGNAL(closed()));
133 void ProgressLoggerGui::close()
135 downloadProgress
->close();
138 void ProgressLoggerGui::show()
140 downloadProgress
->show();
143 void ProgressLoggerGui::saveErrorLog()
145 QString filename
= QFileDialog::getSaveFileName(downloadProgress
, tr("Save system trace log"),
146 QDir::homePath(), "*.log");
150 QFile
file(filename
);
151 if(!file
.open(QIODevice::WriteOnly
))
155 QString loggerTexts
= "\n*********************************************\n"
156 "*************** Logger *******************\n"
157 "*********************************************\n";
158 file
.write(loggerTexts
.toUtf8(), loggerTexts
.size());
163 while(dp
.listProgress
->item(i
) != NULL
)
165 loggerTexts
.append(dp
.listProgress
->item(i
)->text());
166 loggerTexts
.append("\n");
169 file
.write(loggerTexts
.toUtf8(), loggerTexts
.size());
172 QString info
= "\n*********************************************\n"
173 "************ SYSTEMINFO *******************\n"
174 "*********************************************\n";
176 file
.write(info
.toUtf8(), info
.size());
177 info
= Sysinfo::getInfo();
178 info
.replace(QRegExp("(<[^>]+>)+"),"\n");
179 file
.write(info
.toUtf8(), info
.size());
182 QString trace
= "\n*********************************************\n"
183 "*********** TRACE **************************\n"
184 "*********************************************\n";
185 file
.write(trace
.toUtf8(), trace
.size());
186 trace
= SysTrace::getTrace();
187 file
.write(trace
.toUtf8(), trace
.size());