Example #1
0
int lassi_tray_init(LassiTrayInfo *i, LassiServer *server) {
    GtkActionEntry  entries[] =
    {
#if GTK_CHECK_VERSION(2,14,0)
        {"Help", GTK_STOCK_HELP, NULL,
         NULL, NULL,
         G_CALLBACK (on_help_activate)},
#endif
        {"Preferences", GTK_STOCK_PREFERENCES, NULL,
         NULL, NULL,
         G_CALLBACK (on_prefs_activate)},
        {"Quit", GTK_STOCK_QUIT, NULL,
         NULL, NULL,
         G_CALLBACK (gtk_main_quit)}
    };
    GtkActionGroup *actions;
    GError         *error = NULL;

    g_assert(i);
    g_assert(server);

    memset(i, 0, sizeof(*i));
    i->server = server;

    notify_init("Mango Lassi");

    i->status_icon = gtk_status_icon_new_from_icon_name(ICON_IDLE);

    i->ui_manager = gtk_ui_manager_new ();
    actions = gtk_action_group_new ("mango-lassi-popup");
    gtk_action_group_add_actions (actions,
                                  entries,
                                  G_N_ELEMENTS (entries),
                                  i);
    gtk_ui_manager_insert_action_group (i->ui_manager, actions, -1);
    gtk_ui_manager_add_ui_from_string (i->ui_manager,
                                       "<popup>"
                                         "<menuitem action='Preferences'/>"
#if GTK_CHECK_VERSION(2,14,0)
                                         "<menuitem action='Help'/>"
#endif
                                         "<separator />"
                                         "<menuitem action='Quit'/>"
                                       "</popup>",
                                       -1,
                                       &error);
    if (error) {
        GtkWidget* dialog = gtk_message_dialog_new (NULL, 0,
                                                    GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
                                                    "%s", _("Initialization Error"));
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                                  _("Cannot initialize the user interface: %s"),
                                                  error->message);

        g_error_free (error);

        gtk_dialog_run (GTK_DIALOG (dialog));

        gtk_widget_destroy (dialog);
        return 1;
    }

    i->menu = gtk_ui_manager_get_widget (i->ui_manager, "/ui/popup");

    g_signal_connect(G_OBJECT(i->status_icon), "popup_menu", G_CALLBACK(on_tray_popup_menu), i);
    g_signal_connect(G_OBJECT(i->status_icon), "activate", G_CALLBACK(on_tray_activate), i);

    lassi_tray_update(i, 0);

    return 0;
}
int
main (int argc, char *argv[])
{
	DrWright     *drwright;
	DrwSelection *selection;
	gboolean      no_check = FALSE;
        const GOptionEntry options[] = {
          { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
            N_("Enable debugging code"), NULL },
          { "no-check", 'n', 0, G_OPTION_ARG_NONE, &no_check,
            N_("Don't check whether the notification area exists"), NULL },
	  { NULL }
        };
        GOptionContext *option_context;
        GError *error = NULL;
        gboolean retval;

	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);  
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

        option_context = g_option_context_new (NULL);
#if GLIB_CHECK_VERSION (2, 12, 0)
        g_option_context_set_translation_domain (option_context, GETTEXT_PACKAGE);
#endif
        g_option_context_add_main_entries (option_context, options, GETTEXT_PACKAGE);
        g_option_context_add_group (option_context, gtk_get_option_group (TRUE));
 
        retval = g_option_context_parse (option_context, &argc, &argv, &error);
        g_option_context_free (option_context);
        if (!retval) {
                g_print ("%s\n", error->message);
                g_error_free (error);
                exit (1);
        }

	g_set_application_name (_("Typing Monitor"));
	gtk_window_set_default_icon_name ("typing-monitor");

	selection = drw_selection_start ();
	if (!drw_selection_is_master (selection)) {
		g_message ("The typing monitor is already running, exiting.");
		return 0;
	}

	if (!no_check && !have_tray ()) {
		GtkWidget *dialog;

		dialog = gtk_message_dialog_new (
			NULL, 0,
			GTK_MESSAGE_INFO,
			GTK_BUTTONS_CLOSE,
			_("The typing monitor uses the notification area to display "
			  "information. You don't seem to have a notification area "
			  "on your panel. You can add it by right-clicking on your "
			  "panel and choosing 'Add to panel', selecting 'Notification "
			  "area' and clicking 'Add'."));
		
		gtk_dialog_run (GTK_DIALOG (dialog));

		gtk_widget_destroy (dialog);
	}
	
	drwright = drwright_new ();

	gtk_main ();

	return 0;
}
Example #3
0
GtkWidget *
gnomemeeting_warning_dialog_on_widget (GtkWindow *parent, 
                                       const char *key,
				       const char *primary_text,
                                       const char *format,
				       ...)
{
  va_list args;
  
  GtkWidget *button = NULL;
  GtkWidget *dialog = NULL;

  char buffer[1025];

  gchar *prim_text = NULL;
  gchar *dialog_text = NULL;

  gboolean do_not_show = FALSE;
  
  g_return_val_if_fail (parent != NULL, NULL);
  g_return_val_if_fail (key != NULL, NULL);

     
  /* if not set, do_not_show will get the value of 0 */
  do_not_show = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (parent), key));
  
  if (do_not_show)
    /* doesn't show warning dialog as state is 'hide' */
    return NULL;

  va_start (args, format);
 
  button = 
    gtk_check_button_new_with_label (_("Do not show this dialog again"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), do_not_show);

  
  if (format == NULL)
    buffer[0] = 0;
  else 
    g_vsnprintf (buffer, 1024, format, args);

  prim_text =
    g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>",
		     primary_text);
  
  dialog_text =
    g_strdup_printf ("%s\n\n%s", prim_text, buffer);

  dialog = gtk_message_dialog_new (parent, 
                                   0,
                                   GTK_MESSAGE_WARNING,
                                   GTK_BUTTONS_OK,
				   NULL);
  gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
  
  gtk_window_set_title (GTK_WINDOW (dialog), "");
  gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), dialog_text);

  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 
                     button);
  
  /* Can be called from threads */
  gm_window_show (dialog);

  g_signal_connect_data (dialog, "response",
			 G_CALLBACK (warning_dialog_destroyed_cb),
			 (gpointer) g_strdup (key),
			 (GClosureNotify) g_free,
			 (GConnectFlags) 0);
  
  va_end (args);

  g_free (prim_text);
  g_free (dialog_text);

  return dialog;
}
Example #4
0
/** \brief Print a satellite pass.
  * \param pass Pointer to the pass_t data
  * \param qth Pointer to the qth_t structure
  * \param parent Transient parent of the dialog, or NULL
  *
  * This function prints a satellite pass to the printer (or a file) using the
  * Gtk+ printing API. The function takes the user configuration into account
  * and only prints the selected columns. The font size will be adjusted so that
  * one row can fit on one line. The function will also try to reduce the number
  * of rows so that the whole pass can fit on one page:
  *
  *    +-------------------------+
  *    |         header          |
  *    |------------+------------|
  *    |            |            |
  *    |            |            |
  *    |  polar     |   az/el    |
  *    |            |            |
  *    |------------+------------|
  *    |                         |
  *    |    Table with data      |
  *    |                         |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |                         |
  *    +-------------------------+
  *
  */
