Example #1
0
/**
 * vu_set_auto_features_on_first_run:
 *
 *  Ask the user's opinion to set some of Viking's default behaviour
 */
void vu_set_auto_features_on_first_run ( void )
{
	gboolean auto_features = FALSE;
	gboolean set_defaults = FALSE;

	if ( a_vik_very_first_run () ) {

		GtkWidget *win = gtk_window_new ( GTK_WINDOW_TOPLEVEL );

		if ( a_dialog_yes_or_no ( GTK_WINDOW(win),
		                          _("This appears to be Viking's very first run.\n\nDo you wish to enable automatic internet features?\n\nIndividual settings can be controlled in the Preferences."), NULL ) )
			auto_features = TRUE;

		// Default to more standard cache layout for new users (well new installs at least)
		maps_layer_set_cache_default ( VIK_MAPS_CACHE_LAYOUT_OSM );
		set_defaults = TRUE;
	}

	if ( auto_features ) {
		// Set Maps to autodownload
		// Ensure the default is true
		maps_layer_set_autodownload_default ( TRUE );
		set_defaults = TRUE;

		// Simplistic repeat of preference settings
		//  Only the name & type are important for setting a preference via this 'external' way

		// Enable auto add map +
		// Enable IP lookup
		VikLayerParam pref_add_map[] = { { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "add_default_map_layer", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, NULL, VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL, NULL, NULL, NULL, NULL, }, };
		VikLayerParam pref_startup_method[] = { { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "startup_method", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, NULL, VIK_LAYER_WIDGET_COMBOBOX, NULL, NULL, NULL, NULL, NULL, NULL}, };

		VikLayerParamData vlp_data;
		vlp_data.b = TRUE;
		a_preferences_run_setparam ( vlp_data, pref_add_map );

		vlp_data.u = VIK_STARTUP_METHOD_AUTO_LOCATION;
		a_preferences_run_setparam ( vlp_data, pref_startup_method );

		// Only on Windows make checking for the latest version on by default
		// For other systems it's expected a Package manager or similar controls the installation, so leave it off
#ifdef WINDOWS
		VikLayerParam pref_startup_version_check[] = { { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "check_version", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, NULL, VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL, NULL, NULL, }, };
		vlp_data.b = TRUE;
		a_preferences_run_setparam ( vlp_data, pref_startup_version_check );
#endif

		// Ensure settings are saved for next time
		a_preferences_save_to_file ();
	}

	// Ensure defaults are saved if changed
	if ( set_defaults )
		a_layer_defaults_save ();
}
Example #2
0
static gboolean new_version_available_message ( new_version_thread_data *nvtd )
{
	// Only a simple goto website option is offered
	// Trying to do an installation update is platform specific
	if ( a_dialog_yes_or_no ( nvtd->window,
	                        _("There is a newer version of Viking available: %s\n\nDo you wish to go to Viking's website now?"), nvtd->version ) )
		// NB 'VIKING_URL' redirects to the Wiki, here we want to go the main site.
		open_url ( nvtd->window, "http://sourceforge.net/projects/viking/" );

	g_free ( nvtd->version );
	g_free ( nvtd );
	return FALSE;
}
Example #3
0
void vik_layers_panel_delete_selected ( VikLayersPanel *vlp )
{
  gint type;
  GtkTreeIter iter;
  
  if ( ! vik_treeview_get_selected_iter ( vlp->vt, &iter ) )
    /* Nothing to do */
    return;

  type = vik_treeview_item_get_type ( vlp->vt, &iter );

  if ( type == VIK_TREEVIEW_TYPE_LAYER )
  {
    // Get confirmation from the user
    if ( ! a_dialog_yes_or_no ( VIK_GTK_WINDOW_FROM_WIDGET(vlp),
				_("Are you sure you want to delete %s?"),
				vik_layer_get_name ( VIK_LAYER(vik_treeview_item_get_pointer ( vlp->vt, &iter )) ) ) )
      return;

    VikAggregateLayer *parent = vik_treeview_item_get_parent ( vlp->vt, &iter );
    if ( parent )
    {
      /* reset trigger if trigger deleted */
      if ( vik_layers_panel_get_selected ( vlp ) == vik_viewport_get_trigger ( vlp->vvp ) )
        vik_viewport_set_trigger ( vlp->vvp, NULL );

      if (IS_VIK_AGGREGATE_LAYER(parent)) {
        if ( vik_aggregate_layer_delete ( parent, &iter ) )
	  vik_layers_panel_emit_update ( vlp );
      }
    }
    else
      a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_WIDGET(vlp), _("You cannot delete the Top Layer.") );
  }
  else if (type == VIK_TREEVIEW_TYPE_SUBLAYER) {
    VikLayer *sel = vik_layers_panel_get_selected ( vlp );
    if ( vik_layer_get_interface(sel->type)->delete_item ) {
      gint subtype = vik_treeview_item_get_data( vlp->vt, &iter);
      vik_layer_get_interface(sel->type)->delete_item ( sel, subtype, vik_treeview_item_get_pointer(sel->vt, &iter) );
    }
  }
}
Example #4
0
void vik_layers_panel_clear ( VikLayersPanel *vlp )
{
  if ( (! vik_aggregate_layer_is_empty(vlp->toplayer)) && a_dialog_yes_or_no ( VIK_GTK_WINDOW_FROM_WIDGET(vlp), _("Are you sure you wish to delete all layers?"), NULL ) )
    vik_aggregate_layer_clear ( vlp->toplayer ); /* simply deletes all layers */
}
Example #5
0
/**
 * Start request for New OSM Access Token
 */
