Rearange menu of mpegplayer. Add new menu with "settings" and "quit", and remove...
[kugel-rb.git] / rbutil / rbutilqt / progressloggergui.cpp
blobde2be96165058537235fe6db2c2dfbe6b1dc3801
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id$
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"
22 #include "sysinfo.h"
23 #include "systrace.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);
31 dp.saveLog->hide();
32 connect(dp.saveLog,SIGNAL(clicked()),this,SLOT(saveErrorLog()));
33 setRunning();
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);
45 switch(flag)
47 case LOGNOICON:
48 break;
49 case LOGOK:
50 item->setIcon(QIcon(":/icons/go-next.png"));
51 break;
52 case LOGINFO:
53 item->setIcon(QIcon(":/icons/dialog-information.png"));
54 break;
55 case LOGWARNING:
56 item->setIcon(QIcon(":/icons/dialog-warning.png"));
57 break;
58 case LOGERROR:
59 item->setIcon(QIcon(":/icons/dialog-error.png"));
60 dp.saveLog->show();
61 break;
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.
73 setProgressMax(max);
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");
148 QFile file(filename);
149 file.open(QIODevice::WriteOnly);
151 //Logger texts
152 QString loggerTexts = "\n*********************************************\n"
153 "*************** Logger *******************\n"
154 "*********************************************\n";
155 file.write(loggerTexts.toUtf8(), loggerTexts.size());
158 int i=0;
159 loggerTexts = "";
160 while(dp.listProgress->item(i) != NULL)
162 loggerTexts.append(dp.listProgress->item(i)->text());
163 loggerTexts.append("\n");
164 i++;
166 file.write(loggerTexts.toUtf8(), loggerTexts.size());
168 //systeminfo
169 QString info = "\n*********************************************\n"
170 "************ SYSTEMINFO *******************\n"
171 "*********************************************\n";
173 file.write(info.toUtf8(), info.size());
174 info = Sysinfo::getInfo();
175 info.replace(QRegExp("(<[^>]+>)+"),"\n");
176 file.write(info.toUtf8(), info.size());
178 // trace
179 QString trace = "\n*********************************************\n"
180 "*********** TRACE **************************\n"
181 "*********************************************\n";
182 file.write(trace.toUtf8(), trace.size());
183 trace = SysTrace::getTrace();
184 file.write(trace.toUtf8(), trace.size());
186 file.close();