Commit 04d6e363 authored by Marek Kašík's avatar Marek Kašík

printers: Remove printer add/remove buttons

Add setting of default printer.
parent 03415e76
......@@ -61,6 +61,7 @@ static void actualize_jobs_list (CcPrintersPanel *self);
static void actualize_printers_list (CcPrintersPanel *self);
static void actualize_allowed_users_list (CcPrintersPanel *self);
static void printer_disable_cb (GtkToggleButton *togglebutton, gpointer user_data);
static void printer_set_default_cb (GtkToggleButton *button, gpointer user_data);
static void
cc_printers_panel_get_property (GObject *object,
......@@ -327,6 +328,15 @@ printer_selection_changed_cb (GtkTreeSelection *selection,
g_signal_handlers_unblock_by_func (G_OBJECT (widget), printer_disable_cb, self);
widget = (GtkWidget*)
gtk_builder_get_object (priv->builder, "printer-default-check-button");
gtk_widget_set_sensitive (widget, TRUE);
g_signal_handlers_block_by_func (G_OBJECT (widget), printer_set_default_cb, self);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), priv->dests[id].is_default);
g_signal_handlers_unblock_by_func (G_OBJECT (widget), printer_set_default_cb, self);
widget = (GtkWidget*)
gtk_builder_get_object (priv->builder, "supply-drawing-area");
......@@ -406,8 +416,8 @@ actualize_printers_list (CcPrintersPanel *self)
current_printer_instance = g_strdup (priv->dests[priv->current_dest].instance);
}
if (priv->num_jobs > 0)
cupsFreeJobs (priv->num_jobs, priv->jobs);
if (priv->num_dests > 0)
cupsFreeDests (priv->num_dests, priv->dests);
priv->num_dests = cupsGetDests (&priv->dests);
priv->current_dest = -1;
......@@ -1087,51 +1097,6 @@ printer_disable_cb (GtkToggleButton *togglebutton,
}
}
static void
printer_delete_cb (GtkToolButton *toolbutton,
gpointer user_data)
{
CcPrintersPanelPrivate *priv;
CcPrintersPanel *self = (CcPrintersPanel*) user_data;
DBusGProxy *proxy;
gboolean ret = FALSE;
GError *error = NULL;
char *ret_error = NULL;
char *name = NULL;
priv = PRINTERS_PANEL_PRIVATE (self);
if (priv->current_dest >= 0 &&
priv->current_dest < priv->num_dests &&
priv->dests != NULL)
name = priv->dests[priv->current_dest].name;
if (name)
{
proxy = get_dbus_proxy ();
if (!proxy)
return;
ret = dbus_g_proxy_call (proxy, "PrinterDelete", &error,
G_TYPE_STRING, name,
G_TYPE_INVALID,
G_TYPE_STRING, &ret_error,
G_TYPE_INVALID);
if (error || (ret_error && ret_error[0] != '\0'))
{
if (error)
g_warning ("%s", error->message);
if (ret_error && ret_error[0] != '\0')
g_warning ("%s", ret_error);
}
else
actualize_printers_list (self);
}
}
static gboolean
supply_levels_draw_cb (GtkWidget *widget,
cairo_t *cr,
......@@ -1324,29 +1289,53 @@ allowed_user_remove_cb (GtkButton *button,
}
static void
set_widget_style (GtkWidget *widget, gchar *style_data)
printer_set_default_cb (GtkToggleButton *button,
gpointer user_data)
{
GtkStyleProvider *provider;
GtkStyleContext *context;
CcPrintersPanelPrivate *priv;
CcPrintersPanel *self = (CcPrintersPanel*) user_data;
DBusGProxy *proxy;
gboolean ret = FALSE;
GError *error = NULL;
char *ret_error = NULL;
char *name = NULL;
if (widget)
priv = PRINTERS_PANEL_PRIVATE (self);
if (priv->current_dest >= 0 &&
priv->current_dest < priv->num_dests &&
priv->dests != NULL)
name = priv->dests[priv->current_dest].name;
if (name)
{
context = gtk_widget_get_style_context (widget);
provider = g_object_get_data (G_OBJECT (widget), "provider");
proxy = get_dbus_proxy ();
if (!proxy)
return;
if (provider == NULL)
ret = dbus_g_proxy_call (proxy, "PrinterSetDefault", &error,
G_TYPE_STRING, name,
G_TYPE_INVALID,
G_TYPE_STRING, &ret_error,
G_TYPE_INVALID);
if (error || (ret_error && ret_error[0] != '\0'))
{
provider = (GtkStyleProvider *)gtk_css_provider_new ();
g_object_set_data (G_OBJECT (widget), "provider", provider);
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
if (error)
g_warning ("%s", error->message);
if (ret_error && ret_error[0] != '\0')
g_warning ("%s", ret_error);
}
else
actualize_printers_list (self);
gtk_css_provider_load_from_data ((GtkCssProvider *)provider,
style_data, -1, NULL);
gtk_style_context_invalidate (context);
}
g_signal_handlers_block_by_func (G_OBJECT (button), printer_set_default_cb, self);
gtk_toggle_button_set_active (button, priv->dests[priv->current_dest].is_default);
g_signal_handlers_unblock_by_func (G_OBJECT (button), printer_set_default_cb, self);
}
}
static void
......@@ -1406,10 +1395,6 @@ cc_printers_panel_init (CcPrintersPanel *self)
gtk_builder_get_object (priv->builder, "printer-disable-button");
g_signal_connect (widget, "toggled", G_CALLBACK (printer_disable_cb), self);
widget = (GtkWidget*)
gtk_builder_get_object (priv->builder, "printer-delete-button");
g_signal_connect (widget, "clicked", G_CALLBACK (printer_delete_cb), self);
widget = (GtkWidget*)
gtk_builder_get_object (priv->builder, "allowed-user-remove-button");
g_signal_connect (widget, "clicked", G_CALLBACK (allowed_user_remove_cb), self);
......@@ -1418,11 +1403,9 @@ cc_printers_panel_init (CcPrintersPanel *self)
gtk_builder_get_object (priv->builder, "supply-drawing-area");
g_signal_connect (widget, "draw", G_CALLBACK (supply_levels_draw_cb), self);
/* set plain style for borders of toolbars */
widget = (GtkWidget*)
gtk_builder_get_object (priv->builder, "printers-toolbar");
set_widget_style (widget, "GtkToolbar { border-style: none }");
gtk_builder_get_object (priv->builder, "printer-default-check-button");
g_signal_connect (widget, "toggled", G_CALLBACK (printer_set_default_cb), self);
/* make unused widgets insensitive for now */
......@@ -1430,10 +1413,6 @@ cc_printers_panel_init (CcPrintersPanel *self)
gtk_builder_get_object (priv->builder, "allowed-user-add-button");
gtk_widget_set_sensitive (widget, FALSE);
widget = (GtkWidget*)
gtk_builder_get_object (priv->builder, "printer-add-button");
gtk_widget_set_sensitive (widget, FALSE);
widget = (GtkWidget*)
gtk_builder_get_object (priv->builder, "print-test-page-button");
gtk_widget_set_sensitive (widget, FALSE);
......
......@@ -36,38 +36,24 @@
</packing>
</child>
<child>
<object class="GtkToolbar" id="printers-toolbar">
<object class="GtkCheckButton" id="printer-default-check-button">
<property name="visible">True</property>
<property name="toolbar_style">icons</property>
<child>
<object class="GtkToolButton" id="printer-add-button">
<property name="visible">True</property>
<property name="tooltip_text" translatable="yes">Add new printer</property>
<property name="label" translatable="yes">AddPrinter</property>
<property name="use_underline">True</property>
<property name="icon_name">list-add</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
<child>
<object class="GtkToolButton" id="printer-delete-button">
<object class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="tooltip_text" translatable="yes">Remove selected printer</property>
<property name="label" translatable="yes">RemovePrinter</property>
<property name="use_underline">True</property>
<property name="icon_name">list-remove</property>
<property name="label" translatable="yes">Default</property>
<attributes>
<attribute name="style" value="italic"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
......
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