]> err.no Git - mapper/blobdiff - src/utils.h
Some fixes
[mapper] / src / utils.h
index bbac3067275b502a0f5a8c4b0941853acff88acc..6bfaa1b8b772d7d48abb1ca55ce8ed8dbe41e133 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of maemo-mapper
+ * This file is part of mapper
  *
  * Copyright (C) 2006-2007 John Costigan.
  *
 #ifndef _MAPPER_UTILS_H
 #define _MAPPER_UTILS_H
 
-#define _GNU_SOURCE
-
-#define _(String) gettext(String)
-
-#include <config.h>
+#include "config.h"
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <sys/wait.h>
 #include <glib/gstdio.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <libgnomevfs/gnome-vfs.h>
 #include <curl/multi.h>
 #include <gconf/gconf-client.h>
-#include <libxml/parser.h>
 
+#include "path.h"
 #include "mapper-types.h"
+#include "gpsdata.h"
 
 /****************************************************************************
  * BELOW: DEFINES ***********************************************************
         (x) = (b); \
 }
 
-#define PI   (3.14159265358979323846f)
-
-#define MERCATOR_SPAN (-6.28318377773622f)
-#define MERCATOR_TOP (3.14159188886811f)
-
 #define SQR(s) ((s)*(s))
 
-/** MAX_ZOOM defines the largest map zoom level we will download.
- * (MAX_ZOOM - 1) is the largest map zoom level that the user can zoom to.
- */
-#define MAX_ZOOM 16
-
-#define TILE_SIZE_PIXELS (256)
-#define TILE_SIZE_P2 (8)
-
-#ifdef WITH_HILDON
-#define BUF_WIDTH_TILES (4)
-#define BUF_HEIGHT_TILES (3)
-#define BUF_WIDTH_PIXELS (1024)
-#define BUF_HEIGHT_PIXELS (768)
-#else
-#define BUF_WIDTH_TILES (8)
-#define BUF_HEIGHT_TILES (8)
-#define BUF_WIDTH_PIXELS (2048)
-#define BUF_HEIGHT_PIXELS (2048)
-#endif
-
 #define ARRAY_CHUNK_SIZE (1024)
 #define BUFFER_SIZE (2048)
-#define WORLD_SIZE_UNITS (2 << (MAX_ZOOM + TILE_SIZE_P2))
-
-#define tile2grid(tile) ((tile) << 3)
-#define grid2tile(grid) ((grid) >> 3)
-#define tile2pixel(tile) ((tile) << 8)
-#define pixel2tile(pixel) ((pixel) >> 8)
-#define tile2unit(tile) ((tile) << (8 + _zoom))
-#define unit2tile(unit) ((unit) >> (8 + _zoom))
-#define tile2zunit(tile, zoom) ((tile) << (8 + zoom))
-#define unit2ztile(unit, zoom) ((unit) >> (8 + zoom))
-
-#define grid2pixel(grid) ((grid) << 5)
-#define pixel2grid(pixel) ((pixel) >> 5)
-#define grid2unit(grid) ((grid) << (5 + _zoom))
-#define unit2grid(unit) ((unit) >> (5 + _zoom))
-
-#define pixel2unit(pixel) ((pixel) << _zoom)
-#define unit2pixel(pixel) ((pixel) >> _zoom)
-#define pixel2zunit(pixel, zoom) ((pixel) << (zoom))
-
-#define unit2bufx(unit) (unit2pixel(unit) - tile2pixel(_base_tilex))
-#define bufx2unit(x) (pixel2unit(x) + tile2unit(_base_tilex))
-#define unit2bufy(unit) (unit2pixel(unit) - tile2pixel(_base_tiley))
-#define bufy2unit(y) (pixel2unit(y) + tile2unit(_base_tiley))
-
-#define unit2x(unit) (unit2pixel(unit) - tile2pixel(_base_tilex) - _offsetx)
-#define x2unit(x) (pixel2unit(x + _offsetx) + tile2unit(_base_tilex))
-#define unit2y(unit) (unit2pixel(unit) - tile2pixel(_base_tiley) - _offsety)
-#define y2unit(y) (pixel2unit(y + _offsety) + tile2unit(_base_tiley))
-
-#define leadx2unit() (_pos.unitx + (_lead_ratio) * pixel2unit(_vel_offsetx))
-#define leady2unit() (_pos.unity + (0.6f*_lead_ratio)*pixel2unit(_vel_offsety))
-
-/* Pans are done two "grids" at a time, or 64 pixels. */
-#define PAN_UNITS (grid2unit(2))
-
-#define INITIAL_DOWNLOAD_RETRIES (3)
 
 #define MACRO_PARSE_INT(tofill, str) { \
     gchar *error_check; \
     } \
 }
 
-#define MACRO_RECALC_CENTER(center_unitx, center_unity) { \
-    switch(_center_mode) \
-    { \
-        case CENTER_LEAD: \
-            center_unitx = leadx2unit(); \
-            center_unity = leady2unit(); \
-            break; \
-        case CENTER_LATLON: \
-            center_unitx = _pos.unitx; \
-            center_unity = _pos.unity; \
-            break; \
-        default: \
-             center_unitx = _center.unitx; \
-             center_unity = _center.unity; \
-            ; \
-    } \
-};
-
-#define latlon2unit(lat, lon, unitx, unity) { \
-    gfloat tmp; \
-    unitx = (lon + 180.f) * (WORLD_SIZE_UNITS / 360.f) + 0.5f; \
-    tmp = sinf(lat * (PI / 180.f)); \
-    unity = 0.5f + (WORLD_SIZE_UNITS / MERCATOR_SPAN) \
-        * (logf((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP); \
-}
-
-#define unit2latlon(unitx, unity, lat, lon) { \
-    (lon) = ((unitx) * (360.f / WORLD_SIZE_UNITS)) - 180.f; \
-    (lat) = (360.f * (atanf(expf(((unity) \
-                                  * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) \
-                     + MERCATOR_TOP)))) * (1.f / PI) - 90.f; \
-}
-
-#define MACRO_RECALC_OFFSET() { \
-    _offsetx = grid2pixel( \
-            unit2grid(_center.unitx) \
-            - _screen_grids_halfwidth \
-            - tile2grid(_base_tilex)); \
-    _offsety = grid2pixel( \
-            unit2grid(_center.unity) \
-            - _screen_grids_halfheight \
-            - tile2grid(_base_tiley)); \
-}
-
-#define MACRO_RECALC_FOCUS_BASE() { \
-    _focus.unitx = x2unit(_screen_width_pixels * _center_ratio / 20); \
-    _focus.unity = y2unit(_screen_height_pixels * _center_ratio / 20); \
-}
-
-#define MACRO_RECALC_FOCUS_SIZE() { \
-    _focus_unitwidth = pixel2unit( \
-            (10 - _center_ratio) * _screen_width_pixels / 10); \
-    _focus_unitheight = pixel2unit( \
-            (10 - _center_ratio) * _screen_height_pixels / 10); \
-}
-
-#define MACRO_RECALC_CENTER_BOUNDS() { \
-  _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth)); \
-  _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight)); \
-  _max_center.unitx = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfwidth) - 1;\
-  _max_center.unity = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfheight)- 1;\
-}
-
-#define MACRO_PATH_INIT(path) { \
-    (path).head = (path).tail = g_new(Point, ARRAY_CHUNK_SIZE); \
-    *((path).tail) = _point_null; \
-    (path).cap = (path).head + ARRAY_CHUNK_SIZE; \
-    (path).whead = g_new(WayPoint, ARRAY_CHUNK_SIZE); \
-    (path).wtail = (path).whead - 1; \
-    (path).wcap = (path).whead + ARRAY_CHUNK_SIZE; \
-}
-
-#define MACRO_PATH_FREE(path) if((path).head) { \
-    WayPoint *curr; \
-    g_free((path).head); \
-    (path).head = (path).tail = (path).cap = NULL; \
-    for(curr = (path).whead - 1; curr++ != (path).wtail; ) \
-        g_free(curr->desc); \
-    g_free((path).whead); \
-    (path).whead = (path).wtail = (path).wcap = NULL; \
-}
-
-#define MACRO_PATH_INCREMENT_TAIL(route) { \
-    if(++(route).tail == (route).cap) \
-        path_resize(&(route), (route).cap - (route).head + ARRAY_CHUNK_SIZE);\
-}
-
-#define MACRO_PATH_INCREMENT_WTAIL(route) { \
-    if(++(route).wtail == (route).wcap) \
-        path_wresize(&(route), \
-                (route).wcap - (route).whead + ARRAY_CHUNK_SIZE); \
-}
-
-#define DISTANCE_SQUARED(a, b) \
-   ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\
-  + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity)))
-
-#define MACRO_QUEUE_DRAW_AREA() \
-    gtk_widget_queue_draw_area( \
-            _map_widget, \
-            0, 0, \
-            _screen_width_pixels, \
-            _screen_height_pixels)
-
-/* Render all on-map metadata an annotations, including POI and paths. */
-#define MACRO_MAP_RENDER_DATA() { \
-    if(_show_poi) \
-        map_render_poi(); \
-    if(_show_tracks > 0) \
-        map_render_paths(); \
-}
-
-#ifdef WITH_HILDON
+#ifdef WITH_OSSO
 #define KEEP_DISPLAY_ON() { \
     /* Note that the flag means keep on ONLY when fullscreen. */ \
     if(_always_keep_on || _fullscreen) \
 #define KEEP_DISPLAY_ON()
 #endif
 
