Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

omgoptions.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Tim Sutton   *
00003  *   tim@linfiniti.com   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <omgoptions.h>
00022 #include <omgmodellerplugininterface.h>
00023 #include <omgui.h> //provides helper functions for getting app paths etc
00024 #include <omgmodellerpluginregistry.h>
00025 //qt includes
00026 #include <QDir>
00027 #include <QColorDialog>
00028 #include <QFileInfo>
00029 #include <QFileDialog>
00030 #include <QRegExp>
00031 #include <QSettings>
00032 #include <QString>
00033 #include <QTabWidget>
00034 #include <QTextCodec>
00035 #include <QCheckBox>
00036 #include <QHash>
00037 
00038 #define DEFAULT_WS_URL "http://modeller.cria.org.br/cgi-bin/om_soap_server.cgi"
00039 
00040 OmgOptions::OmgOptions(QWidget* parent, Qt::WFlags fl)
00041     : QDialog(parent,fl)
00042 {
00043   //required by Qt4 to initialise the ui
00044   setupUi(this);
00045   QSettings mySettings;
00046 
00047   // User data path
00048   leDataDirectory->setText(mySettings.value("dataDirs/dataDir",QDir::homePath() + QString("/.omgui/")).toString());
00049 
00050   //populate teh output image formats combo
00051   QHash<QString,QString> myHash = Omgui::getOutputFormats();
00052   QHashIterator<QString, QString> myIterator(myHash);
00053   QString myFormat = mySettings.value("outputFormat","GreyTiff100").toString();
00054   int myDefaultIndex=0;
00055   int myCurrentIndex=0;
00056   while (myIterator.hasNext()) 
00057   {
00058     myIterator.next();
00059     //We will add the hash item key to the Qt::UserRole 
00060     //for the combo list entry
00061     cboOutputFormat->addItem(myIterator.value(), myIterator.key());
00062     if (myIterator.key()==myFormat)
00063     {
00064       myDefaultIndex=myCurrentIndex;
00065     }
00066     ++myCurrentIndex;
00067   }
00068   cboOutputFormat->setCurrentIndex(myDefaultIndex);
00069 
00070 
00071   //Web proxy settings
00072   grpProxy->setChecked(mySettings.value("proxy/proxyEnabled", "0").toBool());
00073   leProxyHost->setText(mySettings.value("proxy/proxyHost", "").toString());
00074   leProxyPort->setText(mySettings.value("proxy/proxyPort", "").toString());
00075   leProxyUser->setText(mySettings.value("proxy/proxyUser", "").toString());
00076   leProxyPassword->setText(mySettings.value("proxy/proxyPassword", "").toString());
00077 
00078   //gbif url settings
00079   leGbifUrl->setText(mySettings.value("openModeller/gbifPlugin/url", "data.gbif.org").toString());
00080   //Plugin Type 
00081   lblPluginSearchPath->setText(Omgui::pluginDirPath());
00082   QString myWebServiceUrl = mySettings.value("openModeller/webServicesPlugin/url", DEFAULT_WS_URL).toString();
00083   //url could still be blank if key exists but user has blanked it, in this case provide a default url again
00084   if (myWebServiceUrl.isEmpty())
00085   {
00086     myWebServiceUrl = DEFAULT_WS_URL;
00087   }
00088   leWebServiceAddress->setText(myWebServiceUrl);
00089   leWebServiceAddress->setEnabled(true);
00090   QString myPluginName = mySettings.value("openModeller/modellerPluginType", "").toString();
00091   QStringList myList = OmgModellerPluginRegistry::instance()->names();
00092   cboModellerPluginName->addItems(myList);
00093   if (myList.contains(myPluginName))
00094   {
00095     cboModellerPluginName->setCurrentIndex(myList.indexOf(QRegExp(myPluginName)));
00096   }
00097   bool myWSLoggingFlag=mySettings.value("openModeller/webServicesPlugin/doLoggingFlag", false).toBool();
00098   cbxModellerLoggingFlag->setChecked(myWSLoggingFlag);
00099   bool myModellerVerboseFlag=mySettings.value("openModeller/modellerVerboseLogFlag", false).toBool();
00100   cbxModellerVerboseFlag->setChecked(myModellerVerboseFlag);
00101 
00102   //Database settings
00103   grpDatabase->setChecked(mySettings.value("database/databaseEnabled", "0").toBool());
00104   leDbHost->setText(mySettings.value("database/databaseHost", "").toString());
00105   leDbUser->setText(mySettings.value("database/databaseUser", "").toString());
00106   leDbPassword->setText(mySettings.value("database/databasePassword", "").toString());
00107   leDbName->setText(mySettings.value("database/databaseName", "").toString());
00108   leDbTable->setText(mySettings.value("database/databaseTable", "").toString());
00109   leDbTaxonField->setText(mySettings.value("database/taxonField", "").toString());
00110   leDbLatitudeField->setText(mySettings.value("database/latitudeField", "").toString());
00111   leDbLongitudeField->setText(mySettings.value("database/longitudeField", "").toString());
00112 
00113   // Tooltips and gui options
00114   bool myTipsFlag = mySettings.value("tipOfTheDay/tipOfTheDay", true).toBool();
00115   cbxShowTooltips->setChecked(myTipsFlag);
00116   bool myThreadingFlag = mySettings.value("openModeller/runExperimentInThread", true).toBool();
00117   cbxExperimentInThread->setChecked(myThreadingFlag);
00118 
00119   // Systray options
00120   bool myUseSystemTrayFlag = mySettings.value("openModeller/useSystemTray", false).toBool();
00121   grpSystrayIcon->setChecked(myUseSystemTrayFlag);
00122   bool myMinimiseToSystemTrayFlag = mySettings.value("openModeller/closeToSystemTray", false).toBool();
00123   cbxMinimizeToSystray->setChecked(myMinimiseToSystemTrayFlag);
00124   bool myShowSystemTrayMessagesFlag = mySettings.value("openModeller/showSystemTrayMessages", false).toBool();
00125   cbxShowSystrayMessages->setChecked(myShowSystemTrayMessagesFlag);
00126   
00127   
00128   bool myResetExtentsFlag= mySettings.value("openModeller/resetExtents", false).toBool();
00129   cbxResetExtents->setChecked(myResetExtentsFlag);
00130 #ifdef OMG_NO_EXPERIMENTAL
00131   //hide the database tab if we are prepareing a release
00132   //as it doesnt do anything yet
00133   tabWidget->removeTab(5);
00134 #endif
00135 
00136   //
00137   // Locale settings 
00138   //
00139   QString mySystemLocale = QTextCodec::locale();
00140   lblSystemLocale->setText(tr("Detected active locale on your system: ") + mySystemLocale);
00141   QString myUserLocale = mySettings.value("locale/userLocale", "").toString();
00142   QStringList myI18nList = Omgui::i18nList();
00143   cboLocale->addItems(myI18nList);
00144   if (myI18nList.contains(myUserLocale))
00145   {
00146     cboLocale->setCurrentText(myUserLocale);
00147   }
00148   bool myLocaleOverrideFlag = mySettings.value("locale/overrideFlag",false).toBool();
00149   grpLocale->setChecked(myLocaleOverrideFlag);
00150 
00151 
00152   //
00153   // Logging options
00154   //
00155   bool myLogToFileFlag = mySettings.value("openModeller/logToFile", false).toBool();
00156   QString myLogFileName = mySettings.value("openModeller/logFile","/tmp/omglog.txt").toString();
00157   grpLogToFile->setChecked(myLogToFileFlag);
00158   leLogFile->setText(myLogFileName);
00159 
00160   //
00161   // Map symbol options
00162   //
00163   spinLocalitySymbolSize->setValue(mySettings.value("mapping/localitySymbolSize",5).toInt());
00164   QColor myPresenceColor(mySettings.value("mapping/presenceColour",QColor(Qt::green).name()).toString());
00165   QColor myAbsenceColor(mySettings.value("mapping/absenceColour",QColor(Qt::red).name()).toString());
00166   lblPresenceColourPreview->setStyleSheet("background-color: " + myPresenceColor.name());
00167   lblAbsenceColourPreview->setStyleSheet("background-color: " + myAbsenceColor.name());
00168   lblPresenceColourPreview->setText( myPresenceColor.name());
00169   lblAbsenceColourPreview->setText(myAbsenceColor.name());
00170 
00171   spinContextLineWidth->setValue(mySettings.value("mapping/contextLineWidth",1).toInt());
00172   QColor myContextColor(mySettings.value("mapping/contextLineColour",QColor(Qt::gray).name()).toString());
00173   lblContextColourPreview->setStyleSheet("background-color: " + myContextColor.name());
00174   lblContextColourPreview->setText(myContextColor.name());
00175   leContextLayer->setText(mySettings.value("mapping/contextLayer").toString());
00176   cbxResetExtents->setChecked(mySettings.value("mapping/resetExtents",false).toBool());
00177 }
00178 
00179 OmgOptions::~OmgOptions()
00180 {
00181 }
00182 
00183 void OmgOptions::on_cboModellerPluginName_currentIndexChanged()
00184 {
00185   QString myKey = cboModellerPluginName->currentText();
00186   qDebug("Plugin changed to: " + myKey.toLocal8Bit());
00187   if (myKey=="Local Modeller Plugin")
00188   {
00189     //disable the url box because none is needed for this plugin
00190     leWebServiceAddress->setEnabled(false);
00191   }
00192   else
00193   {
00194     leWebServiceAddress->setEnabled(true);
00195   }
00196 }
00197 
00198 void OmgOptions::on_cboOutputFormat_currentIndexChanged()
00199 {
00200   QHash<QString,QString> myHash = Omgui::getOutputFormatNotes();
00201   QString myKey = cboOutputFormat->itemData(cboOutputFormat->currentIndex()).toString();
00202   QString myNotes = myHash[myKey];
00203   lblFormatNotes->setText(myNotes);
00204 }
00205 void OmgOptions::accept()
00206 {
00207   QSettings mySettings;
00208   //qDebug("Saving options");
00209 
00210   //User data dir settings
00211   mySettings.setValue("dataDirs/dataDir", leDataDirectory->text());
00212   //output format
00213   mySettings.setValue("outputFormat",cboOutputFormat->itemData(cboOutputFormat->currentIndex()).toString());
00214   //Web proxy settings
00215   mySettings.setValue("proxy/proxyEnabled", grpProxy->isChecked());
00216   mySettings.setValue("proxy/proxyHost", leProxyHost->text());
00217   mySettings.setValue("proxy/proxyPort", leProxyPort->text());
00218   mySettings.setValue("proxy/proxyUser", leProxyUser->text());
00219   mySettings.setValue("proxy/proxyPassword", leProxyPassword->text());
00220 
00221   //Gbif settings
00222   mySettings.setValue("openModeller/gbifPlugin/url",leGbifUrl->text());
00223   //Plugin url (only releveant for e.g. web services plugin)
00224   mySettings.setValue("openModeller/webServicesPlugin/url", leWebServiceAddress->text());
00225   //Plugin type
00226   mySettings.setValue("openModeller/modellerPluginType", cboModellerPluginName->currentText());
00227   mySettings.setValue("openModeller/webServicesPlugin/doLoggingFlag",  cbxModellerLoggingFlag->isChecked());
00228   mySettings.setValue("openModeller/modellerVerboseLogFlag",  cbxModellerVerboseFlag->isChecked());
00229 
00230   //Database settings
00231   mySettings.setValue("database/databaseEnabled", grpDatabase->isChecked());
00232   mySettings.setValue("database/databaseHost", leDbHost->text());
00233   mySettings.setValue("database/databaseUser", leDbUser->text());
00234   mySettings.setValue("database/databasePassword", leDbPassword->text());
00235   mySettings.setValue("database/databaseName", leDbName->text());
00236   mySettings.setValue("database/databaseTable", leDbTable->text());
00237   mySettings.setValue("database/taxonField", leDbTaxonField->text());
00238   mySettings.setValue("database/latitudeField", leDbLatitudeField->text());
00239   mySettings.setValue("database/longitudeField", leDbLongitudeField->text());
00240   //
00241   // Locale settings 
00242   //
00243   mySettings.setValue("locale/userLocale", cboLocale->currentText());
00244   mySettings.setValue("locale/overrideFlag", grpLocale->isChecked());
00245   // Tip of the day and gui settings
00246   mySettings.setValue("tipOfTheDay/tipOfTheDay", cbxShowTooltips->isChecked());
00247   mySettings.setValue("openModeller/runExperimentInThread", cbxExperimentInThread->isChecked());
00248   // System tray options
00249   mySettings.setValue("openModeller/useSystemTray", grpSystrayIcon->isChecked());
00250   mySettings.setValue("openModeller/closeToSystemTray", cbxMinimizeToSystray->isChecked());
00251   mySettings.setValue("openModeller/showSystemTrayMessages",cbxShowSystrayMessages->isChecked());
00252 
00253   //
00254   // Logging options
00255   //
00256   mySettings.setValue("openModeller/logToFile", grpLogToFile->isChecked());
00257   mySettings.value("openModeller/logFile",leLogFile->text());
00258 
00259   //
00260   // Map symbol colours
00261   //
00262   mySettings.setValue("mapping/localitySymbolSize",spinLocalitySymbolSize->value());
00263   mySettings.setValue("mapping/presenceColour",lblPresenceColourPreview->text());
00264   mySettings.setValue("mapping/absenceColour",lblAbsenceColourPreview->text());
00265   mySettings.setValue("mapping/contextLineWidth",spinContextLineWidth->value());
00266   mySettings.setValue("mapping/contextLineColour",lblContextColourPreview->text());
00267   mySettings.setValue("mapping/contextLayer",leContextLayer->text());
00268   mySettings.setValue("mapping/resetExtents",cbxResetExtents->isChecked());
00269   close(true);
00270 
00271 }
00272 
00273 void OmgOptions::on_toolSelectLogFile_clicked()
00274 {
00275   QString myFileName = QFileDialog::getOpenFileName(
00276       this,
00277       tr("Select a directory where your data will be saved") , //caption
00278       QFileInfo(leLogFile->text()).absolutePath() //initial dir
00279     );
00280         leDataDirectory->setText(myFileName);
00281 }
00282 
00283 void OmgOptions::on_toolSelectDataDirectory_clicked()
00284 {
00285   QString myFileName = QFileDialog::getExistingDirectory(
00286       this,
00287       tr("Select a directory where your data will be saved") , //caption
00288       leDataDirectory->text() //initial dir
00289     );
00290         leDataDirectory->setText(myFileName);
00291 }
00292 
00293 void OmgOptions::on_toolSelectContextLayer_clicked()
00294 {
00295   QString myFileName = QFileDialog::getOpenFileName(
00296       this,
00297       tr("Select a context layer to overlay on your models") , //caption
00298       leContextLayer->text() //initial dir
00299     );
00300         leContextLayer->setText(myFileName);
00301 }
00302 
00303 void OmgOptions::on_toolPresenceColour_clicked()
00304 {
00305   QColor myColour(lblPresenceColourPreview->text());
00306   myColour = QColorDialog::getColor( myColour, this );
00307   lblPresenceColourPreview->setStyleSheet("background-color: " + myColour.name());
00308   lblPresenceColourPreview->setText(myColour.name());
00309 }
00310 void OmgOptions::on_toolAbsenceColour_clicked()
00311 {
00312   QColor myColour(lblAbsenceColourPreview->text());
00313   myColour = QColorDialog::getColor( myColour, this );
00314   lblAbsenceColourPreview->setStyleSheet("background-color: " + myColour.name());
00315   lblAbsenceColourPreview->setText(myColour.name());
00316 }
00317 void OmgOptions::on_toolContextColour_clicked()
00318 {
00319   QColor myColour(lblContextColourPreview->text());
00320   myColour = QColorDialog::getColor( myColour, this );
00321   lblContextColourPreview->setStyleSheet("background-color: " + myColour.name());
00322   lblContextColourPreview->setText(myColour.name());
00323 }

Generated on Mon Apr 28 15:07:33 2008 for openModellerDesktop by  doxygen 1.4.1-20050210