widget.cpp
55 lines
| 1.7 KiB
| text/x-c
|
CppLexer
Marek Rosa
|
r2229 | #include "widget.h" | ||
#include <QPushButton> | ||||
#include <QDir> | ||||
#include <QGridLayout> | ||||
#include <QApplication> | ||||
#include <QProcess> | ||||
Tero Ahola
|
r2237 | #include <QDebug> | ||
Marek Rosa
|
r2229 | |||
Widget::Widget(QWidget *parent) | ||||
: QWidget(parent), | ||||
m_demoApp(0) | ||||
{ | ||||
Tero Ahola
|
r2237 | // Create a list of executables | ||
Marek Rosa
|
r2229 | QList<QFileInfo> appList; | ||
Tero Ahola
|
r2237 | m_appFolder = QDir(QApplication::applicationDirPath()); | ||
Tero Ahola
|
r2239 | #ifdef Q_OS_MAC | ||
Tero Ahola
|
r2237 | // The executable is inside an application bundle (a folder) on OSX | ||
m_appFolder.cdUp(); | ||||
m_appFolder.cdUp(); | ||||
m_appFolder.cdUp(); | ||||
appList = m_appFolder.entryInfoList(QStringList("*.app"), QDir::Executable | QDir::Dirs | QDir::NoDotAndDotDot); | ||||
Tero Ahola
|
r2239 | #elif defined(Q_OS_WIN) | ||
Tero Ahola
|
r2237 | appList = m_appFolder.entryInfoList(QStringList("*.exe"), QDir::Executable | QDir::Files | QDir::NoDotAndDotDot); | ||
#else | ||||
appList = m_appFolder.entryInfoList(QDir::Executable | QDir::Files | QDir::NoDotAndDotDot); | ||||
#endif | ||||
Marek Rosa
|
r2232 | for (int k = appList.count() - 1; k >= 0; k--) { | ||
QString name = appList[k].fileName(); | ||||
Tero Ahola
|
r2237 | if (name.startsWith("tst_") || name.startsWith("demoLauncher")) | ||
Marek Rosa
|
r2232 | appList.removeAt(k); | ||
} | ||||
Tero Ahola
|
r2237 | // Create push buttons for starting the executables | ||
Marek Rosa
|
r2229 | QGridLayout* demosLayout = new QGridLayout; | ||
for( int i = 0; i < appList.count(); i++) { | ||||
Tero Ahola
|
r2237 | QPushButton *button = new QPushButton(appList[i].fileName()); | ||
Marek Rosa
|
r2229 | connect(button, SIGNAL(clicked()), this, SLOT (runApp())); | ||
demosLayout->addWidget(button, i%10, i/10); | ||||
} | ||||
setLayout(demosLayout); | ||||
} | ||||
Widget::~Widget() | ||||
{ | ||||
Marek Rosa
|
r2232 | if (m_demoApp) | ||
m_demoApp->close(); | ||||
Marek Rosa
|
r2229 | } | ||
void Widget::runApp() | ||||
{ | ||||
QString name = qobject_cast<QPushButton *>(sender())->text(); | ||||
Tero Ahola
|
r2237 | QString program = m_appFolder.absolutePath() + QDir::separator() + name; | ||
Marek Rosa
|
r2229 | m_demoApp = new QProcess(this); | ||
m_demoApp->start(program); | ||||
} | ||||