~fboucault/qtcreator-plugin-ubuntu/newarch_arm64

« back to all changes in this revision

Viewing changes to src/ubuntu/processoutputdialog.cpp

  • Committer: Benjamin Zeller
  • Date: 2016-06-08 15:09:39 UTC
  • mfrom: (443.2.36 ubuntu)
  • Revision ID: benjamin.zeller@canonical.com-20160608150939-v4ffv2a9xy5lcr5s
LXD rewrite for building and running apps in LXD containers

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2014 Canonical Ltd.
 
2
 * Copyright 2014-2016 Canonical Ltd.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU Lesser General Public License as published by
15
15
 *
16
16
 * Author: Benjamin Zeller <benjamin.zeller@canonical.com>
17
17
 */
18
 
#include "ubuntuclickdialog.h"
19
 
#include "ui_ubuntuclickdialog.h"
20
 
#include "ubuntuconstants.h"
21
 
#include "clicktoolchain.h"
22
 
#include "ubuntukitmanager.h"
23
 
 
24
 
#include <QMessageBox>
 
18
#include "processoutputdialog.h"
 
19
#include "ui_processoutputdialog.h"
 
20
 
 
21
#include <texteditor/fontsettings.h>
 
22
#include <coreplugin/icore.h>
 
23
 
25
24
#include <QPushButton>
26
 
 
27
 
#include <projectexplorer/projectexplorer.h>
28
 
#include <projectexplorer/toolchainmanager.h>
29
 
#include <texteditor/fontsettings.h>
30
 
 
31
 
#include "ubuntucreatenewchrootdialog.h"
32
 
#include "clickchrootagent_interface.h"
 
25
#include <QDebug>
 
26
 
33
27
 
34
28
namespace Ubuntu {
35
29
namespace Internal {
36
30
 
37
 
UbuntuClickDialog::UbuntuClickDialog(QWidget *parent)
 
31
const char PROCESS_ERROR_EXIT_MESSAGE[] = "Task exited with errors, please check the output";
 
32
const char PROCESS_SUCCESS_EXIT_MESSAGE[] = "Task exited with no errors";
 
33
 
 
34
ProcessOutputDialog::ProcessOutputDialog(QWidget *parent)
38
35
    : QDialog(parent)
39
 
