#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtGui/QBrush>
+#include <QtGui/QImageReader>
namespace Qt4ProjectManager {
namespace Internal {
+namespace {
+const QLatin1String RemoteIconPath("/usr/share/icons/hicolor/64x64/apps");
+} // anonymous namespace
MaemoDeployableListModel::MaemoDeployableListModel(const Qt4ProFileNode *proFileNode,
ProFileUpdateSetting updateSetting, QObject *parent)
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)
{
if (!canAddDesktopFile())
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)
{
QFile projectFile(m_proFilePath);
#include <projectexplorer/target.h>
#include <utils/qtcassert.h>
+#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
+#include <QtGui/QPixmap>
namespace Qt4ProjectManager {
namespace Internal {
SLOT(setModel(int)));
connect(ui->addDesktopFileButton, SIGNAL(clicked()),
SLOT(addDesktopFile()));
+ connect(ui->addIconButton, SIGNAL(clicked()), SLOT(addIcon()));
handleModelListReset();
}
ui->tableView->reset(); // Otherwise we'll crash if the user is currently editing.
ui->tableView->setModel(0);
ui->addDesktopFileButton->setEnabled(false);
+ ui->addIconButton->setEnabled(false);
}
void MaemoDeployStepWidget::handleModelListReset()
void MaemoDeployStepWidget::setModel(int row)
{
bool canAddDesktopFile = false;
+ bool canAddIconFile = false;
if (row != -1) {
MaemoDeployableListModel *const model
= m_step->deployables()->modelAt(row);
ui->tableView->setModel(model);
ui->tableView->resizeRowsToContents();
canAddDesktopFile = model->canAddDesktopFile();
+ canAddIconFile = model->canAddIcon();
}
ui->addDesktopFileButton->setEnabled(canAddDesktopFile);
+ ui->addIconButton->setEnabled(canAddIconFile);
}
void MaemoDeployStepWidget::addDesktopFile()
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 Qt4ProjectManager