~fboucault/qtcreator-plugin-ubuntu/newarch_arm64

54.12.5 by Zoltán Balogh
Add copyright info to the new files
1
/*
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
2
 * Copyright 2014-2016 Canonical Ltd.
54.12.5 by Zoltán Balogh
Add copyright info to the new files
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation; version 2.1.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU Lesser General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU Lesser General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 *
16
 * Author: Benjamin Zeller <benjamin.zeller@canonical.com>
17
 */
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
18
#include "processoutputdialog.h"
19
#include "ui_processoutputdialog.h"
20
21
#include <texteditor/fontsettings.h>
22
#include <coreplugin/icore.h>
23
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
24
#include <QPushButton>
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
25
#include <QDebug>
26
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
27
28
namespace Ubuntu {
29
namespace Internal {
30
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
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)
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
35
    : QDialog(parent)
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
36
    ,m_ui(new Ui::ProcessOutputDialog)
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
37
{
38
    m_ui->setupUi(this);
39
40
    QFont f(TextEditor::FontSettings::defaultFixedFontFamily());
41
    f.setStyleHint(QFont::TypeWriter);
42
    m_ui->output->setFont(f);
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
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);
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
53
54
    m_process = new Utils::QtcProcess(this);
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
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);
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
61
}
62
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
63
ProcessOutputDialog::~ProcessOutputDialog()
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
64
{
65
    delete m_ui;
66
}
67
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
68
void ProcessOutputDialog::setParameters(const QList<ProjectExplorer::ProcessParameters> &params)
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
69
{
331.1.13 by Benjamin Zeller
- Add support to run more than one click maintenance task in the chroot
70
    m_tasks = params;
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
71
}
72
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
73
int ProcessOutputDialog::lastExitCode() const
66.2.15 by Benjamin Zeller
Tweaking build files to allow local build
74
{
75
    return m_exitCode;
76
}
77
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
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());
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
86
    dlg.setParameters(params);
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
87
    QMetaObject::invokeMethod(&dlg,"runTasks",Qt::QueuedConnection);
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
88
    dlg.exec();
66.2.15 by Benjamin Zeller
Tweaking build files to allow local build
89
90
    return dlg.m_exitCode;
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
91
}
92
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
93
void ProcessOutputDialog::runTasks( )
94
{
95
    m_hadErrors = false;
96
    disableCloseButton(true);
97
    nextTask();
98
}
99
100
void ProcessOutputDialog::done(int code)
101
{
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
102
    QDialog::done(code);
103
}
104
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
105
void ProcessOutputDialog::disableCloseButton(const bool &disabled)
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
106
{
107
    QPushButton* bt = m_ui->buttonBox->button(QDialogButtonBox::Close);
108
    if(bt) bt->setDisabled(disabled);
109
}
110
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
111
void ProcessOutputDialog::nextTask()
331.1.13 by Benjamin Zeller
- Add support to run more than one click maintenance task in the chroot
112
{
113
    if(m_tasks.length() <= 0)
114
        return;
115
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
116
117
    m_ui->progressBar->setRange(0,0);
118
331.1.13 by Benjamin Zeller
- Add support to run more than one click maintenance task in the chroot
119
    ProjectExplorer::ProcessParameters params = m_tasks.takeFirst();
120
    params.resolveAll();
121
    m_process->setCommand(params.command(),params.arguments());
122
    m_process->setEnvironment(params.environment());
123
    m_process->setWorkingDirectory(params.workingDirectory());
124
    m_process->start();
125
}
126
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
127
void ProcessOutputDialog::on_processFinished(int exitCode)
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
128
{
129
    if (exitCode != 0) {
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
130
        m_hadErrors = true;
131
        on_processReadyReadStandardError(tr("---%0---").arg(QLatin1String(PROCESS_ERROR_EXIT_MESSAGE)));
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
132
    } else {
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
133
        on_processReadyReadStandardOutput(tr("---%0---").arg(QLatin1String(PROCESS_SUCCESS_EXIT_MESSAGE)));
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
134
    }
66.2.15 by Benjamin Zeller
Tweaking build files to allow local build
135
331.1.13 by Benjamin Zeller
- Add support to run more than one click maintenance task in the chroot
136
    if(m_tasks.length() > 0) {
137
        nextTask();
138
        return;
139
    }
140
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
141
    m_ui->progressBar->setRange(0,1);
142
    m_ui->progressBar->setValue(1);
331.1.13 by Benjamin Zeller
- Add support to run more than one click maintenance task in the chroot
143
    disableCloseButton(false);
66.2.15 by Benjamin Zeller
Tweaking build files to allow local build
144
    m_exitCode = exitCode;
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
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
    }
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
152
}
153
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
154
void ProcessOutputDialog::on_processReadyReadStandardOutput(const QString txt)
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
155
{
352.2.1 by Michael Zanetti
make the click output scroll to bottom automatically
156
    QString outText = QString::fromLocal8Bit("<div>");
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
157
158
    if(txt.isEmpty())
352.2.1 by Michael Zanetti
make the click output scroll to bottom automatically
159
        outText.append(QString::fromLocal8Bit(m_process->readAllStandardOutput()));
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
160
    else
352.2.1 by Michael Zanetti
make the click output scroll to bottom automatically
161
        outText.append(txt);
162
163
    outText.append(QString::fromLocal8Bit("</div>"));
164
    m_ui->output->append(outText);
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
165
}
166
443.2.15 by Benjamin Zeller
- Refactor clickdialog to be more generic
167
void ProcessOutputDialog::on_processReadyReadStandardError(const QString txt)
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
168
{
352.2.1 by Michael Zanetti
make the click output scroll to bottom automatically
169
    QString outText = QString::fromLocal8Bit("<div style=\"color:red; font-weight: bold;\">");
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
170
171
    if(txt.isEmpty())
352.2.1 by Michael Zanetti
make the click output scroll to bottom automatically
172
        outText.append(QString::fromLocal8Bit(m_process->readAllStandardError()));
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
173
    else
352.2.1 by Michael Zanetti
make the click output scroll to bottom automatically
174
        outText.append(txt);
175
176
    outText.append(QString::fromLocal8Bit("</div>"));
177
    m_ui->output->append(outText);
66.2.13 by Benjamin Zeller
refactored UbuntuClickDialog to use ui files
178
}
179
180
} // namespace Internal
181
} // namespace Ubuntu