Remove info.c/info.h

The one remaining helper function in there was moved to maintab.cpp (which
was the one remaining user).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-10-07 11:48:14 -07:00
parent d9f24b282a
commit 90b0f75d40
7 changed files with 29 additions and 240 deletions

View file

@ -23,7 +23,6 @@ ICONDIR = $(ICONPATH)/scalable/apps
MANDIR = $(DATADIR)/man/man1
XSLTDIR = $(DATADIR)/$(NAME)/xslt
MARBLEDIR = marbledata/maps/earth/googlesat
gtk_update_icon_cache = gtk-update-icon-cache -f -t $(ICONPATH)
ICONFILE = $(NAME)-icon.svg
DESKTOPFILE = $(NAME).desktop
@ -67,7 +66,6 @@ SOURCES = \
divelist.c \
equipment.c \
file.c \
info.c \
parse-xml.c \
planner.c \
subsurfacestartup.c \

4
dive.c
View file

@ -771,10 +771,6 @@ struct dive *fixup_dive(struct dive *dive)
int i;
struct divecomputer *dc;
add_people(dive->buddy);
add_people(dive->divemaster);
add_location(dive->location);
add_suit(dive->suit);
sanitize_cylinder_info(dive);
dive->maxcns = dive->cns;

3
dive.h
View file

