Beispiel #1
0
static gchar *facebook_get_user_auth_token_from_url(dt_storage_facebook_gui_data_t *ui)
{
  ///////////// open the authentication url in a browser. just use some port, we won't listen anyway
  if(!_open_browser("http://localhost:8123/" FB_CALLBACK_ID)) return NULL;

  ////////////// build & show the validation dialog
  gchar *text1 = _("step 1: a new window or tab of your browser should have been "
                   "loaded. you have to login into your facebook account there "
                   "and authorize darktable to upload photos before continuing.");
  gchar *text2 = _("step 2: paste your browser URL and click the OK button once "
                   "you are done.");

  GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
  GtkDialog *fb_auth_dialog = GTK_DIALOG(
      gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION,
                             GTK_BUTTONS_OK_CANCEL, _("facebook authentication")));
  gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(fb_auth_dialog), "%s\n\n%s", text1, text2);

  GtkWidget *entry = gtk_entry_new();
  GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(gtk_label_new(_("URL:"))), FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry), TRUE, TRUE, 0);

  GtkWidget *fbauthdialog_vbox = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(fb_auth_dialog));
  gtk_box_pack_end(GTK_BOX(fbauthdialog_vbox), hbox, TRUE, TRUE, 0);

  gtk_widget_show_all(GTK_WIDGET(fb_auth_dialog));

  ////////////// wait for the user to enter the validation URL
  gint result;
  gchar *token = NULL;
  const char *replyurl;
  while(TRUE)
  {
    result = gtk_dialog_run(GTK_DIALOG(fb_auth_dialog));
    if(result == GTK_RESPONSE_CANCEL) break;
    replyurl = gtk_entry_get_text(GTK_ENTRY(entry));
    if(replyurl == NULL || g_strcmp0(replyurl, "") == 0)
    {
      gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(fb_auth_dialog),
                                                 "%s\n\n%s\n\n<span foreground=\"" MSGCOLOR_RED
                                                 "\" ><small>%s</small></span>",
                                                 text1, text2, _("please enter the validation URL"));
      continue;
    }
    token = fb_extract_token_from_url(replyurl);
    if(token != NULL) // we have a valid token
      break;
    else
      gtk_message_dialog_format_secondary_markup(
          GTK_MESSAGE_DIALOG(fb_auth_dialog),
          "%s\n\n%s%s\n\n<span foreground=\"" MSGCOLOR_RED "\"><small>%s</small></span>", text1, text2,
          _("the given URL is not valid, it should look like: "),
          FB_WS_BASE_URL "connect/login_success.html?...");
  }
  gtk_widget_destroy(GTK_WIDGET(fb_auth_dialog));

  return token;
}
Beispiel #2
0
/*
 * Modal dialog with yes or no buttons. 
 * Varargs allows the secondary to have printf style varargs. 
 * Returns UIDIALOG_YES (True or 1) or UIDIALOG_NO (False or 0) 
 */
int uidialog_yes_or_no (char *parent_window_name,
			char *primary_text, 
			char *secondary_text, ... /* varagrs */) {

     GtkWidget *askw, *parent_win;

     parent_win = get_widget(parent_window_name);

     askw = gtk_message_dialog_new(GTK_WINDOW(parent_win),
				   GTK_DIALOG_MODAL | 
				   GTK_DIALOG_DESTROY_WITH_PARENT,
				   GTK_MESSAGE_QUESTION,
				   GTK_BUTTONS_YES_NO,
				   primary_text, NULL);

     va_list ap;
     va_start(ap, secondary_text);
     gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(askw),
						secondary_text, ap);
     va_end(ap);
 
     gint result = gtk_dialog_run(GTK_DIALOG(askw));
     gtk_widget_destroy(askw);

     switch (result) {
     case GTK_RESPONSE_YES:
          return UIDIALOG_YES;
     default:
          return UIDIALOG_NO;
     }

     return UIDIALOG_NO;
}
Beispiel #3
0
// NOTE: this is used from 'mscorlib.dll' System.IO.IsolatedStorage/MoonIsolatedStorageFile.cs
// NOTE: we let the caller supply the string so i18n can occur in managed land only
gboolean
isolated_storage_increase_quota_to (const char *primary_text, const char* secondary_text)
{
#if PAL_GTK_WINDOWING
	// the dialog is displayed only if the action leading to this call was initiated directly from the user
	if (!Deployment::GetCurrent ()->GetSurface ()->IsUserInitiatedEvent ())
		return false;

	Surface *surface = Deployment::GetCurrent ()->GetSurface ();

	GtkWidget *widget = gtk_message_dialog_new_with_markup (NULL,
						GTK_DIALOG_MODAL,
						GTK_MESSAGE_QUESTION,
						GTK_BUTTONS_YES_NO,
						primary_text);

	gtk_window_set_title (GTK_WINDOW (widget), PACKAGE_STRING);
	gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (widget), secondary_text);

	gboolean result = (gtk_dialog_run (GTK_DIALOG (widget)) == GTK_RESPONSE_YES);
	surface->SetCurrentDeployment ();
	gtk_widget_destroy (widget);
	return result;
#else
	return TRUE;
