/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* Viking - GPS data editor
- * Copyright (C) 2007, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
* Copyright (C) 2014, Rob Norris <rw_norris@hotmail.com>
+ * Copyright 2006-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
+ * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
+ * Copyright 2011-2012 Matthew Brush <mbrush(at)codebrainz(dot)ca>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "util.h"
#include "dialog.h"
+#include "settings.h"
#ifdef WINDOWS
#include <windows.h>
#endif
-/*
+
#ifndef WINDOWS
static gboolean spawn_command_line_async(const gchar * cmd,
const gchar * arg)
return status;
}
#endif
-*/
+
// Annoyingly gtk_show_uri() doesn't work so resort to ShellExecute method
// (non working at least in our Windows build with GTK+2.24.10 on Windows 7)
#ifdef WINDOWS
ShellExecute(NULL, NULL, (char *) url, NULL, ".\\", 0);
#else
- GError *error = NULL;
- gtk_show_uri ( gtk_widget_get_screen (GTK_WIDGET(parent)), url, GDK_CURRENT_TIME, &error );
- if ( error ) {
- a_dialog_error_msg_extra ( parent, _("Could not launch web browser. %s"), error->message );
- g_error_free ( error );
+ gboolean use_browser = FALSE;
+ if ( a_settings_get_boolean ( "use_env_browser", &use_browser ) ) {
+ const gchar *browser = g_getenv("BROWSER");
+ if (browser == NULL || browser[0] == '\0') {
+ browser = "firefox";
+ }
+ if (spawn_command_line_async(browser, url)) {
+ return;
+ }
+ else
+ g_warning("Failed to run: %s on %s", browser, url);
+ }
+ else {
+ GError *error = NULL;
+ gtk_show_uri ( gtk_widget_get_screen (GTK_WIDGET(parent)), url, GDK_CURRENT_TIME, &error );
+ if ( error ) {
+ a_dialog_error_msg_extra ( parent, _("Could not launch web browser. %s"), error->message );
+ g_error_free ( error );
+ }
}
#endif
}
for (iii = 0; iii < width; iii++) for (jjj = 0; jjj < height; jjj++)
{
pixels += 3;
- *pixels++ = alpha;
+ if ( *pixels != 0 )
+ *pixels = alpha;
+ pixels++;
}
return pixbuf;
}
for (iii = 0; iii < width; iii++) for (jjj = 0; jjj < height; jjj++)
{
pixels += 3;
- *pixels = (guint8)(((guint16)*pixels * (guint16)alpha) / 255);
+ if ( *pixels != 0 )
+ *pixels = (guint8)(((guint16)*pixels * (guint16)alpha) / 255);
pixels++;
}
return pixbuf;
g_free (uri);
}
}
+
+/**
+ * Clear the entry text if the specified icon is pressed
+ */
+static void ui_icon_clear_entry ( GtkEntry *entry,
+ GtkEntryIconPosition position,
+ GdkEventButton *event,
+ gpointer data )
+{
+ if ( position == GPOINTER_TO_INT(data) )
+ gtk_entry_set_text ( entry, "" );
+}
+
+static void
+text_changed_cb (GtkEntry *entry,
+ GParamSpec *pspec,
+ gpointer data)
+{
+ if ( data ) {
+ gboolean has_text = gtk_entry_get_text_length(entry) > 0;
+ gtk_entry_set_icon_sensitive ( entry, GPOINTER_TO_INT(data), has_text );
+ }
+}
+
+/**
+ * Create an entry field with an icon to clear the entry
+ *
+ * Ideal for entries used for getting user entered transitory data,
+ * so it is easy to delete the text and start again.
+ */
+GtkWidget *ui_entry_new ( const gchar *str, GtkEntryIconPosition position )
+{
+ GtkWidget *entry = gtk_entry_new();
+ if ( str )
+ gtk_entry_set_text ( GTK_ENTRY(entry), str );
+ gtk_entry_set_icon_from_stock ( GTK_ENTRY(entry), position, GTK_STOCK_CLEAR );
+#if GTK_CHECK_VERSION (2,20,0)
+ text_changed_cb ( GTK_ENTRY(entry), NULL, GINT_TO_POINTER(position) );
+ g_signal_connect ( entry, "notify::text", G_CALLBACK(text_changed_cb), GINT_TO_POINTER(position) );
+#endif
+ g_signal_connect ( entry, "icon-release", G_CALLBACK(ui_icon_clear_entry), GINT_TO_POINTER(position) );
+ return entry;
+}
+
+/**
+ * Create a spinbutton with an icon to clear the entry
+ *
+ * Ideal for entries used for getting user entered transitory data,
+ * so it is easy to delete the number and start again.
+ */
+GtkWidget *ui_spin_button_new ( GtkAdjustment *adjustment,
+ gdouble climb_rate,
+ guint digits )
+{
+ GtkWidget *spin = gtk_spin_button_new ( adjustment, climb_rate, digits );
+ gtk_entry_set_icon_from_stock ( GTK_ENTRY(spin), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_CLEAR );
+ g_signal_connect ( spin, "icon-release", G_CALLBACK(ui_icon_clear_entry), GINT_TO_POINTER(GTK_ENTRY_ICON_PRIMARY) );
+ return spin;
+}