Subversion Repositories public

Rev

Rev 276 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

//
// C++ Implementation:
//
// Description:
//
//
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include "config.h"
#include "shapewidget.h"
#include <KConfig>
#include <KUrlRequester>
#include <KLineEdit>
#include <QDir>

shapeWidget::shapeWidget (QWidget* parent, Qt::WFlags fl)
                : QDialog (parent, fl), Ui::shapeWidgetBase()
{
QString basePath;
QDir dir = QDir::home();
QString path = dir.absolutePath();

        setupUi (this);
        // Make sure we are useing only existing files on the local system.
        edShapeFileSet->setMode(KFile::ExistingOnly | KFile::LocalOnly);
        edPluginPath->setMode(KFile::ExistingOnly | KFile::LocalOnly);
        edFontPath->setMode(KFile::ExistingOnly | KFile::LocalOnly);
        edXmlFile->setMode(KFile::ExistingOnly | KFile::LocalOnly);

        // Get some already saved information from the config file
        KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
        KConfigGroup ic (&cfg, "SportWatcher");
        KConfigGroup sh (&cfg, "ShapeFile");
        basePath = ic.readEntry("Data", path + "/.sportwatcher");
        edShapeFileSet->setUrl(ic.readEntry("MAP", basePath + "/shapefiles"));
        // Read the shape specific informations
#ifdef MAPNIK_PLUGINS
        edPluginPath->setUrl(QString(MAPNIK_PLUGINS));
        edPluginPath->setEnabled(false);
#else
        // Test some default path
        if (dir.exists(QString("/usr/lib/mapnik/input")))
           edPluginPath->setUrl(sh.readEntry("PluginPath", QString("/usr/lib/mapnik/input")));
        else if (dir.exists(QString("/usr/local/lib/mapnik/input")))
           edPluginPath->setUrl(sh.readEntry("PluginPath", QString("/usr/local/lib/mapnik/input")));
        else if (dir.exists(QString("/usr/lib/mapnik/0.6/input")))
           edPluginPath->setUrl(sh.readEntry("PluginPath", QString("/usr/lib/mapnik/0.6/input")));
        else
           edPluginPath->setUrl(sh.readEntry("PluginPath", QString("")));
#endif
#ifdef MAPNIK_FONTS
        edFontPath->setUrl(QString(MAPNIK_FONTS));
        edFontPath->setEnabled(false);
#else
        // Test some default path
        if (dir.exists(QString("/usr/lib/mapnik/fonts")))
           edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/lib/mapnik/fonts")));
        else if (dir.exists(QString("/usr/local/lib/mapnik/fonts")))
           edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/local/lib/mapnik/fonts")));
        else if (dir.exists(QString("/usr/share/mapnik/fonts")))
           edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/share/mapnik/fonts")));
        else if (dir.exists(QString("/usr/share/fonts/truetype/ttf-dejavu")))
           edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/share/fonts/truetype/ttf-dejavu")));
        else
           edFontPath->setUrl(sh.readEntry("FontPath", QString("")));
#endif
        edXmlFile->setUrl(sh.readEntry("XmlFile", basePath + "/shapefiles/osm.xml"));
}

shapeWidget::~shapeWidget()
{
}

/*$SPECIALIZATION$*/
void shapeWidget::accept()
{
        KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
        KConfigGroup ic (&cfg, "SportWatcher");
        KConfigGroup sh (&cfg, "ShapeFile");
        ic.writeEntry("MAP", edShapeFileSet->lineEdit()->text());
        sh.writeEntry("PluginPath", edPluginPath->lineEdit()->text());
        sh.writeEntry("FontPath", edFontPath->lineEdit()->text());
        sh.writeEntry("XmlFile", edXmlFile->lineEdit()->text());
        cfg.sync();
        done(QDialog::Accepted);
}

#include "shapewidget.moc"