#endif
}
Beispiel #4
0
static void
show_error (const gchar *format, ...)
{
  va_list var_args;
  gchar *s;

  va_start (var_args, format);

  s = g_strdup_vprintf (format, var_args);

  if (have_gtk)
    {
      GtkWidget *dialog;
      dialog = gtk_message_dialog_new_with_markup (NULL,
                                                   GTK_DIALOG_MODAL,
                                                   GTK_MESSAGE_ERROR,
                                                   GTK_BUTTONS_CLOSE,
                                                   "<big><b>%s</b></big>",
                                                   _("An error occurred"));
      gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog), "%s", s);
      gtk_window_set_title (GTK_WINDOW (dialog), _("Disk Image Mounter"));
      gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);
    }
  else
    {
      g_printerr ("%s\n", s);
    }

  g_free (s);
  va_end (var_args);
}
Beispiel #5
0
void
vino_util_show_error (const gchar *title, const gchar *message, GtkWindow *parent)
{
  GtkWidget *d;
  gchar     *t;

  if (title)
    t = g_strdup (title);
  else
    t = g_strdup (_("An error has occurred:"));

  d = gtk_message_dialog_new (parent,
			      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
			      GTK_MESSAGE_ERROR,
			      GTK_BUTTONS_CLOSE,
			      "%s",
			      t);
  g_free (t);

  if (message)
    gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (d),
					      "%s",
					      message);

  g_signal_connect_swapped (d,
			    "response", 
			    G_CALLBACK (gtk_widget_destroy),
			    d);
  gtk_widget_show_all (GTK_WIDGET(d));
}
JNIEXPORT void JNICALL
Java_org_gnome_gtk_GtkMessageDialog_gtk_1message_1dialog_1format_1secondary_1markup
(
	JNIEnv* env,
	jclass cls,
	jlong _self,
	jstring _messageFormat
)
{
	GtkMessageDialog* self;
	const gchar* messageFormat;

	// convert parameter self
	self = (GtkMessageDialog*) _self;

	// convert parameter messageFormat
	messageFormat = (const gchar*) bindings_java_getString(env, _messageFormat);
	if (messageFormat == NULL) {
		return; // Java Exception already thrown
	}

	// call function
	gtk_message_dialog_format_secondary_markup(self, messageFormat, NULL);

	// cleanup parameter self

	// cleanup parameter messageFormat
	bindings_java_releaseString(messageFormat);
}
Beispiel #7
0
void show_error_dialog(GmpvApplication *app, const gchar *prefix, const gchar *msg)
{
	GmpvMainWindow *wnd;
	GtkWidget *dialog;
	GtkWidget *msg_area;
	GList *iter;

	wnd = gmpv_application_get_main_window(app);
	dialog =	gtk_message_dialog_new
			(	GTK_WINDOW(wnd),
				GTK_DIALOG_DESTROY_WITH_PARENT,
				GTK_MESSAGE_ERROR,
				GTK_BUTTONS_OK,
				_("Error") );
	msg_area =	gtk_message_dialog_get_message_area
			(GTK_MESSAGE_DIALOG(dialog));
	iter = gtk_container_get_children(GTK_CONTAINER(msg_area));

	while(iter)
	{
		if(GTK_IS_LABEL(iter->data))
		{
			GtkLabel *label = iter->data;

			gtk_label_set_line_wrap_mode
				(label, PANGO_WRAP_WORD_CHAR);
		}

		iter = g_list_next(iter);
	}

	g_list_free(iter);

	if(prefix)
	{
		gchar *prefix_escaped = g_markup_printf_escaped("%s", prefix);
		gchar *msg_escaped = g_markup_printf_escaped("%s", msg);

		gtk_message_dialog_format_secondary_markup
			(	GTK_MESSAGE_DIALOG(dialog),
				"<b>[%s]</b> %s",
				prefix_escaped,
				msg_escaped );

		g_free(prefix_escaped);
		g_free(msg_escaped);
	}
	else
	{
		gtk_message_dialog_format_secondary_text
			(GTK_MESSAGE_DIALOG(dialog), "%s", msg);
	}

	gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
}
static void
change_filename(GFile* src, const char* dst_name, GtkWidget* parent_window)
{
    char* src_name;
    GFile* parent;
    GFile* dst;
    gboolean res;
    GError* error = NULL;

    if (dst_name == NULL)
	return;

    src_name = g_file_get_basename(src);
    if (strcmp(src_name, dst_name) != 0) {
	parent = g_file_get_parent(src);
	dst = g_file_get_child(parent, dst_name);

	res = g_file_move(src, dst, G_FILE_COPY_NOFOLLOW_SYMLINKS,
		NULL, NULL, NULL, &error);

	if (!res) {
	    GtkWidget* dialog;
	    char* display_name;
	    gboolean do_free = FALSE;;

	    if (g_utf8_validate(src_name, -1, NULL)) {
		display_name = src_name;
	    } else {
		display_name = get_display_name(src_name);
		do_free = TRUE;
	    }

	    dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(parent_window),
                GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
                GTK_MESSAGE_ERROR,
                GTK_BUTTONS_CLOSE,
                _("<span size=\"larger\" weight=\"bold\">There was an error renaming \"%s\" to \"%s\"</span>"),
		display_name, dst_name);
	    gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),
		"%s", error->message);
	    gtk_dialog_run(GTK_DIALOG(dialog));
	    gtk_widget_destroy(dialog);

	    g_error_free(error);

	    if (do_free)
		g_free(display_name);
	}

	g_object_unref(G_OBJECT(dst));
    }

    g_free(src_name);
}
void
no_fileopen_infodisplay(gtk_gui* w, const char* caption) {
	GtkMessageDialog* dialog = (GtkMessageDialog*) gtk_message_dialog_new (NULL,
		GTK_DIALOG_DESTROY_WITH_PARENT,
		GTK_MESSAGE_INFO,
		GTK_BUTTONS_OK,
		"%s",
		caption);
	gtk_message_dialog_format_secondary_markup (dialog, "No file open: Please first select File->Open");
	gtk_dialog_run (GTK_DIALOG (dialog));
	gtk_widget_destroy (GTK_WIDGET (dialog));
}
Beispiel #10
0
//static void on_browse(GtkWidget * widget, gpointer data)
void ladish_run_load_project_dialog(ladish_room_proxy_handle room)
{
  GtkFileFilter * filter;
  GtkWidget * dialog;
  char * filename;

  dialog = gtk_file_chooser_dialog_new(
    _("Load project"),
    NULL,
    GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    NULL);

  gtk_file_chooser_set_create_folders(GTK_FILE_CHOOSER(dialog), FALSE);

  filter = gtk_file_filter_new();
  gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME, reject_filter, dialog, NULL); /* reject all files */
  gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
  //g_signal_connect(G_OBJECT(dialog), "selection-changed", G_CALLBACK(on_dir_select), dialog);
  g_signal_connect(G_OBJECT(dialog), "current-folder-changed", G_CALLBACK(dir_changed), dialog);

