示例#1
0
static GtkFileChooserDefault *
get_impl_from_dialog (GtkWidget *dialog)
{
  GtkFileChooserDialog *d;
  GtkFileChooserDialogPrivate *dialog_priv;
  GtkFileChooserWidget *chooser_widget;
  GtkFileChooserWidgetPrivate *widget_priv;
  GtkFileChooserDefault *impl;

  d = GTK_FILE_CHOOSER_DIALOG (dialog);
  dialog_priv = d->priv;
  chooser_widget = GTK_FILE_CHOOSER_WIDGET (dialog_priv->widget);
  if (!chooser_widget)
    g_error ("BUG: dialog_priv->widget is not a GtkFileChooserWidget");

  widget_priv = chooser_widget->priv;
  impl = (GtkFileChooserDefault *) (widget_priv->impl);
  if (!impl)
    g_error ("BUG: widget_priv->impl is not a GtkFileChooserDefault");

  return impl;
}
示例#2
0
文件: gtk_glue.c 项目: Emerentius/gtk
GtkFileChooserWidget* cast_GtkFileChooserWidget(GtkWidget* widget) {
    return GTK_FILE_CHOOSER_WIDGET(widget);
}
示例#3
0
static void
gnc_ui_file_access( int type )
{
    FileAccessWindow *faw;
    GladeXML* xml;
    GtkWidget* box;
    GList* ds_node;
    GtkButton* op;
    GtkWidget* align;
    GtkFileChooserWidget* fileChooser;
    GtkFileChooserAction fileChooserAction = GTK_FILE_CHOOSER_ACTION_OPEN;
    GList* list;
    GList* node;
    GtkWidget* uri_type_container;
    gboolean need_access_method_file = FALSE;
    gboolean need_access_method_mysql = FALSE;
    gboolean need_access_method_postgres = FALSE;
    gboolean need_access_method_sqlite3 = FALSE;
    gboolean need_access_method_xml = FALSE;
    gint access_method_index = -1;
    gint active_access_method_index = -1;
    const gchar* default_db;
    const gchar *button_label = NULL;

    g_return_if_fail( type == FILE_ACCESS_OPEN || type == FILE_ACCESS_SAVE_AS );

    faw = g_new0(FileAccessWindow, 1);
    g_return_if_fail( faw != NULL );

    faw->type = type;

    /* Open the dialog */
    xml = gnc_glade_xml_new( "dialog-file-access.glade", "File Access" );
    faw->dialog = glade_xml_get_widget( xml, "File Access" );
    g_object_set_data_full( G_OBJECT(faw->dialog), "FileAccessWindow", faw,
                            g_free );

    faw->frame_file = glade_xml_get_widget( xml, "frame_file" );
    faw->frame_database = glade_xml_get_widget( xml, "frame_database" );
    faw->tf_host = GTK_ENTRY(glade_xml_get_widget( xml, "tf_host" ));
    gtk_entry_set_text( faw->tf_host, DEFAULT_HOST );
    faw->tf_database = GTK_ENTRY(glade_xml_get_widget( xml, "tf_database" ));
    default_db = get_default_database();
    gtk_entry_set_text( faw->tf_database, default_db );
    faw->tf_username = GTK_ENTRY(glade_xml_get_widget( xml, "tf_username" ));
    faw->tf_password = GTK_ENTRY(glade_xml_get_widget( xml, "tf_password" ));

    switch ( type )
    {
    case FILE_ACCESS_OPEN:
        gtk_window_set_title(GTK_WINDOW(faw->dialog), _("Open..."));
        button_label = "gtk-open";
        fileChooserAction = GTK_FILE_CHOOSER_ACTION_OPEN;
        break;

    case FILE_ACCESS_SAVE_AS:
        gtk_window_set_title(GTK_WINDOW(faw->dialog), _("Save As..."));
        button_label = "gtk-save-as";
        fileChooserAction = GTK_FILE_CHOOSER_ACTION_SAVE;
        break;
    }

    op = GTK_BUTTON(glade_xml_get_widget( xml, "pb_op" ));
    if ( op != NULL )
    {
        gtk_button_set_label( op, button_label );
        gtk_button_set_use_stock( op, TRUE );
    }

    align = glade_xml_get_widget( xml, "alignment_file_chooser" );
    fileChooser = GTK_FILE_CHOOSER_WIDGET(gtk_file_chooser_widget_new( fileChooserAction ));
    faw->fileChooser = GTK_FILE_CHOOSER(fileChooser);
    gtk_container_add( GTK_CONTAINER(align), GTK_WIDGET(fileChooser) );
    g_object_connect( G_OBJECT(faw->fileChooser), "signal::file-activated",
                      gnc_ui_file_access_file_activated_cb, faw, NULL );

    uri_type_container = glade_xml_get_widget( xml, "vb_uri_type_container" );
    faw->cb_uri_type = GTK_COMBO_BOX(gtk_combo_box_new_text());
    gtk_container_add( GTK_CONTAINER(uri_type_container), GTK_WIDGET(faw->cb_uri_type) );
    gtk_box_set_child_packing( GTK_BOX(uri_type_container), GTK_WIDGET(faw->cb_uri_type),
                               /*expand*/TRUE, /*fill*/FALSE, /*padding*/0, GTK_PACK_START );
    g_object_connect( G_OBJECT(faw->cb_uri_type),
                      "signal::changed", cb_uri_type_changed_cb, NULL,
                      NULL );

    /* Autoconnect signals */
    glade_xml_signal_autoconnect_full( xml, gnc_glade_autoconnect_full_func,
                                       faw->dialog );

    /* See what qof backends are available and add appropriate ones to the combo box */
    list = qof_backend_get_registered_access_method_list();
    for ( node = list; node != NULL; node = node->next )
    {
        const gchar* access_method = node->data;

        /* For the different access methods, "mysql" and "postgres" are added if available.  Access
        methods "xml" and "sqlite3" are compressed to "file" if opening a file, but when saving a file,
        both access methods are added. */
        if ( strcmp( access_method, "mysql" ) == 0 )
        {
            need_access_method_mysql = TRUE;
        }
        else if ( strcmp( access_method, "postgres" ) == 0 )
        {
            need_access_method_postgres = TRUE;
        }
        else if ( strcmp( access_method, "xml" ) == 0 )
        {
            if ( type == FILE_ACCESS_OPEN )
            {
                need_access_method_file = TRUE;
            }
            else
            {
                need_access_method_xml = TRUE;
            }
        }
        else if ( strcmp( access_method, "sqlite3" ) == 0 )
        {
            if ( type == FILE_ACCESS_OPEN )
            {
                need_access_method_file = TRUE;
            }
            else
            {
                need_access_method_sqlite3 = TRUE;
            }
        }
    }
    g_list_free(list);

    /* Now that the set of access methods has been ascertained, add them to the list, and set the
    default. */
    access_method_index = -1;
    if ( need_access_method_file )
    {
        gtk_combo_box_append_text( faw->cb_uri_type, "file" );
        active_access_method_index = ++access_method_index;
    }
    if ( need_access_method_mysql )
    {
        gtk_combo_box_append_text( faw->cb_uri_type, "mysql" );
        ++access_method_index;
    }
    if ( need_access_method_postgres )
    {
        gtk_combo_box_append_text( faw->cb_uri_type, "postgres" );
        ++access_method_index;
    }
    if ( need_access_method_sqlite3 )
    {
        gtk_combo_box_append_text( faw->cb_uri_type, "sqlite3" );
        active_access_method_index = ++access_method_index;
    }
    if ( need_access_method_xml )
    {
        gtk_combo_box_append_text( faw->cb_uri_type, "xml" );
        ++access_method_index;

        // Set XML as default if it is offered (which mean we are in
        // the "Save As" dialog)
        active_access_method_index = access_method_index;
    }
    g_assert( active_access_method_index >= 0 );

    /* Clean up the xml data structure when the dialog is destroyed */
    g_object_set_data_full( G_OBJECT(faw->dialog), "dialog-file-access.glade",
                            xml, g_object_unref );

    /* Run the dialog */
    gtk_widget_show_all( faw->dialog );

    /* Hide the frame that's not required for the active access method so either only
     * the File or only the Database frame are presented. */
    gtk_combo_box_set_active( faw->cb_uri_type, active_access_method_index );
    set_widget_sensitivity_for_uri_type( faw, gtk_combo_box_get_active_text( faw->cb_uri_type ) );
}