]> git.cworth.org Git - apitrace/commitdiff
Allow retracing from the gui plus make the call list cleaner.
authorZack Rusin <zack@kde.org>
Mon, 28 Mar 2011 03:53:36 +0000 (23:53 -0400)
committerZack Rusin <zack@kde.org>
Thu, 31 Mar 2011 02:48:42 +0000 (22:48 -0400)
gui/CMakeLists.txt
gui/apitracecall.cpp
gui/apitracecall.h
gui/mainwindow.cpp
gui/mainwindow.h
gui/ui/mainwindow.ui

index d4c462a120f8f9084e12c062eb02634f90e32322..86f60d95521ff35e1ddbdd0a951a5065f404f128 100644 (file)
@@ -18,6 +18,7 @@ QT4_WRAP_UI(qapitrace_UIS_H ${qapitrace_UIS})
 #add_app_icon(qapitrace_SRCS ../icons/hi*-qapitrace.png)
 
 include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..)
+add_definitions(-DBUILD_DIR="${CMAKE_CURRENT_BINARY_DIR}/..")
 
 add_executable(qapitrace ${qapitrace_SRCS} ${qapitrace_UIS_H})
 
index f5a5ff714e40ad21d6c61796004178a7cd1a882e..313d9eae0cb964aa38c4ff2b55924e4a599aa9f5 100644 (file)
@@ -227,9 +227,33 @@ void ApiArray::init(const Trace::Array *arr)
 
 QStaticText ApiTraceCall::staticText() const
 {
-    if (!m_richText.isEmpty())
+    if (!m_staticText.text().isEmpty())
         return m_staticText;
 
+    QString richText = QString::fromLatin1("<span style=\"font-weight:bold\">%1</span>(").arg(name);
+    for (int i = 0; i < argNames.count(); ++i) {
+        richText += QLatin1String("<span style=\"color:#0000ff\">");
+        richText += apiVariantToString(argValues[i]);
+        richText += QLatin1String("</span>");
+        if (i < argNames.count() - 1)
+            richText += QString::fromLatin1(", ");
+    }
+    richText += QLatin1String(")");
+
+    m_staticText.setText(richText);
+    QTextOption opt;
+    opt.setWrapMode(QTextOption::NoWrap);
+    m_staticText.setTextOption(opt);
+    m_staticText.prepare();
+
+    return m_staticText;
+}
+
+QString ApiTraceCall::toHtml() const
+{
+    if (!m_richText.isEmpty())
+        return m_richText;
+
     m_richText = QString::fromLatin1("<span style=\"font-weight:bold\">%1</span>(").arg(name);
     for (int i = 0; i < argNames.count(); ++i) {
         m_richText += argNames[i];
@@ -248,19 +272,6 @@ QStaticText ApiTraceCall::staticText() const
         m_richText += apiVariantToString(returnValue);
         m_richText += QLatin1String("</span>");
     }
-
-    m_staticText.setText(m_richText);
-    QTextOption opt;
-    opt.setWrapMode(QTextOption::NoWrap);
-    m_staticText.setTextOption(opt);
-    m_staticText.prepare();
-
-    return m_staticText;
-}
-
-QString ApiTraceCall::richText() const
-{
-    staticText();
     return m_richText;
 }
 
index e47a88de5dbd11c690d5152d612e8097428f1df6..8b925e8159829818f75a1171de63630c98ba3573 100644 (file)
@@ -106,13 +106,13 @@ public:
     QVariantList argValues;
     QVariant returnValue;
 
+    QString toHtml() const;
     QString filterText() const;
-    QString richText() const;
     QStaticText staticText() const;
 private:
     mutable QString m_richText;
-    mutable QStaticText m_staticText;
     mutable QString m_filterText;
+    mutable QStaticText m_staticText;
 };
 Q_DECLARE_METATYPE(ApiTraceCall);
 Q_DECLARE_METATYPE(ApiTraceCall*);
index 4382def1ab30efef90fcd8f7aee454a944dd17f6..74d9f94cc7742e10df6c54ff5717f47abb798cce 100644 (file)
@@ -8,14 +8,17 @@
 #include <QAction>
 #include <QDebug>
 #include <QDir>
