summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-12-04 23:02:23 (GMT)
committerfluxgen <fluxgen>2003-12-04 23:02:23 (GMT)
commit95d565ba62df3bd98aa026a98b9d3d6d8d6a509e (patch)
tree0a4f59b0efec4d1f9cb911255b8a3d461860aa45
parent29beda2d6be3eb6ccf849d7454a804fb966e7ccb (diff)
downloadfluxbox_lack-95d565ba62df3bd98aa026a98b9d3d6d8d6a509e.zip
fluxbox_lack-95d565ba62df3bd98aa026a98b9d3d6d8d6a509e.tar.bz2
toggle clock format via menu
-rw-r--r--src/ClockTool.cc73
-rw-r--r--src/ClockTool.hh8
-rw-r--r--src/ToolFactory.cc4
3 files changed, 78 insertions, 7 deletions
diff --git a/src/ClockTool.cc b/src/ClockTool.cc
index cc74b35..4120749 100644
--- a/src/ClockTool.cc
+++ b/src/ClockTool.cc
@@ -20,7 +20,7 @@
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE. 21// DEALINGS IN THE SOFTWARE.
22 22
23// $Id: ClockTool.cc,v 1.5 2003/08/15 15:30:18 fluxgen Exp $ 23// $Id: ClockTool.cc,v 1.6 2003/12/04 23:02:23 fluxgen Exp $
24 24
25#include "ClockTool.hh" 25#include "ClockTool.hh"
26 26
@@ -29,6 +29,8 @@
29 29
30#include "FbTk/SimpleCommand.hh" 30#include "FbTk/SimpleCommand.hh"
31#include "FbTk/ImageControl.hh" 31#include "FbTk/ImageControl.hh"
32#include "FbTk/Menu.hh"
33#include "FbTk/MenuItem.hh"
32 34
33#ifdef HAVE_CONFIG_H 35#ifdef HAVE_CONFIG_H
34#include "config.h" 36#include "config.h"
@@ -36,8 +38,68 @@
36 38
37#include <ctime> 39#include <ctime>
38 40
41class ClockMenuItem: public FbTk::MenuItem {
42public:
43 ClockMenuItem::ClockMenuItem(ClockTool &tool):
44 FbTk::MenuItem(""), m_tool(tool) {
45 // determine 12/24 hour format
46 if (m_tool.timeFormat().find("%k") != std::string::npos ||
47 m_tool.timeFormat().find("%H") != std::string::npos ||
48 m_tool.timeFormat().find("%T") != std::string::npos)
49 setLabel("Clock: 24h");
50 else
51 setLabel("Clock: 12h");
52 }
53
54 void click(int button, int time) {
55 std::string newformat = m_tool.timeFormat();
56 size_t pos = newformat.find("%k");
57 std::string newstr;
58 bool clock24hour = true;
59 if (pos != std::string::npos)
60 newstr = "%l";
61 else if ((pos = newformat.find("%H")) != std::string::npos)
62 newstr = "%I";
63 else if ((pos = newformat.find("%T")) != std::string::npos)
64 newstr = "%r";
65
66 // 12 hour
67 if (newstr.empty()) {
68 clock24hour = false;
69 if ((pos = newformat.find("%l")) != std::string::npos)
70 newstr = "%k";
71 else if ((pos = newformat.find("%I")) != std::string::npos)
72 newstr = "%H";
73 else if ((pos = newformat.find("%r")) != std::string::npos)
74 newstr = "%T";
75
76 }
77
78 if (!newstr.empty()) {
79
80 newformat.replace(pos, 2, newstr);
81 if (!clock24hour) { // erase %P/%p (AM|PM / am|pm)
82 pos = newformat.find("%p");
83 if (pos != std::string::npos)
84 newformat.erase(pos, 2);
85 else if ((pos = newformat.find("%P")) != std::string::npos)
86 newformat.erase(pos, 2);
87 }
88 if (clock24hour)
89 setLabel("Clock: 24h");
90 else
91 setLabel("Clock: 12h");
92
93 m_tool.setTimeFormat(newformat);
94 } // else some other strange format...so we don't do anything
95 FbTk::MenuItem::click(button, time);
96 }
97private:
98 ClockTool &m_tool;
99};
100
39ClockTool::ClockTool(const FbTk::FbWindow &parent, 101ClockTool::ClockTool(const FbTk::FbWindow &parent,
40 ToolTheme &theme, BScreen &screen): 102 ToolTheme &theme, BScreen &screen, FbTk::Menu &menu):
41 ToolbarItem(ToolbarItem::FIXED), 103 ToolbarItem(ToolbarItem::FIXED),
42 m_button(parent, theme.font(), ""), 104 m_button(parent, theme.font(), ""),
43 m_theme(theme), 105 m_theme(theme),
@@ -59,7 +121,7 @@ ClockTool::ClockTool(const FbTk::FbWindow &parent,
59 m_timer.start(); 121 m_timer.start();
60 122
61 m_button.setGC(m_theme.textGC()); 123 m_button.setGC(m_theme.textGC());
62 124 menu.insert(new ClockMenuItem(*this));
63 update(0); 125 update(0);
64} 126}
65 127
@@ -92,6 +154,11 @@ void ClockTool::hide() {
92 m_button.hide(); 154 m_button.hide();
93} 155}
94 156
157void ClockTool::setTimeFormat(const std::string &format) {
158 *m_timeformat = format;
159 update(0);
160}
161
95void ClockTool::update(FbTk::Subject *subj) { 162void ClockTool::update(FbTk::Subject *subj) {
96 updateTime(); 163 updateTime();
97 164
diff --git a/src/ClockTool.hh b/src/ClockTool.hh
index 9978f27..70f80cc 100644
--- a/src/ClockTool.hh
+++ b/src/ClockTool.hh
@@ -20,7 +20,7 @@
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE. 21// DEALINGS IN THE SOFTWARE.
22 22
23// $Id: ClockTool.hh,v 1.3 2003/08/19 16:12:43 fluxgen Exp $ 23// $Id: ClockTool.hh,v 1.4 2003/12/04 23:02:23 fluxgen Exp $
24 24
25#ifndef CLOCKTOOL_HH 25#ifndef CLOCKTOOL_HH
26#define CLOCKTOOL_HH 26#define CLOCKTOOL_HH
@@ -41,11 +41,12 @@ class BScreen;
41namespace FbTk { 41namespace FbTk {
42class ImageControl; 42class ImageControl;
43class Subject; 43class Subject;
44class Menu;
44} 45}
45 46
46class ClockTool:public ToolbarItem, public FbTk::Observer { 47class ClockTool:public ToolbarItem, public FbTk::Observer {
47public: 48public:
48 ClockTool(const FbTk::FbWindow &parent, ToolTheme &theme, BScreen &screen); 49 ClockTool(const FbTk::FbWindow &parent, ToolTheme &theme, BScreen &screen, FbTk::Menu &menu);
49 virtual ~ClockTool(); 50 virtual ~ClockTool();
50 51
51 void move(int x, int y); 52 void move(int x, int y);
@@ -55,9 +56,12 @@ public:
55 56
56 void show(); 57 void show();
57 void hide(); 58 void hide();
59 void setTimeFormat(const std::string &format);
60 // accessors
58 unsigned int width() const; 61 unsigned int width() const;
59 unsigned int height() const; 62 unsigned int height() const;
60 unsigned int borderWidth() const; 63 unsigned int borderWidth() const;
64 inline const std::string &timeFormat() const { return *m_timeformat; }
61private: 65private:
62 void updateTime(); 66 void updateTime();
63 void update(FbTk::Subject *subj); 67 void update(FbTk::Subject *subj);
diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc
index 24ab499..522c339 100644
--- a/src/ToolFactory.cc
+++ b/src/ToolFactory.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: ToolFactory.cc,v 1.1 2003/10/13 23:37:41 fluxgen Exp $ 22// $Id: ToolFactory.cc,v 1.2 2003/12/04 23:02:23 fluxgen Exp $
23 23
24#include "ToolFactory.hh" 24#include "ToolFactory.hh"
25 25
@@ -100,7 +100,7 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &
100 } else if (name == "systemtray") { 100 } else if (name == "systemtray") {
101 return new SystemTray(parent); 101 return new SystemTray(parent);
102 } else if (name == "clock") { 102 } else if (name == "clock") {
103 return new ClockTool(parent, m_clock_theme, screen()); 103 return new ClockTool(parent, m_clock_theme, screen(), tbar.menu());
104 } else if (name == "nextworkspace" || 104 } else if (name == "nextworkspace" ||
105 name == "prevworkspace") { 105 name == "prevworkspace") {
106 106