summaryrefslogtreecommitdiffstats
path: root/src/b2qt-flashing-wizard/commit_page.cpp
blob: e7a3c167d0a72a212cd9fa7bb90a2a43b3601603 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc
** All rights reserved.
** For any questions to Digia, please use the contact form at
** http://qt.digia.com/
**
** This file is part of Qt Enterprise Embedded.
**
** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** the contact form at http://qt.digia.com/
**
****************************************************************************/

#include "commit_page.h"
#include "scriptwriter.h"
#include "progress_page.h"
#include "mainwindow.h"
#include <QDebug>
#include <QVBoxLayout>
#include <QLabel>

extern QString G_platform;
extern QString G_version;
extern QString G_os;
extern QString G_device;
extern QString G_board;
extern QString G_SDKDIR;
extern QString G_mode;
QLabel *createErrorLabel(QWidget *parent);

CommitPage::CommitPage(QWidget *parent)
    : QWizardPage(parent)
    , mText(new QLabel(this))
    , mActor(0)
    , mError(createErrorLabel(this))
    , mLayout(new QVBoxLayout(this))
    , mComplete(false)
{
    setButtonText(QWizard::CommitButton, "Write");
    setCommitPage(true);
    setTitle("Confirm action");
    setSubTitle("Confirm the action to be done");
    mLayout->addWidget(mText);
    mLayout->addSpacerItem(new QSpacerItem(40,40,QSizePolicy::Minimum, QSizePolicy::Expanding));
    mLayout->addWidget(mError);
    setLayout(mLayout);
}

CommitPage::~CommitPage()
{
}

bool CommitPage::isComplete() const
{
    if (!mComplete)
        return false;

    QString error;
    bool result = mActor->ready(error);
    if (result)
        mError->clear();
    else
        mError->setText(error);

    return result;
}

void CommitPage::initializePage()
{
    qDebug() << "platform:" << G_platform << "version:" << G_version << "os:" << G_os
             << "device:" << G_device << "board:" << G_board << "mode:" << G_mode;
    QString text("Write %1-%2 (%3) to device %4.");
    mText->setText(text.arg(G_platform, G_os, G_version, G_device));
    mComplete = true;

    qDebug() << "os:" << G_os << "platform:" << G_platform << "device:" << G_device;

    if (G_platform == "generic-4.2" && G_os == "eAndroid" && G_board == "iMX6") {
        ScriptWriter *i = new ScriptWriter(this);
        i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/" + G_board + "/deploy.sh");
        i->setAdditionalArgs(QStringList() << G_device << "--verbose");
        i->setEnvironment("VERBOSE","1");
        mActor = i;
    } else if (G_platform == "iMX6" && G_os == "eLinux") {
        ScriptWriter *i = new ScriptWriter(this);
        i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh");
        i->setAdditionalArgs(QStringList() << G_device << "--verbose");
        i->setEnvironment("VERBOSE","1");
        mActor = i;
    } else if (G_platform == "beaglebone" && G_os == "eLinux") {
        ScriptWriter *i = new ScriptWriter(this);
        i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh");
        i->setAdditionalArgs(QStringList() << G_device << "--verbose");
        i->setEnvironment("VERBOSE","1");
        mActor = i;
    } else if (G_platform == "generic-4.4" && G_os == "eAndroid" && G_board == "beaglebone") {
        ScriptWriter *i = new ScriptWriter(this);
        i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/" + G_board + "/deploy.sh");
        i->setAdditionalArgs(QStringList() << G_device << "--verbose");
        i->setEnvironment("VERBOSE","1");
        mActor = i;
    } else if (G_platform == "generic-4.4" && G_os == "eAndroid" && G_board == "nexus7v2") {
        ScriptWriter *i = new ScriptWriter(this);
        i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/" + G_board + "/deploy.sh");
        if (G_mode == "fastboot")
            i->setAdditionalArgs(QStringList() << "-fastboot");
        mActor = i;
    } else if (G_platform == "generic-4.4" && G_os == "eAndroid" && G_board == "nexus7") {
        ScriptWriter *i = new ScriptWriter(this);
        i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/" + G_board + "/deploy.sh");
        if (G_mode == "fastboot")
            i->setAdditionalArgs(QStringList() << "-fastboot");
        mActor = i;
    } else if (G_platform == "generic-4.2" && G_os == "eAndroid" && G_board == "nexus7") {
        ScriptWriter *i = new ScriptWriter(this);
        i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/" + G_board + "/deploy.sh");
        if (G_mode == "fastboot")
            i->setAdditionalArgs(QStringList() << "-fastboot");
        mActor = i;
    } else if (G_platform == "raspberrypi" && G_os == "eLinux") {
        ScriptWriter *i = new ScriptWriter(this);
        i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh");
        i->setAdditionalArgs(QStringList() << G_device << "--verbose");
        i->setEnvironment("VERBOSE","1");
        mActor = i;
    } else if (G_platform == "imx6qsabresd" && G_os == "eLinux") {
        ScriptWriter *i = new ScriptWriter(this);
        i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh");
        i->setAdditionalArgs(QStringList() << G_device << "--verbose");
        i->setEnvironment("VERBOSE","1");
        mActor = i;
    } else if (G_platform == "apalis-imx6" && G_os == "eLinux") {
        ScriptWriter *i = new ScriptWriter(this);
        i->setScriptFile(G_SDKDIR + G_version + "/" + G_platform + "-" + G_os + "/images/deploy.sh");
        i->setAdditionalArgs(QStringList() << G_device << "--verbose");
        i->setEnvironment("VERBOSE","1");
        mActor = i;
    } else {
        mError->setText("Unsupported platform combination");
        mComplete = false;
    }
}

bool CommitPage::validatePage()
{
    ProgressPage *p = qobject_cast<ProgressPage*>(wizard()->page(MainWindow::Page_Progress));
    Q_ASSERT(p);

    p->setActor(mActor);
    return true;
}