-#include <QLineEdit>
 #include <QFileDialog>
+#include <QLineEdit>
+#include <QMessageBox>
+#include <QProcess>
 #include <QToolBar>
 #include <QWebView>
 
 
 MainWindow::MainWindow()
-    : QMainWindow()
+    : QMainWindow(),
+      m_replayProcess(0)
 {
     m_ui.setupUi(this);
 
@@ -35,6 +38,14 @@ MainWindow::MainWindow()
 
     connect(m_ui.actionOpen, SIGNAL(triggered()),
             this, SLOT(openTrace()));
+    connect(m_ui.actionQuit, SIGNAL(triggered()),
+            this, SLOT(close()));
+
+    connect(m_ui.actionReplay, SIGNAL(triggered()),
+            this, SLOT(replayStart()));
+    connect(m_ui.actionStop, SIGNAL(triggered()),
+            this, SLOT(replayStop()));
+
     connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
             this, SLOT(callItemSelected(const QModelIndex &)));
     connect(m_filterEdit, SIGNAL(returnPressed()),
@@ -52,21 +63,28 @@ void MainWindow::openTrace()
 
     qDebug()<< "File name : " <<fileName;
 
+    newTraceFile(fileName);
     m_model->loadTraceFile(fileName);
 }
 
 void MainWindow::loadTrace(const QString &fileName)
 {
+    if (!QFile::exists(fileName)) {
+        QMessageBox::warning(this, tr("File Missing"),
+                             tr("File '%1' doesn't exist.").arg(fileName));
+        return;
+    }
     qDebug()<< "Loading  : " <<fileName;
 
     m_model->loadTraceFile(fileName);
+    newTraceFile(fileName);
 }
 
 void MainWindow::callItemSelected(const QModelIndex &index)
 {
     ApiTraceCall *call = index.data().value<ApiTraceCall*>();
     if (call) {
-        m_ui.detailsWebView->setHtml(call->richText());
+        m_ui.detailsWebView->setHtml(call->toHtml());
         m_ui.detailsDock->show();
     } else {
         m_ui.detailsDock->hide();
@@ -78,4 +96,92 @@ void MainWindow::filterTrace()
     m_proxyModel->setFilterString(m_filterEdit->text());
 }
 
+void MainWindow::replayStart()
+{
+    if (!m_replayProcess) {
+#ifdef Q_OS_WIN
+        QString format = QLatin1String("%1;");
+#else
+        QString format = QLatin1String("%1:");
+#endif
+        QString buildPath = format.arg(BUILD_DIR);
+        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+        env.insert("PATH", buildPath + env.value("PATH"));
+
+        qputenv("PATH", env.value("PATH").toLatin1());
+
+        m_replayProcess = new QProcess(this);
+        m_replayProcess->setProcessEnvironment(env);
+
+        connect(m_replayProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
+                this, SLOT(replayFinished()));
+        connect(m_replayProcess, SIGNAL(error(QProcess::ProcessError)),
+                this, SLOT(replayError(QProcess::ProcessError)));
+    }
+
+    if (m_traceFileName.isEmpty())
+        return;
+
+    QStringList arguments;
+    arguments << m_traceFileName;
+
+    m_replayProcess->start(QLatin1String("glretrace"),
+                           arguments);
+
+    m_ui.actionStop->setEnabled(true);
+    m_ui.actionReplay->setEnabled(false);
+}
+
+void MainWindow::replayStop()
+{
+    if (m_replayProcess) {
+        m_replayProcess->kill();
+
+        m_ui.actionStop->setEnabled(false);
+        m_ui.actionReplay->setEnabled(true);
+    }
+}
+
+void MainWindow::newTraceFile(const QString &fileName)
+{
+    m_traceFileName = fileName;
+
+    if (m_traceFileName.isEmpty()) {
+        m_ui.actionReplay->setEnabled(false);
+    } else {
+        m_ui.actionReplay->setEnabled(true);
+    }
+}
+
+void MainWindow::replayFinished()
+{
+    m_ui.actionStop->setEnabled(false);
+    m_ui.actionReplay->setEnabled(true);
+
+    QString output = m_replayProcess->readAllStandardOutput();
+
+#if 0
+    qDebug()<<"Process finished = ";
+    qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError();
+    qDebug()<<"\tout = "<<output;
+#endif
+
+    if (output.length() < 80) {
+        statusBar()->showMessage(output);
+    }
+}
+
+void MainWindow::replayError(QProcess::ProcessError err)
+{
+    m_ui.actionStop->setEnabled(false);
+    m_ui.actionReplay->setEnabled(true);
+
+    qDebug()<<"Process error = "<<err;
+    qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError();
+    qDebug()<<"\tout = "<<m_replayProcess->readAllStandardOutput();
+    QMessageBox::warning(
+        this, tr("Replay Failed"),
+        tr("Couldn't execute the replay file '%1'").arg(m_traceFileName));
+}
+
 #include "mainwindow.moc"
index c27db8be1f9f0469736cdd175e5ea20064a4eb11..56c1195790d45dad893fa377e06d0ceb88c4fc71 100644 (file)
@@ -4,12 +4,14 @@
 #include "ui_mainwindow.h"
 
 #include <QMainWindow>
+#include <QProcess>
 
 
 class ApiTraceModel;
 class ApiTraceFilter;
 class QLineEdit;
 class QModelIndex;
+class QProcess;
 
 class MainWindow : public QMainWindow
 {
@@ -24,12 +26,23 @@ private slots:
     void callItemSelected(const QModelIndex &index);
     void openTrace();
     void filterTrace();
+    void replayStart();
+    void replayStop();
+    void replayFinished();
+    void replayError(QProcess::ProcessError err);
+
+private:
+    void newTraceFile(const QString &fileName);
 
 private:
     Ui_MainWindow m_ui;
     ApiTraceModel *m_model;
     ApiTraceFilter *m_proxyModel;
     QLineEdit *m_filterEdit;
+
+    QProcess *m_replayProcess;
+
+    QString m_traceFileName;
 };
 
 
index e509cb61c9e66d727899b34c93467982b01dbec1..a6f17b3b8ef87c2ae985da678f3773c2ace42952 100644 (file)
    </property>
    <widget class="QMenu" name="menuFile">
     <property name="title">
-     <string>File</string>
+     <string>&amp;File</string>
     </property>
     <addaction name="actionOpen"/>
+    <addaction name="separator"/>
+    <addaction name="actionQuit"/>
+   </widget>
+   <widget class="QMenu" name="menu_Trace">
+    <property name="title">
+     <string>&amp;Trace</string>
+    </property>
+    <addaction name="actionReplay"/>
+    <addaction name="actionStop"/>
    </widget>
    <addaction name="menuFile"/>
+   <addaction name="menu_Trace"/>
   </widget>
   <widget class="QStatusBar" name="statusbar"/>
   <widget class="QDockWidget" name="detailsDock">
    </property>
   </action>
   <action name="actionOpen">
+   <property name="icon">
+    <iconset theme="document-open">
+     <normaloff/>
+    </iconset>
+   </property>
+   <property name="text">
+    <string>&amp;Open...</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+O</string>
+   </property>
+  </action>
+  <action name="actionQuit">
+   <property name="icon">
+    <iconset theme="application-exit">
+     <normaloff/>
+    </iconset>
+   </property>
+   <property name="text">
+    <string>&amp;Quit</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+Q</string>
+   </property>
+   <property name="shortcutContext">
+    <enum>Qt::ApplicationShortcut</enum>
+   </property>
+   <property name="menuRole">
+    <enum>QAction::QuitRole</enum>
+   </property>
+  </action>
+  <action name="actionReplay">
+   <property name="enabled">
+    <bool>false</bool>
+   </property>
+   <property name="icon">
+    <iconset theme="media-playback-start">
+     <normaloff/>
+    </iconset>
+   </property>
+   <property name="text">
+    <string>&amp;Replay</string>
+   </property>
+  </action>
+  <action name="actionStop">
+   <property name="enabled">
+    <bool>false</bool>
+   </property>
+   <property name="icon">
+    <iconset theme="media-playback-stop">
+     <normaloff/>
+    </iconset>
+   </property>
    <property name="text">
-    <string>Open</string>
+    <string>&amp;Stop</string>
    </property>
   </action>
  </widget>