Improve voice creation window a bit.
[maemo-rb.git] / rbutil / rbutilqt / progressloggergui.cpp
blobf6b33bc11e842c59b722a6cd3c111e0563628cf9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
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.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include "progressloggergui.h"
21 #include "sysinfo.h"
22 #include "systrace.h"
24 ProgressLoggerGui::ProgressLoggerGui(QWidget* parent): ProgressloggerInterface(parent)
26 downloadProgress = new QDialog(parent);
27 downloadProgress->setModal(true);
28 dp.setupUi(downloadProgress);
29 dp.listProgress->setAlternatingRowColors(true);
30 dp.saveLog->hide();
31 connect(dp.saveLog,SIGNAL(clicked()),this,SLOT(saveErrorLog()));
32 setRunning();
35 void ProgressLoggerGui::addItem(const QString &text)
37 addItem(text, LOGNOICON);
40 void ProgressLoggerGui::addItem(const QString &text, int flag)
42 QListWidgetItem* item = new QListWidgetItem(text);
44 switch(flag)
46 case LOGNOICON:
47 break;
48 case LOGOK:
49 item->setIcon(QIcon(":/icons/go-next.png"));
50 break;
51 case LOGINFO:
52 item->setIcon(QIcon(":/icons/dialog-information.png"));
53 break;
54 case LOGWARNING:
55 item->setIcon(QIcon(":/icons/dialog-warning.png"));
56 break;
57 case LOGERROR:
58 item->setIcon(QIcon(":/icons/dialog-error.png"));
59 dp.saveLog->show();
60 break;
63 dp.listProgress->addItem(item);
64 dp.listProgress->scrollToItem(item);
67 void ProgressLoggerGui::setProgress(int value, int max)
69 // set maximum first to avoid setting a value outside of the max range.
70 // If the current value is outside of the valid range QProgressBar
71 // calls reset() internally.
72 setProgressMax(max);
73 setProgressValue(value);
77 void ProgressLoggerGui::setProgressValue(int value)
79 dp.progressBar->setValue(value);
82 void ProgressLoggerGui::setProgressMax(int max)
84 dp.progressBar->setMaximum(max);
87 int ProgressLoggerGui::getProgressMax()
89 return dp.progressBar->maximum();
92 void ProgressLoggerGui::setProgressVisible(bool b)
94 dp.progressBar->setVisible(b);
98 /** Set logger into "running" state -- the reporting process is still running.
99 * Display "Abort" and emit the aborted() signal on button press.
101 void ProgressLoggerGui::setRunning()
103 dp.buttonAbort->setText(tr("&Abort"));
104 dp.buttonAbort->setIcon(QIcon(QString::fromUtf8(":/icons/process-stop.png")));
106 // make sure to not close the window on button press.
107 disconnect(dp.buttonAbort, SIGNAL(clicked()), downloadProgress, SLOT(close()));
108 // emit aborted() once button is pressed but not closed().
109 disconnect(dp.buttonAbort, SIGNAL(clicked()), this, SIGNAL(closed()));
110 connect(dp.buttonAbort, SIGNAL(clicked()), this, SIGNAL(aborted()));
115 /** Set logger into "finished" state -- the reporting process is finished.
116 * Display "Ok". Don't emit aborted() as there is nothing running left.
117 * Close logger on button press and emit closed().
119 void ProgressLoggerGui::setFinished()
121 dp.buttonAbort->setText(tr("&Ok"));
122 dp.buttonAbort->setIcon(QIcon(QString::fromUtf8(":/icons/go-next.png")));
124 // close the window on button press.
125 connect(dp.buttonAbort, SIGNAL(clicked()), downloadProgress, SLOT(close()));
126 // emit closed() once button is pressed but not aborted().
127 disconnect(dp.buttonAbort, SIGNAL(clicked()), this, SIGNAL(aborted()));
128 connect(dp.buttonAbort, SIGNAL(clicked()), this, SIGNAL(closed()));
132 void ProgressLoggerGui::close()
134 downloadProgress->close();
137 void ProgressLoggerGui::show()
139 downloadProgress->show();
142 void ProgressLoggerGui::saveErrorLog()
144 QString filename = QFileDialog::getSaveFileName(downloadProgress, tr("Save system trace log"),
145 QDir::homePath(), "*.log");
146 if(filename == "")
147 return;
149 QFile file(filename);
150 if(!file.open(QIODevice::WriteOnly))
151 return;
153 //Logger texts
154 QString loggerTexts = "\n*********************************************\n"
155 "*************** Logger *******************\n"
156 "*********************************************\n";
157 file.write(loggerTexts.toUtf8(), loggerTexts.size());
160 int i=0;
161 loggerTexts = "";
162 while(dp.listProgress->item(i) != NULL)
164 loggerTexts.append(dp.listProgress->item(i)->text());
165 loggerTexts.append("\n");
166 i++;
168 file.write(loggerTexts.toUtf8(), loggerTexts.size());
170 //systeminfo
171 QString info = "\n*********************************************\n"
172 "************ SYSTEMINFO *******************\n"
173 "*********************************************\n";
175 file.write(info.toUtf8(), info.size());
176 info = Sysinfo::getInfo();
177 info.replace(QRegExp("(<[^>]+>)+"),"\n");
178 file.write(info.toUtf8(), info.size());
180 // trace
181 QString trace = "\n*********************************************\n"
182 "*********** TRACE **************************\n"
183 "*********************************************\n";
184 file.write(trace.toUtf8(), trace.size());
185 trace = SysTrace::getTrace();
186 file.write(trace.toUtf8(), trace.size());
188 file.close();