    ,m_ui(new Ui::UbuntuClickDialog)
 
36
    ,m_ui(new Ui::ProcessOutputDialog)
40
37
{
41
38
    m_ui->setupUi(this);
42
39
 
43
40
    QFont f(TextEditor::FontSettings::defaultFixedFontFamily());
44
41
    f.setStyleHint(QFont::TypeWriter);
45
42
    m_ui->output->setFont(f);
46
 
    m_ui->exitStatusLabel->setVisible(false);
 
43
 
 
44
    connect(m_ui->checkBox, &QCheckBox::toggled, [this](bool checked){
 
45
        m_ui->output->setVisible(checked);
 
46
        if(checked)
 
47
            adjustSize();
 
48
        else
 
49
            resize(minimumSize());
 
50
    });
 
51
 
 
52
    m_ui->checkBox->setChecked(false);
47
53
 
48
54
    m_process = new Utils::QtcProcess(this);
49
 
    connect(m_process,SIGNAL(readyReadStandardOutput()),this,SLOT(on_clickReadyReadStandardOutput()));
50
 
    connect(m_process,SIGNAL(readyReadStandardError()),this,SLOT(on_clickReadyReadStandardError()));
51
 
    connect(m_process,SIGNAL(finished(int)),this,SLOT(on_clickFinished(int)));
 
55
    connect(m_process,SIGNAL(readyReadStandardOutput()),this,SLOT(on_processReadyReadStandardOutput()));
 
56
    connect(m_process,SIGNAL(readyReadStandardError()),this,SLOT(on_processReadyReadStandardError()));
 
57
    connect(m_process,SIGNAL(finished(int)),this,SLOT(on_processFinished(int)));
 
58
 
 
59
    //make sure the progressbar is not animating just yet
 
60
    m_ui->progressBar->setRange(0, 1);
52
61
}
53
62
 
54
 
UbuntuClickDialog::~UbuntuClickDialog()
 
63
ProcessOutputDialog::~ProcessOutputDialog()
55
64
{
56
65
    delete m_ui;
57
66
}
58
67
 
59
 
void UbuntuClickDialog::setParameters(const QList<ProjectExplorer::ProcessParameters> &params)
 
68
void ProcessOutputDialog::setParameters(const QList<ProjectExplorer::ProcessParameters> &params)
60
69
{
61
70
    m_tasks = params;
62
71
}
63
72
 
64
 
int UbuntuClickDialog::lastExitCode() const
 
73
int ProcessOutputDialog::lastExitCode() const
65
74
{
66
75
    return m_exitCode;
67
76
}
68
77
 
69
 
void UbuntuClickDialog::runClick( )
70
 
{
71
 
#if 0
72
 
    //change the button to cancel
73
 
    m_buttonBox->clear();
74
 
    m_buttonBox->addButton(QDialogButtonBox::Cancel);
75
 
#endif
76
 
    disableCloseButton(true);
77
 
    nextTask();
78
 
}
79
 
 
80
 
int UbuntuClickDialog::runClickModal(const ProjectExplorer::ProcessParameters &params, QWidget *parent)
81
 
{
82
 
    return runClickModal(QList<ProjectExplorer::ProcessParameters>()<<params,parent);
83
 
}
84
 
 
85
 
int UbuntuClickDialog::runClickModal(const QList<ProjectExplorer::ProcessParameters> &params, QWidget *parent)
86
 
{
87
 
    UbuntuClickDialog dlg( parent ? parent : Core::ICore::mainWindow());
 
78
int ProcessOutputDialog::runProcessModal(const ProjectExplorer::ProcessParameters &params, QWidget *parent)
 
79
{
 
80
    return runProcessModal(QList<ProjectExplorer::ProcessParameters>()<<params,parent);
 
81
}
 
82
 
 
83
int ProcessOutputDialog::runProcessModal(const QList<ProjectExplorer::ProcessParameters> &params, QWidget *parent)
 
84
{
 
85
    ProcessOutputDialog dlg( parent ? parent : Core::ICore::mainWindow());
88
86
    dlg.setParameters(params);
89
 
    QMetaObject::invokeMethod(&dlg,"runClick",Qt::QueuedConnection);
 
87
    QMetaObject::invokeMethod(&dlg,"runTasks",Qt::QueuedConnection);
90
88
    dlg.exec();
91
89
 
92
90
    return dlg.m_exitCode;
93
91
}
94
92
 
95
 
bool UbuntuClickDialog::createClickChrootModal(bool redetectKits, const QString &arch, const QString &framework, QWidget *parent)
96
 
{
97
 
 
98
 
    UbuntuClickTool::Target t;
99
 
    if(!UbuntuCreateNewChrootDialog::getNewChrootTarget(&t,arch,framework,parent))
100
 
        return false;
101
 
 
102
 
    ProjectExplorer::ProcessParameters params;
103
 
    UbuntuClickTool::parametersForCreateChroot(t,&params);
104
 
 
105
 
    bool success = (runClickModal(params,parent) == 0);
106
 
 
107
 
    if(success) {
108
 
        ClickToolChain* tc = new ClickToolChain(t, ProjectExplorer::ToolChain::AutoDetection);
109
 
        ProjectExplorer::ToolChainManager::registerToolChain(tc);
110
 
 
111
 
        if(redetectKits)
112
 
            UbuntuKitManager::autoDetectKits();
113
 
    }
114
 
 
115
 
    return success;
116
 
}
117
 
 
118
 
int UbuntuClickDialog::maintainClickModal(const UbuntuClickTool::Target &target, const UbuntuClickTool::MaintainMode &mode)
119
 
{
120
 
    return maintainClickModal(QList<UbuntuClickTool::Target>()<<target,mode);
121
 
}
122
 
 
123
 
int UbuntuClickDialog::maintainClickModal(const QList<UbuntuClickTool::Target> &targetList, const UbuntuClickTool::MaintainMode &mode)
124
 
{
125
 
    QList<ProjectExplorer::ProcessParameters> paramList;
126
 
    foreach(const UbuntuClickTool::Target &target, targetList) {
127
 
        if(mode == UbuntuClickTool::Delete) {
128
 
            QString title = tr(Constants::UBUNTU_CLICK_DELETE_TITLE);
129
 
            QString text  = tr(Constants::UBUNTU_CLICK_DELETE_MESSAGE);
130
 
            if( QMessageBox::question(Core::ICore::mainWindow(),title,text) != QMessageBox::Yes )
131
 
                return 0;
132
 
 
133
 
            if(UbuntuClickTool::clickChrootSuffix() == QLatin1String(Constants::UBUNTU_CLICK_CHROOT_DEFAULT_NAME)) {
134
 
                ComUbuntuSdkClickChrootAgentInterface clickAgent(QStringLiteral("com.ubuntu.sdk.ClickChrootAgent"),
135
 
                                                                 QStringLiteral("/com/ubuntu/sdk/ClickChrootAgent"),
136
 
                                                                 QDBusConnection::sessionBus());
137
 
                if(clickAgent.isValid()) {
138
 
                    QDBusPendingReply<bool> ret = clickAgent.releaseSession(target.framework,target.architecture);
139
 
                    if(ret.isError())
140
 
                        qDebug()<<ret.error();
141
 
 
142
 
                    ret.waitForFinished();
143
 
                }
144
 
            }
145
 
        }
146
 
 
147
 
        ProjectExplorer::ProcessParameters params;
148
 
        UbuntuClickTool::parametersForMaintainChroot(mode,target,&params);
149
 
        paramList<<params;
150
 
    }
151
 
 
152
 
    return runClickModal(paramList);
153
 
}
154
 
 
155
 
void UbuntuClickDialog::done(int code)
156
 
{
157
 
    if(code == QDialog::Rejected) {
158
 
        if(m_process->state() != QProcess::NotRunning) {
159
 
            //ask the user if he really wants to do that
160
 
            QString title = tr(Constants::UBUNTU_CLICK_STOP_TITLE);
161
 
            QString text  = tr(Constants::UBUNTU_CLICK_STOP_MESSAGE);
162
 
            if( QMessageBox::question(Core::ICore::mainWindow(),title,text)!= QMessageBox::Yes )
163
 
                return;
164
 
 
165
 
            m_process->terminate();
166
 
            m_process->waitForFinished(100);
167
 
            m_process->kill();
168
 
 
169
 
            m_ui->exitStatusLabel->setText(tr(Constants::UBUNTU_CLICK_STOP_WAIT_MESSAGE));
170
 
            m_ui->exitStatusLabel->setVisible(true);
171
 
            return;
172
 
        }
173
 
    }
 
93
void ProcessOutputDialog::runTasks( )
 
94
{
 
95
    m_hadErrors = false;
 
96
    disableCloseButton(true);
 
97
    nextTask();
 
98
}
 
99
 
 
100
void ProcessOutputDialog::done(int code)
 
101
{
174
102
    QDialog::done(code);
175
103
}
176
104
 
177
 
void UbuntuClickDialog::disableCloseButton(const bool &disabled)
 
105
void ProcessOutputDialog::disableCloseButton(const bool &disabled)
178
106
{
179
107
    QPushButton* bt = m_ui->buttonBox->button(QDialogButtonBox::Close);
180
108
    if(bt) bt->setDisabled(disabled);
181
109
}
182
110
 
183
 
void UbuntuClickDialog::nextTask()
 
111
void ProcessOutputDialog::nextTask()
184
112
{
185
113
    if(m_tasks.length() <= 0)
186
114
        return;
187
115
 
 
116
 
 
117
    m_ui->progressBar->setRange(0,0);
 
118
 
188
119
    ProjectExplorer::ProcessParameters params = m_tasks.takeFirst();
189
120
    params.resolveAll();
190
121
    m_process->setCommand(params.command(),params.arguments());
193
124
    m_process->start();
194
125
}
195
126
 
196
 
void UbuntuClickDialog::on_clickFinished(int exitCode)
 
127
void ProcessOutputDialog::on_processFinished(int exitCode)
197
128
{
198
129
    if (exitCode != 0) {
199
 
        on_clickReadyReadStandardError(tr("---%0---").arg(QLatin1String(Constants::UBUNTU_CLICK_ERROR_EXIT_MESSAGE)));
 
130
        m_hadErrors = true;
 
131
        on_processReadyReadStandardError(tr("---%0---").arg(QLatin1String(PROCESS_ERROR_EXIT_MESSAGE)));
200
132
    } else {
201
 
        on_clickReadyReadStandardOutput(tr("---%0---").arg(QLatin1String(Constants::UBUNTU_CLICK_SUCCESS_EXIT_MESSAGE)));
 
133
        on_processReadyReadStandardOutput(tr("---%0---").arg(QLatin1String(PROCESS_SUCCESS_EXIT_MESSAGE)));
202
134
    }
203
135
 
204
136
    if(m_tasks.length() > 0) {
206
138
        return;
207
139
    }
208
140
 
 
141
    m_ui->progressBar->setRange(0,1);
 
142
    m_ui->progressBar->setValue(1);
209
143
    disableCloseButton(false);
210
 
#if 0
211
 
    //set the button to close again
212
 
    m_buttonBox->clear();
213
 
    m_buttonBox->addButton(QDialogButtonBox::Close);
214
 
#endif
215
 
 
216
144
    m_exitCode = exitCode;
 
145
 
 
146
    if (m_hadErrors) {
 
147
        m_ui->label->setText(tr("There were errors while executing the tasks, please check the details."));
 
148
        m_ui->checkBox->setChecked(true);
 
149
    } else {
 
150
        m_ui->label->setText(tr("All tasks finished, check the details for more information"));
 
151
    }
217
152
}
218
153
 
219
 
void UbuntuClickDialog::on_clickReadyReadStandardOutput(const QString txt)
 
154
void ProcessOutputDialog::on_processReadyReadStandardOutput(const QString txt)
220
155
{
221
156
    QString outText = QString::fromLocal8Bit("<div>");
222
157
 
229
164
    m_ui->output->append(outText);
230
165
}
231
166
 
232
 
void UbuntuClickDialog::on_clickReadyReadStandardError(const QString txt)
 
167
void ProcessOutputDialog::on_processReadyReadStandardError(const QString txt)
233
168
{
234
169
    QString outText = QString::fromLocal8Bit("<div style=\"color:red; font-weight: bold;\">");
235
170