loop:
  if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
  {
    filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));

    if (!is_project_dir(filename))
    {
      GtkWidget * dialog;
      dialog = get_gtk_builder_widget("error_dialog");
      gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), _("<b><big>Not a project dir</big></b>"));
      gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog), "%s", filename);
      gtk_widget_show(dialog);
      gtk_dialog_run(GTK_DIALOG(dialog));
      gtk_widget_hide(dialog);
      goto loop;
    }

    //gtk_entry_set_text(GTK_ENTRY(get_gtk_builder_widget("load_project_path_entry")), filename);
    log_info("Loading project from '%s'", filename);
    if (!ladish_room_proxy_load_project(room, filename))
    {
      log_error("ladish_room_proxy_load_project() failed.");
    }

    g_free(filename);

    //gtk_widget_activate(gtk_dialog_get_widget_for_response(GTK_DIALOG(data), GTK_RESPONSE_OK));
  }
  gtk_widget_destroy(dialog);
  return;
}
Beispiel #11
0
static void
gs_page_needs_user_action (GsPageHelper *helper, AsScreenshot *ss)
{
	GtkWidget *content_area;
	GtkWidget *dialog;
	GtkWidget *ssimg;
	g_autofree gchar *escaped = NULL;
	GsPagePrivate *priv = gs_page_get_instance_private (helper->page);

	dialog = gtk_message_dialog_new (gs_shell_get_window (priv->shell),
					 GTK_DIALOG_MODAL |
					 GTK_DIALOG_USE_HEADER_BAR,
					 GTK_MESSAGE_INFO,
					 GTK_BUTTONS_CANCEL,
					 /* TRANSLATORS: this is a prompt message, and
					  * '%s' is an application summary, e.g. 'GNOME Clocks' */
					 _("Prepare %s"),
					 gs_app_get_name (helper->app));
	escaped = g_markup_escape_text (as_screenshot_get_caption (ss, NULL), -1);
	gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
						    "%s", escaped);

	/* this will be enabled when the device is in the right mode */
	helper->button_install = gtk_dialog_add_button (GTK_DIALOG (dialog),
							/* TRANSLATORS: update the fw */
							_("Install"),
							GTK_RESPONSE_OK);
	helper->notify_quirk_id =
		g_signal_connect (helper->app, "notify::quirk",
				  G_CALLBACK (gs_page_notify_quirk_cb),
				  helper);
	gtk_widget_set_sensitive (helper->button_install, FALSE);

	/* load screenshot */
	helper->soup_session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
							      gs_user_agent (), NULL);
	ssimg = gs_screenshot_image_new (helper->soup_session);
	gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg), ss);
	gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg), 400, 225);
	gs_screenshot_image_load_async (GS_SCREENSHOT_IMAGE (ssimg),
					helper->cancellable);
	gtk_widget_set_margin_start (ssimg, 24);
	gtk_widget_set_margin_end (ssimg, 24);
	content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
	gtk_container_add (GTK_CONTAINER (content_area), ssimg);
	gtk_container_child_set (GTK_CONTAINER (content_area), ssimg, "pack-type", GTK_PACK_END, NULL);

	/* handle this async */
	g_signal_connect (dialog, "response",
			  G_CALLBACK (gs_page_update_app_response_cb), helper);
	gs_shell_modal_dialog_present (priv->shell, GTK_DIALOG (dialog));
}
static void
unmount_mount_callback (GObject *source_object,
			GAsyncResult *res,
			gpointer user_data)
{
	GError *error;
	char *primary;
	gboolean unmounted;
	gboolean should_eject;
	GtkWidget *dialog;


	should_eject = user_data != NULL;

	error = NULL;
	if (should_eject) {
		unmounted = g_mount_eject_with_operation_finish (G_MOUNT (source_object),
								 res, &error);
	} else {
		unmounted = g_mount_unmount_with_operation_finish (G_MOUNT (source_object),
								   res, &error);
	}
	
	if (! unmounted) {
		if (error->code != G_IO_ERROR_FAILED_HANDLED) {
			if (should_eject) {
				primary = g_strdup_printf (_("Unable to eject %p"), source_object);
			} else {
				primary = g_strdup_printf (_("Unable to unmount %p"), source_object);
			}

			dialog = gtk_message_dialog_new (NULL,
							 0,
							 GTK_MESSAGE_INFO,
							 GTK_BUTTONS_OK,
							 "%s",
							 primary);
			gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
								    "%s",
								    error->message);
			
			gtk_widget_show (GTK_WIDGET (dialog));
			g_signal_connect (dialog, "response",
					  G_CALLBACK (gtk_widget_destroy), NULL);
			g_free (primary);
		}
	}

	if (error != NULL) {
		g_error_free (error);
	}
}
Beispiel #13
0
static void
warn_if_no_roms (void)
{
        const gchar *sql = SQL_COUNT_ROMS;
        GtkWidget *dialog;
        gchar **result;
        glong n_roms;
        GError *error = NULL;

        if (!gva_db_get_table (sql, &result, NULL, NULL, &error))
        {
                gva_error_handle (&error);
                return;
        }

        errno = 0;
        g_return_if_fail (g_strv_length (result) > 1);
        n_roms = strtol (result[1], NULL, 10);
        g_strfreev (result);

        if (errno != 0)
        {
                g_warning ("%s", g_strerror (errno));
                return;
        }

        if (n_roms > 0)
                return;

        dialog = gtk_message_dialog_new_with_markup (
                GTK_WINDOW (GVA_WIDGET_MAIN_WINDOW),
                GTK_DIALOG_DESTROY_WITH_PARENT,
                GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
                "<big><b>%s</b></big>",
                _("No ROM files found"));

        gtk_message_dialog_format_secondary_markup (
                GTK_MESSAGE_DIALOG (dialog),
                _("GNOME Video Arcade was unable to locate any ROM files. "
                  "It could be that MAME is misconfigured or that no ROM "
                  "files are installed. Click <b>Help</b> for more details "
                  "and troubleshooting tips."));

        gtk_dialog_add_button (
                GTK_DIALOG (dialog), GTK_STOCK_HELP, GTK_RESPONSE_HELP);

        if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_HELP)
                gva_help_display (GTK_WINDOW (dialog), "troubleshooting");

        gtk_widget_destroy (dialog);
}
/* for when the vte cannot be located */
static void show_error_message(void)
{
    GtkWidget *dlg = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
                        GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s %s", 
                        ST_PLUGIN_NAME, _("Plugin"));
    
    gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dlg), "%s",
        _("There is currently no terminal loaded in Geany.  Enable the terminal "
        "in Geany's prefrences dialog and restart Geany to use the plugin "
        "or disable the plugin to stop seeing this error message."));
    
    gtk_dialog_run(GTK_DIALOG(dlg));
    gtk_widget_destroy(dlg);
}
Beispiel #15
0
static void
confirm_dialog (DBusGProxy *adapter,
		DBusGProxy *device,
		const char *name,
		const char *long_name,
		const char *value,
		DBusGMethodInvocation *context)
{
	GtkWidget *dialog;
	GtkBuilder *xml;
	char *str;
	input_data *input;

	input = g_new0 (input_data, 1);
	input->path = g_strdup (dbus_g_proxy_get_path(adapter));
	input->device = g_object_ref (device);
	input->context = context;

	xml = gtk_builder_new ();
	if (gtk_builder_add_from_file (xml, "confirm-dialogue.ui", NULL) == 0)
		gtk_builder_add_from_file (xml, PKGDATADIR "/confirm-dialogue.ui", NULL);

	dialog = GTK_WIDGET (gtk_builder_get_object (xml, "dialog"));
	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
	if (notification_supports_actions () != FALSE)
		gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
	else
		gtk_window_set_focus_on_map (GTK_WINDOW (dialog), FALSE);
	gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE);
	input->dialog = dialog;

	str = g_strdup_printf (_("Device '%s' wants to pair with this computer"),
			       name);
	g_object_set (G_OBJECT (dialog), "text", str, NULL);
	g_free (str);

	str = g_strdup_printf ("<b>%s</b>", value);
	gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
						    _("Please confirm whether the PIN '%s' matches the one on device %s."),
						    str, long_name);
	g_free (str);

	input_list = g_list_append (input_list, input);

	g_signal_connect (G_OBJECT (dialog), "response",
			  G_CALLBACK (confirm_callback), input);

	enable_blinking ();
}
Beispiel #16
0
GtkWidget *
glide_gtk_util_show_error_dialog (const gchar *text,
				  const gchar *secondary)
{
  GtkWidget *d = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
					 GTK_MESSAGE_ERROR,
					 GTK_BUTTONS_OK,
					 text, NULL);
  gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (d), secondary, NULL);
  
  gtk_widget_show (d);
  g_signal_connect (d, "response", G_CALLBACK (glide_error_response_callback), NULL);
  
  return d;
}
static void
show_error_message (GtkWindow *parent, gchar *primary_text, gchar *secondary_text)
{
    GtkWidget *dialog;

    dialog = gtk_message_dialog_new (parent,
                                     GTK_DIALOG_MODAL,
                                     GTK_MESSAGE_ERROR,
                                     GTK_BUTTONS_CLOSE,
                                     "%s", primary_text);
    gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
            "%s", secondary_text);
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (dialog);
}
Beispiel #18
0
static void
ask_show_ui (DonnaTaskHelper    *th,
             struct ask         *ask)
{
    GtkWidget *w;
    guint i;
    gint r;

    ask->th = th;

    w = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
            "%s", ask->question);
    if (ask->details_markup)
        gtk_message_dialog_format_secondary_markup ((GtkMessageDialog *) w,
                "%s", ask->details);
    else
        gtk_message_dialog_format_secondary_text ((GtkMessageDialog *) w,
                "%s", ask->details);

    for (i = 0, r = 1; i < ask->buttons->len; i += 2, ++r)
    {
        GtkButton *btn;

        btn = (GtkButton *) gtk_button_new_with_label (ask->buttons->pdata[i]);
        if (ask->buttons->pdata[i + 1])
        {
            GdkPixbuf *pb;

            pb = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                    ask->buttons->pdata[i + 1], /*FIXME*/16, 0, NULL);
            if (pb)
            {
                gtk_button_set_image (btn, gtk_image_new_from_pixbuf (pb));
                g_object_unref (pb);
            }
        }

        gtk_widget_set_can_default ((GtkWidget *) btn, TRUE);
        gtk_dialog_add_action_widget ((GtkDialog *) w, (GtkWidget *) btn, r);
    }
    gtk_dialog_set_default_response ((GtkDialog *) w, ask->btn_default);

    g_signal_connect (w, "delete-event", (GCallback) gtk_true, NULL);
    g_signal_connect (w, "response", (GCallback) ask_response, ask);
    ask->widget = w;

    gtk_widget_show_all (w);
}
Beispiel #19
0
static void
handle_with_cb (GObject *source,
    GAsyncResult *result,
    gpointer user_data)
{
  TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
  GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (user_data);
  GError *error = NULL;

  if (!tp_channel_dispatch_operation_handle_with_finish (cdo, result, &error))
    {
      g_print ("HandleWith() failed: %s\n", error->message);
      gtk_message_dialog_format_secondary_markup (dialog,
          "<b>Error</b>\n\nAsking LibreOffice to accept the session failed: <i>%s</i>",
          error->message);
      g_error_free (error);
      return;
    }

  g_print ("HandleWith() succeeded\n");
  gtk_widget_destroy (GTK_WIDGET (dialog));
}
Beispiel #20
0
/**
 * Display a dialog presenting the license of a map.
 * Allow to read the license by launching a web browser.
 */
