maemopackagecreationwidget.cpp 8.88 KB
Newer Older
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
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "maemopackagecreationwidget.h"
43
#include "ui_maemopackagecreationwidget.h"
44
45

#include "maemopackagecreationstep.h"
46
#include "maemotemplatesmanager.h"
47
#include "maemotoolchain.h"
48

49
#include <coreplugin/editormanager/editormanager.h>
50
51
52
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <qt4projectmanager/qt4buildconfiguration.h>
53
#include <utils/qtcassert.h>
54

55
#include <QtCore/QTimer>
56
57
#include <QtGui/QFileDialog>
#include <QtGui/QImageReader>
58
59
#include <QtGui/QMessageBox>

60
61
using namespace ProjectExplorer;

62
63
64
65
namespace Qt4ProjectManager {
namespace Internal {

MaemoPackageCreationWidget::MaemoPackageCreationWidget(MaemoPackageCreationStep *step)
66
67
68
    : ProjectExplorer::BuildStepConfigWidget(),
      m_step(step),
      m_ui(new Ui::MaemoPackageCreationWidget)
69
{
70
    m_ui->setupUi(this);
ck's avatar
ck committed
71
    m_ui->skipCheckBox->setChecked(!m_step->isPackagingEnabled());
72
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
73
    QTimer::singleShot(0, this, SLOT(initGui()));
74
75
}

Christian Kandeler's avatar
Christian Kandeler committed
76
77
78
79
80
MaemoPackageCreationWidget::~MaemoPackageCreationWidget()
{
    delete m_ui;
}

81
82
83
84
void MaemoPackageCreationWidget::init()
{
}

85
void MaemoPackageCreationWidget::initGui()
86
{
87
88
89
    updateDebianFileList(thisProject());
    updateVersionInfo(thisProject());
    handleControlFileUpdate(thisProject());
90
91
    connect(m_step, SIGNAL(packageFilePathChanged()), this,
        SIGNAL(updateSummary()));
92
93
94
    connect(m_step, SIGNAL(qtVersionChanged()), this,
        SLOT(handleToolchainChanged()));
    handleToolchainChanged();
95
96
97
98
99
100
101
    versionInfoChanged();
    connect(MaemoTemplatesManager::instance(),
        SIGNAL(debianDirContentsChanged(const ProjectExplorer::Project*)),
        this, SLOT(updateDebianFileList(const ProjectExplorer::Project*)));
    connect(MaemoTemplatesManager::instance(),
        SIGNAL(changeLogChanged(const ProjectExplorer::Project*)), this,
        SLOT(updateVersionInfo(const ProjectExplorer::Project*)));
102
103
    connect(MaemoTemplatesManager::instance(),
        SIGNAL(controlChanged(const ProjectExplorer::Project*)), this,
104
105
        SLOT(handleControlFileUpdate(const ProjectExplorer::Project*)));
    connect(m_ui->nameLineEdit, SIGNAL(editingFinished()), SLOT(setName()));
106
107
108
109
}

void MaemoPackageCreationWidget::updateDebianFileList(const ProjectExplorer::Project *project)
{
110
    if (thisProject() == project)
111
112
113
114
115
116
117
118
119
120
121
        m_ui->debianFilesComboBox->clear();
        const QStringList &debianFiles = MaemoTemplatesManager::instance()
            ->debianFiles(project);
        foreach (const QString &fileName, debianFiles) {
            if (fileName != QLatin1String("compat"))
                m_ui->debianFilesComboBox->addItem(fileName);
        }
}

void MaemoPackageCreationWidget::updateVersionInfo(const ProjectExplorer::Project *project)
{
122
    if (project != thisProject())
123
124
        return;

125
126
127
    QString error;
    QString versionString = m_step->versionString(&error);
    if (versionString.isEmpty()) {
Friedemann Kleint's avatar
Friedemann Kleint committed
128
        QMessageBox::critical(this, tr("No Version Available."), error);
129
130
131
        versionString = MaemoPackageCreationStep::DefaultVersionNumber;
    }
    const QStringList list = versionString.split(QLatin1Char('.'),
132
133
134
135
        QString::SkipEmptyParts);
    m_ui->major->setValue(list.value(0, QLatin1String("0")).toInt());
    m_ui->minor->setValue(list.value(1, QLatin1String("0")).toInt());
    m_ui->patch->setValue(list.value(2, QLatin1String("0")).toInt());
136
137
}

138
void MaemoPackageCreationWidget::handleControlFileUpdate(const Project *project)
139
{
140
    if (project != thisProject())
141
        return;
142
143
144
145
    updatePackageManagerIcon(project);
    updateName(project);
    updateShortDescription(project);
}
146

147
148
void MaemoPackageCreationWidget::updatePackageManagerIcon(const Project *project)
{
149
150
151
    QString error;
    const QIcon &icon
        = MaemoTemplatesManager::instance()->packageManagerIcon(project, &error);
152
    if (!error.isEmpty()) {
153
        QMessageBox::critical(this, tr("Could not read icon"), error);
154
    } else {
155
        m_ui->packageManagerIconButton->setIcon(icon);
156
157
        m_ui->packageManagerIconButton->setIconSize(m_ui->packageManagerIconButton->size());
    }
158
159
}

160
161
162
163
164
165
166
167
168
169
170
void MaemoPackageCreationWidget::updateName(const Project *project)
{
    m_ui->nameLineEdit->setText(MaemoTemplatesManager::instance()->name(project));
}

void MaemoPackageCreationWidget::updateShortDescription(const Project *project)
{
    // TODO: Implment
    Q_UNUSED(project);
}

171
172
173
174
175
176
177
178
void MaemoPackageCreationWidget::setPackageManagerIcon()
{
    QString imageFilter = tr("Images") + QLatin1String("( ");
    const QList<QByteArray> &imageTypes = QImageReader::supportedImageFormats();
    foreach (const QByteArray &imageType, imageTypes)
        imageFilter += "*." + QString::fromAscii(imageType) + QLatin1Char(' ');
    imageFilter += QLatin1Char(')');
    const QString iconFileName = QFileDialog::getOpenFileName(this,
179
180
        tr("Choose Image (will be scaled to 48x48 pixels if necessary)"),
        QString(), imageFilter);
181
182
    if (!iconFileName.isEmpty()) {
        QString error;
183
184
        if (!MaemoTemplatesManager::instance()->setPackageManagerIcon(thisProject(),
                iconFileName, &error))
Friedemann Kleint's avatar
Friedemann Kleint committed
185
            QMessageBox::critical(this, tr("Could Not Set New Icon"), error);
186
187
188
    }
}

189
190
191
192
193
194
195
196
197
198
199
200
201
202
void MaemoPackageCreationWidget::setName()
{
    if (!MaemoTemplatesManager::instance()->setName(thisProject(),
            m_ui->nameLineEdit->text())) {
        QMessageBox::critical(this, tr("File Error"),
            tr("Could not set project name."));
    }
}

void MaemoPackageCreationWidget::setShortDescription()
{

}

203
204
void MaemoPackageCreationWidget::handleToolchainChanged()
{
205
206
    if (!m_step->maemoToolChain())
        return;
207
208
209
210
211
212
    m_ui->skipCheckBox
        ->setVisible(m_step->maemoToolChain()->allowsPackagingDisabling());
    m_ui->skipCheckBox->setChecked(!m_step->isPackagingEnabled());
    emit updateSummary();
}

213
214
QString MaemoPackageCreationWidget::summaryText() const
{
215
216
217
218
219
    const QString constantString = tr("<b>Create Package:</b> ");
    const QString dynamicString = m_step->isPackagingEnabled()
        ? QDir::toNativeSeparators(m_step->packageFilePath())
        : tr("(Packaging disabled)");
    return constantString + dynamicString;
220
221
222
223
224
225
226
}

QString MaemoPackageCreationWidget::displayName() const
{
    return m_step->displayName();
}

ck's avatar
ck committed
227
228
void MaemoPackageCreationWidget::handleSkipButtonToggled(bool checked)
{
229
230
231
    m_ui->major->setEnabled(!checked);
    m_ui->minor->setEnabled(!checked);
    m_ui->patch->setEnabled(!checked);
232
233
    m_ui->debianFilesComboBox->setEnabled(!checked);
    m_ui->editDebianFileButton->setEnabled(!checked);
ck's avatar
ck committed
234
    m_step->setPackagingEnabled(!checked);
235
    emit updateSummary();
ck's avatar
ck committed
236
237
}

238
239
void MaemoPackageCreationWidget::versionInfoChanged()
{
240
241
242
243
244
    QString error;
    const bool success = m_step->setVersionString(m_ui->major->text()
        + QLatin1Char('.') + m_ui->minor->text() + QLatin1Char('.')
        + m_ui->patch->text(), &error);
    if (!success)
Friedemann Kleint's avatar
Friedemann Kleint committed
245
        QMessageBox::critical(this, tr("Could Not Set Version Number"), error);
246
247
}

248
249
void MaemoPackageCreationWidget::editDebianFile()
{
250
251
252
    const QString debianFilePath
        = MaemoTemplatesManager::instance()->debianDirPath(thisProject())
              + QLatin1Char('/') + m_ui->debianFilesComboBox->currentText();
253
254
255
    Core::EditorManager::instance()->openEditor(debianFilePath,
                                                QString(),
                                                Core::EditorManager::ModeSwitch);
256
257
}

258
259
260
261
262
Project *MaemoPackageCreationWidget::thisProject() const
{
    return m_step->buildConfiguration()->target()->project();
}

263
264
} // namespace Internal
} // namespace Qt4ProjectManager