static void new_access_token_cb ( )
{
  GtkWindow *parent = GTK_WINDOW(a_vik_window_get_a_window());

  const gchar *access_token_key_pref = a_preferences_get(OSM_ACCESS_TOKEN_KEY)->s;
  const gchar *access_token_secret_pref = a_preferences_get(OSM_ACCESS_TOKEN_SECRET)->s;
  if ( access_token_key_pref && access_token_secret_pref &&
       strlen(access_token_key_pref) > 1 && strlen(access_token_secret_pref) > 1 ) {

    // Check to really override existing values...
    if ( !a_dialog_yes_or_no(parent, _("Do you want to overwrite existing values?"), NULL) )
      return;
  }

  gchar *request_key = NULL;
  gchar *request_secret = NULL;
  // Request
  gint grt = get_request_tokens ( &request_key, &request_secret );
  if ( grt != 0 )
     g_warning ( "get_request_tokens() returned %d", grt );

  if ( !request_key || !request_secret ) {
    a_dialog_error_msg ( parent, _("Not able to generate OSM request tokens.") );
    return;
  }

  // JOSM uses some kind of Out of Bound 'OOB' method which doesn't direct the user to the webpage.
  // However I'm unclear how this works at a low level
  // it's possible that liboauth doesn't support this 1.0A feature anyway

  // Auto authorize if possible...
  // gboolean authorized = liboauth_authorize_url ( request_key );
  // if ( !authorized ) {
  //   msg();
  //   return;
  // }

  // So for now just direct user to OSM website (you will have to enter credentials there & grant permissions)
  gchar *authorize_url = get_authorize_url ( request_key );
  g_debug ( "%s:%s", __FUNCTION__, authorize_url );
  if ( authorize_url ) {
    gtk_show_uri ( gdk_screen_get_default(), authorize_url, GDK_CURRENT_TIME, NULL );
  }
  g_free ( authorize_url );

  GtkWidget *dialog = gtk_message_dialog_new ( parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK_CANCEL,
					       _("Waiting for authorization approval.\nEnsure you have granted access at the website before continuing here."));
  gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT );
  if ( gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK ) {
      gtk_widget_destroy ( dialog );
      return;
  }
  gtk_widget_destroy ( dialog );

  gchar *access_token_key = NULL;
  gchar *access_token_secret = NULL;

  gint gnat = get_new_access_tokens ( request_key, request_secret, &access_token_key, &access_token_secret );
  if ( gnat != 0 )
     g_warning ( "get_new_access_tokens() returned %d", gnat );

  if ( !access_token_key || !access_token_key ) {
    a_dialog_error_msg ( parent, _("No Authorization.") );
    return;
  }

  // Save the values
  VikLayerParamData vlp_data;
  VikLayerParam *pref_key = a_preferences_get_param ( OSM_ACCESS_TOKEN_KEY );
  VikLayerParam *pref_secret = a_preferences_get_param ( OSM_ACCESS_TOKEN_SECRET );
  if ( !pref_key || !pref_secret ) {
    g_critical ("%s: preference not found", __FUNCTION__);
    return;
  }

  // Unfortunately since the callback mechanism in preferences only allows a function call with no parameters
  //  we have no way of accessing the dialog to effect any updates, other than closing it
  a_uibuilder_factory_close ( GTK_RESPONSE_REJECT );
  // Note since we are in an event handler already, using GTK_RESPONSE_ACCEPT means this signal
  //  is processed after this current function finishes.
  // This then in turn means it would save the values from the dialog,
  //  overwriting the values set here :(
  // The current side effect is that any other preferences the user has modified in the dialog are lost

  // Now apply the new values
  vlp_data.s = access_token_key;
  a_preferences_run_setparam ( vlp_data, pref_key );
  vlp_data.s = access_token_secret;
  a_preferences_run_setparam ( vlp_data, pref_secret );

  a_preferences_save_to_file ();

  g_free ( access_token_key );
  g_free ( access_token_secret );

  // On success mention can remove username/password if they already exist
  VikLayerParamData *pref_user = a_preferences_get ( OSM_USERNAME );
  VikLayerParamData *pref_pwd = a_preferences_get ( OSM_PASSWORD );

  if ( pref_user && pref_pwd &&
       pref_user->s && pref_pwd->s && strlen(pref_user->s) > 1 ) {
    a_dialog_info_msg ( parent, _("OSM Username and Password preferences are not required anymore. You can now remove them.") );
    return;
  }
}