void a_dialog_license ( GtkWindow *parent, const gchar *map, const gchar *license, const gchar *url)
{
  GtkWidget *dialog = gtk_message_dialog_new (parent,
                                 GTK_DIALOG_DESTROY_WITH_PARENT,
                                 GTK_MESSAGE_INFO,
                                 GTK_BUTTONS_OK,
                                 _("The map data is licensed: %s."),
                                 license);
  gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
    _("The data provided by '<b>%s</b>' are licensed under the following license: <b>%s</b>."),
    map, license);
#define RESPONSE_OPEN_LICENSE 600
  if (url != NULL) {
    gtk_dialog_add_button (GTK_DIALOG (dialog), _("Open license"), RESPONSE_OPEN_LICENSE);
  }
  gint response;
  do {
    response = gtk_dialog_run (GTK_DIALOG (dialog));
    if (response == RESPONSE_OPEN_LICENSE) {
      open_url (parent, url);
    }
  } while (response != GTK_RESPONSE_DELETE_EVENT && response != GTK_RESPONSE_OK);
  gtk_widget_destroy (dialog);
}
Beispiel #21
0
static void paste(GeanyDocument * doc, const gchar * website)
{
    SoupSession *session;
    SoupMessage *msg = NULL;

    gchar *f_content;
    gchar const *f_type;
    gchar *f_title;
    gchar *p_url;
    gchar *formdata = NULL;
    gchar *user_agent = NULL;
    gchar **tokens_array;

    const gchar *langs_supported_codepad[] =
    {
        "C", "C++", "D", "Haskell",
        "Lua", "OCaml", "PHP", "Perl", "Plain Text",
        "Python", "Ruby", "Scheme", "Tcl"
    };

    const gchar *langs_supported_dpaste[] =
    {
        "Bash", "C", "CSS", "Diff",
        "Django/Jinja", "HTML", "IRC logs", "JavaScript", "PHP",
        "Python console session", "Python Traceback", "Python",
        "Python3", "Restructured Text", "SQL", "Text only"
    };

    gint occ_position;
    gint i;
    guint status;
    gsize f_length;

    g_return_if_fail(doc && doc->is_valid);

    f_type = doc->file_type->name;

    if (doc->file_name == NULL)
        f_title = document_get_basename_for_display(doc, -1);
    else
        f_title = g_path_get_basename(doc->file_name);

    load_settings();
    
    f_content = get_paste_text(doc, &f_length);
    if (f_content == NULL || f_content[0] == '\0')
    {
        dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Refusing to create blank paste"));
        return;
    }

    switch (website_selected)
    {

    case CODEPAD_ORG:

        for (i = 0; i < G_N_ELEMENTS(langs_supported_codepad); i++)
        {
            if (g_strcmp0(f_type, langs_supported_codepad[i]) == 0)
                break;
            else
                f_type = DEFAULT_TYPE_CODEPAD;
        }

        msg = soup_message_new("POST", website);
        formdata = soup_form_encode("lang", f_type,
                                    "code", f_content,
                                    "submit", "Submit",
                                    NULL);

        break;

    case TINYPASTE_COM:

        msg = soup_message_new("POST", website);
        formdata = soup_form_encode("paste", f_content, 
                                    "title", f_title,
                                    "is_code", g_strcmp0(f_type, "None") == 0 ? "0" : "1",
                                    NULL);

        break;


    case DPASTE_DE:

        for (i = 0; i < G_N_ELEMENTS(langs_supported_dpaste); i++)
        {
            if (g_strcmp0(f_type, langs_supported_dpaste[i]) == 0)
                break;
            else
                f_type = DEFAULT_TYPE_DPASTE;
        }

        msg = soup_message_new("POST", website);
        /* apparently dpaste.de detects automatically the syntax of the
         * pasted code so 'lexer' should be unneeded
         */
        formdata = soup_form_encode("content", f_content,
                                    "title", f_title,
                                    "lexer", f_type,
                                    NULL);

        break;

    case SPRUNGE_US:

        msg = soup_message_new("POST", website);
        formdata = soup_form_encode("sprunge", f_content, NULL);

        break;

    case PASTEBIN_GEANY_ORG:

        msg = soup_message_new("POST", website);
        formdata = soup_form_encode("content", f_content,
                                    "author", author_name,
                                    "title", f_title,
                                    "lexer", f_type,
                                    NULL);

        break;

    }

    g_free(f_content);

    user_agent = g_strconcat(PLUGIN_NAME, " ", PLUGIN_VERSION, " / Geany ", GEANY_VERSION, NULL);
    session = soup_session_async_new_with_options(SOUP_SESSION_USER_AGENT, user_agent, NULL);
    g_free(user_agent);

    soup_message_set_request(msg, "application/x-www-form-urlencoded",
                             SOUP_MEMORY_TAKE, formdata, strlen(formdata));

    status = soup_session_send_message(session, msg);
    p_url = g_strdup(msg->response_body->data);

    g_object_unref(session);
    g_object_unref(msg);

    if(status == SOUP_STATUS_OK)
    {

        /*
         * codepad.org doesn't return only the url of the new snippet pasted
         * but an html page. This minimal parser will get the bare url.
         */

        if (website_selected == CODEPAD_ORG)
        {
            tokens_array = g_strsplit(p_url, "<a href=\"", 0);

            /* cuts the string when it finds the first occurrence of '/'
             * It shoud work even if codepad would change its url.
             */

            SETPTR(p_url, g_strdup(tokens_array[5]));
            occ_position = indexof(tokens_array[5], '\"');

            g_strfreev(tokens_array);

            if(occ_position != -1)
            {
                p_url[occ_position] = '\0';
            }
            else
            {
                dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Unable to paste the code on codepad.org\n"
                                    "Retry or select another pastebin."));
                g_free(p_url);
                return;
            }

        }
        else if(website_selected == TINYPASTE_COM)
        {
            /* tinypaste.com returns a XML response which looks
             * like this:
             * 
             * <?xml version="1.0" encoding="utf-8"?>
             * <result>
             *      <response>xxxxx</response>
             * </result>
             */
            tokens_array = g_strsplit_set(p_url, "<>", 0);
            
            SETPTR(p_url, g_strdup_printf("http://%s/%s", websites[TINYPASTE_COM], tokens_array[6]));
            
            g_strfreev(tokens_array);
        }
            
        else if(website_selected == DPASTE_DE)
        {
            SETPTR(p_url, g_strndup(p_url + 1, strlen(p_url) - 2));

        }
        else if(website_selected == SPRUNGE_US)
        {

            /* in order to enable the syntax highlightning on sprunge.us
             * it is necessary to append at the returned url a question
             * mark '?' followed by the file type.
             *
             * e.g. sprunge.us/xxxx?c
             */
            gchar *ft_tmp = g_ascii_strdown(f_type, -1);
            g_strstrip(p_url);
            SETPTR(p_url, g_strdup_printf("%s?%s", p_url, ft_tmp));
            g_free(ft_tmp);
        }

        if (check_button_is_checked)
        {
            utils_open_browser(p_url);
        }
        else
        {
            GtkWidget *dlg = gtk_message_dialog_new(GTK_WINDOW(geany->main_widgets->window),
                GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
                _("Paste Successful"));
            gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dlg),
                _("Your paste can be found here:\n<a href=\"%s\" "
                "title=\"Click to open the paste in your browser\">%s</a>"), p_url, p_url);
            gtk_dialog_run(GTK_DIALOG(dlg));
            gtk_widget_destroy(dlg);
        }
    }
    else
    {
        dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Unable to paste the code. Check your connection and retry.\n"
                            "Error code: %d\n"), status);
    }

    g_free(p_url);
}
Beispiel #22
0
/**
 * @see https://developers.google.com/accounts/docs/OAuth2InstalledApp
 * @returns NULL if the user cancels the operation or a valid token
 */
