+
+static VikLayerParam prefs[] = {
+ { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_IO_NAMESPACE "gpsbabel", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("GPSBabel:"), VIK_LAYER_WIDGET_FILEENTRY, NULL, NULL,
+ N_("Allow setting the specific instance of GPSBabel. You must restart Viking for this value to take effect."), NULL, NULL, NULL },
+};
+
+/**
+ * a_babel_init:
+ *
+ * Just setup preferences first
+ */
+void a_babel_init ()
+{
+ // Set the defaults
+ VikLayerParamData vlpd;
+#ifdef WINDOWS
+ // Basic guesses - could use %ProgramFiles% but this is simpler:
+ if ( g_file_test ( "C:\\Program Files (x86)\\GPSBabel\\gpsbabel.exe", G_FILE_TEST_EXISTS ) )
+ // 32 bit location on a 64 bit system
+ vlpd.s = "C:\\Program Files (x86)\\GPSBabel\\gpsbabel.exe";
+ else
+ vlpd.s = "C:\\Program Files\\GPSBabel\\gpsbabel.exe";
+#else
+ vlpd.s = "gpsbabel";
+#endif
+ a_preferences_register(&prefs[0], vlpd, VIKING_PREFERENCES_IO_GROUP_KEY);
+}
+
+/**
+ * a_babel_post_init:
+ *
+ * Initialises babel module.
+ * Mainly check existence of gpsbabel progam
+ * and load all features available in that version.
+ */
+void a_babel_post_init ()
+{
+ // Read the current preference
+ const gchar *gpsbabel = a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "gpsbabel")->s;
+ // If setting is still the UNIX default then lookup in the path - otherwise attempt to use the specified value directly.
+ if ( g_strcmp0 ( gpsbabel, "gpsbabel" ) == 0 ) {
+ gpsbabel_loc = g_find_program_in_path( "gpsbabel" );
+ if ( !gpsbabel_loc )
+ g_critical( "gpsbabel not found in PATH" );
+ }
+ else
+ gpsbabel_loc = (gchar*)gpsbabel;
+
+ // Unlikely to package unbuffer on Windows so ATM don't even bother trying
+ // Highly unlikely unbuffer is available on a Windows system otherwise
+#ifndef WINDOWS
+ unbuffer_loc = g_find_program_in_path( "unbuffer" );
+ if ( !unbuffer_loc )
+ g_warning( "unbuffer not found in PATH" );
+#endif
+
+ load_feature ();
+}
+
+/**
+ * a_babel_uninit:
+ *
+ * Free resources acquired by a_babel_init.
+ */
+void a_babel_uninit ()
+{
+ g_free ( gpsbabel_loc );
+ g_free ( unbuffer_loc );
+
+ if ( a_babel_file_list ) {
+ GList *gl;
+ for (gl = a_babel_file_list; gl != NULL; gl = g_list_next(gl)) {
+ BabelFile *file = gl->data;
+ g_free ( file->name );
+ g_free ( file->ext );
+ g_free ( file->label );
+ g_free ( gl->data );
+ }
+ g_list_free ( a_babel_file_list );
+ }
+
+ if ( a_babel_device_list ) {
+ GList *gl;
+ for (gl = a_babel_device_list; gl != NULL; gl = g_list_next(gl)) {
+ BabelDevice *device = gl->data;
+ g_free ( device->name );
+ g_free ( device->label );
+ g_free ( gl->data );
+ }
+ g_list_free ( a_babel_device_list );
+ }
+
+}
+
+/**
+ * a_babel_available:
+ *
+ * Indicates if babel is available or not.
+ *
+ * Returns: true if babel available
+ */
+gboolean a_babel_available ()
+{
+ return a_babel_device_list != NULL;
+}