-#define lat_format(A, B) deg_format(_degformat,(A), (B), 'S', 'N')
-#define lon_format(A, B) deg_format(_degformat,(A), (B), 'W', 'E')
-
 #define TRACKS_MASK 0x00000001
 #define ROUTES_MASK 0x00000002
 
     C = curl_easy_init(); \
     curl_easy_setopt(C, CURLOPT_NOPROGRESS, 1); \
     curl_easy_setopt(C, CURLOPT_FOLLOWLOCATION, 1); \
+    curl_easy_setopt(C, CURLOPT_MAXREDIRS, 20); \
     curl_easy_setopt(C, CURLOPT_FAILONERROR, 1); \
     curl_easy_setopt(C, CURLOPT_USERAGENT, \
-            "Mozilla/5.0 (X11; U; Linux i686; en-US; " \
-            "rv:1.8.0.4) Gecko/20060701 Firefox/1.5.0.4"); \
+            "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060701 Firefox/1.5.0.4"); \
     curl_easy_setopt(C, CURLOPT_TIMEOUT, 30); \
     curl_easy_setopt(C, CURLOPT_CONNECTTIMEOUT, 10); \
 }
@@ -321,26 +141,6 @@ if (_http_proxy_host) { \
 #define MACRO_BANNER_SHOW_INFO(A, S) { hildon_banner_show_information(A, NULL, S); }
 #endif
 
-#define WRITE_STRING(string) { \
-    GnomeVFSResult vfs_result; \
-    GnomeVFSFileSize size; \
-    if(GNOME_VFS_OK != (vfs_result = gnome_vfs_write( \
-                    handle, (string), strlen((string)), &size))) \
-    { \
-        gchar buffer[BUFFER_SIZE]; \
-        snprintf(buffer, sizeof(buffer), \
-                "%s:\n%s\n%s", _("Error while writing to file"), \
-                _("File is incomplete."), \
-                gnome_vfs_result_to_string(vfs_result)); \
-        popup_error(_window, buffer); \
-        return FALSE; \
-    } \
-}
-
-gint download_comparefunc(const ProgressUpdateInfo * a,
-                         const ProgressUpdateInfo * b, gpointer user_data);
-gfloat calculate_distance(gfloat lat1, gfloat lon1, gfloat lat2, gfloat lon2);
-void deg_format(DegFormat degformat, gfloat coor, gchar *scoor, gchar neg_char, gchar pos_char);
-void integerize_data();
+void sound_noise(void);
 
 #endif