Commit 6a6d0a07 authored by Fabien Parent's avatar Fabien Parent
Browse files

Migration from GConf to GSettings.

parent 6996b0ef
......@@ -64,7 +64,8 @@ src_regexxer_SOURCES = \
src/translation.cc \
src/translation.h \
src/undostack.cc \
src/undostack.h
src/undostack.h \
src/settings.h
nodist_src_regexxer_SOURCES = \
ui/stockimages.h
......@@ -83,9 +84,7 @@ iconthemedir = $(datadir)/icons/hicolor
appicondir = $(iconthemedir)/48x48/apps
dist_appicon_DATA = ui/regexxer.png
schemas_in_files = ui/regexxer.schemas.in
schemasdir = $(GCONF_SCHEMA_FILE_DIR)
schemas_DATA = ui/regexxer.schemas
gsettingsschema_DATA = ui/org.gnome.regexxer.gschema.xml
desktop_in_files = ui/regexxer.desktop.in
desktopdir = $(datadir)/applications
......@@ -94,27 +93,23 @@ desktop_DATA = ui/regexxer.desktop
dist_intltool = intltool-extract.in intltool-merge.in intltool-update.in
stockimages = ui/stock_save_all_16.png ui/stock_save_all_24.png
dist_noinst_DATA = $(stockimages) $(dist_intltool) $(desktop_in_files) $(schemas_in_files)
dist_noinst_DATA = $(stockimages) $(dist_intltool) $(desktop_in_files)
dist_noinst_SCRIPTS = autogen.sh
BUILT_SOURCES = $(nodist_src_regexxer_SOURCES)
CLEANFILES = $(nodist_src_regexxer_SOURCES) $(desktop_DATA) $(schemas_DATA)
CLEANFILES = $(nodist_src_regexxer_SOURCES) $(desktop_DATA)
DISTCLEANFILES = intltool-extract intltool-merge intltool-update
pixbuf_csource = $(GDK_PIXBUF_CSOURCE) --raw
update_icon_cache = $(GTK_UPDATE_ICON_CACHE) --ignore-theme-index --force
gconftool = GCONF_CONFIG_SOURCE='$(GCONF_SCHEMA_CONFIG_SOURCE)' $(GCONFTOOL)
@INTLTOOL_SCHEMAS_RULE@
@INTLTOOL_DESKTOP_RULE@
if GCONF_SCHEMAS_INSTALL
install-data-hook: install-schemas install-update-icon-cache
uninstall-hook: uninstall-schemas uninstall-update-icon-cache
else
install-data-hook: install-update-icon-cache
$(GLIB_COMPILE_SCHEMAS) $(gsettingsschemadir)
#$(gsettingsupdateschemacache) $(gsettingsschemadir)
uninstall-hook: uninstall-update-icon-cache
endif
dist-hook: dist-changelog
......@@ -144,15 +139,6 @@ dist-changelog:
then mv -f .ChangeLog.tmp "$(top_distdir)/ChangeLog"; \
else rm -f .ChangeLog.tmp; exit 1; fi; \
fi
install-schemas: $(schemas_DATA)
@$(POST_INSTALL)
test -n "$(DESTDIR)" || $(gconftool) --makefile-install-rule $(schemas_DATA)
uninstall-schemas: $(schemas_DATA)
@$(POST_UNINSTALL)
test -n "$(DESTDIR)" || $(gconftool) --makefile-uninstall-rule $(schemas_DATA)
install-update-icon-cache:
@$(POST_INSTALL)
test -n "$(DESTDIR)" || $(update_icon_cache) "$(iconthemedir)"
......@@ -161,7 +147,7 @@ uninstall-update-icon-cache:
@$(POST_UNINSTALL)
test -n "$(DESTDIR)" || $(update_icon_cache) "$(iconthemedir)"
.PHONY: dist-changelog install-schemas uninstall-schemas \
.PHONY: dist-changelog \
install-update-icon-cache uninstall-update-icon-cache
.DELETE_ON_ERROR:
......@@ -35,17 +35,14 @@ AC_SUBST([GETTEXT_PACKAGE], [regexxer])
AM_GNU_GETTEXT_VERSION([0.11])
AM_GLIB_GNU_GETTEXT
# gmodule-export-2.0 adds -Wl,--export-dynamic to the linker flags
# so that libglade can get at the custom widget creation functions.
PKG_CHECK_MODULES([REGEXXER_MODULES],
[gtk+-2.0 >= 2.16.0 gtkmm-2.4 >= 2.12.0 glibmm-2.4 >= 2.27.4.1
gconfmm-2.6 >= 2.6.1 gtksourceviewmm-2.0 >= 2.9.0])
gtksourceviewmm-2.0 >= 2.9.0])
DK_PKG_PATH_PROG([GDK_PIXBUF_CSOURCE], [gdk-pixbuf-2.0], [gdk-pixbuf-csource])
DK_PKG_PATH_PROG([GTK_UPDATE_ICON_CACHE], [gtk+-2.0], [gtk-update-icon-cache])
DK_PKG_PATH_PROG([GCONFTOOL], [gconf-2.0], [gconftool-2])
AM_GCONF_SOURCE_2
GLIB_GSETTINGS
AC_LANG([C++])
......
......@@ -24,9 +24,9 @@
#include "miscutils.h"
#include "stringutils.h"
#include "translation.h"
#include "settings.h"
#include <glib.h>
#include <gconfmm/client.h>
#include <algorithm>
#include <list>
......@@ -55,7 +55,7 @@ protected:
virtual ~RegexxerTags();
private:
void on_conf_value_changed(const Glib::ustring& key, const Gnome::Conf::Value& value);
void on_conf_value_changed(const Glib::ustring& key);
};
RegexxerTags::RegexxerTags()
......@@ -71,30 +71,30 @@ RegexxerTags::RegexxerTags()
error_title->property_scale() = Pango::SCALE_X_LARGE;
Gnome::Conf::Client::get_default_client()->signal_value_changed()
.connect(sigc::mem_fun(*this, &RegexxerTags::on_conf_value_changed));
add(error_message);
add(error_title);
add(match);
add(current);
Glib::RefPtr<Gio::Settings> settings = Regexxer::Settings::instance();
settings->signal_changed().connect(sigc::mem_fun(*this, &RegexxerTags::on_conf_value_changed));
std::vector<std::string> keys = settings->list_keys();
for (std::vector<std::string>::iterator i = keys.begin(); i != keys.end(); ++i)
on_conf_value_changed(*i);
}
RegexxerTags::~RegexxerTags()
{}
void RegexxerTags::on_conf_value_changed(const Glib::ustring& key, const Gnome::Conf::Value& value)
void RegexxerTags::on_conf_value_changed(const Glib::ustring& key)
{
using namespace Regexxer;
if (value.get_type() == Gnome::Conf::VALUE_STRING)
{
if (key.raw() == conf_key_match_color)
match->property_background() = value.get_string();
else if (key.raw() == conf_key_current_match_color)
current->property_background() = value.get_string();
}
if (key.raw() == conf_key_match_color)
match->property_background() = Settings::instance()->get_string(key);
else if (key.raw() == conf_key_current_match_color)
current->property_background() = Settings::instance()->get_string(key);
}
// static
......
......@@ -23,9 +23,9 @@
#include "globalstrings.h"
#include "stringutils.h"
#include "translation.h"
#include "settings.h"
#include <glibmm.h>
#include <gconfmm/client.h>
#include <gtkmm/stock.h>
#include <config.h>
......@@ -98,8 +98,7 @@ FileTree::FileTree()
selection->set_select_function(&FileTree::select_func);
selection->signal_changed().connect(mem_fun(*this, &FileTree::on_selection_changed));
Gnome::Conf::Client::get_default_client()
->signal_value_changed().connect(mem_fun(*this, &FileTree::on_conf_value_changed));
Settings::instance()->signal_changed().connect(mem_fun(*this, &FileTree::on_conf_value_changed));
}
FileTree::~FileTree()
......@@ -934,13 +933,10 @@ void FileTree::load_file_with_fallback(const Gtk::TreeModel::iterator& iter,
}
}
void FileTree::on_conf_value_changed(const Glib::ustring& key, const Gnome::Conf::Value& value)
void FileTree::on_conf_value_changed(const Glib::ustring& key)
{
if (value.get_type() == Gnome::Conf::VALUE_STRING)
{
if (key.raw() == conf_key_fallback_encoding)
fallback_encoding_ = value.get_string();
}
if (key == conf_key_fallback_encoding)
fallback_encoding_ = Settings::instance()->get_string(key);
}
} // namespace Regexxer
......@@ -34,7 +34,6 @@
namespace Gtk { class TreeStore; }
namespace Glib { class Regex; }
namespace Gnome { namespace Conf { class Value; } }
namespace Regexxer
{
......@@ -155,7 +154,7 @@ private:
void load_file_with_fallback(const Gtk::TreeModel::iterator& iter, const FileInfoPtr& fileinfo);
void on_conf_value_changed(const Glib::ustring& key, const Gnome::Conf::Value& value);
void on_conf_value_changed(const Glib::ustring& key);
};
class FileTree::Error
......
......@@ -32,14 +32,13 @@ namespace Regexxer
* The final executable contains exactly one copy of each string literal,
* so there's no need to define them in a separate object file.
*/
const char *const conf_dir_application = "/apps/regexxer";
const char *const conf_key_textview_font = "/apps/regexxer/textview_font";
const char *const conf_key_match_color = "/apps/regexxer/match_color";
const char *const conf_key_current_match_color = "/apps/regexxer/current_match_color";
const char *const conf_key_toolbar_style = "/apps/regexxer/toolbar_style";
const char *const conf_key_fallback_encoding = "/apps/regexxer/fallback_encoding";
const char *const conf_key_substitution_patterns = "/apps/regexxer/substitution_patterns";
const char *const conf_key_regex_patterns = "/apps/regexxer/regex_patterns";
const char *const conf_schema = "org.gnome.regexxer";
const char *const conf_key_textview_font = "textview-font";
const char *const conf_key_match_color = "match-color";
const char *const conf_key_current_match_color = "current-match-color";
const char *const conf_key_fallback_encoding = "fallback-encoding";
const char *const conf_key_substitution_patterns = "substitution-patterns";
const char *const conf_key_regex_patterns = "regex-patterns";
const char *const ui_mainwindow_filename = REGEXXER_PKGDATADIR G_DIR_SEPARATOR_S
"mainwindow.ui";
......
......@@ -26,7 +26,6 @@
#include <glib.h>
#include <gtk/gtkwindow.h> /* for gtk_window_set_default_icon_name() */
#include <glibmm.h>
#include <gconfmm.h>
#include <gtkmm/iconfactory.h>
#include <gtkmm/iconset.h>
#include <gtkmm/iconsource.h>
......@@ -194,45 +193,6 @@ void register_stock_items()
factory->add_default();
}
static
void trap_gconf_exceptions()
{
try
{
throw; // re-throw current exception
}
catch (const Gnome::Conf::Error&)
{
// Ignore GConf exceptions thrown from GObject signal handlers.
// GConf itself is going print the warning message for us
// since we set the error handling mode to CLIENT_HANDLE_ALL.
}
}
static
void initialize_configuration()
{
using namespace Gnome::Conf;
Glib::add_exception_handler(&trap_gconf_exceptions);
const Glib::RefPtr<Client> client = Client::get_default_client();
client->set_error_handling(CLIENT_HANDLE_ALL);
client->add_dir(Regexxer::conf_dir_application, CLIENT_PRELOAD_ONELEVEL);
const std::list<Entry> entries = client->all_entries(Regexxer::conf_dir_application);
// Issue an artificial value_changed() signal for each entry in /apps/regexxer.
// Reusing the signal handlers this way neatly avoids the need for separate
// startup-initialization routines.
for (std::list<Entry>::const_iterator p = entries.begin(); p != entries.end(); ++p)
{
client->value_changed(p->get_key(), p->get_value());
}
}
} // anonymous namespace
int main(int argc, char** argv)
......@@ -240,7 +200,6 @@ int main(int argc, char** argv)
try
{
Util::initialize_gettext(PACKAGE_TARNAME, REGEXXER_LOCALEDIR);
Gnome::Conf::init();
std::auto_ptr<RegexxerOptions> options = RegexxerOptions::create();
Gtk::Main main_instance (argc, argv, options->context());
......@@ -253,7 +212,6 @@ int main(int argc, char** argv)
Regexxer::MainWindow window;
initialize_configuration();
window.initialize(options->init_state());
options.reset();
......
......@@ -25,11 +25,11 @@
#include "statusline.h"
#include "stringutils.h"
#include "translation.h"
#include "settings.h"
#include <glib.h>
#include <gtkmm.h>
#include <gtksourceviewmm.h>
#include <gconfmm/client.h>
#include <algorithm>
#include <functional>
#include <iostream>
......@@ -185,10 +185,10 @@ MainWindow::MainWindow()
button_recursive_ (0),
button_hidden_ (0),
entry_regex_ (0),
entry_regex_completion_stack_(10, Gnome::Conf::Client::get_default_client()->get_string_list(conf_key_regex_patterns)),
entry_regex_completion_stack_(10, Settings::instance()->get_string_array(conf_key_regex_patterns)),
entry_regex_completion_ (Gtk::EntryCompletion::create()),
entry_substitution_ (0),
entry_substitution_completion_stack_(10, Gnome::Conf::Client::get_default_client()->get_string_list(conf_key_substitution_patterns)),
entry_substitution_completion_stack_(10, Settings::instance()->get_string_array(conf_key_substitution_patterns)),
entry_substitution_completion_ (Gtk::EntryCompletion::create()),
button_multiple_ (0),
button_caseless_ (0),
......@@ -356,8 +356,7 @@ void MainWindow::connect_signals()
controller_.replace_file.connect(mem_fun(*this, &MainWindow::on_replace_file));
controller_.replace_all .connect(mem_fun(*this, &MainWindow::on_replace_all));
Gnome::Conf::Client::get_default_client()
->signal_value_changed().connect(mem_fun(*this, &MainWindow::on_conf_value_changed));
Settings::instance()->signal_changed().connect(mem_fun(*this, &MainWindow::on_conf_value_changed));
statusline_->signal_cancel_clicked.connect(
mem_fun(*this, &MainWindow::on_busy_action_cancel));
......@@ -575,10 +574,11 @@ void MainWindow::on_exec_search()
const Glib::ustring regex = entry_regex_->get_text();
const bool caseless = button_caseless_->get_active();
const bool multiple = button_multiple_->get_active();
entry_regex_completion_stack_.push(regex);
Gnome::Conf::Client::get_default_client()->set_string_list(conf_key_regex_patterns, entry_regex_completion_stack_.get_stack());
Settings::instance()->set_string_array(conf_key_regex_patterns, entry_regex_completion_stack_.get_stack());
try
{
Glib::RefPtr<Glib::Regex> pattern =
......@@ -759,7 +759,7 @@ void MainWindow::on_replace()
{
const Glib::ustring substitution = entry_substitution_->get_text();
entry_substitution_completion_stack_.push(substitution);
Gnome::Conf::Client::get_default_client()->set_string_list(conf_key_substitution_patterns, entry_substitution_completion_stack_.get_stack());
Settings::instance()->set_string_array(conf_key_substitution_patterns, entry_substitution_completion_stack_.get_stack());
buffer->replace_current_match(substitution);
on_go_next(true);
}
......@@ -771,7 +771,7 @@ void MainWindow::on_replace_file()
{
const Glib::ustring substitution = entry_substitution_->get_text();
entry_substitution_completion_stack_.push(substitution);
Gnome::Conf::Client::get_default_client()->set_string_list(conf_key_substitution_patterns, entry_substitution_completion_stack_.get_stack());
Settings::instance()->set_string_array(conf_key_substitution_patterns, entry_substitution_completion_stack_.get_stack());
buffer->replace_all_matches(substitution);
statusline_->set_match_index(0);
}
......@@ -783,7 +783,7 @@ void MainWindow::on_replace_all()
const Glib::ustring substitution = entry_substitution_->get_text();
entry_substitution_completion_stack_.push(substitution);
Gnome::Conf::Client::get_default_client()->set_string_list(conf_key_substitution_patterns, entry_substitution_completion_stack_.get_stack());
Settings::instance()->set_string_array(conf_key_substitution_patterns, entry_substitution_completion_stack_.get_stack());
filetree_->replace_all_matches(substitution);
statusline_->set_match_index(0);
}
......@@ -1003,16 +1003,13 @@ void MainWindow::on_pref_dialog_hide()
const std::auto_ptr<PrefDialog> temp (pref_dialog_);
}
void MainWindow::on_conf_value_changed(const Glib::ustring& key, const Gnome::Conf::Value& value)
void MainWindow::on_conf_value_changed(const Glib::ustring& key)
{
if (value.get_type() == Gnome::Conf::VALUE_STRING)
if (key == conf_key_textview_font)
{
if (key.raw() == conf_key_textview_font)
{
const Pango::FontDescription font (value.get_string());
textview_ ->modify_font(font);
entry_preview_->modify_font(font);
}
const Pango::FontDescription font (Settings::instance()->get_string(key));
textview_ ->modify_font(font);
entry_preview_->modify_font(font);
}
}
......
......@@ -55,8 +55,6 @@ namespace gtksourceview
class SourceView;
}
namespace Gnome { namespace Conf { class Value; } }
namespace Regexxer
{
......@@ -197,7 +195,7 @@ private:
void on_preferences();
void on_pref_dialog_hide();
void on_conf_value_changed(const Glib::ustring& key, const Gnome::Conf::Value& value);
void on_conf_value_changed(const Glib::ustring& key);
};
} // namespace Regexxer
......
......@@ -22,11 +22,12 @@
#include "globalstrings.h"
#include "stringutils.h"
#include "translation.h"
#include "settings.h"
#include <glib.h>
#include <gtkmm.h>
#include <gconfmm/client.h>
#include <list>
#include <iostream>
#include <config.h>
......@@ -108,82 +109,64 @@ void PrefDialog::on_response(int)
{
if (entry_fallback_changed_)
entry_fallback_->activate();
Gnome::Conf::Client::get_default_client()->suggest_sync();
std::cout << std::boolalpha << Settings::instance()->is_writable(conf_key_match_color) << std::endl;
dialog_->hide();
}
/*
* Note that it isn't strictly required to block the change notification
* as done below for the "toolbar_style" setting. GConf doesn't emit
* "value_changed" if the new value is identical to the old one. If, however,
* the value was reset to the schema default, the following change notification
* would again detach the schema. This won't look neat, and I like neat.
*/
void PrefDialog::on_conf_value_changed(const Glib::ustring& key, const Gnome::Conf::Value& value)
void PrefDialog::on_conf_value_changed(const Glib::ustring& key)
{
if (value.get_type() == Gnome::Conf::VALUE_STRING)
Glib::RefPtr<Gio::Settings> settings = Settings::instance();
if (key.raw() == conf_key_textview_font)
{
button_textview_font_->set_font_name(settings->get_string(key));
}
else if (key.raw() == conf_key_match_color)
{
if (key.raw() == conf_key_textview_font)
{
button_textview_font_->set_font_name(value.get_string());
}
else if (key.raw() == conf_key_match_color)
{
button_match_color_->set_color(Gdk::Color(value.get_string()));
}
else if (key.raw() == conf_key_current_match_color)
{
button_current_color_->set_color(Gdk::Color(value.get_string()));
}
else if (key.raw() == conf_key_fallback_encoding)
{
entry_fallback_->set_text(value.get_string());
entry_fallback_changed_ = false;
}
button_match_color_->set_color(Gdk::Color(settings->get_string(key)));
}
else if (key.raw() == conf_key_current_match_color)
{
button_current_color_->set_color(Gdk::Color(settings->get_string(key)));
}
else if (key.raw() == conf_key_fallback_encoding)
{
entry_fallback_->set_text(settings->get_string(key));
entry_fallback_changed_ = false;
}
}
void PrefDialog::initialize_configuration()
{
using namespace Gnome::Conf;
Glib::RefPtr<Gio::Settings> settings = Settings::instance();
const std::list<Glib::ustring> entries = settings->list_keys();
const Glib::RefPtr<Client> client = Client::get_default_client();
const std::list<Entry> entries (client->all_entries(conf_dir_application));
for (std::list<Entry>::const_iterator p = entries.begin(); p != entries.end(); ++p)
{
on_conf_value_changed(p->get_key(), p->get_value());
}
for (std::list<Glib::ustring>::const_iterator p = entries.begin(); p != entries.end(); ++p)
on_conf_value_changed(*p);
client->signal_value_changed().connect(
sigc::mem_fun(*this, &PrefDialog::on_conf_value_changed));
settings->bind(conf_key_textview_font, button_textview_font_, "font_name");
}
void PrefDialog::on_textview_font_set()
{
const Glib::ustring value = button_textview_font_->get_font_name();
Gnome::Conf::Client::get_default_client()->set(conf_key_textview_font, value);
Settings::instance()->set_string(conf_key_textview_font, value);
}
void PrefDialog::on_match_color_set()
{
const Glib::ustring value = Util::color_to_string(button_match_color_->get_color());
Gnome::Conf::Client::get_default_client()->set(conf_key_match_color, value);
Settings::instance()->set_string(conf_key_match_color, value);
}
void PrefDialog::on_current_color_set()
{
const Glib::ustring value = Util::color_to_string(button_current_color_->get_color());
Gnome::Conf::Client::get_default_client()->set(conf_key_current_match_color, value);
Settings::instance()->set_string(conf_key_current_match_color, value);
}
void PrefDialog::on_entry_fallback_changed()
{
// On dialog close, write back to the GConf database only if the user
// actually did something with the entry widget. This prevents GConf from
// detaching the key's Schema each time the preferences dialog is closed.
entry_fallback_changed_ = true;
}
......@@ -193,8 +176,8 @@ void PrefDialog::on_entry_fallback_activate()
if (Util::validate_encoding(fallback_encoding.raw()))
{
Gnome::Conf::Client::get_default_client()
->set(conf_key_fallback_encoding, fallback_encoding.uppercase());
Settings::instance()->set_string(conf_key_fallback_encoding,
fallback_encoding.uppercase());
entry_fallback_changed_ = false;
}
......
......@@ -38,9 +38,6 @@ class Widget;
class Window;
}
namespace Gnome { namespace Conf { class Value; } }
namespace Regexxer
{
......@@ -58,7 +55,6 @@ private:
Gtk::ColorButton* button_match_color_;
Gtk::ColorButton* button_current_color_;
Gtk::Entry* entry_fallback_;
Util::AutoConnection conn_toolbar_style_;
bool entry_fallback_changed_;
void load_xml();
......@@ -66,7 +62,7 @@ private:
void on_response(int response_id);
void on_conf_value_changed(const Glib::ustring& key, const Gnome::Conf::Value& value);
void on_conf_value_changed(const Glib::ustring& key);
void initialize_configuration();
void on_textview_font_set();
......
/*
* Copyright (c) 2010 Fabien Parent <parent.f@gmail.com>
*
* This file is part of regexxer.
*
* regexxer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* regexxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with regexxer; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __REGEXXER_SETTINGS_H_INCLUDED__
#define __REGEXXER_SETTINGS_H_INCLUDED__
#include <glibmm/refptr.h>
#include <giomm/settings.h>
#include "globalstrings.h"
namespace Regexxer
{
class Settings
{
private:
Settings();
public:
static Glib::RefPtr<Gio::Settings> instance()
{