@ -659,9 +659,6 @@ extern void add_event(struct divecomputer *dc, int time, int type, int flags, in
extern void add_cylinder_description(cylinder_type_t *);
extern void add_weightsystem_description(weightsystem_t *);
extern void add_people(const char *string);
extern void add_location(const char *string);
extern void add_suit(const char *string);
extern void remember_event(const char *eventname);
extern int evn_foreach(void (*callback)(const char *, int *, void *), void *data);
extern void clear_events(void);

189
info.c
View file

@ -1,189 +0,0 @@
/* info.c
*
* UI toolkit independent logic used for the info frame
*
* bool gps_changed(struct dive *dive, struct dive *master, const char *gps_text);
* void print_gps_coordinates(char *buffer, int len, int lat, int lon);
* void save_equipment_data(struct dive *dive);
* void update_equipment_data(struct dive *dive, struct dive *master);
* void update_time_depth(struct dive *dive, struct dive *edited);
* const char *get_window_title(struct dive *dive);
* char *evaluate_string_change(const char *newstring, char **textp, const char *master);
* int text_changed(const char *old, const char *new);
* bool parse_gps_text(const char *gps_text, double *latitude, double *longitude);
* int divename(char *buf, size_t size, struct dive *dive, char *trailer);
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <sys/time.h>
#include "gettext.h"
#include "dive.h"
#include "display.h"
#include "divelist.h"
/* 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;
const char *lath, *lonh;
char dbuf_lat[32], dbuf_lon[32];
if (!lat && !lon) {
*buffer = 0;
return;
}
lath = lat >= 0 ? tr("N") : tr("S");
lonh = lon >= 0 ? tr("E") : tr("W");
lat = abs(lat);
lon = abs(lon);
latdeg = lat / 1000000;
londeg = lon / 1000000;
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);
if (!*dbuf_lat || !*dbuf_lon) {
*buffer = 0;
return;
}
snprintf(buffer, len, "%s%u%s %s\' , %s%u%s %s\'",
lath, latdeg, UTF8_DEGREE, dbuf_lat,
lonh, londeg, UTF8_DEGREE, dbuf_lon);
}
/* we use these to find out if we edited the cylinder or weightsystem entries */
static cylinder_t remember_cyl[MAX_CYLINDERS];
static weightsystem_t remember_ws[MAX_WEIGHTSYSTEMS];
#define CYL_BYTES sizeof(cylinder_t) * MAX_CYLINDERS
#define WS_BYTES sizeof(weightsystem_t) * MAX_WEIGHTSYSTEMS
void save_equipment_data(struct dive *dive)
{
if (dive) {
memcpy(remember_cyl, dive->cylinder, CYL_BYTES);
memcpy(remember_ws, dive->weightsystem, WS_BYTES);
}
}
/* Empty and NULL compare equal */
static int same_string(const char *a, const char *b)
{
/* Both NULL or same */
if (a == b)
return 1;
/* Both non-NULL: strcmp */
if (a && b)
return !strcmp(a, b);
/* One non-NULL? Is that one empty? */
return !*(a ? a : b);
}
static int same_type(cylinder_t *dst, cylinder_t *src)
{
return dst->type.size.mliter == src->type.size.mliter &&
dst->type.workingpressure.mbar == src->type.workingpressure.mbar &&
same_string(dst->type.description, src->type.description);
}
static void copy_type(cylinder_t *dst, cylinder_t *src)
{
dst->type.size = src->type.size;
dst->type.workingpressure = src->type.workingpressure;
if (dst->type.description)
free((void *)dst->type.description);
if (!src->type.description || !*src->type.description)
dst->type.description = NULL;
else
dst->type.description = strdup((char *)src->type.description);
}
static int same_gasmix(cylinder_t *dst, cylinder_t *src)
{
return !memcmp(&dst->gasmix, &src->gasmix, sizeof(dst->gasmix));
}
static void copy_gasmix(cylinder_t *dst, cylinder_t *src)
{
memcpy(&dst->gasmix, &src->gasmix, sizeof(dst->gasmix));
}
static int same_press(cylinder_t *dst, cylinder_t *src)
{
return dst->start.mbar == src->start.mbar &&
dst->end.mbar == src->end.mbar;
}
static void copy_press(cylinder_t *dst, cylinder_t *src)
{
dst->start = src->start;
dst->end = src->end;
}
/*
* When we update the cylinder information, we do it individually
* by type/gasmix/pressure, so that you can change them separately.
*
* The rule is: the destination has to be the same as the original
* field, and the source has to have changed. If so, we change the
* destination field.
*/
static void update_cylinder(cylinder_t *dst, cylinder_t *src, cylinder_t *orig)
{
/* Destination type same? Change it */
if (same_type(dst, orig) && !same_type(src, orig))
copy_type(dst, src);
/* Destination gasmix same? Change it */
if (same_gasmix(dst, orig) && !same_gasmix(src, orig))
copy_gasmix(dst, src);
/* Destination pressures the same? */
if (same_press(dst, orig) && !same_press(src, orig))
copy_press(dst, src);
}
/* the editing happens on the master dive; we copy the equipment
data if it has changed in the master dive and the other dive
either has no entries for the equipment or the same entries
as the master dive had before it was edited */
void update_equipment_data(struct dive *dive, struct dive *master)
{
int i;
if (dive == master)
return;
for (i = 0; i < MAX_CYLINDERS; i++)
update_cylinder(dive->cylinder+i, master->cylinder+i, remember_cyl+i);
if (! weightsystems_equal(remember_ws, master->weightsystem) &&
(no_weightsystems(dive->weightsystem) ||
weightsystems_equal(dive->weightsystem, remember_ws)))
memcpy(dive->weightsystem, master->weightsystem, WS_BYTES);
}
/* we can simply overwrite these - this only gets called if we edited
* a single dive and the dive was first copied into edited - so we can
* just take those values */
void update_time_depth(struct dive *dive, struct dive *edited)
{
dive->when = edited->when;
dive->dc.duration.seconds = edited->dc.duration.seconds;
dive->dc.maxdepth.mm = edited->dc.maxdepth.mm;
dive->dc.meandepth.mm = edited->dc.meandepth.mm;
}
void add_people(const char *string)
{
/* add names to the completion list for people */
}
void add_location(const char *string)
{
/* add names to the completion list for locations */
}
void add_suit(const char *string)
{
/* add names to the completion list for suits */
}

28
info.h
View file

@ -1,28 +0,0 @@
/*
* info.h
*
* logic functions used from info-gtk.c
*/
#ifndef INFO_H
#define INFO_H
#ifdef __cplusplus
extern "C" {
#endif
extern bool gps_changed(struct dive *dive, struct dive *master, const char *gps_text);
extern void print_gps_coordinates(char *buffer, int len, int lat, int lon);
extern void save_equipment_data(struct dive *dive);
extern void update_equipment_data(struct dive *dive, struct dive *master);
extern void update_time_depth(struct dive *dive, struct dive *edited);
extern const char *get_window_title(struct dive *dive);
extern char *evaluate_string_change(const char *newstring, char **textp, const char *master);
extern int text_changed(const char *old, const char * /*new is a c++ keyword*/);
extern bool parse_gps_text(const char *gps_text, double *latitude, double *longitude);
extern int divename(char *buf, size_t size, struct dive *dive, char *trailer);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -8,7 +8,6 @@
#include "mainwindow.h"
#include "../helpers.h"
#include "../statistics.h"
#include "../info.h"
#include "divelistview.h"
#include "modeldelegates.h"
#include "globe.h"
@ -265,9 +264,7 @@ void MainTab::updateDiveInfo(int dive)
UPDATE_TEMP(d, airtemp);
UPDATE_TEMP(d, watertemp);
if (d) {
char buffer[256];
print_gps_coordinates(buffer, sizeof buffer, d->latitude.udeg, d->longitude.udeg);
ui.coordinates->setText(buffer);
ui.coordinates->setText(printGPSCoords(d->latitude.udeg, d->longitude.udeg));
ui.dateTimeEdit->setDateTime(QDateTime::fromTime_t(d->when - gettimezoneoffset()));
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
// only use trip relevant fields
@ -328,7 +325,7 @@ void MainTab::updateDiveInfo(int dive)
ui.airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar));
else
ui.airPressureText->clear();
ui.depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, TRUE));
ui.depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, TRUE));
ui.depthLimits->setMinimum(get_depth_string(stats_selection.min_depth, TRUE));
ui.depthLimits->setAverage(get_depth_string(stats_selection.avg_depth, TRUE));
ui.sacLimits->setMaximum(get_volume_string(stats_selection.max_sac, TRUE).append(tr("/min")));
@ -425,10 +422,7 @@ void MainTab::acceptChanges()
} else {
struct dive *curr = current_dive;
//Reset coordinates field, in case it contains garbage.
char buffer[256];
print_gps_coordinates(buffer, sizeof buffer
, current_dive->latitude.udeg, current_dive->longitude.udeg);
ui.coordinates->setText(buffer);
ui.coordinates->setText(printGPSCoords(current_dive->latitude.udeg, current_dive->longitude.udeg));
if (notesBackup[curr].buddy != ui.buddy->text() ||
notesBackup[curr].suit != ui.suit->text() ||
notesBackup[curr].notes != ui.notes->toPlainText() ||
@ -657,10 +651,7 @@ void MainTab::on_location_textChanged(const QString& text)
(dive->latitude.udeg || dive->longitude.udeg)) {
EDIT_SELECTED_DIVES( mydive->latitude = dive->latitude );
EDIT_SELECTED_DIVES( mydive->longitude = dive->longitude );
char buffer[256];
print_gps_coordinates(buffer, sizeof buffer
, dive->latitude.udeg, dive->longitude.udeg);
ui.coordinates->setText(buffer);
ui.coordinates->setText(printGPSCoords(dive->latitude.udeg, dive->longitude.udeg));
markChangedWidget(ui.coordinates);
break;
}
@ -734,3 +725,26 @@ void MainTab::editWeightWidget(const QModelIndex& index)
if (index.isValid() && index.column() != WeightModel::REMOVE)
ui.weights->edit(index);
}
QString MainTab::printGPSCoords(int lat, int lon)
{
unsigned int latdeg, londeg;
unsigned int ilatmin, ilonmin;
QString lath, lonh, result;
if (!lat && !lon)
return QString("");
lath = lat >= 0 ? tr("N") : tr("S");
lonh = lon >= 0 ? tr("E") : tr("W");
lat = abs(lat);
lon = abs(lon);
latdeg = lat / 1000000;
londeg = lon / 1000000;
ilatmin = (lat % 1000000) * 60;
ilonmin = (lon % 1000000) * 60;
result.sprintf("%s%u%s %2d.%05d\' , %s%u%s %2d.%05d\'",
lath.toLocal8Bit().data(), latdeg, UTF8_DEGREE, ilatmin / 1000000, (ilatmin % 1000000) / 10,
lonh.toLocal8Bit().data(), londeg, UTF8_DEGREE, ilonmin / 1000000, (ilonmin % 1000000) / 10);
return result;
}

View file

@ -91,7 +91,8 @@ private:
enum { NONE, DIVE, TRIP, ADD } editMode;
Completers completers;
void enableEdition();
void resetPallete();
void resetPallete();
QString printGPSCoords(int lat, int lon);
};
#endif