static int gphoto_get_user_auth_token(dt_storage_gphoto_gui_data_t *ui)
{
  ///////////// open the authentication url in a browser
  GError *error = NULL;
  gchar *params = NULL;
  params = dt_util_dstrcat(params,
                           GOOGLE_WS_BASE_URL
                           "o/oauth2/v2/auth?"
                           "client_id=%s&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
                           "&scope=" GOOGLE_API_BASE_URL "auth/photoslibrary "
                           GOOGLE_API_BASE_URL "auth/userinfo.profile "
                           GOOGLE_API_BASE_URL "auth/userinfo.email"
                           "&response_type=code&access_type=offline",
                           ui->gphoto_api->google_client_id);

  if(!gtk_show_uri(gdk_screen_get_default(), params, gtk_get_current_event_time(), &error))
  {
    fprintf(stderr, "[gphoto] error opening browser: %s\n", error->message);
    g_error_free(error);
  }

  ////////////// build & show the validation dialog
  const gchar *text1 = _("step 1: a new window or tab of your browser should have been "
                         "loaded. you have to login into your google account there "
                         "and authorize darktable to upload photos before continuing.");
  const gchar *text2 = _("step 2: paste the verification code shown to you in the browser "
                         "and click the OK button once you are done.");

  GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
  GtkDialog *gphoto_auth_dialog = GTK_DIALOG(
      gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION,
                             GTK_BUTTONS_OK_CANCEL, _("google authentication")));
#ifdef GDK_WINDOWING_QUARTZ
  dt_osx_disallow_fullscreen(GTK_WIDGET(gphoto_auth_dialog));
#endif
  gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(gphoto_auth_dialog), "%s\n\n%s", text1, text2);

  GtkWidget *entry = gtk_entry_new();
  GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(gtk_label_new(_("verification code:"))), FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry), TRUE, TRUE, 0);

  GtkWidget *gphotoauthdialog_vbox
      = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(gphoto_auth_dialog));
  gtk_box_pack_end(GTK_BOX(gphotoauthdialog_vbox), hbox, TRUE, TRUE, 0);

  gtk_widget_show_all(GTK_WIDGET(gphoto_auth_dialog));

  ////////////// wait for the user to enter the verification code
  gint result;
  gchar *token = NULL;
  const char *replycode;
  while(TRUE)
  {
    result = gtk_dialog_run(GTK_DIALOG(gphoto_auth_dialog));
    if(result == GTK_RESPONSE_CANCEL) break;
    replycode = gtk_entry_get_text(GTK_ENTRY(entry));
    if(replycode == NULL || g_strcmp0(replycode, "") == 0)
    {
      gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(gphoto_auth_dialog),
                                                 "%s\n\n%s\n\n<span foreground=\"" MSGCOLOR_RED
                                                 "\" ><small>%s</small></span>",
                                                 text1, text2, _("please enter the verification code"));
      continue;
    }
    else
    {
      token = g_strdup(replycode);
      break;
    }
  }
  gtk_widget_destroy(GTK_WIDGET(gphoto_auth_dialog));
  g_free(params);

  if(result == GTK_RESPONSE_CANCEL)
    return 1;

  // Interchange now the authorization_code for an access_token and refresh_token
  JsonObject *reply;

  params = NULL;
  params = dt_util_dstrcat(params, "code=%s&client_id=%s&client_secret=%s"
                           "&redirect_uri=" GOOGLE_URI "&grant_type=authorization_code",
                           token, ui->gphoto_api->google_client_id, ui->gphoto_api->google_client_secret);

  g_free(token);

  reply = gphoto_query_post_auth(ui->gphoto_api, GOOGLE_WS_BASE_URL "o/oauth2/token", params);

  gchar *access_token = g_strdup(json_object_get_string_member(reply, "access_token"));

  gchar *refresh_token = g_strdup(json_object_get_string_member(reply, "refresh_token"));

  ui->gphoto_api->token = access_token;
  ui->gphoto_api->refresh_token = refresh_token;

  g_free(params);

  return 0; // FIXME
}
Beispiel #23
0
static void
task_list_io_xml_save (CTaskList  * self,
                       gchar const* path)
{
        GMappedFile* old_version;
        gchar* xml_path = task_list_io_xml_path (path);
        FILE* file;

	/* we don't care if this fails */
	old_version = g_mapped_file_new (xml_path, FALSE, NULL);
	if (old_version) {
		gchar* backup_path = g_strdup_printf ("%s.%li", xml_path, time (NULL));
		g_file_set_contents (backup_path,
				     g_mapped_file_get_contents (old_version),
				     g_mapped_file_get_length (old_version),
				     NULL);
		g_free (backup_path);
		g_mapped_file_free (old_version);
	}

        file = fopen (xml_path, "w");
        if (!file)
          {
            int old_errno = errno;
            GtkWidget* dialog;

            if (old_errno == ENOENT)
              {
                gchar* folder = g_path_get_dirname (xml_path);
                if (g_mkdir_with_parents (folder, 0755) == 0)
                  {
                    file = fopen (xml_path, "w");
                  }

                g_free (folder);

                if (file)
                  {
                    goto cont;
                  }
              }

            /* FIXME: the user should be able to save to a different place */
            old_errno = errno;
            dialog = gtk_message_dialog_new (NULL, /* FIXME: add window */
                                             0, /* FIXME: make modal */
                                             GTK_MESSAGE_ERROR,
                                             GTK_BUTTONS_CLOSE,
                                             "%s", _("Error saving to file"));
            gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
                                                        _("Couldn't open file \"%s\" for writing:\n\n"
                                                          "<span style='italic'>%s</span>"),
                                                        xml_path,
                                                        strerror (old_errno));

            gtk_dialog_run (GTK_DIALOG (dialog));
            gtk_widget_destroy (dialog);

            goto cleanup;
          }
cont:
        fprintf (file, "<?xml version=\"1.0\" encoding=\"iso-8859-15\"?>\n");
        fprintf (file, "<tasks>\n");
        dump_nodes (self, file, NULL);
        fprintf (file, "</tasks>\n");
        if (fclose (file) != 0)
          {
            /* FIXME: come up with a proper fallback solution */
            g_warning ("error closing file: %s", strerror (errno));
          }
