diff --git a/src/skanlite.cpp b/src/skanlite.cpp --- a/src/skanlite.cpp +++ b/src/skanlite.cpp @@ -372,18 +372,45 @@ } } +bool pathExists(const QString& dir, QWidget* parent) +{ + // propose directory creation if doesn't exists + QUrl dirUrl(dir); + if (dirUrl.isLocalFile()) { + QDir path(dirUrl.path()); + if (!path.exists()) { + if (KMessageBox::questionYesNo(parent, i18n("Directory doesn't exist, do you wish to create it?")) == KMessageBox::ButtonCode::Yes ) { + if (!path.mkpath(QLatin1String("."))) { + KMessageBox::error(parent, i18n("Could not create directory %1", path.path())); + return false; + } + } + } + } + + if (parent) { + // allows UI to repaint itself after KMessageBox is closed + // as rendering may be freezed till huge image is saved to a slow drive. + parent->repaint(); + } + return true; +} + void Skanlite::saveImage() { // ask the first time if we are in "ask on first" mode - if ((m_settingsUi.saveModeCB->currentIndex() == SaveModeAskFirst) && m_firstImage) { + QString dir = QDir::cleanPath(m_saveLocation->u_urlRequester->url().url()).append(QLatin1Char('/')); //make sure whole value is processed as path to directory + + while ((m_firstImage && (m_settingsUi.saveModeCB->currentIndex() == SaveModeAskFirst)) || + !pathExists(dir, this)) { if (m_saveLocation->exec() != QFileDialog::Accepted) { m_ksanew->scanCancel(); // In case we are cancelling a document feeder scan return; } + dir = QDir::cleanPath(m_saveLocation->u_urlRequester->url().url()).append(QLatin1Char('/')); m_firstImage = false; } - QString dir = QDir::cleanPath(m_saveLocation->u_urlRequester->url().url()).append(QLatin1Char('/')); //make sure whole value is processed as path to directory QString prefix = m_saveLocation->u_imgPrefix->text(); QString imgFormat = m_saveLocation->u_imgFormat->currentText().toLower(); int fileNumber = m_saveLocation->u_numStartFrom->value();