Example #1
0
static void termomix_color_dialog (GtkWidget *widget, void *data) {
    GtkWidget *color_dialog;
    GtkWidget *label1, *label2;
    GtkWidget *buttonfore, *buttonback;
    GtkWidget *hbox_fore, *hbox_back;
    gint response;
    guint16 backalpha;

    color_dialog=gtk_dialog_new_with_buttons(gettext("Select color"),
            GTK_WINDOW(termomix.main_window), GTK_DIALOG_MODAL, GTK_STOCK_CANCEL,
            GTK_RESPONSE_REJECT, GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT, NULL);

    gtk_dialog_set_default_response(GTK_DIALOG(color_dialog), GTK_RESPONSE_ACCEPT);
    gtk_window_set_modal(GTK_WINDOW(color_dialog), TRUE);
    /* Set style */
    gchar *css = g_strdup_printf (HIG_DIALOG_CSS);
    gtk_css_provider_load_from_data(termomix.provider, css, -1, NULL);
    GtkStyleContext *context = gtk_widget_get_style_context (color_dialog);
    gtk_style_context_add_provider (context, 
            GTK_STYLE_PROVIDER(termomix.provider),
            GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
    g_free(css);

    hbox_fore=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
    hbox_back=gtk_box_new(FALSE, 12);
    label1=gtk_label_new(gettext("Select foreground color:"));
    label2=gtk_label_new(gettext("Select background color:"));
    buttonfore=gtk_color_button_new_with_color(&termomix.forecolor);
    buttonback=gtk_color_button_new_with_color(&termomix.backcolor);
    /* When the times comes (gtk-3.4) */
    // buttonfore=gtk_color_button_new_with_rgba(&termomix.forecolor);
    // buttonback=gtk_color_button_new_with_rgba(&termomix.backcolor);*/

    /* This rounding sucks...*/
    backalpha = roundf((termomix.opacity_level*65535)/99);
    if (termomix.has_rgba) {
        gtk_color_button_set_use_alpha(GTK_COLOR_BUTTON(buttonback), TRUE);
        gtk_color_button_set_alpha(GTK_COLOR_BUTTON(buttonback), backalpha);
    }

    gtk_box_pack_start(GTK_BOX(hbox_fore), label1, FALSE, FALSE, 12);
    gtk_box_pack_end(GTK_BOX(hbox_fore), buttonfore, FALSE, FALSE, 12);
    gtk_box_pack_start(GTK_BOX(hbox_back), label2, FALSE, FALSE, 12);
    gtk_box_pack_end(GTK_BOX(hbox_back), buttonback, FALSE, FALSE, 12);
    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(color_dialog))), hbox_fore, FALSE, FALSE, 6);
    gtk_box_pack_end(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(color_dialog))), hbox_back, FALSE, FALSE, 6);

    gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(color_dialog)));

    response=gtk_dialog_run(GTK_DIALOG(color_dialog));

    if (response==GTK_RESPONSE_ACCEPT) {
        /* TODO: Remove deprecated get_color */
        //gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(color_dialog), &termomix.forecolor);
        //gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(color_dialog), &termomix.backcolor);
        gtk_color_button_get_color(GTK_COLOR_BUTTON(buttonfore), &termomix.forecolor);
        gtk_color_button_get_color(GTK_COLOR_BUTTON(buttonback), &termomix.backcolor);

        if (termomix.has_rgba) {
            backalpha = gtk_color_button_get_alpha(GTK_COLOR_BUTTON(buttonback));
        }

        if (termomix.has_rgba) {
            vte_terminal_set_opacity(VTE_TERMINAL (termomix.term->vte), backalpha);
        }
        vte_terminal_set_colors(VTE_TERMINAL(termomix.term->vte), &termomix.forecolor,
                &termomix.backcolor, termomix.palette, PALETTE_SIZE);

        gchar *cfgtmp;
        cfgtmp = g_strdup_printf("#%02x%02x%02x", termomix.forecolor.red >>8,
                                 termomix.forecolor.green>>8, termomix.forecolor.blue>>8);
        termomix_set_config_string("forecolor", cfgtmp);
        g_free(cfgtmp);

        cfgtmp = g_strdup_printf("#%02x%02x%02x", termomix.backcolor.red >>8,
                                 termomix.backcolor.green>>8, termomix.backcolor.blue>>8);
        termomix_set_config_string("backcolor", cfgtmp);
        g_free(cfgtmp);

        termomix.opacity_level= roundf((backalpha*99)/65535);     /* Opacity value is between 0 and 99 */
        termomix_set_config_integer("opacity_level", termomix.opacity_level);  

    }
Example #2
0
static GObject*
settings_dlg_constructor (GType type, guint n_construct_properties,
                          GObjectConstructParam *construct_properties)
{
  GObject *object;
  SettingsDlg *dialog;
  GtkWidget *frame;

  object = parent_class->constructor (type,
				      n_construct_properties,
				      construct_properties);
  dialog = SETTINGS_DLG (object);
  gpa_window_set_title (GTK_WINDOW (dialog), _("Settings"));
  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
                          GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                          GTK_STOCK_OK, GTK_RESPONSE_OK,
                          NULL);
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           GTK_RESPONSE_APPLY,
                                           -1);

  /* The UI mode section.  */
  frame = user_interface_mode_frame (dialog);
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame,
                      FALSE, FALSE, 0);

  /* The default key section.  */
  frame = default_key_frame (dialog);
  gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame);

  /* The default keyserver section.  Note that there is no keyserver
     entry if we are using gnupg 2.1.  There we do not have the
     keyserver helpers anymore and thus the keyservers are to be
     enabled in the backend preferences. */
#ifdef ENABLE_KEYSERVER_SUPPORT
  if (!dialog->gnupg21)
    {
      frame = default_keyserver_frame (dialog);
      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame,
                          FALSE, FALSE, 0);
    }
#endif /*ENABLE_KEYSERVER_SUPPORT*/

  /* The auto key locate section.  */
  dialog->akl.enabled = dialog->gnupg21;
  if (dialog->akl.enabled)
    {
      frame = auto_key_locate_frame (dialog);
      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame,
                          FALSE, FALSE, 0);
    }

  /* Connect the response signal.  */
  g_signal_connect (GTK_OBJECT (dialog), "response",
                    G_CALLBACK (dialog_response), NULL);


  /* Load values.  */
  load_settings (dialog);

  /* Show all windows and hide those we don't want. */
  gtk_widget_show_all (GTK_WIDGET(dialog));
  update_show_advanced_options (dialog);

  return object;
}
Example #3
0
static int
passphrase_dialog(char *message)
{
    const char *failed;
    char *passphrase, *local;
    int result, grab_tries, grab_server, grab_pointer;
    GtkWidget *dialog, *entry;
    GdkGrabStatus status;

    grab_server = (getenv("GNOME_SSH_ASKPASS_GRAB_SERVER") != NULL);
    grab_pointer = (getenv("GNOME_SSH_ASKPASS_GRAB_POINTER") != NULL);
    grab_tries = 0;

    dialog = gtk_message_dialog_new(NULL, 0,
                                    GTK_MESSAGE_QUESTION,
                                    GTK_BUTTONS_OK_CANCEL,
                                    "%s",
                                    message);

    entry = gtk_entry_new();
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, FALSE,
                       FALSE, 0);
    gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
    gtk_widget_grab_focus(entry);
    gtk_widget_show(entry);

    gtk_window_set_title(GTK_WINDOW(dialog), "OpenSSH");
    gtk_window_set_position (GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
    gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE);
    gtk_label_set_line_wrap(GTK_LABEL((GTK_MESSAGE_DIALOG(dialog))->label),
                            TRUE);

    /* Make <enter> close dialog */
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
    g_signal_connect(G_OBJECT(entry), "activate",
                     G_CALLBACK(ok_dialog), dialog);

    gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE);

    /* Grab focus */
    gtk_widget_show_now(dialog);
    if (grab_pointer) {
        for(;;) {
            status = gdk_pointer_grab(
                         (GTK_WIDGET(dialog))->window, TRUE, 0, NULL,
                         NULL, GDK_CURRENT_TIME);
            if (status == GDK_GRAB_SUCCESS)
                break;
            usleep(GRAB_WAIT * 1000);
            if (++grab_tries > GRAB_TRIES) {
                failed = "mouse";
                goto nograb;
            }
        }
    }
    for(;;) {
        status = gdk_keyboard_grab((GTK_WIDGET(dialog))->window,
                                   FALSE, GDK_CURRENT_TIME);
        if (status == GDK_GRAB_SUCCESS)
            break;
        usleep(GRAB_WAIT * 1000);
        if (++grab_tries > GRAB_TRIES) {
            failed = "keyboard";
            goto nograbkb;
        }
    }
    if (grab_server) {
        gdk_x11_grab_server();
    }

    result = gtk_dialog_run(GTK_DIALOG(dialog));

    /* Ungrab */
    if (grab_server)
        XUngrabServer(GDK_DISPLAY());
    if (grab_pointer)
        gdk_pointer_ungrab(GDK_CURRENT_TIME);
    gdk_keyboard_ungrab(GDK_CURRENT_TIME);
    gdk_flush();

    /* Report passphrase if user selected OK */
    passphrase = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
    if (result == GTK_RESPONSE_OK) {
        local = g_locale_from_utf8(passphrase, strlen(passphrase),
                                   NULL, NULL, NULL);
        if (local != NULL) {
            puts(local);
            memset(local, '\0', strlen(local));
            g_free(local);
        } else {
            puts(passphrase);
        }
    }

    /* Zero passphrase in memory */
    memset(passphrase, '\b', strlen(passphrase));
    gtk_entry_set_text(GTK_ENTRY(entry), passphrase);
    memset(passphrase, '\0', strlen(passphrase));
    g_free(passphrase);

    gtk_widget_destroy(dialog);
    return (result == GTK_RESPONSE_OK ? 0 : -1);

    /* At least one grab failed - ungrab what we got, and report
       the failure to the user.  Note that XGrabServer() cannot
       fail.  */
nograbkb:
    gdk_pointer_ungrab(GDK_CURRENT_TIME);
