Merge pull request #18 from gergelypolonkai/settings

Add minimalistic preferences dialog
This commit is contained in:
Gergely Polonkai 2014-06-30 23:01:07 +02:00
commit e14f796c38
6 changed files with 181 additions and 6 deletions

View File

@ -16,6 +16,7 @@ astrognome_source_files = \
ag-window.c \ ag-window.c \
ag-chart.c \ ag-chart.c \
ag-settings.c \ ag-settings.c \
ag-preferences.c \
astrognome.c \ astrognome.c \
$(NULL) $(NULL)

View File

@ -2,6 +2,7 @@
#include "ag-app.h" #include "ag-app.h"
#include "ag-window.h" #include "ag-window.h"
#include "ag-chart.h" #include "ag-chart.h"
#include "ag-preferences.h"
#include "config.h" #include "config.h"
#include "astrognome.h" #include "astrognome.h"
@ -62,7 +63,11 @@ new_window_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
static void static void
preferences_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) preferences_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
{ {
//ag_preferences_show_dialog(); AgApp *app = AG_APP(user_data);
GtkWindow *window;
window = ag_app_peek_first_window(app);
ag_preferences_show_dialog(window);
} }
static void static void

77
src/ag-preferences.c Normal file
View File

@ -0,0 +1,77 @@
#include <gtk/gtk.h>
#include "ag-settings.h"
#include "ag-preferences.h"
static GtkWidget *prefs_dialog = NULL;
typedef struct _AgPreferencesPrivate {
GtkCheckButton *maximized;
AgSettings *settings;
} AgPreferencesPrivate;
G_DEFINE_TYPE_WITH_PRIVATE(AgPreferences, ag_preferences, GTK_TYPE_DIALOG);
static void
ag_preferences_finalize(GObject *gobject)
{
AgPreferencesPrivate *priv;
priv = ag_preferences_get_instance_private(AG_PREFERENCES(gobject));
g_clear_object(&priv->settings);
G_OBJECT_CLASS(ag_preferences_parent_class)->finalize(gobject);
}
static void
ag_preferences_response(GtkDialog *dlg, gint response_id)
{
gtk_widget_destroy(GTK_WIDGET(dlg));
}
static void
ag_preferences_class_init(AgPreferencesClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS(klass);
object_class->finalize = ag_preferences_finalize;
dialog_class->response = ag_preferences_response;
gtk_widget_class_set_template_from_resource(widget_class, "/eu/polonkai/gergely/astrognome/ag-preferences.ui");
gtk_widget_class_bind_template_child_private(widget_class, AgPreferences, maximized);
}
static void
ag_preferences_init(AgPreferences *prefs)
{
AgPreferencesPrivate *priv;
GSettings *settings_window;
priv = ag_preferences_get_instance_private(prefs);
gtk_widget_init_template(GTK_WIDGET(prefs));
priv->settings = ag_settings_get();
settings_window = ag_settings_peek_window_settings(priv->settings);
g_settings_bind(settings_window, "maximized", priv->maximized, "active", G_SETTINGS_BIND_DEFAULT);
}
void
ag_preferences_show_dialog(GtkWindow *parent)
{
g_return_if_fail(GTK_IS_WINDOW(parent));
if (prefs_dialog == NULL) {
prefs_dialog = GTK_WIDGET(g_object_new(AG_TYPE_PREFERENCES, NULL));
g_signal_connect(prefs_dialog, "destroy", G_CALLBACK(gtk_widget_destroyed), &prefs_dialog);
}
if (parent != gtk_window_get_transient_for(GTK_WINDOW(prefs_dialog))) {
gtk_window_set_transient_for(GTK_WINDOW(prefs_dialog), parent);
}
gtk_window_present(GTK_WINDOW(prefs_dialog));
}

32
src/ag-preferences.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef __AG_PREFERENCES_H__
#define __AG_PREFERENCES_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define AG_TYPE_PREFERENCES (ag_preferences_get_type())
#define AG_PREFERENCES(o) (G_TYPE_CHECK_INSTANCE_CAST((o), AG_TYPE_PREFERENCES, AgPreferences))
#define AG_PREFERENCES_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), AG_TYPE_PREFERENCES, AgPreferencesClass))
#define AG_IS_PREFERENCES(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), AG_TYPE_PREFERENCES))
#define AG_IS_PREFERENCES_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), AG_TYPE_PREFERENCES))
#define AG_PREFERENCES_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), AG_TYPE_PREFERENCES, AgPreferencesClass))
typedef struct _AgPreferences AgPreferences;
typedef struct _AgPreferencesClass AgPreferencesClass;
struct _AgPreferences {
GtkDialog parent;
};
struct _AgPreferencesClass {
GtkDialogClass parent_class;
};
GType ag_preferences_get_type(void);
void ag_preferences_show_dialog(GtkWindow *parent);
G_END_DECLS
#endif /* __AG_PREFERENCES_H__ */

59
src/ag-preferences.ui Normal file
View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<template class="AgPreferences" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="type_hint">normal</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCheckButton" id="maximized">
<property name="label" translatable="yes">New windows start maximized</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</template>
</interface>

View File

@ -2,5 +2,6 @@
<gresources> <gresources>
<gresource prefix="/eu/polonkai/gergely/astrognome"> <gresource prefix="/eu/polonkai/gergely/astrognome">
<file>astrognome.ui</file> <file>astrognome.ui</file>
<file>ag-preferences.ui</file>
</gresource> </gresource>
</gresources> </gresources>