[glfw] Save/Restore online status of DefaultFileSource

This commit is contained in:
Konstantin Käfer
2017-07-26 16:10:15 +02:00
parent 3a8dc12a8e
commit 796386473e
5 changed files with 26 additions and 0 deletions

View File

@@ -110,6 +110,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
printf("- Press `N` to reset north\n");
printf("- Press `R` to enable the route demo\n");
printf("- Press `E` to insert an example building extrusion layer\n");
printf("- Press `O` to toggle online connectivity\n");
printf("- Press `Z` to cycle through north orientations\n");
printf("- Prezz `X` to cycle through the viewport modes\n");
printf("- Press `A` to cycle through Mapbox offices in the world + dateline monument\n");
@@ -176,6 +177,9 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
if (!mods)
view->map->resetPosition();
break;
case GLFW_KEY_O:
view->onlineStatusCallback();
break;
case GLFW_KEY_S:
if (view->changeStyleCallback)
view->changeStyleCallback();

View File

@@ -28,6 +28,10 @@ public:
pauseResumeCallback = callback;
};
void setOnlineStatusCallback(std::function<void()> callback) {
onlineStatusCallback = callback;
}
void setShouldClose();
void setWindowTitle(const std::string&);
@@ -111,6 +115,7 @@ private:
std::function<void()> changeStyleCallback;
std::function<void()> pauseResumeCallback;
std::function<void()> onlineStatusCallback;
std::function<void(mbgl::Map*)> animateRouteCallback;
mbgl::util::RunLoop runLoop;

View File

@@ -44,6 +44,7 @@ int main(int argc, char *argv[]) {
const struct option long_options[] = {
{"fullscreen", no_argument, nullptr, 'f'},
{"benchmark", no_argument, nullptr, 'b'},
{"offline", no_argument, nullptr, 'o'},
{"style", required_argument, nullptr, 's'},
{"lon", required_argument, nullptr, 'x'},
{"lat", required_argument, nullptr, 'y'},
@@ -65,6 +66,9 @@ int main(int argc, char *argv[]) {
case 'b':
benchmark = true;
break;
case 'o':
settings.online = false;
break;
case 's':
style = std::string(optarg);
break;
@@ -104,6 +108,10 @@ int main(int argc, char *argv[]) {
view = &backend;
mbgl::DefaultFileSource fileSource("/tmp/mbgl-cache.db", ".");
if (!settings.online) {
fileSource.setOnlineStatus(false);
mbgl::Log::Warning(mbgl::Event::Setup, "Application is offline. Press `O` to toggle online status.");
}
// Set access token if present
const char *token = getenv("MAPBOX_ACCESS_TOKEN");
@@ -128,6 +136,11 @@ int main(int argc, char *argv[]) {
map.setPitch(settings.pitch);
map.setDebug(mbgl::MapDebugOptions(settings.debug));
view->setOnlineStatusCallback([&settings, &fileSource]() {
settings.online = !settings.online;
fileSource.setOnlineStatus(settings.online);
mbgl::Log::Info(mbgl::Event::Setup, "Application is %s. Press `O` to toggle online status.", settings.online ? "online" : "offline");
});
view->setChangeStyleCallback([&map] () {
static uint8_t currentStyleIndex;

View File

@@ -14,6 +14,7 @@ void Settings_JSON::load() {
file >> bearing;
file >> pitch;
file >> debug;
file >> online;
}
}
@@ -26,6 +27,7 @@ void Settings_JSON::save() {
file << bearing << std::endl;
file << pitch << std::endl;
file << debug << std::endl;
file << online << std::endl;
}
}
@@ -36,6 +38,7 @@ void Settings_JSON::clear() {
bearing = 0;
pitch = 0;
debug = 0;
online = true;
}
} // namespace mbgl

View File

@@ -19,6 +19,7 @@ public:
double pitch = 0;
EnumType debug = 0;
bool online = true;
};
} // namespace mbgl