nograb:
    if (grab_server)
        XUngrabServer(GDK_DISPLAY());
    gtk_widget_destroy(dialog);

    report_failed_grab(failed);

    return (-1);
}
Example #4
0
static void
get_input(GncGWENGui *gui, guint32 flags, const gchar *title, const gchar *text,
          gchar **input, gint min_len, gint max_len)
{
    GladeXML *xml;
    GtkWidget *dialog;
    GtkWidget *heading_label;
    GtkWidget *input_entry;
    GtkWidget *confirm_entry;
    GtkWidget *confirm_label;
    GtkWidget *remember_pin_checkbutton;
    const gchar *internal_input, *internal_confirmed;
    gboolean confirm = (flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) != 0;
    gboolean hidden = (flags & GWEN_GUI_INPUT_FLAGS_SHOW) == 0;
    gboolean is_tan = (flags & GWEN_GUI_INPUT_FLAGS_TAN) != 0;
    gint retval;

    g_return_if_fail(input);
    g_return_if_fail(max_len >= min_len && max_len > 0);

    ENTER(" ");

    /* Set up dialog */
    xml = gnc_glade_xml_new("aqbanking.glade", "Password Dialog");
    dialog = glade_xml_get_widget(xml, "Password Dialog");
    g_object_set_data_full(G_OBJECT(dialog), "xml", xml, g_object_unref);

    heading_label = glade_xml_get_widget(xml, "heading_label");
    input_entry = glade_xml_get_widget(xml, "input_entry");
    confirm_entry = glade_xml_get_widget(xml, "confirm_entry");
    confirm_label = glade_xml_get_widget(xml, "confirm_label");
    remember_pin_checkbutton = glade_xml_get_widget(xml, "remember_pin");
    if (is_tan)
    {
        gtk_widget_hide(remember_pin_checkbutton);
    }
    else
    {
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remember_pin_checkbutton),
                                     gui->cache_passwords);
    }

    if (gui->parent)
        gtk_window_set_transient_for(GTK_WINDOW(dialog),
                                     GTK_WINDOW(gui->parent));
    if (title)
        gtk_window_set_title(GTK_WINDOW(dialog), title);

    if (text)
    {
        gchar *raw_text = strip_html(g_strdup(text));
        gtk_label_set_text(GTK_LABEL(heading_label), raw_text);
        g_free(raw_text);
    }

    if (*input)
    {
        gtk_entry_set_text(GTK_ENTRY(input_entry), *input);
        erase_password(*input);
        *input = NULL;
    }

    if (confirm)
    {
        gtk_entry_set_activates_default(GTK_ENTRY(input_entry), FALSE);
        gtk_entry_set_activates_default(GTK_ENTRY(confirm_entry), TRUE);
        gtk_entry_set_max_length(GTK_ENTRY(input_entry), max_len);
        gtk_entry_set_max_length(GTK_ENTRY(confirm_entry), max_len);
    }
    else
    {
        gtk_entry_set_activates_default(GTK_ENTRY(input_entry), TRUE);
        gtk_entry_set_max_length(GTK_ENTRY(input_entry), max_len);
        gtk_widget_hide(confirm_entry);
        gtk_widget_hide(confirm_label);
    }
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);

    /* Ask the user until he enters a valid input or cancels */
    while (TRUE)
    {
        gboolean remember_pin;

        if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
            break;

        if (!is_tan)
        {
            /* Enable or disable the password cache */
            remember_pin = gtk_toggle_button_get_active(
                               GTK_TOGGLE_BUTTON(remember_pin_checkbutton));
            enable_password_cache(gui, remember_pin);
            gnc_gconf_set_bool(GCONF_SECTION_AQBANKING, KEY_REMEMBER_PIN,
                               remember_pin, NULL);
        }

        internal_input = gtk_entry_get_text(GTK_ENTRY(input_entry));
        if (strlen(internal_input) < min_len)
        {
            gboolean retval;
            gchar *msg = g_strdup_printf(
                             _("The PIN needs to be at least %d characters \n"
                               "long. Do you want to try again?"), min_len);
            retval = gnc_verify_dialog(gui->parent, TRUE, "%s", msg);
            g_free(msg);
            if (!retval)
                break;
            continue;
        }

        if (!confirm)
        {
            *input = g_strdup(internal_input);
            break;
        }

        internal_confirmed = gtk_entry_get_text(GTK_ENTRY(confirm_entry));
        if (strcmp(internal_input, internal_confirmed) == 0)
        {
            *input = g_strdup(internal_input);
            break;
        }
    }

    /* This trashes passwords in the entries' memory as well */
    gtk_widget_destroy(dialog);

    LEAVE("input %s", *input ? "non-NULL" : "NULL");
}
Example #5
0
void
open_pdf_cb (GtkWidget *widget, gpointer data)
{
	GtkWidget *dialog, * window;
	GtkTextView * text_view;
	GtkFileFilter *pdffilter, *txtfilter;
	Ebook * ebook;

	ebook = (Ebook *)data;
	window = GTK_WIDGET(gtk_builder_get_object (ebook->builder, "gpdfwindow"));
	text_view = GTK_TEXT_VIEW(gtk_builder_get_object (ebook->builder, "textview"));
	dialog = gtk_file_chooser_dialog_new (_("Open file"),
		GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN,
		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
		GTK_RESPONSE_ACCEPT, NULL);
	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);

	pdffilter = gtk_file_filter_new ();
	gtk_file_filter_set_name (pdffilter, _("All PDF Files (*.pdf)"));
	gtk_file_filter_add_mime_type (pdffilter, "application/pdf");
	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), pdffilter);
	gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), pdffilter);
	txtfilter = gtk_file_filter_new ();
	gtk_file_filter_set_name (txtfilter, _("ASCII text files (*.txt)"));
	gtk_file_filter_add_mime_type (txtfilter, "text/plain");
	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), txtfilter);
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
	{
		gchar *filename;
		GtkFileFilter * f;

		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
		// read the filter property.
		g_object_get (G_OBJECT(GTK_FILE_CHOOSER (dialog)), "filter", &f, NULL);
		if (f == pdffilter)
		{
			/* get the dialog out of the way before the work starts. */
			gtk_widget_destroy (dialog);
			open_file (ebook, filename);
		}
		else
		{
			gchar * contents, * msg;
			GtkTextBuffer * buffer;
			GtkStatusbar * statusbar;
			GtkProgressBar * progressbar;
			guint id;

			/* get the dialog out of the way before the work starts. */
			gtk_widget_destroy (dialog);
			progressbar = GTK_PROGRESS_BAR(gtk_builder_get_object (ebook->builder, "progressbar"));
			statusbar = GTK_STATUSBAR(gtk_builder_get_object (ebook->builder, "statusbar"));
			id = gtk_statusbar_get_context_id (statusbar, PACKAGE);
			/* typical text files are v.large and this can block. FIXME. */
			g_file_get_contents (filename, &contents, NULL, NULL);
			buffer = gtk_text_view_get_buffer (text_view);
			gtk_text_buffer_set_text (buffer, contents, -1);
			msg = g_strconcat (PACKAGE, " - ", g_filename_display_basename (filename), NULL);
			gtk_window_set_title (GTK_WINDOW(window), msg);
			gtk_progress_bar_set_text (progressbar, "");
			gtk_progress_bar_set_fraction (progressbar, 0.0);
			gtk_statusbar_push (statusbar, id, _("Done"));
		}
		/* this is the PDF filename, so free it. */
		g_free (filename);
		filename = NULL;
		return;
	}
	gtk_widget_destroy (dialog);
}
Example #6
0
/* Caller must g_slist_free() the returned list .*/
GSList *
ghid_dialog_file_select_multiple(gchar * title, gchar ** path, gchar * shortcuts)
{
  GtkWidget *dialog;
  GSList *result = NULL;
  gchar *folder, *seed;
  GHidPort *out = &ghid_port;
  GtkFileFilter *no_filter;

  dialog = gtk_file_chooser_dialog_new (title,
					GTK_WINDOW (out->top_window),
					GTK_FILE_CHOOSER_ACTION_OPEN,
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					GTK_STOCK_OK, GTK_RESPONSE_OK,
					NULL);

  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

  gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER (dialog), TRUE);

  /* add a default filter for not filtering files */
  no_filter = gtk_file_filter_new ();
  gtk_file_filter_set_name (no_filter, "all");
  gtk_file_filter_add_pattern (no_filter, "*.*");
  gtk_file_filter_add_pattern (no_filter, "*");
  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), no_filter);

  /* in case we have a dialog for loading schematic files */
  if (strcmp (title, _("Load schematics")) == 0)
  {
    /* add a filter for schematic files */
    GtkFileFilter *sch_filter;
    sch_filter = gtk_file_filter_new ();
    gtk_file_filter_set_name (sch_filter, "sch");
    gtk_file_filter_add_mime_type (sch_filter, "application/x-geda-schematic");
    gtk_file_filter_add_pattern (sch_filter, "*.sch");
    gtk_file_filter_add_pattern (sch_filter, "*.SCH");
    gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), sch_filter);
  }

  if (path && *path)
    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), *path);

  if (shortcuts && *shortcuts)
    {
      folder = g_strdup (shortcuts);
      seed = folder;
      while ((folder = strtok (seed, ":")) != NULL)
	{
	  gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
						folder, NULL);
	  seed = NULL;
	}
      g_free (folder);
    }

  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
    {
      result = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (dialog));
      folder =
	gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
      if (folder && path)
	{
	  dup_string (path, folder);
	  g_free (folder);
	}
    }
  gtk_widget_destroy (dialog);


  return result;
}
Example #7
0
static GtkWidget *
create_add_emblems_dialog (CajaEmblemSidebar *emblem_sidebar,
                           GSList *emblems)
{
    GtkWidget *dialog, *label, *table, *image;
    GtkWidget *first_entry, *entry, *scroller, *hbox;
    Emblem *emblem;
    GSList *list;
    int num_emblems;

    first_entry = NULL;

    dialog = gtk_dialog_new_with_buttons (_("Add Emblems..."),
                                          NULL,
                                          0,
                                          GTK_STOCK_CANCEL,
                                          GTK_RESPONSE_CANCEL,
                                          GTK_STOCK_OK,
                                          GTK_RESPONSE_OK,
                                          GTK_STOCK_HELP,
                                          GTK_RESPONSE_HELP,
                                          NULL);

    gtk_dialog_set_default_response (GTK_DIALOG (dialog),
                                     GTK_RESPONSE_OK);

    /* FIXME:  make a better message */
    if (g_slist_length (emblems) > 1)
    {
        label = gtk_label_new (_("Enter a descriptive name next to each emblem.  This name will be used in other places to identify the emblem."));
    }
    else
    {
        label = gtk_label_new (_("Enter a descriptive name next to the emblem.  This name will be used in other places to identify the emblem."));
    }

    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                        label, FALSE, FALSE, 8);
    gtk_widget_show (label);

    scroller = eel_scrolled_wrap_table_new (TRUE, GTK_SHADOW_NONE, &table);
    eel_wrap_table_set_x_spacing (EEL_WRAP_TABLE (table), 8);
    eel_wrap_table_set_y_spacing (EEL_WRAP_TABLE (table), 8);

    num_emblems=0;
    list = emblems;
    while (list != NULL)
    {
        /* walk through the list of emblems, and create an image
         * and entry for each one
         */

        emblem = (Emblem *)list->data;
        list = list->next;

        image = gtk_image_new_from_pixbuf (emblem->pixbuf);

        hbox = gtk_hbox_new (TRUE, 0);
        gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);

        entry = gtk_entry_new ();
        gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
        g_signal_connect (entry, "changed",
                          G_CALLBACK (emblem_name_entry_changed_cb),
                          emblem);

        gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
        gtk_container_add (GTK_CONTAINER (table), hbox);

        if (num_emblems == 0)
        {
            first_entry = entry;
        }

        num_emblems++;
    }

    gtk_container_set_border_width (GTK_CONTAINER (dialog), 8);
    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                        scroller, TRUE, TRUE, 8);
    gtk_widget_show_all (scroller);

    gtk_widget_grab_focus (first_entry);

    /* we expand the window to hold up to about 4 emblems, but after that
     * let the scroller do its thing.  Is there a better way to do this?
     */
    gtk_window_set_default_size (GTK_WINDOW (dialog), 400,
                                 MIN (120+(60*num_emblems), 350));

    g_object_set_data_full (G_OBJECT (dialog), "emblems-to-add",
                            emblems, (GDestroyNotify)destroy_emblem_list);

    return dialog;
}
static void on_get_http_response(char *buffer, size_t buffer_len, gpointer userdata)
{
	if (!buffer)
		return;
	const char *p = g_strstr_len(buffer, buffer_len, "\r\n\r\n");
	if (!p) {
		return;
	}
	p += 4;
	if(g_str_has_prefix(p, UTF8_BOM))
		p += (sizeof(UTF8_BOM)-1); // better than strlen(UTF8_BOM);
	updateinfo_ParseUserData Data;
	Data.latest_version_num = 0;
	const gchar* const *languages = g_get_language_names();
	const char *locale = languages[0];
	if (locale && locale[0] != '\0') {
		const char *p = strchr(locale, '.');
		if (p) {
			Data.locale_name.assign(locale, p - locale);
		} else {
			Data.locale_name = locale;
		}
	}
	GMarkupParser parser;
	parser.start_element = NULL;
	parser.end_element = NULL;
	parser.text = updateinfo_parse_text;
	parser.passthrough = NULL;
	parser.error = NULL;
	GMarkupParseContext* context = g_markup_parse_context_new(&parser, (GMarkupParseFlags)0, &Data, NULL);
	g_markup_parse_context_parse(context, p, buffer_len - (p - buffer), NULL);
	g_markup_parse_context_end_parse(context, NULL);
	g_markup_parse_context_free(context);

	bool updated = false;
	if (Data.latest_version_num != latest_version_num) {
		updated = true;
		latest_version_num = Data.latest_version_num;
		version_msg_title = Data.version_msg_title;
		version_msg_content = Data.version_msg_content;
	}
	if (Data.latest_version_num > my_version_num && Data.latest_version_num != last_prompt_num) {
		std::string content = version_msg_content;
		content += "\n\n";
		content += _("Visit StarDict website now?");
		GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(plugin_info->mainwin), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_YES_NO, "%s", content.c_str());
		GtkWidget *prompt = gtk_check_button_new_with_mnemonic(_("_Don't show this until the next update."));
		gtk_widget_show(prompt);
		gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), prompt);
		gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
		gtk_window_set_title (GTK_WINDOW (dialog), version_msg_title.c_str());
		if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) {
			plugin_service->show_url("http://www.stardict.org");
		}
		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prompt))) {
			updated = true;
			last_prompt_num = Data.latest_version_num;
		}
		gtk_widget_destroy (dialog);
	}
	if (Data.latest_news != latest_news) {
		updated = true;
		latest_news = Data.latest_news;
	}
	if (updated) {
		GKeyFile *keyfile = g_key_file_new();
		g_key_file_set_string(keyfile, "update", "version_msg_title", version_msg_title.c_str());
		g_key_file_set_string(keyfile, "update", "version_msg_content", version_msg_content.c_str());
		g_key_file_set_string(keyfile, "update", "latest_news", latest_news.c_str());
		g_key_file_set_integer(keyfile, "update", "latest_version_num", latest_version_num);
		g_key_file_set_integer(keyfile, "update", "last_prompt_num", last_prompt_num);
		g_key_file_set_boolean(keyfile, "misc", "show_ads", show_ads);
		gsize length;
		gchar *content = g_key_file_to_data(keyfile, &length, NULL);
		std::string res = get_cfg_filename();
		g_file_set_contents(res.c_str(), content, length, NULL);
		g_free(content);
	}
	if (show_ads) {
		plugin_service->set_news(latest_news.c_str(), Data.links.c_str());
	}
}
static void
gb_editor_view_actions_save (GSimpleAction *action,
                             GVariant      *param,
                             gpointer       user_data)
{
  GbEditorView *self = user_data;
  IdeContext *context;
  IdeBufferManager *buffer_manager;
  IdeFile *file;
  IdeProgress *progress = NULL;
  IdeVcs *vcs;
  GFile *workdir;

  g_assert (GB_IS_EDITOR_VIEW (self));

  file = ide_buffer_get_file (IDE_BUFFER (self->document));
  context = ide_buffer_get_context (IDE_BUFFER (self->document));
  buffer_manager = ide_context_get_buffer_manager (context);
  vcs = ide_context_get_vcs (context);
  workdir = ide_vcs_get_working_directory (vcs);

  if (ide_file_get_is_temporary (file))
    {
      GtkDialog *dialog;
      GtkWidget *toplevel;
      GtkWidget *suggested;

      toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
      dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
                             "action", GTK_FILE_CHOOSER_ACTION_SAVE,
                             "do-overwrite-confirmation", TRUE,
                             "local-only", FALSE,
                             "modal", TRUE,
                             "select-multiple", FALSE,
                             "show-hidden", FALSE,
                             "transient-for", toplevel,
                             "title", _("Save Document"),
                             NULL);

      gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog), workdir, NULL);

      gtk_dialog_add_buttons (GTK_DIALOG (dialog),
                              _("Cancel"), GTK_RESPONSE_CANCEL,
                              _("Save"), GTK_RESPONSE_OK,
                              NULL);
      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

      suggested = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
      gtk_style_context_add_class (gtk_widget_get_style_context (suggested),
                                   GTK_STYLE_CLASS_SUGGESTED_ACTION);

      g_signal_connect (dialog, "response", G_CALLBACK (save_temp_response), g_object_ref (self));

      gtk_window_present (GTK_WINDOW (dialog));

      return;
    }

  ide_buffer_manager_save_file_async (buffer_manager,
                                      IDE_BUFFER (self->document),
                                      file,
                                      &progress,
                                      NULL,
                                      save_file_cb,
                                      g_object_ref (self));
  g_object_bind_property (progress, "fraction", self->progress_bar, "fraction",
                          G_BINDING_SYNC_CREATE);
  gtk_widget_show (GTK_WIDGET (self->progress_bar));
  g_clear_object (&progress);
}
static void
hildon_font_selection_dialog_show_preview       (HildonFontSelectionDialog *fontsel)
{
    HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel);
    gint size;
    gboolean family_set, size_set;
    PangoAttribute *attr;
    PangoAttrList *list;
    GtkWidget *preview_dialog;
    GtkWidget *preview_label;
    gchar *str = NULL;
    gboolean position_set = FALSE;
    gint position = 0;
    gboolean show_ref = FALSE;

    g_assert (priv);

    g_object_get (G_OBJECT (fontsel), "position-set", &position_set, NULL);

    if (position_set) {
        g_object_get (G_OBJECT (fontsel), "position", &position, NULL);
        if (position == 1 || position == -1)
            show_ref = TRUE;
    }

    /* preview dialog init */
    preview_dialog =
        gtk_dialog_new_with_buttons (_("ecdg_ti_preview_font"), NULL,
                GTK_DIALOG_MODAL |
                GTK_DIALOG_DESTROY_WITH_PARENT |
                GTK_DIALOG_NO_SEPARATOR,
                _("ecdg_bd_font_dialog_ok"),
                GTK_RESPONSE_ACCEPT,
                NULL);

    str = (show_ref) ? g_strconcat (_("ecdg_fi_preview_font_preview_reference"), priv->preview_text, 0) :
        g_strdup (priv->preview_text);

    preview_label = gtk_label_new (str);
    gtk_label_set_line_wrap (GTK_LABEL(preview_label), TRUE);

    if (str) 
        g_free (str);

    str = NULL;

    /* set keypress handler (ESC hardkey) */
    g_signal_connect (G_OBJECT (preview_dialog), "key-press-event",
            G_CALLBACK(hildon_font_selection_dialog_preview_key_press),
            NULL);

    /* Set the font */
    list = (show_ref) ? hildon_font_selection_dialog_create_attrlist (fontsel, 
            strlen (_("ecdg_fi_preview_font_preview_reference")),
            strlen (priv->preview_text)) :
        hildon_font_selection_dialog_create_attrlist (fontsel, 0, strlen(priv->preview_text));

    g_object_get (G_OBJECT (fontsel), "family", &str, "family-set",
            &family_set, "size", &size, "size-set", &size_set,
            NULL);

    /* A smallish hack to add scrollbar when font size is really big */

    if (size_set && size > 24) {
        GtkScrolledWindow *scrolled = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
        gtk_scrolled_window_set_policy (scrolled, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
        gtk_scrolled_window_add_with_viewport (scrolled, GTK_WIDGET (preview_label));
        gtk_container_add (GTK_CONTAINER (GTK_DIALOG(preview_dialog)->vbox), GTK_WIDGET (scrolled));
        gtk_widget_set_size_request (GTK_WIDGET (scrolled), -1, 400);
    } else 
        gtk_container_add (GTK_CONTAINER (GTK_DIALOG(preview_dialog)->vbox), GTK_WIDGET (preview_label));

    /* make reference text to have the same fontface and size */
    if (family_set)
    {
        attr = pango_attr_family_new (str);
        add_preview_text_attr (list, attr, 0, strlen (_("ecdg_fi_preview_font_preview_reference")));
    }
    if (str != NULL)
        g_free (str);

    str = NULL;

    /* size */
    if (size_set)
    {
        attr = pango_attr_size_new (size * PANGO_SCALE);
        add_preview_text_attr (list, attr, 0, strlen (_("ecdg_fi_preview_font_preview_reference")));
    }

    gtk_label_set_attributes (GTK_LABEL (preview_label), list);
    pango_attr_list_unref (list);

    /*And show the dialog*/
    gtk_window_set_transient_for (GTK_WINDOW (preview_dialog), 
            GTK_WINDOW (fontsel));

    gtk_widget_show_all (preview_dialog);
    gtk_dialog_set_default_response (GTK_DIALOG (preview_dialog), GTK_RESPONSE_OK);
    
    GtkBox *action_area = (GtkBox *) GTK_DIALOG (preview_dialog)->action_area;
    GtkWidget *button = ((GtkBoxChild *) ((GSList *) action_area->children)->data)->widget;
    gtk_widget_grab_focus (button);

    gtk_dialog_run (GTK_DIALOG (preview_dialog));
    gtk_widget_destroy (preview_dialog);
}
Example #11
0
static void
pin_dialog (DBusGProxy *adapter,
		DBusGProxy *device,
		const char *name,
		const char *long_name,
		gboolean numeric,
		DBusGMethodInvocation *context)
{
	GtkWidget *dialog;
	GtkWidget *button;
	GtkWidget *entry;
	GtkBuilder *xml;
	char *str;
	input_data *input;

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

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

	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;

	gtk_dialog_set_default_response (GTK_DIALOG (dialog),
					 GTK_RESPONSE_OK);
	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
					   GTK_RESPONSE_OK,
					   FALSE);

	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);

	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
						  _("Please enter the PIN mentioned on device %s."),
						  long_name);

	entry = GTK_WIDGET (gtk_builder_get_object (xml, "entry"));
	if (numeric == TRUE) {
		gtk_entry_set_max_length (GTK_ENTRY (entry), 6);
		gtk_entry_set_width_chars (GTK_ENTRY (entry), 6);
		g_signal_connect (G_OBJECT (entry), "insert-text",
				  G_CALLBACK (insert_callback), input);
	} else {
		gtk_entry_set_max_length (GTK_ENTRY (entry), 16);
		gtk_entry_set_width_chars (GTK_ENTRY (entry), 16);
		gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
	}
	gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
	input->entry = entry;
	g_signal_connect (G_OBJECT (entry), "changed",
			  G_CALLBACK (changed_callback), input);

	button = GTK_WIDGET (gtk_builder_get_object (xml, "showinput_button"));
	if (numeric == FALSE) {
		g_signal_connect (G_OBJECT (button), "toggled",
				  G_CALLBACK (toggled_callback), input);
	} else {
		gtk_widget_set_no_show_all (button, TRUE);
		gtk_widget_hide (button);
	}

	input_list = g_list_append(input_list, input);

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

	enable_blinking();
}
Example #12
0
gint
main (gint argc, gchar **argv)
{
  GError        *error = NULL;
  GtkWidget     *dialog;
  GtkWidget     *button;
  gint           result;
  gint           retval = EXIT_SUCCESS;
  gint           default_response = GTK_RESPONSE_CANCEL;
  XfconfChannel *channel;
  gint           configver;
  gchar         *filename_46;
  gchar         *filename_default;
  gboolean       migrate_vendor_default;

  /* set translation domain */
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

#ifndef NDEBUG
  /* terminate the program on warnings and critical messages */
  g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
#endif

  gtk_init (&argc, &argv);

  if (!xfconf_init (&error))
    {
      g_critical ("Failed to initialize Xfconf: %s", error->message);
      g_error_free (error);
      return EXIT_FAILURE;
    }

  channel = xfconf_channel_get (XFCE_PANEL_CHANNEL_NAME);
  if (!xfconf_channel_has_property (channel, "/panels"))
    {
      /* lookup the old 4.6 config file */
      filename_46 = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, XFCE_46_CONFIG);

      /* lookup the default configuration */
      xfce_resource_push_path (XFCE_RESOURCE_CONFIG, XDGCONFIGDIR);
      filename_default = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, DEFAULT_CONFIG_FILENAME);
      xfce_resource_pop_path (XFCE_RESOURCE_CONFIG);

      if (filename_46 == NULL && filename_default == NULL)
        {
          g_warning ("No default or old configuration found");
          return EXIT_FAILURE;
        }

      /* if the default configuration does not match with the file found
       * by the resource lookup, migrate it without asking */
      migrate_vendor_default = (g_strcmp0 (DEFAULT_CONFIG_PATH, filename_default) != 0);

      /* check if we auto-migrate the default configuration */
      if (g_getenv ("XFCE_PANEL_MIGRATE_DEFAULT") != NULL
          || migrate_vendor_default)
        {
          if (filename_46 != NULL)
            g_message ("Tried to auto-migrate, but old configuration found");
          else if (filename_default == NULL)
            g_message ("Tried to auto-migrate, but no default configuration found");
          else
            goto migrate_default;
        }

      /* create question dialog */
      dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
                                       _("Welcome to the first start of the panel"));
      gtk_window_set_title (GTK_WINDOW (dialog), _("Panel"));
      gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_PREFERENCES);
      gtk_window_stick (GTK_WINDOW (dialog));
      gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);

      if (filename_46 != NULL)
        {
          gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s\n%s",
              _("Because the panel moved to a new system for storing the "
                "settings, it has to load a fresh initial configuration."),
              _("Choose below which setup you want for the first startup."));

          button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Migrate old config"), GTK_RESPONSE_OK);
          gtk_widget_set_tooltip_text (button, _("Migrate the old 4.6 configuration to Xfconf"));
          default_response = GTK_RESPONSE_OK;
        }
      else
        {
          gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
              _("Choose below which setup you want for the first startup."));
        }

      if (filename_default != NULL)
        {
          button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Use default config"), GTK_RESPONSE_YES);
          gtk_widget_set_tooltip_text (button, _("Load the default configuration"));

          if (default_response == GTK_RESPONSE_CANCEL)
            default_response = GTK_RESPONSE_YES;
        }

      button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("One empty panel"), GTK_RESPONSE_CANCEL);
      gtk_widget_set_tooltip_text (button, _("Start with one empty panel"));

      gtk_dialog_set_default_response (GTK_DIALOG (dialog), default_response);
      result = gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);

      if (result == GTK_RESPONSE_OK && filename_46 != NULL)
        {
          /* restore 4.6 config */
          if (!migrate_46 (filename_46, channel, &error))
            {
              xfce_dialog_show_error (NULL, error, _("Failed to migrate the old panel configuration"));
              g_error_free (error);
              retval = EXIT_FAILURE;
            }
        }
      else if (result == GTK_RESPONSE_YES && filename_default != NULL)
        {
          migrate_default:

          /* apply default config */
          if (!migrate_default (filename_default, &error))
            {
              xfce_dialog_show_error (NULL, error, _("Failed to load the default configuration"));
              g_error_free (error);
              retval = EXIT_FAILURE;
            }
        }

      g_free (filename_46);
      g_free (filename_default);
    }

  configver = xfconf_channel_get_int (channel, "/configver", -1);
  if (configver < XFCE4_PANEL_CONFIG_VERSION)
    {
      g_message (_("Panel config needs migration..."));

      if (!migrate_config (channel, configver, &error))
        {
          xfce_dialog_show_error (NULL, error, _("Failed to migrate the existing configuration"));
          g_error_free (error);
          retval = EXIT_FAILURE;
        }
      else
        {
          g_message (_("Panel configuration has been updated."));
        }

      /* migration complete, set new version */
      xfconf_channel_set_int (channel, "/configver", XFCE4_PANEL_CONFIG_VERSION);
    }

  xfconf_shutdown ();

  return retval;
}
Example #13
0
static void
fit_dialog(FitArgs *args)
{
    GtkWidget *label, *dialog, *hbox, *hbox2, *table, *align, *expander, *scroll;
    GtkTable *table2;
    GwyGraphModel *gmodel;
    GwyGraphCurveModel *cmodel;
    GwyGraphArea *area;
    GwySelection *selection;
    GwySIUnit *siunit;
    FitControls controls;
    gint response, row;
    GString *report;
    gdouble xmin, xmax;

    controls.args = args;
    controls.in_update = TRUE;
    controls.param = g_array_new(FALSE, TRUE, sizeof(FitParamControl));

    gmodel = gwy_graph_get_model(GWY_GRAPH(args->parent_graph));
    gwy_graph_model_get_x_range(gmodel, &xmin, &xmax);
    g_object_get(gmodel, "si-unit-x", &siunit, NULL);
    args->abscissa_vf
        = gwy_si_unit_get_format_with_digits(siunit,
                                             GWY_SI_UNIT_FORMAT_VFMARKUP,
                                             MAX(fabs(xmin), fabs(xmax)), 4,
                                             NULL);
    g_object_unref(siunit);

    dialog = gtk_dialog_new_with_buttons(_("Fit FD Curve"), NULL, 0, NULL);
    controls.dialog = dialog;
    gtk_dialog_add_action_widget(GTK_DIALOG(dialog),
                                 gwy_stock_like_button_new(gwy_sgettext("verb|_Fit"),
                                                           GTK_STOCK_EXECUTE),
                                 RESPONSE_FIT);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          gwy_sgettext("verb|_Estimate"), RESPONSE_ESTIMATE);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          _("_Plot Inits"), RESPONSE_PLOT);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          GTK_STOCK_SAVE, RESPONSE_SAVE);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
    gtk_dialog_add_button(GTK_DIALOG(dialog),
                          GTK_STOCK_OK, GTK_RESPONSE_OK);
    gwy_help_add_to_graph_dialog(GTK_DIALOG(dialog), GWY_HELP_DEFAULT);
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);

    hbox = gtk_hbox_new(FALSE, 2);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, TRUE, 0);

    /* Graph */
    args->graph_model = gwy_graph_model_new_alike(gmodel);
    controls.graph = gwy_graph_new(args->graph_model);
    g_object_unref(args->graph_model);
    gtk_widget_set_size_request(controls.graph, 400, 300);

    gwy_graph_enable_user_input(GWY_GRAPH(controls.graph), FALSE);
    gtk_box_pack_start(GTK_BOX(hbox), controls.graph, TRUE, TRUE, 0);
    gwy_graph_set_status(GWY_GRAPH(controls.graph), GWY_GRAPH_STATUS_XSEL);

    area = GWY_GRAPH_AREA(gwy_graph_get_area(GWY_GRAPH(controls.graph)));
    selection = gwy_graph_area_get_selection(area, GWY_GRAPH_STATUS_XSEL);
    gwy_selection_set_max_objects(selection, 1);
    g_signal_connect(selection, "changed",
                     G_CALLBACK(graph_selected), &controls);

    gwy_graph_model_add_curve(controls.args->graph_model,
                              gwy_graph_model_get_curve(gmodel, args->curve));
    args->fitfunc = NULL;

    /* Controls */
    align = gtk_alignment_new(0.0, 0.0, 0.0, 0.0);
    gtk_box_pack_start(GTK_BOX(hbox), align, FALSE, FALSE, 0);
    g_signal_connect(align, "size-request", G_CALLBACK(grow_width), NULL);

    table = gtk_table_new(7, 2, FALSE);
    gtk_table_set_row_spacings(GTK_TABLE(table), 2);
    gtk_table_set_col_spacings(GTK_TABLE(table), 6);
    gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, FALSE, 0);
    gtk_container_set_border_width(GTK_CONTAINER(table), 4);
    row = 0;

    /* Curve to fit */
    label = gtk_label_new_with_mnemonic(_("_Graph curve:"));
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), label,
                     0, 1, row, row+1, GTK_FILL, 0, 0, 0);

    controls.curve = curve_selector_new(gmodel,
                                        G_CALLBACK(curve_changed), &controls,
                                        args->curve);
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), controls.curve);
    gtk_table_attach(GTK_TABLE(table), controls.curve,
                     1, 2, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
    row++;

    /* Fitted function */
    label = gtk_label_new_with_mnemonic(_("F_unction:"));
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), label,
                     0, 1, row, row+1, GTK_FILL, 0, 0, 0);

    controls.function = function_selector_new(G_CALLBACK(function_changed),
                                              &controls, args->function_type);
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), controls.function);
    
    gtk_table_attach(GTK_TABLE(table), controls.function,
                     1, 2, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
    row++;

    controls.formula = gtk_label_new("f(x) =");
    gtk_misc_set_alignment(GTK_MISC(controls.formula), 0.0, 0.5);
    gtk_label_set_selectable(GTK_LABEL(controls.formula), TRUE);
    
    scroll = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), controls.formula);
    
    gtk_table_attach(GTK_TABLE(table), scroll,
                     0, 2, row, row+1, GTK_FILL, 0, 0, 8);
    row++;

    /* Parameters sought */
    controls.param_table = gtk_table_new(1, 10, FALSE);
    table2 = GTK_TABLE(controls.param_table);
    gtk_table_set_row_spacing(table2, 0, 2);
    gtk_table_set_col_spacings(table2, 2);
    gtk_table_set_col_spacing(table2, 0, 6);
    gtk_table_set_col_spacing(table2, 4, 6);
    gtk_table_set_col_spacing(table2, 5, 6);
    gtk_table_set_col_spacing(table2, 7, 6);
    gtk_table_set_col_spacing(table2, 8, 6);
    gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(table2),
                     0, 2, row, row+1, GTK_FILL, 0, 0, 0);
    gtk_table_set_row_spacing(GTK_TABLE(table), row, 8);
    row++;

    gtk_table_attach(table2, gwy_label_new_header(_("Fix")),
                     0, 1, 0, 1, GTK_FILL, 0, 0, 0);
    gtk_table_attach(table2, gwy_label_new_header(_("Parameter")),
                     1, 5, 0, 1, GTK_FILL, 0, 0, 0);
    gtk_table_attach(table2, gwy_label_new_header(_("Error")),
                     6, 8, 0, 1, GTK_FILL, 0, 0, 0);
    gtk_table_attach(table2, gwy_label_new_header(_("Initial")),
                     9, 10, 0, 1, GTK_FILL, 0, 0, 0);

    /* Make space for 4 parameters */
