Turn prefs into MidoriPreferences

This commit is contained in:
Christian Dywan 2008-04-20 03:30:24 +02:00
parent 457b012240
commit 50ab1e8bc7
7 changed files with 278 additions and 105 deletions

View file

@ -9,7 +9,7 @@ src/midori-panel.c
src/midori-trash.c src/midori-trash.c
src/midori-websettings.c src/midori-websettings.c
src/midori-webview.c src/midori-webview.c
src/prefs.c src/midori-preferences.c
src/search.c src/search.c
src/sokoke.c src/sokoke.c
src/webSearch.c src/webSearch.c

View file

@ -24,7 +24,7 @@ midori_SOURCES = \
midori-trash.c midori-trash.h \ midori-trash.c midori-trash.h \
midori-webview.c midori-webview.h \ midori-webview.c midori-webview.h \
midori-websettings.c midori-websettings.h \ midori-websettings.c midori-websettings.h \
prefs.c prefs.h \ midori-preferences.c midori-preferences.h \
webSearch.c webSearch.h \ webSearch.c webSearch.h \
helpers.c helpers.h \ helpers.c helpers.h \
sokoke.c sokoke.h \ sokoke.c sokoke.h \

View file

@ -16,10 +16,10 @@
#include "global.h" #include "global.h"
#include "helpers.h" #include "helpers.h"
#include "webSearch.h" #include "webSearch.h"
#include "prefs.h"
#include "sokoke.h" #include "sokoke.h"
#include "midori-webview.h" #include "midori-webview.h"
#include "midori-preferences.h"
#include "midori-panel.h" #include "midori-panel.h"
#include "midori-console.h" #include "midori-console.h"
#include "midori-trash.h" #include "midori-trash.h"
@ -876,7 +876,7 @@ _action_preferences_activate (GtkAction* action,
{ {
MidoriBrowserPrivate* priv = browser->priv; MidoriBrowserPrivate* priv = browser->priv;
dialog = prefs_preferences_dialog_new (GTK_WINDOW (browser), dialog = midori_preferences_new (GTK_WINDOW (browser),
priv->settings); priv->settings);
gtk_widget_show (dialog); gtk_widget_show (dialog);
} }

View file

@ -37,14 +37,14 @@ typedef struct _MidoriPanelClass MidoriPanelClass;
struct _MidoriPanel struct _MidoriPanel
{ {
GtkFrame parent_instance; GtkHBox parent_instance;
MidoriPanelPrivate* priv; MidoriPanelPrivate* priv;
}; };
struct _MidoriPanelClass struct _MidoriPanelClass
{ {
GtkFrameClass parent_class; GtkHBoxClass parent_class;
/* Signals */ /* Signals */
gboolean gboolean

View file

@ -9,14 +9,64 @@
See the file COPYING for the full license text. See the file COPYING for the full license text.
*/ */
#include "prefs.h" #include "midori-preferences.h"
#include "helpers.h"
#include "sokoke.h" #include "sokoke.h"
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <stdlib.h>
#include <string.h> G_DEFINE_TYPE (MidoriPreferences, midori_preferences, GTK_TYPE_DIALOG)
struct _MidoriPreferencesPrivate
{
GtkWidget* notebook;
};
#define MIDORI_PREFERENCES_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
MIDORI_TYPE_PREFERENCES, MidoriPreferencesPrivate))
enum
{
PROP_0,
PROP_SETTINGS
};
static void
midori_preferences_finalize (GObject* object);
static void
midori_preferences_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec);
static void
midori_preferences_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec);
static void
midori_preferences_class_init (MidoriPreferencesClass* class)
{
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = midori_preferences_finalize;
gobject_class->set_property = midori_preferences_set_property;
gobject_class->get_property = midori_preferences_get_property;
g_object_class_install_property (gobject_class,
PROP_SETTINGS,
g_param_spec_object (
"settings",
"Settings",
_("Settings instance to provide properties"),
MIDORI_TYPE_WEB_SETTINGS,
G_PARAM_WRITABLE));
g_type_class_add_private (class, sizeof (MidoriPreferencesPrivate));
}
static void static void
clear_button_clicked_cb (GtkWidget* button, GtkWidget* file_chooser) clear_button_clicked_cb (GtkWidget* button, GtkWidget* file_chooser)
@ -26,46 +76,146 @@ clear_button_clicked_cb (GtkWidget* button, GtkWidget* file_chooser)
g_signal_emit_by_name (file_chooser, "file-set"); g_signal_emit_by_name (file_chooser, "file-set");
} }
GtkWidget* prefs_preferences_dialog_new (GtkWindow* window, static void
MidoriWebSettings* settings) midori_preferences_init (MidoriPreferences* preferences)
{ {
gchar* dialogTitle = g_strdup_printf(_("%s Preferences"), g_get_application_name()); preferences->priv = MIDORI_PREFERENCES_GET_PRIVATE (preferences);
GtkWidget* dialog = gtk_dialog_new_with_buttons(dialogTitle MidoriPreferencesPrivate* priv = preferences->priv;
, window
, GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR
, GTK_STOCK_HELP, GTK_RESPONSE_HELP
, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE
, NULL);
gtk_window_set_icon_name(GTK_WINDOW(dialog), GTK_STOCK_PREFERENCES);
// TODO: Implement some kind of help function
gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_HELP, FALSE); //...
g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog);
CPrefs* prefs = g_new0(CPrefs, 1); priv->notebook = NULL;
g_signal_connect(dialog, "response", G_CALLBACK(g_free), prefs);
gchar* dialog_title = g_strdup_printf (_("%s Preferences"),
g_get_application_name ());
g_object_set (preferences,
"icon-name", GTK_STOCK_PREFERENCES,
"title", dialog_title,
"has-separator", FALSE,
NULL);
gtk_dialog_add_buttons (GTK_DIALOG (preferences),
GTK_STOCK_HELP, GTK_RESPONSE_HELP,
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
NULL);
// TODO: Implement some kind of help function
gtk_dialog_set_response_sensitive (GTK_DIALOG (preferences),
GTK_RESPONSE_HELP, FALSE); //...
g_signal_connect (preferences, "response",
G_CALLBACK (gtk_widget_destroy), preferences);
// TODO: Do we want tooltips for explainations or can we omit that? // TODO: Do we want tooltips for explainations or can we omit that?
// TODO: We need mnemonics g_free (dialog_title);
// TODO: Take multiple windows into account when applying changes }
static void
midori_preferences_finalize (GObject* object)
{
G_OBJECT_CLASS (midori_preferences_parent_class)->finalize (object);
}
static void
midori_preferences_set_property (GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec)
{
MidoriPreferences* preferences = MIDORI_PREFERENCES (object);
switch (prop_id)
{
case PROP_SETTINGS:
{
GtkWidget* xfce_heading; GtkWidget* xfce_heading;
GtkWindow* parent;
g_object_get (object, "transient-for", &parent, NULL);
if ((xfce_heading = sokoke_xfce_header_new ( if ((xfce_heading = sokoke_xfce_header_new (
gtk_window_get_icon_name(window), dialogTitle))) gtk_window_get_icon_name (parent),
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox) gtk_window_get_title (GTK_WINDOW (object)))))
, xfce_heading, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (preferences)->vbox),
g_free(dialogTitle); xfce_heading, FALSE, FALSE, 0);
GtkWidget* notebook = gtk_notebook_new(); midori_preferences_set_settings (preferences,
gtk_container_set_border_width(GTK_CONTAINER(notebook), 6); g_value_get_object (value));
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
midori_preferences_get_property (GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec)
{
MidoriPreferences* preferences = MIDORI_PREFERENCES (object);
MidoriPreferencesPrivate* priv = preferences->priv;
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* midori_preferences_new:
* @parent: the parent window
* @settings: the settings
*
* Creates a new preferences dialog.
*
* Return value: a new #MidoriPreferences
**/
GtkWidget*
midori_preferences_new (GtkWindow* parent,
MidoriWebSettings* settings)
{
g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
g_return_val_if_fail (MIDORI_IS_WEB_SETTINGS (settings), NULL);
MidoriPreferences* preferences = g_object_new (MIDORI_TYPE_PREFERENCES,
"transient-for", parent,
"settings", settings,
NULL);
return GTK_WIDGET (preferences);
}
/**
* midori_preferences_set_settings:
* @settings: the settings
*
* Assigns a settings instance to a preferences dialog.
*
* Note: This must not be called more than once.
**/
void
midori_preferences_set_settings (MidoriPreferences* preferences,
MidoriWebSettings* settings)
{
g_return_if_fail (MIDORI_IS_PREFERENCES (preferences));
g_return_if_fail (MIDORI_IS_WEB_SETTINGS (settings));
MidoriPreferencesPrivate* priv = preferences->priv;
g_return_if_fail (!priv->notebook);
priv->notebook = gtk_notebook_new ();
gtk_container_set_border_width (GTK_CONTAINER (priv->notebook), 6);
GtkSizeGroup* sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); GtkSizeGroup* sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
GtkWidget* page; GtkWidget* frame; GtkWidget* table; GtkWidget* align; GtkWidget* page; GtkWidget* frame; GtkWidget* table; GtkWidget* align;
GtkWidget* label; GtkWidget* button; GtkWidget* label; GtkWidget* button;
GtkWidget* entry; GtkWidget* hbox; GtkWidget* entry; GtkWidget* hbox;
#define PAGE_NEW(__label) page = gtk_vbox_new (FALSE, 0); \ #define PAGE_NEW(__label) page = gtk_vbox_new (FALSE, 0); \
gtk_container_set_border_width (GTK_CONTAINER (page), 5); \ gtk_container_set_border_width (GTK_CONTAINER (page), 5); \
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, gtk_label_new(__label)) gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page, \
gtk_label_new (__label))
#define FRAME_NEW(__label) frame = sokoke_hig_frame_new (__label); \ #define FRAME_NEW(__label) frame = sokoke_hig_frame_new (__label); \
gtk_container_set_border_width (GTK_CONTAINER (frame), 5); \ gtk_container_set_border_width (GTK_CONTAINER (frame), 5); \
gtk_box_pack_start (GTK_BOX (page), frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (page), frame, FALSE, FALSE, 0);
#define TABLE_NEW(__rows, __cols) table = gtk_table_new(__rows, __cols, FALSE);\ #define TABLE_NEW(__rows, __cols) table = gtk_table_new ( \
__rows, __cols, FALSE); \
gtk_container_set_border_width (GTK_CONTAINER (table), 5); \ gtk_container_set_border_width (GTK_CONTAINER (table), 5); \
gtk_container_add (GTK_CONTAINER (frame), table); gtk_container_add (GTK_CONTAINER (frame), table);
#define WIDGET_ADD(__widget, __left, __right, __top, __bottom) \ #define WIDGET_ADD(__widget, __left, __right, __top, __bottom) \
@ -242,8 +392,7 @@ GtkWidget* prefs_preferences_dialog_new (GtkWindow* window,
button = katze_property_proxy (settings, "remember-last-downloaded-files", NULL); button = katze_property_proxy (settings, "remember-last-downloaded-files", NULL);
SPANNED_ADD (button, 0, 2, 2, 3); SPANNED_ADD (button, 0, 2, 2, 3);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox) gtk_box_pack_start (GTK_BOX (GTK_DIALOG (preferences)->vbox),
, notebook, FALSE, FALSE, 4); priv->notebook, FALSE, FALSE, 4);
gtk_widget_show_all(GTK_DIALOG(dialog)->vbox); gtk_widget_show_all (GTK_DIALOG (preferences)->vbox);
return dialog;
} }

65
src/midori-preferences.h Normal file
View file

@ -0,0 +1,65 @@
/*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#ifndef __MIDORI_PREFERENCES_H__
#define __MIDORI_PREFERENCES_H__
#include "midori-websettings.h"
#include <gtk/gtk.h>
#include <katze/katze.h>
G_BEGIN_DECLS
#define MIDORI_TYPE_PREFERENCES \
(midori_preferences_get_type ())
#define MIDORI_PREFERENCES(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_PREFERENCES, MidoriPreferences))
#define MIDORI_PREFERENCES_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_PREFERENCES, MidoriPreferencesClass))
#define MIDORI_IS_PREFERENCES(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_PREFERENCES))
#define MIDORI_IS_PREFERENCES_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_PREFERENCES))
#define MIDORI_PREFERENCES_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_PREFERENCES, MidoriPreferencesClass))
typedef struct _MidoriPreferences MidoriPreferences;
typedef struct _MidoriPreferencesPrivate MidoriPreferencesPrivate;
typedef struct _MidoriPreferencesClass MidoriPreferencesClass;
struct _MidoriPreferences
{
GtkDialog parent_instance;
MidoriPreferencesPrivate* priv;
};
struct _MidoriPreferencesClass
{
GtkDialogClass parent_class;
};
GType
midori_preferences_get_type (void);
GtkWidget*
midori_preferences_new (GtkWindow* parent,
MidoriWebSettings* settings);
void
midori_preferences_set_settings (MidoriPreferences* preferences,
MidoriWebSettings* settings);
G_END_DECLS
#endif /* __MIDORI_PREFERENCES_H__ */

View file

@ -1,41 +0,0 @@
/*
Copyright (C) 2007 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
See the file COPYING for the full license text.
*/
#ifndef __PREFS_H__
#define __PREFS_H__ 1
#include <gtk/gtk.h>
#include "midori-websettings.h"
// -- Types
typedef struct
{
GtkWidget* userStylesheetUri;
GtkWidget* treeview;
GtkWidget* combobox;
GtkWidget* add;
} CPrefs;
enum
{
PROTOCOLS_COL_NAME,
PROTOCOLS_COL_COMMAND,
PROTOCOLS_COL_N
};
// -- Declarations
GtkWidget*
prefs_preferences_dialog_new(GtkWindow*, MidoriWebSettings*);
#endif /* !__PREFS_H__ */