Commit 7895d37f authored by Murray Cumming's avatar Murray Cumming Committed by Murray Cumming
Browse files

regexxer now depends on gconfmm. Removed the check for 2.2-specific

2003-11-29  Murray Cumming  <murrayc@usa.net>

        * configure.ac: regexxer now depends on gconfmm. Removed the check
        for 2.2-specific features.
        * Remoevd all gtkmm 2.2-specific #ifdefs because 2.2 is everywhere
        now..
        * src/configdata.[h|cc]: Changed the implemention to use GConfmm
        instead of the text file.
parent 1ff96b1a
2003-11-29 Murray Cumming <murrayc@usa.net>
* configure.ac: regexxer now depends on gconfmm. Removed the check
for 2.2-specific features.
* Remoevd all gtkmm 2.2-specific #ifdefs because 2.2 is everywhere
now..
* src/configdata.[h|cc]: Changed the implemention to use GConfmm
instead of the text file.
2003-10-31 Murray Cumming <murrayc@usa.net>
* src/mainwindow.cc: Used larger HIG-like borders and spacings to
......
......@@ -34,21 +34,10 @@ AC_CHECK_HEADERS([sys/types.h sys/stat.h])
AC_CHECK_FUNCS([umask])
AC_CHECK_TYPES([mode_t])
PKG_CHECK_MODULES([GTKMM], [glib-2.0 >= 2.0.7 gtk+-2.0 >= 2.0.6 sigc++-1.2 >= 1.2.1 gtkmm-2.0 >= 2.0.0])
PKG_CHECK_MODULES([GTKMM], [gtkmm-2.0 >= 2.2.8 gconfmm-2.0 >= 2.0.0])
AC_SUBST([GTKMM_CFLAGS])
AC_SUBST([GTKMM_LIBS])
AC_MSG_CHECKING([whether gtkmm-2.2 API additions are available])
regexxer_have_gtkmm_22=no
${PKG_CONFIG:-"pkg-config"} --atleast-version=2.2.0 gtkmm-2.0 2>&5 && regexxer_have_gtkmm_22=yes
AC_MSG_RESULT([${regexxer_have_gtkmm_22}])
if test "x$regexxer_have_gtkmm_22" = "xyes"; then
{
AC_DEFINE([REGEXXER_HAVE_GTKMM_22], [1], [Define to 1 if gtkmm 2.2 API is available.])
}
fi
gdk_pixbuf_exec_prefix=`${PKG_CONFIG:-"pkg-config"} --variable=exec_prefix gdk-pixbuf-2.0 2>&5`
prog_search_path=${gdk_pixbuf_exec_prefix:+"$gdk_pixbuf_exec_prefix/bin$PATH_SEPARATOR"}$PATH
......
......@@ -94,13 +94,11 @@ ContributorBox::ContributorBox(const Glib::ustring& what, const Glib::ustring& w
Label *const label_who = new SelectableLabel(who);
pack_start(*manage(label_who), PACK_SHRINK);
#if REGEXXER_HAVE_GTKMM_22
const Glib::RefPtr<Atk::Object> accessible_what = label_what->get_accessible();
const Glib::RefPtr<Atk::Object> accessible_who = label_who ->get_accessible();
accessible_what->add_relationship(Atk::RELATION_FLOWS_TO, accessible_who);
accessible_who ->add_relationship(Atk::RELATION_FLOWS_FROM, accessible_what);
#endif
}
ContributorBox::~ContributorBox()
......@@ -142,15 +140,11 @@ AboutDialog::AboutDialog(Gtk::Window& parent)
label_title->set_alignment(0.0, 0.5);
label_title->set_markup("<span size=\"xx-large\" weight=\"heavy\">" PACKAGE_STRING "</span>");
#if REGEXXER_HAVE_GTKMM_22
const Glib::RefPtr<Atk::Object> image_accessible = image->get_accessible();
image_accessible->set_name("regexxer icon");
#if 0 /* TODO: enable this when gtkmm-2.1.3 has been released */
Glib::RefPtr<Atk::Image>::cast_dynamic(image_accessible)
->set_image_description("The application icon of regexxer");
#endif
#endif
}
{
Box *const box_text = new VBox(false, 10);
......
......@@ -27,43 +27,9 @@
#include <config.h>
#if HAVE_UMASK
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if !HAVE_MODE_T
typedef int mode_t;
#endif
#endif /* HAVE_UMASK */
namespace
{
#if HAVE_UMASK
class ScopedUmask
{
private:
mode_t old_mask_;
ScopedUmask(const ScopedUmask&);
ScopedUmask& operator=(const ScopedUmask&);
public:
explicit ScopedUmask(mode_t mask) : old_mask_ (umask(mask)) {}
~ScopedUmask() { umask(old_mask_); }
};
#endif /* HAVE_UMASK */
void print_warning(const char* text)
{
......@@ -75,11 +41,13 @@ void print_warning(const char* text, const Glib::ustring& what)
g_warning(text, what.c_str());
}
/*
void print_invalid_value_warning(const Glib::ustring& value, const Glib::ustring& key)
{
g_warning("Error in configuration file: invalid value `%s' for key `%s'",
value.c_str(), key.c_str());
}
*/
struct NickValuePair
......@@ -88,8 +56,7 @@ struct NickValuePair
int value;
};
int enum_from_string(const Glib::ustring& value, const Glib::ustring& key,
const NickValuePair* value_map)
int enum_from_string(const Glib::ustring& value, const NickValuePair* value_map)
{
const NickValuePair* p = value_map;
......@@ -99,7 +66,7 @@ int enum_from_string(const Glib::ustring& value, const Glib::ustring& key,
return p->value;
}
print_invalid_value_warning(value, key);
//print_invalid_value_warning(value);
return p->value; // return some fallback value
}
......@@ -115,12 +82,19 @@ Glib::ustring enum_to_string(int value, const NickValuePair* value_map)
g_return_val_if_reached("");
}
void color_from_string(Gdk::Color& color, const Glib::ustring& value, const Glib::ustring& key)
void color_from_string(Gdk::Color& color, const Glib::ustring& value)
{
if(!color.parse(value))
print_invalid_value_warning(value, key);
color.parse(value);
//print_invalid_value_warning(value, key);
}
} // anonymous namespace
namespace Regexxer
{
/**** Regexxer::ConfigData *************************************************/
const NickValuePair toolbar_style_values[] =
{
......@@ -131,93 +105,43 @@ const NickValuePair toolbar_style_values[] =
{ 0, Gtk::TOOLBAR_BOTH_HORIZ }
};
Glib::RefPtr<Glib::IOChannel> open_config_file(const std::string& mode)
{
const std::string filename = Glib::build_filename(Glib::get_home_dir(), ".regexxer");
return Glib::IOChannel::create_from_file(filename, mode);
}
bool read_config_entry(const Glib::RefPtr<Glib::IOChannel>& channel,
Glib::ustring& key, Glib::ustring& value)
bool ConfigData::read_config_entry(const Glib::ustring& key, Glib::ustring& value)
{
using Glib::ustring;
//Set the value of the key in GConf:
const Glib::ustring key_complete = gconf_dir_path_ + key;
ustring line;
while(channel->read_line(line) == Glib::IO_STATUS_NORMAL)
try
{
ustring::const_iterator pbegin = line.begin();
ustring::const_iterator pend = line.end();
Util::trim_whitespace(pbegin, pend);
if(pbegin == pend || *pbegin == '#')
continue;
// Use byte-wise std::string iterators because it's faster.
// It's possible to do this when searching for an ASCII character.
const ustring::const_iterator passign (std::find(pbegin.base(), pend.base(), '='));
if(passign == pend)
{
print_warning("Error in configuration file: missing `='");
continue;
}
ustring::const_iterator pend_key = passign;
Util::trim_whitespace(pbegin, pend_key);
if(pend_key == pbegin)
{
print_warning("Error in configuration file: missing key before `='");
continue;
}
ustring::const_iterator pbegin_value = passign;
Util::trim_whitespace(++pbegin_value, pend);
if(pbegin_value == pend)
{
print_warning("Error in configuration file: missing value after `='");
continue;
}
key.assign(pbegin, pend_key);
value.assign(pbegin_value, pend);
value = refClient_->get_string(key_complete);
return true;
}
return false;
catch(const Gnome::Conf::Error& ex)
{
print_warning("Error while retrieving configuration: %s", ex.what().c_str());
return false;
}
}
void write_config_entry(const Glib::RefPtr<Glib::IOChannel>& channel,
const Glib::ustring& key, const Glib::ustring& value)
void ConfigData::write_config_entry(const Glib::ustring& key, const Glib::ustring& value)
{
channel->write(key);
channel->write("=");
channel->write(value);
channel->write("\n");
//Set the value of the key in GConf:
const Glib::ustring key_complete = gconf_dir_path_ + key;
refClient_->set(key_complete, value);
}
} // anonymous namespace
namespace Regexxer
{
/**** Regexxer::ConfigData *************************************************/
ConfigData::ConfigData()
:
textview_font ("Monospace"),
match_color ("orange"),
current_color ("yellow"),
toolbar_style (Gtk::TOOLBAR_BOTH_HORIZ),
fallback_encoding ("ISO-8859-15")
{}
fallback_encoding ("ISO-8859-15"),
gconf_dir_path_("/apps/gnome/regexxer")
{
//Connect to GConf:
refClient_ = Gnome::Conf::Client::get_default_client();
refClient_->add_dir(gconf_dir_path_);
}
ConfigData::~ConfigData()
{}
......@@ -225,41 +149,27 @@ ConfigData::~ConfigData()
void ConfigData::load()
{
try
{
const Glib::RefPtr<Glib::IOChannel> channel = open_config_file("r");
Glib::ustring key;
Glib::ustring value;
while(read_config_entry(channel, key, value))
{
if(key.raw() == "textview_font")
textview_font = value;
else if(key.raw() == "match_color")
color_from_string(match_color, value, key);
else if(key.raw() == "current_match_color")
color_from_string(current_color, value, key);
else if(key.raw() == "toolbar_style")
toolbar_style = Gtk::ToolbarStyle(enum_from_string(value, key, toolbar_style_values));
else if(key.raw() == "fallback_encoding")
set_fallback_encoding_from_string(value);
else if(key.raw() != "menutool_mode") // ignore key: menutool_mode is no longer supported
print_warning("Error in configuration file: unknown key `%s'", key);
}
}
catch(const Glib::FileError& error)
{
if(error.code() != Glib::FileError::NO_SUCH_ENTITY)
print_warning("Failed to open configuration file: %s", error.what());
{
read_config_entry("textview_font", textview_font);
Glib::ustring color_string;
read_config_entry("match_color", color_string);
color_from_string(match_color, color_string);
read_config_entry("current_match_color", color_string);
color_from_string(current_color, color_string);
Glib::ustring style_string;
read_config_entry("toolbar_style", style_string);
toolbar_style = Gtk::ToolbarStyle(enum_from_string(style_string, toolbar_style_values));
Glib::ustring value_string;
read_config_entry("fallback_encoding", value_string);
set_fallback_encoding_from_string(value_string);
}
catch(const Glib::Error& error)
catch(const Gnome::Conf::Error& error)
{
print_warning("Failed to read configuration file: %s", error.what());
print_warning("Failed to read configuration: %s", error.what());
}
}
......@@ -267,28 +177,15 @@ void ConfigData::save()
{
try
{
#if HAVE_UMASK
ScopedUmask scoped_umask (077); // set -rw------- for newly created files
#endif
const Glib::RefPtr<Glib::IOChannel> channel = open_config_file("w");
channel->write("# " PACKAGE_STRING " configuration file\n");
write_config_entry(channel, "textview_font", textview_font);
write_config_entry(channel, "match_color", Util::color_to_string(match_color));
write_config_entry(channel, "current_match_color", Util::color_to_string(current_color));
write_config_entry(channel, "toolbar_style", enum_to_string(toolbar_style, toolbar_style_values));
write_config_entry(channel, "fallback_encoding", get_string_from_fallback_encoding());
channel->close(); // close explicitly because it might fail
}
catch(const Glib::FileError& error)
{
print_warning("Failed to open configuration file: %s", error.what());
write_config_entry("textview_font", textview_font);
write_config_entry("match_color", Util::color_to_string(match_color));
write_config_entry("current_match_color", Util::color_to_string(current_color));
write_config_entry("toolbar_style", enum_to_string(toolbar_style, toolbar_style_values));
write_config_entry("fallback_encoding", get_string_from_fallback_encoding());
}
catch(const Glib::Error& error)
catch(const Gnome::Conf::Error& error)
{
print_warning("Failed to write configuration file: %s", error.what());
print_warning("Failed to write configuration: %s", error.what());
}
}
......@@ -303,7 +200,7 @@ void ConfigData::set_fallback_encoding_from_string(const Glib::ustring& value)
}
else
{
print_invalid_value_warning(value, "fallback_encoding");
//print_invalid_value_warning(value, "fallback_encoding");
}
}
......
......@@ -21,6 +21,7 @@
#ifndef REGEXXER_CONFIGDATA_H_INCLUDED
#define REGEXXER_CONFIGDATA_H_INCLUDED
#include <gconfmm.h>
#include <gdkmm/color.h>
#include <glibmm/ustring.h>
#include <gtkmm/toolbar.h>
......@@ -29,8 +30,11 @@
namespace Regexxer
{
struct ConfigData
// This class is a bit strange because it originally read/wrote a text configuration file,
// but now it is implemented with GConf instead (which is much simpler).
class ConfigData
{
public:
Glib::ustring textview_font;
Gdk::Color match_color;
Gdk::Color current_color;
......@@ -46,6 +50,12 @@ struct ConfigData
private:
void set_fallback_encoding_from_string(const Glib::ustring& value);
Glib::ustring get_string_from_fallback_encoding() const;
bool read_config_entry(const Glib::ustring& key, Glib::ustring& value);
void write_config_entry(const Glib::ustring& key, const Glib::ustring& value);
Glib::RefPtr<Gnome::Conf::Client> refClient_;
Glib::ustring gconf_dir_path_;
};
} // namespace Regexxer
......
......@@ -327,7 +327,6 @@ Gtk::Widget* Controller::create_action_area()
Button *const button_replace_all = new ImageLabelButton(Stock::CONVERT, "_All files", true);
box_replace->pack_start(*manage(button_replace_all));
#if REGEXXER_HAVE_GTKMM_22
button_prev_file ->get_accessible()->set_description("Go to the previous matching file");
button_prev ->get_accessible()->set_description("Go to previous match");
button_next ->get_accessible()->set_description("Go to next match");
......@@ -335,7 +334,6 @@ Gtk::Widget* Controller::create_action_area()
button_replace ->get_accessible()->set_description("Replace current match");
button_replace_file->get_accessible()->set_description("Replace all matches in the current file");
button_replace_all ->get_accessible()->set_description("Replace all matches in all files");
#endif
add_widget_button(next_file, *button_next_file);
add_widget_button(prev_file, *button_prev_file);
......
......@@ -77,6 +77,7 @@ void save_iochannel(const Glib::RefPtr<Glib::IOChannel>& output, const Glib::Ref
Glib::RefPtr<FileBuffer> load_try_encoding(const std::string& filename, const std::string& encoding)
{
//TODO: Use gnome-vfsmm: murrayc.
const Glib::RefPtr<Glib::IOChannel> channel = Glib::IOChannel::create_from_file(filename, "r");
channel->set_buffer_size(BUFSIZE);
......
......@@ -714,17 +714,7 @@ bool FileTree::prev_match_file(Gtk::TreeModel::iterator& iter,
void FileTree::expand_and_select(const Gtk::TreePath& path)
{
#if REGEXXER_HAVE_GTKMM_22
expand_to_path(path);
#else
std::stack<Gtk::TreePath> parents;
for(Gtk::TreePath parent (path); parent.up(); )
parents.push(parent);
for(; !parents.empty(); parents.pop())
expand_row(parents.top(), false);
#endif
get_selection()->select(path);
......
......@@ -36,11 +36,7 @@ ImageButton::ImageButton(const Gtk::StockID& stock_id, const Glib::ustring& name
{
add(*Gtk::manage(new Gtk::Image(stock_id, Gtk::ICON_SIZE_BUTTON)));
#if REGEXXER_HAVE_GTKMM_22
get_accessible()->set_name(name);
#else
(void) name; // suppress warning about unused parameter
#endif
}
ImageButton::~ImageButton()
......
......@@ -21,6 +21,8 @@
#include "mainwindow.h"
#include <glib.h>
#include <gconfmm.h>
#include <gtkmm/iconfactory.h>
#include <gtkmm/iconset.h>
#include <gtkmm/iconsource.h>
......@@ -133,11 +135,11 @@ int main(int argc, char** argv)
{
try
{
Gnome::Conf::init();
Gtk::Main main_instance (&argc, &argv);
#if REGEXXER_HAVE_GTKMM_22
Glib::set_application_name("regexxer");
#endif
regexxer_register_stock_items();
regexxer_set_window_icon();
......
......@@ -349,9 +349,7 @@ Gtk::Widget* MainWindow::create_left_pane()
scrollwin->add(*manage(filetree_));
scrollwin->set_policy(POLICY_AUTOMATIC, POLICY_ALWAYS);
#if REGEXXER_HAVE_GTKMM_22
entry_folder_->get_accessible()->set_name("Folder");
#endif
tooltips_.set_tip(*entry_folder_, "The directory to be searched");
tooltips_.set_tip(*entry_pattern_, "A filename pattern as used by the shell. "
......@@ -421,9 +419,7 @@ Gtk::Widget* MainWindow::create_right_pane()
entry_preview_->set_editable(false);
entry_preview_->unset_flags(CAN_FOCUS);
#if REGEXXER_HAVE_GTKMM_22
entry_preview_->get_accessible()->set_name("Preview");
#endif
tooltips_.set_tip(*entry_regex_, "A regular expression in Perl syntax");
tooltips_.set_tip(*entry_substitution_, "The new string to substitute. As in Perl, you can "
......
......@@ -28,12 +28,6 @@
#include <config.h>
#if !REGEXXER_HAVE_GTKMM_22
#include <gtk/gtkrc.h>
#include <gtk/gtkwidget.h>
#endif
namespace
{
......@@ -230,19 +224,9 @@ ColorSelectionButton::ColorLabel::ColorLabel()
const Glib::RefPtr<Gtk::RcStyle> rcstyle = get_modifier_style();
const Glib::ustring none = "<none>";
#if REGEXXER_HAVE_GTKMM_22
rcstyle->set_bg_pixmap_name(Gtk::STATE_NORMAL, none);
rcstyle->set_bg_pixmap_name(Gtk::STATE_ACTIVE, none);
rcstyle->set_bg_pixmap_name(Gtk::STATE_PRELIGHT, none);
#else
g_free(rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_NORMAL]);
g_free(rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_ACTIVE]);
g_free(rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_PRELIGHT]);
rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_NORMAL] = g_strdup(none.c_str());
rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_ACTIVE] = g_strdup(none.c_str());
rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_PRELIGHT] = g_strdup(none.c_str());
#endif
modify_style(rcstyle);
}
......@@ -276,15 +260,8 @@ bool ColorSelectionButton::ColorLabel::on_expose_event(GdkEventExpose* event)
Gtk::Widget& button = *get_parent();
#if REGEXXER_HAVE_GTKMM_22
button.get_style_property("focus_padding", focus_padding);
button.get_style_property("focus_line_width", focus_line_width);
#else
gtk_widget_style_get(button.gobj(),
"focus_padding", &focus_padding,
"focus_line_width", &focus_line_width,
static_cast<char*>(0));
#endif
const int margin = focus_padding + focus_line_width + 1;
const GdkRectangle alloc = get_allocation();
......
......@@ -257,9 +257,7 @@ StatusLine::StatusLine()
progressbar_->set_pulse_step(0.025);
#if REGEXXER_HAVE_GTKMM_22
stop_button_->get_accessible()->set_description("Cancels the running search");
#endif
show_all_children();
}
......
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