void print_pass   (pass_t *pass, qth_t *qth, GtkWindow *parent)
{
    gchar *text,*header,*buff;

    GtkPrintOperation *operation;
    PrintData *data;
    GError *error = NULL;


    /* TODO check pass and qth */


    operation = gtk_print_operation_new ();
    data = g_new0 (PrintData, 1);
    data->font_size = 12.0;  // FIXME

    /* page header */
    data->pgheader = g_strdup_printf (_("Pass details for %s (orbit %d)"), pass->satname, pass->orbit);

    /* convert data to printable strings; we use existing pass_to_txt functions */
    data->fields = sat_cfg_get_int (SAT_CFG_INT_PRED_SINGLE_COL);
    header = pass_to_txt_tblheader (pass, qth, data->fields);
    text = pass_to_txt_tblcontents (pass, qth, data->fields);
    buff = g_strconcat (header, text, NULL);
    data->lines = g_strsplit (buff, "\n", 0);
    g_free (text);
    g_free (header);
    g_free (buff);

    g_signal_connect (G_OBJECT (operation), "begin-print", G_CALLBACK (begin_print), data);
    g_signal_connect (G_OBJECT (operation), "draw-page", G_CALLBACK (draw_page), data);
    g_signal_connect (G_OBJECT (operation), "end-print", G_CALLBACK (end_print), data);

    gtk_print_operation_set_use_full_page (operation, FALSE);
    gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS);

    gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                             parent, &error);

    g_object_unref (operation);


    if (error) {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     "%s: %s", __func__, error->message);

        GtkWidget *dialog;

        dialog = gtk_message_dialog_new (parent,
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                         GTK_MESSAGE_ERROR,
                                         GTK_BUTTONS_CLOSE,
                                         "%s", error->message);
        g_error_free (error);

        g_signal_connect (dialog, "response",
                          G_CALLBACK (gtk_widget_destroy), NULL);

        gtk_widget_show (dialog);
    }


}
Example #5
0
static GdkFilterReturn
screen_on_event (GdkXEvent *xevent,
                 GdkEvent *event,
                 gpointer data)
{
#ifdef HAVE_RANDR
    MateRRScreen *screen = data;
    XEvent *e = xevent;
    int event_num;

    if (!e)
        return GDK_FILTER_CONTINUE;

    event_num = e->type - screen->randr_event_base;

    if (event_num == RRScreenChangeNotify) {
        /* We don't reprobe the hardware; we just fetch the X server's latest
         * state.  The server already knows the new state of the outputs; that's
         * why it sent us an event!
         */
        screen_update (screen, TRUE, FALSE, NULL); /* NULL-GError */
#if 0
        /* Enable this code to get a dialog showing the RANDR timestamps, for debugging purposes */
        {
            GtkWidget *dialog;
            XRRScreenChangeNotifyEvent *rr_event;
            static int dialog_num;

            rr_event = (XRRScreenChangeNotifyEvent *) e;

            dialog = gtk_message_dialog_new (NULL,
                                             0,
                                             GTK_MESSAGE_INFO,
                                             GTK_BUTTONS_CLOSE,
                                             "RRScreenChangeNotify timestamps (%d):\n"
                                             "event change: %u\n"
                                             "event config: %u\n"
                                             "event serial: %lu\n"
                                             "----------------------"
                                             "screen change: %u\n"
                                             "screen config: %u\n",
                                             dialog_num++,
                                             (guint32) rr_event->timestamp,
                                             (guint32) rr_event->config_timestamp,
                                             rr_event->serial,
                                             (guint32) screen->info->resources->timestamp,
                                             (guint32) screen->info->resources->configTimestamp);
            g_signal_connect (dialog, "response",
                              G_CALLBACK (gtk_widget_destroy), NULL);
            gtk_widget_show (dialog);
        }
#endif
    }
#if 0
    /* WHY THIS CODE IS DISABLED:
     *
     * Note that in mate_rr_screen_new(), we only select for
     * RRScreenChangeNotifyMask.  We used to select for other values in
     * RR*NotifyMask, but we weren't really doing anything useful with those
     * events.  We only care about "the screens changed in some way or another"
     * for now.
     *
     * If we ever run into a situtation that could benefit from processing more
     * detailed events, we can enable this code again.
     *
     * Note that the X server sends RRScreenChangeNotify in conjunction with the
     * more detailed events from RANDR 1.2 - see xserver/randr/randr.c:TellChanged().
     */
    else if (event_num == RRNotify)
    {
        /* Other RandR events */

        XRRNotifyEvent *event = (XRRNotifyEvent *)e;

        /* Here we can distinguish between RRNotify events supported
         * since RandR 1.2 such as RRNotify_OutputProperty.  For now, we
         * don't have anything special to do for particular subevent types, so
         * we leave this as an empty switch().
         */
        switch (event->subtype)
        {
        default:
            break;
        }

        /* No need to reprobe hardware here */
        screen_update (screen, TRUE, FALSE, NULL); /* NULL-GError */
    }
#endif

#endif /* HAVE_RANDR */

    /* Pass the event on to GTK+ */
    return GDK_FILTER_CONTINUE;
}
static gboolean
rejilla_status_dialog_2G_file_cb (RejillaTrackDataCfg *track,
				  const gchar *name,
				  RejillaStatusDialog *dialog)
{
	gint answer;
	gchar *string;
	GtkWidget *message;
	GtkWindow *transient_win;
	RejillaStatusDialogPrivate *priv;

	priv = REJILLA_STATUS_DIALOG_PRIVATE (dialog);

	if (priv->accept_2G_files)
		return TRUE;

	if (priv->reject_2G_files)
		return FALSE;

	g_signal_emit (dialog,
	               rejilla_status_dialog_signals [USER_INTERACTION],
	               0);

	gtk_widget_hide (GTK_WIDGET (dialog));

	string = g_strdup_printf (_("Do you really want to add \"%s\" to the selection and use the third version of the ISO9660 standard to support it?"), name);
	transient_win = gtk_window_get_transient_for (GTK_WINDOW (dialog));
	message = gtk_message_dialog_new (transient_win,
	                                  GTK_DIALOG_DESTROY_WITH_PARENT|
					  GTK_DIALOG_MODAL,
					  GTK_MESSAGE_WARNING,
					  GTK_BUTTONS_NONE,
					  "%s",
					  string);
	g_free (string);

	if (gtk_window_get_icon_name (GTK_WINDOW (dialog)))
		gtk_window_set_icon_name (GTK_WINDOW (message),
					  gtk_window_get_icon_name (GTK_WINDOW (dialog)));
	else if (transient_win)
		gtk_window_set_icon_name (GTK_WINDOW (message),
					  gtk_window_get_icon_name (transient_win));

	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
						  _("The size of the file is over 2 GiB. Files larger than 2 GiB are not supported by the ISO9660 standard in its first and second versions (the most widespread ones)."
						    "\nIt is recommended to use the third version of the ISO9660 standard, which is supported by most operating systems, including Linux and all versions of Windowsâ„¢."
						    "\nHowever, Mac OS X cannot read images created with version 3 of the ISO9660 standard."));

	gtk_dialog_add_button (GTK_DIALOG (message), _("Ne_ver Add Such File"), GTK_RESPONSE_REJECT);
	gtk_dialog_add_button (GTK_DIALOG (message), _("Al_ways Add Such File"), GTK_RESPONSE_ACCEPT);

	answer = gtk_dialog_run (GTK_DIALOG (message));
	gtk_widget_destroy (message);

	gtk_widget_show (GTK_WIDGET (dialog));

	priv->accept_2G_files = (answer == GTK_RESPONSE_ACCEPT);
	priv->reject_2G_files = (answer == GTK_RESPONSE_REJECT);

	return (answer != GTK_RESPONSE_YES && answer != GTK_RESPONSE_ACCEPT);
}
Example #7
0
void gtkw_dialog_error(GtkWidget * parent, const ustring & error)
{
  GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(parent), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", error.c_str());
  gtk_dialog_run(GTK_DIALOG(dialog));
  gtk_widget_destroy(dialog);
}
Example #8
0
static void delete_button_clicked(GtkButton *button, gpointer user_data)
{
  dt_lib_module_t *self = (dt_lib_module_t *)user_data;
  dt_lib_tagging_t *d = (dt_lib_tagging_t *)self->data;

  int res = GTK_RESPONSE_YES;

  guint tagid;
  GtkTreeIter iter;
  GtkTreeModel *model = NULL;
  GtkTreeView *view = d->related;
  GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
  if(!gtk_tree_selection_get_selected(selection, &model, &iter)) return;
  gtk_tree_model_get(model, &iter, DT_LIB_TAGGING_COL_ID, &tagid, -1);

  // First check how many images are affected by the remove
  int count = dt_tag_remove(tagid, FALSE);
  if(count > 0 && dt_conf_get_bool("plugins/lighttable/tagging/ask_before_delete_tag"))
  {
    GtkWidget *dialog;
    GtkWidget *win = dt_ui_main_window(darktable.gui->ui);
    gchar *tagname = dt_tag_get_name(tagid);
    dialog = gtk_message_dialog_new(
        GTK_WINDOW(win), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
        ngettext("do you really want to delete the tag `%s'?\n%d image is assigned this tag!",
                 "do you really want to delete the tag `%s'?\n%d images are assigned this tag!", count),
        tagname, count);
    gtk_window_set_title(GTK_WINDOW(dialog), _("delete tag?"));
    res = gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
    free(tagname);
  }
  if(res != GTK_RESPONSE_YES) return;

  GList *tagged_images = NULL;
  sqlite3_stmt *stmt;
  DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select imgid from tagged_images where tagid=?1",
                              -1, &stmt, NULL);
  DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, tagid);
  while(sqlite3_step(stmt) == SQLITE_ROW)
  {
    tagged_images = g_list_append(tagged_images, GINT_TO_POINTER(sqlite3_column_int(stmt, 0)));
  }
  sqlite3_finalize(stmt);

  dt_tag_remove(tagid, TRUE);

  GList *list_iter;
  if((list_iter = g_list_first(tagged_images)) != NULL)
  {
    do
    {
      dt_image_synch_xmp(GPOINTER_TO_INT(list_iter->data));
    } while((list_iter = g_list_next(list_iter)) != NULL);
  }
  g_list_free(g_list_first(tagged_images));

  update(self, 0);
  update(self, 1);

  dt_control_signal_raise(darktable.signals, DT_SIGNAL_TAG_CHANGED);
}
static void
action_caja_manual_callback (GtkAction *action,
                             gpointer user_data)
{
    CajaWindow *window;
    GError *error;
    GtkWidget *dialog;

    error = NULL;
    window = CAJA_WINDOW (user_data);

    if (CAJA_IS_DESKTOP_WINDOW (window))
    {
#if GTK_CHECK_VERSION (3, 0, 0)
        GdkScreen *screen;
        GdkAppLaunchContext *launch_context;
        GAppInfo *app_info = NULL;
        app_info = g_app_info_create_from_commandline ("mate-help",
                                                       NULL,
                                                       G_APP_INFO_CREATE_NONE,
                                                       &error);
        if (error == NULL)
        {
            screen = gtk_window_get_screen(GTK_WINDOW(window));
            launch_context = gdk_app_launch_context_new ();
            gdk_app_launch_context_set_screen (launch_context, screen);
            g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error);
            g_object_unref (launch_context);
        }
        if (app_info != NULL)
            g_object_unref (app_info);
#else
#if GTK_CHECK_VERSION (2, 24, 0)
        gdk_spawn_command_line_on_screen(gtk_window_get_screen(GTK_WINDOW(window)), "mate-help", &error);
#else
        g_spawn_command_line_async("mate-help", &error);
#endif
#endif
    }
    else
    {
        gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (window)),
                      "help:mate-user-guide/goscaja-1",
                      gtk_get_current_event_time (), &error);
    }

    if (error)
    {
        dialog = gtk_message_dialog_new (GTK_WINDOW (window),
                                         GTK_DIALOG_MODAL,
                                         GTK_MESSAGE_ERROR,
                                         GTK_BUTTONS_OK,
                                         _("There was an error displaying help: \n%s"),
                                         error->message);
        g_signal_connect (G_OBJECT (dialog), "response",
                          G_CALLBACK (gtk_widget_destroy),
                          NULL);

        gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
        gtk_widget_show (dialog);
        g_error_free (error);
    }
}
void XAP_UnixDialog_MessageBox::runModal(XAP_Frame * pFrame)
{
    XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(pFrame->getFrameImpl());
    UT_return_if_fail(pUnixFrameImpl);

    XAP_UnixApp * pApp = static_cast<XAP_UnixApp *>(XAP_App::getApp());
    UT_return_if_fail(pApp);

    GtkWidget * message = 0;	// initialize to prevent compiler warning
    GtkWindow * toplevel;

    toplevel = GTK_WINDOW(pUnixFrameImpl->getTopLevelWindow());

    int dflFlags = GTK_DIALOG_MODAL;
    int dflResponse = GTK_RESPONSE_OK;

    switch (m_buttons)
    {
    case b_O:
	// just put up an information box
	message = gtk_message_dialog_new ( toplevel, GTK_DIALOG_MODAL,
					   GTK_MESSAGE_INFO,
					   GTK_BUTTONS_OK,
					   "%s",
					   m_szMessage ) ;

	break;

    case b_YN:
	// YES - NO - most certainly a question
	message = gtk_message_dialog_new ( toplevel, GTK_DIALOG_MODAL,
					   GTK_MESSAGE_QUESTION,
					   GTK_BUTTONS_YES_NO,
					   "%s",
					   m_szMessage ) ;
	if(m_defaultAnswer == XAP_Dialog_MessageBox::a_YES)
	{
	    gtk_dialog_set_default_response (GTK_DIALOG(message),
					     GTK_RESPONSE_YES);
	}
	else
	{
	    gtk_dialog_set_default_response (GTK_DIALOG(message),
					     GTK_RESPONSE_NO);
	}
	break;

    case b_YNC:
    {
	// YES - NO - CANCEL
	// this is only used for saving files.
#ifndef EMBEDDED_TARGET
	std::string no, cancel, save;
	std::string labelText;
	const XAP_StringSet * pSS = pApp->getStringSet ();

	message = gtk_dialog_new_with_buttons("",
					      toplevel,
					      static_cast<GtkDialogFlags>(dflFlags),
					      NULL, NULL);
	pSS->getValueUTF8(XAP_STRING_ID_DLG_Exit_CloseWithoutSaving, no);
	pSS->getValueUTF8(XAP_STRING_ID_DLG_Cancel, cancel);
	pSS->getValueUTF8(XAP_STRING_ID_DLG_Save, save);
	gtk_dialog_add_buttons(GTK_DIALOG(message),
			       convertMnemonics(no).c_str(),
			       GTK_RESPONSE_NO,
			       convertMnemonics(cancel).c_str(),
			       GTK_RESPONSE_CANCEL,
			       convertMnemonics(save).c_str(),
			       GTK_RESPONSE_YES,
			       NULL);

	dflResponse = GTK_RESPONSE_YES;

	GtkWidget * label = gtk_label_new(NULL);
	const char * separator;
	separator = m_szSecondaryMessage ? "\n\n" : "";

	gchar     * msg = g_markup_escape_text (m_szMessage, -1);
	labelText = UT_std_string_sprintf(
	    "<span weight=\"bold\" size=\"larger\">%s</span>%s%s",
	    msg, separator, m_szSecondaryMessage);
	g_free (msg); msg = NULL;

	gtk_label_set_markup(GTK_LABEL(label), labelText.c_str());

	GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);

	gtk_box_pack_start (GTK_BOX (hbox),
			    gtk_image_new_from_icon_name("dialog-warning",
							 GTK_ICON_SIZE_DIALOG),
			    FALSE, FALSE, 0);

	gtk_box_pack_start (GTK_BOX (hbox), label,
			    TRUE, TRUE, 0);

	GtkBox *content_area = GTK_BOX (gtk_dialog_get_content_area(GTK_DIALOG(message)));
	gtk_box_pack_start (content_area, hbox, FALSE, FALSE, 0);

	gtk_box_set_spacing(content_area, 12);
	gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
	gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);

	gtk_widget_show_all (hbox);

#else
	message = gtk_message_dialog_new (toplevel,
					  static_cast<GtkDialogFlags>(dflFlags),
					  GTK_MESSAGE_QUESTION,
					  GTK_BUTTONS_NONE,
					  "%s",
					  m_szMessage);

	gtk_dialog_add_buttons(GTK_DIALOG(message),
			       GTK_STOCK_NO,
			       GTK_RESPONSE_NO,
			       GTK_STOCK_CANCEL,
			       GTK_RESPONSE_CANCEL,
			       GTK_STOCK_YES,
			       GTK_RESPONSE_YES,
			       NULL);
#endif
	gtk_dialog_set_default_response (GTK_DIALOG(message),
					 GTK_RESPONSE_CANCEL);

	break;
    }
    default:
	UT_ASSERT_NOT_REACHED();
    }

    // set the title to '', as per GNOME HIG, Section 3, Alerts
    gtk_window_set_title (GTK_WINDOW(message), "");

    UT_ASSERT(message);

    switch ( abiRunModalDialog ( GTK_DIALOG(message), pFrame,
				 this, dflResponse, true, ATK_ROLE_ALERT ) )
    {
    case GTK_RESPONSE_OK:
	m_answer = XAP_Dialog_MessageBox::a_OK;
	break;
    case GTK_RESPONSE_YES:
	m_answer = XAP_Dialog_MessageBox::a_YES;
	break;
    case GTK_RESPONSE_NO:
	m_answer = XAP_Dialog_MessageBox::a_NO;
	break;
    case GTK_RESPONSE_CANCEL:
    default:
	m_answer = XAP_Dialog_MessageBox::a_CANCEL; break;
    }
}
Example #11
0
gboolean updatecheck (GtkWindow* parent) {
    GtkWidget* dialog;
    struct sockaddr_in servaddr;
    struct hostent *hp;
    gint sock_fd = 0, i = 0;
    struct timeval timeout;
    gchar data[BUFSIZ] = { 0 };
    const gchar* avail_version;
    const gchar* request = "GET /projects/gummi/repository/raw/"
        "trunk/dev/latest HTTP/1.1\r\n"
        "User-Agent: Gummi\r\n"
        "Host: dev.midnightcoding.org\r\n"
        "\r\n";

    if (-1 == (sock_fd = socket (AF_INET, SOCK_STREAM, 0))) {
        slog (L_ERROR, "socket () error\n");
        return FALSE;
    }

    /* set timeout to prevent hanging */
    memset (&timeout, 0, sizeof (struct timeval));
    timeout.tv_sec = 5;
    if (setsockopt (sock_fd, SOL_SOCKET, SO_RCVTIMEO, &timeout,
            sizeof (struct timeval))) {
        slog (L_ERROR, "setsockopt () error\n");
        return FALSE;
    }

    memset (&servaddr, 0, sizeof (servaddr));
    if (NULL == (hp = gethostbyname ("dev.midnightcoding.org"))) {
        slog (L_ERROR, "gethostbyname () error\n");
        return FALSE;
    }

    memcpy((gchar*)&servaddr.sin_addr.s_addr, (gchar*)hp->h_addr, hp->h_length);
    servaddr.sin_port = htons (80);
    servaddr.sin_family = AF_INET;

    if (0 != connect(sock_fd, (struct sockaddr*)&servaddr, sizeof (servaddr))) {
        slog (L_G_ERROR, "connect () error");
        return FALSE;
    }

    write (sock_fd, request, strlen (request));
    read (sock_fd, data, BUFSIZ);

    if (0 == strlen (data)) {
        slog (L_ERROR, "connection timeout\n");
        return FALSE;
    }

    /* get version string */
    for (i = strlen (data) -2; i >= 0 && data[i] != '\n'; --i);
    avail_version = data + i + 1;
    
    slog (L_INFO, "Currently installed: "PACKAGE_VERSION"\n");
    slog (L_INFO, "Currently available: %s", avail_version);
    
    /* TODO: move gtk part to gui-menu.c */

    dialog = gtk_message_dialog_new (parent, 
        GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
        GTK_MESSAGE_INFO,
        GTK_BUTTONS_OK,
        _("Currently installed:\n%s\n\nCurrently available:\n%s"),
        PACKAGE_VERSION, avail_version);
    gtk_window_set_title (GTK_WINDOW (dialog), _("Update Check"));
    gtk_dialog_run (GTK_DIALOG (dialog));      
    gtk_widget_destroy (dialog);

    return TRUE;
}
static gboolean
handle_access_dialog (XdpImplAccess *object,
                      GDBusMethodInvocation *invocation,
                      const char *arg_handle,
                      const char *arg_app_id,
                      const char *arg_parent_window,
                      const char *arg_title,
                      const char *arg_subtitle,
                      const char *arg_body,
                      GVariant *arg_options)
{
  g_autoptr(Request) request = NULL;
  const char *sender;
  AccessDialogHandle *handle;
  g_autoptr(GError) error = NULL;
  g_autofree char *filename = NULL;
  gboolean modal;
  GtkWidget *dialog;
  GdkWindow *foreign_parent = NULL;
  const char *deny_label;
  const char *grant_label;
  const char *icon;
  g_autoptr(GVariant) choices = NULL;
  GtkWidget *area;
  GtkWidget *image;
  GHashTable *choice_table = NULL;

  sender = g_dbus_method_invocation_get_sender (invocation);

  request = request_new (sender, arg_app_id, arg_handle);

  if (!g_variant_lookup (arg_options, "modal", "b", &modal))
    modal = TRUE;

  if (!g_variant_lookup (arg_options, "deny_label", "&s", &deny_label))
    deny_label = _("Deny Access");

  if (!g_variant_lookup (arg_options, "grant_label", "&s", &grant_label))
    grant_label = _("Grant Access");

  if (!g_variant_lookup (arg_options, "icon", "&s", &icon))
    icon = NULL;

  choices = g_variant_lookup_value (arg_options, "choices", G_VARIANT_TYPE ("a(ssa(ss)s)"));

  dialog = gtk_message_dialog_new (NULL,
                                   0,
                                   GTK_MESSAGE_QUESTION,
                                   GTK_BUTTONS_NONE,
                                   arg_title,
                                   NULL);
  gtk_window_set_modal (GTK_WINDOW (dialog), modal);
  gtk_dialog_add_button (GTK_DIALOG (dialog), deny_label, GTK_RESPONSE_CANCEL);
  gtk_dialog_add_button (GTK_DIALOG (dialog), grant_label, GTK_RESPONSE_OK);
  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", arg_subtitle);

  area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
  fix_up_label_alignment (area);

  if (choices)
    {
      int i;

      choice_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
      for (i = 0; i < g_variant_n_children (choices); i++)
        add_choice (area, g_variant_get_child_value (choices, i), choice_table);
    }

  if (!g_str_equal (arg_body, ""))
    {
      GtkWidget *body_label;

      body_label = gtk_label_new (arg_body);
      gtk_widget_set_halign (body_label, GTK_ALIGN_START);
      g_object_set (body_label, "margin-top", 10, NULL);
      gtk_label_set_xalign (GTK_LABEL (body_label), 0);
      gtk_label_set_line_wrap (GTK_LABEL (body_label), TRUE);
      gtk_label_set_max_width_chars (GTK_LABEL (body_label), 50);
      gtk_widget_show (body_label);
      gtk_container_add (GTK_CONTAINER (area), body_label);
    }

  image = gtk_image_new_from_icon_name (icon ? icon : "image-missing", GTK_ICON_SIZE_DIALOG);
  gtk_widget_set_opacity (image, icon ? 1.0 : 0.0);
  gtk_widget_show (image);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
G_GNUC_END_IGNORE_DEPRECATIONS

#ifdef GDK_WINDOWING_X11
  if (g_str_has_prefix (arg_parent_window, "x11:"))
    {
      int xid;

      if (sscanf (arg_parent_window, "x11:%x", &xid) != 1)
        g_warning ("invalid xid");
      else
        foreign_parent = gdk_x11_window_foreign_new_for_display (gtk_widget_get_display (dialog), xid);
    }
#endif
  else
    g_warning ("Unhandled parent window type %s", arg_parent_window);

  handle = g_new0 (AccessDialogHandle, 1);
  handle->impl = object;
  handle->invocation = invocation;
  handle->request = g_object_ref (request);
  handle->dialog = g_object_ref (dialog);
  handle->choices = choice_table;

  g_signal_connect (request, "handle-close", G_CALLBACK (handle_close), handle);

  g_signal_connect (dialog, "response", G_CALLBACK (access_dialog_response), handle);

  gtk_widget_realize (dialog);

  if (foreign_parent)
    gdk_window_set_transient_for (gtk_widget_get_window (dialog), foreign_parent);

  gtk_widget_show (dialog);

  request_export (request, g_dbus_method_invocation_get_connection (invocation));

  return TRUE;
}
Example #13
0
static int
common_gtk_glade_main( struct configured_features *my_config) {
	SDL_TimerID limiter_timer;
        gdbstub_handle_t arm9_gdb_stub;
        gdbstub_handle_t arm7_gdb_stub;
        struct armcpu_memory_iface *arm9_memio = &arm9_base_memory_iface;
        struct armcpu_memory_iface *arm7_memio = &arm7_base_memory_iface;
        struct armcpu_ctrl_iface *arm9_ctrl_iface;
        struct armcpu_ctrl_iface *arm7_ctrl_iface;

#ifdef GTKGLEXT_AVAILABLE
// check if you have GTHREAD when running configure script
	//g_thread_init(NULL);
	register_gl_fun(my_gl_Begin,my_gl_End);
#endif

#ifdef DEBUG
        LogStart();
#endif
	init_keyvals();

        if ( my_config->arm9_gdb_port != 0) {
          arm9_gdb_stub = createStub_gdb( my_config->arm9_gdb_port,
                                          &arm9_memio,
                                          &arm9_base_memory_iface);

          if ( arm9_gdb_stub == NULL) {
            g_print( "Failed to create ARM9 gdbstub on port %d\n",
                     my_config->arm9_gdb_port);
            return -1;
          }
        }
        if ( my_config->arm7_gdb_port != 0) {
          arm7_gdb_stub = createStub_gdb( my_config->arm7_gdb_port,
                                          &arm7_memio,
                                          &arm7_base_memory_iface);

          if ( arm7_gdb_stub == NULL) {
            g_print( "Failed to create ARM7 gdbstub on port %d\n",
                     my_config->arm7_gdb_port);
            return -1;
          }
        }


	if(SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO) == -1)
          {
            fprintf(stderr, "Error trying to initialize SDL: %s\n",
                    SDL_GetError());
            return 1;
          }

	desmume_init( arm9_memio, &arm9_ctrl_iface,
                      arm7_memio, &arm7_ctrl_iface);

        /*
         * Activate the GDB stubs
         * This has to come after the NDS_Init (called in desmume_init)
         * where the cpus are set up.
         */
        if ( my_config->arm9_gdb_port != 0) {
          activateStub_gdb( arm9_gdb_stub, arm9_ctrl_iface);
        }
        if ( my_config->arm7_gdb_port != 0) {
          activateStub_gdb( arm7_gdb_stub, arm7_ctrl_iface);
        }

        /* Initialize joysticks */
        if(!init_joy()) return 1;

	CONFIG_FILE = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL);
	Read_ConfigFile();

	/* load the interface */
	xml           = glade_xml_new(get_ui_file("DeSmuMe.glade"), NULL, NULL);
	xml_tools     = glade_xml_new(get_ui_file("DeSmuMe_Dtools.glade"), NULL, NULL);
	pWindow       = glade_xml_get_widget(xml, "wMainW");
	pDrawingArea  = glade_xml_get_widget(xml, "wDraw_Main");
	pDrawingArea2 = glade_xml_get_widget(xml, "wDraw_Sub");

	/* connect the signals in the interface */
	glade_xml_signal_autoconnect_StringObject(xml);
	glade_xml_signal_autoconnect_StringObject(xml_tools);

	init_GL_capabilities( my_config->software_colour_convert);

	/* check command line file */
	if( my_config->nds_file) {
		if(desmume_open( my_config->nds_file) >= 0)	{
			desmume_resume();
			enable_rom_features();
		} else {
			GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow),
					GTK_DIALOG_MODAL,
					GTK_MESSAGE_INFO,
					GTK_BUTTONS_OK,
					"Unable to load :\n%s", my_config->nds_file);
			gtk_dialog_run(GTK_DIALOG(pDialog));
			gtk_widget_destroy(pDialog);
		}
	}

        gtk_widget_show(pDrawingArea);
        gtk_widget_show(pDrawingArea2);

        {
          int use_null_3d = my_config->disable_3d;

#ifdef GTKGLEXT_AVAILABLE
          if ( !use_null_3d) {
            /* setup the gdk 3D emulation */
            if ( init_opengl_gdk_3Demu()) {
              NDS_3D_SetDriver(1);

              if (!gpu3D->NDS_3D_Init()) {
                fprintf( stderr, "Failed to initialise openGL 3D emulation; "
                         "removing 3D support\n");
                use_null_3d = 1;
              }
            }
            else {
              fprintf( stderr, "Failed to setup openGL 3D emulation; "
                       "removing 3D support\n");
              use_null_3d = 1;
            }
          }
#endif
          if ( use_null_3d) {
            NDS_3D_SetDriver ( 0);
            gpu3D->NDS_3D_Init();
          }
        }

//	on_menu_tileview_activate(NULL,NULL);

        /* setup the frame limiter and indicate if it is disabled */
        glade_fps_limiter_disabled = my_config->disable_limiter;

        if ( !glade_fps_limiter_disabled) {
          /* create the semaphore used for fps limiting */
          glade_fps_limiter_semaphore = SDL_CreateSemaphore( 1);

          /* start a SDL timer for every FPS_LIMITER_FRAME_PERIOD
           * frames to keep us at 60 fps */
          limiter_timer = SDL_AddTimer( 16 * FPS_LIMITER_FRAME_PERIOD,
                                        glade_fps_limiter_fn,
                                        glade_fps_limiter_semaphore);
          if ( limiter_timer == NULL) {
            fprintf( stderr, "Error trying to start FPS limiter timer: %s\n",
                     SDL_GetError());
            SDL_DestroySemaphore( glade_fps_limiter_semaphore);
            glade_fps_limiter_disabled = 1;
          }
        }

	/* start event loop */
	gtk_main();
	desmume_free();

        if ( !glade_fps_limiter_disabled) {
          /* tidy up the FPS limiter timer and semaphore */
          SDL_RemoveTimer( limiter_timer);
          SDL_DestroySemaphore( glade_fps_limiter_semaphore);
        }

