/*
* Copyright 2009-2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "mapcontrol.h"
#include "marker.h"
#include "point.h"
#include "projection.h"
#include "theme.h"
#include <QDebug>
#include <QDir>
#include <KConfigGroup>
#include <KStandardDirs>
Config::Config() : ConfigBase()
{
}
void Config::loadSettings()
{
Projection::setProjection(Config::projection());
if (!Theme::self()->loadTheme(Config::currentTheme())) {
Theme::self()->loadDefaultTheme();
}
//"biergarten.png" "coffeeshop.png" "fast_food.png" "pint.png";
//"pub.png" "restaurant.png" "supermarket.png" "post_box.png" "post_office.png";
//"library.png" "theatre.png" "courthouse.png" "townhall.png";
//"place_of_worship.png" "school.png" "university.png" "subway_entrance.png";
//"aerodrome.png" "power_wind.png";
KConfigGroup poiGroup(KGlobal::config(), "POI");
Theme::self()->loadIconTheme("default");
QList<IconThemeData *> l = Theme::self()->allIcons();
QString s;
foreach (IconThemeData *data, l) {
s = data->key;
bool b = poiGroup.readEntry(s, false);
Point::showIcon->insert(s, b);
b = poiGroup.readEntry(s+"_text", false);
Point::showText->insert(s, b);
}
Point::showText->insert("country", Config::showCountryName());
Point::showText->insert("state", Config::showStateName());
Point::showText->insert("region", Config::showCountyName());
Point::showText->insert("county", Config::showCountyName());
Point::showText->insert("city", Config::showCityName());
Point::showText->insert("town", Config::showTownName());
Point::showText->insert("village", Config::showVillageName());
Point::showText->insert("suburb", Config::showVillageName());
Point::showText->insert("motorway_junction", Config::showVillageName());
setIcons();
Theme::self()->setFont("country", Config::countryFont());
Theme::self()->setFont("state", Config::stateFont());
Theme::self()->setFont("county", Config::countyFont());
Theme::self()->setFont("city", Config::cityFont());
Theme::self()->setFont("town", Config::townFont());
Theme::self()->setFont("village", Config::villageFont());
Theme::self()->setFont("street", Config::streetFont());
Theme::self()->setFont("marker", Config::markerFont());
Theme::self()->setFont("poi", Config::poiFont());
}
void Config::saveSettings()
{
KConfigGroup general(KGlobal::config(), "general");
general.writeEntry("projection", projection());
general.config()->sync();
KConfigGroup theme(KGlobal::config(), "theme");
theme.writeEntry("currentTheme", currentTheme());
theme.config()->sync();
KConfigGroup gui(KGlobal::config(), "gui");
gui.writeEntry("navigatorControls", navigatorControls());
gui.config()->sync();
setIcons();
}
void Config::saveHome()
{
KConfigGroup cg(KGlobal::config(), "home");
cg.writeEntry("position", Projection::toSpherical(
MapControl::self()->specialIconPos("home")));
cg.config()->sync();
}
void Config::savePOI()
{
KConfigGroup cg(KGlobal::config(), "POI");
QStringList l = Point::showIcon->keys();
QString s;
for (int i = 0; i < l.size(); i++) {
s = l.at(i);
if (Point::showIcon->value(s)) {
cg.writeEntry(s, true);
} else {
cg.deleteEntry(s);
}
if (Point::showText->value(s)) {
cg.writeEntry(s+"_text", true);
} else {
cg.deleteEntry(s+"_text");
}
}
cg.config()->sync();
}
void Config::setIcons()
{
Marker *m = 0;
if (Config::homeDefault()) {
m = new Marker(MapControl::self()->specialIconPos("home"), QString("go-home"));
} else if (Config::homeCustom()) {
m = new Marker(MapControl::self()->specialIconPos("home"), Config::customHomeIcon());
} else {
m = new Marker(MapControl::self()->specialIconPos("home"), QString(""));
}
MapControl::self()->setSpecialIcon("home", m);
KConfigGroup homeGroup(KGlobal::config(), "home");
QPointF p = homeGroup.readEntry("position", QPointF());
MapControl::self()->setSpecialIconPos("home", Projection::toCartesian(p));
m = 0;
if (Config::gpsDefault()) {
m = new Marker(QPointF(), QString("tux"));
} else if (Config::gpsCustom()) {
m = new Marker(QPointF(), Config::customGpsIcon());
} else {
m = new Marker(QPointF(), QString(""));
}
MapControl::self()->setSpecialIcon("gps", m);
MapControl::self()->setSpecialIconVisible("gps", false);
}