[kphotoalbum] HTMLGenerator: Usability improvements for HTML export.
Johannes Zarl-Zierl
johannes at zarl-zierl.at
Wed Oct 5 21:45:23 UTC 2016
Git commit ae0da97b55f6eac2f9b08f5b60314f90f487d82a by Johannes Zarl-Zierl.
Committed on 05/10/2016 at 21:38.
Pushed by johanneszarl into branch 'master'.
Usability improvements for HTML export.
GUI: File|Generate HTML... dialog
M +5 -6 HTMLGenerator/Generator.cpp
M +76 -28 HTMLGenerator/HTMLDialog.cpp
M +4 -0 HTMLGenerator/HTMLDialog.h
http://commits.kde.org/kphotoalbum/ae0da97b55f6eac2f9b08f5b60314f90f487d82a
diff --git a/HTMLGenerator/Generator.cpp b/HTMLGenerator/Generator.cpp
index a63a402..516d168 100644
--- a/HTMLGenerator/Generator.cpp
+++ b/HTMLGenerator/Generator.cpp
@@ -78,18 +78,16 @@ HTMLGenerator::Generator::~Generator()
}
void HTMLGenerator::Generator::generate()
{
- Debug() << "Generating gallery" << m_setup.title() << "containing" << m_setup.imageList().size() << "entries in" << m_setup.destURL();
+ Debug() << "Generating gallery" << m_setup.title() << "containing" << m_setup.imageList().size() << "entries in" << m_setup.baseDir();
// Generate .kim file
if ( m_setup.generateKimFile() ) {
Debug() << "Generating .kim file...";
bool ok;
QString destURL = m_setup.destURL();
- if ( destURL.isEmpty() )
- destURL = m_setup.baseURL();
ImportExport::Export exp( m_setup.imageList(), kimFileName( false ),
false, -1, ImportExport::ManualCopy,
- destURL + QString::fromLatin1("/") + m_setup.outputDir(), true, &ok);
+ destURL + QDir::separator() + m_setup.outputDir(), true, &ok);
if ( !ok )
{
Debug() << ".kim file failed!";
@@ -658,8 +656,9 @@ bool HTMLGenerator::Generator::linkIndexFile()
ImageSizeCheckBox* resolution = m_setup.activeResolutions()[0];
QString fromFile = QString::fromLatin1("index-%1.html" )
.arg(resolution->text(true));
+ fromFile = m_tempDir.filePath(fromFile);
QString destFile = m_tempDir.filePath( QString::fromLatin1("index.html") );
- bool ok = Utilities::copy( QFileInfo(destFile).path() +QDir::separator() + fromFile, destFile );
+ bool ok = Utilities::copy( fromFile, destFile );
if ( !ok ) {
KMessageBox::error( this, i18n("<p>Unable to copy %1 to %2</p>"
, fromFile , destFile ) );
@@ -762,7 +761,7 @@ void HTMLGenerator::Generator::showBrowser()
ImportExport::Export::showUsageDialog();
if ( ! m_setup.baseURL().isEmpty() )
- new KRun( QUrl(QString::fromLatin1( "%1/%2/index.html" ).arg( m_setup.baseURL() ).arg( m_setup.outputDir()) ),
+ new KRun( QUrl::fromUserInput(QString::fromLatin1( "%1/%2/index.html" ).arg( m_setup.baseURL() ).arg( m_setup.outputDir()) ),
MainWindow::Window::theMainWindow());
m_eventLoop->exit();
diff --git a/HTMLGenerator/HTMLDialog.cpp b/HTMLGenerator/HTMLDialog.cpp
index e028982..9aa619d 100644
--- a/HTMLGenerator/HTMLDialog.cpp
+++ b/HTMLGenerator/HTMLDialog.cpp
@@ -72,6 +72,10 @@ HTMLDialog::HTMLDialog( QWidget* parent )
createContentPage();
createLayoutPage();
createDestinationPage();
+ // destUrl is only relevant for .kim file creation:
+ connect(m_generateKimFile,&QCheckBox::toggled,m_destURL,&QLineEdit::setEnabled);
+ // automatically fill in output directory:
+ connect(m_title,&QLineEdit::editingFinished,this,&HTMLDialog::slotSuggestOutputDir);
QDialogButtonBox *buttonBox = this->buttonBox();
connect(buttonBox, &QDialogButtonBox::accepted, this, &HTMLDialog::accept);
@@ -188,7 +192,7 @@ void HTMLDialog::createLayoutPage()
QWidget* layoutPage = new QWidget;
KPageWidgetItem* page = new KPageWidgetItem( layoutPage, i18n("Layout" ) );
page->setHeader( i18n("Layout" ) );
- page->setIcon( QIcon::fromTheme( QString::fromLatin1( "matrix" )) );
+ page->setIcon( QIcon::fromTheme( QString::fromLatin1( "configure" )) );
addPage(page);
QVBoxLayout* lay1 = new QVBoxLayout( layoutPage );
@@ -303,13 +307,13 @@ void HTMLDialog::createDestinationPage()
QVBoxLayout* lay1 = new QVBoxLayout( destinationPage );
QGridLayout* lay2 = new QGridLayout;
lay1->addLayout( lay2 );
+ int row = -1;
// Base Directory
QLabel* label = new QLabel( i18n("Base directory:"), destinationPage );
- lay2->addWidget( label, 0, 0 );
-
+ lay2->addWidget( label, ++row, 0 );
QHBoxLayout* lay3 = new QHBoxLayout;
- lay2->addLayout( lay3, 0, 1 );
+ lay2->addLayout( lay3, row, 1 );
m_baseDir = new QLineEdit( destinationPage );
lay3->addWidget( m_baseDir );
@@ -322,32 +326,45 @@ void HTMLDialog::createDestinationPage()
connect(but, &QPushButton::clicked, this, &HTMLDialog::selectDir);
m_baseDir->setText( Settings::SettingsData::instance()->HTMLBaseDir() );
- // Base URL
- label = new QLabel( i18n("Base URL:"), destinationPage );
- lay2->addWidget( label, 1, 0 );
+ // Output Directory
+ label = new QLabel( i18n("Gallery directory:"), destinationPage );
+ lay2->addWidget( label, ++row, 0 );
+ m_outputDir = new QLineEdit( destinationPage );
+ lay2->addWidget( m_outputDir, row, 1 );
+ label->setBuddy( m_outputDir );
- m_baseURL = new QLineEdit( destinationPage );
- m_baseURL->setText( Settings::SettingsData::instance()->HTMLBaseURL() );
- lay2->addWidget( m_baseURL, 1, 1 );
- label->setBuddy( m_baseURL );
+ // fully "Assembled" output Directory
+ label = new QLabel( i18n("Output directory:"), destinationPage );
+ lay2->addWidget( label, ++row, 0 );
+ m_outputLabel = new QLabel( destinationPage );
+ lay2->addWidget( m_outputLabel, row, 1 );
+ label->setBuddy( m_outputLabel );
+ connect(m_baseDir, &QLineEdit::textChanged, this, &HTMLDialog::slotUpdateOutputLabel);
+ connect(m_outputDir, &QLineEdit::textChanged, this, &HTMLDialog::slotUpdateOutputLabel);
+ // initial text
+ slotUpdateOutputLabel();
// Destination URL
- label = new QLabel( i18n("URL for final destination:" ), destinationPage );
- lay2->addWidget( label, 2, 0 );
+ label = new QLabel( i18n("URL for final destination of .kim file:" ), destinationPage );
+ label->setToolTip( i18n(
+ "<p>If you move the gallery to a remote location, set this to the destination URL.</p>"
+ "<p>This only affects the generated <filename>.kim</filename> file.</p>"
+ )
+ );
+ lay2->addWidget( label, ++row, 0 );
m_destURL = new QLineEdit( destinationPage );
m_destURL->setText( Settings::SettingsData::instance()->HTMLDestURL() );
- lay2->addWidget( m_destURL, 2, 1 );
+ lay2->addWidget( m_destURL, row, 1 );
label->setBuddy( m_destURL );
- // Output Directory
- label = new QLabel( i18n("Output directory:"), destinationPage );
- lay2->addWidget( label, 3, 0 );
- m_outputDir = new QLineEdit( destinationPage );
- lay2->addWidget( m_outputDir, 3, 1 );
- label->setBuddy( m_outputDir );
+ // Base URL
+ label = new QLabel( i18n("Open gallery in browser:"), destinationPage );
+ lay2->addWidget( label, ++row, 0 );
+ m_openInBrowser = new QCheckBox(destinationPage);
+ m_openInBrowser->setChecked(true);
+ lay2->addWidget( m_openInBrowser, row, 1);
+ label->setBuddy( m_openInBrowser );
- label = new QLabel( i18n("<b>Hint: Press the help button for descriptions of the fields</b>"), destinationPage );
- lay1->addWidget( label );
lay1->addStretch( 1 );
}
@@ -364,7 +381,6 @@ void HTMLDialog::slotOk()
accept();
Settings::SettingsData::instance()->setHTMLBaseDir( m_baseDir->text() );
- Settings::SettingsData::instance()->setHTMLBaseURL( m_baseURL->text() );
Settings::SettingsData::instance()->setHTMLDestURL( m_destURL->text() );
Settings::SettingsData::instance()->setHTMLCopyright( m_copyright->text() );
Settings::SettingsData::instance()->setHTMLDate( m_date->isChecked() );
@@ -384,11 +400,11 @@ void HTMLDialog::slotOk()
void HTMLDialog::selectDir()
{
- QUrl dir = QFileDialog::getExistingDirectoryUrl( this,
+ QString dir = QFileDialog::getExistingDirectory( this,
i18n("Select base directory..."),
- QUrl::fromUserInput(m_baseDir->text()) );
- if ( !dir.url().isNull() )
- m_baseDir->setText( dir.url() );
+ m_baseDir->text() );
+ if ( !dir.isEmpty() )
+ m_baseDir->setText( dir );
}
bool HTMLDialog::checkVars()
@@ -564,6 +580,35 @@ void HTMLDialog::displayThemeDescription(int themenr)
// however, storing author and descriptions separately might be cleaner.
}
+void HTMLDialog::slotUpdateOutputLabel()
+{
+ QString outputDir = QDir(m_baseDir->text()).filePath(m_outputDir->text());
+ // feedback on validity:
+ if (outputDir == m_baseDir->text())
+ {
+ m_outputLabel->setStyleSheet(QString::fromLatin1("QLabel { color : darkred; }"));
+ outputDir.append(i18n("<p>Gallery directory cannot be empty.</p>"));
+ } else if ( QDir(outputDir).exists())
+ {
+ m_outputLabel->setStyleSheet(QString::fromLatin1("QLabel { color : darkorange; }"));
+ outputDir.append(i18n("<p>The output directory already exists.</p>"));
+ } else
+ {
+ m_outputLabel->setStyleSheet(QString::fromLatin1("QLabel { color : black; }"));
+ }
+ m_outputLabel->setText( outputDir );
+
+}
+
+void HTMLDialog::slotSuggestOutputDir()
+{
+ if (m_outputDir->text().isEmpty())
+ {
+ // the title is often an adequate directory name:
+ m_outputDir->setText( m_title->text() );
+ }
+}
+
int HTMLDialog::exec(const DB::FileNameList& list)
{
if (list.empty())
@@ -582,7 +627,10 @@ Setup HTMLGenerator::HTMLDialog::setup() const
Setup setup;
setup.setTitle( m_title->text() );
setup.setBaseDir( m_baseDir->text() );
- setup.setBaseURL( m_baseURL->text() );
+ if (m_openInBrowser->isEnabled())
+ {
+ setup.setBaseURL( m_baseDir->text() );
+ }
setup.setDestURL( m_destURL->text() );
setup.setOutputDir( m_outputDir->text() );
setup.setThumbSize( m_thumbSize->value() );
diff --git a/HTMLGenerator/HTMLDialog.h b/HTMLGenerator/HTMLDialog.h
index 4a61de5..3902519 100644
--- a/HTMLGenerator/HTMLDialog.h
+++ b/HTMLGenerator/HTMLDialog.h
@@ -50,6 +50,8 @@ protected slots:
void slotOk();
void selectDir();
void displayThemeDescription(int);
+ void slotUpdateOutputLabel();
+ void slotSuggestOutputDir();
protected:
bool checkVars();
@@ -68,6 +70,8 @@ private:
QLineEdit* m_baseURL;
QLineEdit* m_destURL;
QLineEdit* m_outputDir;
+ QLabel *m_outputLabel;
+ QCheckBox *m_openInBrowser;
QLineEdit* m_copyright;
QCheckBox* m_date;
QSpinBox* m_thumbSize;
More information about the kde-doc-english
mailing list