cleanup:
        g_free (xml_path);
}
Beispiel #24
0
static gchar* nsgtk_download_dialog_show (const gchar *filename, const gchar *domain,
				   const gchar *size)
{
	enum { GTK_RESPONSE_DOWNLOAD, GTK_RESPONSE_SAVE_AS };
	GtkWidget *dialog;
	char *destination = NULL;
	gchar *message = g_strdup(messages_get("gtkStartDownload"));
	gchar *info = g_strdup_printf(messages_get("gtkInfo"), filename,
				      domain, size);

	dialog = gtk_message_dialog_new_with_markup(nsgtk_download_parent,
						    GTK_DIALOG_DESTROY_WITH_PARENT,
						    GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
						    "<span size=\"x-large\" weight=\"ultrabold\">%s</span>"
						    "\n\n<small>%s</small>",
						    message, info);

	gtk_dialog_add_buttons(GTK_DIALOG(dialog), NSGTK_STOCK_SAVE,
			       GTK_RESPONSE_DOWNLOAD, NSGTK_STOCK_CANCEL,
			       GTK_RESPONSE_CANCEL, NSGTK_STOCK_SAVE_AS,
			       GTK_RESPONSE_SAVE_AS, NULL);

	gint result = gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
	g_free(message);
	g_free(info);

	switch (result) {
	case GTK_RESPONSE_SAVE_AS: {
		dialog = gtk_file_chooser_dialog_new
			(messages_get("gtkSave"),
			 nsgtk_download_parent,
			 GTK_FILE_CHOOSER_ACTION_SAVE,
			 NSGTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
			 NSGTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
			 NULL);
		gtk_file_chooser_set_current_name
			(GTK_FILE_CHOOSER(dialog), filename);
		gtk_file_chooser_set_current_folder
			(GTK_FILE_CHOOSER(dialog),
			 nsoption_charp(downloads_directory));
		gtk_file_chooser_set_do_overwrite_confirmation
			(GTK_FILE_CHOOSER(dialog),
			 nsoption_bool(request_overwrite));

		gint result = gtk_dialog_run(GTK_DIALOG(dialog));
		if (result == GTK_RESPONSE_ACCEPT)
			destination = gtk_file_chooser_get_filename
				(GTK_FILE_CHOOSER(dialog));
		gtk_widget_destroy(dialog);
		break;
	}
	case GTK_RESPONSE_DOWNLOAD: {
		destination = malloc(strlen(nsoption_charp(downloads_directory))
				     + strlen(filename) + SLEN("/") + 1);
		if (destination == NULL) {
			nsgtk_warning(messages_get("NoMemory"), 0);
			break;
		}
		sprintf(destination, "%s/%s",
			nsoption_charp(downloads_directory), filename);
		/* Test if file already exists and display overwrite
		 * confirmation if needed */
		if (g_file_test(destination, G_FILE_TEST_EXISTS) &&
		    nsoption_bool(request_overwrite)) {
			message = g_strdup_printf(messages_get(
							  "gtkOverwrite"), filename);
			info = g_strdup_printf(messages_get(
						       "gtkOverwriteInfo"),
					       nsoption_charp(downloads_directory));

			dialog = gtk_message_dialog_new_with_markup(
				nsgtk_download_parent,
				GTK_DIALOG_DESTROY_WITH_PARENT,
				GTK_MESSAGE_QUESTION,
				GTK_BUTTONS_CANCEL,
				"<b>%s</b>",message);
			gtk_message_dialog_format_secondary_markup(
				GTK_MESSAGE_DIALOG(dialog),
				"%s", info);

			GtkWidget *button = gtk_dialog_add_button(
				GTK_DIALOG(dialog),
				"_Replace",
				GTK_RESPONSE_DOWNLOAD);
			gtk_button_set_image(GTK_BUTTON(button),
					     nsgtk_image_new_from_stock(
						     NSGTK_STOCK_SAVE,
						     GTK_ICON_SIZE_BUTTON));

			gint result = gtk_dialog_run(GTK_DIALOG(dialog));
			if (result == GTK_RESPONSE_CANCEL)
				destination = NULL;

			gtk_widget_destroy(dialog);
			g_free(message);
			g_free(info);
		}
		break;
	}
	}
	return destination;
}
static VALUE
mdiag_format_secondary_markup(VALUE self, VALUE markup)
{
    gtk_message_dialog_format_secondary_markup(_SELF(self), RVAL2CSTR(markup), NULL);
    return self;
}
Beispiel #26
0
/**
 * @see https://developers.facebook.com/docs/authentication/
 * @returs NULL if the user cancel the operation or a valid token
 */
static gchar *facebook_get_user_auth_token(dt_storage_facebook_gui_data_t *ui)
{
  ///////////// open the authentication url in a browser
  GError *error = NULL;
  gtk_show_uri(gdk_screen_get_default(),
               FB_WS_BASE_URL"dialog/oauth?"
               "client_id=" FB_API_KEY
               "&redirect_uri="FB_WS_BASE_URL"connect/login_success.html"
               "&scope=user_photos,publish_stream"
               "&response_type=token", gtk_get_current_event_time(), &error);

  ////////////// build & show the validation dialog
  gchar *text1 = _("step 1: a new window or tab of your browser should have been"
                   "loaded. you have to login into your facebook account there "
                   "and authorize darktable to upload photos before continuing.");
  gchar *text2 = _("step 2: paste your browser url and click the ok button once "
                   "you are done.");

  GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
  GtkDialog *fb_auth_dialog = GTK_DIALOG(gtk_message_dialog_new (GTK_WINDOW (window),
                                  GTK_DIALOG_DESTROY_WITH_PARENT,
                                  GTK_MESSAGE_QUESTION,
                                  GTK_BUTTONS_OK_CANCEL,
                                  _("Facebook authentication")));
  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (fb_auth_dialog),
      "%s\n\n%s", text1, text2);

  GtkWidget *entry = gtk_entry_new();
  GtkWidget *hbox = gtk_hbox_new(FALSE, 5);
  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(gtk_label_new(_("url:"))), FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry), TRUE, TRUE, 0);
  gtk_box_pack_end(GTK_BOX(fb_auth_dialog->vbox), hbox, TRUE, TRUE, 0);

  gtk_widget_show_all(GTK_WIDGET(fb_auth_dialog));

  ////////////// wait for the user to entrer the validation URL
  gint result;
  gchar *token = NULL;
  const char *replyurl;
  while (TRUE)
  {
    result = gtk_dialog_run (GTK_DIALOG (fb_auth_dialog));
    if (result == GTK_RESPONSE_CANCEL)
      break;
    replyurl = gtk_entry_get_text(GTK_ENTRY(entry));
    if (replyurl == NULL || g_strcmp0(replyurl, "") == 0)
    {
      gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(fb_auth_dialog),
                                                 "%s\n\n%s\n\n<span foreground=\"" MSGCOLOR_RED "\" ><small>%s</small></span>",
                                                 text1, text2, _("please enter the validation url"));
      continue;
    }
    token = fb_extract_token_from_url(replyurl);
    if (token != NULL)//we have a valid token
      break;
    else
      gtk_message_dialog_format_secondary_markup(
            GTK_MESSAGE_DIALOG(fb_auth_dialog),
            "%s\n\n%s%s\n\n<span foreground=\"" MSGCOLOR_RED "\"><small>%s</small></span>",
            text1, text2,
            _("the given url is not valid, it should look like: "),
              FB_WS_BASE_URL"connect/login_success.html?...");
  }
  gtk_widget_destroy(GTK_WIDGET(fb_auth_dialog));

  return token;
}
Beispiel #27
0
/**
 * gs_app_notify_unavailable:
 **/
GtkResponseType
gs_app_notify_unavailable (GsApp *app, GtkWindow *parent)
{
	GsAppLicenceHint hint = GS_APP_LICENCE_FREE;
	GtkResponseType response;
	GtkWidget *dialog;
	const gchar *licence;
	gboolean already_enabled = FALSE;	/* FIXME */
	guint i;
	struct {
		const gchar	*str;
		GsAppLicenceHint hint;
	} keywords[] = {
		{ "NonFree",		GS_APP_LICENCE_NONFREE },
		{ "PatentConcern",	GS_APP_LICENCE_PATENT_CONCERN },
		{ "Proprietary",	GS_APP_LICENCE_NONFREE },
		{ NULL, 0 }
	};
	_cleanup_free_ gchar *origin_url = NULL;
	_cleanup_object_unref_ GSettings *settings = NULL;
	_cleanup_string_free_ GString *body = NULL;
	_cleanup_string_free_ GString *title = NULL;

	/* this is very crude */
	licence = gs_app_get_licence (app);
	if (licence != NULL) {
		for (i = 0; keywords[i].str != NULL; i++) {
			if (g_strstr_len (licence, -1, keywords[i].str) != NULL)
				hint |= keywords[i].hint;
		}
	} else {
		/* use the worst-case assumption */
		hint = GS_APP_LICENCE_NONFREE | GS_APP_LICENCE_PATENT_CONCERN;
	}

	/* check if the user has already dismissed */
	settings = g_settings_new ("org.gnome.software");
	if (!g_settings_get_boolean (settings, "prompt-for-nonfree"))
		return GTK_RESPONSE_OK;

	title = g_string_new ("");
	if (already_enabled) {
		g_string_append_printf (title, "<b>%s</b>",
					/* TRANSLATORS: window title */
					_("Install Third-Party Software?"));
	} else {
		g_string_append_printf (title, "<b>%s</b>",
					/* TRANSLATORS: window title */
					_("Enable Third-Party Software Source?"));
	}
	dialog = gtk_message_dialog_new (parent,
					 GTK_DIALOG_MODAL,
					 GTK_MESSAGE_QUESTION,
					 GTK_BUTTONS_CANCEL,
					 NULL);
	gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), title->str);

	/* FIXME: get the URL somehow... */
	origin_url = g_strdup_printf ("<a href=\"\">%s>/a>", gs_app_get_origin (app));
	body = g_string_new ("");
	if (hint & GS_APP_LICENCE_NONFREE) {
		g_string_append_printf (body,
					/* TRANSLATORS: the replacements are as follows:
					 * 1. Application name, e.g. "Firefox"
					 * 2. Software source name, e.g. fedora-optional
					 */
					_("%s is not <a href=\"https://en.wikipedia.org/wiki/Free_and_open-source_software\">"
					  "free and open source software</a>, "
					  "and is provided by “%s”."),
					gs_app_get_name (app),
					origin_url);
	} else {
		g_string_append_printf (body,
					/* TRANSLATORS: the replacements are as follows:
					 * 1. Application name, e.g. "Firefox"
					 * 2. Software source name, e.g. fedora-optional */
					_("%s is provided by “%s”."),
					gs_app_get_name (app),
					origin_url);
	}

	/* tell the use what needs to be done */
	if (!already_enabled) {
		g_string_append (body, " ");
		g_string_append (body,
				/* TRANSLATORS: a software source is a repo */
				_("This software source must be "
				  "enabled to continue installation."));
	}

	/* be aware of patent clauses */
	if (hint & GS_APP_LICENCE_PATENT_CONCERN) {
		g_string_append (body, "\n\n");
		if (gs_app_get_id_kind (app) != AS_ID_KIND_CODEC) {
			g_string_append_printf (body,
						/* TRANSLATORS: Laws are geographical, urgh... */
						_("It may be illegal to install "
						  "or use %s in some countries."),
						gs_app_get_name (app));
		} else {
			g_string_append (body,
					/* TRANSLATORS: Laws are geographical, urgh... */
					_("It may be illegal to install or use "
					  "this codec in some countries."));
		}
	}

	gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog), "%s", body->str);
	/* TRANSLATORS: this is button text to not ask about non-free content again */
	if (0) gtk_dialog_add_button (GTK_DIALOG (dialog), _("Don't Warn Again"), GTK_RESPONSE_YES);
	if (already_enabled) {
		gtk_dialog_add_button (GTK_DIALOG (dialog),
				       /* TRANSLATORS: button text */
				       _("Install"),
				       GTK_RESPONSE_OK);
	} else {
		gtk_dialog_add_button (GTK_DIALOG (dialog),
				       /* TRANSLATORS: button text */
				       _("Enable and Install"),
				       GTK_RESPONSE_OK);
	}
	response = gtk_dialog_run (GTK_DIALOG (dialog));
	if (response == GTK_RESPONSE_YES) {
		response = GTK_RESPONSE_OK;
		g_settings_set_boolean (settings, "prompt-for-nonfree", FALSE);
	}
	gtk_widget_destroy (dialog);
	return response;
}
void
GtkNSSSecurityWarningDialogs::DoDialog (nsIInterfaceRequestor *aContext,
					const char *aPrefName,
					GtkMessageType aType,
					GtkButtonsType aButtons,
					int aDefaultResponse,
					const char *aPrimary,
					const char *aSecondary,
					const char *aButtonText,
					PRBool *_retval)
{
	if (_retval) *_retval = PR_FALSE;

	nsresult rv;
	PRBool show = PR_TRUE;
	nsCOMPtr<nsIPrefBranch> prefBranch
		(do_GetService (NS_PREFSERVICE_CONTRACTID));
	if (prefBranch && aPrefName)
	{
		rv = prefBranch->GetBoolPref (aPrefName, &show);
		if (NS_FAILED(rv)) show = PR_TRUE;
	}

	char *showOncePref = NULL;
	PRBool showOnce = PR_FALSE;
	if (!show && prefBranch && aPrefName)
	{
		showOncePref = g_strconcat (aPrefName, ".show_once", NULL);
		rv = prefBranch->GetBoolPref (showOncePref, &showOnce);
		if (NS_FAILED (rv)) showOnce = PR_FALSE;
	}

	if (!show && !showOnce)
	{
		g_free (showOncePref);
		if (_retval) *_retval = PR_TRUE;
		return;
	}
	
	AutoJSContextStack stack;
	rv = stack.Init ();
	if (NS_FAILED (rv)) return;

	/* Didn't you know it, mozilla SUCKS!
	 * the "aContext" interface requestor is made from a nsIDOMWindow,
	 * but can only give out a nsIPrompt, from where there's no way to get
	 * the nsIDOMWindow back!
	 *
	 * However GaleonUtils::FindGtkParent falls back to the current active
	 * window so this vageuly works for us at the moment
	 *
	 * https://bugzilla.mozilla.org/show_bug.cgi?id=277587
	 */
	nsCOMPtr<nsIDOMWindow> domWin (do_GetInterface (aContext));
	GtkWidget *parent = GaleonUtils::FindGtkParent (domWin);

	GtkDialogFlags flags = parent ? (GtkDialogFlags)0 : GTK_DIALOG_MODAL;
#if GTK_CHECK_VERSION(2,6,0)
	GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (parent), flags,
						    aType, aButtons, "%s", aPrimary);

        if (aSecondary)
        {
                gtk_message_dialog_format_secondary_markup
                        (GTK_MESSAGE_DIALOG (dialog), "%s", aSecondary);
        }

#else
	GtkWidget *dialog = hig_alert_new (GTK_WINDOW (parent),	flags,
					   aType == GTK_MESSAGE_INFO ?
					   HIG_ALERT_INFORMATION : HIG_ALERT_CONFIRMATION,
					   aPrimary, aSecondary, NULL);
	if (aButtons == GTK_BUTTONS_OK)
	{
		gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK,
				       GTK_RESPONSE_OK);
	}
	else if (aButtons == GTK_BUTTONS_CANCEL)
	{
		gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL,
				       GTK_RESPONSE_CANCEL);
	}
	else
	{
		g_assert_not_reached();
	}

