[pan2] fixed singletons, moved color init to pan.cc
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2] fixed singletons, moved color init to pan.cc
- Date: Sun, 15 Jul 2012 22:48:58 +0000 (UTC)
commit 87c6bda7ef009f530456e87a7d10f14ab96ebf58
Author: Heinrich MÃller <henmull src gnome org>
Date: Mon Jul 16 00:31:33 2012 +0200
fixed singletons, moved color init to pan.cc
pan/general/log.cc | 7 -----
pan/general/log.h | 6 +---
pan/general/singleton-template.h | 5 +++
pan/gui/pan-colors.h | 7 -----
pan/gui/pan.cc | 55 ++++++++++++++++++++++++++++++++++++++
pan/gui/prefs.cc | 46 +------------------------------
6 files changed, 64 insertions(+), 62 deletions(-)
---
diff --git a/pan/general/log.cc b/pan/general/log.cc
index a0f5840..aba4177 100644
--- a/pan/general/log.cc
+++ b/pan/general/log.cc
@@ -35,13 +35,6 @@ Log :: clear ()
fire_cleared ();
}
-Log&
-Log :: get()
-{
- static Log * log = new Log;
- return *log;
-}
-
/***
***/
diff --git a/pan/general/log.h b/pan/general/log.h
index fb5edd7..2def9a6 100644
--- a/pan/general/log.h
+++ b/pan/general/log.h
@@ -24,13 +24,14 @@
#include <set>
#include <string>
#include <deque>
+#include <pan/general/singleton-template.h>
namespace pan
{
/**
* Logs information and error messages that that the user should see.
*/
- class Log
+ class Log : public PanSingleton< Log >
{
public:
enum Severity {
@@ -74,7 +75,6 @@ namespace pan
void clear ();
void add_listener (Listener* l) { _listeners.insert(l); }
void remove_listener (Listener* l) { _listeners.erase(l); }
- static Log& get();
private:
typedef std::set<Listener*> listeners_t;
@@ -82,8 +82,6 @@ namespace pan
void fire_entry_added (const Entry& e);
void fire_cleared ();
entries_t _entries;
- Log () { } // singleton
- ~Log () { } // singleton
public: // convenience functions
static void add_info (const char * s) { Log::get().add (Log::PAN_SEVERITY_INFO, s); }
diff --git a/pan/general/singleton-template.h b/pan/general/singleton-template.h
index 022d5ce..a3c9f72 100644
--- a/pan/general/singleton-template.h
+++ b/pan/general/singleton-template.h
@@ -17,6 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifndef _PAN_SINGLETON_H_
+#define _PAN_SINGLETON_H_
template <class T_DERIVED>
class PanSingleton
@@ -35,3 +37,6 @@ class PanSingleton
PanSingleton( const PanSingleton& ) ;
PanSingleton& operator=( const PanSingleton& ) {return *this;}
} ;
+
+
+#endif
diff --git a/pan/gui/pan-colors.h b/pan/gui/pan-colors.h
index 64536b0..ab5e407 100644
--- a/pan/gui/pan-colors.h
+++ b/pan/gui/pan-colors.h
@@ -32,13 +32,6 @@ class PanColors : public PanSingleton< PanColors >
GdkColor def_fg_col;
GdkColor def_bg_col;
- PanColors(std::string& fg, std::string& bg, GdkColor& fg_col, GdkColor& bg_col) :
- def_fg (fg), def_bg(bg), def_fg_col(fg_col), def_bg_col(bg_col) // {}
- {
- if (!def_fg.empty()) std::cerr<<def_fg<<" "<<def_bg<<"\n";
- }
- PanColors() {}
- virtual ~PanColors() {}
};
#endif
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index e957882..5eaea8c 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -808,6 +808,58 @@ namespace
GUI * gui_ptr (0);
}
+namespace
+{
+ void init_colors()
+ {
+
+ GtkWidget* r = gtk_label_new("bla");
+
+ GdkColor def_fg, def_bg;
+ std::string fg_col, bg_col;
+
+ // init colors of PanColors
+#if GTK_CHECK_VERSION(3,0,0)
+ GdkRGBA fg_color, bg_color;
+ GtkStyleContext* ctx = gtk_widget_get_style_context(r);
+ if(!ctx || !gtk_style_context_lookup_color(ctx, "color", &fg_color))
+ gdk_color_parse("black", &def_fg);
+ else
+ {
+ def_fg.red = fg_color.red;
+ def_fg.green = fg_color.red;
+ def_fg.blue = fg_color.blue;
+ }
+ if(!ctx || !gtk_style_context_lookup_color(ctx, "background-color", &bg_color))
+ gdk_color_parse("white", &def_bg);
+ else
+ {
+ def_bg.red = bg_color.red;
+ def_bg.green = bg_color.red;
+ def_bg.blue = bg_color.blue;
+ }
+#else
+ GtkStyle *style = gtk_rc_get_style(r);
+ if(!style || !gtk_style_lookup_color(style, "text_color", &def_fg))
+ gdk_color_parse("black", &def_fg);
+ if(!style || !gtk_style_lookup_color(style, "bg_color", &def_bg))
+ gdk_color_parse("white", &def_bg);
+
+#endif
+
+ fg_col = GroupPrefs::color_to_string(def_fg);
+ bg_col = GroupPrefs::color_to_string(def_bg);
+
+ gtk_widget_destroy (r);
+
+ PanColors& c (PanColors::get());
+ c.def_fg = fg_col;
+ c.def_bg = bg_col;
+ c.def_fg_col = def_fg;
+ c.def_bg_col = def_bg;
+ }
+
+}
int
main (int argc, char *argv[])
@@ -896,6 +948,9 @@ main (int argc, char *argv[])
GroupPrefs group_prefs (filename);
g_free (filename);
+ //init color scheme
+ init_colors();
+
// instantiate the backend...
const int cache_megs = prefs.get_int ("cache-size-megs", 10);
DataImpl data (prefs.get_string("cache-file-extension","msg"), prefs, false, cache_megs);
diff --git a/pan/gui/prefs.cc b/pan/gui/prefs.cc
index 87b2518..174f76b 100644
--- a/pan/gui/prefs.cc
+++ b/pan/gui/prefs.cc
@@ -37,52 +37,10 @@ using namespace pan;
Prefs :: Prefs() :
_rules_changed(false)
-{
-
- GtkWidget* root = gtk_entry_new();
-
- GdkColor def_fg, def_bg;
- std::string fg_col, bg_col;
-
-#if GTK_CHECK_VERSION(3,0,0)
- GdkRGBA fg_color, bg_color;
- GtkStyleContext* ctx = gtk_widget_get_style_context(root);
- if(!ctx || !gtk_style_context_lookup_color(ctx, "color", &fg_color))
- gdk_color_parse("black", &def_fg);
- else
- {
- def_fg.red = fg_color.red;
- def_fg.green = fg_color.red;
- def_fg.blue = fg_color.blue;
- }
- if(!ctx || !gtk_style_context_lookup_color(ctx, "background-color", &bg_color))
- gdk_color_parse("white", &def_bg);
- else
- {
- def_bg.red = bg_color.red;
- def_bg.green = bg_color.red;
- def_bg.blue = bg_color.blue;
- }
-#else
- GtkStyle *style = gtk_rc_get_style(root);
- if(!style || !gtk_style_lookup_color(style, "text_color", &def_fg))
- gdk_color_parse("black", &def_fg);
- if(!style || !gtk_style_lookup_color(style, "bg_color", &def_bg))
- gdk_color_parse("white", &def_bg);
-
-#endif
-
- fg_col = GroupPrefs::color_to_string(def_fg);
- bg_col = GroupPrefs::color_to_string(def_bg);
-
- gtk_widget_destroy (root);
-
-}
+{}
Prefs :: ~Prefs()
-{
-// delete _pan_colors; // TODO make pancolors a singleton?
-}
+{}
// called for open tags <foo bar='baz'>
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]