summaryrefslogtreecommitdiff
path: root/gui/tracedialog.cpp
blob: a25c7aca9ad133977dc960fc12a3508c3ad68710 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "tracedialog.h"

#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>

TraceDialog::TraceDialog(QWidget *parent)
    : QDialog(parent)
{
    setupUi(this);

    connect(browseButton, SIGNAL(clicked()),
            this, SLOT(browse()));
}

QString TraceDialog::applicationPath() const
{
    return applicationEdit->text();
}

QStringList TraceDialog::arguments() const
{
    QStringList args =
        argumentsEdit->text().split(';');
    return args;
}

void TraceDialog::browse()
{
    QString fileName =
        QFileDialog::getOpenFileName(
            this,
            tr("Find the application"),
            QDir::currentPath());

    if (isFileOk(fileName)) {
        applicationEdit->setText(fileName);
    }
}

void TraceDialog::accept()
{
    if (isFileOk(applicationEdit->text())) {
        QDialog::accept();
    }
}

bool TraceDialog::isFileOk(const QString &fileName)
{
    QFileInfo fi(fileName);

    if (!fi.exists()) {
        QMessageBox::warning(this, tr("File Missing"),
                             tr("File '%1' doesn't exist.")
                             .arg(fi.fileName()));
        return false;
    }
    if (!fi.isExecutable()) {
        QMessageBox::warning(this, tr("Application Not Runnable"),
                             tr("File '%1' can't be executed.")
                             .arg(fi.fileName()));
        return false;
    }

    return true;
}

#include "tracedialog.moc"