1 #include "mainwindow.h"
4 #include "apitracecall.h"
5 #include "apicalldelegate.h"
6 #include "apitracemodel.h"
7 #include "apitracefilter.h"
12 #include <QFileDialog>
14 #include <QMessageBox>
16 #include <QProgressBar>
21 MainWindow::MainWindow()
27 m_trace = new ApiTrace();
28 connect(m_trace, SIGNAL(startedLoadingTrace()),
29 this, SLOT(startedLoadingTrace()));
30 connect(m_trace, SIGNAL(finishedLoadingTrace()),
31 this, SLOT(finishedLoadingTrace()));
33 m_model = new ApiTraceModel();
34 m_model->setApiTrace(m_trace);
35 m_proxyModel = new ApiTraceFilter();
36 m_proxyModel->setSourceModel(m_model);
37 m_ui.callView->setModel(m_proxyModel);
38 m_ui.callView->setItemDelegate(new ApiCallDelegate);
39 for (int column = 0; column < m_model->columnCount(); ++column)
40 m_ui.callView->resizeColumnToContents(column);
42 QToolBar *toolBar = addToolBar(tr("Navigation"));
43 m_filterEdit = new QLineEdit(toolBar);
44 toolBar->addWidget(m_filterEdit);
46 m_progressBar = new QProgressBar();
47 m_progressBar->setRange(0, 0);
48 statusBar()->addPermanentWidget(m_progressBar);
49 m_progressBar->hide();
51 m_ui.detailsDock->hide();
53 connect(m_ui.actionOpen, SIGNAL(triggered()),
54 this, SLOT(openTrace()));
55 connect(m_ui.actionQuit, SIGNAL(triggered()),
58 connect(m_ui.actionReplay, SIGNAL(triggered()),
59 this, SLOT(replayStart()));
60 connect(m_ui.actionStop, SIGNAL(triggered()),
61 this, SLOT(replayStop()));
63 connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
64 this, SLOT(callItemSelected(const QModelIndex &)));
65 connect(m_filterEdit, SIGNAL(returnPressed()),
66 this, SLOT(filterTrace()));
69 void MainWindow::openTrace()
72 QFileDialog::getOpenFileName(
76 tr("Trace Files (*.trace)"));
78 qDebug()<< "File name : " <<fileName;
80 newTraceFile(fileName);
83 void MainWindow::loadTrace(const QString &fileName)
85 if (!QFile::exists(fileName)) {
86 QMessageBox::warning(this, tr("File Missing"),
87 tr("File '%1' doesn't exist.").arg(fileName));
90 qDebug()<< "Loading : " <<fileName;
92 m_progressBar->setValue(0);
93 newTraceFile(fileName);
96 void MainWindow::callItemSelected(const QModelIndex &index)
98 ApiTraceCall *call = index.data().value<ApiTraceCall*>();
100 m_ui.detailsWebView->setHtml(call->toHtml());
101 m_ui.detailsDock->show();
103 m_ui.detailsDock->hide();
107 void MainWindow::filterTrace()
109 m_proxyModel->setFilterString(m_filterEdit->text());
112 void MainWindow::replayStart()
114 if (!m_replayProcess) {
116 QString format = QLatin1String("%1;");
118 QString format = QLatin1String("%1:");
120 QString buildPath = format.arg(BUILD_DIR);
121 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
122 env.insert("PATH", buildPath + env.value("PATH"));
124 qputenv("PATH", env.value("PATH").toLatin1());
126 m_replayProcess = new QProcess(this);
127 m_replayProcess->setProcessEnvironment(env);
129 connect(m_replayProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
130 this, SLOT(replayFinished()));
131 connect(m_replayProcess, SIGNAL(error(QProcess::ProcessError)),
132 this, SLOT(replayError(QProcess::ProcessError)));
135 if (m_traceFileName.isEmpty())
138 QStringList arguments;
139 arguments << m_traceFileName;
141 m_replayProcess->start(QLatin1String("glretrace"),
144 m_ui.actionStop->setEnabled(true);
145 m_ui.actionReplay->setEnabled(false);
148 void MainWindow::replayStop()
150 if (m_replayProcess) {
151 m_replayProcess->kill();
153 m_ui.actionStop->setEnabled(false);
154 m_ui.actionReplay->setEnabled(true);
158 void MainWindow::newTraceFile(const QString &fileName)
160 m_traceFileName = fileName;
161 m_trace->setFileName(fileName);
163 if (m_traceFileName.isEmpty()) {
164 m_ui.actionReplay->setEnabled(false);
166 m_ui.actionReplay->setEnabled(true);
170 void MainWindow::replayFinished()
172 m_ui.actionStop->setEnabled(false);
173 m_ui.actionReplay->setEnabled(true);
175 QString output = m_replayProcess->readAllStandardOutput();
178 qDebug()<<"Process finished = ";
179 qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError();
180 qDebug()<<"\tout = "<<output;
183 if (output.length() < 80) {
184 statusBar()->showMessage(output);
188 void MainWindow::replayError(QProcess::ProcessError err)
190 m_ui.actionStop->setEnabled(false);
191 m_ui.actionReplay->setEnabled(true);
193 qDebug()<<"Process error = "<<err;
194 qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError();
195 qDebug()<<"\tout = "<<m_replayProcess->readAllStandardOutput();
196 QMessageBox::warning(
197 this, tr("Replay Failed"),
198 tr("Couldn't execute the replay file '%1'").arg(m_traceFileName));
201 void MainWindow::startedLoadingTrace()
204 m_progressBar->show();
205 QFileInfo info(m_trace->fileName());
206 statusBar()->showMessage(
207 tr("Loading %1...").arg(info.fileName()));
210 void MainWindow::finishedLoadingTrace()
212 m_progressBar->hide();
216 QFileInfo info(m_trace->fileName());
217 statusBar()->showMessage(
218 tr("Loaded %1").arg(info.fileName()), 3000);
221 #include "mainwindow.moc"