summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Grandin <grandinp@altern.org>2017-01-22 11:56:06 -0800
committerPierre Grandin <grandinp@altern.org>2017-01-22 11:56:06 -0800
commit68c3f9591b618a683280502a720f9869e45e7e25 (patch)
tree32018b91475a78dc0f066916efac41534472b1b9
parentc5127edf4987d9cb1868602f1bd2f5f0083c85b4 (diff)
downloadnavit-68c3f9591b618a683280502a720f9869e45e7e25.tar.gz
Added a map downloader stub
-rwxr-xr-xCMakeLists.txt7
-rw-r--r--config.h.cmake2
-rw-r--r--navit/CMakeLists.txt4
-rw-r--r--navit/gui/internal/CMakeLists.txt10
-rw-r--r--navit/gui/internal/gui_internal_command.c7
-rw-r--r--navit/gui/internal/gui_internal_map_downloader.c150
-rw-r--r--navit/gui/internal/gui_internal_map_downloader.h1
-rw-r--r--navit/gui/internal/gui_internal_priv.h13
8 files changed, 192 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d154e1e6c..b0fa2922c 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -148,6 +148,7 @@ find_package(DBusGLib)
find_package(PythonLibs)
find_package(OpenSSL)
find_package(Threads)
+find_package(CURL)
libfind_pkg_check_modules(FONTCONFIG fontconfig)
#Qt detection
if (NOT DISABLE_QT)
@@ -399,6 +400,12 @@ if (GETTEXT_FOUND)
set_with_reason(USE_NATIVE_LANGUAGE_SUPPORT "Gettext found" TRUE)
endif(GETTEXT_FOUND)
+if (CURL_FOUND)
+ list(APPEND NAVIT_LIBS "-lcurl")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -u download_map")
+ set(HAVE_CURL 1)
+endif(CURL_FOUND)
+
#Independent modules
add_module(graphics/null "Default" TRUE)
add_module(osd/core "Default" TRUE)
diff --git a/config.h.cmake b/config.h.cmake
index 4774efbaf..169bfa0a4 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -93,3 +93,5 @@
#cmakedefine HAVE_SHMEM 1
#cmakedefine HAVE_IMLIB2 1
+
+#cmakedefine HAVE_CURL 1
diff --git a/navit/CMakeLists.txt b/navit/CMakeLists.txt
index 5333c9ff4..ebb9593ac 100644
--- a/navit/CMakeLists.txt
+++ b/navit/CMakeLists.txt
@@ -11,6 +11,10 @@ set(NAVIT_SRC announcement.c atom.c attr.c cache.c callback.c command.c config_.
profile.c profile_option.c projection.c roadprofile.c route.c script.c search.c speech.c start_real.c sunriset.c transform.c track.c
search_houseno_interpol.c util.c vehicle.c vehicleprofile.c xmlconfig.c )
+if(HAVE_CURL)
+ list(APPEND NAVIT_SRC network.c)
+endif(HAVE_CURL)
+
if(NOT USE_PLUGINS)
list(APPEND NAVIT_SRC ${CMAKE_CURRENT_BINARY_DIR}/builtin.c)
endif(NOT USE_PLUGINS)
diff --git a/navit/gui/internal/CMakeLists.txt b/navit/gui/internal/CMakeLists.txt
index 230e315d6..6bd74ddaf 100644
--- a/navit/gui/internal/CMakeLists.txt
+++ b/navit/gui/internal/CMakeLists.txt
@@ -1 +1,9 @@
-module_add_library(gui_internal gui_internal.c gui_internal_bookmark.c gui_internal_command.c gui_internal_gesture.c gui_internal_html.c gui_internal_menu.c gui_internal_poi.c gui_internal_search.c gui_internal_widget.c gui_internal_keyboard.c)
+if(HAVE_CURL)
+ set(map_downloader_sources gui_internal_map_downloader.c )
+endif(HAVE_CURL)
+
+module_add_library(gui_internal ${map_downloader_sources}
+ gui_internal.c gui_internal_bookmark.c
+ gui_internal_command.c gui_internal_gesture.c gui_internal_html.c
+ gui_internal_menu.c gui_internal_poi.c gui_internal_search.c
+ gui_internal_widget.c gui_internal_keyboard.c)
diff --git a/navit/gui/internal/gui_internal_command.c b/navit/gui/internal/gui_internal_command.c
index d26bd677d..81c89dbda 100644
--- a/navit/gui/internal/gui_internal_command.c
+++ b/navit/gui/internal/gui_internal_command.c
@@ -36,6 +36,9 @@
#include "gui_internal_search.h"
#include "gui_internal_poi.h"
#include "gui_internal_command.h"
+#ifdef HAVE_CURL
+#include "gui_internal_map_downloader.h"
+#endif
extern char *version;
@@ -1279,7 +1282,9 @@ static struct command_table commands[] = {
{"waypoints",command_cast(gui_internal_cmd2)},
{"write",command_cast(gui_internal_cmd_write)},
{"about",command_cast(gui_internal_cmd2)},
-
+#ifdef HAVE_CURL
+ {"map_downloader", command_cast (gui_internal_map_downloader)},
+#endif
};
void
diff --git a/navit/gui/internal/gui_internal_map_downloader.c b/navit/gui/internal/gui_internal_map_downloader.c
new file mode 100644
index 000000000..9e36d6dbb
--- /dev/null
+++ b/navit/gui/internal/gui_internal_map_downloader.c
@@ -0,0 +1,150 @@
+#include <glib.h>
+#include <navit/main.h>
+#include <navit/debug.h>
+#include <navit/point.h>
+#include <navit/navit.h>
+#include <navit/callback.h>
+#include <navit/color.h>
+#include "graphics.h"
+#include <navit/event.h>
+#include <navit/command.h>
+#include <navit/config_.h>
+#include <navit/transform.h>
+
+#include "gui_internal.h"
+#include "coord.h"
+#include "math.h"
+#include "gui_internal_menu.h"
+#include "gui_internal_widget.h"
+#include "gui_internal_priv.h"
+#include "gui_internal_map_downloader.h"
+#include "network.h"
+#include <pthread.h>
+
+pthread_t dl_thread;
+struct map_download_info dl_info;
+
+void
+gui_internal_download_update(struct gui_priv * this)
+{
+ dbg(lvl_debug, "downloading status = %i\n", dl_info.downloading);
+ if(dl_info.downloading == 1){
+ event_add_timeout(500, 0, this->download_cb);
+ } else {
+ if(pthread_join(dl_thread, NULL)) {
+ dbg(lvl_error, "Error joining download thread\n");
+ }
+ }
+
+ if(this->download_data.download_showing) {
+ gui_internal_populate_download_table(this);
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ gui_internal_menu_render(this);
+ graphics_draw_mode(this->gra, draw_mode_end);
+ }
+}
+
+void
+gui_internal_map_downloader(struct gui_priv *this, struct widget *wm, void *data)
+{
+ struct widget *wb, *w, *wr, *wk, *we, *wl;
+ wb=gui_internal_menu(this,"Map download");
+ w=gui_internal_box_new(this, gravity_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(wb, w);
+ wr=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(w, wr);
+ we=gui_internal_box_new(this, gravity_left_center|orientation_horizontal|flags_fill);
+ gui_internal_widget_append(wr, we);
+
+ struct widget * box;
+
+ if(! this->download_cb)
+ {
+ dbg(lvl_error, "Added callback\n");
+ this->download_cb = callback_new_1(callback_cast(gui_internal_download_update), this);
+ event_add_timeout(500, 0, this->download_cb);
+ }
+
+ this->download_data.download_table = gui_internal_widget_table_new(this,gravity_left_top | flags_fill | flags_expand |orientation_vertical,1);
+
+ wb->wfree=gui_internal_download_screen_free;
+ this->download_data.download_showing=1;
+ this->download_data.download_table->spx = this->spacing;
+
+
+ box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
+
+ gui_internal_widget_append(box,this->download_data.download_table);
+ box->w=wb->w;
+ box->spx = this->spacing;
+ this->download_data.download_table->w=box->w;
+ gui_internal_widget_append(wb,box);
+ gui_internal_populate_download_table(this);
+
+ if ( dl_thread ) {
+ dbg(lvl_error, "Download already in progress\n");
+
+ } else {
+ dbg(lvl_error, "Download will be started\n");
+ strcpy (dl_info.url, g_strdup_printf ("http://maps9.navit-project.org/api/map/?bbox=-125.94,32.43,-114.08,42.07&timestamp=161223"));
+ strcpy (dl_info.url, g_strdup_printf ("http://www.navit-project.org/maps/osm_bbox_11.3,47.9,11.7,48.2.osm.bz2"));
+ dbg(lvl_error,"Url %s\n", dl_info.url);
+
+ if(pthread_create(&dl_thread, NULL, download_map, &dl_info)) {
+ dbg(lvl_error, "Error creating download thread\n");
+ return 1;
+ }
+
+ }
+
+ gui_internal_menu_render(this);
+}
+
+void
+gui_internal_populate_download_table(struct gui_priv * this)
+{
+ struct navigation * nav = NULL;
+ struct item * item =NULL;
+ struct attr attr,route;
+ struct widget * label = NULL;
+ struct widget * row = NULL;
+ struct coord c;
+
+ if(this->download_data.download_showing){
+ GList *toprow;
+ struct item topitem={0};
+ toprow=gui_internal_widget_table_top_row(this, this->download_data.download_table);
+ if(toprow && toprow->data)
+ topitem=((struct widget*)toprow->data)->item;
+ gui_internal_widget_table_clear(this,this->download_data.download_table);
+
+ row = gui_internal_widget_table_row_new(this,
+ gravity_left
+ | flags_fill
+ | orientation_horizontal);
+ gui_internal_widget_append(this->download_data.download_table,row);
+ double percent = dl_info.dl_now / dl_info.dl_total * 100;
+ char * text;
+ text=g_strdup_printf("Download is %s %lf / %lf = %lf% \n", dl_info.downloading == 1 ? "active" : "inactive" ,dl_info.dl_now, dl_info.dl_total, percent);
+ label = gui_internal_label_new(this,text);
+ gui_internal_widget_append(row,label);
+ g_free(text);
+ }
+}
+
+
+/**
+ * @brief Called when the download screen is closed (deallocated).
+ *
+ * The main purpose of this function is to remove the widgets from
+ * references download_data because those widgets are about to be freed.
+ */
+void
+gui_internal_download_screen_free(struct gui_priv * this,struct widget * w)
+{
+ if(this) {
+ this->download_data.download_showing=0;
+ this->download_data.download_table=NULL;
+ g_free(w);
+ }
+}
diff --git a/navit/gui/internal/gui_internal_map_downloader.h b/navit/gui/internal/gui_internal_map_downloader.h
new file mode 100644
index 000000000..e3fba89cc
--- /dev/null
+++ b/navit/gui/internal/gui_internal_map_downloader.h
@@ -0,0 +1 @@
+void gui_internal_map_downloader(struct gui_priv *this, struct widget *wm, void *data);
diff --git a/navit/gui/internal/gui_internal_priv.h b/navit/gui/internal/gui_internal_priv.h
index 0dee59db2..3fea8fb39 100644
--- a/navit/gui/internal/gui_internal_priv.h
+++ b/navit/gui/internal/gui_internal_priv.h
@@ -35,6 +35,12 @@ struct route_data {
int route_showing;
};
+struct download_data {
+ struct widget * download_table;
+ int download_showing;
+};
+
+
/**
* Private data for the internal GUI.
*
@@ -91,7 +97,10 @@ struct gui_priv {
struct point current;
struct callback * vehicle_cb;
+ struct event_timeout * download_cb;
+
struct route_data route_data; /**< Stores information about the route. */
+ struct download_data download_data; /**< Stores information about the map downloads */
struct gui_internal_data data;
struct callback_list *cbl;
@@ -224,5 +233,9 @@ struct heightline *item_get_heightline(struct item *item);
void gui_internal_route_update(struct gui_priv *this, struct navit *navit, struct vehicle *v);
void gui_internal_route_screen_free(struct gui_priv *this_, struct widget *w);
void gui_internal_populate_route_table(struct gui_priv *this, struct navit *navit);
+void gui_internal_download_update(struct gui_priv *this);
+void gui_internal_populate_download_table(struct gui_priv *this);
+void gui_internal_download_screen_free(struct gui_priv *this_, struct widget *w);
+
void plugin_init(void);
/* end of prototypes */