Remove lots of ifdef'ed out code from GTK/glib version

There's still a ton more left, but this is a start.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-10-06 10:55:18 -07:00
parent b01cc72ef5
commit 70352c3962
4 changed files with 1 additions and 389 deletions

View file

@ -534,38 +534,6 @@ void update_cylinder_related_info(struct dive *dive)
}
}
#if USE_GTK_UI
static void get_string(char **str, const char *s)
{
int len;
char *n;
if (!s)
s = "";
len = g_utf8_strlen(s, -1);
if (len > 60)
len = 60;
n = malloc(len * sizeof(gunichar) + 1);
g_utf8_strncpy(n, s, len);
*str = n;
}
void get_location(struct dive *dive, char **str)
{
get_string(str, dive->location);
}
void get_cylinder(struct dive *dive, char **str)
{
get_string(str, dive->cylinder[0].type.description);
}
void get_suit(struct dive *dive, char **str)
{
get_string(str, dive->suit);
}
#endif
#define MAX_DATE_STRING 256
/* caller needs to free the string */
char *get_dive_date_string(timestamp_t when)
@ -610,7 +578,7 @@ char *get_trip_date_string(timestamp_t when, int nr)
utc_mkdate(when, &tm);
if (nr != 1) {
snprintf(buffer, MAX_DATE_STRING,
#if 0
#if PLURAL_HANDLING_IN_TRANLATION
/*++GETTEXT 60 char buffer monthname, year, nr dives */
ngettext("%1$s %2$d (%3$d dive)",
"%1$s %2$d (%3$d dives)", nr),

284
info.c
View file

@ -24,287 +24,11 @@
#include "display.h"
#include "divelist.h"
#if USE_GTK_UI
/* old is NULL or a valid string, new is a valid string
* NOTE: NULL and "" need to be treated as "unchanged" */
int text_changed(const char *old, const char *new)
{
return (old && strcmp(old,new)) ||
(!old && strcmp("",new));
}
static const char *skip_space(const char *str)
{
if (str) {
while (g_ascii_isspace(*str))
str++;
if (!*str)
str = NULL;
}
return str;
}
/*
* should this string be changed?
* The "master" string is the string of the current dive - we only consider it
* changed if the old string is either empty, or matches that master string.
*/
char *evaluate_string_change(const char *newstring, char **textp, const char *master)
{
char *old = *textp;
const char *old_text;
old_text = skip_space(old);
master = skip_space(master);
/*
* If we had a master string, and it doesn't match our old
* string, we will always pick the old value (it means that
* we're editing another dive's info that already had a
* valid value).
*/
if (master && old_text)
if (strcmp(master, old_text))
return NULL;
while (g_ascii_isspace(*newstring))
newstring++;
/* If the master string didn't change, don't change other dives either! */
if (!text_changed(master, newstring))
return NULL;
if (!text_changed(old, newstring))
return NULL;
free(old);
*textp = strdup(newstring);
return *textp;
}
int divename(char *buf, size_t size, struct dive *dive, char *trailer)
{
struct tm tm;
utc_mkdate(dive->when, &tm);
/*++GETTEXT 80 char buffer: dive nr, weekday, month, day, year, hour, min <trailing text>*/
return snprintf(buf, size, tr("Dive #%1$d - %2$s %3$02d/%4$02d/%5$04d at %6$d:%7$02d %8$s"),
dive->number,
weekday(tm.tm_wday),
tm.tm_mon+1, tm.tm_mday,
tm.tm_year+1900,
tm.tm_hour, tm.tm_min,
trailer);
}
/* caller should free the string returned after it is no longer needed */
const char *get_window_title(struct dive *dive)
{
const char *text;
const int maxlen = 128;
char *basename;
char *title;
char *buffer = NULL;
int len1, len2, sz;
if (!dive) {
if (existing_filename) {
char *basename;
basename = g_path_get_basename(existing_filename);
len1 = sizeof("Subsurface: ");
len2 = g_utf8_strlen(basename, -1);
sz = (len1 + len2) * sizeof(gunichar);
title = malloc(sz);
strncpy(title, "Subsurface: ", len1);
g_utf8_strncpy(title + len1, basename, len2);
} else {
title = strdup("Subsurface");
}
} else {
/* dive number and location (or lacking that, the date) go in the window title */
text = dive->location;
if (!text)
text = "";
if (*text) {
if (dive->number) {
len1 = g_utf8_strlen(text, -1);
sz = (len1 + 32) * sizeof(gunichar);
buffer = malloc(sz);
snprintf(buffer, sz, tr("Dive #%d - "), dive->number);
g_utf8_strncpy(buffer + strlen(buffer), text, len1);
text = buffer;
}
} else {
sz = (maxlen + 32) * sizeof(gunichar);
buffer = malloc(sz);
divename(buffer, sz, dive, "");
text = buffer;
}
/* put it all together */
if (existing_filename) {
basename = g_path_get_basename(existing_filename);
len1 = g_utf8_strlen(basename, -1);
len2 = g_utf8_strlen(text, -1);
if (len2 > maxlen)
len2 = maxlen;
sz = (len1 + len2 + 3) * sizeof(gunichar); /* reserver space for ": " */
title = malloc(sz);
g_utf8_strncpy(title, basename, len1);
strncpy(title + strlen(basename), (const char *)": ", 2);
g_utf8_strncpy(title + strlen(basename) + 2, text, len2);
} else {
title = strdup(text);
}
if (buffer)
free(buffer);
}
return title;
}
/* this is used to skip the cardinal directions (or check if they are
* present). You pass in the text and a STRING with the direction.
* This checks for both the standard english text (just one character)
* and the translated text (possibly longer) and returns 0 if not found
* and the number of chars to skip otherwise. */
static int string_advance_cardinal(const char *text, const char *look)
{
char *trans;
int len = strlen(look);
if (!strncasecmp(text, look, len))
return len;
trans = tr(look);
len = strlen(trans);
if (!strncasecmp(text, trans, len))
return len;
return 0;
}
/* this has to be done with UTF8 as people might want to enter the degree symbol */
bool parse_gps_text(const char *gps_text, double *latitude, double *longitude)
{
const char *text = gps_text;
char *endptr;
bool south = FALSE;
bool west = FALSE;
double parselat, parselong;
gunichar degrees = UCS4_DEGREE;
gunichar c;
int incr;
while (g_unichar_isspace(g_utf8_get_char(text)))
text = g_utf8_next_char(text);
/* an empty string is interpreted as 0.0,0.0 and therefore "no gps location" */
if (!*text) {
*latitude = 0.0;
*longitude = 0.0;
return TRUE;
}
/* ok, let's parse by hand - first degrees of latitude */
text += string_advance_cardinal(text, "N");
if ((incr = string_advance_cardinal(text, "S")) > 0) {
text += incr;
south = TRUE;
}
parselat = g_ascii_strtod(text, &endptr);
if (text == endptr)
return FALSE;
text = endptr;
if (parselat < 0.0) {
south = TRUE;
parselat *= -1;
}
/* next optional minutes as decimal, skipping degree symbol */
while (g_unichar_isspace(c = g_utf8_get_char(text)) || c == degrees)
text = g_utf8_next_char(text);
incr = string_advance_cardinal(text, "E") + string_advance_cardinal(text, "W");
if (!incr && c != ';' && c != ',') {
parselat += g_ascii_strtod(text, &endptr) / 60.0;
if (text == endptr)
return FALSE;
text = endptr;
/* skip trailing minute symbol */
if (g_utf8_get_char(text) == '\'')
text = g_utf8_next_char(text);
}
/* skip seperator between latitude and longitude */
while (g_unichar_isspace(c = g_utf8_get_char(text)) || c == ';' || c == ',')
text = g_utf8_next_char(text);
/* next degrees of longitude */
text += string_advance_cardinal(text, "E");
if ((incr = string_advance_cardinal(text, "W")) > 0) {
text += incr;
west = TRUE;
}
parselong = g_ascii_strtod(text, &endptr);
if (text == endptr)
return FALSE;
text = endptr;
if (parselong < 0.0) {
west = TRUE;
parselong *= -1;
}
/* next optional minutes as decimal, skipping degree symbol */
while (g_unichar_isspace(c = g_utf8_get_char(text)) || c == degrees)
text = g_utf8_next_char(text);
if (*text) {
parselong += g_ascii_strtod(text, &endptr) / 60.0;
if (text == endptr)
return FALSE;
text = endptr;
/* skip trailing minute symbol */
if (g_utf8_get_char(text) == '\'')
text = g_utf8_next_char(text);
/* make sure there's nothing else left on the input */
while (g_unichar_isspace(g_utf8_get_char(text)))
text = g_utf8_next_char(text);
if (*text)
return FALSE;
}
if (west && parselong > 0.0)
parselong *= -1;
if (south && parselat > 0.0)
parselat *= -1;
*latitude = parselat;
*longitude = parselong;
return TRUE;
}
bool gps_changed(struct dive *dive, struct dive *master, const char *gps_text)
{
double latitude, longitude;
int latudeg, longudeg;
/* if we have a master and the dive's gps address is different from it,
* don't change the dive */
if (master && (master->latitude.udeg != dive->latitude.udeg ||
master->longitude.udeg != dive->longitude.udeg))
return FALSE;
if (!parse_gps_text(gps_text, &latitude, &longitude))
return FALSE;
latudeg = rint(1000000 * latitude);
longudeg = rint(1000000 * longitude);
/* if dive gps didn't change, nothing changed */
if (dive->latitude.udeg == latudeg && dive->longitude.udeg == longudeg)
return FALSE;
/* ok, update the dive and mark things changed */
dive->latitude.udeg = latudeg;
dive->longitude.udeg = longudeg;
return TRUE;
}
#endif
/* take latitude and longitude in udeg and print them in a human readable
* form, without losing precision */
void print_gps_coordinates(char *buffer, int len, int lat, int lon)
{
unsigned int latdeg, londeg;
#if 0
double latmin, lonmin;
#endif
const char *lath, *lonh;
char dbuf_lat[32], dbuf_lon[32];
@ -318,18 +42,10 @@ void print_gps_coordinates(char *buffer, int len, int lat, int lon)
lon = abs(lon);
latdeg = lat / 1000000;
londeg = lon / 1000000;
#if 0
latmin = (lat % 1000000) * 60.0 / 1000000.0;
lonmin = (lon % 1000000) * 60.0 / 1000000.0;
*dbuf_lat = *dbuf_lon = 0;
g_ascii_formatd(dbuf_lat, sizeof(dbuf_lat), "%8.5f", latmin);
g_ascii_formatd(dbuf_lon, sizeof(dbuf_lon), "%8.5f", lonmin);
#else
int ilatmin = (lat % 1000000) * 60;
int ilonmin = (lon % 1000000) * 60;
snprintf(dbuf_lat, sizeof(dbuf_lat), "%2d.%05d", ilatmin / 1000000, (ilatmin % 1000000) / 10);
snprintf(dbuf_lon, sizeof(dbuf_lon), "%2d.%05d", ilonmin / 1000000, (ilonmin % 1000000) / 10);
#endif
if (!*dbuf_lat || !*dbuf_lon) {
*buffer = 0;
return;

View file

@ -8,9 +8,6 @@
#include "dive.h"
#include "display.h"
#if USE_GTK_UI
#include "display-gtk.h"
#endif
#include "divelist.h"
#include "profile.h"
@ -28,24 +25,6 @@ static struct plot_data *last_pi_entry = NULL;
#define cairo_set_line_width_scaled(cr, w) \
cairo_set_line_width((cr), (w) * plot_scale);
#if USE_GTK_UI
/* keep the last used gc around so we can invert the SCALEX calculation in
* order to calculate a time value for an x coordinate */
static struct graphics_context last_gc;
int x_to_time(double x)
{
int seconds = (x - last_gc.drawing_area.x) / last_gc.maxx * (last_gc.rightx - last_gc.leftx) + last_gc.leftx;
return (seconds > 0) ? seconds : 0;
}
/* x offset into the drawing area */
int x_abs(double x)
{
return x - last_gc.drawing_area.x;
}
#endif /* USE_GTK_UI */
/* debugging tool - not normally used */
static void dump_pi (struct plot_info *pi)
{
@ -205,54 +184,6 @@ void setup_pp_limits(struct graphics_context *gc)
gc->bottomy = -gc->topy / 20;
}
#if 0
static void plot_smoothed_profile(struct graphics_context *gc, struct plot_info *pi)
{
int i;
struct plot_data *entry = pi->entry;
set_source_rgba(gc, SMOOTHED);
move_to(gc, entry->sec, entry->smoothed);
for (i = 1; i < pi->nr; i++) {
entry++;
line_to(gc, entry->sec, entry->smoothed);
}
cairo_stroke(gc->cr);
}
static void plot_minmax_profile_minute(struct graphics_context *gc, struct plot_info *pi,
int index)
{
int i;
struct plot_data *entry = pi->entry;
set_source_rgba(gc, MINUTE);
move_to(gc, entry->sec, entry->min[index]->depth);
for (i = 1; i < pi->nr; i++) {
entry++;
line_to(gc, entry->sec, entry->min[index]->depth);
}
for (i = 1; i < pi->nr; i++) {
line_to(gc, entry->sec, entry->max[index]->depth);
entry--;
}
cairo_close_path(gc->cr);
cairo_fill(gc->cr);
}
static void plot_minmax_profile(struct graphics_context *gc, struct plot_info *pi)
{
if (gc->printer)
return;
plot_minmax_profile_minute(gc, pi, 2);
plot_minmax_profile_minute(gc, pi, 1);
plot_minmax_profile_minute(gc, pi, 0);
}
#endif /* USE_GTK_UI */
int get_cylinder_pressure_range(struct graphics_context *gc)
{
gc->leftx = 0;

View file

@ -66,10 +66,7 @@ Translator::Translator(QObject *parent):
QString Translator::translate(const char *context, const char *sourceText,
const char *disambiguation) const
{
return sourceText;
#if 0
return gettext(sourceText);
#endif
}
#endif