#ifdef DEBUG
        LogStop();
#endif
        /* Unload joystick */
        uninit_joy();

	SDL_Quit();
	Write_ConfigFile();
	return EXIT_SUCCESS;
}
Example #14
0
/*! \brief Main Scheme(GUILE) program function.
 *  \par Function Description
 *  This function is the main program called from scm_boot_guile.
 *  It handles initializing all libraries and gSchem variables
 *  and passes control to the gtk main loop.
 */
void main_prog(void *closure, int argc, char *argv[])
{
  int i;
  char *cwd = NULL;
  GSCHEM_TOPLEVEL *w_current = NULL;
  char *input_str = NULL;
  int argv_index;
  int first_page = 1;
  char *filename;
  SCM scm_tmp;

#ifdef HAVE_GTHREAD
  /* Gschem isn't threaded, but some of GTK's file chooser
   * backends uses threading so we need to call g_thread_init().
   * GLib requires threading be initialised before any other GLib
   * functions are called. Do it now if its not already setup.  */
  if (!g_thread_supported ()) g_thread_init (NULL);
#endif

#if ENABLE_NLS
  /* this should be equivalent to setlocale (LC_ALL, "") */
  gtk_set_locale();

  /* This must be the same for all locales */
  setlocale(LC_NUMERIC, "C");

  /* Disable gtk's ability to set the locale. */ 
  /* If gtk is allowed to set the locale, then it will override the     */
  /* setlocale for LC_NUMERIC (which is important for proper PS output. */
  /* This may look funny here, given we make a call to gtk_set_locale() */
  /* above.  I don't know yet, if this is really the right thing to do. */
  gtk_disable_setlocale(); 

#endif

  gtk_init(&argc, &argv);

  argv_index = parse_commandline(argc, argv);
  cwd = g_get_current_dir();
  
  libgeda_init();

  /* create log file right away even if logging is enabled */
  s_log_init ("gschem");

  s_log_message(
                _("gEDA/gschem version %s%s.%s\n"), PREPEND_VERSION_STRING,
                PACKAGE_DOTTED_VERSION, PACKAGE_DATE_VERSION);
  s_log_message(
                _("gEDA/gschem comes with ABSOLUTELY NO WARRANTY; see COPYING for more details.\n"));
  s_log_message(
                _("This is free software, and you are welcome to redistribute it under certain\n"));
  s_log_message(
                _("conditions; please see the COPYING file for more details.\n\n")); 

#if defined(__MINGW32__) && defined(DEBUG)
  fprintf(stderr, _("This is the MINGW32 port.\n"));
#endif  

#if DEBUG
  fprintf(stderr, _("Current locale settings: %s\n"), setlocale(LC_ALL, NULL));
#endif

  /* init global buffers */
  o_buffer_init();

  /* register guile (scheme) functions */
  g_register_funcs();
  g_init_window ();
  g_init_select ();
  g_init_hook ();
  g_init_attrib ();
  g_init_keys ();
  g_init_util ();

  /* initialise color map (need to do this before reading rc files */
  x_color_init ();

  o_undo_init(); 

  if (s_path_sys_data () == NULL) {
    const gchar *message = 
      _("You must set the GEDADATA environment variable!\n\n"
        "gschem cannot locate its data files. You must set the GEDADATA\n"
        "environment variable to point to the correct location.\n");
    GtkWidget* error_diag =
      gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR,
                              GTK_BUTTONS_OK,
                              "%s", message);
    gtk_dialog_run (GTK_DIALOG (error_diag));
    g_error ("%s", message);
  }

  /* Allocate w_current */
  w_current = gschem_toplevel_new ();

  /* Connect hooks that run for each s_toplevel_new() first */
  s_toplevel_append_new_hook ((NewToplevelFunc) add_libgeda_toplevel_hooks,
                              w_current);

  w_current->toplevel = s_toplevel_new ();

  w_current->toplevel->load_newer_backup_func = x_fileselect_load_backup;
  w_current->toplevel->load_newer_backup_data = w_current;

  o_text_set_rendered_bounds_func (w_current->toplevel,
                                   o_text_get_rendered_bounds, w_current);

  /* Damage notifications should invalidate the object on screen */
  o_add_change_notify (w_current->toplevel,
                       (ChangeNotifyFunc) o_invalidate,
                       (ChangeNotifyFunc) o_invalidate, w_current);

  scm_dynwind_begin (0);
  g_dynwind_window (w_current);

  /* Run pre-load Scheme expressions */
  g_scm_eval_protected (s_pre_load_expr, scm_current_module ());

  /* By this point, libgeda should have setup the Guile load path, so
   * we can take advantage of that.  */
  scm_tmp = scm_sys_search_load_path (scm_from_utf8_string ("gschem.scm"));
  if (scm_is_false (scm_tmp)) {
    s_log_message (_("Couldn't find init scm file [%s]\n"), "gschem.scm");
  }
  input_str = scm_to_utf8_string (scm_tmp);
  if (g_read_file(w_current->toplevel, input_str, NULL)) {
    s_log_message(_("Read init scm file [%s]\n"), input_str);
  } else {
    /*! \todo These two messages are the same. Should be
     * integrated. */
    s_log_message(_("Failed to read init scm file [%s]\n"),
                  input_str);
  }
  free (input_str); /* M'allocated by scm_to_utf8_string() */
  scm_remember_upto_here_1 (scm_tmp);

  /* Now read in RC files. */
  g_rc_parse_gtkrc();
  x_rc_parse_gschem (w_current, rc_filename);

  /* Set default icon */
  x_window_set_default_icon();

  /* At end, complete set up of window. */
  x_color_allocate();
  x_window_setup (w_current);

#ifdef HAVE_LIBSTROKE
  x_stroke_init ();
#endif /* HAVE_LIBSTROKE */

  for (i = argv_index; i < argc; i++) {

    if (g_path_is_absolute(argv[i]))
    {
      /* Path is already absolute so no need to do any concat of cwd */
      filename = g_strdup (argv[i]);
    } else {
      filename = g_build_filename (cwd, argv[i], NULL);
    }

    if ( first_page )
      first_page = 0;

    /*
     * SDB notes:  at this point the filename might be unnormalized, like
     * /path/to/foo/../bar/baz.sch.  Bad filenames will be normalized in
     * f_open (called by x_window_open_page). This works for Linux and MINGW32.
     */
    x_window_open_page(w_current, filename);
    g_free (filename);
  }

  g_free(cwd);

  /* If no page has been loaded (wasn't specified in the command line.) */
  /* Then create an untitled page */
  if ( first_page ) {
    x_window_open_page( w_current, NULL );
  }

  /* Update the window to show the current page */
  x_window_set_current_page( w_current, w_current->toplevel->page_current );


#if DEBUG
  scm_c_eval_string ("(display \"hello guile\n\")");
