forked from qt-creator/qt-creator
Maemo: Allow adding an application launcher icon via the GUI.
Reviewed-by: kh1
This commit is contained in:
@@ -41,9 +41,13 @@
|
|||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtGui/QBrush>
|
#include <QtGui/QBrush>
|
||||||
|
#include <QtGui/QImageReader>
|
||||||
|
|
||||||
namespace Qt4ProjectManager {
|
namespace Qt4ProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
namespace {
|
||||||
|
const QLatin1String RemoteIconPath("/usr/share/icons/hicolor/64x64/apps");
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
MaemoDeployableListModel::MaemoDeployableListModel(const Qt4ProFileNode *proFileNode,
|
MaemoDeployableListModel::MaemoDeployableListModel(const Qt4ProFileNode *proFileNode,
|
||||||
ProFileUpdateSetting updateSetting, QObject *parent)
|
ProFileUpdateSetting updateSetting, QObject *parent)
|
||||||
@@ -232,6 +236,21 @@ bool MaemoDeployableListModel::canAddDesktopFile() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MaemoDeployableListModel::canAddIcon() const
|
||||||
|
{
|
||||||
|
if (m_projectType == LibraryTemplate)
|
||||||
|
return false;
|
||||||
|
const QList<QByteArray> &imageTypes = QImageReader::supportedImageFormats();
|
||||||
|
foreach (const MaemoDeployable &d, m_deployables) {
|
||||||
|
const QByteArray extension
|
||||||
|
= QFileInfo(d.localFilePath).suffix().toLocal8Bit();
|
||||||
|
if (d.remoteDir.startsWith(RemoteIconPath)
|
||||||
|
&& imageTypes.contains(extension))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool MaemoDeployableListModel::addDesktopFile(QString &error)
|
bool MaemoDeployableListModel::addDesktopFile(QString &error)
|
||||||
{
|
{
|
||||||
if (!canAddDesktopFile())
|
if (!canAddDesktopFile())
|
||||||
@@ -283,6 +302,28 @@ bool MaemoDeployableListModel::addDesktopFile(QString &error)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MaemoDeployableListModel::addIcon(const QString &fileName, QString &error)
|
||||||
|
{
|
||||||
|
if (!canAddIcon())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
const QString filesLine = QLatin1String("icon.files = ") + fileName;
|
||||||
|
const QString pathLine = QLatin1String("icon.path = ") + RemoteIconPath;
|
||||||
|
const QLatin1String installsLine("INSTALLS += icon");
|
||||||
|
if (!addLinesToProFile(QStringList() << filesLine << pathLine
|
||||||
|
<< installsLine)) {
|
||||||
|
error = tr("Error writing project file.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||||
|
const QString filePath = QFileInfo(m_proFilePath).path()
|
||||||
|
+ QLatin1Char('/') + fileName;
|
||||||
|
m_deployables << MaemoDeployable(filePath, RemoteIconPath);
|
||||||
|
endInsertRows();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool MaemoDeployableListModel::addLinesToProFile(const QStringList &lines)
|
bool MaemoDeployableListModel::addLinesToProFile(const QStringList &lines)
|
||||||
{
|
{
|
||||||
QFile projectFile(m_proFilePath);
|
QFile projectFile(m_proFilePath);
|
||||||
|
|||||||
@@ -68,7 +68,9 @@ public:
|
|||||||
QString proFilePath() const { return m_proFilePath; }
|
QString proFilePath() const { return m_proFilePath; }
|
||||||
bool hasTargetPath() const { return m_hasTargetPath; }
|
bool hasTargetPath() const { return m_hasTargetPath; }
|
||||||
bool canAddDesktopFile() const;
|
bool canAddDesktopFile() const;
|
||||||
|
bool canAddIcon() const;
|
||||||
bool addDesktopFile(QString &error);
|
bool addDesktopFile(QString &error);
|
||||||
|
bool addIcon(const QString &fileName, QString &error);
|
||||||
ProFileUpdateSetting proFileUpdateSetting() const {
|
ProFileUpdateSetting proFileUpdateSetting() const {
|
||||||
return m_proFileUpdateSetting;
|
return m_proFileUpdateSetting;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,9 @@
|
|||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include <QtGui/QFileDialog>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
|
#include <QtGui/QPixmap>
|
||||||
|
|
||||||
namespace Qt4ProjectManager {
|
namespace Qt4ProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -35,6 +37,7 @@ MaemoDeployStepWidget::MaemoDeployStepWidget(MaemoDeployStep *step) :
|
|||||||
SLOT(setModel(int)));
|
SLOT(setModel(int)));
|
||||||
connect(ui->addDesktopFileButton, SIGNAL(clicked()),
|
connect(ui->addDesktopFileButton, SIGNAL(clicked()),
|
||||||
SLOT(addDesktopFile()));
|
SLOT(addDesktopFile()));
|
||||||
|
connect(ui->addIconButton, SIGNAL(clicked()), SLOT(addIcon()));
|
||||||
handleModelListReset();
|
handleModelListReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +107,7 @@ void MaemoDeployStepWidget::handleModelListToBeReset()
|
|||||||
ui->tableView->reset(); // Otherwise we'll crash if the user is currently editing.
|
ui->tableView->reset(); // Otherwise we'll crash if the user is currently editing.
|
||||||
ui->tableView->setModel(0);
|
ui->tableView->setModel(0);
|
||||||
ui->addDesktopFileButton->setEnabled(false);
|
ui->addDesktopFileButton->setEnabled(false);
|
||||||
|
ui->addIconButton->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoDeployStepWidget::handleModelListReset()
|
void MaemoDeployStepWidget::handleModelListReset()
|
||||||
@@ -120,14 +124,17 @@ void MaemoDeployStepWidget::handleModelListReset()
|
|||||||
void MaemoDeployStepWidget::setModel(int row)
|
void MaemoDeployStepWidget::setModel(int row)
|
||||||
{
|
{
|
||||||
bool canAddDesktopFile = false;
|
bool canAddDesktopFile = false;
|
||||||
|
bool canAddIconFile = false;
|
||||||
if (row != -1) {
|
if (row != -1) {
|
||||||
MaemoDeployableListModel *const model
|
MaemoDeployableListModel *const model
|
||||||
= m_step->deployables()->modelAt(row);
|
= m_step->deployables()->modelAt(row);
|
||||||
ui->tableView->setModel(model);
|
ui->tableView->setModel(model);
|
||||||
ui->tableView->resizeRowsToContents();
|
ui->tableView->resizeRowsToContents();
|
||||||
canAddDesktopFile = model->canAddDesktopFile();
|
canAddDesktopFile = model->canAddDesktopFile();
|
||||||
|
canAddIconFile = model->canAddIcon();
|
||||||
}
|
}
|
||||||
ui->addDesktopFileButton->setEnabled(canAddDesktopFile);
|
ui->addDesktopFileButton->setEnabled(canAddDesktopFile);
|
||||||
|
ui->addIconButton->setEnabled(canAddIconFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoDeployStepWidget::addDesktopFile()
|
void MaemoDeployStepWidget::addDesktopFile()
|
||||||
@@ -146,5 +153,46 @@ void MaemoDeployStepWidget::addDesktopFile()
|
|||||||
ui->tableView->resizeRowsToContents();
|
ui->tableView->resizeRowsToContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MaemoDeployStepWidget::addIcon()
|
||||||
|
{
|
||||||
|
const int modelRow = ui->modelComboBox->currentIndex();
|
||||||
|
if (modelRow == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
MaemoDeployableListModel *const model
|
||||||
|
= m_step->deployables()->modelAt(modelRow);
|
||||||
|
const QString origFilePath = QFileDialog::getOpenFileName(this,
|
||||||
|
tr("Choose Icon (will be scaled to 64x64 pixels, if necessary)"),
|
||||||
|
model->projectDir(), QLatin1String("(*.png)"));
|
||||||
|
if (origFilePath.isEmpty())
|
||||||
|
return;
|
||||||
|
QPixmap pixmap(origFilePath);
|
||||||
|
if (pixmap.isNull()) {
|
||||||
|
QMessageBox::critical(this, tr("Invalid Icon"),
|
||||||
|
tr("Unable to read image"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QSize iconSize(64, 64);
|
||||||
|
if (pixmap.size() != iconSize)
|
||||||
|
pixmap = pixmap.scaled(iconSize);
|
||||||
|
const QString newFileName = model->projectName() + QLatin1Char('.')
|
||||||
|
+ QFileInfo(origFilePath).suffix();
|
||||||
|
const QString newFilePath = model->projectDir() + QLatin1Char('/')
|
||||||
|
+ newFileName;
|
||||||
|
if (!pixmap.save(newFilePath)) {
|
||||||
|
QMessageBox::critical(this, tr("Failed to Save Icon"),
|
||||||
|
tr("Could not save icon to '%1'.").arg(newFilePath));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString error;
|
||||||
|
if (!model->addIcon(newFileName, error)) {
|
||||||
|
QMessageBox::critical(this, tr("Could Not Add Icon"),
|
||||||
|
tr("Error adding icon: %1").arg(error));
|
||||||
|
}
|
||||||
|
ui->addIconButton->setEnabled(model->canAddIcon());
|
||||||
|
ui->tableView->resizeRowsToContents();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Qt4ProjectManager
|
} // namespace Qt4ProjectManager
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ private:
|
|||||||
Q_SLOT void handleModelListToBeReset();
|
Q_SLOT void handleModelListToBeReset();
|
||||||
Q_SLOT void handleModelListReset();
|
Q_SLOT void handleModelListReset();
|
||||||
Q_SLOT void addDesktopFile();
|
Q_SLOT void addDesktopFile();
|
||||||
|
Q_SLOT void addIcon();
|
||||||
|
|
||||||
virtual void init();
|
virtual void init();
|
||||||
virtual QString summaryText() const;
|
virtual QString summaryText() const;
|
||||||
|
|||||||
@@ -154,6 +154,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="addIconButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add Launcher Icon ...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|||||||
Reference in New Issue
Block a user