insilmaril@824: #include "exporthtmldialog.h" insilmaril@824: insilmaril@824: #include insilmaril@824: #include insilmaril@824: #include insilmaril@824: insilmaril@824: #include "options.h" insilmaril@824: #include "settings.h" insilmaril@824: #include "warningdialog.h" insilmaril@824: insilmaril@824: insilmaril@824: extern Options options; insilmaril@824: extern QDir vymBaseDir; insilmaril@824: extern Settings settings; insilmaril@824: extern bool debug; insilmaril@824: insilmaril@824: ExportHTMLDialog::ExportHTMLDialog(QWidget* parent) : QDialog(parent) insilmaril@824: { insilmaril@824: ui.setupUi(this); insilmaril@824: insilmaril@824: filepath=""; insilmaril@824: settingsChanged=false; insilmaril@824: insilmaril@824: // signals and slots connections insilmaril@824: connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed())); insilmaril@824: connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool))); insilmaril@824: connect(ui.browseCSSButton, SIGNAL(pressed()), this, SLOT(browseCSSPressed())); insilmaril@824: connect(ui.imageButton, SIGNAL(toggled(bool)), this, SLOT(imageButtonPressed(bool))); insilmaril@824: connect(ui.textColorButton, SIGNAL(toggled(bool)), this, SLOT(textcolorButtonPressed(bool))); insilmaril@824: connect(ui.lineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(dirChanged())); insilmaril@824: connect(ui.lineEditCSS, SIGNAL(textChanged(const QString&)), this, SLOT(cssChanged())); insilmaril@824: connect(ui.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool))); insilmaril@824: connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged())); insilmaril@824: connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed())); insilmaril@824: } insilmaril@824: insilmaril@824: insilmaril@824: void ExportHTMLDialog::readSettings() insilmaril@824: { insilmaril@824: insilmaril@824: dir=settings.readLocalEntry (filepath,"/export/html/exportDir",vymBaseDir.currentDirPath() ); insilmaril@824: ui.lineEditDir->setText(dir); insilmaril@824: insilmaril@824: if ( settings.readLocalEntry (filepath,"/export/html/useImage","yes")=="yes") insilmaril@824: useImage=true; insilmaril@824: else insilmaril@824: useImage=false; insilmaril@824: ui.imageButton->setChecked(useImage); insilmaril@824: insilmaril@824: if ( settings.readLocalEntry (filepath,"/export/html/useTextColor","no")=="yes") insilmaril@824: useTextColor=true; insilmaril@824: else insilmaril@824: useTextColor=false; insilmaril@824: ui.textColorButton->setChecked(useTextColor); insilmaril@824: insilmaril@824: /* TODO this was used in old html export, is not yet in new stylesheet insilmaril@824: if ( settings.readEntry ("/export/html/useHeading","no")=="yes") insilmaril@824: useHeading=true; insilmaril@824: else insilmaril@824: useHeading=false; insilmaril@824: checkBox4_2->setChecked(useHeading); insilmaril@824: */ insilmaril@824: insilmaril@824: if ( settings.readLocalEntry (filepath,"/export/html/saveSettingsInMap","no")=="yes") insilmaril@824: saveSettingsInMap=true; insilmaril@824: else insilmaril@824: saveSettingsInMap=false; insilmaril@824: ui.saveSettingsInMapButton->setChecked(saveSettingsInMap); insilmaril@824: insilmaril@824: if ( settings.readEntry ("/export/html/showOutput","no")=="yes") insilmaril@824: showOutput=true; insilmaril@824: else insilmaril@824: showOutput=false; insilmaril@824: ui.outputButton->setChecked(showOutput); insilmaril@824: insilmaril@824: // For testing better use local styles insilmaril@824: const QString defcss(vymBaseDir.path() + "/styles/vym.css"); insilmaril@824: if (options.isOn ("local")) insilmaril@824: { insilmaril@824: css=defcss; insilmaril@824: } else insilmaril@824: { insilmaril@824: css=settings.readLocalEntry insilmaril@824: (filepath,"/export/html/css",defcss); insilmaril@824: } insilmaril@824: ui.lineEditCSS->setText(css); insilmaril@824: insilmaril@824: postscript=settings.readLocalEntry insilmaril@824: (filepath,"/export/html/postscript",""); insilmaril@824: ui.lineEditPostScript->setText (postscript); insilmaril@824: insilmaril@825: if (!postscript.isEmpty()) insilmaril@824: { insilmaril@824: QMessageBox::warning( 0, tr( "Warning" ),tr( insilmaril@824: "The settings saved in the map " insilmaril@825: "would like to run script:\n\n" insilmaril@824: "%1\n\n" insilmaril@824: "Please check, if you really\n" insilmaril@825: "want to allow this in your system!").arg(postscript)); insilmaril@824: insilmaril@824: } insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::setDir(const QString &d) insilmaril@824: { insilmaril@824: dir=d; insilmaril@824: if (dir.right(1)!="/") dir+="/"; insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::dirChanged() insilmaril@824: { insilmaril@824: setDir (ui.lineEditDir->text()); insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::browseDirectoryPressed() insilmaril@824: { insilmaril@824: QFileDialog fd( this); insilmaril@824: fd.setMode (QFileDialog::DirectoryOnly); insilmaril@824: fd.setCaption(tr("VYM - Export HTML to directory")); insilmaril@824: fd.setModal (true); insilmaril@824: fd.setDirectory (QDir::current()); insilmaril@824: fd.show(); insilmaril@824: insilmaril@824: if ( fd.exec() == QDialog::Accepted ) insilmaril@824: { insilmaril@824: QDir dir=fd.selectedFile(); insilmaril@824: ui.lineEditDir->setText (dir.path() ); insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::imageButtonPressed(bool b) insilmaril@824: { insilmaril@824: useImage=b; insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::textcolorButtonPressed(bool b) insilmaril@824: { insilmaril@824: useTextColor=b; insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::saveSettingsInMapButtonPressed(bool b) insilmaril@824: { insilmaril@824: saveSettingsInMap=b; insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::warningsButtonPressed(bool b) insilmaril@824: { insilmaril@824: showWarnings=b; insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: insilmaril@824: insilmaril@824: void ExportHTMLDialog::outputButtonPressed(bool b) insilmaril@824: { insilmaril@824: showOutput=b; insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::cssChanged() insilmaril@824: { insilmaril@824: css=ui.lineEditCSS->text(); insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: insilmaril@824: QString ExportHTMLDialog::getCSSPath() insilmaril@824: { insilmaril@824: return css; insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::browseCSSPressed() insilmaril@824: { insilmaril@824: QFileDialog fd( this); insilmaril@824: fd.setModal (true); insilmaril@824: fd.setFilter ("Cascading Stylesheet (*.css)"); insilmaril@824: fd.setDirectory (QDir::current()); insilmaril@824: fd.show(); insilmaril@824: insilmaril@824: if ( fd.exec() == QDialog::Accepted ) insilmaril@824: { insilmaril@824: css=fd.selectedFile(); insilmaril@824: ui.lineEditCSS->setText (css ); insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::postscriptChanged() insilmaril@824: { insilmaril@824: postscript=ui.lineEditPostScript->text(); insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::browsePostExportButtonPressed() insilmaril@824: { insilmaril@824: QFileDialog fd( this); insilmaril@824: fd.setModal (true); insilmaril@824: fd.setFilter ("Scripts (*.sh *.pl *.py *.php)"); insilmaril@824: fd.setDirectory (QDir::current()); insilmaril@824: fd.show(); insilmaril@824: insilmaril@824: if ( fd.exec() == QDialog::Accepted ) insilmaril@824: { insilmaril@824: postscript=fd.selectedFile(); insilmaril@824: ui.lineEditPostScript->setText (postscript ); insilmaril@824: settingsChanged=true; insilmaril@824: } insilmaril@824: } insilmaril@824: insilmaril@824: insilmaril@825: void ExportHTMLDialog::saveSettings () insilmaril@824: { insilmaril@824: insilmaril@824: // Save options to settings file insilmaril@824: // (but don't save at destructor, which insilmaril@824: // is called for "cancel", too) insilmaril@824: settings.setLocalEntry (filepath,"/export/html/exportDir",dir); insilmaril@824: settings.setLocalEntry (filepath,"/export/html/postscript",postscript); insilmaril@824: insilmaril@824: if (useImage) insilmaril@824: settings.setLocalEntry (filepath,"/export/html/useImage","yes"); insilmaril@824: else insilmaril@824: settings.setLocalEntry (filepath,"/export/html/useImage","no"); insilmaril@824: insilmaril@824: if (useTextColor) insilmaril@824: settings.setLocalEntry (filepath,"/export/html/useTextColor","yes"); insilmaril@824: else insilmaril@824: settings.setLocalEntry (filepath,"/export/html/useTextColor","no"); insilmaril@824: insilmaril@824: if (showWarnings) insilmaril@824: settings.writeEntry ("/export/html/showWarnings","yes"); insilmaril@824: else insilmaril@824: settings.writeEntry ("/export/html/showWarnings","no"); insilmaril@824: insilmaril@824: if (showOutput) insilmaril@824: settings.writeEntry ("/export/html/showOutput","yes"); insilmaril@824: else insilmaril@824: settings.writeEntry ("/export/html/showOutput","no"); insilmaril@824: insilmaril@824: QString ipath; insilmaril@824: ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png"; insilmaril@824: if (!options.isOn ("local")) insilmaril@824: { insilmaril@824: settings.setLocalEntry insilmaril@824: (filepath,"/export/html/css",css); insilmaril@824: } insilmaril@824: insilmaril@824: if (!saveSettingsInMap) insilmaril@824: settings.clearLocal("/export/html"); insilmaril@824: else insilmaril@824: settings.setLocalEntry insilmaril@824: (filepath,"/export/html/saveSettingsInMap","yes"); insilmaril@824: insilmaril@829: // Provide a smaller URL-icon to improve Layout //FIXME-2 add option to choose this insilmaril@824: QPixmap pm; insilmaril@824: if (!pm.load(ipath,"PNG") ) insilmaril@824: QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath)); insilmaril@824: insilmaril@824: insilmaril@824: if(!pm.save (dir + "flags/flag-url-16x16.png","PNG")) insilmaril@824: QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath)); insilmaril@824: insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::setFilePath(const QString &s) insilmaril@824: { insilmaril@824: filepath=s; insilmaril@824: } insilmaril@824: insilmaril@824: void ExportHTMLDialog::setMapName(const QString &s) insilmaril@824: { insilmaril@824: mapname=s; insilmaril@824: } insilmaril@824: insilmaril@824: QString ExportHTMLDialog::getDir() insilmaril@824: { insilmaril@824: return dir; insilmaril@824: } insilmaril@824: insilmaril@824: bool ExportHTMLDialog::warnings() insilmaril@824: { insilmaril@824: return showWarnings; insilmaril@824: } insilmaril@824: insilmaril@824: bool ExportHTMLDialog::hasChanged() insilmaril@824: { insilmaril@824: return settingsChanged; insilmaril@824: } insilmaril@824: insilmaril@824: