1
by Joshua Judson Rosen
Imported from tangogps-0.9.7 tarball. |
1 |
#ifdef HAVE_CONFIG_H
|
2 |
# include <config.h>
|
|
3 |
#endif
|
|
4 |
||
5 |
#include <stdlib.h> |
|
6 |
#include <locale.h> |
|
7 |
#include <string.h> |
|
305
by Paul Wise
Remove trailing whitespace |
8 |
#include <gtk/gtk.h> |
133.1.8
by Joshua Judson Rosen
Support the standard "--version" command-line flag. |
9 |
|
1
by Joshua Judson Rosen
Imported from tangogps-0.9.7 tarball. |
10 |
#include <glade/glade.h> |
11 |
||
12 |
#include "interface.h" |
|
13 |
#include "support.h" |
|
24.3.5
by Joshua Judson Rosen
Load the main window (`window1') with libglade rather than using create_window1() from interface.c. |
14 |
#include "init.h" |
15 |
#include "callbacks.h" |
|
1
by Joshua Judson Rosen
Imported from tangogps-0.9.7 tarball. |
16 |
#include "globals.h" |
17 |
#include "wp.h" |
|
18 |
#include "poi.h" |
|
19 |
#include "converter.h" |
|
20 |
#include "map_management.h" |
|
314
by Pavel Machek
Add --lat/--lon options for setting waypoint from the command-line. |
21 |
|
22 |
int
|
|
23 |
main (int argc, char *argv[]) |
|
24 |
{
|
|
1
by Joshua Judson Rosen
Imported from tangogps-0.9.7 tarball. |
25 |
GError *error = NULL; |
26 |
||
27 |
gboolean fullscreen = FALSE; |
|
28 |
gboolean show_version = FALSE; |
|
26.1.1
by Joshua Judson Rosen
Use GLib for command-line option-parsing, rather than rolling our own. |
29 |
char * waypoint_lat = NULL; |
30 |
char * waypoint_lon = NULL; |
|
31 |
||
133.1.8
by Joshua Judson Rosen
Support the standard "--version" command-line flag. |
32 |
GOptionEntry cmd_options[] = |
314
by Pavel Machek
Add --lat/--lon options for setting waypoint from the command-line. |
33 |
{
|
34 |
{"version", 0, 0, G_OPTION_ARG_NONE, &show_version, |
|
26.1.1
by Joshua Judson Rosen
Use GLib for command-line option-parsing, rather than rolling our own. |
35 |
N_("Print the program version and exit"), NULL}, |
36 |
{"fullscreen", 0, 0, G_OPTION_ARG_NONE, &fullscreen, |
|
37 |
N_("Start in fullscreen mode"), NULL}, |
|
133.1.8
by Joshua Judson Rosen
Support the standard "--version" command-line flag. |
38 |
{"gui", 0, 0, G_OPTION_ARG_FILENAME, &gladefile, |
159
by Joshua Judson Rosen
Mark (most?) strings that should be marked as translatable. |
39 |
N_("Load the GUI from this GladeXML file"), "GLADEFILE"}, |
26.1.1
by Joshua Judson Rosen
Use GLib for command-line option-parsing, rather than rolling our own. |
40 |
{"lat", 0, 0, G_OPTION_ARG_STRING, &waypoint_lat, |
159
by Joshua Judson Rosen
Mark (most?) strings that should be marked as translatable. |
41 |
N_("Select waypoint's latitude"), "LAT"}, |
24.3.25
by Joshua Judson Rosen
Added a "--gui=" command option that can be used to specify a GladeXML file at startup. |
42 |
{"lon", 0, 0, G_OPTION_ARG_STRING, &waypoint_lon, |
159
by Joshua Judson Rosen
Mark (most?) strings that should be marked as translatable. |
43 |
N_("Select waypoint's longitude"), "LON"}, |
314
by Pavel Machek
Add --lat/--lon options for setting waypoint from the command-line. |
44 |
{NULL} |
45 |
};
|
|
46 |
||
47 |
GOptionContext *option_context = |
|
306
by Paul Wise
Consistently use tabs for indentation and spaces for alignment |
48 |
g_option_context_new ("\n\nA friendly GPS & mapping " |
26.1.1
by Joshua Judson Rosen
Use GLib for command-line option-parsing, rather than rolling our own. |
49 |
"application."); |
50 |
||
51 |
g_option_context_add_group (option_context, |
|
218.1.2
by Joshua Judson Rosen
Autogenerate a basically-useful man page. |
52 |
gtk_get_option_group (TRUE)); |
26.1.1
by Joshua Judson Rosen
Use GLib for command-line option-parsing, rather than rolling our own. |
53 |
|
54 |
g_option_context_add_main_entries (option_context, |
|
55 |
cmd_options, |
|
56 |
#ifdef ENABLE_NLS
|
|
57 |
GETTEXT_PACKAGE
|
|
58 |
#else
|
|
59 |
NULL
|
|
60 |
#endif
|
|
61 |
);
|
|
62 |
||
63 |
#ifdef ENABLE_NLS
|
|
64 |
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); |
|
65 |
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
|
66 |
textdomain (GETTEXT_PACKAGE); |
|
1
by Joshua Judson Rosen
Imported from tangogps-0.9.7 tarball. |
67 |
#endif
|
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
68 |
|
69 |
gtk_set_locale (); |
|
70 |
||
1
by Joshua Judson Rosen
Imported from tangogps-0.9.7 tarball. |
71 |
if (!g_option_context_parse (option_context, &argc, &argv, &error)) |
72 |
{
|
|
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
73 |
g_print (_("option parsing failed: %s\n"), error->message); |
305
by Paul Wise
Remove trailing whitespace |
74 |
return 1; |
26.1.1
by Joshua Judson Rosen
Use GLib for command-line option-parsing, rather than rolling our own. |
75 |
}
|
76 |
||
159
by Joshua Judson Rosen
Mark (most?) strings that should be marked as translatable. |
77 |
if (show_version) |
26.1.1
by Joshua Judson Rosen
Use GLib for command-line option-parsing, rather than rolling our own. |
78 |
{
|
79 |
g_print ("%s %s\n", _(PACKAGE_NAME), _(PACKAGE_VERSION)); |
|
133.1.8
by Joshua Judson Rosen
Support the standard "--version" command-line flag. |
80 |
exit (0); |
81 |
}
|
|
82 |
||
83 |
/* g_thread_init is deprecated since version 2.32 and is no longer
|
|
84 |
* necessary. https://developer.gnome.org/glib/2.34/glib-Deprecated-Thread-APIs.html#g-thread-init
|
|
85 |
* For more on GLIB_CHECK_VERSION, see
|
|
305
by Paul Wise
Remove trailing whitespace |
86 |
* https://developer.gnome.org/glib/stable/glib-Version-Information.html#GLIB-CHECK-VERSION:CAPS */
|
315
by Charles Curley
Use current glib thread functions when available |
87 |
#if ! GLIB_CHECK_VERSION(2,32,0)
|
88 |
if (!g_thread_supported ()) |
|
89 |
g_thread_init (NULL); |
|
90 |
#endif
|
|
91 |
gdk_threads_init (); |
|
133.1.9
by Joshua Judson Rosen
Delay initialisation of GTK+ until after option-processing. |
92 |
gdk_threads_enter (); |
93 |
gtk_init (&argc, &argv); |
|
315
by Charles Curley
Use current glib thread functions when available |
94 |
|
133.1.9
by Joshua Judson Rosen
Delay initialisation of GTK+ until after option-processing. |
95 |
setlocale (LC_NUMERIC, "C"); |
237
by Joshua Judson Rosen
Wrap the GTK+ init/mainloop sequence in gdk_threads_enter()/gdk_threads_leave(). |
96 |
|
133.1.9
by Joshua Judson Rosen
Delay initialisation of GTK+ until after option-processing. |
97 |
add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); |
98 |
||
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
99 |
|
305
by Paul Wise
Remove trailing whitespace |
100 |
glade_init (); |
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
101 |
|
305
by Paul Wise
Remove trailing whitespace |
102 |
gladexml = glade_xml_new (gladefile, NULL, GETTEXT_PACKAGE); |
103 |
||
306
by Paul Wise
Consistently use tabs for indentation and spaces for alignment |
104 |
if (!gladexml) |
24.3.22
by Joshua Judson Rosen
Fail with clear intent and explanation if we can't loud our GUI-definition. |
105 |
{
|
306
by Paul Wise
Consistently use tabs for indentation and spaces for alignment |
106 |
/* Developers may run into this if they're naively
|
24.3.22
by Joshua Judson Rosen
Fail with clear intent and explanation if we can't loud our GUI-definition. |
107 |
trying to run from the build-tree without having
|
108 |
specifically configured the build to allow that or
|
|
109 |
having passed a "--gui=..." option to the program,
|
|
110 |
so we need to actually catch this error and output
|
|
111 |
an informative message.
|
|
24.3.25
by Joshua Judson Rosen
Added a "--gui=" command option that can be used to specify a GladeXML file at startup. |
112 |
|
113 |
This is, however, not an error that end users should face;
|
|
24.3.22
by Joshua Judson Rosen
Fail with clear intent and explanation if we can't loud our GUI-definition. |
114 |
if they do, then someone upstream from them messed up--
|
115 |
either `make install' worked only half-way, or a packager
|
|
116 |
left something critical out of the package. In either case,
|
|
117 |
we want to fail in a way that indicates to the user
|
|
118 |
that something is really wrong and they should report
|
|
119 |
a bug.
|
|
120 |
*/
|
|
121 |
||
122 |
g_error (_("%s could not load its user interface; " |
|
123 |
"%s does not not appear to be properly installed."), |
|
124 |
PACKAGE, PACKAGE); |
|
125 |
}
|
|
126 |
||
127 |
glade_xml_signal_autoconnect (gladexml); |
|
128 |
||
129 |
pre_init(); |
|
130 |
window1 = glade_xml_get_widget (gladexml, "window1"); |
|
306
by Paul Wise
Consistently use tabs for indentation and spaces for alignment |
131 |
char *window_title = |
24.3.5
by Joshua Judson Rosen
Load the main window (`window1') with libglade rather than using create_window1() from interface.c. |
132 |
g_strdup_printf (gtk_window_get_title (GTK_WINDOW (window1)), |
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
133 |
_(PACKAGE_NAME)); |
24.3.5
by Joshua Judson Rosen
Load the main window (`window1') with libglade rather than using create_window1() from interface.c. |
134 |
gtk_window_set_title (GTK_WINDOW (window1), window_title); |
126.1.2
by Joshua Judson Rosen
Actually, let's just substitute the (translated) package-name and -version into the GUI at runtime. |
135 |
g_free (window_title); window_title = NULL; |
136 |
||
137 |
||
138 |
int screen_height, screen_width; |
|
139 |
GtkWidget *toolbar; |
|
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
140 |
|
305
by Paul Wise
Remove trailing whitespace |
141 |
screen_height = gdk_screen_get_height(gdk_screen_get_default()); |
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
142 |
screen_width = gdk_screen_get_width (gdk_screen_get_default()); |
306
by Paul Wise
Consistently use tabs for indentation and spaces for alignment |
143 |
|
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
144 |
if (screen_height > screen_width) |
306
by Paul Wise
Consistently use tabs for indentation and spaces for alignment |
145 |
{
|
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
146 |
toolbar = lookup_widget(window1, "toolbar1"); |
305
by Paul Wise
Remove trailing whitespace |
147 |
global_landscape = FALSE; |
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
148 |
}
|
149 |
else { |
|
150 |
toolbar = lookup_widget(window1, "toolbar4"); |
|
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
151 |
global_landscape = TRUE; |
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
152 |
}
|
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
153 |
gtk_widget_show(toolbar); |
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
154 |
|
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
155 |
|
156 |
if(screen_height < 640 && screen_height > screen_width) |
|
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
157 |
{
|
305
by Paul Wise
Remove trailing whitespace |
158 |
gtk_window_resize(GTK_WINDOW(window1), |
159 |
(screen_width < 480) ? screen_width : 480, |
|
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
160 |
screen_height-30); |
161 |
}
|
|
305
by Paul Wise
Remove trailing whitespace |
162 |
else if(screen_height < 640 && screen_width <= 1024 && screen_height < screen_width) |
163 |
{
|
|
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
164 |
gtk_window_resize(GTK_WINDOW(window1), |
165 |
(screen_width < 480) ? screen_width : 480, |
|
166 |
screen_height-60); |
|
167 |
}
|
|
305
by Paul Wise
Remove trailing whitespace |
168 |
|
169 |
GtkWidget *hbox; |
|
170 |
hbox = lookup_widget(window1, "hbox49a"); |
|
2
by Joshua Judson Rosen
Updates from tangogps-0.9.8 ("connecting people") tarball. |
171 |
global_infopane_widgets = gtk_container_get_children(GTK_CONTAINER(hbox)); |
305
by Paul Wise
Remove trailing whitespace |
172 |
|
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
173 |
GtkWidget *version_label; |
174 |
char *package_string; |
|
175 |
version_label = lookup_widget(window1, "label117"); |
|
176 |
package_string = g_strdup_printf |
|
126.1.2
by Joshua Judson Rosen
Actually, let's just substitute the (translated) package-name and -version into the GUI at runtime. |
177 |
(gtk_label_get_label (GTK_LABEL (version_label)), |
178 |
_(PACKAGE_NAME), _(PACKAGE_VERSION)); |
|
179 |
gtk_label_set_label (GTK_LABEL (version_label), package_string); |
|
180 |
g_free (package_string); package_string = NULL; |
|
181 |
||
182 |
gtk_widget_show (window1); |
|
183 |
||
184 |
if (fullscreen) |
|
305
by Paul Wise
Remove trailing whitespace |
185 |
{
|
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
186 |
GtkToggleToolButton *toggle; |
305
by Paul Wise
Remove trailing whitespace |
187 |
|
26.1.1
by Joshua Judson Rosen
Use GLib for command-line option-parsing, rather than rolling our own. |
188 |
toggle = GTK_TOGGLE_TOOL_BUTTON (lookup_widget (window1, |
189 |
"button1")); |
|
193
by Joshua Judson Rosen
Make the `fullscreen' button into a toggle |
190 |
gtk_toggle_tool_button_set_active(toggle, TRUE); |
191 |
||
192 |
toggle = GTK_TOGGLE_TOOL_BUTTON (lookup_widget (window1, |
|
193 |
"button53")); |
|
194 |
gtk_toggle_tool_button_set_active(toggle, TRUE); |
|
195 |
}
|
|
196 |
||
197 |
window2 = glade_xml_get_widget (gladexml, "window2"); |
|
198 |
window3 = glade_xml_get_widget (gladexml, "window3"); |
|
26.1.1
by Joshua Judson Rosen
Use GLib for command-line option-parsing, rather than rolling our own. |
199 |
menu1 = glade_xml_get_widget (gladexml, "menu1"); |
200 |
route_menu = glade_xml_get_widget (gladexml, "route_menu"); |
|
24.3.26
by Joshua Judson Rosen
Recreated `GPS Info' dialogue in GladeXML, replacing create_window2(). |
201 |
|
24.3.54
by Joshua Judson Rosen
Recreated `Geo Photo' popup preview-window, replacing create_window3(). |
202 |
#ifdef ENABLE_HRM
|
24.3.9
by Joshua Judson Rosen
Load the main window's popup menu with libglade rather than using create_menu1(). |
203 |
gtk_widget_show (glade_xml_get_widget (gladexml, "frame15")); |
208.1.4
by Dr. Tilmann Bubeck
Add route-planning functionality |
204 |
#else
|
133.2.10
by Joshua Judson Rosen
Hide HRM-related GUI elements unless we actually have HRM-support enabled. |
205 |
/* It looks like we can't hide widgets attached to a grid,
|
206 |
so the next best thing is to just `null them out':
|
|
207 |
*/
|
|
208 |
gtk_label_set_label (glade_xml_get_widget (gladexml, "label205"), ""); |
|
209 |
gtk_label_set_label (glade_xml_get_widget (gladexml, "label206"), ""); |
|
306
by Paul Wise
Consistently use tabs for indentation and spaces for alignment |
210 |
gtk_label_set_label (glade_xml_get_widget (gladexml, "label207"), ""); |
211 |
#endif
|
|
133.2.10
by Joshua Judson Rosen
Hide HRM-related GUI elements unless we actually have HRM-support enabled. |
212 |
|
213 |
init(); |
|
214 |
||
215 |
if (waypoint_lat && waypoint_lon) |
|
305
by Paul Wise
Remove trailing whitespace |
216 |
{
|
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
217 |
double lat = deg2rad(parse_degrees(waypoint_lat)); |
305
by Paul Wise
Remove trailing whitespace |
218 |
double lon = deg2rad(parse_degrees(waypoint_lon)); |
314
by Pavel Machek
Add --lat/--lon options for setting waypoint from the command-line. |
219 |
|
220 |
set_current_wp(lat, lon); |
|
221 |
}
|
|
222 |
||
223 |
gtk_main (); |
|
224 |
||
225 |
gdk_threads_leave (); |
|
226 |
||
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
227 |
return 0; |
6.1.1
by Marcus Bauer
Removed superfluous locking of the GUI in main(). |
228 |
}
|
237
by Joshua Judson Rosen
Wrap the GTK+ init/mainloop sequence in gdk_threads_enter()/gdk_threads_leave(). |
229 |
|
305
by Paul Wise
Remove trailing whitespace |
230 |
|
4
by Joshua Judson Rosen
Updates from tangogps-0.99.1 ("lots of layout love") tarball. |
231 |
|
1
by Joshua Judson Rosen
Imported from tangogps-0.9.7 tarball. |
232 |