-
Notifications
You must be signed in to change notification settings - Fork 6
/
FriendMapSettings.cpp
166 lines (150 loc) · 6.1 KB
/
FriendMapSettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*!
* @file FriendMapSettings.cpp
* @author Nyfor, RetroShare Team
*
* Copyright (C) 2014 - Nyfor, RetroShare Team
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "FriendMapSettings.h"
#include <QFile>
#include <QDir>
#include <QCoreApplication>
#include <QMessageBox>
#include <marble/MarbleDirs.h>
#include "gui/settings/rsharesettings.h"
//!
//! \brief FriendMapSettings::FriendMapSettings
//!
FriendMapSettings::FriendMapSettings()
{
this->show_grid = false;
this->show_links = true;
this->projection = Marble::Spherical;
this->geoip_data_path = "";
this->detached = false;
//earth/openstreetmap/openstreetmap.dgml
//earth/plain/plain.dgml
//earth/schagen1689/schagen1689.dgml
//"earth/citylights/citylights.dgml"
//this->map_theme_id = "earth/openstreetmap/openstreetmap.dgml";
this->map_theme_id = "earth/bluemarble/bluemarble.dgml";
processSettings(true);
}
//!
//! \brief FriendMapSettings::processSettings
//! \param load
//!
void FriendMapSettings::processSettings(bool load)
{
Settings->beginGroup(QString("FriendMapSettings"));
if (load) {
// load settings
show_grid = Settings->value("show_grid").toBool();
show_links = Settings->value("show_links").toBool();
show_borders = Settings->value("show_borders").toBool();
show_cities = Settings->value("show_cities").toBool();
show_ice_layer = Settings->value("show_ice_layer").toBool();
show_clouds = Settings->value("show_clouds").toBool();
show_city_lights = Settings->value("show_city_lights").toBool();
show_sun_shading = Settings->value("show_sun_shading").toBool();
show_avatars = Settings->value("show_avatars").toBool();
detached = Settings->value("detached").toBool();
projection = (Marble::Projection)Settings->value("projection_type").toInt();
map_theme_id = Settings->value("map_theme_id").toString().toStdString();
if (map_theme_id.length() < 2)map_theme_id = "earth/bluemarble/bluemarble.dgml";
} else {
// save settings
Settings->setValue("show_grid", show_grid);
Settings->setValue("show_links", show_links);
Settings->setValue("show_borders", show_borders);
Settings->setValue("show_cities", show_cities);
Settings->setValue("show_ice_layer", show_ice_layer);
Settings->setValue("show_clouds", show_clouds);
Settings->setValue("show_city_lights", show_city_lights);
Settings->setValue("show_sun_shading", show_sun_shading);
Settings->setValue("show_avatars", show_avatars);
Settings->setValue("detached", detached);
Settings->setValue("projection_type", projection);
Settings->setValue("map_theme_id", QString::fromStdString(map_theme_id));
}
Settings->endGroup();
}
//!
//! \brief FriendMapSettings::setMarblePath
//! \param marble_path
//! \return
//!
bool FriendMapSettings::setMarblePath(const QDir &marble_path)
{
this->marble_path = QDir::toNativeSeparators(marble_path.canonicalPath());
QDir plugins = QDir(marble_path);
QDir data = QDir(marble_path);
bool valid = plugins.cd("plugins") && data.cd("data");
if(valid){
Marble::MarbleDirs::setMarblePluginPath(plugins.canonicalPath());
Marble::MarbleDirs::setMarbleDataPath(data.canonicalPath());
}
return valid;
}
//!
//! \brief FriendMapSettings::setStdPaths
//! \param pgHandler
//!
void FriendMapSettings::setStdPaths(RsPluginHandler *pgHandler)
{
#ifdef WIN32
//Finding marble installation
//Included with the plugin, RS_folder/marble
QDir marblepathlocal = QDir(QCoreApplication::applicationDirPath());
if(marblepathlocal.cd("marble") && setMarblePath(marblepathlocal)){
//found in RS folder, nothing to do
}else{
//look for it in Program Files
QByteArray pfdir = qgetenv("PROGRAMFILES(X86)");
if(pfdir.isNull() || pfdir.isEmpty()){
pfdir = qgetenv("PROGRAMFILES");
}
//check it again
if(!pfdir.isNull() && !pfdir.isEmpty()){
QString path = QString(pfdir);
QDir marblepathprogramfiles = QDir(QDir::fromNativeSeparators(path));
if(marblepathprogramfiles.cd("marble") && setMarblePath(marblepathprogramfiles)){
//found in Program Files, nothing to do
//TODO: check installed marble version, only if somebody reports problem about it
}else{
QString message = QString("Marble not found in the following places, please install Marble and/or set the path manually in the options<br>");
message += QString(QCoreApplication::applicationDirPath() + "/marble<br>");
message += QString(path + "/marble<br>");
QMessageBox::warning(NULL, "Marble not found", message);
}
}else{
//this shouldn't happen on Windows
QMessageBox::warning(NULL, "Program Files directory not found", "Are your enviroment variables correct?");
}
}
#endif
const std::vector<std::string>& plugin_directories = pgHandler->getPluginDirectories();
foreach(const std::string& dir, plugin_directories){
QFileInfo finfo(QString::fromStdString(dir+"GeoLiteCity.dat"));
std::cout<<QString::fromStdString(dir+"GeoLiteCity.dat").toStdString();
if(finfo.exists()){
geoip_data_path = QDir::toNativeSeparators(finfo.canonicalFilePath()).toStdString();
break;
}
}
}
// eof