27 #include "../../common/PlatformUtils.h" 
   28 #include "../../common/SystemApplicationSettings.h" 
   29 #include "../../common/UserApplicationSettings.h" 
   30 #include "../../dataaccess/serialization/xml/Serializer.h" 
   31 #include "../../maptools/AbstractLayer.h" 
   32 #include "../../plugin/PluginManager.h" 
   33 #include "../../plugin/PluginInfo.h" 
   34 #include "../../maptools/serialization/xml/Layer.h" 
   35 #include "../../xml/Reader.h" 
   36 #include "../../xml/ReaderFactory.h" 
   37 #include "../../xml/Writer.h" 
   38 #include "../../Version.h" 
   51 #include <boost/filesystem.hpp> 
   52 #include <boost/format.hpp> 
   53 #include <boost/property_tree/ptree.hpp> 
   54 #include <boost/algorithm/string/replace.hpp> 
   61 #include <QTextStream> 
   62 #include <QApplication> 
   64 #include <QMainWindow> 
   65 #include <QMessageBox> 
   70   boost::filesystem::path furi(uri);
 
   72   if (!boost::filesystem::exists(furi) || !boost::filesystem::is_regular_file(furi))   
 
   73     throw Exception((boost::format(
TE_TR(
"Could not read project file: %1%.")) % uri).str());
 
   76   xmlReader->setValidationScheme(
false);
 
   80   if(!xmlReader->next())
 
   81     throw Exception((boost::format(
TE_TR(
"Could not read project information in the file: %1%.")) % uri).str());
 
   84     throw Exception((boost::format(
TE_TR(
"Error reading the document %1%, the start element wasn't found.")) % uri).str());
 
   86   if(xmlReader->getElementLocalName() != 
"Project")
 
   87     throw Exception((boost::format(
TE_TR(
"The first tag in the document %1% is not 'Project'.")) % uri).str());
 
   93   XMLFormatter::format(proj, 
false);
 
  103   std::auto_ptr<Project> project(
new Project);
 
  157   project->setProjectAsChanged(
false);
 
  159   return project.release();
 
  164   std::ofstream fout(uri.c_str(), std::ios_base::trunc);
 
  170   XMLFormatter::format(&p, 
true);
 
  174   XMLFormatter::format(&p, 
false);
 
  187   boost::replace_all(schema_loc, 
" ", 
"%20");
 
  189   writer.
writeAttribute(
"xmlns:xsd", 
"http://www.w3.org/2001/XMLSchema-instance");
 
  190   writer.
writeAttribute(
"xmlns:te_da", 
"http://www.terralib.org/schemas/dataaccess");
 
  191   writer.
writeAttribute(
"xmlns:te_map", 
"http://www.terralib.org/schemas/maptools");
 
  192   writer.
writeAttribute(
"xmlns:te_qt_af", 
"http://www.terralib.org/schemas/common/af");
 
  196   writer.
writeAttribute(
"xmlns:xlink", 
"http://www.w3.org/1999/xlink");
 
  198   writer.
writeAttribute(
"xmlns", 
"http://www.terralib.org/schemas/qt/af");
 
  199   writer.