#if 0
    for (i = 0; i < 4; i++)
        fit_param_row_create(&controls, i, table2, i+1);
#endif

    /* Chi^2 */
    label = gtk_label_new(NULL);
    gtk_label_set_markup(GTK_LABEL(label), _("Ļ‡<sup>2</sup> result:"));
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), label,
                     0, 1, row, row+1, GTK_FILL, 0, 0, 0);

    controls.chisq = gtk_label_new(NULL);
    gtk_misc_set_alignment(GTK_MISC(controls.chisq), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), controls.chisq,
                     1, 2, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);

    gtk_table_set_row_spacing(GTK_TABLE(table), row, 8);
    row++;

    /* Correlation matrix */
    expander = gtk_expander_new(NULL);
    gtk_expander_set_label_widget(GTK_EXPANDER(expander),
                                 gwy_label_new_header(_("Correlation Matrix")));
    gtk_table_attach(GTK_TABLE(table), expander,
                     0, 2, row, row+1, GTK_FILL, 0, 0, 0);
    gtk_table_set_row_spacing(GTK_TABLE(table), row, 8);
    row++;

    align = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
    gtk_container_add(GTK_CONTAINER(expander), align);
    row++;

    controls.covar = g_array_new(FALSE, TRUE, sizeof(GtkWidget*));
    controls.covar_table = gtk_table_new(1, 1, TRUE);
    table2 = GTK_TABLE(controls.covar_table);
    gtk_table_set_col_spacings(table2, 6);
    gtk_table_set_row_spacings(table2, 2);
    gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(table2));

    /* Fit area */
    hbox2 = gtk_hbox_new(FALSE, 6);
    gtk_table_attach(GTK_TABLE(table), hbox2,
                     0, 2, row, row+1, GTK_FILL, 0, 0, 0);
    row++;

    label = gtk_label_new(_("Range:"));
    gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);

    controls.from = gtk_entry_new();
    g_object_set_data(G_OBJECT(controls.from), "id", (gpointer)"from");
    gtk_entry_set_width_chars(GTK_ENTRY(controls.from), 8);
    gtk_box_pack_start(GTK_BOX(hbox2), controls.from, FALSE, FALSE, 0);
    g_signal_connect(controls.from, "activate",
                     G_CALLBACK(range_changed), &controls);
    gwy_widget_set_activate_on_unfocus(controls.from, TRUE);

    label = gtk_label_new(gwy_sgettext("range|to"));
    gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);

    controls.to = gtk_entry_new();
    g_object_set_data(G_OBJECT(controls.to), "id", (gpointer)"to");
    gtk_entry_set_width_chars(GTK_ENTRY(controls.to), 8);
    gtk_box_pack_start(GTK_BOX(hbox2), controls.to, FALSE, FALSE, 0);
    g_signal_connect(controls.to, "activate",
                     G_CALLBACK(range_changed), &controls);
    gwy_widget_set_activate_on_unfocus(controls.to, TRUE);

    label = gtk_label_new(NULL);
    gtk_label_set_markup(GTK_LABEL(label), args->abscissa_vf->units);
    gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);

    /* Auto-update */
    hbox2 = gtk_hbox_new(FALSE, 6);
    gtk_table_attach(GTK_TABLE(table), hbox2,
                     0, 2, row, row+1, GTK_FILL, 0, 0, 0);
    row++;

    label = gtk_label_new(_("Instant:"));
    gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);

    controls.auto_estimate = gtk_check_button_new_with_mnemonic(_("e_stimate"));
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(controls.auto_estimate),
                                 args->auto_estimate);
    gtk_box_pack_start(GTK_BOX(hbox2), controls.auto_estimate, FALSE, FALSE, 0);
    g_signal_connect(controls.auto_estimate, "toggled",
                     G_CALLBACK(auto_estimate_changed), &controls);

    controls.auto_plot = gtk_check_button_new_with_mnemonic(_("p_lot"));
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(controls.auto_plot),
                                 args->auto_plot);
    gtk_box_pack_start(GTK_BOX(hbox2), controls.auto_plot, FALSE, FALSE, 0);
    g_signal_connect(controls.auto_plot, "toggled",
                     G_CALLBACK(auto_plot_changed), &controls);

    function_changed(GTK_COMBO_BOX(controls.function), &controls);
    graph_selected(selection, -1, &controls);

    controls.in_update = FALSE;
    gtk_widget_show_all(dialog);

    do {
        response = gtk_dialog_run(GTK_DIALOG(dialog));
        fit_fetch_entry(&controls);
        switch (response) {
            case GTK_RESPONSE_CANCEL:
            case GTK_RESPONSE_DELETE_EVENT:
            gtk_widget_destroy(dialog);
            fit_controls_free(&controls);
            return;
            break;

            case GTK_RESPONSE_OK:
            if (args->is_estimated) {
                cmodel = gwy_graph_model_get_curve(args->graph_model, 1);
                gwy_graph_model_add_curve(gmodel, cmodel);
            }
            gtk_widget_destroy(dialog);
            break;

            case RESPONSE_SAVE:
            report = create_fit_report(args);
            gwy_save_auxiliary_data(_("Save Fit Report"), GTK_WINDOW(dialog),
                                    -1, report->str);
            g_string_free(report, TRUE);
            break;

            case RESPONSE_ESTIMATE:
            fit_estimate(&controls);
            break;

            case RESPONSE_PLOT:
            fit_set_state(&controls, FALSE, TRUE);
            fit_plot_curve(args);
            break;

            case RESPONSE_FIT:
            fit_do(&controls);
            break;

            default:
            g_assert_not_reached();
            break;
        }
    } while (response != GTK_RESPONSE_OK);
    fit_controls_free(&controls);
}
static void
create_account_details_ui (GoaProvider    *provider,
                           GtkDialog      *dialog,
                           GtkBox         *vbox,
                           gboolean        new_account,
                           AddAccountData *data)
{
  GtkWidget *grid0;
  GtkWidget *grid1;
  GtkWidget *grid2;
  GtkWidget *hbox;
  gint width;

  goa_utils_set_dialog_title (provider, dialog, new_account);

  grid0 = gtk_grid_new ();
  gtk_container_set_border_width (GTK_CONTAINER (grid0), 5);
  gtk_widget_set_margin_bottom (grid0, 6);
  gtk_orientable_set_orientation (GTK_ORIENTABLE (grid0), GTK_ORIENTATION_VERTICAL);
  gtk_grid_set_row_spacing (GTK_GRID (grid0), 12);
  gtk_container_add (GTK_CONTAINER (vbox), grid0);

  data->cluebar = gtk_info_bar_new ();
  gtk_info_bar_set_message_type (GTK_INFO_BAR (data->cluebar), GTK_MESSAGE_ERROR);
  gtk_widget_set_hexpand (data->cluebar, TRUE);
  gtk_widget_set_no_show_all (data->cluebar, TRUE);
  gtk_container_add (GTK_CONTAINER (grid0), data->cluebar);

  data->cluebar_label = gtk_label_new ("");
  gtk_label_set_line_wrap (GTK_LABEL (data->cluebar_label), TRUE);
  gtk_container_add (GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (data->cluebar))),
                     data->cluebar_label);

  grid1 = gtk_grid_new ();
  gtk_orientable_set_orientation (GTK_ORIENTABLE (grid1), GTK_ORIENTATION_VERTICAL);
  gtk_grid_set_row_spacing (GTK_GRID (grid1), 12);

  grid2 = gtk_grid_new ();
  gtk_orientable_set_orientation (GTK_ORIENTABLE (grid2), GTK_ORIENTATION_VERTICAL);
  gtk_grid_set_row_spacing (GTK_GRID (grid2), 12);

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
  gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
  gtk_box_pack_start (GTK_BOX (hbox), grid1, FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), grid2, TRUE, TRUE, 0);
  gtk_container_add (GTK_CONTAINER (grid0), hbox);

  add_entry (grid1, grid2, _("_E-mail"), &data->email_address);
  add_entry (grid1, grid2, _("_Password"), &data->password);
  if (new_account)
    {
      data->expander = gtk_expander_new_with_mnemonic (_("_Custom"));
      gtk_expander_set_expanded (GTK_EXPANDER (data->expander), FALSE);
      gtk_expander_set_resize_toplevel (GTK_EXPANDER (data->expander), TRUE);
      gtk_container_add (GTK_CONTAINER (grid0), data->expander);

      grid1 = gtk_grid_new ();
      gtk_orientable_set_orientation (GTK_ORIENTABLE (grid1), GTK_ORIENTATION_VERTICAL);
      gtk_grid_set_row_spacing (GTK_GRID (grid1), 12);

      grid2 = gtk_grid_new ();
      gtk_orientable_set_orientation (GTK_ORIENTABLE (grid2), GTK_ORIENTATION_VERTICAL);
      gtk_grid_set_row_spacing (GTK_GRID (grid2), 12);

      hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
      gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
      gtk_box_pack_start (GTK_BOX (hbox), grid1, FALSE, FALSE, 0);
      gtk_box_pack_start (GTK_BOX (hbox), grid2, TRUE, TRUE, 0);
      gtk_container_add (GTK_CONTAINER (data->expander), hbox);

      add_entry (grid1, grid2, _("User_name"), &data->username);
      add_entry (grid1, grid2, _("_Server"), &data->server);
    }

  gtk_entry_set_visibility (GTK_ENTRY (data->password), FALSE);

  gtk_widget_grab_focus ((new_account) ? data->email_address : data->password);

  g_signal_connect (data->email_address, "changed", G_CALLBACK (on_email_address_or_password_changed), data);
  g_signal_connect (data->password, "changed", G_CALLBACK (on_email_address_or_password_changed), data);

  data->spinner_button = goa_spinner_button_new_from_stock (GTK_STOCK_CONNECT);
  gtk_dialog_add_action_widget (data->dialog, data->spinner_button, GTK_RESPONSE_OK);
  gtk_dialog_set_default_response (data->dialog, GTK_RESPONSE_OK);
  gtk_dialog_set_response_sensitive (data->dialog, GTK_RESPONSE_OK, FALSE);

  gtk_window_get_size (GTK_WINDOW (data->dialog), &width, NULL);
  gtk_widget_set_size_request (GTK_WIDGET (data->dialog), width, -1);
}
Example #15
0
static int
extract_cb (GtkWidget   *w,
	    DialogData  *data)
{
	FrWindow   *window = data->window;
	gboolean    do_not_extract = FALSE;
	GFile      *destination;
	gboolean    skip_newer;
	gboolean    selected_files;
	gboolean    pattern_files;
	gboolean    junk_paths;
	GList      *file_list;
	char       *base_dir = NULL;
	GError     *error = NULL;

	data->extract_clicked = TRUE;

	/* collect extraction options. */

	destination = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (data->dialog));

	/* check directory existence. */

	if (! _g_file_query_is_dir (destination)) {
		if (! ForceDirectoryCreation) {
			GtkWidget *d;
			int        r;
			char      *folder_name;
			char      *msg;

			folder_name = _g_file_get_display_basename (destination);
			msg = g_strdup_printf (_("Destination folder \"%s\" does not exist.\n\nDo you want to create it?"), folder_name);
			g_free (folder_name);

			d = _gtk_message_dialog_new (GTK_WINDOW (data->dialog),
						     GTK_DIALOG_MODAL,
						     msg,
						     NULL,
						     _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
						     _("Create _Folder"), GTK_RESPONSE_YES,
						     NULL);

			gtk_dialog_set_default_response (GTK_DIALOG (d), GTK_RESPONSE_YES);
			r = gtk_dialog_run (GTK_DIALOG (d));
			gtk_widget_destroy (GTK_WIDGET (d));

			g_free (msg);

			if (r != GTK_RESPONSE_YES)
				do_not_extract = TRUE;
		}

		if (! do_not_extract && ! _g_file_make_directory_tree (destination, 0755, &error)) {
			GtkWidget  *d;

			d = _gtk_error_dialog_new (GTK_WINDOW (window),
						   GTK_DIALOG_DESTROY_WITH_PARENT,
						   NULL,
						   _("Extraction not performed"),
						   _("Could not create the destination folder: %s."),
						   error->message);
			gtk_dialog_run (GTK_DIALOG (d));
			gtk_widget_destroy (GTK_WIDGET (d));

			g_error_free (error);

			return FALSE;
		}
	}

	if (do_not_extract) {
		GtkWidget *d;

		d = _gtk_message_dialog_new (GTK_WINDOW (window),
					     GTK_DIALOG_DESTROY_WITH_PARENT,
					     _("Extraction not performed"),
					     NULL,
					     _GTK_LABEL_CLOSE, GTK_RESPONSE_OK,
					     NULL);
		gtk_dialog_set_default_response (GTK_DIALOG (d), GTK_RESPONSE_OK);
		gtk_dialog_run (GTK_DIALOG (d));
		gtk_widget_destroy (GTK_WIDGET (d));

		if (fr_window_is_batch_mode (data->window))
			gtk_widget_destroy (data->dialog);

		return FALSE;
	}

	/* check extraction directory permissions. */

	if (_g_file_query_is_dir (destination)
	    && ! _g_file_check_permissions (destination, R_OK | W_OK))
	{
		GtkWidget *d;
		char      *utf8_path;

		utf8_path = _g_file_get_display_basename (destination);

		d = _gtk_error_dialog_new (GTK_WINDOW (window),
					   GTK_DIALOG_DESTROY_WITH_PARENT,
					   NULL,
					   _("Extraction not performed"),
					   _("You don't have the right permissions to extract archives in the folder \"%s\""),
					   utf8_path);
		gtk_dialog_run (GTK_DIALOG (d));
		gtk_widget_destroy (GTK_WIDGET (d));

		g_free (utf8_path);
		g_object_unref (destination);

		return FALSE;
	}

	fr_window_set_extract_default_dir (window, destination);

	skip_newer = ! gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (GET_WIDGET ("keep_newer_checkbutton"))) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("keep_newer_checkbutton")));
	junk_paths = ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("keep_structure_checkbutton")));

	if (! gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (GET_WIDGET ("keep_newer_checkbutton"))))
		g_settings_set_boolean (data->settings, PREF_EXTRACT_SKIP_NEWER, skip_newer);
	g_settings_set_boolean (data->settings, PREF_EXTRACT_RECREATE_FOLDERS, ! junk_paths);

	selected_files = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("selected_files_radiobutton")));
	pattern_files = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("file_pattern_radiobutton")));

	/* create the file list. */

	file_list = NULL;

	if (selected_files) {
		file_list = data->selected_files;
		data->selected_files = NULL;       /* do not the list when destroying the dialog. */
	}
	else if (pattern_files) {
		const char *pattern;

		pattern = gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("file_pattern_entry")));
		file_list = fr_window_get_file_list_pattern (window, pattern);
		if (file_list == NULL) {
			gtk_widget_destroy (data->dialog);
			g_object_unref (destination);
			return FALSE;
		}
	}

	if (selected_files) {
		base_dir = data->base_dir_for_selection;
		data->base_dir_for_selection = NULL;
	}
	else
		base_dir = NULL;

	/* close the dialog. */

	gtk_widget_destroy (data->dialog);

	/* extract ! */

	fr_window_extract_archive_and_continue (window,
				       	        file_list,
						destination,
						base_dir,
						skip_newer,
						FR_OVERWRITE_ASK,
						junk_paths);

	_g_string_list_free (file_list);
	g_object_unref (destination);
	g_free (base_dir);

	return TRUE;
}
Example #16
0
/*! \brief Creates the hotkeys dialog
 *  \par Function Description
 *  This function creates the hotkey dialog and puts the list of hotkeys
 *  into it.
 */
