1
0

Add preferences window with option to turn off maximized windows

This is very limited right now. See README.md for other options to
integrate here (and throughout the app).
Este cometimento está contido em:
2014-06-30 22:51:15 +02:00
ascendente 1cee8bf38c
cometimento b2cab90dcb
5 ficheiros modificados com 143 adições e 26 eliminações

Ver ficheiro

@@ -63,7 +63,11 @@ new_window_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
static void
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

Ver ficheiro

@@ -1,43 +1,77 @@
#include <glib.h>
#include <gtk/gtk.h>
#include "ag-settings.h"
#include "ag-preferences.h"
typedef struct {
GtkWidget *dialog;
static GtkWidget *prefs_dialog = NULL;
typedef struct _AgPreferencesPrivate {
GtkCheckButton *maximized;
AgSettings *settings;
} AgPreferences;
} AgPreferencesPrivate;
static AgPreferences *prefs;
G_DEFINE_TYPE_WITH_PRIVATE(AgPreferences, ag_preferences, GTK_TYPE_DIALOG);
static void
ag_preferences_init(void)
ag_preferences_finalize(GObject *gobject)
{
GApplication *app;
AgPreferencesPrivate *priv;
if (prefs) {
return;
}
priv = ag_preferences_get_instance_private(AG_PREFERENCES(gobject));
if ((app = g_application_get_default()) == NULL) {
g_warning("Cannot launch preferences: No default application found");
g_clear_object(&priv->settings);
return;
}
G_OBJECT_CLASS(ag_preferences_parent_class)->finalize(gobject);
}
prefs = g_new0(AgPreferences, 1);
prefs->settings = ag_settings_get();
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(void)
ag_preferences_show_dialog(GtkWindow *parent)
{
ag_preferences_init();
g_return_if_fail(GTK_IS_WINDOW(parent));
if (prefs->dialog != NULL) {
gtk_window_present(GTK_WINDOW(prefs->dialog));
return;
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));
}

Ver ficheiro

@@ -5,9 +5,28 @@
G_BEGIN_DECLS
void ag_preferences_show_dialog(void);
#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 Ficheiro normal
Ver ficheiro

@@ -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>

Ver ficheiro

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