Commit 1addd38c authored by Simon Steinbeiss's avatar Simon Steinbeiss Committed by Simon Steinbeiß
Browse files

Simplify settings dialog code

parent f4e9726e
......@@ -15,44 +15,16 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libxfce4ui/libxfce4ui.h>
#include "settings.h"
#include "settings-dialog.h"
#include "settings-dialog_ui.h"
typedef struct _XtmSettingsDialogClass XtmSettingsDialogClass;
struct _XtmSettingsDialogClass
{
GtkWidgetClass parent_class;
};
struct _XtmSettingsDialog
{
GtkWidget parent;
/*<private>*/
GtkWidget * window;
XtmSettings * settings;
};
G_DEFINE_TYPE (XtmSettingsDialog, xtm_settings_dialog, GTK_TYPE_WIDGET)
static void xtm_settings_dialog_finalize (GObject *object);
static void xtm_settings_dialog_show (GtkWidget *widget);
static void xtm_settings_dialog_hide (GtkWidget *widget);
static void show_about_dialog (GtkWidget *widget);
static GtkWidget *xtm_settings_dialog_new (GtkBuilder *builder, GtkWidget *parent_window);
static void
xtm_settings_dialog_class_init (XtmSettingsDialogClass *klass)
{
GObjectClass *class;
GtkWidgetClass *widget_class;
xtm_settings_dialog_parent_class = g_type_class_peek_parent (klass);
class = G_OBJECT_CLASS (klass);
class->finalize = xtm_settings_dialog_finalize;
widget_class = GTK_WIDGET_CLASS (klass);
widget_class->show = xtm_settings_dialog_show;
widget_class->hide = xtm_settings_dialog_hide;
}
static void
button_toggled (GtkToggleButton *button, XtmSettings *settings)
......@@ -76,14 +48,6 @@ builder_bind_toggle_button (GtkBuilder *builder, gchar *widget_name, XtmSettings
g_signal_connect (button, "toggled", G_CALLBACK (button_toggled), settings);
}
static void
combobox_changed (GtkComboBox *combobox, XtmSettings *settings)
{
gint active = gtk_combo_box_get_active (combobox);
gchar *setting_name = g_object_get_data (G_OBJECT (combobox), "setting-name");
g_object_set (settings, setting_name, active, NULL);
}
static void
show_about_dialog (GtkWidget *widget)
{
......@@ -132,79 +96,46 @@ show_about_dialog (GtkWidget *widget)
NULL);
}
static void
xtm_settings_dialog_init (XtmSettingsDialog *dialog)
static GtkWidget *
xtm_settings_dialog_new (GtkBuilder *builder, GtkWidget *parent_window)
{
GtkBuilder *builder;
GtkWidget *about;
g_object_ref_sink (dialog);
dialog->settings = xtm_settings_get_default ();
builder = gtk_builder_new ();
gtk_builder_add_from_string (builder, settings_dialog_ui, settings_dialog_ui_length, NULL);
GtkWidget *dialog;
GtkWidget *button;
XtmSettings *settings;
dialog->window = GTK_WIDGET (gtk_builder_get_object (builder, "settings-dialog"));
settings = xtm_settings_get_default ();
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "settings-dialog"));
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent_window));
#ifndef HAVE_WNCK
gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (builder, "button-show-application-icons")));
#endif
builder_bind_toggle_button (builder, "button-show-application-icons", dialog->settings, "show-application-icons");
builder_bind_toggle_button (builder, "button-full-command-line", dialog->settings, "full-command-line");
builder_bind_toggle_button (builder, "button-more-precision", dialog->settings, "more-precision");
builder_bind_toggle_button (builder, "button-prompt-terminate-task", dialog->settings, "prompt-terminate-task");
builder_bind_toggle_button (builder, "button-show-status-icon", dialog->settings, "show-status-icon");
builder_bind_toggle_button (builder, "button-process-tree", dialog->settings, "process-tree");
about = GTK_WIDGET (gtk_builder_get_object (builder, "button-about"));
g_signal_connect_swapped (about, "clicked", G_CALLBACK (show_about_dialog), dialog->window);
builder_bind_toggle_button (builder, "button-show-application-icons", settings, "show-application-icons");
builder_bind_toggle_button (builder, "button-full-command-line", settings, "full-command-line");
builder_bind_toggle_button (builder, "button-more-precision", settings, "more-precision");
builder_bind_toggle_button (builder, "button-prompt-terminate-task", settings, "prompt-terminate-task");
builder_bind_toggle_button (builder, "button-show-status-icon", settings, "show-status-icon");
builder_bind_toggle_button (builder, "button-process-tree", settings, "process-tree");
g_object_unref (builder);
}
static void
xtm_settings_dialog_finalize (GObject *object)
{
XtmSettingsDialog *dialog = XTM_SETTINGS_DIALOG (object);
gtk_widget_destroy (dialog->window);
g_object_unref (dialog->settings);
}
button = GTK_WIDGET (gtk_builder_get_object (builder, "button-about"));
g_signal_connect_swapped (button, "clicked", G_CALLBACK (show_about_dialog), dialog);
GtkWidget *
xtm_settings_dialog_new (GtkWindow *parent_window)
{
GtkWidget *dialog = g_object_new (XTM_TYPE_SETTINGS_DIALOG, NULL);
gtk_window_set_transient_for (GTK_WINDOW (XTM_SETTINGS_DIALOG (dialog)->window), parent_window);
return dialog;
}
static void
xtm_settings_dialog_show (GtkWidget *widget)
void
xtm_settings_dialog_run (GtkWidget *parent_window)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GTK_IS_WIDGET (XTM_SETTINGS_DIALOG (widget)->window));
gtk_widget_show (XTM_SETTINGS_DIALOG (widget)->window);
gtk_window_present (GTK_WINDOW (XTM_SETTINGS_DIALOG (widget)->window));
}
GtkBuilder *builder;
GtkWidget *dialog;
static void
xtm_settings_dialog_hide (GtkWidget *widget)
{
gint winx, winy;
g_return_if_fail (GTK_IS_WIDGET (widget));
if (!GTK_IS_WIDGET (XTM_SETTINGS_DIALOG (widget)->window))
return;
gtk_window_get_position (GTK_WINDOW (XTM_SETTINGS_DIALOG (widget)->window), &winx, &winy);
gtk_widget_hide (XTM_SETTINGS_DIALOG (widget)->window);
gtk_window_move (GTK_WINDOW (XTM_SETTINGS_DIALOG (widget)->window), winx, winy);
}
builder = gtk_builder_new ();
gtk_builder_add_from_string (builder, settings_dialog_ui, settings_dialog_ui_length, NULL);
g_return_if_fail (GTK_IS_BUILDER (builder));
void
xtm_settings_dialog_run (XtmSettingsDialog *dialog)
{
gtk_dialog_run (GTK_DIALOG (dialog->window));
dialog = xtm_settings_dialog_new (builder, parent_window);
g_object_unref (builder);
gtk_dialog_run (GTK_DIALOG (dialog));
}
......@@ -17,17 +17,6 @@
#include <glib-object.h>
#include <gtk/gtk.h>
#define XTM_TYPE_SETTINGS_DIALOG (xtm_settings_dialog_get_type ())
#define XTM_SETTINGS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_SETTINGS_DIALOG, XtmSettingsDialog))
#define XTM_SETTINGS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_SETTINGS_DIALOG, XtmSettingsDialogClass))
#define XTM_IS_SETTINGS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_SETTINGS_DIALOG))
#define XTM_IS_SETTINGS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_SETTINGS_DIALOG))
#define XTM_SETTINGS_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_SETTINGS_DIALOG, XtmSettingsDialogClass))
typedef struct _XtmSettingsDialog XtmSettingsDialog;
GType xtm_settings_dialog_get_type (void);
GtkWidget * xtm_settings_dialog_new (GtkWindow *parent_window);
void xtm_settings_dialog_run (XtmSettingsDialog *dialog);
void xtm_settings_dialog_run (GtkWidget *parent_window);
#endif /* !SETTINGS_DIALOG_H */
This diff is collapsed.
......@@ -65,9 +65,8 @@ static void
show_settings_dialog (XtmSettingsToolButton *button)
{
GtkWidget *parent_window = gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_WINDOW);
GtkWidget *dialog = xtm_settings_dialog_new (GTK_WINDOW (parent_window));
xtm_settings_dialog_run (XTM_SETTINGS_DIALOG (dialog));
g_object_unref (dialog);
xtm_settings_dialog_run (parent_window);
}
static void
......
......@@ -100,8 +100,6 @@ xtm_settings_class_init (XtmSettingsClass *klass)
g_param_spec_boolean ("monitor-paint-box", "MonitorPaintBox", "Paint box around monitor", TRUE, G_PARAM_READWRITE));
g_object_class_install_property (class, PROP_SHOW_APPLICATION_ICONS,
g_param_spec_boolean ("show-application-icons", "ShowApplicationIcons", "Show application icons", TRUE, G_PARAM_READWRITE));
g_object_class_install_property (class, PROP_TOOLBAR_STYLE,
g_param_spec_enum ("toolbar-style", "ToolbarStyle", "Toolbar style", XTM_TYPE_TOOLBAR_STYLE, XTM_TOOLBAR_STYLE_DEFAULT, G_PARAM_READWRITE));
g_object_class_install_property (class, PROP_PROMPT_TERMINATE_TASK,
g_param_spec_boolean ("prompt-terminate-task", "PromptTerminateTask", "Prompt dialog for terminating a task", TRUE, G_PARAM_READWRITE));
g_object_class_install_property (class, PROP_REFRESH_RATE,
......
Supports Markdown
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