Back to index

easystroke  0.5.5.1
prefdb.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008-2009, Thomas Jaeger <ThJaeger@gmail.com>
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00011  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
00013  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00014  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 #ifndef __PREFDB_H__
00017 #define __PREFDB_H__
00018 #include <string>
00019 #include <set>
00020 #include <map>
00021 #include <boost/serialization/access.hpp>
00022 #include <boost/serialization/version.hpp>
00023 #include <boost/serialization/split_member.hpp>
00024 #include <gdkmm/color.h>
00025 
00026 #include "var.h"
00027 
00028 enum TraceType { TraceDefault, TraceShape, TraceNone, TraceAnnotate, TraceFire, TraceWater };
00029 enum TimeoutType { TimeoutOff, TimeoutDefault, TimeoutMedium, TimeoutAggressive, TimeoutFlick, TimeoutCustom, TimeoutConservative };
00030 
00031 class ButtonInfo {
00032        friend class boost::serialization::access;
00033        template<class Archive> void serialize(Archive & ar, const unsigned int version) {
00034               ar & button;
00035               ar & state;
00036               if (version == 1) {
00037                      int special;
00038                      ar & special;
00039                      return;
00040               }
00041               if (version < 3)
00042                      return;
00043               ar & instant;
00044               if (version < 4)
00045                      return;
00046               ar & click_hold;
00047        }
00048 public:
00049        guint button;
00050        guint state;
00051        bool instant;
00052        bool click_hold;
00053        bool operator<(const ButtonInfo &bi) const { return button < bi.button; }
00054        bool operator==(const ButtonInfo &bi) const {
00055               return button == bi.button && state == bi.state && !instant == !bi.instant && !click_hold == !bi.click_hold;
00056        }
00057        void press();
00058        Glib::ustring get_button_text() const;
00059        bool overlap(const ButtonInfo &bi) const;
00060        ButtonInfo(guint button_) : button(button_), state(0), instant(false), click_hold(false) {}
00061        ButtonInfo() : button(0), state(0), instant(false), click_hold(false) {}
00062 };
00063 BOOST_CLASS_VERSION(ButtonInfo, 4)
00064 
00065 typedef boost::shared_ptr<ButtonInfo> RButtonInfo;
00066 
00067 struct RGBA {
00068        Gdk::Color color;
00069        guint16 alpha;
00070        RGBA() : alpha(65535) {}
00071        RGBA(Gdk::Color c) : color(c), alpha(65535) {}
00072        template<class Archive> void save(Archive &ar, unsigned int version) const {
00073               gushort r, g, b;
00074               r = color.get_red();
00075               g = color.get_green();
00076               b = color.get_blue();
00077               ar & r;
00078               ar & g;
00079               ar & b;
00080               ar & alpha;
00081        }
00082        template<class Archive> void load(Archive &ar, unsigned int version) {
00083               gushort r, g, b;
00084               ar & r;
00085               ar & g;
00086               ar & b;
00087               ar & alpha;
00088               color.set_red(r);
00089               color.set_green(g);
00090               color.set_blue(b);
00091        }
00092        bool operator==(const RGBA rgba) {
00093               return color == rgba.color && alpha == rgba.alpha;
00094        }
00095        BOOST_SERIALIZATION_SPLIT_MEMBER()
00096 };
00097 
00098 extern const ButtonInfo default_button;
00099 extern const int default_pressure_threshold;
00100 
00101 class PrefDB : public TimeoutWatcher {
00102        friend class boost::serialization::access;
00103        bool good_state;
00104        template<class Archive> void serialize(Archive & ar, const unsigned int version);
00105 
00106        template <class T> struct PrefSource : public Source<T> {
00107               PrefSource();
00108               PrefSource(T x_);
00109        };
00110 public:
00111        PrefDB();
00112 
00113        PrefSource<std::map<std::string, RButtonInfo> > exceptions;
00114        PrefSource<ButtonInfo> button;
00115        PrefSource<TraceType> trace;
00116        PrefSource<bool> advanced_ignore;
00117        PrefSource<bool> pressure_abort;
00118        PrefSource<int> pressure_threshold;
00119        PrefSource<bool> proximity;
00120        PrefSource<bool> feedback;
00121        PrefSource<bool> left_handed;
00122        PrefSource<int> init_timeout;
00123        PrefSource<int> final_timeout;
00124        PrefSource<TimeoutType> timeout_profile;
00125        PrefSource<bool> timeout_gestures;
00126        PrefSource<bool> tray_icon;
00127        PrefSource<std::set<std::string> > excluded_devices;
00128        PrefSource<RGBA> color;
00129        PrefSource<int> trace_width;
00130        PrefSource<std::vector<ButtonInfo> > extra_buttons;
00131        PrefSource<bool> advanced_popups;
00132        PrefSource<bool> scroll_invert;
00133        PrefSource<double> scroll_speed;
00134        PrefSource<bool> tray_feedback;
00135        PrefSource<bool> show_osd;
00136        PrefSource<bool> move_back;
00137        PrefSource<std::map<std::string, TimeoutType> > device_timeout;
00138 
00139        void init();
00140        virtual void timeout();
00141 };
00142 
00143 BOOST_CLASS_VERSION(PrefDB, 17)
00144 
00145 extern PrefDB prefs;
00146 
00147 template <class T> PrefDB::PrefSource<T>::PrefSource() : Source<T>() { prefs.watch(*this); }
00148 template <class T> PrefDB::PrefSource<T>::PrefSource(T x_) : Source<T>(x_) { prefs.watch(*this); }
00149 #endif