Commit 2bcd0daf authored by Alexander Stippich's avatar Alexander Stippich
Browse files

fix preselecting the image format

with the one from the settings dialog.
image/+fileSuffix does not always correspond to the mimetype

BUG: 441223
BUG: 419274
parent a2678f5d
......@@ -57,17 +57,63 @@ QUrl SaveLocation::folderUrl() const
return folderUrl.adjusted(QUrl::NormalizePathSegments);
}
QString SaveLocation::imagePrefix() const { return m_ui->u_imgPrefix->text(); }
QString SaveLocation::imageFormat() const { return m_ui->u_imgFormat->currentText().toLower(); }
int SaveLocation::startNumber() const { return m_ui->u_numStartFrom->value(); }
int SaveLocation::startNumberMax() const { return m_ui->u_numStartFrom->maximum(); }
QString SaveLocation::imagePrefix() const
{
return m_ui->u_imgPrefix->text();
}
QString SaveLocation::imageMimetype() const
{
return m_ui->u_imgFormat->currentData().toString();
}
QString SaveLocation::imageSuffix() const
{
return m_ui->u_imgFormat->currentText().toLower();
}
int SaveLocation::startNumber() const
{
return m_ui->u_numStartFrom->value();
}
int SaveLocation::startNumberMax() const
{
return m_ui->u_numStartFrom->maximum();
}
void SaveLocation::setFolderUrl(const QUrl &url)
{
m_ui->u_urlRequester->setUrl(url);
}
void SaveLocation::setFolderUrl(const QUrl &url) { m_ui->u_urlRequester->setUrl(url); }
void SaveLocation::setImagePrefix(const QString &prefix) { m_ui->u_imgPrefix->setText(prefix); }
void SaveLocation::setImageFormats(const QStringList &formats) { m_ui->u_imgFormat->addItems(formats); }
void SaveLocation::setImageFormat(const QString &format) { m_ui->u_imgFormat->setCurrentText(format); }
void SaveLocation::setStartNumber(int number) { m_ui->u_numStartFrom->setValue(number); }
void SaveLocation::setImagePrefix(const QString &prefix)
{
m_ui->u_imgPrefix->setText(prefix);
}
void SaveLocation::addImageFormat(const QString &suffix, const QString &mimetype)
{
m_ui->u_imgFormat->addItem(suffix, mimetype);
}
void SaveLocation::setImageFormatIndex(int index)
{
m_ui->u_imgFormat->setCurrentIndex(index);
}
void SaveLocation::setImageFormat(const QString &suffix)
{
int index = m_ui->u_imgFormat->findText(suffix);
if (index >= 0) {
m_ui->u_imgFormat->setCurrentIndex(index);
}
}
void SaveLocation::setStartNumber(int number)
{
m_ui->u_numStartFrom->setValue(number);
}
void SaveLocation::setOpenRequesterOnShow(bool open)
{
......
......@@ -26,17 +26,18 @@ public:
QUrl folderUrl() const;
QString imagePrefix() const;
QString imageFormat() const;
QString imageMimetype() const;
QString imageSuffix() const;
int startNumber() const;
int startNumberMax() const;
void setFolderUrl(const QUrl &url);
void setImagePrefix(const QString &prefix);
void setImageFormat(const QString &format);
void setImageFormat(const QString &suffix);
void setImageFormatIndex(int index);
void addImageFormat(const QString &type, const QString &mimetype);
void setStartNumber(int number);
void setImageFormats(const QStringList &formats);
void setOpenRequesterOnShow(bool open);
protected:
......
......@@ -135,25 +135,19 @@ Skanlite::Skanlite(const QString &device, QWidget *parent)
m_filter16BitList << QStringLiteral("image/png");
m_filter16BitList << QStringLiteral("image/tiff");
// fill m_filterList (...) and m_typeList (list of file suffixes)
// fill m_filterList (...)
{
QStringList namedMimeTypes;
for (const QString &mimeStr : qAsConst(m_filterList)) {
QMimeType mimeType = QMimeDatabase().mimeTypeForName(mimeStr);
namedMimeTypes.append(mimeType.name());
QStringList fileSuffixes = mimeType.suffixes();
if (fileSuffixes.size() > 0) {
m_typeList << fileSuffixes.first();
}
m_settingsUi.imgFormat->addItem(mimeType.preferredSuffix(), mimeType.name());
m_saveLocation->addImageFormat(mimeType.preferredSuffix(), mimeType.name());
}
m_filterList << std::move(namedMimeTypes);
}
m_settingsUi.imgFormat->addItems(m_typeList);
m_saveLocation->setImageFormats(m_typeList);
mainLayout->addWidget(settingsWidget);
QDialogButtonBox *dlgButtonBoxBottom = new QDialogButtonBox(this);
......@@ -171,7 +165,7 @@ Skanlite::Skanlite(const QString &device, QWidget *parent)
// default directory for the save dialog
m_saveLocation->setFolderUrl(m_settingsUi.saveDirRequester->url());
m_saveLocation->setImagePrefix(m_settingsUi.imgPrefix->text());
m_saveLocation->setImageFormat(m_settingsUi.imgFormat->currentText());
m_saveLocation->setImageFormatIndex(m_settingsUi.imgFormat->currentIndex());
}
// open the scan device
......@@ -281,7 +275,12 @@ void Skanlite::readSettings(void)
}
m_settingsUi.saveDirRequester->setUrl(saving.readEntry("Location", QUrl(QDir::homePath())));
m_settingsUi.imgPrefix->setText(saving.readEntry("NamePrefix", i18nc("prefix for auto naming", "Image-")));
m_settingsUi.imgFormat->setCurrentText(saving.readEntry("ImgFormat", "png"));
QString format = saving.readEntry("ImgFormat", "image/png");
int index = m_settingsUi.imgFormat->findData(format);
if (index >= 0) {
m_settingsUi.imgFormat->setCurrentIndex(index);
}
m_settingsUi.imgQuality->setValue(saving.readEntry("ImgQuality", 90));
m_settingsUi.setQuality->setChecked(saving.readEntry("SetQuality", false));
m_settingsUi.showB4Save->setChecked(saving.readEntry("ShowBeforeSave", true));
......@@ -313,7 +312,7 @@ void Skanlite::showSettingsDialog(void)
saving.writeEntry("SaveMode", m_settingsUi.saveModeCB->currentIndex());
saving.writeEntry("Location", m_settingsUi.saveDirRequester->url());
saving.writeEntry("NamePrefix", m_settingsUi.imgPrefix->text());
saving.writeEntry("ImgFormat", m_settingsUi.imgFormat->currentText());
saving.writeEntry("ImgFormat", m_settingsUi.imgFormat->currentData().toString());
saving.writeEntry("SetQuality", m_settingsUi.setQuality->isChecked());
saving.writeEntry("ImgQuality", m_settingsUi.imgQuality->value());
saving.writeEntry("ShowBeforeSave", m_settingsUi.showB4Save->isChecked());
......@@ -338,7 +337,7 @@ void Skanlite::showSettingsDialog(void)
// pressing OK in the settings dialog means use those settings.
m_saveLocation->setFolderUrl(m_settingsUi.saveDirRequester->url());
m_saveLocation->setImagePrefix(m_settingsUi.imgPrefix->text());
m_saveLocation->setImageFormat(m_settingsUi.imgFormat->currentText());
m_saveLocation->setImageFormatIndex(m_settingsUi.imgFormat->currentIndex());
m_firstImage = true;
}
......@@ -405,21 +404,21 @@ void Skanlite::saveImage()
m_saveLocation->setFolderUrl(dirUrl);
}
QString prefix = m_saveLocation->imagePrefix();
QString imgFormat = m_saveLocation->imageFormat().toLower();
QString imageMimetype = m_saveLocation->imageMimetype();
int fileNumber = m_saveLocation->startNumber();
QStringList filterList = m_filterList;
QStringList filterList;
if ((m_img.format() == QImage::Format_Grayscale16) ||
(m_img.format() == QImage::Format_RGBX64))
{
filterList = m_filter16BitList;
if (imgFormat != QLatin1String("png") && imgFormat != QLatin1String("tif")
&& imgFormat != QLatin1String("tiff")) {
imgFormat = QStringLiteral("png");
if (imageMimetype != QLatin1String("image/png") && imageMimetype != QLatin1String("image/tiff")) {
imageMimetype = QStringLiteral("image/png");
KMessageBox::information(this, i18n("The image will be saved in the PNG format, as the selected image type does not support saving 16 bit color images."));
}
} else {
filterList = m_filterList;
}
// find next available file name for name suggestion
......@@ -429,7 +428,7 @@ void Skanlite::saveImage()
fname = QStringLiteral("%1%2.%3")
.arg(prefix)
.arg(i, 4, 10, QLatin1Char('0'))
.arg(imgFormat);
.arg(m_saveLocation->imageSuffix());
fileUrl = dirUrl;
fileUrl.setPath(fileUrl.path() + fname);
......@@ -451,10 +450,8 @@ void Skanlite::saveImage()
// NOTE it is probably a bug that both setDirectoryUrl and selectUrl have
// to be set to get remote urls to work
QStringList actualFilterList = filterList;
QString currentMimeFilter = QLatin1String("image/") + imgFormat;
saveDialog.setMimeTypeFilters(actualFilterList);
saveDialog.selectMimeTypeFilter(currentMimeFilter);
saveDialog.setMimeTypeFilters(filterList);
saveDialog.selectMimeTypeFilter(imageMimetype);
if (saveDialog.exec() != QFileDialog::Accepted) {
return;
......
......@@ -92,7 +92,6 @@ private:
DBusInterface m_dbusInterface;
QStringList m_filterList;
QStringList m_filter16BitList;
QStringList m_typeList;
bool m_firstImage;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment