all repos — fluxbox @ 95d565ba62df3bd98aa026a98b9d3d6d8d6a509e

custom fork of the fluxbox windowmanager

toggle clock format via menu
fluxgen fluxgen
commit

95d565ba62df3bd98aa026a98b9d3d6d8d6a509e

parent

29beda2d6be3eb6ccf849d7454a804fb966e7ccb

3 files changed, 78 insertions(+), 7 deletions(-)

jump to
M src/ClockTool.ccsrc/ClockTool.cc

@@ -20,7 +20,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ClockTool.cc,v 1.5 2003/08/15 15:30:18 fluxgen Exp $ +// $Id: ClockTool.cc,v 1.6 2003/12/04 23:02:23 fluxgen Exp $ #include "ClockTool.hh"

@@ -29,6 +29,8 @@ #include "Screen.hh"

#include "FbTk/SimpleCommand.hh" #include "FbTk/ImageControl.hh" +#include "FbTk/Menu.hh" +#include "FbTk/MenuItem.hh" #ifdef HAVE_CONFIG_H #include "config.h"

@@ -36,8 +38,68 @@ #endif // HAVE_CONFIG_H

#include <ctime> +class ClockMenuItem: public FbTk::MenuItem { +public: + ClockMenuItem::ClockMenuItem(ClockTool &tool): + FbTk::MenuItem(""), m_tool(tool) { + // determine 12/24 hour format + if (m_tool.timeFormat().find("%k") != std::string::npos || + m_tool.timeFormat().find("%H") != std::string::npos || + m_tool.timeFormat().find("%T") != std::string::npos) + setLabel("Clock: 24h"); + else + setLabel("Clock: 12h"); + } + + void click(int button, int time) { + std::string newformat = m_tool.timeFormat(); + size_t pos = newformat.find("%k"); + std::string newstr; + bool clock24hour = true; + if (pos != std::string::npos) + newstr = "%l"; + else if ((pos = newformat.find("%H")) != std::string::npos) + newstr = "%I"; + else if ((pos = newformat.find("%T")) != std::string::npos) + newstr = "%r"; + + // 12 hour + if (newstr.empty()) { + clock24hour = false; + if ((pos = newformat.find("%l")) != std::string::npos) + newstr = "%k"; + else if ((pos = newformat.find("%I")) != std::string::npos) + newstr = "%H"; + else if ((pos = newformat.find("%r")) != std::string::npos) + newstr = "%T"; + + } + + if (!newstr.empty()) { + + newformat.replace(pos, 2, newstr); + if (!clock24hour) { // erase %P/%p (AM|PM / am|pm) + pos = newformat.find("%p"); + if (pos != std::string::npos) + newformat.erase(pos, 2); + else if ((pos = newformat.find("%P")) != std::string::npos) + newformat.erase(pos, 2); + } + if (clock24hour) + setLabel("Clock: 24h"); + else + setLabel("Clock: 12h"); + + m_tool.setTimeFormat(newformat); + } // else some other strange format...so we don't do anything + FbTk::MenuItem::click(button, time); + } +private: + ClockTool &m_tool; +}; + ClockTool::ClockTool(const FbTk::FbWindow &parent, - ToolTheme &theme, BScreen &screen): + ToolTheme &theme, BScreen &screen, FbTk::Menu &menu): ToolbarItem(ToolbarItem::FIXED), m_button(parent, theme.font(), ""), m_theme(theme),

@@ -59,7 +121,7 @@ m_timer.setCommand(update_graphic);

m_timer.start(); m_button.setGC(m_theme.textGC()); - + menu.insert(new ClockMenuItem(*this)); update(0); }

@@ -90,6 +152,11 @@ }

void ClockTool::hide() { m_button.hide(); +} + +void ClockTool::setTimeFormat(const std::string &format) { + *m_timeformat = format; + update(0); } void ClockTool::update(FbTk::Subject *subj) {
M src/ClockTool.hhsrc/ClockTool.hh

@@ -20,7 +20,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ClockTool.hh,v 1.3 2003/08/19 16:12:43 fluxgen Exp $ +// $Id: ClockTool.hh,v 1.4 2003/12/04 23:02:23 fluxgen Exp $ #ifndef CLOCKTOOL_HH #define CLOCKTOOL_HH

@@ -41,11 +41,12 @@

namespace FbTk { class ImageControl; class Subject; +class Menu; } class ClockTool:public ToolbarItem, public FbTk::Observer { public: - ClockTool(const FbTk::FbWindow &parent, ToolTheme &theme, BScreen &screen); + ClockTool(const FbTk::FbWindow &parent, ToolTheme &theme, BScreen &screen, FbTk::Menu &menu); virtual ~ClockTool(); void move(int x, int y);

@@ -55,9 +56,12 @@ unsigned int width, unsigned int height);

void show(); void hide(); + void setTimeFormat(const std::string &format); + // accessors unsigned int width() const; unsigned int height() const; unsigned int borderWidth() const; + inline const std::string &timeFormat() const { return *m_timeformat; } private: void updateTime(); void update(FbTk::Subject *subj);
M src/ToolFactory.ccsrc/ToolFactory.cc

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ToolFactory.cc,v 1.1 2003/10/13 23:37:41 fluxgen Exp $ +// $Id: ToolFactory.cc,v 1.2 2003/12/04 23:02:23 fluxgen Exp $ #include "ToolFactory.hh"

@@ -100,7 +100,7 @@ screen(), tbar.menu());

} else if (name == "systemtray") { return new SystemTray(parent); } else if (name == "clock") { - return new ClockTool(parent, m_clock_theme, screen()); + return new ClockTool(parent, m_clock_theme, screen(), tbar.menu()); } else if (name == "nextworkspace" || name == "prevworkspace") {