void x_dialog_hotkeys (GschemToplevel *w_current)
{
  GtkWidget *vbox, *scrolled_win;
  GtkTreeModel *store;
  GtkWidget *treeview;
  GtkCellRenderer *renderer;
  GtkTreeViewColumn *column;

  if (!w_current->hkwindow) {
    w_current->hkwindow = gschem_dialog_new_with_buttons(_("Hotkeys"),
                                                         GTK_WINDOW(w_current->main_window),
                                                         0, /* not modal */
                                                         "hotkeys", w_current,
                                                         GTK_STOCK_CLOSE,
                                                         GTK_RESPONSE_REJECT,
                                                         NULL);

    gtk_window_set_position (GTK_WINDOW (w_current->hkwindow), GTK_WIN_POS_NONE);

    g_signal_connect (G_OBJECT (w_current->hkwindow), "response",
                      G_CALLBACK (x_dialog_hotkeys_response),
                      w_current);

    gtk_dialog_set_default_response(GTK_DIALOG(w_current->hkwindow),
                                    GTK_RESPONSE_ACCEPT);

    gtk_container_set_border_width (GTK_CONTAINER (w_current->hkwindow),
                                    DIALOG_BORDER_SPACING);
    gtk_widget_set_size_request (w_current->hkwindow, 300, 300);

    vbox = GTK_DIALOG(w_current->hkwindow)->vbox;
    gtk_box_set_spacing(GTK_BOX(vbox), DIALOG_V_SPACING);

    scrolled_win = gtk_scrolled_window_new (NULL, NULL);
    gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);

    /* the model */
    store = GTK_TREE_MODEL (gschem_hotkey_store_new ());

    /* the tree view */
    treeview = gtk_tree_view_new_with_model (store);
    gtk_container_add(GTK_CONTAINER(scrolled_win), treeview);

    /* the columns */
    /* The first column contains the action's icon (if one was set)
     * and its label. */
    renderer = gtk_cell_renderer_pixbuf_new ();
    column = gtk_tree_view_column_new_with_attributes (_("Action"),
                                                       renderer,
                                                       "stock-id",
                                                       GSCHEM_HOTKEY_STORE_COLUMN_ICON,
                                                       NULL);
    /* Fix things up to show stock icons *and* theme icons. */
    g_signal_connect (renderer, "notify::stock-id",
                      G_CALLBACK (x_dialog_hotkeys_cell_stock_id_notify),
                      NULL);

    renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_column_pack_start (column, renderer, FALSE);
    gtk_tree_view_column_set_attributes (column, renderer,
                                         "text", GSCHEM_HOTKEY_STORE_COLUMN_LABEL,
                                         NULL);

    /* The second column contains the action's keybinding */
    gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
    column = gtk_tree_view_column_new_with_attributes (_("Keystroke(s)"),
                                                       renderer,
                                                       "text",
                                                       GSCHEM_HOTKEY_STORE_COLUMN_KEYS,
                                                       NULL);
    gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);

    /* show all recursively */
    gtk_widget_show_all(w_current->hkwindow);
  }

  else { /* dialog already created */
    gtk_window_present(GTK_WINDOW(w_current->hkwindow));
  }
}
Example #17
0
/* Caller must g_free() the returned filename.*/
gchar *
ghid_dialog_file_select_open (gchar * title, gchar ** path, gchar * shortcuts)
{
  GtkWidget *dialog;
  gchar *result = NULL, *folder, *seed;
  GHidPort *out = &ghid_port;
  GtkFileFilter *no_filter;

  dialog = gtk_file_chooser_dialog_new (title,
					GTK_WINDOW (out->top_window),
					GTK_FILE_CHOOSER_ACTION_OPEN,
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					GTK_STOCK_OK, GTK_RESPONSE_OK,
					NULL);

  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

  /* add a default filter for not filtering files */
  no_filter = gtk_file_filter_new ();
  gtk_file_filter_set_name (no_filter, "all");
  gtk_file_filter_add_pattern (no_filter, "*.*");
  gtk_file_filter_add_pattern (no_filter, "*");
  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), no_filter);

  /* in case we have a dialog for loading a footprint file */
  if (strcmp (title, _("Load element to buffer")) == 0)
  {
    /* add a filter for footprint files */
    GtkFileFilter *fp_filter;
    fp_filter = gtk_file_filter_new ();
    gtk_file_filter_set_name (fp_filter, "fp");
    gtk_file_filter_add_mime_type (fp_filter, "application/x-pcb-footprint");
    gtk_file_filter_add_pattern (fp_filter, "*.fp");
    gtk_file_filter_add_pattern (fp_filter, "*.FP");
    gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), fp_filter);
  }

  /* in case we have a dialog for loading a layout file */
  if ((strcmp (title, _("Load layout file")) == 0)
    || (strcmp (title, _("Load layout file to buffer")) == 0))
  {
    /* add a filter for layout files */
    GtkFileFilter *pcb_filter;
    pcb_filter = gtk_file_filter_new ();
    gtk_file_filter_set_name (pcb_filter, "pcb");
    gtk_file_filter_add_mime_type (pcb_filter, "application/x-pcb-layout");
    gtk_file_filter_add_pattern (pcb_filter, "*.pcb");
    gtk_file_filter_add_pattern (pcb_filter, "*.PCB");
    gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), pcb_filter);
  }

  /* in case we have a dialog for loading a netlist file */
  if (strcmp (title, _("Load netlist file")) == 0)
  {
    /* add a filter for netlist files */
    GtkFileFilter *net_filter;
    net_filter = gtk_file_filter_new ();
    gtk_file_filter_set_name (net_filter, "netlist");
    gtk_file_filter_add_mime_type (net_filter, "application/x-pcb-netlist");
    gtk_file_filter_add_pattern (net_filter, "*.net");
    gtk_file_filter_add_pattern (net_filter, "*.NET");
    gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), net_filter);
  }

  if (path && *path)
    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), *path);

  if (shortcuts && *shortcuts)
    {
      folder = g_strdup (shortcuts);
      seed = folder;
      while ((folder = strtok (seed, ":")) != NULL)
	{
	  gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
						folder, NULL);
	  seed = NULL;
	}
      g_free (folder);
    }

  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
    {
      result = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
      folder =
	gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
      if (folder && path)
	{
	  dup_string (path, folder);
	  g_free (folder);
	}
    }
  gtk_widget_destroy (dialog);


  return result;
}
GtkWidget *
totem_open_location_new (void)
{
    TotemOpenLocation *open_location;
    char *clipboard_location;
    GtkEntryCompletion *completion;
    GtkTreeModel *model;
    GList *recent_items, *streams_recent_items = NULL;

    open_location = TOTEM_OPEN_LOCATION (g_object_new (TOTEM_TYPE_OPEN_LOCATION,
                                         "use-header-bar", 1, NULL));

    if (open_location->priv->uri_container == NULL) {
        g_object_unref (open_location);
        return NULL;
    }

    gtk_window_set_title (GTK_WINDOW (open_location), _("Add Web Video"));
    gtk_dialog_add_buttons (GTK_DIALOG (open_location),
                            _("_Cancel"), GTK_RESPONSE_CANCEL,
                            _("_Add"), GTK_RESPONSE_OK,
                            NULL);
    gtk_dialog_set_response_sensitive (GTK_DIALOG (open_location), GTK_RESPONSE_OK, FALSE);
    gtk_container_set_border_width (GTK_CONTAINER (open_location), 5);
    gtk_dialog_set_default_response (GTK_DIALOG (open_location), GTK_RESPONSE_OK);

    /* Get item from clipboard to fill GtkEntry */
    clipboard_location = totem_open_location_set_from_clipboard (open_location);
    if (clipboard_location != NULL && strcmp (clipboard_location, "") != 0)
        gtk_entry_set_text (open_location->priv->uri_entry, clipboard_location);
    g_free (clipboard_location);

    /* Add items in Totem's GtkRecentManager to the URI GtkEntry's GtkEntryCompletion */
    completion = gtk_entry_completion_new();
    model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
    gtk_entry_set_completion (open_location->priv->uri_entry, completion);

    recent_items = gtk_recent_manager_get_items (gtk_recent_manager_get_default ());

    if (recent_items != NULL)
    {
        GList *p;
        GtkTreeIter iter;

        /* Filter out non-Totem items */
        for (p = recent_items; p != NULL; p = p->next)
        {
            GtkRecentInfo *info = (GtkRecentInfo *) p->data;
            if (!gtk_recent_info_has_group (info, "TotemStreams")) {
                gtk_recent_info_unref (info);
                continue;
            }
            streams_recent_items = g_list_prepend (streams_recent_items, info);
        }

        streams_recent_items = g_list_sort (streams_recent_items, (GCompareFunc) totem_compare_recent_stream_items);

        /* Populate the list store for the combobox */
        for (p = streams_recent_items; p != NULL; p = p->next)
        {
            GtkRecentInfo *info = (GtkRecentInfo *) p->data;
            gtk_list_store_append (GTK_LIST_STORE (model), &iter);
            gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, gtk_recent_info_get_uri (info), -1);
            gtk_recent_info_unref (info);
        }

        g_list_free (streams_recent_items);
    }

    g_list_free (recent_items);

    gtk_entry_completion_set_model (completion, model);
    gtk_entry_completion_set_text_column (completion, 0);
    gtk_entry_completion_set_match_func (completion, (GtkEntryCompletionMatchFunc) totem_open_location_match, model, NULL);

    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (open_location))),
                        open_location->priv->uri_container,
                        TRUE,       /* expand */
                        TRUE,       /* fill */
                        0);         /* padding */

    gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (open_location)));

    return GTK_WIDGET (open_location);
}
Example #19
0
/* Caller must g_free() the returned filename. */
gchar *
ghid_fileselect (const char *title, const char *descr,
                 char *default_file, char *default_ext,
		 const char *history_tag, int flags)
{
  GtkWidget *dialog;
  gchar *result = NULL;
  GHidPort *out = &ghid_port;
  gchar *path = NULL, *base = NULL;
  int history_pool = -1;
  int i;
 
  if (history_tag && *history_tag)
    {
      /* 
       * I used a simple linear search here because the number of
       * entries in the array is likely to be quite small (5, maybe 10 at
       * the absolute most) and this function is used when pulling up
       * a file dialog box instead of something called over and over
       * again as part of moving elements or autorouting.  So, keep it
       * simple....
       */
      history_pool = 0;
      while (history_pool < n_recent_dirs &&
	     strcmp (recent_dirs[history_pool].id, history_tag) != 0)
	{
	  history_pool++;
	}
      
      /*
       * If we counted all the way to n_recent_dirs, that means we
       * didn't find our entry
       */
      if (history_pool >= n_recent_dirs)
	{
	  n_recent_dirs++;

	  recent_dirs = (ghid_file_history *)realloc (recent_dirs, 
				  n_recent_dirs * sizeof (ghid_file_history));

	  if (recent_dirs == NULL)
	    {
	      fprintf (stderr, "%s():  realloc failed\n", __FUNCTION__);
	      exit (1);
	    }
	  
	  recent_dirs[history_pool].id = strdup (history_tag);

	  /* Initialize the entries in our history list to all be NULL */
	  for (i = 0; i < NHIST; i++)
	    {
	      recent_dirs[history_pool].history[i] = NULL;
	    }
	}
    }

  if (default_file && *default_file)
    {
      path = g_path_get_dirname (default_file);
      base = g_path_get_basename (default_file);
    }

  dialog = gtk_file_chooser_dialog_new (title,
					GTK_WINDOW (out->top_window),
					(flags & HID_FILESELECT_READ) ? 
					GTK_FILE_CHOOSER_ACTION_OPEN : 
					GTK_FILE_CHOOSER_ACTION_SAVE,
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					GTK_STOCK_OK, GTK_RESPONSE_OK,
					NULL);

  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

  if (path && *path )
    {
      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), path);
      g_free (path);
    }

  if (base && *base)
    {
      /* default file is only supposed to be for writing, not reading */
      if (!(flags & HID_FILESELECT_READ))
	{
	  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), base);
	}
      g_free (base);
    }

  for (i = 0; i < NHIST && recent_dirs[history_pool].history[i] != NULL ; i++)
    {
      gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
					    recent_dirs[history_pool].history[i], 
					    NULL);
    }

  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
    {
      result = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
      if (result != NULL)
	path = g_path_get_dirname (result);
      else
	path = NULL;

      /* update the history list */
      if (path != NULL)
	{
	  char *tmps, *tmps2;
	  int k = 0;

	  /* 
	   * Put this at the top of the list and bump everything else
	   * down but skip any old entry of this directory
	   *
	   */
	  while ( k < NHIST &&
		 recent_dirs[history_pool].history[k] != NULL &&
		 strcmp ( recent_dirs[history_pool].history[k], path) == 0)
	    {
	      k++;
	    }
	  tmps = recent_dirs[history_pool].history[k];
	  recent_dirs[history_pool].history[0] = path;
	  for (i = 1 ; i < NHIST ; i++)
	    {
	      /* store our current entry, but skip duplicates */
	      while (i + k < NHIST &&
		     recent_dirs[history_pool].history[i + k] != NULL &&
		     strcmp ( recent_dirs[history_pool].history[i + k], path) == 0)
		{
		  k++;
		}
		     
	      if (i + k < NHIST)
		tmps2 = recent_dirs[history_pool].history[i + k];
	      else
		tmps2 = NULL;

	      /* move down the one we stored last time */
	      recent_dirs[history_pool].history[i] = tmps;

	      /* and remember the displace entry */
	      tmps = tmps2;
	    }

	  /* 
	   * the last one has fallen off the end of the history list
	   * so we need to free() it.
	   */
	  if (tmps)
	    {
	      free (tmps);
	    }
	}
      
#ifdef DEBUG
      printf ("\n\n-----\n\n");
      for (i = 0 ; i < NHIST ; i++)
	{
	  printf ("After update recent_dirs[%d].history[%d] = \"%s\"\n",
		  history_pool, i, recent_dirs[history_pool].history[i] != NULL ?
		  recent_dirs[history_pool].history[i] : "NULL");
	}
#endif

    }
  gtk_widget_destroy (dialog);


  return result;
}
int
xfsm_splash_screen_choose (XfsmSplashScreen *splash,
                           GList            *sessions,
                           const gchar      *default_session,
                           gchar           **name_return)
{
  GtkWidget *chooser;
  GtkWidget *label;
  GtkWidget *dialog;
  GtkWidget *entry;
  gchar      title[256];
  int        result;

  g_assert (default_session != NULL);

  if (splash->engine.choose != NULL)
    {
      result = splash->engine.choose (&splash->engine,
                                      sessions,
                                      default_session,
                                      name_return);
    }
  else
    {
again:
      xfsm_splash_screen_next (splash, _("Choose session"));

      chooser = g_object_new (XFSM_TYPE_CHOOSER,
                              "screen", splash->engine.primary_screen,
                              "type", GTK_WINDOW_POPUP,
                              NULL);
      xfsm_window_add_border (GTK_WINDOW (chooser));
      xfsm_chooser_set_sessions (XFSM_CHOOSER (chooser),
                                 sessions, default_session);
      result = xfsm_splash_screen_run (splash, chooser);

      if (result == XFSM_RESPONSE_LOAD)
        {
          if (name_return != NULL)
            *name_return = xfsm_chooser_get_session (XFSM_CHOOSER (chooser));
          result = XFSM_CHOOSE_LOAD;
        }
      else if (result == XFSM_RESPONSE_NEW)
        {
          result = XFSM_CHOOSE_NEW;
        }
      else
        {
          result = XFSM_CHOOSE_LOGOUT;
        }

      gtk_widget_destroy (chooser);

      if (result == XFSM_CHOOSE_NEW)
        {
          xfsm_splash_screen_next (splash, _("Choose session name"));

          dialog = gtk_dialog_new_with_buttons (NULL,
                                                NULL,
                                                GTK_DIALOG_NO_SEPARATOR,
                                                GTK_STOCK_CANCEL,
                                                GTK_RESPONSE_CANCEL,
                                                GTK_STOCK_OK,
                                                GTK_RESPONSE_OK,
                                                NULL);
          gtk_dialog_set_default_response (GTK_DIALOG (dialog),
                                           GTK_RESPONSE_OK);

          g_snprintf (title, 256, "<big>%s</big>",
                      _("Choose a name for the new session:"));
          label = gtk_label_new (title);
          gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
          gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
                              label, TRUE, TRUE, 6);
          gtk_widget_show (label);

          entry = gtk_entry_new ();
          gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
                              entry, TRUE, TRUE, 6);
          gtk_widget_show (entry);

          xfsm_window_add_border (GTK_WINDOW (dialog));

again1:
          result = xfsm_splash_screen_run (splash, dialog);

          if (result != GTK_RESPONSE_OK)
            {
              gtk_widget_destroy (dialog);
              goto again;
            }

          if (name_return != NULL)
            {
              *name_return = gtk_editable_get_chars (GTK_EDITABLE (entry),
                                                     0, -1);
              if (strlen (*name_return) == 0)
                {
                  g_free (*name_return);
                  goto again1;
                }
            }

          gtk_widget_destroy (dialog);
          result = XFSM_CHOOSE_NEW;
        }
    }

  return result;
}
Example #21
0
static void
mc_preferences_setup_dialog (GtkBuilder *builder,
			     MCData     *mc)
{
    MCPrefsDialog   *dialog;
    GtkCellRenderer *renderer;
    GdkRGBA          color;

    dialog = &mc->prefs_dialog;

    g_signal_connect (dialog->dialog, "response",
		      G_CALLBACK (preferences_response), mc);

    gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_CLOSE);
    gtk_window_set_default_size (GTK_WINDOW (dialog->dialog), 400, -1);

    dialog->auto_complete_history_toggle = GTK_WIDGET (gtk_builder_get_object (builder, "auto_complete_history_toggle"));
    dialog->size_spinner                 = GTK_WIDGET (gtk_builder_get_object (builder, "size_spinner"));
    dialog->use_default_theme_toggle     = GTK_WIDGET (gtk_builder_get_object (builder, "default_theme_toggle"));
    dialog->fg_color_picker              = GTK_WIDGET (gtk_builder_get_object (builder, "fg_color_picker"));
    dialog->bg_color_picker              = GTK_WIDGET (gtk_builder_get_object (builder, "bg_color_picker"));
    dialog->macros_tree                  = GTK_WIDGET (gtk_builder_get_object (builder, "macros_tree"));
    dialog->delete_button                = GTK_WIDGET (gtk_builder_get_object (builder, "delete_button"));
    dialog->add_button                   = GTK_WIDGET (gtk_builder_get_object (builder, "add_button"));

    /* History based autocompletion */
    g_signal_connect (dialog->auto_complete_history_toggle, "toggled",
		      G_CALLBACK (auto_complete_history_toggled), mc);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->auto_complete_history_toggle),
				  mc->preferences.auto_complete_history);
    if (!g_settings_is_writable (mc->settings, KEY_AUTOCOMPLETE_HISTORY))
	    hard_set_sensitive (dialog->auto_complete_history_toggle, FALSE);

    /* Width */
    gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->size_spinner), mc->preferences.normal_size_x);
    g_signal_connect (dialog->size_spinner, "value_changed",
		      G_CALLBACK (size_value_changed), mc); 
    if (!g_settings_is_writable (mc->settings, KEY_NORMAL_SIZE_X)) {
	    hard_set_sensitive (dialog->size_spinner, FALSE);
	    hard_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "size_label")), FALSE);
	    hard_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "size_post_label")), FALSE);
    }

    /* Use default theme */
    g_signal_connect (dialog->use_default_theme_toggle, "toggled",
		      G_CALLBACK (use_default_theme_toggled), mc);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->use_default_theme_toggle),
				  mc->preferences.show_default_theme);
    if (!g_settings_is_writable (mc->settings, KEY_SHOW_DEFAULT_THEME))
	    hard_set_sensitive (dialog->use_default_theme_toggle, FALSE);

    /* Foreground color */
    g_signal_connect (dialog->fg_color_picker, "color_set",
		      G_CALLBACK (foreground_color_set), mc);
    gdk_rgba_parse (&color, mc->preferences.cmd_line_color_fg);
    gtk_color_button_set_rgba (GTK_COLOR_BUTTON (dialog->fg_color_picker), &color);
    soft_set_sensitive (dialog->fg_color_picker, !mc->preferences.show_default_theme);

    if (!g_settings_is_writable (mc->settings, KEY_CMD_LINE_COLOR_FG)) {
	    hard_set_sensitive (dialog->fg_color_picker, FALSE);
	    hard_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "fg_color_label")), FALSE);
    }

    /* Background color */
    g_signal_connect (dialog->bg_color_picker, "color_set",
		      G_CALLBACK (background_color_set), mc);
    gdk_rgba_parse (&color, mc->preferences.cmd_line_color_bg);
    gtk_color_button_set_rgba (GTK_COLOR_BUTTON (dialog->bg_color_picker), &color);
    soft_set_sensitive (dialog->bg_color_picker, !mc->preferences.show_default_theme);

    if (!g_settings_is_writable (mc->settings, KEY_CMD_LINE_COLOR_BG)) {
	    hard_set_sensitive (dialog->bg_color_picker, FALSE);
	    hard_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "bg_color_label")), FALSE);
    }


    /* Macros Delete and Add buttons */
    g_signal_connect (dialog->delete_button, "clicked", G_CALLBACK (macro_delete), mc);
    g_signal_connect (dialog->add_button, "clicked", G_CALLBACK (macro_add), mc);

    if (!g_settings_is_writable (mc->global_settings, KEY_MACRO_PATTERNS) ||
	    !g_settings_is_writable (mc->global_settings, KEY_MACRO_COMMANDS)) {
	    hard_set_sensitive (dialog->add_button, FALSE);
	    hard_set_sensitive (dialog->delete_button, FALSE);
	    hard_set_sensitive (dialog->macros_tree, FALSE);
    }

    /* Macros tree view */
    dialog->macros_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING, NULL);
    gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->macros_tree),
			     GTK_TREE_MODEL (dialog->macros_store));

    renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, "editable", TRUE, NULL);
    g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_PATTERN));
    g_signal_connect (renderer, "edited", G_CALLBACK (macro_edited), mc);

    gtk_tree_view_insert_column_with_attributes (
			GTK_TREE_VIEW (dialog->macros_tree), -1,
			_("Pattern"), renderer,
			"text", COLUMN_PATTERN,
			NULL);

    renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, "editable", TRUE, NULL);
    g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_COMMAND));
    g_signal_connect (renderer, "edited", G_CALLBACK (macro_edited), mc);

    gtk_tree_view_insert_column_with_attributes (
			GTK_TREE_VIEW (dialog->macros_tree), -1,
			_("Command"), renderer,
			"text", COLUMN_COMMAND,
			NULL);

    show_macros_list (mc);
}
void
procdialog_create_renice_dialog (ProcData *procdata)
{
    ProcInfo  *info = procdata->selected_process;
    GtkWidget *dialog = NULL;
    GtkWidget *dialog_vbox;
    GtkWidget *vbox;
    GtkWidget *label;
    GtkWidget *priority_label;
    GtkWidget *grid;
    GtkAdjustment *renice_adj;
    GtkWidget *hscale;
    GtkWidget *button;
    GtkWidget *icon;
    gchar     *text;
    gchar     *dialog_title;

    if (renice_dialog)
        return;

    if (!info)
        return;

    dialog_title = g_strdup_printf (_("Change Priority of Process ā€œ%sā€ (PID: %u)"),
                                    info->name, info->pid);
    dialog = gtk_dialog_new_with_buttons (dialog_title, NULL,
                                          GTK_DIALOG_DESTROY_WITH_PARENT,
                                          "gtk-cancel", GTK_RESPONSE_CANCEL,
                                          NULL);
    g_free (dialog_title);

    renice_dialog = dialog;
    gtk_window_set_resizable (GTK_WINDOW (renice_dialog), FALSE);
    gtk_container_set_border_width (GTK_CONTAINER (renice_dialog), 5);

    button = gtk_button_new_with_mnemonic (_("Change _Priority"));
    gtk_widget_set_can_default (button, TRUE);

    icon = gtk_image_new_from_stock ("gtk-ok", GTK_ICON_SIZE_BUTTON);
    gtk_button_set_image (GTK_BUTTON (button), icon);

    gtk_dialog_add_action_widget (GTK_DIALOG (renice_dialog), button, 100);
    gtk_dialog_set_default_response (GTK_DIALOG (renice_dialog), 100);
    new_nice_value = -100;

    dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
    gtk_box_set_spacing (GTK_BOX (dialog_vbox), 2);
    gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);

    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
    gtk_box_pack_start (GTK_BOX (dialog_vbox), vbox, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);

    grid = gtk_grid_new ();
    gtk_grid_set_column_spacing (GTK_GRID(grid), 12);
    gtk_grid_set_row_spacing (GTK_GRID(grid), 6);
    gtk_box_pack_start (GTK_BOX (vbox), grid, TRUE, TRUE, 0);

    label = gtk_label_new_with_mnemonic (_("_Nice value:"));
    gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 2);

    renice_adj = gtk_adjustment_new (info->nice, RENICE_VAL_MIN, RENICE_VAL_MAX, 1, 1, 0);
    new_nice_value = 0;
    hscale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, renice_adj);
    gtk_label_set_mnemonic_widget (GTK_LABEL (label), hscale);
    gtk_scale_set_digits (GTK_SCALE (hscale), 0);
    gtk_widget_set_hexpand (hscale, TRUE);
    gtk_grid_attach (GTK_GRID (grid), hscale, 1, 0, 1, 1);
    text = g_strdup_printf(_("(%s Priority)"), procman::get_nice_level (info->nice));
    priority_label = gtk_label_new (text);
    gtk_grid_attach (GTK_GRID (grid), priority_label, 1, 1, 1, 1);
    g_free(text);

    text = g_strconcat("<small><i><b>", _("Note:"), "</b> ",
        _("The priority of a process is given by its nice value. A lower nice value corresponds to a higher priority."),
        "</i></small>", NULL);
    label = gtk_label_new (_(text));
    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
    gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
    gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
    g_free (text);

    g_signal_connect (G_OBJECT (dialog), "response",
                      G_CALLBACK (renice_dialog_button_pressed), procdata);
    g_signal_connect (G_OBJECT (renice_adj), "value_changed",
                      G_CALLBACK (renice_scale_changed), priority_label);

    gtk_widget_show_all (dialog);


}
Example #23
0
/* Opens a box allowing the user to change the name of a pinned icon.
 * If the icon is destroyed then the box will close.
 * If the user chooses OK then the callback is called once the icon's
 * name, src_path and path fields have been updated and the item field
 * restatted.
 */
