Repository navigation
Expand file tree
/
Copy pathFriendMapConfigPage.cpp
More file actions
161 lines (146 loc) · 6.22 KB
/
Copy pathFriendMapConfigPage.cpp
File metadata and controls
161 lines (146 loc) · 6.22 KB
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
/*!
* @file FriendMapConfigPage.cpp
* @author RetroShare Team
*
* Copyright (C) 2014 - 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 "FriendMapConfigPage.h"
#include "ui_FriendMapConfigPage.h"
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QMessageBox>
#include <QFileInfo>
//!
//! \brief FriendMapConfigPage::FriendMapConfigPage
//! \param settings
//!
FriendMapConfigPage::FriendMapConfigPage(FriendMapSettings* settings) :
ui(new Ui::FriendMapConfigPage)
{
ui->setupUi(this);
connect(ui->detached_window, SIGNAL(toggled(bool)), this, SLOT(detached_toggled(bool)));
this->settings = settings;
load();
// Preferences have no OK button any more, so apply every change right away.
// Connected after load() so filling the widgets does not trigger a save.
const QList<QCheckBox*> boxes = {
ui->show_grid, ui->show_links, ui->show_borders, ui->show_cities,
ui->show_ice_layer, ui->show_clouds, ui->show_city_lights,
ui->show_sun_shading, ui->show_avatars, ui->detached_window };
for (QCheckBox* box : boxes)
connect(box, &QCheckBox::toggled, this, &FriendMapConfigPage::applySettings);
connect(ui->projection_box, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &FriendMapConfigPage::applySettings);
connect(ui->theme_dgml, QOverload<int>::of(&QComboBox::activated),
this, &FriendMapConfigPage::applySettings);
if (ui->theme_dgml->lineEdit()) // editable: apply a typed theme when editing ends
connect(ui->theme_dgml->lineEdit(), &QLineEdit::editingFinished,
this, &FriendMapConfigPage::applySettings);
connect(ui->geoip_path_line, &QLineEdit::editingFinished,
this, &FriendMapConfigPage::applySettings);
connect(ui->marble_path_line, &QLineEdit::editingFinished,
this, &FriendMapConfigPage::applySettings);
}
//!
//! \brief FriendMapConfigPage::applySettings
//! Saves the page and updates the map; shows the error if a path is invalid.
//!
void FriendMapConfigPage::applySettings()
{
QString errmsg;
if (!save(errmsg))
QMessageBox::warning(this, tr("FriendMap"), errmsg);
}
//!
//! \brief FriendMapConfigPage::~FriendMapConfigPage
//! Destructor - destroys the user interface
//
FriendMapConfigPage::~FriendMapConfigPage()
{
delete ui;
}
//!
//! \brief FriendMapConfigPage::load
//!
void FriendMapConfigPage::load(){
int themeindex = ui->theme_dgml->findText(QString::fromStdString(settings->map_theme_id));
if (themeindex<0)themeindex=0;
ui->theme_dgml->setCurrentIndex(themeindex);
ui->projection_box->setCurrentIndex(settings->getProjection());
ui->show_grid->setChecked(settings->show_grid);
ui->show_links->setChecked(settings->show_links);
ui->show_borders->setChecked(settings->show_borders);
ui->show_cities->setChecked(settings->show_cities);
ui->show_ice_layer->setChecked(settings->show_ice_layer);
ui->show_clouds->setChecked(settings->show_clouds);
ui->show_city_lights->setChecked(settings->show_city_lights);
ui->show_sun_shading->setChecked(settings->show_sun_shading);
ui->show_avatars->setChecked(settings->show_avatars);
ui->detached_window->setChecked(settings->detached);
ui->geoip_path_line->setText(QString::fromStdString(settings->geoip_data_path));
ui->marble_path_line->setText(settings->marble_path);
}
//!
//! \brief FriendMapConfigPage::save
//! \param errmsg
//! \return
//!
bool FriendMapConfigPage::save(QString &errmsg)
{
settings->show_grid = ui->show_grid->isChecked();
settings->show_links = ui->show_links->isChecked();
settings->show_borders = ui->show_borders->isChecked();
settings->show_cities = ui->show_cities->isChecked();
settings->show_ice_layer = ui->show_ice_layer->isChecked();
settings->show_clouds = ui->show_clouds->isChecked();
settings->show_city_lights = ui->show_city_lights->isChecked();
settings->show_sun_shading = ui->show_sun_shading->isChecked();
settings->show_avatars = ui->show_avatars->isChecked();
settings->detached = ui->detached_window->isChecked();
settings->projection = (Marble::Projection)ui->projection_box->currentIndex();
settings->map_theme_id = ui->theme_dgml->currentText().toStdString();
QString geoip_path = QDir::fromNativeSeparators(ui->geoip_path_line->text().trimmed());
if(!geoip_path.isEmpty() && !QFileInfo(geoip_path).isFile()){
errmsg = "GeoIP data file not found: " + geoip_path;
return false;
}
settings->geoip_data_path = QDir::toNativeSeparators(geoip_path).toStdString();
#ifdef WIN32
// why is this just for windows? On Linux returns warning for unused variable
QString dir = QDir::fromNativeSeparators(ui->marble_path_line->text());
// only re-register Marble's data/plugin folders when the path really changed
if(QDir(dir).canonicalPath() != QDir(QDir::fromNativeSeparators(settings->marble_path)).canonicalPath()
&& !settings->setMarblePath(QDir(dir))){
errmsg = "invalid marble path";
return false;
}
#endif
emit configChanged();
settings->processSettings(false);
errmsg = ""; // set errmsg to a null string
return true;
}
void FriendMapConfigPage::detached_toggled(bool state)
{
if(settings->getDetached() == state)
ui->detached_window->setText(QString(""));
else
ui->detached_window->setText(QString("Restart is required to take effect"));
}
// eof