Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 1 | #include "mainwindow.h" |
| 2 | |
Zack Rusin | 96130ac | 2011-03-27 01:48:36 -0400 | [diff] [blame] | 3 | #include "apitracecall.h" |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 4 | #include "apicalldelegate.h" |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 5 | #include "apitracemodel.h" |
Zack Rusin | 9106537 | 2011-03-26 01:54:10 -0400 | [diff] [blame] | 6 | #include "apitracefilter.h" |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 7 | |
| 8 | #include <QAction> |
| 9 | #include <QDebug> |
| 10 | #include <QDir> |
| 11 | #include <QFileDialog> |
Zack Rusin | 27cb2c4 | 2011-03-27 23:53:36 -0400 | [diff] [blame^] | 12 | #include <QLineEdit> |
| 13 | #include <QMessageBox> |
| 14 | #include <QProcess> |
Zack Rusin | ea29545 | 2011-03-27 02:22:13 -0400 | [diff] [blame] | 15 | #include <QToolBar> |
Zack Rusin | 96130ac | 2011-03-27 01:48:36 -0400 | [diff] [blame] | 16 | #include <QWebView> |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 17 | |
| 18 | |
| 19 | MainWindow::MainWindow() |
Zack Rusin | 27cb2c4 | 2011-03-27 23:53:36 -0400 | [diff] [blame^] | 20 | : QMainWindow(), |
| 21 | m_replayProcess(0) |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 22 | { |
| 23 | m_ui.setupUi(this); |
| 24 | |
| 25 | m_model = new ApiTraceModel(); |
Zack Rusin | 9106537 | 2011-03-26 01:54:10 -0400 | [diff] [blame] | 26 | m_proxyModel = new ApiTraceFilter(); |
| 27 | m_proxyModel->setSourceModel(m_model); |
Zack Rusin | 96130ac | 2011-03-27 01:48:36 -0400 | [diff] [blame] | 28 | m_ui.callView->setModel(m_proxyModel); |
Zack Rusin | 18eade5 | 2011-03-26 14:23:35 -0400 | [diff] [blame] | 29 | m_ui.callView->setItemDelegate(new ApiCallDelegate); |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 30 | for (int column = 0; column < m_model->columnCount(); ++column) |
| 31 | m_ui.callView->resizeColumnToContents(column); |
| 32 | |
Zack Rusin | ea29545 | 2011-03-27 02:22:13 -0400 | [diff] [blame] | 33 | QToolBar *toolBar = addToolBar(tr("Navigation")); |
| 34 | m_filterEdit = new QLineEdit(toolBar); |
| 35 | toolBar->addWidget(m_filterEdit); |
| 36 | |
Zack Rusin | 96130ac | 2011-03-27 01:48:36 -0400 | [diff] [blame] | 37 | m_ui.detailsDock->hide(); |
| 38 | |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 39 | connect(m_ui.actionOpen, SIGNAL(triggered()), |
| 40 | this, SLOT(openTrace())); |
Zack Rusin | 27cb2c4 | 2011-03-27 23:53:36 -0400 | [diff] [blame^] | 41 | connect(m_ui.actionQuit, SIGNAL(triggered()), |
| 42 | this, SLOT(close())); |
| 43 | |
| 44 | connect(m_ui.actionReplay, SIGNAL(triggered()), |
| 45 | this, SLOT(replayStart())); |
| 46 | connect(m_ui.actionStop, SIGNAL(triggered()), |
| 47 | this, SLOT(replayStop())); |
| 48 | |
Zack Rusin | 96130ac | 2011-03-27 01:48:36 -0400 | [diff] [blame] | 49 | connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)), |
| 50 | this, SLOT(callItemSelected(const QModelIndex &))); |
Zack Rusin | ea29545 | 2011-03-27 02:22:13 -0400 | [diff] [blame] | 51 | connect(m_filterEdit, SIGNAL(returnPressed()), |
| 52 | this, SLOT(filterTrace())); |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void MainWindow::openTrace() |
| 56 | { |
| 57 | QString fileName = |
| 58 | QFileDialog::getOpenFileName( |
| 59 | this, |
| 60 | tr("Open Trace"), |
| 61 | QDir::homePath(), |
| 62 | tr("Trace Files (*.trace)")); |
| 63 | |
| 64 | qDebug()<< "File name : " <<fileName; |
| 65 | |
Zack Rusin | 27cb2c4 | 2011-03-27 23:53:36 -0400 | [diff] [blame^] | 66 | newTraceFile(fileName); |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 67 | m_model->loadTraceFile(fileName); |
| 68 | } |
| 69 | |
| 70 | void MainWindow::loadTrace(const QString &fileName) |
| 71 | { |
Zack Rusin | 27cb2c4 | 2011-03-27 23:53:36 -0400 | [diff] [blame^] | 72 | if (!QFile::exists(fileName)) { |
| 73 | QMessageBox::warning(this, tr("File Missing"), |
| 74 | tr("File '%1' doesn't exist.").arg(fileName)); |
| 75 | return; |
| 76 | } |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 77 | qDebug()<< "Loading : " <<fileName; |
| 78 | |
| 79 | m_model->loadTraceFile(fileName); |
Zack Rusin | 27cb2c4 | 2011-03-27 23:53:36 -0400 | [diff] [blame^] | 80 | newTraceFile(fileName); |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 81 | } |
| 82 | |
Zack Rusin | 96130ac | 2011-03-27 01:48:36 -0400 | [diff] [blame] | 83 | void MainWindow::callItemSelected(const QModelIndex &index) |
| 84 | { |
| 85 | ApiTraceCall *call = index.data().value<ApiTraceCall*>(); |
| 86 | if (call) { |
Zack Rusin | 27cb2c4 | 2011-03-27 23:53:36 -0400 | [diff] [blame^] | 87 | m_ui.detailsWebView->setHtml(call->toHtml()); |
Zack Rusin | 96130ac | 2011-03-27 01:48:36 -0400 | [diff] [blame] | 88 | m_ui.detailsDock->show(); |
| 89 | } else { |
| 90 | m_ui.detailsDock->hide(); |
| 91 | } |
| 92 | } |
| 93 | |
Zack Rusin | ea29545 | 2011-03-27 02:22:13 -0400 | [diff] [blame] | 94 | void MainWindow::filterTrace() |
| 95 | { |
| 96 | m_proxyModel->setFilterString(m_filterEdit->text()); |
| 97 | } |
| 98 | |
Zack Rusin | 27cb2c4 | 2011-03-27 23:53:36 -0400 | [diff] [blame^] | 99 | void MainWindow::replayStart() |
| 100 | { |
| 101 | if (!m_replayProcess) { |
| 102 | #ifdef Q_OS_WIN |
| 103 | QString format = QLatin1String("%1;"); |
| 104 | #else |
| 105 | QString format = QLatin1String("%1:"); |
| 106 | #endif |
| 107 | QString buildPath = format.arg(BUILD_DIR); |
| 108 | QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); |
| 109 | env.insert("PATH", buildPath + env.value("PATH")); |
| 110 | |
| 111 | qputenv("PATH", env.value("PATH").toLatin1()); |
| 112 | |
| 113 | m_replayProcess = new QProcess(this); |
| 114 | m_replayProcess->setProcessEnvironment(env); |
| 115 | |
| 116 | connect(m_replayProcess, SIGNAL(finished(int, QProcess::ExitStatus)), |
| 117 | this, SLOT(replayFinished())); |
| 118 | connect(m_replayProcess, SIGNAL(error(QProcess::ProcessError)), |
| 119 | this, SLOT(replayError(QProcess::ProcessError))); |
| 120 | } |
| 121 | |
| 122 | if (m_traceFileName.isEmpty()) |
| 123 | return; |
| 124 | |
| 125 | QStringList arguments; |
| 126 | arguments << m_traceFileName; |
| 127 | |
| 128 | m_replayProcess->start(QLatin1String("glretrace"), |
| 129 | arguments); |
| 130 | |
| 131 | m_ui.actionStop->setEnabled(true); |
| 132 | m_ui.actionReplay->setEnabled(false); |
| 133 | } |
| 134 | |
| 135 | void MainWindow::replayStop() |
| 136 | { |
| 137 | if (m_replayProcess) { |
| 138 | m_replayProcess->kill(); |
| 139 | |
| 140 | m_ui.actionStop->setEnabled(false); |
| 141 | m_ui.actionReplay->setEnabled(true); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | void MainWindow::newTraceFile(const QString &fileName) |
| 146 | { |
| 147 | m_traceFileName = fileName; |
| 148 | |
| 149 | if (m_traceFileName.isEmpty()) { |
| 150 | m_ui.actionReplay->setEnabled(false); |
| 151 | } else { |
| 152 | m_ui.actionReplay->setEnabled(true); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | void MainWindow::replayFinished() |
| 157 | { |
| 158 | m_ui.actionStop->setEnabled(false); |
| 159 | m_ui.actionReplay->setEnabled(true); |
| 160 | |
| 161 | QString output = m_replayProcess->readAllStandardOutput(); |
| 162 | |
| 163 | #if 0 |
| 164 | qDebug()<<"Process finished = "; |
| 165 | qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError(); |
| 166 | qDebug()<<"\tout = "<<output; |
| 167 | #endif |
| 168 | |
| 169 | if (output.length() < 80) { |
| 170 | statusBar()->showMessage(output); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void MainWindow::replayError(QProcess::ProcessError err) |
| 175 | { |
| 176 | m_ui.actionStop->setEnabled(false); |
| 177 | m_ui.actionReplay->setEnabled(true); |
| 178 | |
| 179 | qDebug()<<"Process error = "<<err; |
| 180 | qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError(); |
| 181 | qDebug()<<"\tout = "<<m_replayProcess->readAllStandardOutput(); |
| 182 | QMessageBox::warning( |
| 183 | this, tr("Replay Failed"), |
| 184 | tr("Couldn't execute the replay file '%1'").arg(m_traceFileName)); |
| 185 | } |
| 186 | |
Zack Rusin | 601e837 | 2011-03-24 22:23:21 -0400 | [diff] [blame] | 187 | #include "mainwindow.moc" |