Saves key-presses on the gui for EGL traces.
Might be handy to implement a top level "apitrace retrace" command too.
 namespace trace {
 
 
+/**
+ * Enum to distuinguish the API for tools.
+ *
+ * It should never be embedded in the trace file.
+ */
 enum API {
+    API_UNKNOWN = 0,
     API_GL, // GL + GLX/WGL/CGL
     API_EGL, // GL/GLES1/GLES2/VG + EGL
     API_D3D7,
 
     file = NULL;
     next_call_no = 0;
     version = 0;
+    api = API_UNKNOWN;
 
     glGetErrorSig = NULL;
 }
         std::cerr << "error: unsupported trace format version " << version << "\n";
         return false;
     }
+    api = API_UNKNOWN;
 
     return true;
 }
         sig->offset = file->currentOffset();
         functions[id] = sig;
 
+        /**
+         * Try to autodetect the API.
+         *
+         * XXX: Ideally we would allow to mix multiple APIs in a single trace,
+         * but as it stands today, retrace is done separately for each API.
+         */
+        if (api == API_UNKNOWN) {
+            const char *n = sig->name;
+            if ((n[0] == 'g' && n[1] == 'l' && n[2] == 'X') || // glX
+                (n[0] == 'w' && n[1] == 'g' && n[2] == 'g' && n[3] >= 'A' && n[3] <= 'Z') || // wgl[A-Z]
+                (n[0] == 'C' && n[1] == 'G' && n[2] == 'L')) { // CGL
+                api = trace::API_GL;
+            } else if (n[0] == 'e' && n[1] == 'g' && n[2] == 'l' && n[3] >= 'A' && n[3] <= 'Z') { // egl
+                api = trace::API_EGL;
+            } else {
+                /* TODO */
+            }
+        }
+
         /**
          * Note down the signature of special functions for future reference.
          *
 
 #include "trace_file.hpp"
 #include "trace_format.hpp"
 #include "trace_model.hpp"
+#include "trace_api.hpp"
 
 
 namespace trace {
 
 public:
     unsigned long long version;
+    API api;
 
     Parser();
 
 
             SIGNAL(frameContentsLoaded(ApiTraceFrame*,QVector<ApiTraceCall*>,quint64)),
             this,
             SLOT(loaderFrameLoaded(ApiTraceFrame*,QVector<ApiTraceCall*>,quint64)));
+    connect(m_loader, SIGNAL(guessedApi(int)),
+            this, SLOT(guessedApi(int)));
     connect(m_loader, SIGNAL(finishedParsing()),
             this, SLOT(finishedParsing()));
     connect(this, SIGNAL(loaderSearch(ApiTrace::SearchRequest)),
     }
 }
 
+void ApiTrace::guessedApi(int api)
+{
+    m_api = static_cast<trace::API>(api);
+}
+
+trace::API ApiTrace::api() const
+{
+    return m_api;
+}
+
 void ApiTrace::finishedParsing()
 {
     if (!m_frames.isEmpty()) {
 
 
 #include "apitracecall.h"
 
+#include "trace_api.hpp"
+
 #include <QObject>
 #include <QSet>
 
 
     bool hasErrors() const;
 
+    trace::API api() const;
+
 public slots:
     void setFileName(const QString &name);
     void save();
 private slots:
     void addFrames(const QList<ApiTraceFrame*> &frames);
     void slotSaved();
+    void guessedApi(int api);
     void finishedParsing();
     void loaderFrameLoaded(ApiTraceFrame *frame,
                            const QVector<ApiTraceCall*> &calls,
     QString m_tempFileName;
 
     QList<ApiTraceFrame*> m_frames;
+    trace::API m_api;
 
     TraceLoader *m_loader;
     QThread     *m_loaderThread;
 
     if (!m_trace) {
         return;
     }
+    m_api = m_trace->api();
     QFileInfo info(m_trace->fileName());
     statusBar()->showMessage(
         tr("Loaded %1").arg(info.fileName()), 3000);
 
     } else if (m_api == trace::API_EGL) {
         prog = QLatin1String("eglretrace");
     } else {
-        Q_ASSERT(0);
+        emit finished(QLatin1String("Unsupported API"));
         return;
     }
 
 
         //Load the entire file into memory
         parseTrace();
     }
+    emit guessedApi(static_cast<int>(m_parser.api));
     emit finishedParsing();
 }
 
 
 signals:
     void startedParsing();
     void parsed(int percent);
+    void guessedApi(int api);
     void finishedParsing();
 
     void framesLoaded(const QList<ApiTraceFrame*> &frames);
     int numberOfCallsInFrame(int frameIdx) const;
 
     void loadHelpFile();
+    void guessApi(const trace::Call *call);
     void scanTrace();
     void parseTrace();
 
 
      <layout class="QVBoxLayout" name="verticalLayout_4">
       <item>
        <widget class="QComboBox" name="apiComboBox">
+        <item>
+         <property name="text">
+          <string>Unknown</string>
+         </property>
+        </item>
         <item>
          <property name="text">
           <string>GL</string>