#endif

  /* Run post-load expressions */
  g_scm_eval_protected (s_post_load_expr, scm_current_module ());

  /* open up log window on startup */
  if (w_current->log_window == MAP_ON_STARTUP) {
    x_log_open ();
  }

  /* if there were any symbols which had major changes, put up an error */
  /* dialog box */
  major_changed_dialog(w_current);

  scm_dynwind_end ();

  /* enter main loop */
  gtk_main();
}
Example #15
0
static PropertyPage *
create_property_page (NemoFileInfo *fileinfo)
{
  PropertyPage *page;
  GError *error;
  ShareInfo *share_info;
  char *share_name;
  gboolean free_share_name;
  const char *comment;
  char *apply_button_label;

  page = g_new0 (PropertyPage, 1);

  page->path = get_fullpath_from_fileinfo(fileinfo);
  page->fileinfo = g_object_ref (fileinfo);
  page->samba_check_ok = FALSE;

  error = NULL;
  if (!shares_get_share_info_for_path (page->path, &share_info, &error))
    {
      /* We'll assume that there is no share for that path, but we'll still
       * bring up an error dialog.
       */
      GtkWidget *message;

      message = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
					_("There was an error while getting the sharing information"));
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s", error->message);
      gtk_widget_show (message);

      share_info = NULL;
      g_error_free (error);
      error = NULL;
    }


  page->xml = gtk_builder_new ();
  gtk_builder_set_translation_domain (page->xml, "nemo-extensions");
  g_assert (gtk_builder_add_from_file (page->xml,
              INTERFACES_DIR"/share-dialog.ui", &error));

  page->main = GTK_WIDGET (gtk_builder_get_object (page->xml, "vbox1"));
  g_assert (page->main != NULL);

  g_object_set_data_full (G_OBJECT (page->main),
			  "PropertyPage",
			  page,
			  free_property_page_cb);

  page->switch_share_folder = GTK_WIDGET (gtk_builder_get_object (page->xml,"switch_share_folder"));
  page->hbox_share_comment = GTK_WIDGET (gtk_builder_get_object (page->xml,"hbox_share_comment"));
  page->hbox_share_name = GTK_WIDGET (gtk_builder_get_object (page->xml,"hbox_share_name"));
  page->checkbutton_share_rw_ro = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_rw_ro"));
  page->checkbutton_share_guest_ok = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_guest_ok"));
  page->entry_share_name = GTK_WIDGET (gtk_builder_get_object (page->xml,"entry_share_name"));
  page->entry_share_comment = GTK_WIDGET (gtk_builder_get_object (page->xml,"entry_share_comment"));
  page->label_status = GTK_WIDGET (gtk_builder_get_object (page->xml,"label_status"));
  page->button_cancel = GTK_WIDGET (gtk_builder_get_object (page->xml,"button_cancel"));
  page->button_apply = GTK_WIDGET (gtk_builder_get_object (page->xml,"button_apply"));

  page->samba_infobar = GTK_WIDGET (gtk_builder_get_object (page->xml, "samba_infobar"));
  page->samba_label = GTK_WIDGET (gtk_builder_get_object (page->xml, "samba_label"));
  page->install_samba_button = GTK_WIDGET (gtk_builder_get_object (page->xml, "install_samba_button"));

  /* Sanity check so that we don't screw up the Glade file */
  g_assert (page->switch_share_folder != NULL
	    && page->hbox_share_comment != NULL
	    && page->hbox_share_name != NULL
	    && page->checkbutton_share_rw_ro != NULL
	    && page->checkbutton_share_guest_ok != NULL
	    && page->entry_share_name != NULL
	    && page->entry_share_comment != NULL
	    && page->label_status != NULL
	    && page->button_cancel != NULL
	    && page->button_apply != NULL);

  if (share_info)
    {
      page->was_initially_shared = TRUE;
      page->was_writable = share_info->is_writable;
    }

  /* Share name */

  if (share_info)
    {
      share_name = share_info->share_name;
      free_share_name = FALSE;
    }
  else
    {
      share_name = g_filename_display_basename (page->path);
      free_share_name = TRUE;
    }

  gtk_entry_set_text (GTK_ENTRY (page->entry_share_name), share_name);

  if (free_share_name)
    g_free (share_name);

  /* Comment */

  if (share_info == NULL || share_info->comment == NULL)
    comment = "";
  else
    comment = share_info->comment;

  gtk_entry_set_text (GTK_ENTRY (page->entry_share_comment), comment);

  /* Share toggle */

  if (share_info)
    gtk_switch_set_active (GTK_SWITCH (page->switch_share_folder), TRUE);
  else
    {
      gtk_switch_set_active (GTK_SWITCH (page->switch_share_folder), FALSE);
    }

  /* Share name */

  if (g_utf8_strlen(gtk_entry_get_text (GTK_ENTRY (page->entry_share_name)), -1) > 12)
    property_page_set_warning (page);

  /* Permissions */
  if (share_info != NULL && share_info->is_writable)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_rw_ro), TRUE);
  else
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_rw_ro), FALSE);

  /* Guest access */
  if (share_info != NULL && share_info->guest_ok)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_guest_ok), TRUE);
  else
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_guest_ok), FALSE);

  /* Apply button */

  if (share_info)
    apply_button_label = _("Modify _Share");
  else
    apply_button_label = _("Create _Share");

  gtk_button_set_label (GTK_BUTTON (page->button_apply), apply_button_label);
  gtk_button_set_use_underline (GTK_BUTTON (page->button_apply), TRUE);
  gtk_button_set_image (GTK_BUTTON (page->button_apply), gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_BUTTON));

  gtk_widget_set_sensitive (page->button_apply, FALSE);

  /* Sensitivity */

  property_page_check_sensitivity (page);

  if (!check_samba_installed ()) {
    gtk_widget_show (page->samba_infobar);
    gtk_widget_set_sensitive (page->switch_share_folder, FALSE);
  } else {
    gtk_widget_hide (page->samba_infobar);
    gtk_widget_set_sensitive (page->switch_share_folder, TRUE);
  }

  /* Signal handlers */

  g_signal_connect_swapped (page->switch_share_folder, "notify::active",
                            G_CALLBACK (on_switch_share_folder_active_changed),
                            page);

  g_signal_connect (page->checkbutton_share_rw_ro, "toggled",
                    G_CALLBACK (on_checkbutton_rw_ro_toggled),
                    page);

  g_signal_connect (page->checkbutton_share_guest_ok, "toggled",
                    G_CALLBACK (on_checkbutton_guest_ok_toggled),
                    page);

  g_signal_connect (page->entry_share_name, "changed",
                    G_CALLBACK (modify_share_name_text_entry),
                    page);

  g_signal_connect (page->entry_share_comment, "changed",
		    G_CALLBACK (modify_share_comment_text_entry),
		    page);

  g_signal_connect (page->button_apply, "clicked",
		    G_CALLBACK (button_apply_clicked_cb), page);

  g_signal_connect (page->install_samba_button, "clicked",
            G_CALLBACK (install_samba_clicked_cb), page);

  if (share_info != NULL)
    shares_free_share_info (share_info);

  return page;
}
NS_IMETHODIMP
nsNativeAppSupportUnix::Start(bool *aRetVal)
{
  NS_ASSERTION(gAppData, "gAppData must not be null.");

#if (MOZ_WIDGET_GTK == 2)
  if (gtk_major_version < MIN_GTK_MAJOR_VERSION ||
      (gtk_major_version == MIN_GTK_MAJOR_VERSION && gtk_minor_version < MIN_GTK_MINOR_VERSION)) {
    GtkWidget* versionErrDialog = gtk_message_dialog_new(NULL,
                     GtkDialogFlags(GTK_DIALOG_MODAL |
                                    GTK_DIALOG_DESTROY_WITH_PARENT),
                     GTK_MESSAGE_ERROR,
                     GTK_BUTTONS_OK,
                     UNSUPPORTED_GTK_MSG,
                     gtk_major_version,
                     gtk_minor_version,
                     MIN_GTK_MAJOR_VERSION,
                     MIN_GTK_MINOR_VERSION);
    gtk_dialog_run(GTK_DIALOG(versionErrDialog));
    gtk_widget_destroy(versionErrDialog);
    exit(0);
  }
#endif

#if (MOZ_PLATFORM_MAEMO == 5)
  /* zero state out. */
  memset(&m_hw_state, 0, sizeof(osso_hw_state_t));

  /* Initialize maemo application
     
     The initalization name will be of the form "Vendor.Name".
     If a Vendor isn't given, then we will just use "Name".
     
     Note that this value must match your X-Osso-Service name
     defined in your desktop file.  If it doesn't, the OSSO
     system will happily kill your process.
  */
  nsAutoCString applicationName;
  if (gAppData->vendor) {
      applicationName.Append(gAppData->vendor);
      applicationName.Append(".");
  }
  applicationName.Append(gAppData->name);
  ToLowerCase(applicationName);

  m_osso_context = osso_initialize(applicationName.get(), 
                                   gAppData->version ? gAppData->version : "1.0",
                                   true,
                                   nullptr);

  /* Check that initilialization was ok */
  if (m_osso_context == nullptr) {
      return NS_ERROR_FAILURE;
  }

  osso_hw_set_event_cb(m_osso_context, nullptr, OssoHardwareCallback, &m_hw_state);
  osso_hw_set_display_event_cb(m_osso_context, OssoDisplayCallback, m_osso_context);
  osso_rpc_set_default_cb_f(m_osso_context, OssoDbusCallback, nullptr);

  // Setup an MCE callback to monitor orientation
  DBusConnection *connnection = (DBusConnection*)osso_get_sys_dbus_connection(m_osso_context);
  dbus_bus_add_match(connnection, MCE_MATCH_RULE, nullptr);
  dbus_connection_add_filter(connnection, OssoModeControlCallback, nullptr, nullptr);
#endif

  *aRetVal = true;

#if defined(MOZ_X11) && (MOZ_WIDGET_GTK == 2)

  PRLibrary *gnomeuiLib = PR_LoadLibrary("libgnomeui-2.so.0");
  if (!gnomeuiLib)
    return NS_OK;

  PRLibrary *gnomeLib = PR_LoadLibrary("libgnome-2.so.0");
  if (!gnomeLib) {
    PR_UnloadLibrary(gnomeuiLib);
    return NS_OK;
  }

  _gnome_program_init_fn gnome_program_init =
    (_gnome_program_init_fn)PR_FindFunctionSymbol(gnomeLib, "gnome_program_init");
  _gnome_program_get_fn gnome_program_get =
    (_gnome_program_get_fn)PR_FindFunctionSymbol(gnomeLib, "gnome_program_get"); 
 _libgnomeui_module_info_get_fn libgnomeui_module_info_get = (_libgnomeui_module_info_get_fn)PR_FindFunctionSymbol(gnomeuiLib, "libgnomeui_module_info_get");
  if (!gnome_program_init || !gnome_program_get || !libgnomeui_module_info_get) {
    PR_UnloadLibrary(gnomeuiLib);
    PR_UnloadLibrary(gnomeLib);
    return NS_OK;
  }

#endif /* MOZ_X11 && (MOZ_WIDGET_GTK == 2) */

#ifdef ACCESSIBILITY
  // We will load gail, atk-bridge by ourself later
  // We can't run atk-bridge init here, because gail get the control
  // Set GNOME_ACCESSIBILITY to 0 can avoid this
  static const char *accEnv = "GNOME_ACCESSIBILITY";
  const char *accOldValue = getenv(accEnv);
  setenv(accEnv, "0", 1);
#endif

#if defined(MOZ_X11) && (MOZ_WIDGET_GTK == 2)
  if (!gnome_program_get()) {
    gnome_program_init("Gecko", "1.0", libgnomeui_module_info_get(), gArgc, gArgv, NULL);
  }
#endif /* MOZ_X11 && (MOZ_WIDGET_GTK == 2) */

#ifdef ACCESSIBILITY
  if (accOldValue) { 
    setenv(accEnv, accOldValue, 1);
  } else {
    unsetenv(accEnv);
  }
#endif

  // Careful! These libraries cannot be unloaded after this point because
  // gnome_program_init causes atexit handlers to be registered. Strange
  // crashes will occur if these libraries are unloaded.

  // TODO GTK3 - see Bug 694570 - Stop using libgnome and libgnomeui on Linux
#if defined(MOZ_X11) && (MOZ_WIDGET_GTK == 2)
  gnome_client_set_restart_command = (_gnome_client_set_restart_command_fn)
    PR_FindFunctionSymbol(gnomeuiLib, "gnome_client_set_restart_command");

  _gnome_master_client_fn gnome_master_client = (_gnome_master_client_fn)
    PR_FindFunctionSymbol(gnomeuiLib, "gnome_master_client");

  GnomeClient *client = gnome_master_client();
  g_signal_connect(client, "save-yourself", G_CALLBACK(save_yourself_cb), NULL);
  g_signal_connect(client, "die", G_CALLBACK(die_cb), NULL);

  // Set the correct/requested restart command in any case.

  // Is there a request to suppress default binary launcher?
  nsAutoCString path;
  char* argv1 = getenv("MOZ_APP_LAUNCHER");

  if(!argv1) {
    // Tell the desktop the command for restarting us so that we can be part of XSMP session restore
    NS_ASSERTION(gDirServiceProvider, "gDirServiceProvider is NULL! This shouldn't happen!");
    nsCOMPtr<nsIFile> executablePath;
    nsresult rv;

    bool dummy;
    rv = gDirServiceProvider->GetFile(XRE_EXECUTABLE_FILE, &dummy, getter_AddRefs(executablePath));

    if (NS_SUCCEEDED(rv)) {
      // Strip off the -bin suffix to get the shell script we should run; this is what Breakpad does
      nsAutoCString leafName;
      rv = executablePath->GetNativeLeafName(leafName);
      if (NS_SUCCEEDED(rv) && StringEndsWith(leafName, NS_LITERAL_CSTRING("-bin"))) {
        leafName.SetLength(leafName.Length() - strlen("-bin"));
        executablePath->SetNativeLeafName(leafName);
      }

      executablePath->GetNativePath(path);
      argv1 = (char*)(path.get());
    }
  }

  if (argv1) {
    gnome_client_set_restart_command(client, 1, &argv1);
  }
#endif /* MOZ_X11 && (MOZ_WIDGET_GTK == 2) */

  return NS_OK;
}
static gboolean
rejilla_status_dialog_deep_directory_cb (RejillaTrackDataCfg *project,
					 const gchar *name,
					 RejillaStatusDialog *dialog)
{
	gint answer;
	gchar *string;
	GtkWidget *message;
	GtkWindow *transient_win;
	RejillaStatusDialogPrivate *priv;

	priv = REJILLA_STATUS_DIALOG_PRIVATE (dialog);

	if (priv->accept_deep_files)
		return TRUE;

	if (priv->reject_deep_files)
		return FALSE;

	g_signal_emit (dialog,
	               rejilla_status_dialog_signals [USER_INTERACTION],
	               0);

	gtk_widget_hide (GTK_WIDGET (dialog));

	string = g_strdup_printf (_("Do you really want to add \"%s\" to the selection?"), name);
	transient_win = gtk_window_get_transient_for (GTK_WINDOW (dialog));
	message = gtk_message_dialog_new (transient_win,
	                                  GTK_DIALOG_DESTROY_WITH_PARENT|
					  GTK_DIALOG_MODAL,
					  GTK_MESSAGE_WARNING,
					  GTK_BUTTONS_NONE,
					  "%s",
					  string);
	g_free (string);

	if (gtk_window_get_icon_name (GTK_WINDOW (dialog)))
		gtk_window_set_icon_name (GTK_WINDOW (message),
					  gtk_window_get_icon_name (GTK_WINDOW (dialog)));
	else if (transient_win)
		gtk_window_set_icon_name (GTK_WINDOW (message),
					  gtk_window_get_icon_name (transient_win));

	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message),
						  _("The children of this directory will have 7 parent directories."
						    "\nRejilla can create an image of such a file hierarchy and burn it but the disc may not be readable on all operating systems."
						    "\nNote: Such a file hierarchy is known to work on Linux."));

	gtk_dialog_add_button (GTK_DIALOG (message), _("Ne_ver Add Such File"), GTK_RESPONSE_REJECT);
	gtk_dialog_add_button (GTK_DIALOG (message), _("Al_ways Add Such File"), GTK_RESPONSE_ACCEPT);

	answer = gtk_dialog_run (GTK_DIALOG (message));
	gtk_widget_destroy (message);

	gtk_widget_show (GTK_WIDGET (dialog));

	priv->accept_deep_files = (answer == GTK_RESPONSE_ACCEPT);
	priv->reject_deep_files = (answer == GTK_RESPONSE_REJECT);

	return (answer != GTK_RESPONSE_YES && answer != GTK_RESPONSE_ACCEPT);
}
Example #18
0
/**
 * thunar_dialogs_show_job_ask:
 * @parent   : the parent #GtkWindow or %NULL.
 * @question : the question text.
 * @choices  : possible responses.
 *
 * Utility function to display a question dialog for the ThunarJob::ask
 * signal.
 *
 * Return value: the #ThunarJobResponse.
 **/