static void show_rename_box(Icon *icon)
{
	GtkDialog	*dialog;
	GtkWidget	*label, *entry, *button, *button2, *hbox, *spacer, *lock_state;
	GtkBox		*vbox;

	if (icon->dialog)
	{
		gtk_window_present(GTK_WINDOW(icon->dialog));
		return;
	}

	icon->dialog = gtk_dialog_new();
	gtk_dialog_set_has_separator(GTK_DIALOG(icon->dialog), FALSE);
	g_signal_connect(icon->dialog, "destroy",
			G_CALLBACK(gtk_widget_destroyed), &icon->dialog);

	dialog = GTK_DIALOG(icon->dialog);
	
	vbox = GTK_BOX(gtk_vbox_new(FALSE, 1));
	gtk_box_pack_start(GTK_BOX(dialog->vbox), (GtkWidget *) vbox,
			   TRUE, TRUE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);

	gtk_window_set_title(GTK_WINDOW(dialog), _("Edit Item"));
	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);

	label = gtk_label_new(_("Clicking the icon opens:"));
	gtk_box_pack_start(vbox, label, TRUE, TRUE, 0);

	entry = gtk_entry_new();
	gtk_box_pack_start(vbox, entry, TRUE, FALSE, 2);
	gtk_entry_set_text(GTK_ENTRY(entry), icon->src_path);
	g_object_set_data(G_OBJECT(dialog), "new_path", entry);
	g_signal_connect_swapped(entry, "activate",
			G_CALLBACK(rename_activate), dialog);

	label = gtk_label_new(_("Arguments to pass (for executables):"));
	gtk_box_pack_start(vbox, label, TRUE, TRUE, 0);

	entry = gtk_entry_new();
	gtk_box_pack_start(vbox, entry, TRUE, FALSE, 2);
	gtk_entry_set_text(GTK_ENTRY(entry), icon->args ? icon->args : "");
	g_object_set_data(G_OBJECT(dialog), "new_arg", entry);
	g_signal_connect_swapped(entry, "activate",
			G_CALLBACK(rename_activate), dialog);

	spacer = gtk_drawing_area_new();
	gtk_widget_set_size_request(spacer, 4, 4);
	gtk_box_pack_start(vbox, spacer, FALSE, FALSE, 0);

	label = gtk_label_new(_("The text displayed under the icon is:"));
	gtk_box_pack_start(vbox, label, TRUE, TRUE, 0);
	entry = gtk_entry_new();
	gtk_box_pack_start(vbox, entry, TRUE, FALSE, 2);
	gtk_entry_set_text(GTK_ENTRY(entry), icon->item->leafname);
	gtk_widget_grab_focus(entry);
	g_object_set_data(G_OBJECT(dialog), "new_name", entry);
	gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
	
	spacer = gtk_drawing_area_new();
	gtk_widget_set_size_request(spacer, 4, 4);
	gtk_box_pack_start(vbox, spacer, FALSE, FALSE, 0);

	label = gtk_label_new(_("The keyboard shortcut is:"));
	gtk_box_pack_start(vbox, label, TRUE, TRUE, 0);

	hbox = gtk_hbox_new(FALSE, 2);
	gtk_box_pack_start(vbox, hbox, TRUE, FALSE, 0);
	button = gtk_button_new_with_label(icon->shortcut
						? icon->shortcut
						: CLICK_TO_SET);
	gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
	g_object_set_data(G_OBJECT(dialog), "new_shortcut",
				GTK_BIN(button)->child);
	g_signal_connect(button, "clicked",
			G_CALLBACK(get_shortcut),
			GTK_BIN(button)->child);
	button2 = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
	gtk_box_pack_start(GTK_BOX(hbox), button2, FALSE, FALSE, 0);
	g_signal_connect(button2, "clicked",
			G_CALLBACK(clear_shortcut),
			GTK_BIN(button)->child);
			
	lock_state = gtk_check_button_new_with_label(_("Locked"));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lock_state), icon->locked);
	gtk_box_pack_start(vbox, lock_state, TRUE, TRUE, 0);
	g_object_set_data(G_OBJECT(dialog), "new_lock_state", lock_state);
	gtk_tooltips_set_tip(tooltips, lock_state,
			_("Locking an item prevents it from being accidentally removed"),
			NULL);

	g_object_set_data(G_OBJECT(dialog), "callback_icon", icon);

	gtk_dialog_add_buttons(dialog,
			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
			GTK_STOCK_OK, GTK_RESPONSE_OK,
			NULL);
	gtk_dialog_set_default_response(dialog, GTK_RESPONSE_OK);

	g_signal_connect(dialog, "response", G_CALLBACK(edit_response), NULL);
	
	gtk_widget_show_all(GTK_WIDGET(dialog));
}
Example #24
0
/*! \brief Opens a file chooser for saving the current page.
 *  \par Function Description
 *  This function opens a file chooser dialog and wait for the user to
 *  select a file where the <B>toplevel</B>'s current page will be
 *  saved.
 *
 *  If the user cancels the operation (with the cancel button), the
 *  page is not saved.
 *
 *  The function updates the user interface.
 *
 *  \param [in] w_current The GSCHEM_TOPLEVEL environment.
 */