writeAttribute(
"xsd:schemaLocation", 
"http://www.terralib.org/schemas/qt/af " + schema_loc);
 
  212   for(std::list<te::map::AbstractLayerPtr>::const_iterator it = project.
getTopLayers().begin();
 
  215     lserial.
write(it->get(), writer);
 
  224   QSettings user_settings(QSettings::IniFormat,
 
  225                           QSettings::UserScope,
 
  226                           QApplication::instance()->organizationName(),
 
  227                           QApplication::instance()->applicationName());
 
  230   if(!prjFiles.empty() && !prjTitles.empty() && (prjFiles.size() == prjTitles.size()))
 
  232     user_settings.setValue(
"projects/most_recent/path", prjFiles.at(0));
 
  233     user_settings.setValue(
"projects/most_recent/title", prjTitles.at(0));
 
  235     if(prjFiles.size() > 1)
 
  237       user_settings.beginGroup(
"projects");
 
  239       user_settings.beginWriteArray(
"recents");
 
  241       for(
int i = 1; i != prjFiles.size(); ++i)
 
  243         user_settings.setArrayIndex(i - 1);
 
  244         user_settings.setValue(
"projects/path", prjFiles.at(i));
 
  245         user_settings.setValue(
"projects/title", prjTitles.at(i));
 
  248       user_settings.endArray();
 
  250       user_settings.endGroup();
 
  255   user_settings.remove(
"plugins/enabled");
 
  257   user_settings.beginGroup(
"plugins");
 
  259   user_settings.beginWriteArray(
"enabled");
 
  265   for(std::size_t i = 0; i != plugins.size(); ++i)
 
  270     user_settings.setArrayIndex(aidx++);
 
  272     user_settings.setValue(
"name", plugins[i].c_str());
 
  275   user_settings.endArray();
 
  277   user_settings.endGroup();
 
  282   QSettings usettings(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  284   QVariant fileName = usettings.value(
"data_sources/data_file");
 
  286   if(fileName.isNull())
 
  288     const QString& udir = ApplicationController::getInstance().getUserDataDir();
 
  292     usettings.setValue(
"data_sources/data_file", fileName);
 
  301   sett.beginGroup(bar->objectName());
 
  303   sett.setValue(
"name", bar->objectName());
 
  305   sett.beginWriteArray(
"Actions");
 
  307   QList<QAction*> acts = bar->actions();
 
  309   for(
int i=0; i<acts.size(); i++)
 
  311     sett.setArrayIndex(i);
 
  312     sett.setValue(
"action", acts.at(i)->objectName());
 
  323   std::vector<QToolBar*>::const_iterator it;
 
  324   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  326   sett.beginGroup(
"toolbars");
 
  328   for (it = bars.begin(); it != bars.end(); ++it)
 
  332     sett.remove(bar->objectName());
 
  342   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  344   sett.beginGroup(
"toolbars");
 
  353   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  355   sett.beginGroup(
"toolbars");
 
  356   sett.remove(bar->objectName());
 
  362   std::vector<QToolBar*> bars;
 
  364   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  366   sett.beginGroup(
"toolbars");
 
  367   QStringList lst = sett.childGroups();
 
  369   QStringList::iterator it;
 
  371   for(it=lst.begin(); it != lst.end(); ++it)
 
  377     QString grName = sett.value(
"name").toString();
 
  379     int size = sett.beginReadArray(
"Actions");
 
  381     QToolBar* toolbar = 
new QToolBar(barsParent);
 
  382     toolbar->setObjectName(grName);
 
  383     toolbar->setWindowTitle(grName);
 
  385     for(
int i=0; i<size; i++)
 
  387       sett.setArrayIndex(i);
 
  388       QString act = sett.value(
"action").toString();
 
  392         toolbar->addSeparator();
 
  396         QAction* a = ApplicationController::getInstance().findAction(act);
 
  399           toolbar->addAction(a);
 
  406     bars.push_back(toolbar);
 
  416   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  418   sett.beginGroup(
"mainWindow");
 
  419   sett.setValue(
"geometry", mainWindow->saveGeometry());
 
  420   sett.setValue(
"windowState", mainWindow->saveState());
 
  426   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  428   sett.beginGroup(
"mainWindow");
 
  429   mainWindow->restoreGeometry(sett.value(
"geometry").toByteArray());
 
  430   mainWindow->restoreState(sett.value(
"windowState").toByteArray());
 
  436   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  438   sett.beginGroup(
"projects");
 
  439   defaultAuthor = sett.value(
"author_name").toString();
 
  440   maxSaved = sett.value(
"recents_history_size").toInt();
 
  446   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  448   sett.beginGroup(
"projects");
 
  449   sett.setValue(
"author_name", defaultAuthor);
 
  450   sett.setValue(
"recents_history_size", maxSaved);
 
  456   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  458   sett.setValue(
"projects/last datasource used", dsType);
 
  463   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  465   sett.setValue(
"projects/openLastDataSource", openLast);
 
  470   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  472   return sett.value(
"projects/last datasource used").toString();
 
  477   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  479   QVariant variant = sett.value(
"projects/openLastDataSource");
 
  482   if(variant.isNull() || !variant.isValid())
 
  485   return variant.toBool();
 
  490   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  492   sett.beginGroup(
"toolbars");
 
  494   sett.beginGroup(
"File Tool Bar");
 
  495   sett.setValue(
"name", 
"File Tool Bar");
 
  496   sett.beginWriteArray(
"Actions");
 
  497   sett.setArrayIndex(0);
 
  498   sett.setValue(
"action", 
"File.New Project");
 
  499   sett.setArrayIndex(1);
 
  500   sett.setValue(
"action", 
"File.Open Project");
 
  501   sett.setArrayIndex(2);
 
  502   sett.setValue(
"action", 
"File.Save Project");
 
  503   sett.setArrayIndex(3);
 
  504   sett.setValue(
"action", 
"");
 
  505   sett.setArrayIndex(4);
 
  506   sett.setValue(
"action", 
"Project.New Folder");
 
  507   sett.setArrayIndex(5);
 
  508   sett.setValue(
"action", 
"Project.Add Layer.All Sources");
 
  512   sett.beginGroup(
"View Tool Bar");
 
  513   sett.setValue(
"name", 
"View Tool Bar");
 
  514   sett.beginWriteArray(
"Actions");
 
  515   sett.setArrayIndex(0);
 
  516   sett.setValue(
"action", 
"View.Layer Explorer");
 
  517   sett.setArrayIndex(1);
 
  518   sett.setValue(
"action", 
"View.Map Display");
 
  519   sett.setArrayIndex(2);
 
  520   sett.setValue(
"action", 
"View.Data Table");
 
  521   sett.setArrayIndex(3);
 
  522   sett.setValue(
"action", 
"View.Style Explorer");
 
  526   sett.beginGroup(
"Map Tool Bar");
 
  527   sett.setValue(
"name", 
"Map Tool Bar");
 
  528   sett.beginWriteArray(
"Actions");  
 
  529   sett.setArrayIndex(0);
 
  530   sett.setValue(
"action", 
"Map.Draw");
 
  531   sett.setArrayIndex(1);
 
  532   sett.setValue(
"action", 
"Map.Previous Extent");
 
  533   sett.setArrayIndex(2);
 
  534   sett.setValue(
"action", 
"Map.Next Extent");
 
  535   sett.setArrayIndex(3);
 
  536   sett.setValue(
"action", 
"Map.Zoom Extent");
 
  537   sett.setArrayIndex(4);
 
  538   sett.setValue(
"action", 
"");
 
  539   sett.setArrayIndex(5);
 
  540   sett.setValue(
"action", 
"Map.Zoom In");
 
  541   sett.setArrayIndex(6);
 
  542   sett.setValue(
"action", 
"Map.Zoom Out");
 
  543   sett.setArrayIndex(7);
 
  544   sett.setValue(
"action", 
"Map.Pan");
 
  545   sett.setArrayIndex(8);
 
  546   sett.setValue(
"action", 
"");
 
  547   sett.setArrayIndex(9);
 
  548   sett.setValue(
"action", 
"Map.Info");
 
  549   sett.setArrayIndex(10);
 
  550   sett.setValue(
"action", 
"Map.Selection");
 
  556   sett.beginGroup(
"projects");
 
  558   sett.setValue(
"author_name", 
"");
 
  559   sett.setValue(
"recents_history_size", 
"8");
 
  566   QString result(windowTitle);
 
  570     if(result.at(result.count()-1) != 
'*')
 
  575     if(result.at(result.count()-1) == 
'*')
 
  576       result.remove((result.count()-1), 1);
 
  584   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  585   QString hexColor = sett.value(
"display/defaultDisplayColor").toString();  
 
  587   defaultColor.setNamedColor(hexColor);
 
  588   if(!defaultColor.isValid())
 
  596   QString sty(
"alternate-background-color: ");
 
  597   sty += 
"rgb(" + QString::number(secondaryColor.red()) + 
", " + QString::number(secondaryColor.green());
 
  598   sty += 
", " + QString::number(secondaryColor.blue()) + 
")";
 
  599   sty += 
";background-color: rgb(" + QString::number(primaryColor.red()) + 
", " + QString::number(primaryColor.green());
 
  600   sty += 
", " + QString::number(primaryColor.blue()) + 
");";
 
  607   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  610   pColor.setNamedColor(sett.value(
"table/primaryColor").toString());
 
  612   sColor.setNamedColor(sett.value(
"table/secondaryColor").toString());
 
  614   if(!pColor.isValid())
 
  616   if(!sColor.isValid())
 
  624   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  625   bool isChecked = sett.value(
"table/tableAlternateColors").toBool();
 
  632   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  634   sett.beginGroup(
"toolbars");
 
  635   QStringList lst = sett.childGroups();
 
  636   QStringList::iterator it;
 
  638   for(it=lst.begin(); it!=lst.end(); ++it)
 
  640     int size = sett.beginReadArray(*it+
"/Actions");
 
  642     for(
int i=0; i<size; i++)
 
  644       sett.setArrayIndex(i);
 
  646       QString v = sett.value(
"action").toString(); 
 
  648       if (v == act->objectName())
 
  650         ApplicationController::getInstance().getToolBar(*it)->addAction(act);
 
  663   std::vector<std::string> res;
 
  667   filters << 
"*.teplg";
 
  671   QFileInfoList files = d.entryInfoList(filters, QDir::Files);
 
  673   foreach(QFileInfo file, files)
 
  675     res.push_back(file.absoluteFilePath().toStdString());
 
  683   std::vector<std::string> res;
 
  684   std::vector<std::string>::const_iterator it;
 
  686   for(it=plgFiles.begin(); it!=plgFiles.end(); ++it)
 
  688     boost::property_tree::ptree p;
 
  689     boost::property_tree::read_xml(*it, p, boost::property_tree::xml_parser::trim_whitespace);
 
  691     res.push_back(p.get<std::string>(
"PluginInfo.Name"));
 
  699   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  701   return sett.value(
"configuration/generation").toString();
 
  706   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  708   sett.setValue(
"configuration/generation", dateTime);
 
  713   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  715   QFileInfo info(sett.fileName());
 
  717   return info.absolutePath();
 
  722   QFileInfo info(fileName);
 
  727     info.dir().remove(info.fileName());
 
  729   std::string olderFile = appSett.
getValue(
"Application.UserSettingsFile.<xmlattr>.xlink:href");
 
  731   appSett.
setValue(
"Application.UserSettingsFile.<xmlattr>.xlink:href", fileName.toStdString());
 
  735     info.setFile(olderFile.c_str());
 
  736     info.dir().remove(info.fileName());
 
  739   info.setFile(fileName);
 
  743     boost::property_tree::xml_writer_settings<char> settings(
'\t', 1);
 
  744     boost::property_tree::write_xml(fileName.toStdString(), usrSett.
getAllSettings(), std::locale(), settings);
 
  747   usrSett.
load(fileName.toStdString());
 
  752   boost::property_tree::ptree p;
 
  757   p.add(
"Project.<xmlattr>.xmlns:xsd", 
"http://www.w3.org/2001/XMLSchema-instance");
 
  758   p.add(
"Project.<xmlattr>.xmlns:te_map", 
"http://www.terralib.org/schemas/maptools");
 
  759   p.add(
"Project.<xmlattr>.xmlns:te_qt_af", 
"http://www.terralib.org/schemas/qt/af");
 
  760   p.add(
"Project.<xmlattr>.xmlns", 
"http://www.terralib.org/schemas/qt/af");
 
  761   p.add(
"Project.<xmlattr>.xsd:schemaLocation", 
"http://www.terralib.org/schemas/qt/af " + schema_location);
 
  762   p.add(
"Project.<xmlattr>.version", TERRALIB_VERSION_STRING);
 
  765   p.add(
"Project.Title", 
"Default project");
 
  766   p.add(
"Project.Author", 
"");
 
  767   p.add(
"Project.ComponentList", 
"");
 
  768   p.add(
"Project.te_map:LayerList", 
"");
 
  771   boost::property_tree::xml_writer_settings<char> settings(
'\t', 1);
 
  772   boost::property_tree::write_xml(fileName.toStdString(), p, std::locale(), settings);
 
  777   QString fileName = qApp->applicationDirPath() + 
"/../.generated";
 
  780   if (!f.open(QFile::ReadOnly | QFile::Text))
 
  784   QString s = in.readAll();
 
TEQTAFEXPORT void RemoveToolBarFromSettings(QToolBar *bar)
Removes a tool bar from the settings. 
 
TEQTAFEXPORT void UpdateToolBarsInTheSettings()
Update plugins file. 
 
TEQTAFEXPORT QColor GetDefaultDisplayColorFromSettings()
 
TEQTAFEXPORT std::vector< std::string > GetPluginsFiles()
 
const std::string & getTitle() const 
It gets the title of the project. 
 
virtual void writeStartElement(const std::string &qName)
 
void write(const te::map::AbstractLayer *alayer, te::xml::Writer &writer) const 
 
This class models a XML reader object. 
 
virtual void writeStartDocument(const std::string &encoding, const std::string &standalone)
 
TEQTAFEXPORT void CreateDefaultSettings()
Creates a default QSettings. 
 
TECOMMONEXPORT std::string FindInTerraLibPath(const std::string &p)
Returns the path relative to a directory or file in the context of TerraLib. 
 
TEQTAFEXPORT void SaveOpenLastProjectOnSettings(bool openLast)
 
This class models a XML writer object. 
 
A singleton for managing application settings applied to a single user. 
 
TEQTAFEXPORT void SetDateTime(const QString &dateTime)
 
TEQTAFEXPORT std::vector< QToolBar * > ReadToolBarsFromSettings(QWidget *barsParent=0)
Returns a vector of tool bars registered in the QSettings. 
 
This class models the concept of a project for the TerraLib Application Framework. 
 
virtual void writeAttribute(const std::string &attName, const std::string &value)
 
TEQTAFEXPORT QString UnsavedStar(const QString windowTitle, bool isUnsaved)
Unsaved star. 
 
void setValue(const std::string &key, const std::string &value)
It stores the value according to the key. 
 
static te::xml::Reader * make()
It creates a new XML reader using the dafault implementation. 
 
TEQTAFEXPORT void SaveLastDatasourceOnSettings(const QString &dsType)
 
#define TE_TR(message)
It marks a string in order to get translated. 
 
TEQTAFEXPORT void SaveState(QMainWindow *mainWindow)
 
TEQTAFEXPORT void UpdateUserSettings(const QStringList &prjFiles, const QStringList &prjTitles, const std::string &userConfigFile)
Updates user settings file section about information of the projects. 
 
TEQTAFEXPORT bool GetAlternateRowColorsFromSettings()
 
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node. 
 
TEQTAFEXPORT void SaveDataSourcesFile()
Saves data sources file. 
 
TEQTAFEXPORT void AddToolBarToSettings(QToolBar *bar)
Update settings with a new tool bar. 
 
const std::list< te::map::AbstractLayerPtr > & getTopLayers() const 
It gets all the top layers of the project (folder and single layers). 
 
te::map::AbstractLayer * read(te::xml::Reader &reader) const 
 
TEQTAFEXPORT void UpdateUserSettingsFile(const QString &fileName, const bool &removeOlder=true)
Changes the user settings file location. 
 
TEQTAFEXPORT void AddActionToCustomToolbars(QAction *act)
Check QSettings for existance of act and adds it if necessary. 
 
TEQTAFEXPORT void SaveProjectInformationsOnSettings(const QString &defaultAuthor, const int &maxSaved)
 
static Layer & getInstance()
It returns a reference to the singleton instance. 
 
virtual void writeElement(const std::string &qName, const std::string &value)
 
TEQTAFEXPORT QString GetDefaultConfigFileOutputDir()
Returns the default path for output of configuration file. 
 
TEQTAFEXPORT QString GetStyleSheetFromColors(QColor primaryColor, QColor secondaryColor)
 
void setProjectAsChanged(const bool &changed)
It sets the project status as changed or not. 
 
A singleton for managing application settings applied to the whole system (all users). 
 
TEDATAACCESSEXPORT void Save(const std::string &fileName)
 
TEQTAFEXPORT void GetProjectInformationsFromSettings(QString &defaultAuthor, int &maxSaved)
 
An exception class for the TerraLib Application Framework. 
 
TEQTAFEXPORT void RestoreState(QMainWindow *mainWindow)
 
TEQTAFEXPORT QString GetGenerationDate()
Returns the date and time of generated binary. 
 
virtual void writeEndElement(const std::string &qName)
 
TEQTAFEXPORT QString GetDateTime()
 
TEQTAFEXPORT void WriteDefaultProjectFile(const QString &fileName)
Writes the configuration file. It updates the application settings. 
 
void setFileName(const std::string &fName)
It sets the filename where the project will be saved. 
 
TEQTAFEXPORT QString GetStyleSheetFromSettings()
 
const std::string & getAuthor() const 
It gets the author of the project. 
 
TEQTAFEXPORT Project * ReadProject(const std::string &uri)
Reads and return a te::qt::af::Project from the file. 
 
This class models the concept of a project for the TerraLib Application Framework. 
 
virtual NodeType getNodeType() const =0
It return the type of node read. 
 
void load(const std::string &fileName)
It tries to find a default config file based on system macros and default condigurations. 
 
void AddToolbarAndActions(QToolBar *bar, QSettings &sett)
 
virtual std::string getElementValue() const =0
It returns the element data value in the case of VALUE node. 
 
Utility routines for the TerraLib Application Framework module. 
 
TEQTAFEXPORT bool GetOpenLastProjectFromSettings()
 
const boost::property_tree::ptree & getAllSettings() const 
It return a reading reference to the internal settings. 
 
std::string getValue(const std::string &key)
It returns the value for a given key or empty. 
 
#define TERRALIB_APPLICATION_DATASOURCE_FILE_NAME
The default name for the application file containing the list of data sources. 
 
TEQTAFEXPORT void Save(const Project &project, const std::string &uri)
Saves the informations of the project in the uri file. 
 
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
 
virtual bool next()=0
It gets the next event to be read. 
 
TEQTAFEXPORT std::vector< std::string > GetPluginsNames(const std::vector< std::string > &plgFiles)
 
The base API for controllers of TerraLib applications. 
 
TEQTAFEXPORT QString GetLastDatasourceFromSettings()