ThunarJobResponse
thunar_dialogs_show_job_ask (GtkWindow        *parent,
                             const gchar      *question,
                             ThunarJobResponse choices)
{
  const gchar *separator;
  const gchar *mnemonic;
  GtkWidget   *message;
  GtkWidget   *button;
  GString     *secondary = g_string_sized_new (256);
  GString     *primary = g_string_sized_new (256);
  gint         response;
  gint         n;
  gboolean     has_cancel = FALSE;

  _thunar_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), THUNAR_JOB_RESPONSE_CANCEL);
  _thunar_return_val_if_fail (g_utf8_validate (question, -1, NULL), THUNAR_JOB_RESPONSE_CANCEL);

  /* try to separate the question into primary and secondary parts */
  separator = strstr (question, ": ");
  if (G_LIKELY (separator != NULL))
    {
      /* primary is everything before the colon, plus a dot */
      g_string_append_len (primary, question, separator - question);
      g_string_append_c (primary, '.');

      /* secondary is everything after the colon (skipping whitespace) */
      do
        ++separator;
      while (g_ascii_isspace (*separator));
      g_string_append (secondary, separator);
    }
  else
    {
      /* otherwise separate based on the \n\n */
      separator = strstr (question, "\n\n");
      if (G_LIKELY (separator != NULL))
        {
          /* primary is everything before the newlines */
          g_string_append_len (primary, question, separator - question);

          /* secondary is everything after the newlines (skipping whitespace) */
          while (g_ascii_isspace (*separator))
            ++separator;
          g_string_append (secondary, separator);
        }
      else
        {
          /* everything is primary */
          g_string_append (primary, question);
        }
    }

  /* allocate the question message dialog */
  message = gtk_message_dialog_new (parent,
                                    GTK_DIALOG_MODAL |
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_QUESTION,
                                    GTK_BUTTONS_NONE,
                                    "%s", primary->str);
  if (G_LIKELY (*secondary->str != '\0'))
    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s", secondary->str);

  /* add the buttons based on the possible choices */
  for (n = 6; n >= 0; --n)
    {
      /* check if the response is set */
      response = choices & (1 << n);
      if (response == 0)
        continue;

      switch (response)
        {
        case THUNAR_JOB_RESPONSE_YES:
          mnemonic = _("_Yes");
          break;

        case THUNAR_JOB_RESPONSE_YES_ALL:
          mnemonic = _("Yes to _all");
          break;

        case THUNAR_JOB_RESPONSE_NO:
          mnemonic = _("_No");
          break;

        case THUNAR_JOB_RESPONSE_NO_ALL:
          mnemonic = _("N_o to all");
          break;

        case THUNAR_JOB_RESPONSE_RETRY:
          mnemonic = _("_Retry");
          break;

        case THUNAR_JOB_RESPONSE_FORCE:
          mnemonic = _("Copy _Anyway");
          break;

        case THUNAR_JOB_RESPONSE_CANCEL:
          /* cancel is always the last option */
          has_cancel = TRUE;
          continue;

        default:
          g_assert_not_reached ();
          break;
        }

      button = gtk_button_new_with_mnemonic (mnemonic);
      gtk_widget_set_can_default (button, TRUE);
      gtk_dialog_add_action_widget (GTK_DIALOG (message), button, response);
      gtk_widget_show (button);

      gtk_dialog_set_default_response (GTK_DIALOG (message), response);
    }

  if (has_cancel)
    {
      button = gtk_button_new_with_mnemonic (_("_Cancel"));
      gtk_widget_set_can_default (button, TRUE);
      gtk_dialog_add_action_widget (GTK_DIALOG (message), button, GTK_RESPONSE_CANCEL);
      gtk_widget_show (button);
      gtk_dialog_set_default_response (GTK_DIALOG (message), GTK_RESPONSE_CANCEL);
    }

  /* run the question dialog */
  response = gtk_dialog_run (GTK_DIALOG (message));
  gtk_widget_destroy (message);

  /* transform the result as required */
  if (G_UNLIKELY (response <= 0))
    response = THUNAR_JOB_RESPONSE_CANCEL;

  /* cleanup */
  g_string_free (secondary, TRUE);
  g_string_free (primary, TRUE);

  return response;
}
Example #19
0
static void edit_preset_response(GtkDialog *dialog, gint response_id, dt_gui_presets_edit_dialog_t *g)
{
  gint is_new = 0;

  if(response_id == GTK_RESPONSE_ACCEPT)
  {
    sqlite3_stmt *stmt;

    const gchar *name = gtk_entry_get_text(g->name);
    if(((g->old_id >= 0) && (strcmp(g->original_name, name) != 0)) || (g->old_id < 0))
    {

      if(strcmp(_("new preset"), name) == 0 || !(name && *name))
      {
        // show error dialog
        GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
        GtkWidget *dlg_changename
            = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING,
                                     GTK_BUTTONS_OK, _("please give preset a name"));

        gtk_window_set_title(GTK_WINDOW(dlg_changename), _("unnamed preset"));

        gtk_dialog_run(GTK_DIALOG(dlg_changename));
        gtk_widget_destroy(dlg_changename);
        return;
      }

      // editing existing preset with different name or store new preset -> check for a preset with the same
      // name:
      DT_DEBUG_SQLITE3_PREPARE_V2(
          dt_database_get(darktable.db),
          "select name from presets where name = ?1 and operation=?2 and op_version=?3", -1, &stmt, NULL);
      DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, name, -1, SQLITE_TRANSIENT);
      DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, g->module->op, -1, SQLITE_TRANSIENT);
      DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, g->module->version());

      if(sqlite3_step(stmt) == SQLITE_ROW)
      {
        sqlite3_finalize(stmt);

        // show overwrite question dialog
        GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
        GtkWidget *dlg_overwrite = gtk_message_dialog_new(
            GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO,
            _("preset `%s' already exists.\ndo you want to overwrite?"), name);

        gtk_window_set_title(GTK_WINDOW(dlg_overwrite), _("overwrite preset?"));

        gint dlg_ret = gtk_dialog_run(GTK_DIALOG(dlg_overwrite));
        gtk_widget_destroy(dlg_overwrite);

        // if result is BUTTON_NO exit without destroy dialog, to permit other name
        if(dlg_ret == GTK_RESPONSE_NO) return;
      }
      else
      {
        is_new = 1;
        sqlite3_finalize(stmt);
      }
    }

    if(g->old_id >= 0)
    {
      // now delete old preset:
      DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
                                  "delete from presets where name=?1 and operation=?2 and op_version=?3", -1,
                                  &stmt, NULL);
      DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, g->original_name, -1, SQLITE_TRANSIENT);
      DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, g->module->op, -1, SQLITE_TRANSIENT);
      DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, g->module->version());

      sqlite3_step(stmt);
      sqlite3_finalize(stmt);
    }

    if(is_new == 0)
    {
      // delete preset, so we can re-insert the new values:
      DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
                                  "delete from presets where name=?1 and operation=?2 and op_version=?3", -1,
                                  &stmt, NULL);
      DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, name, -1, SQLITE_TRANSIENT);
      DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, g->module->op, -1, SQLITE_TRANSIENT);
      DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, g->module->version());
      sqlite3_step(stmt);
      sqlite3_finalize(stmt);
    }

    // rename accelerators
    char path[1024];
    snprintf(path, sizeof(path), "%s/%s", _("preset"), g->original_name);
    dt_accel_rename_preset_iop(g->module, path, name);
    // commit all the user input fields
    DT_DEBUG_SQLITE3_PREPARE_V2(
        dt_database_get(darktable.db),
        "INSERT INTO presets (name, description, operation, op_version, op_params, enabled, "
        "blendop_params, blendop_version, multi_priority, multi_name, "
        "model, maker, lens, iso_min, iso_max, exposure_min, exposure_max, aperture_min, aperture_max, "
        "focal_length_min, focal_length_max, writeprotect, autoapply, filter, def, format) "
        "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, 0, '', ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, "
        "?19, 0, ?20, ?21, 0, ?22)",
        -1, &stmt, NULL);
    DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, name, -1, SQLITE_TRANSIENT);
    DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, gtk_entry_get_text(g->description), -1, SQLITE_TRANSIENT);
    DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 3, g->module->op, -1, SQLITE_TRANSIENT);
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 4, g->module->version());
    DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 5, g->module->params, g->module->params_size, SQLITE_TRANSIENT);
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 6, g->module->enabled);
    DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 7, g->module->blend_params, sizeof(dt_develop_blend_params_t),
                               SQLITE_TRANSIENT);
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 8, dt_develop_blend_version());
    DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 9, gtk_entry_get_text(GTK_ENTRY(g->model)), -1, SQLITE_TRANSIENT);
    DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 10, gtk_entry_get_text(GTK_ENTRY(g->maker)), -1, SQLITE_TRANSIENT);
    DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 11, gtk_entry_get_text(GTK_ENTRY(g->lens)), -1, SQLITE_TRANSIENT);
    DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 12, gtk_spin_button_get_value(GTK_SPIN_BUTTON(g->iso_min)));
    DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 13, gtk_spin_button_get_value(GTK_SPIN_BUTTON(g->iso_max)));
    DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 14,
                                 dt_gui_presets_exposure_value[dt_bauhaus_combobox_get(g->exposure_min)]);
    DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 15,
                                 dt_gui_presets_exposure_value[dt_bauhaus_combobox_get(g->exposure_max)]);
    DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 16,
                                 dt_gui_presets_aperture_value[dt_bauhaus_combobox_get(g->aperture_min)]);
    DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 17,
                                 dt_gui_presets_aperture_value[dt_bauhaus_combobox_get(g->aperture_max)]);
    DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 18, gtk_spin_button_get_value(GTK_SPIN_BUTTON(g->focal_length_min)));
    DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 19, gtk_spin_button_get_value(GTK_SPIN_BUTTON(g->focal_length_max)));
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 20, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->autoapply)));
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 21, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->filter)));
    int format = 0;
    for(int k = 0; k < 3; k++)
      format += gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->format_btn[k])) * dt_gui_presets_format_flag[k];
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 22, format);
    sqlite3_step(stmt);
    sqlite3_finalize(stmt);

    dt_gui_store_last_preset(name);
  }

  gtk_widget_destroy(GTK_WIDGET(dialog));
  g_free(g->original_name);
  free(g);
}
Example #20
0
gboolean
thunar_dialogs_show_insecure_program (gpointer     parent,
                                      const gchar *primary,
                                      ThunarFile  *file,
                                      const gchar *command)
{
  GdkScreen      *screen;
  GtkWindow      *window;
  gint            response;
  GtkWidget      *dialog;
  GString        *secondary;
  ThunarFileMode  old_mode;
  ThunarFileMode  new_mode;
  GFileInfo      *info;
  GError         *err = NULL;

  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
  _thunar_return_val_if_fail (g_utf8_validate (command, -1, NULL), FALSE);

  /* parse the parent window and screen */
  screen = thunar_util_parse_parent (parent, &window);

  /* secondary text */
  secondary = g_string_new (NULL);
  g_string_append_printf (secondary, _("The desktop file \"%s\" is in an insecure location "
                                       "and not marked as executable. If you do not trust "
                                       "this program, click Cancel."),
                                       thunar_file_get_display_name (file));
  g_string_append (secondary, "\n\n");
  if (exo_str_looks_like_an_uri (command))
    g_string_append_printf (secondary, G_KEY_FILE_DESKTOP_KEY_URL"=%s", command);
  else
    g_string_append_printf (secondary, G_KEY_FILE_DESKTOP_KEY_EXEC"=%s", command);

  /* allocate and display the error message dialog */
  dialog = gtk_message_dialog_new (window,
                                   GTK_DIALOG_MODAL |
                                   GTK_DIALOG_DESTROY_WITH_PARENT,
                                   GTK_MESSAGE_WARNING,
                                   GTK_BUTTONS_NONE,
                                   "%s", primary);
  gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Launch Anyway"), GTK_RESPONSE_OK);
  if (thunar_file_is_chmodable (file))
    gtk_dialog_add_button (GTK_DIALOG (dialog), _("Mark _Executable"), GTK_RESPONSE_APPLY);
  gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
  if (screen != NULL && window == NULL)
    gtk_window_set_screen (GTK_WINDOW (dialog), screen);
  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", secondary->str);
  g_string_free (secondary, TRUE);
  response = gtk_dialog_run (GTK_DIALOG (dialog));
  gtk_widget_destroy (dialog);

  /* check if we should make the file executable */
  if (response == GTK_RESPONSE_APPLY)
    {
      /* try to query information about the file */
      info = g_file_query_info (thunar_file_get_file (file),
                                G_FILE_ATTRIBUTE_UNIX_MODE,
                                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                NULL, &err);

      if (G_LIKELY (info != NULL))
        {
          if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE))
            {
              /* determine the current mode */
              old_mode = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);

              /* generate the new mode */
              new_mode = old_mode | THUNAR_FILE_MODE_USR_EXEC | THUNAR_FILE_MODE_GRP_EXEC | THUNAR_FILE_MODE_OTH_EXEC;

              if (old_mode != new_mode)
                {
                  g_file_set_attribute_uint32 (thunar_file_get_file (file),
                                               G_FILE_ATTRIBUTE_UNIX_MODE, new_mode,
                                               G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                               NULL, &err);
                }
            }
          else
            {
              g_warning ("No %s attribute found", G_FILE_ATTRIBUTE_UNIX_MODE);
            }

          g_object_unref (info);
        }

      if (err != NULL)
        {
          thunar_dialogs_show_error (parent, err, ("Unable to mark launcher executable"));
          g_error_free (err);
        }

      /* just launch */
      response = GTK_RESPONSE_OK;
    }

  return (response == GTK_RESPONSE_OK);
}
Example #21
0
void gtkw_dialog_warning(GtkWidget * parent, const ustring & warning)
{
  GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(parent), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "%s", warning.c_str());
  gtk_dialog_run(GTK_DIALOG(dialog));
  gtk_widget_destroy(dialog);
}
void on_button_saveToProgram_clicked(GtkWidget*widget, gpointer data)
{
  /* See if the looped checkmark is checked */
  bool playLooped = false;
  string* program;
  GtkWidget *w;
  w = GTK_WIDGET(gtk_builder_get_object(g_builder, "checkbutton_playLooped"));
  if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {
    playLooped = true;
  }  
  GtkWidget* combobox;
  combobox = GTK_WIDGET(gtk_builder_get_object(g_builder, "combobox_poseLanguage"));
  int languageindex = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox));
  char defaultFilename[128];
  switch(languageindex) {
    case 0: // C++/Ch
      program = g_robotManager->generateChProgram(playLooped, g_holdOnExit);
      strcpy(defaultFilename, "untitled.ch");
      break;
    case 1:
      program = g_robotManager->generateCppProgram(playLooped, g_holdOnExit);
      strcpy(defaultFilename, "untitled.cpp");
      break;
    case 2: // Python
      program = g_robotManager->generatePythonProgram(playLooped, g_holdOnExit);
      strcpy(defaultFilename, "untitled.py");
      break;
  }
  
  /* Open a save file dialog */
  GtkWidget *dialog;
  dialog = gtk_file_chooser_dialog_new ("Save File",
      GTK_WINDOW(g_window),
      GTK_FILE_CHOOSER_ACTION_SAVE,
      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
      NULL);
  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), defaultFilename);
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  {
    char *filename;
    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
    FILE *fp;
    fp = fopen(filename, "w");
    if(fp == NULL) {
      /* Could not open the file. Pop up an error message */
      GtkWidget* dialog;
      dialog = gtk_message_dialog_new (GTK_WINDOW(g_window),
          GTK_DIALOG_DESTROY_WITH_PARENT,
          GTK_MESSAGE_ERROR,
          GTK_BUTTONS_CLOSE,
          "Error saving to file '%s': %s",
          filename, g_strerror (errno));

      /* Destroy the dialog when the user responds to it (e.g. clicks a button) */
      g_signal_connect_swapped (dialog, "response",
          G_CALLBACK (gtk_widget_destroy),
          dialog);
      return;
    }
    fwrite(program->c_str(), program->size(), sizeof(char), fp);
    fclose(fp);
    g_free (filename);
  }
  gtk_widget_destroy (dialog);
  delete program;
}
Example #23
0
static void
do_simple_message_box(ESD_TYPE_E type, gboolean *notagain,
                      const char *secondary_msg, const char *msg_format,
                      va_list ap)
{
  GtkMessageType  gtk_message_type;
  gchar          *message;
  GtkWidget      *msg_dialog;
  GtkWidget      *checkbox = NULL;

  if (notagain != NULL) {
    if (*notagain) {
      /*
       * The user had checked the "Don't show this message again" checkbox
       * in the past; don't bother showing it.
       */
      return;
    }
  }

  switch (type) {

  case ESD_TYPE_INFO:
    gtk_message_type = GTK_MESSAGE_INFO;
    break;

  case ESD_TYPE_WARN:
    gtk_message_type = GTK_MESSAGE_WARNING;
    break;

  case ESD_TYPE_ERROR:
    gtk_message_type = GTK_MESSAGE_ERROR;
    break;

  default:
    g_assert_not_reached();
    gtk_message_type = GTK_MESSAGE_INFO;
    break;
  }

  /* Format the message. */
  message = g_strdup_vprintf(msg_format, ap);
  msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
                                      (GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
                                      gtk_message_type,
                                      GTK_BUTTONS_OK,
                                      "%s", message);
  g_free(message);
  if (secondary_msg != NULL)
    gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
                                             "%s", secondary_msg);

  if (notagain != NULL) {
    checkbox = gtk_check_button_new_with_label("Don't show this message again.");
    gtk_container_set_border_width(GTK_CONTAINER(checkbox), 12);
    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(msg_dialog))),
                       checkbox, TRUE, TRUE, 0);
    gtk_widget_show(checkbox);
  }

  gtk_dialog_run(GTK_DIALOG(msg_dialog));
  if (notagain != NULL) {
    /*
     * OK, did they check the checkbox?
     */
    *notagain = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox));
  }
  gtk_widget_destroy(msg_dialog);
}
Example #24
0
static gboolean
check_database_tables (GdaConnection *conn,
		       PlannerPlugin *plugin)
{
	GtkWindow    *window;
	GdaDataModel *model;
	GtkWidget    *dialog;
	gint          result;
	gboolean      success;
	GDir*         dir;
	const gchar  *name;
	gboolean      upgradable = FALSE;
	gboolean      create_tables;
	gboolean      can_create_tables = FALSE;
	gchar        *max_version_database;
	gchar        *max_version_upgrade;
	gchar        *upgrade_file = NULL;
	gchar        *database_file = NULL;
	gchar        *database_version = VERSION;
	const gchar  *database_name;
	gboolean      retval = FALSE;
	gchar        *sql_dir = mrp_paths_get_sql_dir ();

	max_version_database = g_strdup ("0.0");
	max_version_upgrade = g_strdup ("0.0");
	database_name = gda_connection_get_database (conn);

	window = GTK_WINDOW (plugin->main_window);

	/* Try to get the database version */
	model = sql_execute_query (conn, "SELECT value FROM property_global WHERE prop_name='database_version'");
	if (model == NULL) {
		create_tables = TRUE;
	} else {
		create_tables = FALSE;
		database_version = get_string (model, 0, 0);
		g_message ("Database version : %s", database_version);
		if (database_version == NULL) {
			database_version = VERSION;
		}
		g_object_unref (model);
	}

	/* Check for tables */
	dir = g_dir_open (sql_dir, 0, NULL);
	while ((name = g_dir_read_name (dir)) != NULL) {
		gchar **namev = NULL, **versionv = NULL;
		gchar  *version;
		gchar  *sql_file;

		if (!g_str_has_suffix (name, ".sql")) {
			continue;
		}

		sql_file = g_build_filename (sql_dir, name, NULL);

		/* Find version between "-" and ".sql" */
		namev = g_strsplit (sql_file,"-",-1);
		/* Upgrade: 2 versions in file */
		if (namev[1] && namev[2]) {
			versionv = g_strsplit (namev[2],".sql",-1);
			if (is_newer_version (versionv[0], namev[1])) {
				if (!strcmp (namev[1], database_version)) {
					upgradable = TRUE;
					if (is_newer_version (versionv[0],
							      max_version_upgrade)) {
						if (upgrade_file) {
							g_free (upgrade_file);
						}
						upgrade_file = g_strdup (sql_file);
						g_free (max_version_upgrade);
						max_version_upgrade = g_strdup (versionv[0]);
					}
				}
			} else {
				g_warning ("Incorrect upgrade file name: %s", sql_file);
			}
		}
		/* Create tables */
		else if (namev[1]) {
			versionv = g_strsplit (namev[1],".sql",-1);
			if (is_newer_version (versionv[0], max_version_database)) {
				if (database_file) {
					g_free (database_file);
				}
				database_file = g_strdup (sql_file);
				g_free (max_version_database);
				max_version_database = g_strdup (versionv[0]);
			}

			can_create_tables = TRUE;
			version = g_strdup (versionv[0]);
			g_free (version);

		} else {
			if (!database_file) {
				database_file = g_strdup (sql_file);
			}
			g_message ("File with no version: %s", sql_file);
			can_create_tables = TRUE;
		}
		if (versionv) {
			g_strfreev (versionv);
		}
		if (namev) {
			g_strfreev (namev);
		}
		g_free (sql_file);
	}

	/* With each database change we need the new complete database description
	   and the upgrades files from different versions */
	if ((is_newer_version (max_version_upgrade, max_version_database) ||
	    is_newer_version (max_version_database, max_version_upgrade))
	    && upgradable) {
		g_warning ("Database file version %s (%s) is different from upgrade file version %s (%s)",
			   max_version_database,
			   database_file,
			   max_version_upgrade,
			   upgrade_file);
		retval = FALSE;
		upgradable = FALSE;
		can_create_tables = FALSE;
	}

	if (!upgradable && !create_tables) {
		retval = TRUE;
	}
	else if (upgradable && !create_tables) {
		gchar *contents;

		dialog = gtk_message_dialog_new (window,
						 GTK_DIALOG_DESTROY_WITH_PARENT,
						 GTK_MESSAGE_QUESTION,
						 GTK_BUTTONS_NONE,
						 _("Database %s needs to be upgraded "
						   "from version %s to version %s.\n"
						   "Please backup database before the upgrade."),
						 database_name, database_version,
						 max_version_upgrade);
		gtk_dialog_add_buttons ((GtkDialog *) dialog,
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					_("Upgrade"), GTK_RESPONSE_YES,
					NULL);

		result = gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);
		if (result == GTK_RESPONSE_YES) {
			g_file_get_contents (upgrade_file, &contents, NULL, NULL);
			success = sql_execute_command (conn, contents);
			g_free (contents);
			if (!success) {
				dialog = gtk_message_dialog_new (window,
								 GTK_DIALOG_DESTROY_WITH_PARENT,
								 GTK_MESSAGE_WARNING,
								 GTK_BUTTONS_CLOSE,
								 _("Could not upgrade database %s.\n Upgrade file used: %s."
								   "\n\nDatabase error: \n%s"),
								 database_name, upgrade_file,
								 sql_get_last_error (conn));

				gtk_dialog_run (GTK_DIALOG (dialog));
				gtk_widget_destroy (dialog);
				retval = FALSE;
			} else {
				gchar *query;

				sql_execute_command (conn, "DELETE * FROM property_global WHERE prop_name='database_version'");
				query = g_strdup_printf ("INSERT INTO property_global (prop_name, value) VALUES ('database_version','%s')", max_version_upgrade);

				sql_execute_command (conn, query);
				g_free (query);
				retval = TRUE;
			}
		} else {
			retval = FALSE;
		}
		g_free (upgrade_file);
	}

	else if (create_tables && !can_create_tables) {
		g_warning ("Need to create tables but no database file");
		retval = FALSE;
	}

	else if (create_tables && can_create_tables) {
		gchar  *contents;

		g_file_get_contents (database_file, &contents, NULL, NULL);
		success = sql_execute_command (conn, contents);
		g_free (contents);
		if (!success) {
			dialog = gtk_message_dialog_new (window,
							 GTK_DIALOG_DESTROY_WITH_PARENT,
							 GTK_MESSAGE_WARNING,
							 GTK_BUTTONS_CLOSE,
							 _("Can't create tables in database %s"),
							 database_name);

			result = gtk_dialog_run (GTK_DIALOG (dialog));
			gtk_widget_destroy (dialog);
			retval = FALSE;
		} else {
			gchar *query;

			query = g_strdup_printf ("INSERT INTO property_global (prop_name, value) VALUES ('database_version','%s')", max_version_database);

			sql_execute_command (conn, query);
			g_free (query);
			retval = TRUE;
		}
		g_free (database_file);
	}

	g_free (max_version_upgrade);
	g_free (max_version_database);
	return retval;
}
Example #25
0
void MessageBox(GtkMessageType type, const char *msg)
{
    GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, type, GTK_BUTTONS_OK, msg);
    gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
}
Example #26
0
/* Try to create the database */
static gboolean
create_database (const gchar   *dsn_name,
		 const gchar   *host,
		 const gchar   *db_name,
		 PlannerPlugin *plugin)
{
	GtkWidget         *dialog;
	GtkWindow         *window;
	guint              result;
	gboolean           retval;
	GdaConnection     *conn;
	GdaClient         *client;
	GdaDataSourceInfo *dsn;
	gchar             *cnc_string_orig;
	/* FIXME: In postgresql we use template1 as the connection database */
	gchar             *init_database = "template1";
	gchar             *query;
	GError            *error;

	dsn = gda_config_find_data_source (dsn_name);
	cnc_string_orig = dsn->cnc_string;
	retval = FALSE;

	window = GTK_WINDOW (plugin->main_window);

	/* Use same data but changing the database */
	dsn->cnc_string = g_strdup_printf (CONNECTION_FORMAT_STRING, host, init_database);
	gda_config_save_data_source_info (dsn);

	client = gda_client_new ();
	conn = gda_client_open_connection (client, dsn_name, NULL, NULL, 0, &error);
	if (conn == NULL) {
		g_warning ("Can't connect to database server in order to check/create the database: %s", cnc_string_orig);
	} else {
		dialog = gtk_message_dialog_new (window,
						 GTK_DIALOG_DESTROY_WITH_PARENT,
						 GTK_MESSAGE_QUESTION,
						 GTK_BUTTONS_YES_NO,
						 _("Database %s is not setup for Planner. "
						   "Do you want to do that?"),
						 db_name);

		result = gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);

		if (result == GTK_RESPONSE_YES) {
			query = g_strdup_printf ("CREATE DATABASE %s WITH ENCODING = 'UTF8'",
						 db_name);
			sql_execute_command (conn, query);
			g_free (query);
			retval = TRUE;
		} else {
			retval = FALSE;
		}
		gda_connection_close (conn);
		g_object_unref (client);
	}
	g_free (dsn->cnc_string);
	dsn->cnc_string = cnc_string_orig;
	gda_config_save_data_source_info (dsn);

	return retval;
}
Example #27
0
static gboolean
gui_message_error_dialog (Gimp                *gimp,
                          GObject             *handler,
                          GimpMessageSeverity  severity,
                          const gchar         *domain,
                          const gchar         *message)
{
  GtkWidget *dialog;

  if (GIMP_IS_PROGRESS (handler))
    {
      /* If there's already an error dialog associated with this
       * progress, then continue without trying gimp_progress_message().
       */
      if (! g_object_get_data (handler, "gimp-error-dialog") &&
          gimp_progress_message (GIMP_PROGRESS (handler), gimp,
                                 severity, domain, message))
        {
          return TRUE;
        }
    }
  else if (GTK_IS_WIDGET (handler))
    {
      GtkWidget      *parent = GTK_WIDGET (handler);
      GtkMessageType  type   = GTK_MESSAGE_ERROR;

      switch (severity)
        {
        case GIMP_MESSAGE_INFO:    type = GTK_MESSAGE_INFO;    break;
        case GIMP_MESSAGE_WARNING: type = GTK_MESSAGE_WARNING; break;
        case GIMP_MESSAGE_ERROR:   type = GTK_MESSAGE_ERROR;   break;
        }

      dialog =
        gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (parent)),
                                GTK_DIALOG_DESTROY_WITH_PARENT,
                                type, GTK_BUTTONS_OK,
                                "%s", message);

      g_signal_connect (dialog, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL);

      gtk_widget_show (dialog);

      return TRUE;
    }

  if (GIMP_IS_PROGRESS (handler) && ! GIMP_IS_PROGRESS_DIALOG (handler))
    dialog = progress_error_dialog (GIMP_PROGRESS (handler));
  else
    dialog = global_error_dialog ();

  if (dialog)
    {
      gimp_error_dialog_add (GIMP_ERROR_DIALOG (dialog),
                             gimp_get_message_stock_id (severity),
                             domain, message);
      gtk_window_present (GTK_WINDOW (dialog));

      return TRUE;
    }

  return FALSE;
}
Example #28
0
void
on_trkproperties_add_new_field_activate
                                        (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{
    GtkTreeView *treeview = GTK_TREE_VIEW (lookup_widget (trackproperties, "metalist"));
    if (!gtk_widget_is_focus(GTK_WIDGET (treeview))) {
        return; // do not add field if Metadata tab is not focused
    }
    GtkWidget *dlg = create_entrydialog ();
    gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (trackproperties));
    gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_OK);
    gtk_window_set_title (GTK_WINDOW (dlg), _("Field name"));
    GtkWidget *e;
    e = lookup_widget (dlg, "title_label");
    gtk_label_set_text (GTK_LABEL(e), _("Name:"));
    for (;;) {
        int res = gtk_dialog_run (GTK_DIALOG (dlg));
        if (res == GTK_RESPONSE_OK) {
            e = lookup_widget (dlg, "title");

            const char *text = gtk_entry_get_text (GTK_ENTRY(e));

            GtkTreeIter iter;

            // check for _ and :
            if (text[0] == '_' || text[0] == ':' || text[0] == '!') {
                GtkWidget *d = gtk_message_dialog_new (GTK_WINDOW (dlg), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Field names must not start with : or _"));
                gtk_window_set_title (GTK_WINDOW (d), _("Cannot add field"));

                gtk_dialog_run (GTK_DIALOG (d));
                gtk_widget_destroy (d);
                continue;
            }

            // check if a field with the same name already exists
            int dup = 0;
            gboolean res = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
            while (res) {
                GValue value = {0,};
                gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter, 2, &value);
                const char *svalue = g_value_get_string (&value);
                if (!strcasecmp (svalue, text)) {
                    dup = 1;
                    break;
                }
                res = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
            }

            if (!dup) {
                int l = strlen (text);
                char title[l+3];
                snprintf (title, sizeof (title), "<%s>", text);
                const char *value = "";
                const char *key = text;

                gtk_list_store_append (store, &iter);
                gtk_list_store_set (store, &iter, 0, title, 1, value, 2, key, -1);
                GtkTreePath *path;
                gint rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
                path = gtk_tree_path_new_from_indices (rows - 1, -1);
                gtk_tree_view_set_cursor (treeview, path, NULL, TRUE); // set cursor onto new field
                gtk_tree_path_free(path);
                trkproperties_modified = 1;
            }
            else {
                GtkWidget *d = gtk_message_dialog_new (GTK_WINDOW (dlg), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Field with such name already exists, please try different name."));
                gtk_window_set_title (GTK_WINDOW (d), _("Cannot add field"));

                gtk_dialog_run (GTK_DIALOG (d));
                gtk_widget_destroy (d);
                continue;
            }
        }
        break;
    }
    gtk_widget_destroy (dlg);
    gtk_window_present (GTK_WINDOW (trackproperties));
}
Example #29
0
static void
add_response (GtkWidget *window,
	      int        id,
	      MCData    *mc)
{
    MCPrefsDialog *dialog;

    dialog = &mc->prefs_dialog;

    switch (id) {
    case GTK_RESPONSE_OK: {
	const char  *pattern;
	const char  *command;
	GtkTreeIter  iter;
	const char  *error_message = NULL;

	pattern = gtk_entry_get_text (GTK_ENTRY (dialog->pattern_entry));
	command = gtk_entry_get_text (GTK_ENTRY (dialog->command_entry));

	if (!pattern || !pattern [0])
		error_message = _("You must specify a pattern");

	if (!command || !command [0]) 
		error_message = error_message != NULL ?
					_("You must specify a pattern and a command") :
					_("You must specify a command");

	if (!error_message && duplicate_pattern (mc, pattern))
		error_message = _("You may not specify duplicate patterns");

	if (error_message) {
	    GtkWidget *error_dialog;

	    error_dialog = gtk_message_dialog_new (GTK_WINDOW (window),
					           GTK_DIALOG_DESTROY_WITH_PARENT,
					           GTK_MESSAGE_ERROR,
					           GTK_BUTTONS_OK,
					           error_message);

	    g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
	    gtk_window_set_resizable (GTK_WINDOW (error_dialog), FALSE);
	    gtk_widget_show_all (error_dialog);
	    return;
	}

	gtk_widget_hide (window);

	gtk_list_store_append (dialog->macros_store, &iter);
	gtk_list_store_set (dialog->macros_store, &iter,
			    COLUMN_PATTERN, pattern, 
			    COLUMN_COMMAND, command,
			    -1);

	gtk_tree_view_columns_autosize (GTK_TREE_VIEW (dialog->macros_tree));

	gtk_editable_delete_text (GTK_EDITABLE (dialog->pattern_entry), 0, -1);
	gtk_editable_delete_text (GTK_EDITABLE (dialog->command_entry), 0, -1);

	save_macros_to_gconf (mc);
    }
	break;
    case GTK_RESPONSE_HELP:
    	show_help_section (GTK_WINDOW (window), "command-line-prefs-2");
	break;
    case GTK_RESPONSE_CLOSE:
    default:
	gtk_editable_delete_text (GTK_EDITABLE (dialog->pattern_entry), 0, -1);
	gtk_editable_delete_text (GTK_EDITABLE (dialog->command_entry), 0, -1);
	gtk_widget_hide (window);
	break;
    }
}
Example #30
0
void insert_image(GdkEvent *event)
{
  GtkTextBuffer *buffer;
  GnomeCanvasItem *canvas_item;
  GdkColor color;
  GtkWidget *dialog;
  GtkFileFilter *filt_all;
  GtkFileFilter *filt_gdkimage;
  char *filename;
  GdkPixbuf *pixbuf;
  double scale=1;
  double pt[2];
  
  dialog = gtk_file_chooser_dialog_new(_("Insert Image"), GTK_WINDOW (winMain),
     GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
     GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
#ifdef FILE_DIALOG_SIZE_BUGFIX
  gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400);
#endif
     
  filt_all = gtk_file_filter_new();
  gtk_file_filter_set_name(filt_all, _("All files"));
  gtk_file_filter_add_pattern(filt_all, "*");
  filt_gdkimage = gtk_file_filter_new();
  gtk_file_filter_set_name(filt_gdkimage, _("Image files"));
  gtk_file_filter_add_pixbuf_formats(filt_gdkimage);
  gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_gdkimage);
  gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);

  if (ui.default_image != NULL) gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), ui.default_image);

  if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
    gtk_widget_destroy(dialog);
    return;
  }
  filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog));
  gtk_widget_destroy(dialog);

  if (filename == NULL) return; /* nothing selected */

  if (ui.default_image != NULL) g_free(ui.default_image);
  ui.default_image = g_strdup(filename);
  
  set_cursor_busy(TRUE);
  pixbuf=gdk_pixbuf_new_from_file(filename, NULL);
  set_cursor_busy(FALSE);
  
  if(pixbuf==NULL) { /* open failed */
    dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_MODAL,
      GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error opening image '%s'"), filename);
    gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
    g_free(filename);
    ui.cur_item = NULL;
    ui.cur_item_type = ITEM_NONE;
    return;
  }

  ui.cur_item_type = ITEM_IMAGE;

  get_pointer_coords(event, pt);
  set_current_page(pt);  

  create_image_from_pixbuf(pixbuf, pt);
}