void
x_fileselect_save (GSCHEM_TOPLEVEL *w_current)
{
  TOPLEVEL *toplevel = w_current->toplevel;
  GtkWidget *dialog;

  dialog = gtk_file_chooser_dialog_new (_("Save as..."),
                                        GTK_WINDOW(w_current->main_window),
                                        GTK_FILE_CHOOSER_ACTION_SAVE,
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                        GTK_STOCK_SAVE,   GTK_RESPONSE_ACCEPT,
                                        NULL);

  /* Set the alternative button order (ok, cancel, help) for other systems */
  gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog),
					  GTK_RESPONSE_ACCEPT,
					  GTK_RESPONSE_CANCEL,
					  -1);

  /* set default response signal. This is usually triggered by the 
     "Return" key */
  gtk_dialog_set_default_response(GTK_DIALOG(dialog),
				  GTK_RESPONSE_ACCEPT);

  g_object_set (dialog,
                /* GtkFileChooser */
                "select-multiple", FALSE,
                /* only in GTK 2.8 */
                /* "do-overwrite-confirmation", TRUE, */
                NULL);
  /* add file filters to dialog */
  x_fileselect_setup_filechooser_filters (GTK_FILE_CHOOSER (dialog));
  /* set the current filename or directory name if new document */
  if ((toplevel->page_current->page_filename != NULL) &&
      g_file_test (toplevel->page_current->page_filename,
                   G_FILE_TEST_EXISTS)) {
    gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog),
                                   toplevel->page_current->page_filename);
  } else {
    gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
                                       "untitled.sch");
  }

  gtk_dialog_set_default_response(GTK_DIALOG(dialog),
				  GTK_RESPONSE_ACCEPT);
  gtk_widget_show (dialog);
  if (gtk_dialog_run ((GtkDialog*)dialog) == GTK_RESPONSE_ACCEPT) {
    gchar *filename =
      gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));

    /* If the file already exists, display a dialog box to check if
       the user really wants to overwrite it. */
    if ((filename != NULL) && g_file_test (filename, G_FILE_TEST_EXISTS)) {
      GtkWidget *checkdialog = 
        gtk_message_dialog_new (GTK_WINDOW(dialog),
                                (GTK_DIALOG_MODAL | 
                                 GTK_DIALOG_DESTROY_WITH_PARENT),
                                GTK_MESSAGE_QUESTION,
                                GTK_BUTTONS_YES_NO,
                                _("The selected file `%s' already exists.\n\n"
                                  "Would you like to overwrite it?"),
                                filename);
      gtk_window_set_title (GTK_WINDOW (checkdialog), _("Overwrite file?"));
      if (gtk_dialog_run (GTK_DIALOG (checkdialog)) != GTK_RESPONSE_YES) {
        s_log_message (_("Save cancelled on user request\n"));
        g_free (filename);
        filename = NULL;
      }
      gtk_widget_destroy (checkdialog);
    }
    /* try saving current page of toplevel to file filename */
    if (filename != NULL) {
      x_window_save_page (w_current,
                          w_current->toplevel->page_current,
                          filename);
    }

    g_free (filename);
  }
  gtk_widget_destroy (dialog);

}
Example #25
0
/**
 * Uploading a VikTrwLayer
 *
 * @param vtl VikTrwLayer
 * @param trk if not null, the track to upload
 */
