diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-06-15 04:12:11 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-06-15 04:12:11 +0300 |
commit | 9e8ae9ad161c7dc587ed8e06566bb3e8aed6bfe9 (patch) | |
tree | 4e2e6dfe772408a6837a3f0d214148aeaec762b3 /src/gui | |
parent | f53e001120632302d214c9b90c373019448a889b (diff) | |
download | mv-9e8ae9ad161c7dc587ed8e06566bb3e8aed6bfe9.tar.gz mv-9e8ae9ad161c7dc587ed8e06566bb3e8aed6bfe9.tar.bz2 mv-9e8ae9ad161c7dc587ed8e06566bb3e8aed6bfe9.tar.xz mv-9e8ae9ad161c7dc587ed8e06566bb3e8aed6bfe9.zip |
Add option to use local time in chat.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/setup_chat.cpp | 16 | ||||
-rw-r--r-- | src/gui/setup_chat.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/chattab.cpp | 28 |
3 files changed, 37 insertions, 10 deletions
diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index 4d9bc9876..4dd5feefc 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -57,6 +57,7 @@ #define ACTION_ENABLE_BATTLE_TAB "show battle tab" #define ACTION_SHOW_BATTLE_EVENTS "show battle events" #define ACTION_RESIZE_CHAT "resize chat" +#define ACTION_LOCAL_TIME "local time" Setup_Chat::Setup_Chat() : mEditDialog(0) @@ -134,6 +135,10 @@ Setup_Chat::Setup_Chat() : mHideChatInputCheckBox = new CheckBox(_("Resize chat tabs if need"), mHideChatInput, this, ACTION_RESIZE_CHAT); + mLocalTime = config.getBoolValue("useLocalTime"); + mLocalTimeCheckBox = new CheckBox(_("Use local time"), + mLocalTime, this, ACTION_LOCAL_TIME); + // Do the layout LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); @@ -156,6 +161,7 @@ Setup_Chat::Setup_Chat() : place(0, 11, mEnableBattleTabCheckBox, 10); place(0, 12, mShowBattleEventsCheckBox, 10); place(0, 13, mHideChatInputCheckBox, 10); + place(0, 14, mLocalTimeCheckBox, 10); place.getCell().matchColWidth(0, 0); place = h.getPlacer(0, 1); @@ -244,6 +250,10 @@ void Setup_Chat::action(const gcn::ActionEvent &event) { mHideChatInput = mHideChatInputCheckBox->isSelected(); } + else if (event.getId() == ACTION_LOCAL_TIME) + { + mLocalTime = mLocalTimeCheckBox->isSelected(); + } } void Setup_Chat::cancel() @@ -296,6 +306,9 @@ void Setup_Chat::cancel() mHideChatInput = config.getBoolValue("hideChatInput"); mHideChatInputCheckBox->setSelected(mHideChatInput); + + mLocalTime = config.getBoolValue("useLocalTime"); + mLocalTimeCheckBox->setSelected(mLocalTime); } void Setup_Chat::apply() @@ -319,8 +332,9 @@ void Setup_Chat::apply() config.setValue("showChatHistory", mShowChatHistory); config.setValue("enableBattleTab", mEnableBattleTab); config.setValue("showBattleEvents", mShowBattleEvents); - config.setValue("hideChatInput", mHideChatInput); + config.setValue("useLocalTime", mLocalTime); + if (chatWindow) chatWindow->adjustTabSize(); } diff --git a/src/gui/setup_chat.h b/src/gui/setup_chat.h index 2a6e5b183..db1472e9c 100644 --- a/src/gui/setup_chat.h +++ b/src/gui/setup_chat.h @@ -89,6 +89,9 @@ class Setup_Chat : public SetupTab, public gcn::ActionListener gcn::CheckBox *mHideChatInputCheckBox; bool mHideChatInput; + gcn::CheckBox *mLocalTimeCheckBox; + bool mLocalTime; + EditDialog *mEditDialog; }; diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 76f74dec8..3f2166de0 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -221,15 +221,25 @@ void ChatTab::chatLog(std::string line, Own own, time_t t; time(&t); - // Format the time string properly - std::stringstream timeStr; - timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast<int>(((t / 60) / 60) % 24) - << ":" << (((t / 60) % 60 < 10) ? "0" : "") - << static_cast<int>((t / 60) % 60) - << "] "; - - line = lineColor + timeStr.str() + tmp.nick + tmp.text; + if (config.getBoolValue("useLocalTime")) + { + struct tm *timeInfo; + timeInfo = localtime(&t); + line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(), + timeInfo->tm_hour, timeInfo->tm_min, tmp.nick.c_str(), + tmp.text.c_str()); + } + else + { + // Format the time string properly + std::stringstream timeStr; + timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "") + << static_cast<int>(((t / 60) / 60) % 24) + << ":" << (((t / 60) % 60 < 10) ? "0" : "") + << static_cast<int>((t / 60) % 60) + << "] "; + line = lineColor + timeStr.str() + tmp.nick + tmp.text; + } if (config.getBoolValue("enableChatLog")) saveToLogFile(line); |