From 2baeff01037773180803cd2c7cb65a6afef6159f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Aug 2011 23:28:50 +0300 Subject: Add missing files. --- src/gui/setup_perfomance.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/gui/setup_perfomance.cpp (limited to 'src/gui/setup_perfomance.cpp') diff --git a/src/gui/setup_perfomance.cpp b/src/gui/setup_perfomance.cpp new file mode 100644 index 000000000..0d5458cc4 --- /dev/null +++ b/src/gui/setup_perfomance.cpp @@ -0,0 +1,95 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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 + * any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/setup_perfomance.h" + +#include "gui/chatwindow.h" +#include "gui/editdialog.h" +#include "gui/setupitem.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/chattab.h" +#include "gui/widgets/checkbox.h" +#include "gui/widgets/inttextfield.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/scrollarea.h" + +#include "configuration.h" +#include "localplayer.h" +#include "log.h" + +#include "utils/gettext.h" + +#include "debug.h" + +Setup_Perfomance::Setup_Perfomance() +{ + setName(_("Perfomance")); + + // Do the layout + LayoutHelper h(this); + ContainerPlacer place = h.getPlacer(0, 0); + place(0, 0, mScroll, 10, 10); + + new SetupItemLabel(_("Better perfomance (enable for better perfomance)"), "", this); + + new SetupItemCheckBox(_("Auto adjust perfomance"), "", + "adjustPerfomance", this, "adjustPerfomanceEvent"); + + new SetupItemCheckBox(_("Show beings transparency"), "", + "beingopacity", this, "beingopacityEvent"); + + new SetupItemCheckBox(_("Hw acceleration"), "", + "hwaccel", this, "hwaccelEvent"); + + new SetupItemCheckBox(_("Enable opacity cache (Software, can " + "use many memory)"), "", "alphaCache", this, "alphaCacheEvent"); + + new SetupItemCheckBox(_("Enable map reduce (Software)"), "", + "enableMapReduce", this, "enableMapReduceEvent"); + + new SetupItemLabel(_("Better quality (disable for better perfomance)"), "", this); + + new SetupItemCheckBox(_("Enable alpha channel fix (Software, can be very slow)"), + "Can slow down drawing", "enableAlphaFix", + this, "enableAlphaFixEvent"); + + new SetupItemCheckBox(_("Enable reorder sprites."), "", + "enableReorderSprites", this, "enableReorderSpritesEvent"); + + new SetupItemLabel(_("Small memory (enable for lower memory usage)"), "", this); + + new SetupItemCheckBox(_("Disable advanced beings caching (Software)"), "", + "disableAdvBeingCaching", this, "disableAdvBeingCachingEvent"); + + new SetupItemCheckBox(_("Disable beings caching (Software)"), "", + "disableBeingCaching", this, "disableBeingCachingEvent"); + + setDimension(gcn::Rectangle(0, 0, 550, 350)); +} + +void Setup_Perfomance::apply() +{ + SetupTabScroll::apply(); +} -- cgit v1.2.3-70-g09d2 From 7455b856a59be26725f9bd1285f256dbddea5335 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Aug 2011 23:44:12 +0300 Subject: Fix code style. --- src/gui/setup_perfomance.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/gui/setup_perfomance.cpp') diff --git a/src/gui/setup_perfomance.cpp b/src/gui/setup_perfomance.cpp index 0d5458cc4..eaadc7c3a 100644 --- a/src/gui/setup_perfomance.cpp +++ b/src/gui/setup_perfomance.cpp @@ -52,7 +52,8 @@ Setup_Perfomance::Setup_Perfomance() ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, mScroll, 10, 10); - new SetupItemLabel(_("Better perfomance (enable for better perfomance)"), "", this); + new SetupItemLabel(_("Better perfomance (enable for better perfomance)"), + "", this); new SetupItemCheckBox(_("Auto adjust perfomance"), "", "adjustPerfomance", this, "adjustPerfomanceEvent"); @@ -69,16 +70,18 @@ Setup_Perfomance::Setup_Perfomance() new SetupItemCheckBox(_("Enable map reduce (Software)"), "", "enableMapReduce", this, "enableMapReduceEvent"); - new SetupItemLabel(_("Better quality (disable for better perfomance)"), "", this); + new SetupItemLabel(_("Better quality (disable for better perfomance)"), + "", this); - new SetupItemCheckBox(_("Enable alpha channel fix (Software, can be very slow)"), - "Can slow down drawing", "enableAlphaFix", + new SetupItemCheckBox(_("Enable alpha channel fix (Software, can " + "be very slow)"), "Can slow down drawing", "enableAlphaFix", this, "enableAlphaFixEvent"); new SetupItemCheckBox(_("Enable reorder sprites."), "", "enableReorderSprites", this, "enableReorderSpritesEvent"); - new SetupItemLabel(_("Small memory (enable for lower memory usage)"), "", this); + new SetupItemLabel(_("Small memory (enable for lower memory usage)"), + "", this); new SetupItemCheckBox(_("Disable advanced beings caching (Software)"), "", "disableAdvBeingCaching", this, "disableAdvBeingCachingEvent"); -- cgit v1.2.3-70-g09d2 From 2d45a2ca5480ae0fdc03a807787f622444830d44 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Aug 2011 03:47:28 +0300 Subject: Rename file names log and chatlog to correct logger and chatlogger. --- manaplus.cbp | 8 +- src/CMakeLists.txt | 8 +- src/Makefile.am | 8 +- src/actorsprite.cpp | 2 +- src/actorspritemanager.cpp | 2 +- src/animatedsprite.cpp | 2 +- src/being.cpp | 2 +- src/chatlog.cpp | 204 --------------------------- src/chatlog.h | 79 ----------- src/chatlogger.cpp | 204 +++++++++++++++++++++++++++ src/chatlogger.h | 79 +++++++++++ src/client.cpp | 2 +- src/commandhandler.cpp | 2 +- src/configuration.cpp | 2 +- src/effectmanager.cpp | 2 +- src/filefilter.txt | 2 + src/game.cpp | 2 +- src/graphics.cpp | 2 +- src/gui/changeemaildialog.cpp | 2 +- src/gui/changepassworddialog.cpp | 2 +- src/gui/charselectdialog.cpp | 2 +- src/gui/connectiondialog.cpp | 2 +- src/gui/didyouknowwindow.cpp | 2 +- src/gui/emotepopup.cpp | 2 +- src/gui/gui.cpp | 2 +- src/gui/helpwindow.cpp | 2 +- src/gui/minimap.cpp | 2 +- src/gui/outfitwindow.cpp | 2 +- src/gui/palette.h | 2 +- src/gui/popupmenu.cpp | 2 +- src/gui/register.cpp | 2 +- src/gui/sdlfont.cpp | 2 +- src/gui/serverdialog.cpp | 4 +- src/gui/setup_audio.cpp | 2 +- src/gui/setup_chat.cpp | 2 +- src/gui/setup_other.cpp | 2 +- src/gui/setup_perfomance.cpp | 2 +- src/gui/setup_players.cpp | 2 +- src/gui/setup_relations.cpp | 2 +- src/gui/setup_theme.cpp | 2 +- src/gui/setup_video.cpp | 2 +- src/gui/setupitem.cpp | 2 +- src/gui/skilldialog.cpp | 2 +- src/gui/socialwindow.cpp | 2 +- src/gui/specialswindow.cpp | 2 +- src/gui/theme.cpp | 2 +- src/gui/unregisterdialog.cpp | 2 +- src/gui/updatewindow.cpp | 2 +- src/gui/userpalette.cpp | 2 +- src/gui/widgets/battletab.cpp | 4 +- src/gui/widgets/browserbox.cpp | 2 +- src/gui/widgets/button.cpp | 2 +- src/gui/widgets/chattab.cpp | 4 +- src/gui/widgets/desktop.cpp | 2 +- src/gui/widgets/emoteshortcutcontainer.cpp | 2 +- src/gui/widgets/inventoryfilter.cpp | 2 +- src/gui/widgets/itemcontainer.cpp | 2 +- src/gui/widgets/layout.cpp | 2 +- src/gui/widgets/popup.cpp | 2 +- src/gui/widgets/scrollarea.cpp | 2 +- src/gui/widgets/spellshortcutcontainer.cpp | 2 +- src/gui/widgets/tab.cpp | 2 +- src/gui/widgets/tabbedarea.cpp | 2 +- src/gui/widgets/textfield.cpp | 2 +- src/gui/widgets/tradetab.cpp | 4 +- src/gui/widgets/whispertab.cpp | 4 +- src/gui/widgets/window.cpp | 2 +- src/inventory.cpp | 2 +- src/joystick.cpp | 2 +- src/keyboardconfig.cpp | 2 +- src/localplayer.cpp | 2 +- src/log.cpp | 217 ----------------------------- src/log.h | 110 --------------- src/logger.cpp | 217 +++++++++++++++++++++++++++++ src/logger.h | 110 +++++++++++++++ src/main.cpp | 2 +- src/map.cpp | 2 +- src/mumblemanager.cpp | 2 +- src/net/download.cpp | 2 +- src/net/ea/beinghandler.cpp | 2 +- src/net/ea/charserverhandler.cpp | 2 +- src/net/ea/chathandler.cpp | 2 +- src/net/ea/gamehandler.cpp | 2 +- src/net/ea/gui/guildtab.cpp | 2 +- src/net/ea/gui/partytab.cpp | 2 +- src/net/ea/guildhandler.cpp | 2 +- src/net/ea/inventoryhandler.cpp | 2 +- src/net/ea/inventoryhandler.h | 2 +- src/net/ea/loginhandler.cpp | 2 +- src/net/ea/partyhandler.cpp | 2 +- src/net/ea/playerhandler.cpp | 2 +- src/net/ea/specialhandler.cpp | 2 +- src/net/ea/tradehandler.cpp | 2 +- src/net/manaserv/attributes.cpp | 2 +- src/net/manaserv/beinghandler.cpp | 2 +- src/net/manaserv/charhandler.cpp | 2 +- src/net/manaserv/connection.cpp | 2 +- src/net/manaserv/effecthandler.cpp | 2 +- src/net/manaserv/guildhandler.cpp | 2 +- src/net/manaserv/inventoryhandler.cpp | 2 +- src/net/manaserv/itemhandler.cpp | 2 +- src/net/manaserv/loginhandler.cpp | 2 +- src/net/manaserv/network.cpp | 2 +- src/net/manaserv/partyhandler.cpp | 2 +- src/net/manaserv/playerhandler.cpp | 2 +- src/net/messagein.cpp | 2 +- src/net/messageout.cpp | 2 +- src/net/tmwa/adminhandler.cpp | 2 +- src/net/tmwa/beinghandler.cpp | 2 +- src/net/tmwa/charserverhandler.cpp | 2 +- src/net/tmwa/chathandler.cpp | 2 +- src/net/tmwa/gamehandler.cpp | 2 +- src/net/tmwa/generalhandler.cpp | 2 +- src/net/tmwa/gui/guildtab.cpp | 2 +- src/net/tmwa/gui/partytab.cpp | 2 +- src/net/tmwa/guildhandler.cpp | 2 +- src/net/tmwa/inventoryhandler.cpp | 2 +- src/net/tmwa/inventoryhandler.h | 2 +- src/net/tmwa/loginhandler.cpp | 2 +- src/net/tmwa/messagein.cpp | 2 +- src/net/tmwa/messageout.cpp | 2 +- src/net/tmwa/network.cpp | 2 +- src/net/tmwa/partyhandler.cpp | 2 +- src/net/tmwa/playerhandler.cpp | 2 +- src/net/tmwa/specialhandler.cpp | 2 +- src/net/tmwa/tradehandler.cpp | 2 +- src/opengl1graphics.cpp | 2 +- src/openglgraphics.cpp | 2 +- src/particle.cpp | 2 +- src/particleemitter.cpp | 2 +- src/playerinfo.cpp | 2 +- src/properties.h | 2 +- src/resources/animation.cpp | 2 +- src/resources/beinginfo.cpp | 2 +- src/resources/colordb.cpp | 2 +- src/resources/dye.cpp | 2 +- src/resources/emotedb.cpp | 2 +- src/resources/image.cpp | 2 +- src/resources/imageset.cpp | 2 +- src/resources/imagewriter.cpp | 2 +- src/resources/itemdb.cpp | 2 +- src/resources/mapdb.cpp | 2 +- src/resources/mapreader.cpp | 2 +- src/resources/monsterdb.cpp | 2 +- src/resources/music.cpp | 2 +- src/resources/npcdb.cpp | 2 +- src/resources/resource.cpp | 2 +- src/resources/resourcemanager.cpp | 2 +- src/resources/soundeffect.cpp | 2 +- src/resources/specialdb.cpp | 2 +- src/resources/spritedef.cpp | 2 +- src/resources/wallpaper.cpp | 2 +- src/simpleanimation.cpp | 2 +- src/sound.cpp | 2 +- src/spellmanager.cpp | 2 +- src/spellshortcut.h | 2 +- src/statuseffect.cpp | 2 +- src/units.cpp | 2 +- src/utils/mutex.h | 2 +- src/utils/xml.cpp | 2 +- 160 files changed, 777 insertions(+), 775 deletions(-) delete mode 100644 src/chatlog.cpp delete mode 100644 src/chatlog.h create mode 100644 src/chatlogger.cpp create mode 100644 src/chatlogger.h delete mode 100644 src/log.cpp delete mode 100644 src/log.h create mode 100644 src/logger.cpp create mode 100644 src/logger.h (limited to 'src/gui/setup_perfomance.cpp') diff --git a/manaplus.cbp b/manaplus.cbp index e31f4fee9..020e65357 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -117,8 +117,8 @@ - - + + @@ -410,8 +410,8 @@ - - + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a9d09f97..a48c4f28a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -472,8 +472,8 @@ SET(SRCS being.h spellmanager.cpp spellmanager.h - chatlog.cpp - chatlog.h + chatlogger.cpp + chatlogger.h client.cpp client.h channel.cpp @@ -532,8 +532,8 @@ SET(SRCS listener.h localplayer.cpp localplayer.h - log.cpp - log.h + logger.cpp + logger.h main.cpp main.h map.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 76010cb73..c1287e06c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -479,8 +479,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ being.h \ spellmanager.cpp \ spellmanager.h \ - chatlog.cpp \ - chatlog.h \ + chatlogger.cpp \ + chatlogger.h \ client.cpp \ client.h \ channel.cpp \ @@ -539,8 +539,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ listener.h \ localplayer.cpp \ localplayer.h \ - log.cpp \ - log.h \ + logger.cpp \ + logger.h \ main.cpp \ main.h \ map.cpp\ diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 5f71c6bbb..848e84e0f 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -26,7 +26,7 @@ #include "effectmanager.h" #include "imagesprite.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "simpleanimation.h" #include "sound.h" #include "statuseffect.h" diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 61534c340..e8244bc30 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -24,7 +24,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "playerinfo.h" #include "playerrelations.h" diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 41aabf60c..7414c94bc 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -23,7 +23,7 @@ #include "animatedsprite.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "resources/action.h" #include "resources/animation.h" diff --git a/src/being.cpp b/src/being.cpp index b6f06a75a..7c2a6bf40 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -31,7 +31,7 @@ #include "guild.h" #include "item.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "particle.h" #include "party.h" diff --git a/src/chatlog.cpp b/src/chatlog.cpp deleted file mode 100644 index 99fe317c6..000000000 --- a/src/chatlog.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2009-2010 Andrei Karas - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program 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 - * any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "chatlog.h" - -#include -#include -#include - -#include -#include -#include - -#ifdef WIN32 -#include -#elif defined __APPLE__ -#include -#endif - -#include "log.h" -#include "configuration.h" - -#include "utils/stringutils.h" - -#include "debug.h" - -ChatLogger::ChatLogger() -{ -} - -ChatLogger::~ChatLogger() -{ - if (mLogFile.is_open()) - mLogFile.close(); -} - -void ChatLogger::setLogFile(const std::string &logFilename) -{ - if (mLogFile.is_open()) - mLogFile.close(); - - mLogFile.open(logFilename.c_str(), std::ios_base::app); - - if (!mLogFile.is_open()) - { - std::cout << "Warning: error while opening " << logFilename << - " for writing.\n"; - } -} - -void ChatLogger::setLogDir(const std::string &logDir) -{ - mLogDir = logDir; - - if (mLogFile.is_open()) - mLogFile.close(); - - DIR *dir = opendir(mLogDir.c_str()); - if (!dir) - makeDir(mLogDir); - else - closedir(dir); -} - -void ChatLogger::log(std::string str) -{ - std::string dateStr = getDateString(); - if (!mLogFile.is_open() || dateStr != mLogDate) - { - mLogDate = dateStr; - setLogFile(strprintf("%s/%s/#General_%s.log", mLogDir.c_str(), - mServerName.c_str(), dateStr.c_str())); - } - - str = removeColors(str); - writeTo(mLogFile, str); -} - -void ChatLogger::log(std::string name, std::string str) -{ - std::ofstream logFile; - logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), - mServerName.c_str(), secureName(name).c_str(), - getDateString().c_str()).c_str(), std::ios_base::app); - - if (!logFile.is_open()) - return; - - str = removeColors(str); - writeTo(logFile, str); - - if (logFile.is_open()) - logFile.close(); -} - -std::string ChatLogger::getDateString() const -{ - std::string date; - - time_t rawtime; - struct tm *timeinfo; - char buffer [81]; - - time (&rawtime); - timeinfo = localtime(&rawtime); - - strftime(buffer, 79, "%y-%m-%d", timeinfo); - date = buffer; - return date; -} - -std::string ChatLogger::secureName(std::string &name) const -{ - for (unsigned int f = 0; f < name.length(); f ++) - { - if (name[f] < '0' && name[f] > '9' && name[f] < 'a' && name[f] > 'z' - && name[f] < 'A' && name[f] > 'Z' - && name[f] != '-' && name[f] != '+' && name[f] != '=' - && name[f] != '.' && name[f] != ',' && name[f] != ')' - && name[f] != '(' && name[f] != '[' && name[f] != ']') - { - name[f] = '_'; - } - } - return name; -} - -void ChatLogger::writeTo(std::ofstream &file, const std::string &str) const -{ - file << str << std::endl; -} - -void ChatLogger::setServerName(const std::string &serverName) -{ - mServerName = serverName; - if (mServerName == "") - mServerName = config.getStringValue("MostUsedServerName0"); - - if (mLogFile.is_open()) - mLogFile.close(); - - secureName(mServerName); - if (mLogDir != "") - { - DIR *dir = opendir((mLogDir + "/" + mServerName).c_str()); - if (!dir) - makeDir(mLogDir + "/" + mServerName); - else - closedir(dir); - } -} - -void ChatLogger::makeDir(const std::string &dir) -{ -#ifdef WIN32 - mkdir(dir.c_str()); -#else - mkdir(dir.c_str(), 0750); -#endif -} - -void ChatLogger::loadLast(std::string name, std::list &list, - unsigned n) -{ - std::ifstream logFile; - - logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), - mServerName.c_str(), secureName(name).c_str(), - getDateString().c_str()).c_str(), std::ios::in); - - if (!logFile.is_open()) - return; - - char line[710]; - while (logFile.getline(line, 700)) - { - list.push_back(line); - if (list.size() > n) - list.pop_front(); - } - - if (logFile.is_open()) - logFile.close(); -} diff --git a/src/chatlog.h b/src/chatlog.h deleted file mode 100644 index 2e9545b04..000000000 --- a/src/chatlog.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * Copyright (C) 2009-2010 Andrei Karas - * - * This file is part of The ManaPlus Client. - * - * This program 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 - * any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef M_CHATLOG_H -#define M_CHATLOG_H - -#include -#include - -class ChatLogger -{ - public: - /** - * Constructor. - */ - ChatLogger(); - - /** - * Destructor, closes log file. - */ - ~ChatLogger(); - - void setLogDir(const std::string &logDir); - - /** - * Enters a message in the log. The message will be timestamped. - */ - void log(std::string str); - - void log(std::string name, std::string str); - - void loadLast(std::string name, std::list &list, - unsigned n); - - std::string getDateString() const; - - std::string secureName(std::string &str) const; - - void setServerName(const std::string &serverName); - - private: - /** - * Sets the file to log to and opens it - */ - void setLogFile(const std::string &logFilename); - - void writeTo(std::ofstream &file, const std::string &str) const; - - void makeDir(const std::string &dir); - - std::ofstream mLogFile; - std::string mLogDir; - std::string mServerName; - std::string mLogDate; -}; - -extern ChatLogger *chatLogger; - -#endif diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp new file mode 100644 index 000000000..067265138 --- /dev/null +++ b/src/chatlogger.cpp @@ -0,0 +1,204 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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 + * any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "chatlogger.h" + +#include +#include +#include + +#include +#include +#include + +#ifdef WIN32 +#include +#elif defined __APPLE__ +#include +#endif + +#include "logger.h" +#include "configuration.h" + +#include "utils/stringutils.h" + +#include "debug.h" + +ChatLogger::ChatLogger() +{ +} + +ChatLogger::~ChatLogger() +{ + if (mLogFile.is_open()) + mLogFile.close(); +} + +void ChatLogger::setLogFile(const std::string &logFilename) +{ + if (mLogFile.is_open()) + mLogFile.close(); + + mLogFile.open(logFilename.c_str(), std::ios_base::app); + + if (!mLogFile.is_open()) + { + std::cout << "Warning: error while opening " << logFilename << + " for writing.\n"; + } +} + +void ChatLogger::setLogDir(const std::string &logDir) +{ + mLogDir = logDir; + + if (mLogFile.is_open()) + mLogFile.close(); + + DIR *dir = opendir(mLogDir.c_str()); + if (!dir) + makeDir(mLogDir); + else + closedir(dir); +} + +void ChatLogger::log(std::string str) +{ + std::string dateStr = getDateString(); + if (!mLogFile.is_open() || dateStr != mLogDate) + { + mLogDate = dateStr; + setLogFile(strprintf("%s/%s/#General_%s.log", mLogDir.c_str(), + mServerName.c_str(), dateStr.c_str())); + } + + str = removeColors(str); + writeTo(mLogFile, str); +} + +void ChatLogger::log(std::string name, std::string str) +{ + std::ofstream logFile; + logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), + mServerName.c_str(), secureName(name).c_str(), + getDateString().c_str()).c_str(), std::ios_base::app); + + if (!logFile.is_open()) + return; + + str = removeColors(str); + writeTo(logFile, str); + + if (logFile.is_open()) + logFile.close(); +} + +std::string ChatLogger::getDateString() const +{ + std::string date; + + time_t rawtime; + struct tm *timeinfo; + char buffer [81]; + + time (&rawtime); + timeinfo = localtime(&rawtime); + + strftime(buffer, 79, "%y-%m-%d", timeinfo); + date = buffer; + return date; +} + +std::string ChatLogger::secureName(std::string &name) const +{ + for (unsigned int f = 0; f < name.length(); f ++) + { + if (name[f] < '0' && name[f] > '9' && name[f] < 'a' && name[f] > 'z' + && name[f] < 'A' && name[f] > 'Z' + && name[f] != '-' && name[f] != '+' && name[f] != '=' + && name[f] != '.' && name[f] != ',' && name[f] != ')' + && name[f] != '(' && name[f] != '[' && name[f] != ']') + { + name[f] = '_'; + } + } + return name; +} + +void ChatLogger::writeTo(std::ofstream &file, const std::string &str) const +{ + file << str << std::endl; +} + +void ChatLogger::setServerName(const std::string &serverName) +{ + mServerName = serverName; + if (mServerName == "") + mServerName = config.getStringValue("MostUsedServerName0"); + + if (mLogFile.is_open()) + mLogFile.close(); + + secureName(mServerName); + if (mLogDir != "") + { + DIR *dir = opendir((mLogDir + "/" + mServerName).c_str()); + if (!dir) + makeDir(mLogDir + "/" + mServerName); + else + closedir(dir); + } +} + +void ChatLogger::makeDir(const std::string &dir) +{ +#ifdef WIN32 + mkdir(dir.c_str()); +#else + mkdir(dir.c_str(), 0750); +#endif +} + +void ChatLogger::loadLast(std::string name, std::list &list, + unsigned n) +{ + std::ifstream logFile; + + logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), + mServerName.c_str(), secureName(name).c_str(), + getDateString().c_str()).c_str(), std::ios::in); + + if (!logFile.is_open()) + return; + + char line[710]; + while (logFile.getline(line, 700)) + { + list.push_back(line); + if (list.size() > n) + list.pop_front(); + } + + if (logFile.is_open()) + logFile.close(); +} diff --git a/src/chatlogger.h b/src/chatlogger.h new file mode 100644 index 000000000..2e9545b04 --- /dev/null +++ b/src/chatlogger.h @@ -0,0 +1,79 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * Copyright (C) 2009-2010 Andrei Karas + * + * This file is part of The ManaPlus Client. + * + * This program 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 + * any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef M_CHATLOG_H +#define M_CHATLOG_H + +#include +#include + +class ChatLogger +{ + public: + /** + * Constructor. + */ + ChatLogger(); + + /** + * Destructor, closes log file. + */ + ~ChatLogger(); + + void setLogDir(const std::string &logDir); + + /** + * Enters a message in the log. The message will be timestamped. + */ + void log(std::string str); + + void log(std::string name, std::string str); + + void loadLast(std::string name, std::list &list, + unsigned n); + + std::string getDateString() const; + + std::string secureName(std::string &str) const; + + void setServerName(const std::string &serverName); + + private: + /** + * Sets the file to log to and opens it + */ + void setLogFile(const std::string &logFilename); + + void writeTo(std::ofstream &file, const std::string &str) const; + + void makeDir(const std::string &dir); + + std::ofstream mLogFile; + std::string mLogDir; + std::string mServerName; + std::string mLogDate; +}; + +extern ChatLogger *chatLogger; + +#endif diff --git a/src/client.cpp b/src/client.cpp index 022bc07d5..e85c5b08f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -23,7 +23,7 @@ #include "client.h" #include "main.h" -#include "chatlog.h" +#include "chatlogger.h" #include "configuration.h" #include "dropshortcut.h" #include "emoteshortcut.h" diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index dc9a4d1bf..f650ac8d1 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -27,7 +27,7 @@ #include "channel.h" #include "game.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "gui/chatwindow.h" diff --git a/src/configuration.cpp b/src/configuration.cpp index 7d1f41fe5..2524d6b93 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -23,7 +23,7 @@ #include "configuration.h" #include "configlistener.h" -#include "log.h" +#include "logger.h" #include "utils/paths.h" #include "utils/stringutils.h" diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp index bb54ced99..36e7aac16 100644 --- a/src/effectmanager.cpp +++ b/src/effectmanager.cpp @@ -21,7 +21,7 @@ #include "being.h" #include "effectmanager.h" -#include "log.h" +#include "logger.h" #include "particle.h" #include "sound.h" diff --git a/src/filefilter.txt b/src/filefilter.txt index b2b1e7d0c..0dde8e90c 100644 --- a/src/filefilter.txt +++ b/src/filefilter.txt @@ -1,5 +1,6 @@ ~ RULE_3_1_A_do_not_start_filename_with_underbar ~ RULE_3_2_CD_do_not_use_special_characters_in_filename +~ RULE_3_2_F_use_representitive_classname_for_cpp_filename ~ RULE_3_2_H_do_not_use_uppercase_for_c_filename ~ RULE_3_3_A_start_function_name_with_lowercase_unix ~ RULE_4_1_A_B_use_space_for_indentation @@ -23,3 +24,4 @@ ~ RULE_8_1_A_provide_file_info_comment ~ RULE_9_1_A_do_not_use_hardcorded_include_path ~ RULE_9_2_D_use_reentrant_function + diff --git a/src/game.cpp b/src/game.cpp index 4332c8e11..4967231b0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -42,7 +42,7 @@ #include "joystick.h" #include "keyboardconfig.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "particle.h" #include "playerrelations.h" diff --git a/src/graphics.cpp b/src/graphics.cpp index 6a6760c36..a86ac7fd0 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -25,7 +25,7 @@ #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "resources/image.h" diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index d424fff91..c24624bc2 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -23,7 +23,7 @@ #include "gui/changeemaildialog.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "gui/register.h" #include "gui/okdialog.h" diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index dc640841a..30012ae52 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -23,7 +23,7 @@ #include "changepassworddialog.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "gui/register.h" #include "gui/okdialog.h" diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 264df06e3..28c7a083c 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -26,7 +26,7 @@ #include "game.h" #include "localplayer.h" #include "units.h" -#include "log.h" +#include "logger.h" #include "gui/changeemaildialog.h" #include "gui/changepassworddialog.h" diff --git a/src/gui/connectiondialog.cpp b/src/gui/connectiondialog.cpp index 157398297..da98ea5ac 100644 --- a/src/gui/connectiondialog.cpp +++ b/src/gui/connectiondialog.cpp @@ -22,7 +22,7 @@ #include "connectiondialog.h" -#include "log.h" +#include "logger.h" #include "gui/widgets/button.h" #include "gui/widgets/label.h" diff --git a/src/gui/didyouknowwindow.cpp b/src/gui/didyouknowwindow.cpp index 03188907f..4d89bd924 100644 --- a/src/gui/didyouknowwindow.cpp +++ b/src/gui/didyouknowwindow.cpp @@ -22,7 +22,7 @@ #include "gui/didyouknowwindow.h" -#include "log.h" +#include "logger.h" #include "gui/gui.h" #include "gui/setup.h" diff --git a/src/gui/emotepopup.cpp b/src/gui/emotepopup.cpp index 3a754d0e3..348a97952 100644 --- a/src/gui/emotepopup.cpp +++ b/src/gui/emotepopup.cpp @@ -28,7 +28,7 @@ #include "emoteshortcut.h" #include "graphics.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/theme.h" diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 0bea1d0d7..3e4ec764f 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -35,7 +35,7 @@ #include "configlistener.h" #include "configuration.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "resources/image.h" #include "resources/imageset.h" diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index ae0a432ea..368049389 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -22,7 +22,7 @@ #include "gui/helpwindow.h" -#include "log.h" +#include "logger.h" #include "gui/gui.h" #include "gui/setup.h" diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 5022f9210..c735eec82 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -27,7 +27,7 @@ #include "configuration.h" #include "graphics.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "gui/userpalette.h" diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 9dd41a643..09e75856f 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -28,7 +28,7 @@ #include "inventory.h" #include "item.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "gui/chatwindow.h" diff --git a/src/gui/palette.h b/src/gui/palette.h index 9409bfc06..1cebe236f 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -24,7 +24,7 @@ #ifndef PALETTE_H #define PALETTE_H -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" #include diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 14a326e41..86ddfda53 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -32,7 +32,7 @@ #include "item.h" #include "itemshortcut.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "party.h" #include "playerinfo.h" diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 80ddb7469..913c958f2 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "gui/logindialog.h" #include "gui/okdialog.h" diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index a0f8699f8..8dd7f929d 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -25,7 +25,7 @@ #include "client.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "resources/image.h" diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 41b0076e1..37870a87f 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -22,10 +22,10 @@ #include "gui/serverdialog.h" -#include "chatlog.h" +#include "chatlogger.h" #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "gui/gui.h" diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 28e6d8cfa..1737e9004 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -23,7 +23,7 @@ #include "gui/setup_audio.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "sound.h" #include "gui/okdialog.h" diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index 621f62810..7ce44a552 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -37,7 +37,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "utils/gettext.h" diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index 3675da4ca..3b603a8ee 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -29,7 +29,7 @@ #include "gui/widgets/scrollarea.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "utils/gettext.h" diff --git a/src/gui/setup_perfomance.cpp b/src/gui/setup_perfomance.cpp index eaadc7c3a..583f2909a 100644 --- a/src/gui/setup_perfomance.cpp +++ b/src/gui/setup_perfomance.cpp @@ -37,7 +37,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "utils/gettext.h" diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 7490135cd..d2664adbd 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -37,7 +37,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "utils/gettext.h" diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index 646d47550..93887b133 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -25,7 +25,7 @@ #include "actorspritemanager.h" #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/editdialog.h" #include "gui/okdialog.h" diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index 42ed0205c..7a2c66595 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -37,7 +37,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "utils/gettext.h" diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 8979a81e1..03b485097 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -26,7 +26,7 @@ #include "game.h" #include "graphics.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "particle.h" diff --git a/src/gui/setupitem.cpp b/src/gui/setupitem.cpp index 182501e72..defdb4005 100644 --- a/src/gui/setupitem.cpp +++ b/src/gui/setupitem.cpp @@ -22,7 +22,7 @@ #include "configuration.h" #include "main.h" -#include "log.h" +#include "logger.h" #include "gui/editdialog.h" diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 5b47a5494..896f06cab 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -22,7 +22,7 @@ #include "gui/skilldialog.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "configuration.h" diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index adcfe4d70..e3aa69b30 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -25,7 +25,7 @@ #include "guild.h" #include "keyboardconfig.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "party.h" diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index 1c41752f3..a5d95c7ff 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -21,7 +21,7 @@ #include "gui/specialswindow.h" -#include "log.h" +#include "logger.h" #include "gui/setup.h" #include "gui/theme.h" diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 92613a3b3..056eafc0f 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -26,7 +26,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "resources/dye.h" #include "resources/image.h" diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index 8f845e746..568e0613e 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -23,7 +23,7 @@ #include "gui/unregisterdialog.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "gui/okdialog.h" #include "gui/register.h" diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index eb5471e2a..895c99121 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "gui/sdlinput.h" diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp index 40dddc4f1..eac9559ef 100644 --- a/src/gui/userpalette.cpp +++ b/src/gui/userpalette.cpp @@ -25,7 +25,7 @@ #include "configuration.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "gui/gui.h" diff --git a/src/gui/widgets/battletab.cpp b/src/gui/widgets/battletab.cpp index e72c78ee0..c5500e801 100644 --- a/src/gui/widgets/battletab.cpp +++ b/src/gui/widgets/battletab.cpp @@ -22,10 +22,10 @@ #include "gui/widgets/battletab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "gui/theme.h" diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 140a72770..7df70bd04 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -25,7 +25,7 @@ #include "client.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 0570630c3..2d9678a53 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -26,7 +26,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "gui/palette.h" #include "gui/theme.h" diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 42a39a20f..e27af8b25 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -23,11 +23,11 @@ #include "gui/widgets/chattab.h" #include "actorspritemanager.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "sound.h" #include "gui/widgets/browserbox.h" diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 3ade3b37f..cfb757638 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -22,7 +22,7 @@ #include "configuration.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "gui/palette.h" diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index bb5af4b1c..5bb972adc 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -29,7 +29,7 @@ #include "itemshortcut.h" #include "keyboardconfig.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/palette.h" #include "gui/textpopup.h" diff --git a/src/gui/widgets/inventoryfilter.cpp b/src/gui/widgets/inventoryfilter.cpp index 563e37b8c..795f0d31e 100644 --- a/src/gui/widgets/inventoryfilter.cpp +++ b/src/gui/widgets/inventoryfilter.cpp @@ -23,7 +23,7 @@ #include "gui/widgets/horizontcontainer.h" #include "gui/widgets/radiobutton.h" -#include "log.h" +#include "logger.h" #include "debug.h" diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 7818432f8..b79f26226 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -27,7 +27,7 @@ #include "item.h" #include "itemshortcut.h" #include "dropshortcut.h" -#include "log.h" +#include "logger.h" #include "gui/chatwindow.h" #include "gui/itempopup.h" diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 274c17d61..382d169dc 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -22,7 +22,7 @@ #include "gui/widgets/layout.h" -#include "log.h" +#include "logger.h" #include diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index ea51c146a..38088770b 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -26,7 +26,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "gui/theme.h" #include "gui/viewport.h" diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index df39854da..08f0b5a70 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -26,7 +26,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "gui/theme.h" diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index 872ed16c7..8d5b563bb 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -40,7 +40,7 @@ #include "keyboardconfig.h" #include "localplayer.h" #include "spellmanager.h" -#include "log.h" +#include "logger.h" #include "resources/image.h" #include "textcommand.h" diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 1b548a6a3..b7d6b4458 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -26,7 +26,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "gui/palette.h" #include "gui/theme.h" diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index d3539a115..940dad12a 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -25,7 +25,7 @@ #include "gui/widgets/scrollarea.h" #include "gui/widgets/tab.h" -#include "log.h" +#include "logger.h" #include diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index d3108a77f..f80039650 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -25,7 +25,7 @@ #include "client.h" #include "configuration.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "gui/palette.h" #include "gui/sdlinput.h" diff --git a/src/gui/widgets/tradetab.cpp b/src/gui/widgets/tradetab.cpp index 99a145d86..deec2aea6 100644 --- a/src/gui/widgets/tradetab.cpp +++ b/src/gui/widgets/tradetab.cpp @@ -22,10 +22,10 @@ #include "gui/widgets/tradetab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/theme.h" diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index bee30b969..c99c4e0c5 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -22,10 +22,10 @@ #include "gui/widgets/whispertab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/theme.h" diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 14448ea86..9a7c689e6 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -25,7 +25,7 @@ #include "client.h" #include "configuration.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "gui/gui.h" #include "gui/palette.h" diff --git a/src/inventory.cpp b/src/inventory.cpp index 3ff40374a..acd35efdd 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -22,7 +22,7 @@ #include "inventory.h" #include "item.h" -#include "log.h" +#include "logger.h" #include "net/inventoryhandler.h" #include "net/net.h" diff --git a/src/joystick.cpp b/src/joystick.cpp index f1255c4c0..8f808a2d1 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -22,7 +22,7 @@ #include "configuration.h" #include "joystick.h" -#include "log.h" +#include "logger.h" #include diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 8ad38ab76..bf58c518a 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -20,7 +20,7 @@ #include "configuration.h" #include "keyboardconfig.h" -#include "log.h" +#include "logger.h" #include "gui/sdlinput.h" #include "gui/setup_keyboard.h" diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 0310bb8ad..a9e9d1f21 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -31,7 +31,7 @@ #include "guild.h" #include "item.h" #include "keyboardconfig.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "party.h" #include "particle.h" diff --git a/src/log.cpp b/src/log.cpp deleted file mode 100644 index 9bcf1ea4f..000000000 --- a/src/log.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program 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 - * any later version. - * - * This program 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 this program. If not, see . - */ - -#include -#include - -#include "log.h" - -#include "configuration.h" - -#include "gui/widgets/chattab.h" - -#ifdef WIN32 -#include -#elif defined __APPLE__ -#include -#elif __linux__ || __linux -#include -#endif - -#include - -#include "debug.h" - -Logger::Logger(): - mLogToStandardOut(true), - mChatWindow(NULL), - mDebugLog(false) -{ -} - -Logger::~Logger() -{ - if (mLogFile.is_open()) - { - mLogFile.close(); - } -} - -void Logger::setLogFile(const std::string &logFilename) -{ - if (mLogFile.is_open()) - mLogFile.close(); - - mLogFile.open(logFilename.c_str(), std::ios_base::trunc); - - if (!mLogFile.is_open()) - { - std::cout << "Warning: error while opening " << logFilename << - " for writing.\n"; - } -} - -void Logger::log(std::string str) -{ - log("%s", str.c_str()); -} - -void Logger::dlog(std::string str) -{ - if (!mDebugLog) - return; - - // Get the current system time - timeval tv; - gettimeofday(&tv, NULL); - - // Print the log entry - std::stringstream timeStr; - timeStr << "[" - << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast(((tv.tv_sec / 60) / 60) % 24) - << ":" - << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") - << static_cast((tv.tv_sec / 60) % 60) - << ":" - << ((tv.tv_sec % 60 < 10) ? "0" : "") - << static_cast(tv.tv_sec % 60) - << "." - << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") - << static_cast((tv.tv_usec / 10000) % 100) - << "] "; - - if (mLogFile.is_open()) - mLogFile << timeStr.str() << str << std::endl; - - if (mLogToStandardOut) - std::cout << timeStr.str() << str << std::endl; - - if (mChatWindow && debugChatTab) - debugChatTab->chatLog(str, BY_LOGGER); -} - -void Logger::log1(const char *buf) -{ - // Get the current system time - timeval tv; - gettimeofday(&tv, NULL); - - // Print the log entry - std::stringstream timeStr; - timeStr << "[" - << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast(((tv.tv_sec / 60) / 60) % 24) - << ":" - << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") - << static_cast((tv.tv_sec / 60) % 60) - << ":" - << ((tv.tv_sec % 60 < 10) ? "0" : "") - << static_cast(tv.tv_sec % 60) - << "." - << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") - << static_cast((tv.tv_usec / 10000) % 100) - << "] "; - - if (mLogFile.is_open()) - mLogFile << timeStr.str() << buf << std::endl; - - if (mLogToStandardOut) - std::cout << timeStr.str() << buf << std::endl; - - if (mChatWindow && debugChatTab) - debugChatTab->chatLog(buf, BY_LOGGER); -} - -void Logger::log(const char *log_text, ...) -{ - unsigned size = 1024; - char* buf = 0; - if (strlen(log_text) * 3> size) - size = static_cast(strlen(log_text) * 3); - - buf = new char[size + 1]; - va_list ap; - - // Use a temporary buffer to fill in the variables - va_start(ap, log_text); - vsnprintf(buf, size, log_text, ap); - buf[size] = 0; - va_end(ap); - - // Get the current system time - timeval tv; - gettimeofday(&tv, NULL); - - // Print the log entry - std::stringstream timeStr; - timeStr << "[" - << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast(((tv.tv_sec / 60) / 60) % 24) - << ":" - << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") - << static_cast((tv.tv_sec / 60) % 60) - << ":" - << ((tv.tv_sec % 60 < 10) ? "0" : "") - << static_cast(tv.tv_sec % 60) - << "." - << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") - << static_cast((tv.tv_usec / 10000) % 100) - << "] "; - - if (mLogFile.is_open()) - mLogFile << timeStr.str() << buf << std::endl; - - if (mLogToStandardOut) - std::cout << timeStr.str() << buf << std::endl; - - if (mChatWindow && debugChatTab) - debugChatTab->chatLog(buf, BY_LOGGER); - - // Delete temporary buffer - delete[] buf; -} - -void Logger::error(const std::string &error_text) -{ - log("Error: %s", error_text.c_str()); -#ifdef WIN32 - MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK); -#elif defined __APPLE__ -// Str255 msg; -// CFStringRef error; -// error = CFStringCreateWithCString(NULL, -// error_text.c_str(), -// kCFStringEncodingMacRoman); -// CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman); -// StandardAlert(kAlertStopAlert, -// (const unsigned char*)"\pError", -// (ConstStr255Param) msg, NULL, NULL); -#elif defined __linux__ || __linux - std::cerr << "Error: " << error_text << std::endl; - std::string msg = "xmessage \"" + error_text + "\""; - system(msg.c_str()); -#else - std::cerr << "Error: " << error_text << std::endl; -#endif - exit(1); -} diff --git a/src/log.h b/src/log.h deleted file mode 100644 index b8517f696..000000000 --- a/src/log.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program 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 - * any later version. - * - * This program 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 this program. If not, see . - */ - -#ifndef M_LOG_H -#define M_LOG_H - -#include "main.h" -#include - -class ChatWindow; - -#ifdef ENABLEDEBUGLOG -#define DEBUGLOG(msg) logger->dlog(msg) -#else -#define DEBUGLOG(msg) {} -#endif - -/** - * The Log Class : Useful to write debug or info messages - */ -class Logger -{ - public: - /** - * Constructor. - */ - Logger(); - - /** - * Destructor, closes log file. - */ - ~Logger(); - - /** - * Sets the file to log to and opens it - */ - void setLogFile(const std::string &logFilename); - - /** - * Sets whether the log should be written to standard output. - */ - void setLogToStandardOut(bool value) { mLogToStandardOut = value; } - - /** - * Enables logging to chat window - */ - void setChatWindow(ChatWindow *window) { mChatWindow = window; } - - /** - * Enters a message in the log. The message will be timestamped. - */ - void log(const char *log_text, ...) -#ifdef __GNUC__ - __attribute__((__format__(__printf__, 2, 3))) -#endif - ; - - /** - * Enters a message in the log. The message will be timestamped. - */ - void log1(const char *log_text); - - /** - * Enters a message in the log. The message will be timestamped. - */ - void log(std::string str); - - /** - * Enters debug message in the log. The message will be timestamped. - */ - void dlog(std::string str); - - void setDebugLog(bool n) - { mDebugLog = n; } - - /** - * Log an error and quit. The error will pop-up on Windows and Mac, and - * will be printed to standard error everywhere else. - */ - void error(const std::string &error_text) __attribute__ ((noreturn)); - - private: - std::ofstream mLogFile; - bool mLogToStandardOut; - ChatWindow *mChatWindow; - bool mDebugLog; -}; - -extern Logger *logger; - -#endif diff --git a/src/logger.cpp b/src/logger.cpp new file mode 100644 index 000000000..6790d622a --- /dev/null +++ b/src/logger.cpp @@ -0,0 +1,217 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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 + * any later version. + * + * This program 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 this program. If not, see . + */ + +#include +#include + +#include "logger.h" + +#include "configuration.h" + +#include "gui/widgets/chattab.h" + +#ifdef WIN32 +#include +#elif defined __APPLE__ +#include +#elif __linux__ || __linux +#include +#endif + +#include + +#include "debug.h" + +Logger::Logger(): + mLogToStandardOut(true), + mChatWindow(NULL), + mDebugLog(false) +{ +} + +Logger::~Logger() +{ + if (mLogFile.is_open()) + { + mLogFile.close(); + } +} + +void Logger::setLogFile(const std::string &logFilename) +{ + if (mLogFile.is_open()) + mLogFile.close(); + + mLogFile.open(logFilename.c_str(), std::ios_base::trunc); + + if (!mLogFile.is_open()) + { + std::cout << "Warning: error while opening " << logFilename << + " for writing.\n"; + } +} + +void Logger::log(std::string str) +{ + log("%s", str.c_str()); +} + +void Logger::dlog(std::string str) +{ + if (!mDebugLog) + return; + + // Get the current system time + timeval tv; + gettimeofday(&tv, NULL); + + // Print the log entry + std::stringstream timeStr; + timeStr << "[" + << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") + << static_cast(((tv.tv_sec / 60) / 60) % 24) + << ":" + << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") + << static_cast((tv.tv_sec / 60) % 60) + << ":" + << ((tv.tv_sec % 60 < 10) ? "0" : "") + << static_cast(tv.tv_sec % 60) + << "." + << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") + << static_cast((tv.tv_usec / 10000) % 100) + << "] "; + + if (mLogFile.is_open()) + mLogFile << timeStr.str() << str << std::endl; + + if (mLogToStandardOut) + std::cout << timeStr.str() << str << std::endl; + + if (mChatWindow && debugChatTab) + debugChatTab->chatLog(str, BY_LOGGER); +} + +void Logger::log1(const char *buf) +{ + // Get the current system time + timeval tv; + gettimeofday(&tv, NULL); + + // Print the log entry + std::stringstream timeStr; + timeStr << "[" + << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") + << static_cast(((tv.tv_sec / 60) / 60) % 24) + << ":" + << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") + << static_cast((tv.tv_sec / 60) % 60) + << ":" + << ((tv.tv_sec % 60 < 10) ? "0" : "") + << static_cast(tv.tv_sec % 60) + << "." + << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") + << static_cast((tv.tv_usec / 10000) % 100) + << "] "; + + if (mLogFile.is_open()) + mLogFile << timeStr.str() << buf << std::endl; + + if (mLogToStandardOut) + std::cout << timeStr.str() << buf << std::endl; + + if (mChatWindow && debugChatTab) + debugChatTab->chatLog(buf, BY_LOGGER); +} + +void Logger::log(const char *log_text, ...) +{ + unsigned size = 1024; + char* buf = 0; + if (strlen(log_text) * 3> size) + size = static_cast(strlen(log_text) * 3); + + buf = new char[size + 1]; + va_list ap; + + // Use a temporary buffer to fill in the variables + va_start(ap, log_text); + vsnprintf(buf, size, log_text, ap); + buf[size] = 0; + va_end(ap); + + // Get the current system time + timeval tv; + gettimeofday(&tv, NULL); + + // Print the log entry + std::stringstream timeStr; + timeStr << "[" + << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") + << static_cast(((tv.tv_sec / 60) / 60) % 24) + << ":" + << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") + << static_cast((tv.tv_sec / 60) % 60) + << ":" + << ((tv.tv_sec % 60 < 10) ? "0" : "") + << static_cast(tv.tv_sec % 60) + << "." + << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") + << static_cast((tv.tv_usec / 10000) % 100) + << "] "; + + if (mLogFile.is_open()) + mLogFile << timeStr.str() << buf << std::endl; + + if (mLogToStandardOut) + std::cout << timeStr.str() << buf << std::endl; + + if (mChatWindow && debugChatTab) + debugChatTab->chatLog(buf, BY_LOGGER); + + // Delete temporary buffer + delete[] buf; +} + +void Logger::error(const std::string &error_text) +{ + log("Error: %s", error_text.c_str()); +#ifdef WIN32 + MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK); +#elif defined __APPLE__ +// Str255 msg; +// CFStringRef error; +// error = CFStringCreateWithCString(NULL, +// error_text.c_str(), +// kCFStringEncodingMacRoman); +// CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman); +// StandardAlert(kAlertStopAlert, +// (const unsigned char*)"\pError", +// (ConstStr255Param) msg, NULL, NULL); +#elif defined __linux__ || __linux + std::cerr << "Error: " << error_text << std::endl; + std::string msg = "xmessage \"" + error_text + "\""; + system(msg.c_str()); +#else + std::cerr << "Error: " << error_text << std::endl; +#endif + exit(1); +} diff --git a/src/logger.h b/src/logger.h new file mode 100644 index 000000000..b8517f696 --- /dev/null +++ b/src/logger.h @@ -0,0 +1,110 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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 + * any later version. + * + * This program 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 this program. If not, see . + */ + +#ifndef M_LOG_H +#define M_LOG_H + +#include "main.h" +#include + +class ChatWindow; + +#ifdef ENABLEDEBUGLOG +#define DEBUGLOG(msg) logger->dlog(msg) +#else +#define DEBUGLOG(msg) {} +#endif + +/** + * The Log Class : Useful to write debug or info messages + */ +class Logger +{ + public: + /** + * Constructor. + */ + Logger(); + + /** + * Destructor, closes log file. + */ + ~Logger(); + + /** + * Sets the file to log to and opens it + */ + void setLogFile(const std::string &logFilename); + + /** + * Sets whether the log should be written to standard output. + */ + void setLogToStandardOut(bool value) { mLogToStandardOut = value; } + + /** + * Enables logging to chat window + */ + void setChatWindow(ChatWindow *window) { mChatWindow = window; } + + /** + * Enters a message in the log. The message will be timestamped. + */ + void log(const char *log_text, ...) +#ifdef __GNUC__ + __attribute__((__format__(__printf__, 2, 3))) +#endif + ; + + /** + * Enters a message in the log. The message will be timestamped. + */ + void log1(const char *log_text); + + /** + * Enters a message in the log. The message will be timestamped. + */ + void log(std::string str); + + /** + * Enters debug message in the log. The message will be timestamped. + */ + void dlog(std::string str); + + void setDebugLog(bool n) + { mDebugLog = n; } + + /** + * Log an error and quit. The error will pop-up on Windows and Mac, and + * will be printed to standard error everywhere else. + */ + void error(const std::string &error_text) __attribute__ ((noreturn)); + + private: + std::ofstream mLogFile; + bool mLogToStandardOut; + ChatWindow *mChatWindow; + bool mDebugLog; +}; + +extern Logger *logger; + +#endif diff --git a/src/main.cpp b/src/main.cpp index faeedadaa..5c13b10ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,7 @@ #include "utils/gettext.h" #include "client.h" -#include "log.h" +#include "logger.h" #include diff --git a/src/map.cpp b/src/map.cpp index 8225aded1..700f6d0d2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -27,7 +27,7 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "particle.h" #include "simpleanimation.h" #include "tileset.h" diff --git a/src/mumblemanager.cpp b/src/mumblemanager.cpp index 456606406..a9a8146b6 100644 --- a/src/mumblemanager.cpp +++ b/src/mumblemanager.cpp @@ -3,7 +3,7 @@ #include "mumblemanager.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "utils/mathutils.h" diff --git a/src/net/download.cpp b/src/net/download.cpp index c93f33c21..93417197e 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -22,7 +22,7 @@ #include "net/download.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "utils/stringutils.h" diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index ee070593f..06e86f8a4 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -31,7 +31,7 @@ #include "guild.h" #include "keyboardconfig.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "party.h" #include "playerrelations.h" #include "configuration.h" diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index c69d8a5be..a0e5b392a 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -23,7 +23,7 @@ #include "net/ea/charserverhandler.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "gui/charcreatedialog.h" #include "gui/okdialog.h" diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index ea9d17798..c188a2204 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -27,7 +27,7 @@ #include "configuration.h" #include "localplayer.h" #include "playerrelations.h" -#include "log.h" +#include "logger.h" #include "gui/chatwindow.h" #include "gui/shopwindow.h" diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index 0b6b8a040..04c13572f 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -26,7 +26,7 @@ #include "event.h" #include "game.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/okdialog.h" diff --git a/src/net/ea/gui/guildtab.cpp b/src/net/ea/gui/guildtab.cpp index 037885fd1..ab030be83 100644 --- a/src/net/ea/gui/guildtab.cpp +++ b/src/net/ea/gui/guildtab.cpp @@ -22,7 +22,7 @@ #include "net/ea/gui/guildtab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "guild.h" #include "localplayer.h" diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp index 02e0910a7..23eab361c 100644 --- a/src/net/ea/gui/partytab.cpp +++ b/src/net/ea/gui/partytab.cpp @@ -22,7 +22,7 @@ #include "net/ea/gui/partytab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "localplayer.h" #include "party.h" diff --git a/src/net/ea/guildhandler.cpp b/src/net/ea/guildhandler.cpp index bb5cbe94b..0210a76ff 100644 --- a/src/net/ea/guildhandler.cpp +++ b/src/net/ea/guildhandler.cpp @@ -25,7 +25,7 @@ #include "guild.h" #include "event.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/socialwindow.h" diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index 2e52b85ff..d921b5e2a 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -24,7 +24,7 @@ #include "inventory.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/ministatus.h" diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h index 1f1f8d296..4be4ddaa6 100644 --- a/src/net/ea/inventoryhandler.h +++ b/src/net/ea/inventoryhandler.h @@ -25,7 +25,7 @@ #include "equipment.h" #include "inventory.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "gui/inventorywindow.h" diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 51502895c..9f7a5f07d 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -23,7 +23,7 @@ #include "net/ea/loginhandler.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "configuration.h" #include "utils/dtor.h" diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index f720f9f96..045a2332b 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -22,7 +22,7 @@ #include "actorspritemanager.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/socialwindow.h" diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 05b6cf9e3..4198c14ad 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -22,7 +22,7 @@ #include "net/ea/playerhandler.h" -#include "log.h" +#include "logger.h" #include "party.h" #include "playerinfo.h" #include "units.h" diff --git a/src/net/ea/specialhandler.cpp b/src/net/ea/specialhandler.cpp index 33fea3b27..4f0f22aed 100644 --- a/src/net/ea/specialhandler.cpp +++ b/src/net/ea/specialhandler.cpp @@ -22,7 +22,7 @@ #include "net/ea/specialhandler.h" -#include "log.h" +#include "logger.h" #include "localplayer.h" #include "playerinfo.h" diff --git a/src/net/ea/tradehandler.cpp b/src/net/ea/tradehandler.cpp index 36a5f8811..a03782db2 100644 --- a/src/net/ea/tradehandler.cpp +++ b/src/net/ea/tradehandler.cpp @@ -25,7 +25,7 @@ #include "event.h" #include "inventory.h" #include "item.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "playerrelations.h" diff --git a/src/net/manaserv/attributes.cpp b/src/net/manaserv/attributes.cpp index b48cc9eff..25c75f9d8 100644 --- a/src/net/manaserv/attributes.cpp +++ b/src/net/manaserv/attributes.cpp @@ -21,7 +21,7 @@ #include "net/manaserv/attributes.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "gui/statuswindow.h" diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index 23aae1f56..d14cdcadf 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -27,7 +27,7 @@ #include "client.h" #include "game.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "particle.h" #include "gui/okdialog.h" diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index c2611c64b..3b2306feb 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "gui/charcreatedialog.h" #include "gui/okdialog.h" diff --git a/src/net/manaserv/connection.cpp b/src/net/manaserv/connection.cpp index 7f51aeb98..33d6f28cf 100644 --- a/src/net/manaserv/connection.cpp +++ b/src/net/manaserv/connection.cpp @@ -22,7 +22,7 @@ #include "net/manaserv/connection.h" -#include "log.h" +#include "logger.h" #include "net/manaserv/internal.h" #include "net/manaserv/messageout.h" diff --git a/src/net/manaserv/effecthandler.cpp b/src/net/manaserv/effecthandler.cpp index 3979a0fde..92cf66302 100644 --- a/src/net/manaserv/effecthandler.cpp +++ b/src/net/manaserv/effecthandler.cpp @@ -24,7 +24,7 @@ #include "actorspritemanager.h" #include "effectmanager.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" diff --git a/src/net/manaserv/guildhandler.cpp b/src/net/manaserv/guildhandler.cpp index dc3dbc616..306a15be4 100644 --- a/src/net/manaserv/guildhandler.cpp +++ b/src/net/manaserv/guildhandler.cpp @@ -24,7 +24,7 @@ #include "event.h" #include "guild.h" -#include "log.h" +#include "logger.h" #include "localplayer.h" #include "channel.h" #include "channelmanager.h" diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 5e38354fb..ce837b5e1 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -38,7 +38,7 @@ #include "resources/iteminfo.h" -#include "log.h" // <<< REMOVE ME! +#include "logger.h" // <<< REMOVE ME! extern Net::InventoryHandler *inventoryHandler; diff --git a/src/net/manaserv/itemhandler.cpp b/src/net/manaserv/itemhandler.cpp index 0afd12d21..89826a33f 100644 --- a/src/net/manaserv/itemhandler.cpp +++ b/src/net/manaserv/itemhandler.cpp @@ -29,7 +29,7 @@ #include "game.h" #include "map.h" -#include "log.h" +#include "logger.h" namespace ManaServ { diff --git a/src/net/manaserv/loginhandler.cpp b/src/net/manaserv/loginhandler.cpp index e6109ca28..bf823562f 100644 --- a/src/net/manaserv/loginhandler.cpp +++ b/src/net/manaserv/loginhandler.cpp @@ -23,7 +23,7 @@ #include "net/manaserv/loginhandler.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "net/logindata.h" diff --git a/src/net/manaserv/network.cpp b/src/net/manaserv/network.cpp index e0ab7af78..53e83e4ec 100644 --- a/src/net/manaserv/network.cpp +++ b/src/net/manaserv/network.cpp @@ -22,7 +22,7 @@ #include "net/manaserv/network.h" -#include "log.h" +#include "logger.h" #include "net/manaserv/connection.h" #include "net/manaserv/internal.h" diff --git a/src/net/manaserv/partyhandler.cpp b/src/net/manaserv/partyhandler.cpp index 0e6af4578..987a40dc5 100644 --- a/src/net/manaserv/partyhandler.cpp +++ b/src/net/manaserv/partyhandler.cpp @@ -23,7 +23,7 @@ #include "net/manaserv/partyhandler.h" #include "event.h" -#include "log.h" +#include "logger.h" #include "localplayer.h" #include "gui/socialwindow.h" diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index ca7fe511f..3dfddb436 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -27,7 +27,7 @@ #include "effectmanager.h" #include "game.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "particle.h" #include "playerinfo.h" #include "configuration.h" diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 8b5f2eee3..5bfeefdb6 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -24,7 +24,7 @@ #include "net/packetcounters.h" -#include "log.h" +#include "logger.h" #include "net.h" #include "utils/stringutils.h" diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 3cdcb42e0..a8b66f5ae 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -24,7 +24,7 @@ #include "net/packetcounters.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp index a0d996dbf..a332b04fa 100644 --- a/src/net/tmwa/adminhandler.cpp +++ b/src/net/tmwa/adminhandler.cpp @@ -28,7 +28,7 @@ #include "being.h" #include "event.h" #include "game.h" -#include "log.h" +#include "logger.h" #include "playerrelations.h" #include "net/chathandler.h" diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index d6f67f716..17503a406 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -29,7 +29,7 @@ #include "guild.h" #include "keyboardconfig.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "party.h" #include "playerrelations.h" #include "configuration.h" diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index fe803dc62..7aa68e617 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "gui/charcreatedialog.h" diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 0f23f6412..90acf0f90 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -29,7 +29,7 @@ #include "game.h" #include "localplayer.h" #include "playerrelations.h" -#include "log.h" +#include "logger.h" #include "gui/chatwindow.h" #include "gui/shopwindow.h" diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index cc0a37c57..242e9f9de 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -26,7 +26,7 @@ #include "event.h" #include "game.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" #include "net/messageout.h" diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 3e46fa66b..746cb6620 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "gui/charselectdialog.h" #include "gui/inventorywindow.h" diff --git a/src/net/tmwa/gui/guildtab.cpp b/src/net/tmwa/gui/guildtab.cpp index 99b775089..05a93bff8 100644 --- a/src/net/tmwa/gui/guildtab.cpp +++ b/src/net/tmwa/gui/guildtab.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/gui/guildtab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "guild.h" #include "localplayer.h" diff --git a/src/net/tmwa/gui/partytab.cpp b/src/net/tmwa/gui/partytab.cpp index d15f4754f..373fcca31 100644 --- a/src/net/tmwa/gui/partytab.cpp +++ b/src/net/tmwa/gui/partytab.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/gui/partytab.h" -#include "chatlog.h" +#include "chatlogger.h" #include "commandhandler.h" #include "localplayer.h" #include "party.h" diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp index 43583971f..640a6fd78 100644 --- a/src/net/tmwa/guildhandler.cpp +++ b/src/net/tmwa/guildhandler.cpp @@ -23,7 +23,7 @@ #include "actorspritemanager.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "net/tmwa/messagein.h" diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index ae79f6842..14a15e59f 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/inventoryhandler.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 405bacc43..9a0978bd0 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -23,7 +23,7 @@ #ifndef NET_TA_INVENTORYHANDLER_H #define NET_TA_INVENTORYHANDLER_H -#include "log.h" +#include "logger.h" #include "net/net.h" diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp index 15ed2f27c..029c379a0 100644 --- a/src/net/tmwa/loginhandler.cpp +++ b/src/net/tmwa/loginhandler.cpp @@ -23,7 +23,7 @@ #include "net/tmwa/loginhandler.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "configuration.h" #include "net/messagein.h" diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index 6e2fcc187..fb1986597 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -24,7 +24,7 @@ #include "net/packetcounters.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index a904b6bbb..6071e0ab6 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -26,7 +26,7 @@ #include "net/tmwa/network.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index c2049d3cc..8ecf04d36 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/network.h" -#include "log.h" +#include "logger.h" #include "net/messagehandler.h" #include "net/messagein.h" diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 5bbf8baf3..7f942a206 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -22,7 +22,7 @@ #include "actorspritemanager.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index f20ea64a0..c34c661e8 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/playerhandler.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" diff --git a/src/net/tmwa/specialhandler.cpp b/src/net/tmwa/specialhandler.cpp index b175368bd..509c5ecd1 100644 --- a/src/net/tmwa/specialhandler.cpp +++ b/src/net/tmwa/specialhandler.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/specialhandler.h" -#include "log.h" +#include "logger.h" #include "net/messagein.h" diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp index 108b544a0..2280079ea 100644 --- a/src/net/tmwa/tradehandler.cpp +++ b/src/net/tmwa/tradehandler.cpp @@ -23,7 +23,7 @@ #include "net/tmwa/tradehandler.h" #include "item.h" -#include "log.h" +#include "logger.h" #include "playerinfo.h" #include "net/messagein.h" diff --git a/src/opengl1graphics.cpp b/src/opengl1graphics.cpp index d40784aff..e93066b96 100644 --- a/src/opengl1graphics.cpp +++ b/src/opengl1graphics.cpp @@ -26,7 +26,7 @@ #include "opengl1graphics.h" #include "graphicsvertexes.h" -#include "log.h" +#include "logger.h" #include "resources/image.h" diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 6081fa6b3..f918a5c0d 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -26,7 +26,7 @@ #include "graphicsvertexes.h" #include "openglgraphics.h" -#include "log.h" +#include "logger.h" #include "resources/image.h" diff --git a/src/particle.cpp b/src/particle.cpp index eca9307ea..7d7a73e9a 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -27,7 +27,7 @@ #include "configuration.h" #include "resources/dye.h" #include "imageparticle.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "particle.h" #include "particleemitter.h" diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index c04b1b36f..caa48a795 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -22,7 +22,7 @@ #include "animationparticle.h" #include "imageparticle.h" -#include "log.h" +#include "logger.h" #include "particle.h" #include "particleemitter.h" #include "rotationalparticle.h" diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index 72b091244..3bb196921 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -26,7 +26,7 @@ #include "event.h" #include "inventory.h" #include "listener.h" -#include "log.h" +#include "logger.h" #include "resources/itemdb.h" #include "resources/iteminfo.h" diff --git a/src/properties.h b/src/properties.h index c65e30c22..19354b9ab 100644 --- a/src/properties.h +++ b/src/properties.h @@ -23,7 +23,7 @@ #ifndef PROPERTIES_H #define PROPERTIES_H -#include "log.h" +#include "logger.h" #include #include #include diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp index ea7f44199..32b57b3b1 100644 --- a/src/resources/animation.cpp +++ b/src/resources/animation.cpp @@ -22,7 +22,7 @@ #include "resources/animation.h" -#include "log.h" +#include "logger.h" #include "utils/dtor.h" diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 6b4f57d81..8beea420d 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -22,7 +22,7 @@ #include "resources/beinginfo.h" -#include "log.h" +#include "logger.h" #include "utils/dtor.h" #include "utils/gettext.h" diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index 72a5e4023..ed8c934dc 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -21,7 +21,7 @@ #include "resources/colordb.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "utils/xml.h" diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index fe7d4bcac..a782b6ec1 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -22,7 +22,7 @@ #include "resources/dye.h" -#include "log.h" +#include "logger.h" #include #include diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index 85a2993dd..b7f7d7901 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -21,7 +21,7 @@ #include "resources/emotedb.h" #include "animatedsprite.h" -#include "log.h" +#include "logger.h" #include "utils/xml.h" #include "configuration.h" diff --git a/src/resources/image.cpp b/src/resources/image.cpp index b1f83e258..802f2ee12 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -31,7 +31,7 @@ #endif #include "client.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "utils/stringutils.h" diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index 1d41c6e63..5cf3e7d82 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -22,7 +22,7 @@ #include "resources/imageset.h" -#include "log.h" +#include "logger.h" #include "resources/image.h" diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index 5d0bd9d94..e6f3c8c27 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -22,7 +22,7 @@ #include "resources/imagewriter.h" -#include "log.h" +#include "logger.h" #if defined __OpenBSD__ #include diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 7919145bd..e60127997 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -23,7 +23,7 @@ #include "resources/itemdb.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "resources/iteminfo.h" #include "resources/resourcemanager.h" diff --git a/src/resources/mapdb.cpp b/src/resources/mapdb.cpp index e8aeaf168..e7288e039 100644 --- a/src/resources/mapdb.cpp +++ b/src/resources/mapdb.cpp @@ -23,7 +23,7 @@ #include "configuration.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "utils/xml.h" diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 35267533f..70c45054f 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -23,7 +23,7 @@ #include "resources/mapreader.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "map.h" #include "tileset.h" diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 7a0494fc9..dbf9d3e9a 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -22,7 +22,7 @@ #include "resources/monsterdb.h" -#include "log.h" +#include "logger.h" #include "net/net.h" diff --git a/src/resources/music.cpp b/src/resources/music.cpp index ccd1d9280..5ae9a2202 100644 --- a/src/resources/music.cpp +++ b/src/resources/music.cpp @@ -22,7 +22,7 @@ #include "resources/music.h" -#include "log.h" +#include "logger.h" #include "debug.h" diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index 49eab5bf2..d04a2518f 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -22,7 +22,7 @@ #include "resources/npcdb.h" -#include "log.h" +#include "logger.h" #include "resources/beinginfo.h" diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index 6e986272a..b180712c1 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -23,7 +23,7 @@ #include "resources/resource.h" #include "client.h" -#include "log.h" +#include "logger.h" #include "resources/resourcemanager.h" diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 92c18fa2a..ee325e253 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -24,7 +24,7 @@ #include "client.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "main.h" #include "resources/dye.h" diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index a01bf21a0..49e7adc31 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -22,7 +22,7 @@ #include "resources/soundeffect.h" -#include "log.h" +#include "logger.h" #include "debug.h" diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp index 4ab5e2a91..573ffb2a3 100644 --- a/src/resources/specialdb.cpp +++ b/src/resources/specialdb.cpp @@ -21,7 +21,7 @@ #include "resources/specialdb.h" -#include "log.h" +#include "logger.h" #include "utils/dtor.h" #include "utils/xml.h" diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index b6addba77..dee93e1e7 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -22,7 +22,7 @@ #include "resources/spritedef.h" -#include "log.h" +#include "logger.h" #include "resources/action.h" #include "resources/animation.h" diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index 397b87993..09c9f2a04 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -23,7 +23,7 @@ #include "resources/wallpaper.h" #include "resources/resourcemanager.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" #include "configuration.h" diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index e3591f30c..4736b2e57 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -23,7 +23,7 @@ #include "simpleanimation.h" #include "graphics.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" diff --git a/src/sound.cpp b/src/sound.cpp index 92a5eaa6f..0a3c75d11 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -24,7 +24,7 @@ #include "configuration.h" #include "localplayer.h" -#include "log.h" +#include "logger.h" #include "sound.h" #include "resources/resourcemanager.h" diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index 13b8e7b69..a79388350 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -25,7 +25,7 @@ #include "being.h" #include "configuration.h" -#include "log.h" +#include "logger.h" #include "localplayer.h" #include "playerinfo.h" diff --git a/src/spellshortcut.h b/src/spellshortcut.h index 4d59384bd..047ccdef3 100644 --- a/src/spellshortcut.h +++ b/src/spellshortcut.h @@ -25,7 +25,7 @@ #define SPELLSHORTCUT_H #include "spellmanager.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" class TextCommand; diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp index 27e351a45..dccf21f46 100644 --- a/src/statuseffect.cpp +++ b/src/statuseffect.cpp @@ -22,7 +22,7 @@ #include "statuseffect.h" -#include "log.h" +#include "logger.h" #include "sound.h" #include "gui/widgets/chattab.h" diff --git a/src/units.cpp b/src/units.cpp index ee0647e2e..db9faadd1 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -22,7 +22,7 @@ #include "units.h" -#include "log.h" +#include "logger.h" #include "utils/stringutils.h" #include "utils/xml.h" diff --git a/src/utils/mutex.h b/src/utils/mutex.h index f23ddc2aa..03dac2e7a 100644 --- a/src/utils/mutex.h +++ b/src/utils/mutex.h @@ -23,7 +23,7 @@ #ifndef MUTEX_H #define MUTEX_H -#include "log.h" +#include "logger.h" #include diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index b31b60ee1..89457a4e8 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -22,7 +22,7 @@ #include "utils/xml.h" -#include "log.h" +#include "logger.h" #include "resources/resourcemanager.h" -- cgit v1.2.3-70-g09d2 From dec741233dc709950fe542bcd4f69b254b33eb80 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 15 Aug 2011 17:31:22 +0300 Subject: Move setupitem class to widgets directory. --- manaplus.cbp | 2 + po/POTFILES.in | 2 +- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 +- src/gui/setup_chat.cpp | 2 +- src/gui/setup_other.cpp | 3 +- src/gui/setup_perfomance.cpp | 2 +- src/gui/setup_players.cpp | 2 +- src/gui/setupitem.cpp | 507 ------------------------------------- src/gui/setupitem.h | 244 ------------------ src/gui/widgets/setupitem.cpp | 507 +++++++++++++++++++++++++++++++++++++ src/gui/widgets/setupitem.h | 244 ++++++++++++++++++ src/gui/widgets/setuptabscroll.cpp | 3 +- 13 files changed, 763 insertions(+), 763 deletions(-) delete mode 100644 src/gui/setupitem.cpp delete mode 100644 src/gui/setupitem.h create mode 100644 src/gui/widgets/setupitem.cpp create mode 100644 src/gui/widgets/setupitem.h (limited to 'src/gui/setup_perfomance.cpp') diff --git a/manaplus.cbp b/manaplus.cbp index f47e5c271..8ed18dbed 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -349,6 +349,8 @@ + + diff --git a/po/POTFILES.in b/po/POTFILES.in index 76bbeb48a..311ca756d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -42,7 +42,6 @@ src/gui/setup_audio.cpp src/gui/setup_chat.cpp src/gui/setup_colors.cpp src/gui/setup.cpp -src/gui/setupitem.cpp src/gui/setup_joystick.cpp src/gui/setup_keyboard.cpp src/gui/setup_other.cpp @@ -67,6 +66,7 @@ src/gui/whoisonline.cpp src/gui/widgets/battletab.cpp src/gui/widgets/channeltab.cpp src/gui/widgets/chattab.cpp +src/gui/widgets/setupitem.cpp src/gui/widgets/tradetab.cpp src/gui/widgets/whispertab.cpp src/gui/windowmenu.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fba255c1c..413a72f65 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -181,6 +181,8 @@ SET(SRCS gui/widgets/resizegrip.h gui/widgets/scrollarea.cpp gui/widgets/scrollarea.h + gui/widgets/setupitem.cpp + gui/widgets/setupitem.h gui/widgets/setuptab.cpp gui/widgets/setuptab.h gui/widgets/setuptabscroll.cpp @@ -299,8 +301,6 @@ SET(SRCS gui/serverdialog.h gui/setup.cpp gui/setup.h - gui/setupitem.cpp - gui/setupitem.h gui/setup_audio.cpp gui/setup_audio.h gui/setup_colors.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 697575b97..57bb4e620 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -184,6 +184,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/resizegrip.h \ gui/widgets/scrollarea.cpp \ gui/widgets/scrollarea.h \ + gui/widgets/setupitem.cpp \ + gui/widgets/setupitem.h \ gui/widgets/setuptab.cpp \ gui/widgets/setuptab.h \ gui/widgets/setuptabscroll.cpp \ @@ -302,8 +304,6 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/serverdialog.h \ gui/setup.cpp \ gui/setup.h \ - gui/setupitem.cpp \ - gui/setupitem.h \ gui/setup_audio.cpp \ gui/setup_audio.h \ gui/setup_colors.cpp \ diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index 7ce44a552..722a3f8b2 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -25,7 +25,6 @@ #include "gui/chatwindow.h" #include "gui/editdialog.h" -#include "gui/setupitem.h" #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" @@ -34,6 +33,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/setupitem.h" #include "configuration.h" #include "localplayer.h" diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index 3b603a8ee..b405f5045 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -23,10 +23,9 @@ #include "gui/setup_other.h" -#include "gui/setupitem.h" - #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/setupitem.h" #include "configuration.h" #include "logger.h" diff --git a/src/gui/setup_perfomance.cpp b/src/gui/setup_perfomance.cpp index 583f2909a..dfb119b91 100644 --- a/src/gui/setup_perfomance.cpp +++ b/src/gui/setup_perfomance.cpp @@ -25,7 +25,6 @@ #include "gui/chatwindow.h" #include "gui/editdialog.h" -#include "gui/setupitem.h" #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" @@ -34,6 +33,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/setupitem.h" #include "configuration.h" #include "localplayer.h" diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index acc6b3d3c..78c77f6f1 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -25,7 +25,6 @@ #include "gui/chatwindow.h" #include "gui/editdialog.h" -#include "gui/setupitem.h" #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" @@ -34,6 +33,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/setupitem.h" #include "configuration.h" #include "localplayer.h" diff --git a/src/gui/setupitem.cpp b/src/gui/setupitem.cpp deleted file mode 100644 index defdb4005..000000000 --- a/src/gui/setupitem.cpp +++ /dev/null @@ -1,507 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program 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 - * any later version. - * - * This program 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 this program. If not, see . - */ - -#include "gui/setupitem.h" - -#include "configuration.h" -#include "main.h" -#include "logger.h" - -#include "gui/editdialog.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/checkbox.h" -#include "gui/widgets/horizontcontainer.h" -#include "gui/widgets/inttextfield.h" -#include "gui/widgets/label.h" -#include "gui/widgets/layouthelper.h" -#include "gui/widgets/tabbedarea.h" -#include "gui/widgets/textfield.h" -#include "gui/widgets/vertcontainer.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" - - -SetupItem::SetupItem(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, bool mainConfig) : - mText(text), - mDescription(description), - mKeyName(keyName), - mParent(parent), - mEventName(eventName), - mMainConfig(mainConfig), - mUseDefault(false), - mValue(""), - mDefault(""), - mWidget(0), - mValueType(VBOOL) -{ -} - -SetupItem::SetupItem(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, std::string def, bool mainConfig) : - mText(text), - mDescription(description), - mKeyName(keyName), - mParent(parent), - mEventName(eventName), - mMainConfig(mainConfig), - mUseDefault(true), - mValue(""), - mDefault(def), - mWidget(0), - mValueType(VBOOL) -{ -} - -SetupItem::~SetupItem() -{ - -} - -Configuration *SetupItem::getConfig() -{ - if (mMainConfig) - return &config; - else - return &serverConfig; -} - -void SetupItem::load() -{ - Configuration *cfg = getConfig(); - if (mUseDefault) - { - mValue = cfg->getValue(mKeyName, mDefault); - } - else - { - switch (mValueType) - { - case VBOOL: - if (cfg->getBoolValue(mKeyName)) - mValue = "1"; - else - mValue = "0"; - break; - case VSTR: - default: - mValue = cfg->getStringValue(mKeyName); - break; - case VINT: - mValue = toString(cfg->getIntValue(mKeyName)); - break; - case VNONE: - break; - } - } -} - -void SetupItem::save() -{ - Configuration *cfg = getConfig(); - cfg->setValue(mKeyName, mValue); -} - -std::string SetupItem::getActionEventId() -{ - if (!mWidget) - return ""; - - return mWidget->getActionEventId(); -} - -void SetupItem::action(const gcn::ActionEvent &event) -{ - if (!mWidget) - return; - - if (event.getId() == mWidget->getActionEventId()) - action(); -} - -void SetupItem::action() -{ - fromWidget(); -} - -void SetupItem::apply(std::string eventName A_UNUSED) -{ - save(); -} - -void SetupItem::cancel(std::string eventName A_UNUSED) -{ - load(); - toWidget(); -} - -void SetupItem::externalUpdated(std::string eventName A_UNUSED) -{ - load(); - toWidget(); -} - -SetupItemCheckBox::SetupItemCheckBox(std::string text, std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, mainConfig) -{ - createControls(); -} - -SetupItemCheckBox::SetupItemCheckBox(std::string text, std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, std::string def, - bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, def, mainConfig) -{ - createControls(); -} - -SetupItemCheckBox::~SetupItemCheckBox() -{ - mWidget = 0; -} - -void SetupItemCheckBox::createControls() -{ - load(); - mCheckBox = new CheckBox(mText, mValue != "0", mParent, mEventName); - mWidget = mCheckBox; - mParent->getContainer()->add(mWidget); - mParent->addControl(this); - mParent->addActionListener(this); - mWidget->addActionListener(this); -} - -void SetupItemCheckBox::fromWidget() -{ - if (!mCheckBox) - return; - - if (mCheckBox->isSelected()) - mValue = "1"; - else - mValue = "0"; -} - -void SetupItemCheckBox::toWidget() -{ - if (!mCheckBox) - return; - - mCheckBox->setSelected(mValue != "0"); -} - - -SetupItemTextField::SetupItemTextField(std::string text, - std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, - bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, mainConfig), - mHorizont(0), - mLabel(0), - mTextField(0), - mButton(0), - mEditDialog(0) -{ - mValueType = VSTR; - createControls(); -} - -SetupItemTextField::SetupItemTextField(std::string text, - std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, std::string def, - bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, def, mainConfig), - mHorizont(0), - mLabel(0), - mTextField(0), - mButton(0), - mEditDialog(0) -{ - mValueType = VSTR; - createControls(); -} - -SetupItemTextField::~SetupItemTextField() -{ - mHorizont = 0; - mWidget = 0; - mTextField = 0; - mLabel = 0; - mButton = 0; -} - -void SetupItemTextField::createControls() -{ - load(); - mHorizont = new HorizontContainer(32, 2); - - mLabel = new Label(mText); - mTextField = new TextField(mValue, true, mParent, mEventName); - mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent); - mWidget = mTextField; - mTextField->setWidth(200); - mHorizont->add(mLabel); - mHorizont->add(mTextField); - mHorizont->add(mButton); - - mParent->getContainer()->add(mHorizont, true, 4); - mParent->addControl(this); - mParent->addControl(this, mEventName + "_EDIT"); - mParent->addControl(this, mEventName + "_EDIT_OK"); - mParent->addActionListener(this); - mWidget->addActionListener(this); - mButton->addActionListener(this); -} - -void SetupItemTextField::fromWidget() -{ - if (!mTextField) - return; - - mValue = mTextField->getText(); -} - -void SetupItemTextField::toWidget() -{ - if (!mTextField) - return; - - mTextField->setText(mValue); -} - -void SetupItemTextField::action(const gcn::ActionEvent &event) -{ - if (!mTextField) - return; - - if (event.getId() == mWidget->getActionEventId()) - { - fromWidget(); - } - else if (event.getId() == mEventName + "_EDIT") - { - mEditDialog = new EditDialog(mText, mTextField->getText(), - mEventName + "_EDIT_OK"); - mEditDialog->addActionListener(this); - } - else if (event.getId() == mEventName + "_EDIT_OK") - { - mTextField->setText(mEditDialog->getMsg()); - mEditDialog = 0; - } -} - -void SetupItemTextField::apply(std::string eventName) -{ - if (eventName != mEventName) - return; - - fromWidget(); - save(); -} - - -SetupItemIntTextField::SetupItemIntTextField(std::string text, - std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, - int min, int max, - bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, mainConfig), - mHorizont(0), - mLabel(0), - mTextField(0), - mButton(0), - mMin(min), - mMax(max), - mEditDialog(0) -{ - mValueType = VSTR; - createControls(); -} - -SetupItemIntTextField::SetupItemIntTextField(std::string text, - std::string description, - std::string keyName, - SetupTabScroll *parent, - std::string eventName, - int min, int max, - std::string def, - bool mainConfig) : - SetupItem(text, description, keyName, parent, eventName, def, mainConfig), - mHorizont(0), - mLabel(0), - mTextField(0), - mButton(0), - mMin(min), - mMax(max), - mEditDialog(0) -{ - mValueType = VSTR; - createControls(); -} - -SetupItemIntTextField::~SetupItemIntTextField() -{ - mHorizont = 0; - mWidget = 0; - mTextField = 0; - mLabel = 0; - mButton = 0; -} - -void SetupItemIntTextField::createControls() -{ - load(); - mHorizont = new HorizontContainer(32, 2); - - mLabel = new Label(mText); - mTextField = new IntTextField(atoi(mValue.c_str()), mMin, mMax, true, 30); - mTextField->setActionEventId(mEventName); - mTextField->addActionListener(mParent); - - mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent); - mWidget = mTextField; - mTextField->setWidth(50); - mHorizont->add(mLabel); - mHorizont->add(mTextField); - mHorizont->add(mButton); - - mParent->getContainer()->add(mHorizont, true, 4); - mParent->addControl(this); - mParent->addControl(this, mEventName + "_EDIT"); - mParent->addControl(this, mEventName + "_EDIT_OK"); - mParent->addActionListener(this); - mWidget->addActionListener(this); - mButton->addActionListener(this); -} - -void SetupItemIntTextField::fromWidget() -{ - if (!mTextField) - return; - - mValue = mTextField->getText(); -} - -void SetupItemIntTextField::toWidget() -{ - if (!mTextField) - return; - - mTextField->setText(mValue); -} - -void SetupItemIntTextField::action(const gcn::ActionEvent &event) -{ - if (!mTextField) - return; - - if (event.getId() == mWidget->getActionEventId()) - { - fromWidget(); - } - else if (event.getId() == mEventName + "_EDIT") - { - mEditDialog = new EditDialog(mText, mTextField->getText(), - mEventName + "_EDIT_OK"); - mEditDialog->addActionListener(this); - } - else if (event.getId() == mEventName + "_EDIT_OK") - { - mTextField->setValue(atoi(mEditDialog->getMsg().c_str())); - mEditDialog = 0; - } -} - -void SetupItemIntTextField::apply(std::string eventName) -{ - if (eventName != mEventName) - return; - - fromWidget(); - save(); -} - -SetupItemLabel::SetupItemLabel(std::string text, std::string description, - SetupTabScroll *parent, bool separator) : - SetupItem(text, description, "", parent, "", "", true), - mLabel(0), - mIsSeparator(separator) -{ - mValueType = VNONE; - createControls(); -} - -SetupItemLabel::~SetupItemLabel() -{ - mWidget = 0; - mLabel = 0; -} - -void SetupItemLabel::createControls() -{ - if (mIsSeparator) - { - const std::string str = " \342\200\225\342\200\225\342\200\225" - "\342\200\225\342\200\225 "; - mLabel = new Label(str + mText + str); - } - else - { - mLabel = new Label(mText); - } - - mWidget = mLabel; - mParent->getContainer()->add(mWidget); - mParent->addControl(this); - mParent->addActionListener(this); - mWidget->addActionListener(this); -} - -void SetupItemLabel::fromWidget() -{ -} - -void SetupItemLabel::toWidget() -{ -} - -void SetupItemLabel::action(const gcn::ActionEvent &event A_UNUSED) -{ -} - -void SetupItemLabel::apply(std::string eventName A_UNUSED) -{ -} diff --git a/src/gui/setupitem.h b/src/gui/setupitem.h deleted file mode 100644 index 3396edea3..000000000 --- a/src/gui/setupitem.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program 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 - * any later version. - * - * This program 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 this program. If not, see . - */ - -#ifndef SETUPITEM_H -#define SETUPITEM_H - -#include "gui/widgets/tabbedarea.h" - -#include "guichanfwd.h" - -#include "gui/widgets/setuptabscroll.h" -#include "gui/widgets/window.h" - -#include -#include - -#include - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - -class CheckBox; -class Configuration; -class ContainerPlacer; -class EditDialog; -class HorizontContainer; -class IntTextField; -class Label; -class TextField; - -class SetupItem : public gcn::ActionListener -{ - public: - enum - { - VBOOL = 0, - VSTR, - VINT, - VNONE - }; - - SetupItem(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, bool mainConfig); - - SetupItem(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, std::string def, bool mainConfig); - - ~SetupItem(); - - void load(); - - void save(); - - virtual void fromWidget() = 0; - - virtual void toWidget() = 0; - - void setWidget(gcn::Widget *widget) - { mWidget = widget; } - - gcn::Widget *getWidget() - { return mWidget; } - - Configuration *getConfig(); - - virtual std::string getActionEventId(); - - virtual void action(const gcn::ActionEvent &event); - - virtual void action(); - - virtual void apply(std::string eventName); - - virtual void cancel(std::string eventName); - - virtual void externalUpdated(std::string eventName); -// virtual int add(ContainerPlacer &place, int x, int y, int width); - - bool isMainConfig() - { return mMainConfig; } - - protected: - std::string mText; - - std::string mDescription; - - std::string mKeyName; - - SetupTabScroll *mParent; - - std::string mEventName; - - bool mMainConfig; - - bool mUseDefault; - - std::string mValue; - - std::string mDefault; - - gcn::Widget *mWidget; - - std::list mTempWidgets; - - int mValueType; -}; - -class SetupItemCheckBox : public SetupItem -{ - public: - SetupItemCheckBox(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, bool mainConfig = true); - - SetupItemCheckBox(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, std::string def, - bool mainConfig = true); - - ~SetupItemCheckBox(); - - void createControls(); - - void fromWidget(); - - void toWidget(); - - protected: - CheckBox *mCheckBox; -}; - -class SetupItemTextField : public SetupItem -{ - public: - SetupItemTextField(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, bool mainConfig = true); - - SetupItemTextField(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, std::string def, - bool mainConfig = true); - - ~SetupItemTextField(); - - void createControls(); - - void fromWidget(); - - void toWidget(); - - void action(const gcn::ActionEvent &event); - - void apply(std::string eventName); - - protected: - HorizontContainer *mHorizont; - Label *mLabel; - TextField *mTextField; - Button *mButton; - EditDialog *mEditDialog; -}; - -class SetupItemIntTextField : public SetupItem -{ - public: - SetupItemIntTextField(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, int min, int max, - bool mainConfig = true); - - SetupItemIntTextField(std::string text, std::string description, - std::string keyName, SetupTabScroll *parent, - std::string eventName, int min, int max, - std::string def, bool mainConfig = true); - - ~SetupItemIntTextField(); - - void createControls(); - - void fromWidget(); - - void toWidget(); - - void action(const gcn::ActionEvent &event); - - void apply(std::string eventName); - - protected: - HorizontContainer *mHorizont; - Label *mLabel; - IntTextField *mTextField; - Button *mButton; - int mMin; - int mMax; - EditDialog *mEditDialog; -}; - -class SetupItemLabel : public SetupItem -{ - public: - SetupItemLabel(std::string text, std::string description, - SetupTabScroll *parent, bool separator = true); - - ~SetupItemLabel(); - - void createControls(); - - void fromWidget(); - - void toWidget(); - - void action(const gcn::ActionEvent &event); - - void apply(std::string eventName); - - protected: - Label *mLabel; - bool mIsSeparator; -}; - -#endif diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp new file mode 100644 index 000000000..fd2c937dc --- /dev/null +++ b/src/gui/widgets/setupitem.cpp @@ -0,0 +1,507 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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 + * any later version. + * + * This program 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 this program. If not, see . + */ + +#include "gui/widgets/setupitem.h" + +#include "configuration.h" +#include "main.h" +#include "logger.h" + +#include "gui/editdialog.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/checkbox.h" +#include "gui/widgets/horizontcontainer.h" +#include "gui/widgets/inttextfield.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/tabbedarea.h" +#include "gui/widgets/textfield.h" +#include "gui/widgets/vertcontainer.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" + + +SetupItem::SetupItem(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, bool mainConfig) : + mText(text), + mDescription(description), + mKeyName(keyName), + mParent(parent), + mEventName(eventName), + mMainConfig(mainConfig), + mUseDefault(false), + mValue(""), + mDefault(""), + mWidget(0), + mValueType(VBOOL) +{ +} + +SetupItem::SetupItem(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, std::string def, bool mainConfig) : + mText(text), + mDescription(description), + mKeyName(keyName), + mParent(parent), + mEventName(eventName), + mMainConfig(mainConfig), + mUseDefault(true), + mValue(""), + mDefault(def), + mWidget(0), + mValueType(VBOOL) +{ +} + +SetupItem::~SetupItem() +{ + +} + +Configuration *SetupItem::getConfig() +{ + if (mMainConfig) + return &config; + else + return &serverConfig; +} + +void SetupItem::load() +{ + Configuration *cfg = getConfig(); + if (mUseDefault) + { + mValue = cfg->getValue(mKeyName, mDefault); + } + else + { + switch (mValueType) + { + case VBOOL: + if (cfg->getBoolValue(mKeyName)) + mValue = "1"; + else + mValue = "0"; + break; + case VSTR: + default: + mValue = cfg->getStringValue(mKeyName); + break; + case VINT: + mValue = toString(cfg->getIntValue(mKeyName)); + break; + case VNONE: + break; + } + } +} + +void SetupItem::save() +{ + Configuration *cfg = getConfig(); + cfg->setValue(mKeyName, mValue); +} + +std::string SetupItem::getActionEventId() +{ + if (!mWidget) + return ""; + + return mWidget->getActionEventId(); +} + +void SetupItem::action(const gcn::ActionEvent &event) +{ + if (!mWidget) + return; + + if (event.getId() == mWidget->getActionEventId()) + action(); +} + +void SetupItem::action() +{ + fromWidget(); +} + +void SetupItem::apply(std::string eventName A_UNUSED) +{ + save(); +} + +void SetupItem::cancel(std::string eventName A_UNUSED) +{ + load(); + toWidget(); +} + +void SetupItem::externalUpdated(std::string eventName A_UNUSED) +{ + load(); + toWidget(); +} + +SetupItemCheckBox::SetupItemCheckBox(std::string text, std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig) +{ + createControls(); +} + +SetupItemCheckBox::SetupItemCheckBox(std::string text, std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, std::string def, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig) +{ + createControls(); +} + +SetupItemCheckBox::~SetupItemCheckBox() +{ + mWidget = 0; +} + +void SetupItemCheckBox::createControls() +{ + load(); + mCheckBox = new CheckBox(mText, mValue != "0", mParent, mEventName); + mWidget = mCheckBox; + mParent->getContainer()->add(mWidget); + mParent->addControl(this); + mParent->addActionListener(this); + mWidget->addActionListener(this); +} + +void SetupItemCheckBox::fromWidget() +{ + if (!mCheckBox) + return; + + if (mCheckBox->isSelected()) + mValue = "1"; + else + mValue = "0"; +} + +void SetupItemCheckBox::toWidget() +{ + if (!mCheckBox) + return; + + mCheckBox->setSelected(mValue != "0"); +} + + +SetupItemTextField::SetupItemTextField(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig), + mHorizont(0), + mLabel(0), + mTextField(0), + mButton(0), + mEditDialog(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemTextField::SetupItemTextField(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, std::string def, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig), + mHorizont(0), + mLabel(0), + mTextField(0), + mButton(0), + mEditDialog(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemTextField::~SetupItemTextField() +{ + mHorizont = 0; + mWidget = 0; + mTextField = 0; + mLabel = 0; + mButton = 0; +} + +void SetupItemTextField::createControls() +{ + load(); + mHorizont = new HorizontContainer(32, 2); + + mLabel = new Label(mText); + mTextField = new TextField(mValue, true, mParent, mEventName); + mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent); + mWidget = mTextField; + mTextField->setWidth(200); + mHorizont->add(mLabel); + mHorizont->add(mTextField); + mHorizont->add(mButton); + + mParent->getContainer()->add(mHorizont, true, 4); + mParent->addControl(this); + mParent->addControl(this, mEventName + "_EDIT"); + mParent->addControl(this, mEventName + "_EDIT_OK"); + mParent->addActionListener(this); + mWidget->addActionListener(this); + mButton->addActionListener(this); +} + +void SetupItemTextField::fromWidget() +{ + if (!mTextField) + return; + + mValue = mTextField->getText(); +} + +void SetupItemTextField::toWidget() +{ + if (!mTextField) + return; + + mTextField->setText(mValue); +} + +void SetupItemTextField::action(const gcn::ActionEvent &event) +{ + if (!mTextField) + return; + + if (event.getId() == mWidget->getActionEventId()) + { + fromWidget(); + } + else if (event.getId() == mEventName + "_EDIT") + { + mEditDialog = new EditDialog(mText, mTextField->getText(), + mEventName + "_EDIT_OK"); + mEditDialog->addActionListener(this); + } + else if (event.getId() == mEventName + "_EDIT_OK") + { + mTextField->setText(mEditDialog->getMsg()); + mEditDialog = 0; + } +} + +void SetupItemTextField::apply(std::string eventName) +{ + if (eventName != mEventName) + return; + + fromWidget(); + save(); +} + + +SetupItemIntTextField::SetupItemIntTextField(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + int min, int max, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig), + mHorizont(0), + mLabel(0), + mTextField(0), + mButton(0), + mMin(min), + mMax(max), + mEditDialog(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemIntTextField::SetupItemIntTextField(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + int min, int max, + std::string def, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig), + mHorizont(0), + mLabel(0), + mTextField(0), + mButton(0), + mMin(min), + mMax(max), + mEditDialog(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemIntTextField::~SetupItemIntTextField() +{ + mHorizont = 0; + mWidget = 0; + mTextField = 0; + mLabel = 0; + mButton = 0; +} + +void SetupItemIntTextField::createControls() +{ + load(); + mHorizont = new HorizontContainer(32, 2); + + mLabel = new Label(mText); + mTextField = new IntTextField(atoi(mValue.c_str()), mMin, mMax, true, 30); + mTextField->setActionEventId(mEventName); + mTextField->addActionListener(mParent); + + mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent); + mWidget = mTextField; + mTextField->setWidth(50); + mHorizont->add(mLabel); + mHorizont->add(mTextField); + mHorizont->add(mButton); + + mParent->getContainer()->add(mHorizont, true, 4); + mParent->addControl(this); + mParent->addControl(this, mEventName + "_EDIT"); + mParent->addControl(this, mEventName + "_EDIT_OK"); + mParent->addActionListener(this); + mWidget->addActionListener(this); + mButton->addActionListener(this); +} + +void SetupItemIntTextField::fromWidget() +{ + if (!mTextField) + return; + + mValue = mTextField->getText(); +} + +void SetupItemIntTextField::toWidget() +{ + if (!mTextField) + return; + + mTextField->setText(mValue); +} + +void SetupItemIntTextField::action(const gcn::ActionEvent &event) +{ + if (!mTextField) + return; + + if (event.getId() == mWidget->getActionEventId()) + { + fromWidget(); + } + else if (event.getId() == mEventName + "_EDIT") + { + mEditDialog = new EditDialog(mText, mTextField->getText(), + mEventName + "_EDIT_OK"); + mEditDialog->addActionListener(this); + } + else if (event.getId() == mEventName + "_EDIT_OK") + { + mTextField->setValue(atoi(mEditDialog->getMsg().c_str())); + mEditDialog = 0; + } +} + +void SetupItemIntTextField::apply(std::string eventName) +{ + if (eventName != mEventName) + return; + + fromWidget(); + save(); +} + +SetupItemLabel::SetupItemLabel(std::string text, std::string description, + SetupTabScroll *parent, bool separator) : + SetupItem(text, description, "", parent, "", "", true), + mLabel(0), + mIsSeparator(separator) +{ + mValueType = VNONE; + createControls(); +} + +SetupItemLabel::~SetupItemLabel() +{ + mWidget = 0; + mLabel = 0; +} + +void SetupItemLabel::createControls() +{ + if (mIsSeparator) + { + const std::string str = " \342\200\225\342\200\225\342\200\225" + "\342\200\225\342\200\225 "; + mLabel = new Label(str + mText + str); + } + else + { + mLabel = new Label(mText); + } + + mWidget = mLabel; + mParent->getContainer()->add(mWidget); + mParent->addControl(this); + mParent->addActionListener(this); + mWidget->addActionListener(this); +} + +void SetupItemLabel::fromWidget() +{ +} + +void SetupItemLabel::toWidget() +{ +} + +void SetupItemLabel::action(const gcn::ActionEvent &event A_UNUSED) +{ +} + +void SetupItemLabel::apply(std::string eventName A_UNUSED) +{ +} diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h new file mode 100644 index 000000000..3396edea3 --- /dev/null +++ b/src/gui/widgets/setupitem.h @@ -0,0 +1,244 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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 + * any later version. + * + * This program 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 this program. If not, see . + */ + +#ifndef SETUPITEM_H +#define SETUPITEM_H + +#include "gui/widgets/tabbedarea.h" + +#include "guichanfwd.h" + +#include "gui/widgets/setuptabscroll.h" +#include "gui/widgets/window.h" + +#include +#include + +#include + +#ifdef __GNUC__ +#define A_UNUSED __attribute__ ((unused)) +#else +#define A_UNUSED +#endif + +class CheckBox; +class Configuration; +class ContainerPlacer; +class EditDialog; +class HorizontContainer; +class IntTextField; +class Label; +class TextField; + +class SetupItem : public gcn::ActionListener +{ + public: + enum + { + VBOOL = 0, + VSTR, + VINT, + VNONE + }; + + SetupItem(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, bool mainConfig); + + SetupItem(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, std::string def, bool mainConfig); + + ~SetupItem(); + + void load(); + + void save(); + + virtual void fromWidget() = 0; + + virtual void toWidget() = 0; + + void setWidget(gcn::Widget *widget) + { mWidget = widget; } + + gcn::Widget *getWidget() + { return mWidget; } + + Configuration *getConfig(); + + virtual std::string getActionEventId(); + + virtual void action(const gcn::ActionEvent &event); + + virtual void action(); + + virtual void apply(std::string eventName); + + virtual void cancel(std::string eventName); + + virtual void externalUpdated(std::string eventName); +// virtual int add(ContainerPlacer &place, int x, int y, int width); + + bool isMainConfig() + { return mMainConfig; } + + protected: + std::string mText; + + std::string mDescription; + + std::string mKeyName; + + SetupTabScroll *mParent; + + std::string mEventName; + + bool mMainConfig; + + bool mUseDefault; + + std::string mValue; + + std::string mDefault; + + gcn::Widget *mWidget; + + std::list mTempWidgets; + + int mValueType; +}; + +class SetupItemCheckBox : public SetupItem +{ + public: + SetupItemCheckBox(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, bool mainConfig = true); + + SetupItemCheckBox(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, std::string def, + bool mainConfig = true); + + ~SetupItemCheckBox(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + protected: + CheckBox *mCheckBox; +}; + +class SetupItemTextField : public SetupItem +{ + public: + SetupItemTextField(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, bool mainConfig = true); + + SetupItemTextField(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, std::string def, + bool mainConfig = true); + + ~SetupItemTextField(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + protected: + HorizontContainer *mHorizont; + Label *mLabel; + TextField *mTextField; + Button *mButton; + EditDialog *mEditDialog; +}; + +class SetupItemIntTextField : public SetupItem +{ + public: + SetupItemIntTextField(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, int min, int max, + bool mainConfig = true); + + SetupItemIntTextField(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, int min, int max, + std::string def, bool mainConfig = true); + + ~SetupItemIntTextField(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + protected: + HorizontContainer *mHorizont; + Label *mLabel; + IntTextField *mTextField; + Button *mButton; + int mMin; + int mMax; + EditDialog *mEditDialog; +}; + +class SetupItemLabel : public SetupItem +{ + public: + SetupItemLabel(std::string text, std::string description, + SetupTabScroll *parent, bool separator = true); + + ~SetupItemLabel(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + protected: + Label *mLabel; + bool mIsSeparator; +}; + +#endif diff --git a/src/gui/widgets/setuptabscroll.cpp b/src/gui/widgets/setuptabscroll.cpp index 805c0c8c7..30bb66469 100644 --- a/src/gui/widgets/setuptabscroll.cpp +++ b/src/gui/widgets/setuptabscroll.cpp @@ -20,10 +20,9 @@ #include "gui/widgets/setuptabscroll.h" -#include "gui/setupitem.h" - #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/setupitem.h" #include "gui/widgets/vertcontainer.h" #include "debug.h" -- cgit v1.2.3-70-g09d2