void osm_traces_upload_viktrwlayer ( VikTrwLayer *vtl, VikTrack *trk )
{
  GtkWidget *dia = gtk_dialog_new_with_buttons (_("OSM upload"),
                                                 VIK_GTK_WINDOW_FROM_LAYER(vtl),
                                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                                 GTK_STOCK_CANCEL,
                                                 GTK_RESPONSE_REJECT,
                                                 GTK_STOCK_OK,
                                                 GTK_RESPONSE_ACCEPT,
                                                 NULL);

  const gchar *name = NULL;
  GtkWidget *user_label, *user_entry;
  GtkWidget *password_label, *password_entry;
  GtkWidget *name_label, *name_entry;
  GtkWidget *description_label, *description_entry;
  GtkWidget *tags_label, *tags_entry;
  GtkWidget *visibility;
  GtkWidget *anonymize_checkbutton = NULL;
  const OsmTraceVis_t *vis_t;

  user_label = gtk_label_new(_("Email:"));
  user_entry = gtk_entry_new();
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), user_label, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), user_entry, FALSE, FALSE, 0);
  gtk_widget_set_tooltip_markup(GTK_WIDGET(user_entry),
                        _("The email used as login\n"
                        "<small>Enter the email you use to login into www.openstreetmap.org.</small>"));

  password_label = gtk_label_new(_("Password:"));
  password_entry = gtk_entry_new();
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), password_label, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), password_entry, FALSE, FALSE, 0);
  gtk_widget_set_tooltip_markup(GTK_WIDGET(password_entry),
                        _("The password used to login\n"
                        "<small>Enter the password you use to login into www.openstreetmap.org.</small>"));

  osm_login_widgets ( user_entry, password_entry );

  name_label = gtk_label_new(_("File's name:"));
  name_entry = gtk_entry_new();
  if (trk != NULL)
    name = trk->name;
  else
    name = vik_layer_get_name(VIK_LAYER(vtl));
  gtk_entry_set_text(GTK_ENTRY(name_entry), name);
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), name_label, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), name_entry, FALSE, FALSE, 0);
  gtk_widget_set_tooltip_markup(GTK_WIDGET(name_entry),
                        _("The name of the file on OSM\n"
                        "<small>This is the name of the file created on the server."
			"This is not the name of the local file.</small>"));

  description_label = gtk_label_new(_("Description:"));
  description_entry = gtk_entry_new();
  const gchar *description = NULL;
  if (trk != NULL)
    description = trk->description;
  else {
    VikTRWMetadata *md = vik_trw_layer_get_metadata (vtl);
    description = md ? md->description : NULL;
  }
  if (description)
    gtk_entry_set_text(GTK_ENTRY(description_entry), description);
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), description_label, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), description_entry, FALSE, FALSE, 0);
  gtk_widget_set_tooltip_text(GTK_WIDGET(description_entry),
                        _("The description of the trace"));

  if (trk != NULL) {
    GtkWidget *label = gtk_label_new(_("Anonymize Times:"));
    anonymize_checkbutton = gtk_check_button_new ();
    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), label, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), anonymize_checkbutton, FALSE, FALSE, 0);
    gtk_widget_set_tooltip_text(GTK_WIDGET(anonymize_checkbutton),
                                _("Anonymize times of the trace.\n"
                                  "<small>You may choose to make the trace identifiable, yet mask the actual real time values</small>"));
  }

  tags_label = gtk_label_new(_("Tags:"));
  tags_entry = gtk_entry_new();
  VikTRWMetadata *md = vik_trw_layer_get_metadata (vtl);
  if (md->keywords)
    gtk_entry_set_text(GTK_ENTRY(tags_entry), md->keywords);
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), tags_label, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), tags_entry, FALSE, FALSE, 0);
  gtk_widget_set_tooltip_text(GTK_WIDGET(tags_entry),
                        _("The tags associated to the trace"));

  visibility = vik_combo_box_text_new();
  for (vis_t = OsmTraceVis; vis_t->combostr != NULL; vis_t++)
    vik_combo_box_text_append (visibility, vis_t->combostr);

  // Set identifiable by default or use the settings for the value
  if ( last_active < 0 ) {
    gint find_entry = -1;
    gint wanted_entry = -1;
    gchar *vis = NULL;
    if ( a_settings_get_string ( VIK_SETTINGS_OSM_TRACE_VIS, &vis ) ) {
      // Use setting
      if ( vis ) {
        for (vis_t = OsmTraceVis; vis_t->apistr != NULL; vis_t++) {
          find_entry++;
          if (!strcmp(vis, vis_t->apistr)) {
            wanted_entry = find_entry;
          }
        }
      }
      // If not found set it to the first entry, otherwise use the entry
      last_active = ( wanted_entry < 0 ) ? 0 : wanted_entry;
    }
    else
      last_active = 0;
  }
  gtk_combo_box_set_active(GTK_COMBO_BOX(visibility), last_active);
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), GTK_WIDGET(visibility), FALSE, FALSE, 0);

  /* User should think about it first... */
  gtk_dialog_set_default_response ( GTK_DIALOG(dia), GTK_RESPONSE_REJECT );

  gtk_widget_show_all ( dia );
  gtk_widget_grab_focus ( description_entry );

  if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_ACCEPT )
  {
    gchar *title = NULL;

    /* overwrite authentication info */
    osm_set_login(gtk_entry_get_text(GTK_ENTRY(user_entry)),
                  gtk_entry_get_text(GTK_ENTRY(password_entry)));

    /* Storing data for the future thread */
    OsmTracesInfo *info = g_malloc(sizeof(OsmTracesInfo));
    info->name        = g_strdup(gtk_entry_get_text(GTK_ENTRY(name_entry)));
    info->description = g_strdup(gtk_entry_get_text(GTK_ENTRY(description_entry)));
    /* TODO Normalize tags: they will be used as URL part */
    info->tags        = g_strdup(gtk_entry_get_text(GTK_ENTRY(tags_entry)));
    info->vistype     = &OsmTraceVis[gtk_combo_box_get_active(GTK_COMBO_BOX(visibility))];
    info->vtl         = VIK_TRW_LAYER(g_object_ref(vtl));
    info->trk         = trk;
    if (trk != NULL && anonymize_checkbutton != NULL )
      info->anonymize_times = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(anonymize_checkbutton));
    else
      info->anonymize_times = FALSE;

    // Save visibility value for default reuse
    last_active = gtk_combo_box_get_active(GTK_COMBO_BOX(visibility));
    a_settings_set_string ( VIK_SETTINGS_OSM_TRACE_VIS, OsmTraceVis[last_active].apistr );

    title = g_strdup_printf(_("Uploading %s to OSM"), info->name);

    /* launch the thread */
    a_background_thread(VIK_GTK_WINDOW_FROM_LAYER(vtl),          /* parent window */
			title,                                   /* description string */
			(vik_thr_func) osm_traces_upload_thread, /* function to call within thread */
			info,                                    /* pass along data */
			(vik_thr_free_func) oti_free,            /* function to free pass along data */
			(vik_thr_free_func) NULL,
			1 );
    g_free ( title ); title = NULL;
  }
  gtk_widget_destroy ( dia );
}
bool ClientHandler::OnJSDialog(CefRefPtr<CefBrowser> browser,
                               const CefString& origin_url,
                               const CefString& accept_lang,
                               JSDialogType dialog_type,
                               const CefString& message_text,
                               const CefString& default_prompt_text,
                               CefRefPtr<CefJSDialogCallback> callback,
                               bool& suppress_message) {
  CEF_REQUIRE_UI_THREAD();

  GtkButtonsType buttons = GTK_BUTTONS_NONE;
  GtkMessageType gtk_message_type = GTK_MESSAGE_OTHER;
  std::string title;

  switch (dialog_type) {
    case JSDIALOGTYPE_ALERT:
      buttons = GTK_BUTTONS_NONE;
      gtk_message_type = GTK_MESSAGE_WARNING;
      title = "JavaScript Alert";
      break;

    case JSDIALOGTYPE_CONFIRM:
      buttons = GTK_BUTTONS_CANCEL;
      gtk_message_type = GTK_MESSAGE_QUESTION;
      title = "JavaScript Confirm";
      break;

    case JSDIALOGTYPE_PROMPT:
      buttons = GTK_BUTTONS_CANCEL;
      gtk_message_type = GTK_MESSAGE_QUESTION;
      title = "JavaScript Prompt";
      break;
  }

  js_dialog_callback_ = callback;

  if (!origin_url.empty()) {
    title += " - ";
    title += origin_url.ToString();
  }

  GtkWidget* window = gtk_widget_get_ancestor(
      GTK_WIDGET(GetMainWindowHandle()), GTK_TYPE_WINDOW);
  gtk_dialog_ = gtk_message_dialog_new(GTK_WINDOW(window),
                                       GTK_DIALOG_MODAL,
                                       gtk_message_type,
                                       buttons,
                                       "%s",
                                       message_text.ToString().c_str());
  g_signal_connect(gtk_dialog_,
                   "delete-event",
                   G_CALLBACK(gtk_widget_hide_on_delete),
                   NULL);

  gtk_window_set_title(GTK_WINDOW(gtk_dialog_), title.c_str());

  GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_),
                                               GTK_STOCK_OK,
                                               GTK_RESPONSE_OK);

  if (dialog_type != JSDIALOGTYPE_PROMPT)
    gtk_widget_grab_focus(ok_button);

  if (dialog_type == JSDIALOGTYPE_PROMPT) {
    GtkWidget* content_area =
        gtk_dialog_get_content_area(GTK_DIALOG(gtk_dialog_));
    GtkWidget* text_box = gtk_entry_new();
    gtk_entry_set_text(GTK_ENTRY(text_box),
                       default_prompt_text.ToString().c_str());
    gtk_box_pack_start(GTK_BOX(content_area), text_box, TRUE, TRUE, 0);
    g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box);
    gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE);
  }

  gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK);
  g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnDialogResponse), this);
  gtk_widget_show_all(GTK_WIDGET(gtk_dialog_));

  return true;
}
static void
polkit_mate_authentication_dialog_constructed (GObject *object)
{
  PolkitMateAuthenticationDialog *dialog;
  GtkWidget *hbox;
  GtkWidget *main_vbox;
  GtkWidget *vbox;
  GtkWidget *table_alignment;
  GtkWidget *table;
  GtkWidget *details_expander;
  GtkWidget *details_vbox;
  GtkWidget *label;
  GtkWidget *image;
  GtkWidget *content_area;
  GtkWidget *action_area;
  gboolean have_user_combobox;
  gchar *s;
  guint rows;

  dialog = POLKIT_MATE_AUTHENTICATION_DIALOG (object);

  if (G_OBJECT_CLASS (polkit_mate_authentication_dialog_parent_class)->constructed != NULL)
    G_OBJECT_CLASS (polkit_mate_authentication_dialog_parent_class)->constructed (object);

  have_user_combobox = FALSE;

  dialog->priv->cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
                                                            GTK_STOCK_CANCEL,
                                                            GTK_RESPONSE_CANCEL);
  dialog->priv->auth_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
                                                          _("_Authenticate"),
                                                          GTK_RESPONSE_OK);
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

  content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
  action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));

  gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
  gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
  gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
  gtk_box_set_spacing (GTK_BOX (action_area), 6);
  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
  gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_DIALOG_AUTHENTICATION);

  hbox = gtk_hbox_new (FALSE, 12);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
  gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);

  image = get_image (dialog);
  gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
  gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);

  main_vbox = gtk_vbox_new (FALSE, 10);
  gtk_box_pack_start (GTK_BOX (hbox), main_vbox, TRUE, TRUE, 0);

  /* main message */
  label = gtk_label_new (NULL);
  s = g_strdup_printf ("<big><b>%s</b></big>", dialog->priv->message);
  gtk_label_set_markup (GTK_LABEL (label), s);
  g_free (s);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
  gtk_box_pack_start (GTK_BOX (main_vbox), label, FALSE, FALSE, 0);

  /* secondary message */
  label = gtk_label_new (NULL);
  if (g_strv_length (dialog->priv->users) > 1)
    {
          gtk_label_set_markup (GTK_LABEL (label),
                                _("An application is attempting to perform an action that requires privileges. "
                                  "Authentication as one of the users below is required to perform this action."));
    }
  else
    {
      if (strcmp (g_get_user_name (), dialog->priv->users[0]) == 0)
        {
          gtk_label_set_markup (GTK_LABEL (label),
                                _("An application is attempting to perform an action that requires privileges. "
                                  "Authentication is required to perform this action."));
        }
      else
        {
          gtk_label_set_markup (GTK_LABEL (label),
                                _("An application is attempting to perform an action that requires privileges. "
                                  "Authentication as the super user is required to perform this action."));
        }
    }
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
  gtk_box_pack_start (GTK_BOX (main_vbox), label, FALSE, FALSE, 0);

  /* user combobox */
  if (g_strv_length (dialog->priv->users) > 1)
    {
      dialog->priv->user_combobox = gtk_combo_box_new ();
      gtk_box_pack_start (GTK_BOX (main_vbox), GTK_WIDGET (dialog->priv->user_combobox), FALSE, FALSE, 0);

      create_user_combobox (dialog);

      have_user_combobox = TRUE;
    }
  else
    {
      dialog->priv->selected_user = g_strdup (dialog->priv->users[0]);
    }

  /* password entry */
  vbox = gtk_vbox_new (FALSE, 0);
  gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);

  table_alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
  gtk_box_pack_start (GTK_BOX (vbox), table_alignment, FALSE, FALSE, 0);
  table = gtk_table_new (1, 2, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 12);
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  gtk_container_add (GTK_CONTAINER (table_alignment), table);
  dialog->priv->password_entry = gtk_entry_new ();
  gtk_entry_set_visibility (GTK_ENTRY (dialog->priv->password_entry), FALSE);
  dialog->priv->prompt_label = add_row (table, 0, _("_Password:"), dialog->priv->password_entry);

  g_signal_connect_swapped (dialog->priv->password_entry, "activate",
                            G_CALLBACK (gtk_window_activate_default),
                            dialog);

  dialog->priv->table_alignment = table_alignment;
  /* initially never show the password entry stuff; we'll toggle it on/off so it's
   * only shown when prompting for a password */
  gtk_widget_set_no_show_all (dialog->priv->table_alignment, TRUE);

  /* A label for showing PAM_TEXT_INFO and PAM_TEXT_ERROR messages */
  label = gtk_label_new (NULL);
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  dialog->priv->info_label = label;

  /* Details */
  details_expander = gtk_expander_new_with_mnemonic (_("<small><b>_Details</b></small>"));
  gtk_expander_set_use_markup (GTK_EXPANDER (details_expander), TRUE);
  gtk_box_pack_start (GTK_BOX (content_area), details_expander, FALSE, FALSE, 0);

  details_vbox = gtk_vbox_new (FALSE, 10);
  gtk_container_add (GTK_CONTAINER (details_expander), details_vbox);

  table_alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
  gtk_box_pack_start (GTK_BOX (details_vbox), table_alignment, FALSE, FALSE, 0);
  table = gtk_table_new (1, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 12);
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  gtk_container_add (GTK_CONTAINER (table_alignment), table);

  /* TODO: sort keys? */
  rows = 0;
  if (dialog->priv->details != NULL)
    {
      guint n;
      gchar **keys;

      keys = polkit_details_get_keys (dialog->priv->details);
      for (n = 0; keys[n] != NULL; n++)
        {
          const gchar *key = keys[n];
          const gchar *value;

          value = polkit_details_lookup (dialog->priv->details, key);

          label = gtk_label_new (NULL);
          s = g_strdup_printf ("<small>%s</small>", value);
          gtk_label_set_markup (GTK_LABEL (label), s);
          g_free (s);
          gtk_misc_set_alignment (GTK_MISC (label), 0, 1.0);
          s = g_strdup_printf ("<small><b>%s:</b></small>", key);
          add_row (table, rows, s, label);
          g_free (s);

          rows++;
        }
      g_strfreev (keys);
    }

  /* --- */

  label = gtk_label_new (NULL);
  gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
  s = g_strdup_printf ("<small><a href=\"%s\">%s</a></small>",
                       dialog->priv->action_id,
                       dialog->priv->action_id);
  gtk_label_set_markup (GTK_LABEL (label), s);
  g_free (s);
  gtk_misc_set_alignment (GTK_MISC (label), 0, 1.0);
  add_row (table, rows++, _("<small><b>Action:</b></small>"), label);
  g_signal_connect (label, "activate-link", G_CALLBACK (action_id_activated), NULL);

  s = g_strdup_printf (_("Click to edit %s"), dialog->priv->action_id);
  gtk_widget_set_tooltip_markup (label, s);
  g_free (s);

  /* --- */

  label = gtk_label_new (NULL);
  gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
  s = g_strdup_printf ("<small><a href=\"%s\">%s</a></small>",
                       dialog->priv->vendor_url,
                       dialog->priv->vendor);
  gtk_label_set_markup (GTK_LABEL (label), s);
  g_free (s);
  gtk_misc_set_alignment (GTK_MISC (label), 0, 1.0);
  add_row (table, rows++, _("<small><b>Vendor:</b></small>"), label);

  s = g_strdup_printf (_("Click to open %s"), dialog->priv->vendor_url);
  gtk_widget_set_tooltip_markup (label, s);
  g_free (s);

  if (have_user_combobox)
    {
      /* ... and make the password entry and "Authenticate" button insensitive */
      gtk_widget_set_sensitive (dialog->priv->prompt_label, FALSE);
      gtk_widget_set_sensitive (dialog->priv->password_entry, FALSE);
      gtk_widget_set_sensitive (dialog->priv->auth_button, FALSE);
    }
  else
    {
    }

  gtk_widget_realize (GTK_WIDGET (dialog));

}
Example #28
0
static void
dlg_extract__common (FrWindow *window,
	             GList    *selected_files,
	             char     *base_dir_for_selection)
{
	DialogData *data;

	data = g_new0 (DialogData, 1);
	data->settings = g_settings_new (FILE_ROLLER_SCHEMA_EXTRACT);
	data->window = window;
	data->selected_files = selected_files;
	data->base_dir_for_selection = base_dir_for_selection;
	data->extract_clicked = FALSE;

	data->dialog = gtk_file_chooser_dialog_new (C_("Window title", "Extract"),
						    GTK_WINDOW (data->window),
						    GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
						    _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
						    _GTK_LABEL_EXTRACT, GTK_RESPONSE_OK,
						    NULL);

	gtk_window_set_default_size (GTK_WINDOW (data->dialog), 530, 510);
	gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (data->dialog), FALSE);
	gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (data->dialog), FALSE);
	gtk_file_chooser_set_create_folders (GTK_FILE_CHOOSER (data->dialog), TRUE);
	gtk_dialog_set_default_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK);

	data->builder = _gtk_builder_new_from_resource ("extract-dialog-options.ui");
	if (data->builder == NULL)
		return;
	gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (data->dialog), GET_WIDGET ("extra_widget"));

	/* Set widgets data. */

	gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (data->dialog), fr_window_get_extract_default_dir (window), NULL);

	if (data->selected_files != NULL)
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("selected_files_radiobutton")), TRUE);
	else {
		gtk_widget_set_sensitive (GET_WIDGET ("selected_files_radiobutton"), FALSE);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("all_files_radiobutton")), TRUE);
	}

	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("keep_newer_checkbutton")), g_settings_get_boolean (data->settings, PREF_EXTRACT_SKIP_NEWER));
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("keep_structure_checkbutton")), g_settings_get_boolean (data->settings, PREF_EXTRACT_RECREATE_FOLDERS));

	/* Set the signals handlers. */

	g_signal_connect (G_OBJECT (data->dialog),
			  "destroy",
			  G_CALLBACK (file_selector_destroy_cb),
			  data);
	g_signal_connect (G_OBJECT (data->dialog),
			  "response",
			  G_CALLBACK (file_selector_response_cb),
			  data);
	g_signal_connect (G_OBJECT (GET_WIDGET ("file_pattern_entry")),
			  "changed",
			  G_CALLBACK (files_entry_changed_cb),
			  data);

	/* Run dialog. */

	gtk_window_set_modal (GTK_WINDOW (data->dialog),TRUE);
	gtk_widget_show (data->dialog);
}
Example #29
0
static gboolean
cload_dialog(CLoadArgs *args,
            GwyDataField *dfield)
{
    GtkWidget *dialog, *dialog2, *table, *label;
    gint row = 0;
    CLoadControls controls;
    enum { RESPONSE_RESET = 1,
        RESPONSE_DUPLICATE_OVERWRITE = 2,
        RESPONSE_DUPLICATE_APPEND = 3 };

    gint response;

    controls.args = args;
    dialog = gtk_dialog_new_with_buttons(_("Load calibration data"), NULL, 0,
                                         _("_Reset"), RESPONSE_RESET,
                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                         GTK_STOCK_OK, GTK_RESPONSE_OK,
                                         NULL);
    controls.dialog = dialog;
    gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);

    gtk_dialog_add_action_widget(GTK_DIALOG(dialog),
                                 gwy_stock_like_button_new(_("_Load"),
                                                           GTK_STOCK_OPEN),
                                 RESPONSE_LOAD);
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);

    table = gtk_table_new(4, 4, FALSE);
    gtk_table_set_row_spacings(GTK_TABLE(table), 2);
    gtk_table_set_col_spacings(GTK_TABLE(table), 6);
    gtk_container_set_border_width(GTK_CONTAINER(table), 4);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table,
                       FALSE, FALSE, 4);

    label = gtk_label_new_with_mnemonic(_("Calibration name:"));
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), label,
                     0, 1, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);

    args->name = g_strdup("new"); //FIXME this should not be here
    controls.name = GTK_ENTRY(gtk_entry_new());
    gtk_entry_set_text(controls.name, args->name);
    gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(controls.name),
                     1, 3, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);

    row++;
    controls.text = gtk_label_new(_("No data loaded"));
    gtk_misc_set_alignment(GTK_MISC(controls.text), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), controls.text,
                     0, 3, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);


    gtk_widget_show_all(dialog);
    do {
        response = gtk_dialog_run(GTK_DIALOG(dialog));
        switch (response) {
            case GTK_RESPONSE_CANCEL:
            case GTK_RESPONSE_DELETE_EVENT:
            gtk_widget_destroy(dialog);
            case GTK_RESPONSE_NONE:
            return FALSE;
            break;

            case GTK_RESPONSE_OK:
            /*check whether this resource already exists*/
            args->name = g_strdup(gtk_entry_get_text(controls.name));
            if (gwy_inventory_get_item(gwy_calibrations(), args->name))
            {
                dialog2 = gtk_message_dialog_new (GTK_WINDOW(dialog),
                                                  GTK_DIALOG_DESTROY_WITH_PARENT,
                                                  GTK_MESSAGE_WARNING,
                                                  GTK_BUTTONS_CANCEL,
                                                  "Calibration '%s' alerady exists",
                                                  args->name);
                gtk_dialog_add_button(GTK_DIALOG(dialog2), "Overwrite", RESPONSE_DUPLICATE_OVERWRITE);
                gtk_dialog_add_button(GTK_DIALOG(dialog2), "Append", RESPONSE_DUPLICATE_APPEND);
                response = gtk_dialog_run(GTK_DIALOG(dialog2));
                if (response == RESPONSE_DUPLICATE_OVERWRITE) {
                    args->duplicate = DUPLICATE_OVERWRITE;
                    response = GTK_RESPONSE_OK;
                } else if (response == RESPONSE_DUPLICATE_APPEND) {
                    args->duplicate = DUPLICATE_APPEND;
                    response = GTK_RESPONSE_OK;
                }
                gtk_widget_destroy (dialog2);
            } else args->duplicate = DUPLICATE_NONE;
            break;

            case RESPONSE_LOAD:
            load_caldata(&controls);
            break;

            default:
            g_assert_not_reached();
            break;
        }
    } while (response != GTK_RESPONSE_OK);

    gtk_widget_destroy(dialog);

    return TRUE;
}
Example #30
0
UgtkSettingDialog*  ugtk_setting_dialog_new (const gchar* title, GtkWindow* parent)
{
	UgtkSettingDialog*  dialog;
	GtkCellRenderer*    renderer;
	GtkWidget*  widget;
	GtkBox*     vbox;
	GtkBox*     hbox;

	dialog = g_malloc0 (sizeof (UgtkSettingDialog));
	dialog->self = (GtkDialog*) gtk_dialog_new_with_buttons (title, parent,
			GTK_DIALOG_DESTROY_WITH_PARENT,
			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
			GTK_STOCK_OK,     GTK_RESPONSE_OK,
			NULL);
#if GTK_MAJOR_VERSION <= 3 && GTK_MINOR_VERSION < 14
	gtk_window_set_has_resize_grip ((GtkWindow*) dialog->self, FALSE);
#endif
	gtk_dialog_set_default_response (dialog->self, GTK_RESPONSE_OK);
	vbox = (GtkBox*) gtk_dialog_get_content_area (dialog->self);
	hbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
	gtk_box_pack_start (vbox, GTK_WIDGET (hbox), FALSE, FALSE, 2);
	// Notebook
	widget = gtk_notebook_new ();
	gtk_widget_set_size_request (widget, 430, 320);
	gtk_box_pack_end (hbox, widget, FALSE, FALSE, 0);
	dialog->notebook = (GtkNotebook*) widget;
	gtk_notebook_set_show_tabs (dialog->notebook, FALSE);
	// TreeView
	dialog->list_store = gtk_list_store_new (1, G_TYPE_STRING);
	widget = gtk_tree_view_new_with_model (
			GTK_TREE_MODEL (dialog->list_store));
	gtk_widget_set_size_request (widget, 130, 120);
	gtk_box_pack_start (hbox, widget, FALSE, FALSE, 0);
	dialog->tree_view = (GtkTreeView*) widget;
	gtk_tree_view_set_headers_visible (dialog->tree_view, FALSE);
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (
			dialog->tree_view, 0,
			_("Name"), renderer,
			"text", 0,
			NULL);
	g_signal_connect (dialog->tree_view, "cursor-changed",
			G_CALLBACK (on_cursor_changed), dialog);

	// ------------------------------------------------------------------------
	// UI settings page
	vbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
	ugtk_user_interface_form_init (&dialog->ui);
	gtk_box_pack_start (vbox, dialog->ui.self, FALSE, FALSE, 2);
	ugtk_setting_dialog_add (dialog, _("User Interface"), (GtkWidget*) vbox);

	// ------------------------------------------------------------------------
	// Clipboard settings page
	ugtk_clipboard_form_init (&dialog->clipboard);
	gtk_container_set_border_width (GTK_CONTAINER (dialog->clipboard.self), 2);
	ugtk_setting_dialog_add (dialog, _("Clipboard"), dialog->clipboard.self);

	// ------------------------------------------------------------------------
	// Bandwidth settings page
	ugtk_bandwidth_form_init (&dialog->bandwidth);
	gtk_container_set_border_width (GTK_CONTAINER (dialog->bandwidth.self), 2);
	ugtk_setting_dialog_add (dialog, _("Bandwidth"), dialog->bandwidth.self);

	// ------------------------------------------------------------------------
	// Scheduler settings page
	ugtk_schedule_form_init (&dialog->scheduler);
	gtk_container_set_border_width (GTK_CONTAINER (dialog->scheduler.self), 2);
	ugtk_setting_dialog_add (dialog, _("Scheduler"), dialog->scheduler.self);

	// ------------------------------------------------------------------------
	// Plugin settings page
	ugtk_plugin_form_init (&dialog->plugin);
	gtk_container_set_border_width (GTK_CONTAINER (dialog->plugin.self), 2);
	ugtk_setting_dialog_add (dialog, _("Plug-in"), dialog->plugin.self);

	// ------------------------------------------------------------------------
	// Others settings page
	vbox = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
	ugtk_setting_dialog_add (dialog, _("Others"), (GtkWidget*) vbox);

	ugtk_commandline_form_init (&dialog->commandline);
	gtk_box_pack_start (vbox, dialog->commandline.self, FALSE, FALSE, 4);
	gtk_box_pack_start (vbox, gtk_label_new (""), FALSE, FALSE, 0);
	ugtk_auto_save_form_init (&dialog->auto_save);
	gtk_box_pack_start (vbox, dialog->auto_save.self, FALSE, FALSE, 2);
	gtk_box_pack_start (vbox, gtk_label_new (""), FALSE, FALSE, 0);
	ugtk_completion_form_init (&dialog->completion);
	gtk_box_pack_start (vbox, dialog->completion.self, FALSE, FALSE, 2);

	gtk_widget_show_all ((GtkWidget*) hbox);
//	gtk_container_set_focus_child (GTK_CONTAINER (dialog->self), dialog->pattern_entry);
//	g_signal_connect (dialog->pattern_entry, "key-press-event", G_CALLBACK (on_key_press_event), dialog);

	return dialog;
}