diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-08-19 15:01:07 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-11-01 10:04:03 (GMT) |
commit | 8a3c7ff2ac1b615ed8f891814f5b3980b8327aae (patch) | |
tree | c0da38ddd391db2b2afd50c2bd569c306c677b4d /util/MenuConvertor.hh | |
parent | 18e8f7cd9906728864ecc3e25b2ab3e29070ec8a (diff) | |
download | fluxbox_paul-8a3c7ff2ac1b615ed8f891814f5b3980b8327aae.zip fluxbox_paul-8a3c7ff2ac1b615ed8f891814f5b3980b8327aae.tar.bz2 |
fluxbox-update_configs: automatically update menu file
To achieve this, I had to partially resurrect (and heavily modify) the old parsing code in
MenuCreator.cc.
Diffstat (limited to 'util/MenuConvertor.hh')
-rw-r--r-- | util/MenuConvertor.hh | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/util/MenuConvertor.hh b/util/MenuConvertor.hh new file mode 100644 index 0000000..bf9f292 --- /dev/null +++ b/util/MenuConvertor.hh | |||
@@ -0,0 +1,78 @@ | |||
1 | // MenuConvertor.hh for Fluxbox | ||
2 | // Copyright (c) 2004 Henrik Kinnunen (fluxgen at fluxbox dot org) | ||
3 | // and Simon Bowden (rathnor at users.sourceforge.net) | ||
4 | // | ||
5 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
6 | // copy of this software and associated documentation files (the "Software"), | ||
7 | // to deal in the Software without restriction, including without limitation | ||
8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
9 | // and/or sell copies of the Software, and to permit persons to whom the | ||
10 | // Software is furnished to do so, subject to the following conditions: | ||
11 | // | ||
12 | // The above copyright notice and this permission notice shall be included in | ||
13 | // all copies or substantial portions of the Software. | ||
14 | // | ||
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
21 | // DEALINGS IN THE SOFTWARE. | ||
22 | |||
23 | #ifndef MENUCREATOR_HH | ||
24 | #define MENUCREATOR_HH | ||
25 | |||
26 | #include <list> | ||
27 | |||
28 | #include "FbTk/FbString.hh" | ||
29 | |||
30 | #include "FbMenuParser.hh" | ||
31 | |||
32 | class Menu { | ||
33 | public: | ||
34 | void load(FbMenuParser &p, FbTk::StringConvertor &m_labelconvertor) { | ||
35 | p>>m_key>>m_label>>m_cmd>>m_icon; | ||
36 | m_label.second = m_labelconvertor.recode(m_label.second); | ||
37 | } | ||
38 | std::string &icon() { return m_icon.second; } | ||
39 | std::string &command() { return m_cmd.second; } | ||
40 | std::string &label() { return m_label.second; } | ||
41 | std::string &key() { return m_key.second; } | ||
42 | |||
43 | std::list<Menu> entries; // for submenus | ||
44 | std::string program; // for wallpaper menu entries | ||
45 | |||
46 | void write(std::ostream &o, unsigned level = 0); | ||
47 | private: | ||
48 | FbMenuParser::Item m_key, m_label, m_cmd, m_icon; | ||
49 | }; | ||
50 | |||
51 | class MenuConvertor { | ||
52 | public: | ||
53 | static bool createFromFile(const std::string &filename, | ||
54 | Menu &inject_into, | ||
55 | bool begin = true); | ||
56 | |||
57 | /** | ||
58 | * Encoding-related helpers (encoding, aka codeset) | ||
59 | */ | ||
60 | |||
61 | // Files are guaranteed to be "balanced", unlike user-created [encoding] tags. | ||
62 | static void startFile(); | ||
63 | static void endFile(); | ||
64 | |||
65 | static void startEncoding(const std::string &encoding); | ||
66 | static void endEncoding(); | ||
67 | |||
68 | private: | ||
69 | // stack of encodings | ||
70 | static std::list<std::string> encoding_stack; | ||
71 | // stack of ints, representing stack size as each file is entered | ||
72 | // (a file should never end more encodings than it starts) | ||
73 | static std::list<size_t> stacksize_stack; | ||
74 | |||
75 | static FbTk::StringConvertor m_stringconvertor; | ||
76 | }; | ||
77 | |||
78 | #endif // MENUCREATOR_HH | ||