274 |
andreas |
1 |
//
|
|
|
2 |
// C++ Implementation:
|
|
|
3 |
//
|
|
|
4 |
// Description:
|
|
|
5 |
//
|
|
|
6 |
//
|
|
|
7 |
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
|
|
|
8 |
//
|
|
|
9 |
// Copyright: See COPYING file that comes with this distribution
|
|
|
10 |
//
|
|
|
11 |
//
|
|
|
12 |
|
|
|
13 |
#include "config.h"
|
|
|
14 |
#include "shapewidget.h"
|
|
|
15 |
#include <KConfig>
|
|
|
16 |
#include <KUrlRequester>
|
|
|
17 |
#include <KLineEdit>
|
276 |
andreas |
18 |
#include <KMessageBox>
|
274 |
andreas |
19 |
#include <QDir>
|
|
|
20 |
|
|
|
21 |
shapeWidget::shapeWidget (QWidget* parent, Qt::WFlags fl)
|
|
|
22 |
: QDialog (parent, fl), Ui::shapeWidgetBase()
|
|
|
23 |
{
|
|
|
24 |
QString basePath;
|
|
|
25 |
QDir dir = QDir::home();
|
|
|
26 |
QString path = dir.absolutePath();
|
|
|
27 |
|
276 |
andreas |
28 |
__maptype = MAP_SHAPE; // default map type
|
274 |
andreas |
29 |
setupUi (this);
|
|
|
30 |
// Make sure we are useing only existing files on the local system.
|
|
|
31 |
edShapeFileSet->setMode(KFile::ExistingOnly | KFile::LocalOnly);
|
|
|
32 |
edPluginPath->setMode(KFile::ExistingOnly | KFile::LocalOnly);
|
|
|
33 |
edFontPath->setMode(KFile::ExistingOnly | KFile::LocalOnly);
|
|
|
34 |
edXmlFile->setMode(KFile::ExistingOnly | KFile::LocalOnly);
|
|
|
35 |
|
|
|
36 |
// Get some already saved information from the config file
|
|
|
37 |
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
|
|
|
38 |
KConfigGroup ic (&cfg, "SportWatcher");
|
|
|
39 |
KConfigGroup sh (&cfg, "ShapeFile");
|
|
|
40 |
basePath = ic.readEntry("Data", path + "/.sportwatcher");
|
|
|
41 |
edShapeFileSet->setUrl(ic.readEntry("MAP", basePath + "/shapefiles"));
|
|
|
42 |
// Read the shape specific informations
|
|
|
43 |
#ifdef MAPNIK_PLUGINS
|
|
|
44 |
edPluginPath->setUrl(QString(MAPNIK_PLUGINS));
|
|
|
45 |
edPluginPath->setEnabled(false);
|
|
|
46 |
#else
|
|
|
47 |
// Test some default path
|
|
|
48 |
if (dir.exists(QString("/usr/lib/mapnik/input")))
|
|
|
49 |
edPluginPath->setUrl(sh.readEntry("PluginPath", QString("/usr/lib/mapnik/input")));
|
|
|
50 |
else if (dir.exists(QString("/usr/local/lib/mapnik/input")))
|
|
|
51 |
edPluginPath->setUrl(sh.readEntry("PluginPath", QString("/usr/local/lib/mapnik/input")));
|
|
|
52 |
else if (dir.exists(QString("/usr/lib/mapnik/0.6/input")))
|
|
|
53 |
edPluginPath->setUrl(sh.readEntry("PluginPath", QString("/usr/lib/mapnik/0.6/input")));
|
|
|
54 |
else
|
|
|
55 |
edPluginPath->setUrl(sh.readEntry("PluginPath", QString("")));
|
|
|
56 |
#endif
|
|
|
57 |
#ifdef MAPNIK_FONTS
|
|
|
58 |
edFontPath->setUrl(QString(MAPNIK_FONTS));
|
|
|
59 |
edFontPath->setEnabled(false);
|
|
|
60 |
#else
|
|
|
61 |
// Test some default path
|
|
|
62 |
if (dir.exists(QString("/usr/lib/mapnik/fonts")))
|
|
|
63 |
edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/lib/mapnik/fonts")));
|
|
|
64 |
else if (dir.exists(QString("/usr/local/lib/mapnik/fonts")))
|
|
|
65 |
edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/local/lib/mapnik/fonts")));
|
|
|
66 |
else if (dir.exists(QString("/usr/share/mapnik/fonts")))
|
|
|
67 |
edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/share/mapnik/fonts")));
|
|
|
68 |
else if (dir.exists(QString("/usr/share/fonts/truetype/ttf-dejavu")))
|
|
|
69 |
edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/share/fonts/truetype/ttf-dejavu")));
|
|
|
70 |
else
|
|
|
71 |
edFontPath->setUrl(sh.readEntry("FontPath", QString("")));
|
|
|
72 |
#endif
|
|
|
73 |
edXmlFile->setUrl(sh.readEntry("XmlFile", basePath + "/shapefiles/osm.xml"));
|
278 |
andreas |
74 |
bool geo = sh.readEntry("Geographic", false);
|
|
|
75 |
rbForward->setChecked(geo);
|
|
|
76 |
rbInverse->setChecked(!geo);
|
274 |
andreas |
77 |
}
|
|
|
78 |
|
|
|
79 |
shapeWidget::~shapeWidget()
|
|
|
80 |
{
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/*$SPECIALIZATION$*/
|
276 |
andreas |
84 |
void shapeWidget::setMapType(maptype mt)
|
|
|
85 |
{
|
|
|
86 |
switch (mt)
|
|
|
87 |
{
|
|
|
88 |
case MAP_SHAPE:
|
|
|
89 |
label->setText(i18n("Path to shape file set"));
|
|
|
90 |
break;
|
|
|
91 |
|
|
|
92 |
case MAP_GIS:
|
|
|
93 |
label->setText(i18n("Domain of machine with database"));
|
|
|
94 |
break;
|
|
|
95 |
|
|
|
96 |
case MAP_OSM:
|
|
|
97 |
label->setText(i18n("Path and name of OSM file"));
|
|
|
98 |
break;
|
|
|
99 |
|
|
|
100 |
default:
|
|
|
101 |
KMessageBox::error(this, i18n("Internal error: Unknown map type was set!"));
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
274 |
andreas |
105 |
void shapeWidget::accept()
|
|
|
106 |
{
|
|
|
107 |
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
|
|
|
108 |
KConfigGroup ic (&cfg, "SportWatcher");
|
|
|
109 |
KConfigGroup sh (&cfg, "ShapeFile");
|
|
|
110 |
ic.writeEntry("MAP", edShapeFileSet->lineEdit()->text());
|
|
|
111 |
sh.writeEntry("PluginPath", edPluginPath->lineEdit()->text());
|
|
|
112 |
sh.writeEntry("FontPath", edFontPath->lineEdit()->text());
|
|
|
113 |
sh.writeEntry("XmlFile", edXmlFile->lineEdit()->text());
|
278 |
andreas |
114 |
sh.writeEntry("Geographic", rbForward->isChecked());
|
274 |
andreas |
115 |
cfg.sync();
|
|
|
116 |
done(QDialog::Accepted);
|
|
|
117 |
}
|
|
|
118 |
|
278 |
andreas |
119 |
void shapeWidget::slotForwarded(bool stat)
|
|
|
120 |
{
|
|
|
121 |
if (!stat)
|
|
|
122 |
{
|
|
|
123 |
rbForward->setChecked(true);
|
|
|
124 |
rbInverse->setChecked(false);
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
void shapeWidget::slotInversed(bool stat)
|
|
|
129 |
{
|
|
|
130 |
if (!stat)
|
|
|
131 |
{
|
|
|
132 |
rbForward->setChecked(false);
|
|
|
133 |
rbInverse->setChecked(true);
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
|
274 |
andreas |
137 |
#include "shapewidget.moc"
|
|
|
138 |
|