exporthtmldialog.cpp
author insilmaril
Tue, 06 Apr 2010 13:30:07 +0000
changeset 843 2d36a7bb0867
parent 829 832e96c9abb6
permissions -rw-r--r--
(Very) minor changes for debugging output
     1 #include "exporthtmldialog.h"
     2 
     3 #include <QFileDialog>
     4 #include <QMessageBox>
     5 #include <QTextStream>
     6 
     7 #include "options.h"
     8 #include "settings.h"
     9 #include "warningdialog.h"
    10 
    11 
    12 extern Options options;
    13 extern QDir vymBaseDir;
    14 extern Settings settings;
    15 extern bool debug;
    16 
    17 ExportHTMLDialog::ExportHTMLDialog(QWidget* parent) : QDialog(parent)
    18 {
    19     ui.setupUi(this);
    20 
    21 	filepath="";
    22 	settingsChanged=false;
    23 
    24     // signals and slots connections
    25     connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed()));
    26     connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool)));
    27     connect(ui.browseCSSButton, SIGNAL(pressed()), this, SLOT(browseCSSPressed()));
    28     connect(ui.imageButton, SIGNAL(toggled(bool)), this, SLOT(imageButtonPressed(bool)));
    29     connect(ui.textColorButton, SIGNAL(toggled(bool)), this, SLOT(textcolorButtonPressed(bool)));
    30     connect(ui.lineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(dirChanged()));
    31     connect(ui.lineEditCSS, SIGNAL(textChanged(const QString&)), this, SLOT(cssChanged()));
    32     connect(ui.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool)));
    33     connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged()));
    34     connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed()));
    35 }	
    36 
    37 
    38 void ExportHTMLDialog::readSettings()
    39 {
    40 
    41 	dir=settings.readLocalEntry (filepath,"/export/html/exportDir",vymBaseDir.currentDirPath() );
    42 	ui.lineEditDir->setText(dir);
    43 	
    44     if ( settings.readLocalEntry (filepath,"/export/html/useImage","yes")=="yes")
    45 		useImage=true;
    46 	else	
    47 		useImage=false;
    48 	ui.imageButton->setChecked(useImage);
    49 		
    50 	if ( settings.readLocalEntry (filepath,"/export/html/useTextColor","no")=="yes")
    51 		useTextColor=true;
    52 	else	
    53 		useTextColor=false;
    54 	ui.textColorButton->setChecked(useTextColor);
    55 	
    56 /* TODO this was used in old html export, is not yet in new stylesheet
    57 	if ( settings.readEntry ("/export/html/useHeading","no")=="yes")
    58 		useHeading=true;
    59 	else	
    60 		useHeading=false;
    61 	checkBox4_2->setChecked(useHeading);
    62 */		
    63 
    64 	if ( settings.readLocalEntry (filepath,"/export/html/saveSettingsInMap","no")=="yes")
    65 		saveSettingsInMap=true;
    66 	else	
    67 		saveSettingsInMap=false;
    68 	ui.saveSettingsInMapButton->setChecked(saveSettingsInMap);
    69 
    70 	if ( settings.readEntry ("/export/html/showOutput","no")=="yes")
    71 		showOutput=true;
    72 	else	
    73 		showOutput=false;
    74 	ui.outputButton->setChecked(showOutput);
    75 
    76 	// For testing better use local styles
    77     const QString defcss(vymBaseDir.path() + "/styles/vym.css");
    78 	if (options.isOn ("local"))
    79 	{
    80 		css=defcss;
    81 	} else
    82 	{
    83 		css=settings.readLocalEntry 
    84 			(filepath,"/export/html/css",defcss);	
    85 	}
    86 	ui.lineEditCSS->setText(css);
    87 	
    88 	postscript=settings.readLocalEntry
    89 		(filepath,"/export/html/postscript","");
    90 	ui.lineEditPostScript->setText (postscript);	
    91 
    92 	if (!postscript.isEmpty())
    93 	{
    94 		QMessageBox::warning( 0, tr( "Warning" ),tr(
    95 		"The settings saved in the map "
    96 		"would like to run script:\n\n"
    97 		"%1\n\n"
    98 		"Please check, if you really\n"
    99 		"want to allow this in your system!").arg(postscript));
   100 		
   101 	}
   102 }
   103 
   104 void ExportHTMLDialog::setDir(const QString &d)
   105 {
   106 	dir=d;
   107 	if (dir.right(1)!="/") dir+="/";
   108 }
   109 
   110 void ExportHTMLDialog::dirChanged()
   111 {
   112 	setDir (ui.lineEditDir->text());
   113 	settingsChanged=true;
   114 }
   115 
   116 void ExportHTMLDialog::browseDirectoryPressed()
   117 {
   118    	QFileDialog fd( this);
   119 	fd.setMode (QFileDialog::DirectoryOnly);
   120 	fd.setCaption(tr("VYM - Export HTML to directory"));
   121 	fd.setModal (true);
   122 	fd.setDirectory (QDir::current());
   123 	fd.show();
   124 
   125 	if ( fd.exec() == QDialog::Accepted )
   126 	{
   127 		QDir dir=fd.selectedFile();
   128 		ui.lineEditDir->setText (dir.path() );
   129 		settingsChanged=true;
   130 	}
   131 }
   132 
   133 void ExportHTMLDialog::imageButtonPressed(bool b)
   134 {
   135 	useImage=b;
   136 	settingsChanged=true;
   137 }
   138 
   139 void ExportHTMLDialog::textcolorButtonPressed(bool b)
   140 {
   141 	useTextColor=b;	
   142 	settingsChanged=true;
   143 }
   144 
   145 void ExportHTMLDialog::saveSettingsInMapButtonPressed(bool b)
   146 {
   147 	saveSettingsInMap=b;	
   148 	settingsChanged=true;
   149 }
   150 
   151 void ExportHTMLDialog::warningsButtonPressed(bool b)
   152 {
   153 	showWarnings=b;
   154 	settingsChanged=true;
   155 }
   156 
   157 
   158 void ExportHTMLDialog::outputButtonPressed(bool b)
   159 {
   160 	showOutput=b;
   161 	settingsChanged=true;
   162 }
   163 
   164 void ExportHTMLDialog::cssChanged()
   165 {
   166 	css=ui.lineEditCSS->text();
   167 	settingsChanged=true;
   168 }
   169 
   170 QString ExportHTMLDialog::getCSSPath()
   171 {
   172 	return css;
   173 }
   174 
   175 void ExportHTMLDialog::browseCSSPressed()
   176 {
   177    	QFileDialog fd( this);
   178 	fd.setModal (true);
   179 	fd.setFilter ("Cascading Stylesheet (*.css)");
   180 	fd.setDirectory (QDir::current());
   181 	fd.show();
   182 
   183 	if ( fd.exec() == QDialog::Accepted )
   184 	{
   185 		css=fd.selectedFile();
   186 		ui.lineEditCSS->setText (css );
   187 		settingsChanged=true;
   188 	}
   189 }
   190 
   191 void ExportHTMLDialog::postscriptChanged()
   192 {
   193 	postscript=ui.lineEditPostScript->text();
   194 	settingsChanged=true;
   195 }
   196 
   197 void ExportHTMLDialog::browsePostExportButtonPressed()
   198 {
   199 	QFileDialog fd( this);
   200 	fd.setModal (true);
   201 	fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
   202 	fd.setDirectory (QDir::current());
   203 	fd.show();
   204 
   205 	if ( fd.exec() == QDialog::Accepted )
   206 	{
   207 		postscript=fd.selectedFile();
   208 		ui.lineEditPostScript->setText (postscript );
   209 		settingsChanged=true;
   210 	}
   211 }
   212 
   213 
   214 void ExportHTMLDialog::saveSettings ()
   215 {
   216 
   217 	// Save options to settings file 
   218 	// (but don't save at destructor, which
   219 	// is called for "cancel", too)
   220 	settings.setLocalEntry (filepath,"/export/html/exportDir",dir);
   221 	settings.setLocalEntry (filepath,"/export/html/postscript",postscript);
   222 
   223     if (useImage)
   224 		settings.setLocalEntry (filepath,"/export/html/useImage","yes");
   225     else
   226 		settings.setLocalEntry (filepath,"/export/html/useImage","no");	
   227 	
   228   if (useTextColor)
   229 		settings.setLocalEntry (filepath,"/export/html/useTextColor","yes");
   230     else
   231 		settings.setLocalEntry (filepath,"/export/html/useTextColor","no");	
   232 	
   233    if (showWarnings)
   234 		settings.writeEntry ("/export/html/showWarnings","yes");
   235     else
   236 		settings.writeEntry ("/export/html/showWarnings","no");	
   237 			
   238 	if (showOutput)
   239 		settings.writeEntry ("/export/html/showOutput","yes");
   240 	else
   241 		settings.writeEntry ("/export/html/showOutput","no");	
   242 
   243 	QString ipath;	
   244 	ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
   245 	if (!options.isOn ("local"))
   246 	{
   247 		settings.setLocalEntry 
   248 			(filepath,"/export/html/css",css);	
   249 	}
   250 
   251 	if (!saveSettingsInMap)
   252 		settings.clearLocal("/export/html");
   253 	else	
   254 		settings.setLocalEntry 
   255 			(filepath,"/export/html/saveSettingsInMap","yes");
   256 
   257 	// Provide a smaller URL-icon to improve Layout //FIXME-2 add option to choose this
   258 	QPixmap pm;
   259 	if (!pm.load(ipath,"PNG") )
   260 		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
   261 		
   262 		
   263 	if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
   264 		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
   265 
   266 }
   267 
   268 void ExportHTMLDialog::setFilePath(const QString &s)
   269 {
   270 	filepath=s;
   271 }
   272 
   273 void ExportHTMLDialog::setMapName(const QString &s)
   274 {
   275 	mapname=s;
   276 }
   277 
   278 QString ExportHTMLDialog::getDir()
   279 {
   280 	return dir;
   281 }
   282 
   283 bool ExportHTMLDialog::warnings()
   284 {
   285 	return showWarnings;
   286 }
   287 
   288 bool ExportHTMLDialog::hasChanged()
   289 {
   290 	return settingsChanged;
   291 }
   292 
   293