verbose setting on theme warnings

This commit is contained in:
fluxgen 2003-08-28 23:06:27 +00:00
parent 95021a60ab
commit ec235918df
2 changed files with 44 additions and 40 deletions

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: Theme.cc,v 1.16 2003/08/28 15:46:13 fluxgen Exp $
// $Id: Theme.cc,v 1.17 2003/08/28 23:06:27 fluxgen Exp $
#include "Theme.hh"
@ -78,16 +78,18 @@ void ThemeItem<FbTk::Font>::setDefaultValue() {
template <>
void ThemeItem<FbTk::Font>::setFromString(const char *str) {
if (m_value.load(str) == false) {
cerr<<"FbTk::Theme: Error loading font "<<
((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<<
if (FbTk::ThemeManager::instance().verbose()) {
cerr<<"FbTk::Theme: Error loading font "<<
((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<<
(m_value.isAntialias() ? "antialias" : "")<<
(m_value.utf8() ? " utf8" : "")<<
(m_value.isAntialias() ? "antialias" : "")<<
(m_value.utf8() ? " utf8" : "")<<
((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<<
"for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl;
((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<<
"for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl;
cerr<<"FbTk::Theme: Setting default value"<<endl;
cerr<<"FbTk::Theme: Setting default value"<<endl;
}
setDefaultValue();
}
@ -131,7 +133,8 @@ void ThemeItem<FbTk::Texture>::load() {
std::auto_ptr<PixmapWithMask> pm(Image::load(pixmap_name, m_tm.screenNum()));
if (pm.get() == 0) {
cerr<<"Resource("<<name()+".pixmap"<<"): Failed to load image: "<<pixmap_name<<endl;
if (FbTk::ThemeManager::instance().verbose())
cerr<<"Resource("<<name()+".pixmap"<<"): Failed to load image: "<<pixmap_name<<endl;
m_value.pixmap() = 0;
} else
m_value.pixmap() = pm->pixmap().release();
@ -175,7 +178,8 @@ void ThemeItem<FbTk::Color>::setDefaultValue() {
template <>
void ThemeItem<FbTk::Color>::setFromString(const char *str) {
if (!m_value.setFromString(str, m_tm.screenNum())) {
cerr<<"FbTk::Theme: Error loading color value for \""<<name()<<"\" or \""<<altName()<<"\"."<<endl;
if (FbTk::ThemeManager::instance().verbose())
cerr<<"FbTk::Theme: Error loading color value for \""<<name()<<"\" or \""<<altName()<<"\"."<<endl;
setDefaultValue();
}
}
@ -185,19 +189,11 @@ template <>
void ThemeItem<FbTk::Color>::load() { }
Theme::Theme(int screen_num):m_screen_num(screen_num) {
if (!ThemeManager::instance().registerTheme(*this)) {
// should it be fatal or not?
cerr<<"FbTk::Theme Warning: Failed to register Theme"<<endl;
}
ThemeManager::instance().registerTheme(*this);
}
Theme::~Theme() {
if (!ThemeManager::instance().unregisterTheme(*this)) {
#ifdef DEBUG
cerr<<"Warning: Theme not registered!"<<endl;
#endif // DEBUG
}
ThemeManager::instance().unregisterTheme(*this);
}
ThemeManager &ThemeManager::instance() {
@ -206,7 +202,8 @@ ThemeManager &ThemeManager::instance() {
}
ThemeManager::ThemeManager():
m_max_screens(ScreenCount(FbTk::App::instance()->display())) {
m_max_screens(ScreenCount(FbTk::App::instance()->display())),
m_verbose(false) {
}
@ -255,8 +252,8 @@ void ThemeManager::loadTheme(Theme &tm) {
if (!loadItem(*resource)) {
// try fallback resource in theme
if (!tm.fallback(*resource)) {
cerr<<"Failed to read theme item: "<<resource->name()<<endl;
cerr<<"Setting default value"<<endl;
if (verbose())
cerr<<"Failed to read theme item: "<<resource->name()<<endl;
resource->setDefaultValue();
}
}
@ -295,22 +292,22 @@ std::string ThemeManager::resourceValue(const std::string &name, const std::stri
}
/*
void ThemeManager::listItems() {
ThemeList::iterator it = m_themelist.begin();
ThemeList::iterator it_end = m_themelist.end();
for (; it != it_end; ++it) {
std::list<ThemeItem_base *>::iterator item = (*it)->itemList().begin();
std::list<ThemeItem_base *>::iterator item_end = (*it)->itemList().end();
for (; item != item_end; ++item) {
cerr<<(*item)->name()<<":"<<endl;
if (typeid(**item) == typeid(ThemeItem<Texture>)) {
cerr<<(*item)->name()<<".pixmap:"<<endl;
cerr<<(*item)->name()<<".color:"<<endl;
cerr<<(*item)->name()<<".colorTo:"<<endl;
}
}
}
void ThemeManager::listItems() {
ThemeList::iterator it = m_themelist.begin();
ThemeList::iterator it_end = m_themelist.end();
for (; it != it_end; ++it) {
std::list<ThemeItem_base *>::iterator item = (*it)->itemList().begin();
std::list<ThemeItem_base *>::iterator item_end = (*it)->itemList().end();
for (; item != item_end; ++item) {
cerr<<(*item)->name()<<":"<<endl;
if (typeid(**item) == typeid(ThemeItem<Texture>)) {
cerr<<(*item)->name()<<".pixmap:"<<endl;
cerr<<(*item)->name()<<".color:"<<endl;
cerr<<(*item)->name()<<".colorTo:"<<endl;
}
}
}
}
}
*/
}; // end namespace FbTk

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: Theme.hh,v 1.8 2003/08/28 14:19:27 fluxgen Exp $
// $Id: Theme.hh,v 1.9 2003/08/28 23:05:29 fluxgen Exp $
/**
@file holds ThemeItem<T>, Theme and ThemeManager which is the base for any theme
@ -106,6 +106,8 @@ public:
void remove(ThemeItem<T> &item);
virtual bool fallback(ThemeItem_base &base) { return false; }
FbTk::Subject &reconfigSig() { return m_reconfig_sig; }
private:
const int m_screen_num;
typedef std::list<ThemeItem_base *> ItemList;
@ -121,11 +123,15 @@ private:
class ThemeManager {
public:
static ThemeManager &instance();
bool load(const std::string &filename);
std::string resourceValue(const std::string &name, const std::string &altname);
void loadTheme(Theme &tm);
bool loadItem(ThemeItem_base &resource);
bool loadItem(ThemeItem_base &resource, const std::string &name, const std::string &altname);
bool verbose() const { return m_verbose; }
void setVerbose(bool value) { m_verbose = value; }
private:
ThemeManager();
~ThemeManager() { }
@ -141,6 +147,7 @@ private:
ThemeList m_themelist;
const int m_max_screens;
XrmDatabaseHelper m_database;
bool m_verbose;
};