Commit 9d1cb044 authored by Robert Ancell's avatar Robert Ancell

WIP: printers: use gtk_dialog_run

parent 013d36d4
Pipeline #42216 failed with stages
in 1 minute and 3 seconds
......@@ -56,9 +56,6 @@ struct _PpDetailsDialog {
PPDList *all_ppds_list;
GCancellable *get_all_ppds_cancellable;
GCancellable *get_ppd_names_cancellable;
/* Dialogs */
PpPPDSelectionDialog *pp_ppd_selection_dialog;
};
struct _PpDetailsDialogClass
......@@ -218,34 +215,27 @@ ppd_selection_dialog_response_cb (GtkDialog *dialog,
gpointer user_data)
{
PpDetailsDialog *self = (PpDetailsDialog*) user_data;
gchar *ppd_name;
if (response_id == GTK_RESPONSE_OK)
{
gchar *ppd_name;
ppd_name = pp_ppd_selection_dialog_get_ppd_name (self->pp_ppd_selection_dialog);
ppd_name = pp_ppd_selection_dialog_get_ppd_name (self->pp_ppd_selection_dialog);
if (self->printer_name && ppd_name)
{
GCancellable *cancellable;
if (self->printer_name && ppd_name)
{
GCancellable *cancellable;
cancellable = g_cancellable_new ();
cancellable = g_cancellable_new ();
printer_set_ppd_async (self->printer_name,
ppd_name,
cancellable,
set_ppd_cb,
self);
printer_set_ppd_async (self->printer_name,
ppd_name,
cancellable,
set_ppd_cb,
self);
g_clear_pointer (&self->ppd_file_name, g_free);
self->ppd_file_name = g_strdup (ppd_name);
}
g_free (ppd_name);
g_clear_pointer (&self->ppd_file_name, g_free);
self->ppd_file_name = g_strdup (ppd_name);
}
gtk_widget_destroy (GTK_WIDGET (self->pp_ppd_selection_dialog));
self->pp_ppd_selection_dialog = NULL;
g_free (ppd_name);
}
static void
......@@ -307,13 +297,18 @@ select_ppd_in_dialog (GtkButton *button,
self->pp_ppd_selection_dialog = pp_ppd_selection_dialog_new (
self->all_ppds_list,
manufacturer,
ppd_selection_dialog_response_cb,
self);
manufacturer);
gtk_window_set_transient_for (GTK_WINDOW (self->pp_ppd_selection_dialog),
GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));
if (gtk_dialog_run (GTK_DIALOG (self->pp_ppd_selection_dialog)) == GTK_RESPONSE_OK)
{
// ...
}
gtk_widget_destroy (GTK_WIDGET (self->pp_ppd_selection_dialog));
g_free (manufacturer);
g_free (device_id);
}
......
......@@ -113,8 +113,6 @@ struct _PpNewPrinterDialogPrivate
GtkCellRenderer *text_renderer;
GtkCellRenderer *icon_renderer;
PpPPDSelectionDialog *ppd_selection_dialog;
PpPrintDevice *new_device;
PPDList *list;
......@@ -217,9 +215,6 @@ pp_new_printer_dialog_set_ppd_list (PpNewPrinterDialog *dialog,
PpNewPrinterDialogPrivate *priv = dialog->priv;
priv->list = ppd_list_copy (list);
if (priv->ppd_selection_dialog)
pp_ppd_selection_dialog_set_ppd_list (priv->ppd_selection_dialog, priv->list);
}
static void
......@@ -2157,8 +2152,6 @@ ppd_selection_cb (GtkDialog *_dialog,
ppd_name = pp_ppd_selection_dialog_get_ppd_name (priv->ppd_selection_dialog);
ppd_display_name = pp_ppd_selection_dialog_get_ppd_display_name (priv->ppd_selection_dialog);
gtk_widget_destroy (GTK_WIDGET (priv->ppd_selection_dialog));
priv->ppd_selection_dialog = NULL;
if (ppd_name)
{
......@@ -2243,10 +2236,6 @@ new_printer_dialog_response_cb (GtkDialog *_dialog,
GtkTreeIter iter;
gint acquisition_method;
gtk_widget_hide (GTK_WIDGET (_dialog));
if (response_id == GTK_RESPONSE_OK)
{
g_cancellable_cancel (priv->cancellable);
g_clear_object (&priv->cancellable);
......@@ -2268,13 +2257,18 @@ new_printer_dialog_response_cb (GtkDialog *_dialog,
acquisition_method == ACQUISITION_METHOD_JETDIRECT ||
acquisition_method == ACQUISITION_METHOD_LPD)
{
PpPPDSelectionDialog *dialog;
priv->new_device = pp_print_device_copy (device);
priv->ppd_selection_dialog =
pp_ppd_selection_dialog_new (priv->list,
NULL,
ppd_selection_cb,
dialog);
gtk_window_set_transient_for (GTK_WINDOW (priv->ppd_selection_dialog), priv->parent);
dialog = pp_ppd_selection_dialog_new (priv->list, NULL);
gtk_window_set_transient_for (GTK_WINDOW (dialog), priv->parent);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
{
// ...
}
gtk_widget_destroy (GTK_WIDGET (dialog));
}
else
{
......@@ -2313,9 +2307,4 @@ new_printer_dialog_response_cb (GtkDialog *_dialog,
g_object_unref (device);
}
}
else
{
emit_response (dialog, GTK_RESPONSE_CANCEL);
}
}
......@@ -59,12 +59,6 @@ struct _PpPPDSelectionDialog {
GtkButton *select_button;
GtkSpinner *spinner;
UserResponseCallback user_callback;
gpointer user_data;
gchar *ppd_name;
gchar *ppd_display_name;
GtkResponseType response;
gchar *manufacturer;
PPDList *list;
......@@ -232,40 +226,11 @@ populate_dialog (PpPPDSelectionDialog *self)
}
}
static void
ppd_selection_dialog_response_cb (PpPPDSelectionDialog *self,
gint response_id,
gpointer user_data)
{
GtkTreeModel *model;
GtkTreeIter iter;
gtk_widget_hide (GTK_WIDGET (self));
self->response = response_id;
if (response_id == GTK_RESPONSE_OK)
{
if (gtk_tree_selection_get_selected (self->models_selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
PPD_NAMES_COLUMN, &self->ppd_name,
PPD_DISPLAY_NAMES_COLUMN, &self->ppd_display_name,
-1);
}
}
self->user_callback (GTK_DIALOG (self),
response_id,
self->user_data);
}
static void
pp_ppd_selection_dialog_dispose (GObject *object)
{
PpPPDSelectionDialog *self = PP_PPD_SELECTION_DIALOG (object);
g_clear_pointer (&self->ppd_name, g_free);
g_clear_pointer (&self->ppd_display_name, g_free);
g_clear_pointer (&self->manufacturer, g_free);
G_OBJECT_CLASS (pp_ppd_selection_dialog_parent_class)->dispose (object);
......@@ -300,10 +265,8 @@ pp_ppd_selection_dialog_init (PpPPDSelectionDialog *self)
}
PpPPDSelectionDialog *
pp_ppd_selection_dialog_new (PPDList *ppd_list,
const gchar *manufacturer,
UserResponseCallback user_callback,
gpointer user_data)
pp_ppd_selection_dialog_new (PPDList *ppd_list,
const gchar *manufacturer)
{
PpPPDSelectionDialog *self;
......@@ -311,18 +274,10 @@ pp_ppd_selection_dialog_new (PPDList *ppd_list,
"use-header-bar", 1,
NULL);
self->user_callback = user_callback;
self->user_data = user_data;
self->response = GTK_RESPONSE_NONE;
self->list = ppd_list_copy (ppd_list);
self->manufacturer = get_standard_manufacturers_name (manufacturer);
/* connect signals */
g_signal_connect (self, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
g_signal_connect (self, "response", G_CALLBACK (ppd_selection_dialog_response_cb), NULL);
gtk_spinner_start (self->spinner);
populate_dialog (self);
......@@ -336,13 +291,35 @@ pp_ppd_selection_dialog_new (PPDList *ppd_list,
gchar *
pp_ppd_selection_dialog_get_ppd_name (PpPPDSelectionDialog *self)
{
return g_strdup (self->ppd_name);
GtkTreeModel *model;
GtkTreeIter iter;
gchar *ppd_name = NULL;
if (gtk_tree_selection_get_selected (self->models_selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
PPD_NAMES_COLUMN, &ppd_name,
-1);
}
return ppd_name;
}
gchar *
pp_ppd_selection_dialog_get_ppd_display_name (PpPPDSelectionDialog *self)
{
return g_strdup (self->ppd_display_name);
GtkTreeModel *model;
GtkTreeIter iter;
gchar *ppd_display_name = NULL;
if (gtk_tree_selection_get_selected (self->models_selection, &model, &iter))
{
gtk_tree_model_get (model, &iter,
PPD_DISPLAY_NAMES_COLUMN, &ppd_display_name,
-1);
}
return ppd_display_name;
}
void
......
......@@ -28,11 +28,9 @@ G_BEGIN_DECLS
#define PP_TYPE_ppd_selection_dialog (pp_ppd_selection_dialog_get_type ())
G_DECLARE_FINAL_TYPE (PpPPDSelectionDialog, pp_ppd_selection_dialog, PP, PPD_SELECTION_DIALOG, GtkDialog)
PpPPDSelectionDialog *pp_ppd_selection_dialog_new (PPDList *ppd_list,
const gchar *manufacturer,
UserResponseCallback user_callback,
gpointer user_data);
gchar *pp_ppd_selection_dialog_get_ppd_name (PpPPDSelectionDialog *dialog);
gchar *pp_ppd_selection_dialog_get_ppd_display_name (PpPPDSelectionDialog *dialog);
void pp_ppd_selection_dialog_set_ppd_list (PpPPDSelectionDialog *dialog,
PPDList *list);
PpPPDSelectionDialog *pp_ppd_selection_dialog_new (PPDList *ppd_list,
const gchar *manufacturer);
gchar *pp_ppd_selection_dialog_get_ppd_name (PpPPDSelectionDialog *dialog);
gchar *pp_ppd_selection_dialog_get_ppd_display_name (PpPPDSelectionDialog *dialog);
void pp_ppd_selection_dialog_set_ppd_list (PpPPDSelectionDialog *dialog,
PPDList *list);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment