Subversion Repositories public

Rev

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

Rev Author Line No. Line
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"));
74
}
75
 
76
shapeWidget::~shapeWidget()
77
{
78
}
79
 
80
/*$SPECIALIZATION$*/
276 andreas 81
void shapeWidget::setMapType(maptype mt)
82
{
83
	switch (mt)
84
	{
85
	   case MAP_SHAPE:
86
	      label->setText(i18n("Path to shape file set"));
87
	   break;
88
 
89
	   case MAP_GIS:
90
	      label->setText(i18n("Domain of machine with database"));
91
	   break;
92
 
93
	   case MAP_OSM:
94
	      label->setText(i18n("Path and name of OSM file"));
95
	   break;
96
 
97
	   default:
98
	      KMessageBox::error(this, i18n("Internal error: Unknown map type was set!"));
99
	}
100
}
101
 
274 andreas 102
void shapeWidget::accept()
103
{
104
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
105
	KConfigGroup ic (&cfg, "SportWatcher");
106
	KConfigGroup sh (&cfg, "ShapeFile");
107
	ic.writeEntry("MAP", edShapeFileSet->lineEdit()->text());
108
	sh.writeEntry("PluginPath", edPluginPath->lineEdit()->text());
109
	sh.writeEntry("FontPath", edFontPath->lineEdit()->text());
110
	sh.writeEntry("XmlFile", edXmlFile->lineEdit()->text());
111
	cfg.sync();
112
	done(QDialog::Accepted);
113
}
114
 
115
#include "shapewidget.moc"
116