Subversion Repositories public

Rev

Rev 276 | 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 <KMessageBox>
#include <QDir>

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

        __maptype = MAP_SHAPE;          // default map type
        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"));
        bool geo = sh.readEntry("Geographic", false);
        rbForward->setChecked(geo);
        rbInverse->setChecked(!geo);
}

shapeWidget::~shapeWidget()
{
}

/*$SPECIALIZATION$*/
void shapeWidget::setMapType(maptype mt)
{
        switch (mt)
        {
           case MAP_SHAPE:
              label->setText(i18n("Path to shape file set"));
           break;

           case MAP_GIS:
              label->setText(i18n("Domain of machine with database"));
           break;

           case MAP_OSM:
              label->setText(i18n("Path and name of OSM file"));
           break;

           default:
              KMessageBox::error(this, i18n("Internal error: Unknown map type was set!"));
        }
}

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());
        sh.writeEntry("Geographic", rbForward->isChecked());
        cfg.sync();
        done(QDialog::Accepted);
}

void shapeWidget::slotForwarded(bool stat)
{
        if (!stat)
        {
           rbForward->setChecked(true);
           rbInverse->setChecked(false);
        }
}

void shapeWidget::slotInversed(bool stat)
{
        if (!stat)
        {
           rbForward->setChecked(false);
           rbInverse->setChecked(true);
        }
}

#include "shapewidget.moc"