#endif

	if (parent && GTK_WINDOW (parent)->group)
	{
		gtk_window_group_add_window (GTK_WINDOW (parent)->group,
					     GTK_WINDOW (dialog));
	}

	if (aButtonText)
	{
		gtk_dialog_add_button (GTK_DIALOG (dialog), aButtonText,
				       GTK_RESPONSE_ACCEPT);
	}

	gtk_dialog_set_default_response (GTK_DIALOG (dialog), aDefaultResponse);

	int response = gtk_dialog_run (GTK_DIALOG (dialog));

	if (_retval) *_retval = response == GTK_RESPONSE_ACCEPT;

	if (prefBranch && showOncePref && showOnce)
	{
		prefBranch->SetBoolPref (showOncePref, PR_FALSE);
	}

	gtk_widget_destroy (dialog);
	g_free (showOncePref);
}
Beispiel #29
0
gboolean
warn_user_of_impending_doom(FormatDialog* dialog, FormatVolume* target)
{
	GSList* mounted_list = NULL;

	/* Figure out if we're about to run over any live partitions first */
	if(target->volume) {
		if(libhal_volume_is_mounted(target->volume)) {
			mounted_list = g_slist_prepend(mounted_list, 
						       get_friendly_volume_name(dialog->hal_context, target->volume));
		}
	}
	else {
		mounted_list = get_volumes_mounted_on_drive(dialog->hal_context, target->drive);
	}

	gchar* message;
	gchar* name = (target->volume ? get_friendly_volume_name(dialog->hal_context, target->volume) : 
					get_friendly_drive_name(target->drive));
	/* Come up with the error message */
	if(!mounted_list) {
		message = g_strdup_printf(_("Formatting will irreversibly destroy all data on %s. "
					    "Are you sure you want to continue?"), name);
	}
	else {
		/* FIXME: There are a ton of malloc's here */
		int i; 	GSList* iter;
		gchar* tmp_list[65];

		/* TODO: It'd be cool if these were hyperlinks that opened nautilus at the mountpoint! */
		for(iter = mounted_list, i=0; iter != NULL && i < 64; iter = iter->next, i++) {
			FormatVolume* current = get_cached_device_from_udi(dialog, (char*)iter->data);
			g_debug("Mounted: %s", iter->data);
			if(!current) 	continue;

			gchar* mountpoint = libhal_volume_get_mount_point(current->volume);
			tmp_list[i] = g_strdup_printf( _("%s mounted at %s"), current->friendly_name, mountpoint);
		}
		tmp_list[i] = NULL;

		gchar* vol_list = g_strjoinv("\n", tmp_list);

		message = g_strdup_printf( _("Formatting will irreversibly destroy all data on %s, "
					     "including these volumes currently in use:"
					     "\n\n%s\n\n"
					     "Are you sure you want to continue?"), name, vol_list);

		/* Free our stuff */
		g_free(vol_list);
		for(int i=0; i < 64; i++) {
			if(!tmp_list[i]) break;
			g_free(tmp_list[i]);
		}
	}
	g_free(name);

	/* Show the dialog and get the response back */
	GtkWidget* messagebox;
	messagebox = gtk_message_dialog_new(GTK_WINDOW(dialog->toplevel), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
			GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, _("Formatting will erase data"));
	gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(messagebox), message);
	gtk_dialog_add_buttons(GTK_DIALOG(messagebox), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 
			 _("Format device"), GTK_RESPONSE_OK, NULL);

	int id = gtk_dialog_run(GTK_DIALOG(messagebox));
	gtk_widget_destroy(messagebox);

	return (id == GTK_RESPONSE_OK);
}
Beispiel #30
0
void
gtr_confirm_remove (GtkWindow  * parent,
                    TrCore     * core,
                    GSList     * torrent_ids,
                    gboolean     delete_files)
{
    GSList * l;
    GtkWidget * d;
    GString * primary_text;
    GString * secondary_text;
    struct delete_data * dd;
    int connected = 0;
    int incomplete = 0;
    const int count = g_slist_length (torrent_ids);

    if (!count)
        return;

    dd = g_new0 (struct delete_data, 1);
    dd->core = core;
    dd->torrent_ids = torrent_ids;
    dd->delete_files = delete_files;

    for (l=torrent_ids; l!=NULL; l=l->next)
    {
        const int id = GPOINTER_TO_INT (l->data);
        tr_torrent * tor = gtr_core_find_torrent (core, id);
        const tr_stat * stat = tr_torrentStat (tor);
        if (stat->leftUntilDone) ++incomplete;
        if (stat->peersConnected) ++connected;
    }

    primary_text = g_string_new (NULL);

    if (!delete_files)
    {
        g_string_printf (primary_text, ngettext ("Remove torrent?",
                                                 "Remove %d torrents?",
                                                 count), count);
    }
    else
    {
        g_string_printf (primary_text, ngettext ("Delete this torrent's downloaded files?",
                                                 "Delete these %d torrents' downloaded files?",
                                                 count), count);
    }

    secondary_text = g_string_new (NULL);

    if (!incomplete && !connected)
    {
        g_string_assign (secondary_text, ngettext (
                "Once removed, continuing the transfer will require the torrent file or magnet link.",
                "Once removed, continuing the transfers will require the torrent files or magnet links.",
                count));
    }
    else if (count == incomplete)
    {
        g_string_assign (secondary_text, ngettext ("This torrent has not finished downloading.",
                                                   "These torrents have not finished downloading.",
                                                   count));
    }
    else if (count == connected)
    {
        g_string_assign (secondary_text, ngettext ("This torrent is connected to peers.",
                                                   "These torrents are connected to peers.",
                                                   count));
    }
    else
    {
        if (connected)
            g_string_append (secondary_text, ngettext ("One of these torrents is connected to peers.",
                                                       "Some of these torrents are connected to peers.",
                                                       connected));
        if (connected && incomplete)
            g_string_append (secondary_text, "\n");

        if (incomplete)
            g_string_assign (secondary_text, ngettext ("One of these torrents has not finished downloading.",
                                                       "Some of these torrents have not finished downloading.",
                                                       incomplete));
    }

    d = gtk_message_dialog_new_with_markup (parent,
                                            GTK_DIALOG_DESTROY_WITH_PARENT,
                                            GTK_MESSAGE_QUESTION,
                                            GTK_BUTTONS_NONE,
                                            "<big><b>%s</b></big>",
                                            primary_text->str);
    if (secondary_text->len)
        gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (d),
                                                    "%s", secondary_text->str);
    gtk_dialog_add_buttons (GTK_DIALOG (d),
                            _("_Cancel"), GTK_RESPONSE_CANCEL,
                          (delete_files ? _("_Delete") :
                              _("_Remove")), GTK_RESPONSE_ACCEPT,
                            NULL);
    gtk_dialog_set_default_response (GTK_DIALOG (d),
                                     GTK_RESPONSE_CANCEL);
    gtk_dialog_set_alternative_button_order (GTK_DIALOG (d),
                                             GTK_RESPONSE_ACCEPT,
                                             GTK_RESPONSE_CANCEL,
                                             -1);
    g_signal_connect (d, "response", G_CALLBACK (on_remove_dialog_response), dd);
    gtk_widget_show_all (d);

    g_string_free (primary_text, TRUE);
    g_string_free (secondary_text, TRUE);
}