aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathias <mathias>2004-12-18 01:29:22 (GMT)
committermathias <mathias>2004-12-18 01:29:22 (GMT)
commitb3fa5c242881b55a76c0e25b3cebaf15d0744f69 (patch)
treebcdb8e0df23428f3f3107e27e6af008d6a0409cc /src
parent6458b1b485c7481da6d2d1bf235b44fe3b700bd3 (diff)
downloadfluxbox-b3fa5c242881b55a76c0e25b3cebaf15d0744f69.zip
fluxbox-b3fa5c242881b55a76c0e25b3cebaf15d0744f69.tar.bz2
* moved FbTk/Directory.cc/hh over to FbTk/FileUtil.cc/hh which contain now
file and directory - helproutines. * created the FileUtil-namespace which contains file-related functions, moved those functions out of Directory - code * changes to the rest of the files to follow those changes
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/FileUtil.cc (renamed from src/FbTk/Directory.cc)88
-rw-r--r--src/FbTk/FileUtil.hh (renamed from src/FbTk/Directory.hh)52
-rw-r--r--src/FbTk/Makefile.am2
-rw-r--r--src/FbTk/Theme.cc8
-rw-r--r--src/MenuCreator.cc68
-rw-r--r--src/fluxbox.cc64
6 files changed, 162 insertions, 120 deletions
diff --git a/src/FbTk/Directory.cc b/src/FbTk/FileUtil.cc
index 0535dc0..b70eff3 100644
--- a/src/FbTk/Directory.cc
+++ b/src/FbTk/FileUtil.cc
@@ -1,5 +1,5 @@
1// Directory.cc 1// FileUtil.cc
2// Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) 2// Copyright (c) 2002 - 2004 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3// 3//
4// Permission is hereby granted, free of charge, to any person obtaining a 4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"), 5// copy of this software and associated documentation files (the "Software"),
@@ -21,13 +21,70 @@
21 21
22// $Id$ 22// $Id$
23 23
24#include "Directory.hh" 24#include "FileUtil.hh"
25 25
26#include <sys/stat.h> 26#include <sys/stat.h>
27#include <unistd.h> 27#include <unistd.h>
28 28
29#include <iostream>
30#include <fstream>
31
32using std::ifstream;
33using std::ofstream;
34using std::cerr;
35using std::endl;
36
29namespace FbTk { 37namespace FbTk {
30 38
39time_t FileUtil::getLastStatusChangeTimestamp(const char* filename) {
40 struct stat buf;
41 if (filename && !stat(filename, &buf)) {
42 return buf.st_ctime;
43 } else
44 return (time_t)-1;
45}
46
47bool FileUtil::isDirectory(const char* filename) {
48 struct stat buf;
49 if (!filename || stat(filename, &buf))
50 return false;
51
52 return S_ISDIR(buf.st_mode);
53}
54
55bool FileUtil::isRegularFile(const char* filename) {
56 struct stat buf;
57 if (!filename || stat(filename, &buf))
58 return false;
59
60 return S_ISREG(buf.st_mode);
61}
62
63bool FileUtil::isExecutable(const char* filename) {
64 struct stat buf;
65 if (!filename || !stat(filename, &buf))
66 return false;
67
68 return buf.st_mode & S_IXUSR ||
69 buf.st_mode & S_IXGRP ||
70 buf.st_mode & S_IXOTH;
71}
72
73bool FileUtil::copyFile(const char* from, const char* to) {
74 ifstream from_file(from);
75 ofstream to_file(to);
76
77 if (!to_file.good())
78 cerr << "Can't write file '"<<to<<"'."<<endl;
79 else if (from_file.good()) {
80 to_file<<from_file.rdbuf();
81 return true;
82 } else
83 cerr << "Can't copy from '"<<from<<"' to '"<<to<<"'."<<endl;
84
85 return false;
86}
87
31Directory::Directory(const char *dir):m_dir(0), 88Directory::Directory(const char *dir):m_dir(0),
32m_num_entries(0) { 89m_num_entries(0) {
33 if (dir != 0) 90 if (dir != 0)
@@ -89,30 +146,5 @@ bool Directory::open(const char *dir) {
89 return true; 146 return true;
90} 147}
91 148
92bool Directory::isDirectory(const std::string &filename) {
93 struct stat statbuf;
94 if (stat(filename.c_str(), &statbuf) != 0)
95 return false;
96
97 return S_ISDIR(statbuf.st_mode);
98}
99
100bool Directory::isRegularFile(const std::string &filename) {
101 struct stat statbuf;
102 if (stat(filename.c_str(), &statbuf) != 0)
103 return false;
104
105 return S_ISREG(statbuf.st_mode);
106}
107
108bool Directory::isExecutable(const std::string &filename) {
109 struct stat statbuf;
110 if (stat(filename.c_str(), &statbuf) != 0)
111 return false;
112
113 return statbuf.st_mode & S_IXUSR ||
114 statbuf.st_mode & S_IXGRP ||
115 statbuf.st_mode & S_IXOTH;
116}
117 149
118}; // end namespace FbTk 150}; // end namespace FbTk
diff --git a/src/FbTk/Directory.hh b/src/FbTk/FileUtil.hh
index f138ce7..718ccb8 100644
--- a/src/FbTk/Directory.hh
+++ b/src/FbTk/FileUtil.hh
@@ -1,5 +1,5 @@
1// Directory.hh 1// FileUtil.hh
2// Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) 2// Copyright (c) 2002 - 2004 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3// 3//
4// Permission is hereby granted, free of charge, to any person obtaining a 4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"), 5// copy of this software and associated documentation files (the "Software"),
@@ -21,19 +21,49 @@
21 21
22// $Id$ 22// $Id$
23 23
24#ifndef FBTK_DIRECTORY_HH 24#ifndef FBTK_FILEUTIL_HH
25#define FBTK_DIRECTORY_HH 25#define FBTK_FILEUTIL_HH
26
27#include "NotCopyable.hh"
28 26
27#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif // HAVE_CONFIG_H
30#ifdef HAVE_CTIME
31 #include <ctime>
32#else
33 #include <time.h>
34#endif
29#include <sys/types.h> 35#include <sys/types.h>
30#include <dirent.h> 36#include <dirent.h>
37
31#include <string> 38#include <string>
32 39
40#include "NotCopyable.hh"
41
33namespace FbTk { 42namespace FbTk {
34 43
44/// Wrapper for file routines
45
46namespace FileUtil {
47
48 /// @return true if file is a directory
49 bool isDirectory(const char* filename);
50 /// @return true if a file is a regular file
51 bool isRegularFile(const char* filename);
52 /// @return true if a file executable for user
53 bool isExecutable(const char* filename);
54
55 /// gets timestamp of last status change
56 /// @return timestamp
57 /// @return -1 (failure)
58 time_t getLastStatusChangeTimestamp(const char* filename);
59
60 /// copies file 'from' to 'to'
61 bool copyFile(const char* from, const char* to);
62
63}; // end of File namespace
64
35/// Wrapper class for DIR * routines 65/// Wrapper class for DIR * routines
36class Directory: private FbTk::NotCopyable { 66class Directory : private FbTk::NotCopyable {
37public: 67public:
38 explicit Directory(const char *dir = 0); 68 explicit Directory(const char *dir = 0);
39 ~Directory(); 69 ~Directory();
@@ -52,12 +82,6 @@ public:
52 bool open(const char *dir); 82 bool open(const char *dir);
53 /// @return number of entries in the directory 83 /// @return number of entries in the directory
54 size_t entries() const { return m_num_entries; } 84 size_t entries() const { return m_num_entries; }
55 /// @return true if file is a directory
56 static bool isDirectory(const std::string &filename);
57 /// @return true if a file is a regular file
58 static bool isRegularFile(const std::string &filename);
59 /// @return true if a file executable for user
60 static bool isExecutable(const std::string &filename);
61 85
62private: 86private:
63 std::string m_name; 87 std::string m_name;
@@ -67,4 +91,4 @@ private:
67 91
68} // end namespace FbTk 92} // end namespace FbTk
69 93
70#endif // FBTK_DIRECTORY_HH 94#endif // FBTK_FILEUTIL_HH
diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am
index 49217bc..be9b3ef 100644
--- a/src/FbTk/Makefile.am
+++ b/src/FbTk/Makefile.am
@@ -13,7 +13,7 @@ xpm_SOURCE= ImageXPM.hh ImageXPM.cc
13endif 13endif
14 14
15libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ 15libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
16 Directory.hh Directory.cc \ 16 FileUtil.hh FileUtil.cc \
17 EventHandler.hh EventManager.hh EventManager.cc \ 17 EventHandler.hh EventManager.hh EventManager.cc \
18 FbWindow.hh FbWindow.cc Font.cc Font.hh FontImp.hh \ 18 FbWindow.hh FbWindow.cc Font.cc Font.hh FontImp.hh \
19 I18n.cc I18n.hh \ 19 I18n.cc I18n.hh \
diff --git a/src/FbTk/Theme.cc b/src/FbTk/Theme.cc
index 40c68e9..5225686 100644
--- a/src/FbTk/Theme.cc
+++ b/src/FbTk/Theme.cc
@@ -26,7 +26,7 @@
26#include "XrmDatabaseHelper.hh" 26#include "XrmDatabaseHelper.hh"
27#include "App.hh" 27#include "App.hh"
28#include "StringUtil.hh" 28#include "StringUtil.hh"
29#include "Directory.hh" 29#include "FileUtil.hh"
30#include "I18n.hh" 30#include "I18n.hh"
31#include "Image.hh" 31#include "Image.hh"
32 32
@@ -87,14 +87,14 @@ bool ThemeManager::load(const std::string &filename, int screen_num) {
87 std::string location = FbTk::StringUtil::expandFilename(filename); 87 std::string location = FbTk::StringUtil::expandFilename(filename);
88 std::string prefix = ""; 88 std::string prefix = "";
89 89
90 if (Directory::isDirectory(filename)) { 90 if (FileUtil::isDirectory(filename.c_str())) {
91 prefix = location; 91 prefix = location;
92 92
93 location.append("/theme.cfg"); 93 location.append("/theme.cfg");
94 if (!Directory::isRegularFile(location)) { 94 if (!FileUtil::isRegularFile(location.c_str())) {
95 location = prefix; 95 location = prefix;
96 location.append("/style.cfg"); 96 location.append("/style.cfg");
97 if (!Directory::isRegularFile(location)) { 97 if (!FileUtil::isRegularFile(location.c_str())) {
98 cerr<<"Error loading theme file "<<location<<": not a regular file"<<endl; 98 cerr<<"Error loading theme file "<<location<<": not a regular file"<<endl;
99 return false; 99 return false;
100 } 100 }
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc
index ca36eef..2fc8194 100644
--- a/src/MenuCreator.cc
+++ b/src/MenuCreator.cc
@@ -46,7 +46,7 @@
46#include "FbTk/MacroCommand.hh" 46#include "FbTk/MacroCommand.hh"
47#include "FbTk/SimpleCommand.hh" 47#include "FbTk/SimpleCommand.hh"
48#include "FbTk/StringUtil.hh" 48#include "FbTk/StringUtil.hh"
49#include "FbTk/Directory.hh" 49#include "FbTk/FileUtil.hh"
50#include "FbTk/MenuSeparator.hh" 50#include "FbTk/MenuSeparator.hh"
51#include "FbTk/MenuIcon.hh" 51#include "FbTk/MenuIcon.hh"
52 52
@@ -58,12 +58,12 @@ void LayerMenuItem<FluxboxWindow>::click(int button, int time) {
58 m_object->moveToLayer(m_layernum); 58 m_object->moveToLayer(m_layernum);
59} 59}
60 60
61static void createStyleMenu(FbTk::Menu &parent, const std::string &label, 61static void createStyleMenu(FbTk::Menu &parent, const std::string &label,
62 const std::string &directory) { 62 const std::string &directory) {
63 // perform shell style ~ home directory expansion 63 // perform shell style ~ home directory expansion
64 string stylesdir(FbTk::StringUtil::expandFilename(directory)); 64 string stylesdir(FbTk::StringUtil::expandFilename(directory));
65 65
66 if (!FbTk::Directory::isDirectory(stylesdir)) 66 if (!FbTk::FileUtil::isDirectory(stylesdir.c_str()))
67 return; 67 return;
68 68
69 FbTk::Directory dir(stylesdir.c_str()); 69 FbTk::Directory dir(stylesdir.c_str());
@@ -81,25 +81,25 @@ static void createStyleMenu(FbTk::Menu &parent, const std::string &label,
81 std::string style(stylesdir + '/' + filelist[file_index]); 81 std::string style(stylesdir + '/' + filelist[file_index]);
82 // add to menu only if the file is a regular file, and not a 82 // add to menu only if the file is a regular file, and not a
83 // .file or a backup~ file 83 // .file or a backup~ file
84 if ((FbTk::Directory::isRegularFile(style) && 84 if ((FbTk::FileUtil::isRegularFile(style.c_str()) &&
85 (filelist[file_index][0] != '.') && 85 (filelist[file_index][0] != '.') &&
86 (style[style.length() - 1] != '~')) || 86 (style[style.length() - 1] != '~')) ||
87 FbTk::Directory::isRegularFile(style + "/theme.cfg") || 87 FbTk::FileUtil::isRegularFile((style + "/theme.cfg").c_str()) ||
88 FbTk::Directory::isRegularFile(style + "/style.cfg")) 88 FbTk::FileUtil::isRegularFile((style + "/style.cfg").c_str()))
89 parent.insert(new StyleMenuItem(filelist[file_index], style)); 89 parent.insert(new StyleMenuItem(filelist[file_index], style));
90 } 90 }
91 // update menu graphics 91 // update menu graphics
92 parent.updateMenu(); 92 parent.updateMenu();
93 Fluxbox::instance()->saveMenuFilename(stylesdir.c_str()); 93 Fluxbox::instance()->saveMenuFilename(stylesdir.c_str());
94 94
95} 95}
96 96
97static void createRootCmdMenu(FbTk::Menu &parent, const string &label, 97static void createRootCmdMenu(FbTk::Menu &parent, const string &label,
98 const string &directory, const string &cmd) { 98 const string &directory, const string &cmd) {
99 // perform shell style ~ home directory expansion 99 // perform shell style ~ home directory expansion
100 string rootcmddir(FbTk::StringUtil::expandFilename(directory)); 100 string rootcmddir(FbTk::StringUtil::expandFilename(directory));
101 101
102 if (!FbTk::Directory::isDirectory(rootcmddir)) 102 if (!FbTk::FileUtil::isDirectory(rootcmddir.c_str()))
103 return; 103 return;
104 104
105 FbTk::Directory dir(rootcmddir.c_str()); 105 FbTk::Directory dir(rootcmddir.c_str());
@@ -114,13 +114,13 @@ static void createRootCmdMenu(FbTk::Menu &parent, const string &label,
114 114
115 // for each file in directory add filename and path to menu 115 // for each file in directory add filename and path to menu
116 for (size_t file_index = 0; file_index < dir.entries(); file_index++) { 116 for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
117 117
118 string rootcmd(rootcmddir+ '/' + filelist[file_index]); 118 string rootcmd(rootcmddir+ '/' + filelist[file_index]);
119 // add to menu only if the file is a regular file, and not a 119 // add to menu only if the file is a regular file, and not a
120 // .file or a backup~ file 120 // .file or a backup~ file
121 if ((FbTk::Directory::isRegularFile(rootcmd) && 121 if ((FbTk::FileUtil::isRegularFile(rootcmd.c_str()) &&
122 (filelist[file_index][0] != '.') && 122 (filelist[file_index][0] != '.') &&
123 (rootcmd[rootcmd.length() - 1] != '~'))) 123 (rootcmd[rootcmd.length() - 1] != '~')))
124 parent.insert(new RootCmdMenuItem(filelist[file_index], rootcmd, cmd)); 124 parent.insert(new RootCmdMenuItem(filelist[file_index], rootcmd, cmd));
125 } 125 }
126 // update menu graphics 126 // update menu graphics
@@ -172,10 +172,10 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
172 172
173 const int screen_number = menu.screenNumber(); 173 const int screen_number = menu.screenNumber();
174 _FB_USES_NLS; 174 _FB_USES_NLS;
175 175
176 if (str_key == "end") { 176 if (str_key == "end") {
177 return; 177 return;
178 } else if (str_key == "nop") { 178 } else if (str_key == "nop") {
179 menu.insert(str_label.c_str()); 179 menu.insert(str_label.c_str());
180 } else if (str_key == "icons") { 180 } else if (str_key == "icons") {
181 FbTk::Menu *submenu = MenuCreator::createMenuType("iconmenu", menu.screenNumber()); 181 FbTk::Menu *submenu = MenuCreator::createMenuType("iconmenu", menu.screenNumber());
@@ -195,7 +195,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
195 // execute and hide menu 195 // execute and hide menu
196 using namespace FbTk; 196 using namespace FbTk;
197 RefCount<Command> exec_cmd(CommandParser::instance().parseLine("exec " + str_cmd)); 197 RefCount<Command> exec_cmd(CommandParser::instance().parseLine("exec " + str_cmd));
198 RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu, 198 RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu,
199 &Menu::hide)); 199 &Menu::hide));
200 MacroCommand *exec_and_hide = new FbTk::MacroCommand(); 200 MacroCommand *exec_and_hide = new FbTk::MacroCommand();
201 exec_and_hide->add(hide_menu); 201 exec_and_hide->add(hide_menu);
@@ -205,7 +205,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
205 } else if (str_key == "macrocmd") { 205 } else if (str_key == "macrocmd") {
206 using namespace FbTk; 206 using namespace FbTk;
207 RefCount<Command> macro_cmd(CommandParser::instance().parseLine("macrocmd " + str_cmd)); 207 RefCount<Command> macro_cmd(CommandParser::instance().parseLine("macrocmd " + str_cmd));
208 RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu, 208 RefCount<Command> hide_menu(new SimpleCommand<FbTk::Menu>(menu,
209 &Menu::hide)); 209 &Menu::hide));
210 MacroCommand *exec_and_hide = new FbTk::MacroCommand(); 210 MacroCommand *exec_and_hide = new FbTk::MacroCommand();
211 exec_and_hide->add(hide_menu); 211 exec_and_hide->add(hide_menu);
@@ -218,7 +218,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
218 BScreen *screen = Fluxbox::instance()->findScreen(screen_number); 218 BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
219 if (screen != 0) 219 if (screen != 0)
220 menu.insert(str_label.c_str(), &screen->configMenu()); 220 menu.insert(str_label.c_str(), &screen->configMenu());
221 } // end of config 221 } // end of config
222 else if (str_key == "include") { // include 222 else if (str_key == "include") { // include
223 223
224 // this will make sure we dont get stuck in a loop 224 // this will make sure we dont get stuck in a loop
@@ -229,7 +229,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
229 safe_counter++; 229 safe_counter++;
230 230
231 string newfile = FbTk::StringUtil::expandFilename(str_label); 231 string newfile = FbTk::StringUtil::expandFilename(str_label);
232 if (FbTk::Directory::isDirectory(newfile)) { 232 if (FbTk::FileUtil::isDirectory(newfile.c_str())) {
233 // inject every file in this directory into the current menu 233 // inject every file in this directory into the current menu
234 FbTk::Directory dir(newfile.c_str()); 234 FbTk::Directory dir(newfile.c_str());
235 235
@@ -241,7 +241,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
241 for (size_t file_index = 0; file_index < dir.entries(); file_index++) { 241 for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
242 std::string thisfile(newfile + '/' + filelist[file_index]); 242 std::string thisfile(newfile + '/' + filelist[file_index]);
243 243
244 if (FbTk::Directory::isRegularFile(thisfile) && 244 if (FbTk::FileUtil::isRegularFile(thisfile.c_str()) &&
245 (filelist[file_index][0] != '.') && 245 (filelist[file_index][0] != '.') &&
246 (thisfile[thisfile.length() - 1] != '~')) { 246 (thisfile[thisfile.length() - 1] != '~')) {
247 MenuCreator::createFromFile(thisfile, menu, false); 247 MenuCreator::createFromFile(thisfile, menu, false);
@@ -259,7 +259,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
259 259
260 } // end of include 260 } // end of include
261 else if (str_key == "submenu") { 261 else if (str_key == "submenu") {
262 262
263 FbTk::Menu *submenu = MenuCreator::createMenu("", screen_number); 263 FbTk::Menu *submenu = MenuCreator::createMenu("", screen_number);
264 if (submenu == 0) 264 if (submenu == 0)
265 return; 265 return;
@@ -274,21 +274,21 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
274 menu.insert(str_label.c_str(), submenu); 274 menu.insert(str_label.c_str(), submenu);
275 // save to screen list so we can delete it later 275 // save to screen list so we can delete it later
276 BScreen *screen = Fluxbox::instance()->findScreen(screen_number); 276 BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
277 if (screen != 0) 277 if (screen != 0)
278 screen->saveMenu(*submenu); 278 screen->saveMenu(*submenu);
279 279
280 } // end of submenu 280 } // end of submenu
281 else if (str_key == "stylesdir" || str_key == "stylesmenu") { 281 else if (str_key == "stylesdir" || str_key == "stylesmenu") {
282 createStyleMenu(menu, str_label, 282 createStyleMenu(menu, str_label,
283 str_key == "stylesmenu" ? str_cmd : str_label); 283 str_key == "stylesmenu" ? str_cmd : str_label);
284 } // end of stylesdir 284 } // end of stylesdir
285 else if (str_key == "themesdir" || str_key == "themesmenu") { 285 else if (str_key == "themesdir" || str_key == "themesmenu") {
286 createStyleMenu(menu, str_label, 286 createStyleMenu(menu, str_label,
287 str_key == "themesmenu" ? str_cmd : str_label); 287 str_key == "themesmenu" ? str_cmd : str_label);
288 } // end of themesdir 288 } // end of themesdir
289 else if (str_key == "wallpapers" || str_key == "wallpapermenu" || 289 else if (str_key == "wallpapers" || str_key == "wallpapermenu" ||
290 str_key == "rootcommands") { 290 str_key == "rootcommands") {
291 createRootCmdMenu(menu, str_label, str_label, 291 createRootCmdMenu(menu, str_label, str_label,
292 str_cmd == "" ? "fbsetbg" : str_cmd); 292 str_cmd == "" ? "fbsetbg" : str_cmd);
293 } // end of wallpapers 293 } // end of wallpapers
294 else if (str_key == "workspaces") { 294 else if (str_key == "workspaces") {
@@ -353,8 +353,8 @@ FbTk::Menu *MenuCreator::createMenu(const std::string &label, int screen_number)
353 if (screen == 0) 353 if (screen == 0)
354 return 0; 354 return 0;
355 355
356 FbTk::Menu *menu = new FbMenu(screen->menuTheme(), 356 FbTk::Menu *menu = new FbMenu(screen->menuTheme(),
357 screen->imageControl(), 357 screen->imageControl(),
358 *screen->layerManager(). 358 *screen->layerManager().
359 getLayer(Fluxbox::instance()->getMenuLayer())); 359 getLayer(Fluxbox::instance()->getMenuLayer()));
360 if (!label.empty()) 360 if (!label.empty())
@@ -390,7 +390,7 @@ FbTk::Menu *MenuCreator::createFromFile(const std::string &filename, int screen_
390 std::string label; 390 std::string label;
391 if (require_begin && !getStart(parser, label)) 391 if (require_begin && !getStart(parser, label))
392 return 0; 392 return 0;
393 393
394 FbTk::Menu *menu = createMenu(label, screen_number); 394 FbTk::Menu *menu = createMenu(label, screen_number);
395 if (menu != 0) 395 if (menu != 0)
396 parseMenu(parser, *menu); 396 parseMenu(parser, *menu);
@@ -416,8 +416,8 @@ bool MenuCreator::createFromFile(const std::string &filename,
416} 416}
417 417
418 418
419bool MenuCreator::createFromFile(const std::string &filename, 419bool MenuCreator::createFromFile(const std::string &filename,
420 FbTk::Menu &inject_into, 420 FbTk::Menu &inject_into,
421 FluxboxWindow &win, bool require_begin) { 421 FluxboxWindow &win, bool require_begin) {
422 std::string real_filename = FbTk::StringUtil::expandFilename(filename); 422 std::string real_filename = FbTk::StringUtil::expandFilename(filename);
423 FbMenuParser parser(real_filename); 423 FbMenuParser parser(real_filename);
@@ -446,7 +446,7 @@ FbTk::Menu *MenuCreator::createMenuType(const std::string &type, int screen_num)
446 return 0; 446 return 0;
447} 447}
448 448
449bool MenuCreator::createWindowMenuItem(const std::string &type, 449bool MenuCreator::createWindowMenuItem(const std::string &type,
450 const std::string &label, 450 const std::string &label,
451 FbTk::Menu &menu, 451 FbTk::Menu &menu,
452 FluxboxWindow &win) { 452 FluxboxWindow &win) {
@@ -502,10 +502,10 @@ bool MenuCreator::createWindowMenuItem(const std::string &type,
502 BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber()); 502 BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber());
503 if (screen == 0) 503 if (screen == 0)
504 return false; 504 return false;
505 FbTk::Menu *submenu = new LayerMenu<FluxboxWindow>(screen->menuTheme(), 505 FbTk::Menu *submenu = new LayerMenu<FluxboxWindow>(screen->menuTheme(),
506 screen->imageControl(), 506 screen->imageControl(),
507 *screen->layerManager(). 507 *screen->layerManager().
508 getLayer(Fluxbox::instance()->getMenuLayer()), 508 getLayer(Fluxbox::instance()->getMenuLayer()),
509 &win, 509 &win,
510 false); 510 false);
511 submenu->disableTitle(); 511 submenu->disableTitle();
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index b5e7828..3d82eb5 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -38,6 +38,7 @@
38 38
39#include "FbTk/I18n.hh" 39#include "FbTk/I18n.hh"
40#include "FbTk/Image.hh" 40#include "FbTk/Image.hh"
41#include "FbTk/FileUtil.hh"
41#include "FbTk/KeyUtil.hh" 42#include "FbTk/KeyUtil.hh"
42#include "FbTk/ImageControl.hh" 43#include "FbTk/ImageControl.hh"
43#include "FbTk/EventManager.hh" 44#include "FbTk/EventManager.hh"
@@ -151,24 +152,11 @@ class Toolbar { };
151using namespace std; 152using namespace std;
152using namespace FbTk; 153using namespace FbTk;
153 154
154static Window last_bad_window = None;
155namespace { 155namespace {
156void copyFile(const std::string &from, const std::string &to) {
157 ifstream from_file(from.c_str());
158 ofstream to_file(to.c_str());
159
160 if (! to_file.good()) {
161 cerr<<"Can't write file: "<<to<<endl;
162 } else if (from_file.good()) {
163 to_file<<from_file.rdbuf(); //copy file
164 } else {
165 cerr<<"Can't copy from "<<from<<" to "<<to<<endl;
166 }
167}
168
169} // end anonymous
170 156
171static int handleXErrors(Display *d, XErrorEvent *e) { 157Window last_bad_window = None;
158
159int handleXErrors(Display *d, XErrorEvent *e) {
172 if (e->error_code == BadWindow) 160 if (e->error_code == BadWindow)
173 last_bad_window = e->resourceid; 161 last_bad_window = e->resourceid;
174#ifdef DEBUG 162#ifdef DEBUG
@@ -183,10 +171,10 @@ static int handleXErrors(Display *d, XErrorEvent *e) {
183 } 171 }
184#endif // !DEBUG 172#endif // !DEBUG
185 173
186
187 return False; 174 return False;
188} 175}
189 176
177} // end anonymous
190 178
191//static singleton var 179//static singleton var
192Fluxbox *Fluxbox::s_singleton=0; 180Fluxbox *Fluxbox::s_singleton=0;
@@ -573,15 +561,15 @@ void Fluxbox::setupConfigFiles() {
573 561
574 // copy key configuration 562 // copy key configuration
575 if (create_keys) 563 if (create_keys)
576 copyFile(DEFAULTKEYSFILE, keys_file); 564 FbTk::FileUtil::copyFile(DEFAULTKEYSFILE, keys_file.c_str());
577 565
578 // copy menu configuration 566 // copy menu configuration
579 if (create_menu) 567 if (create_menu)
580 copyFile(DEFAULTMENU, menu_file); 568 FbTk::FileUtil::copyFile(DEFAULTMENU, menu_file.c_str());
581 569
582 // copy init file 570 // copy init file
583 if (create_init) 571 if (create_init)
584 copyFile(DEFAULT_INITFILE, init_file); 572 FbTk::FileUtil::copyFile(DEFAULT_INITFILE, init_file.c_str());
585 573
586} 574}
587 575
@@ -1644,10 +1632,11 @@ bool Fluxbox::menuTimestampsChanged() const {
1644 std::list<MenuTimestamp *>::const_iterator it = m_menu_timestamps.begin(); 1632 std::list<MenuTimestamp *>::const_iterator it = m_menu_timestamps.begin();
1645 std::list<MenuTimestamp *>::const_iterator it_end = m_menu_timestamps.end(); 1633 std::list<MenuTimestamp *>::const_iterator it_end = m_menu_timestamps.end();
1646 for (; it != it_end; ++it) { 1634 for (; it != it_end; ++it) {
1647 struct stat buf; 1635
1636 time_t timestamp = FbTk::FileUtil::getLastStatusChangeTimestamp((*it)->filename.c_str());
1648 1637
1649 if (! stat((*it)->filename.c_str(), &buf)) { 1638 if (timestamp >= 0) {
1650 if ((*it)->timestamp != buf.st_ctime) 1639 if (timestamp != (*it)->timestamp)
1651 return true; 1640 return true;
1652 } else 1641 } else
1653 return true; 1642 return true;
@@ -1683,13 +1672,12 @@ void Fluxbox::rereadMenu(bool show_after_reread) {
1683 1672
1684 1673
1685void Fluxbox::real_rereadMenu() { 1674void Fluxbox::real_rereadMenu() {
1686 std::list<MenuTimestamp *>::iterator it = m_menu_timestamps.begin(); 1675
1687 std::list<MenuTimestamp *>::iterator it_end = m_menu_timestamps.end(); 1676 clearMenuFilenames();
1688 for (; it != it_end; ++it) 1677
1689 delete *it; 1678 for_each(m_screen_list.begin(),
1690 1679 m_screen_list.end(),
1691 m_menu_timestamps.erase(m_menu_timestamps.begin(), m_menu_timestamps.end()); 1680 mem_fun(&BScreen::rereadMenu));
1692 for_each(m_screen_list.begin(), m_screen_list.end(), mem_fun(&BScreen::rereadMenu));
1693 1681
1694 if(m_show_menu_after_reread) { 1682 if(m_show_menu_after_reread) {
1695 1683
@@ -1716,13 +1704,13 @@ void Fluxbox::saveMenuFilename(const char *filename) {
1716 } 1704 }
1717 1705
1718 if (! found) { 1706 if (! found) {
1719 struct stat buf; 1707 time_t timestamp = FbTk::FileUtil::getLastStatusChangeTimestamp(filename);
1720 1708
1721 if (! stat(filename, &buf)) { 1709 if (timestamp >= 0) {
1722 MenuTimestamp *ts = new MenuTimestamp; 1710 MenuTimestamp *ts = new MenuTimestamp;
1723 1711
1724 ts->filename = filename; 1712 ts->filename = filename;
1725 ts->timestamp = buf.st_ctime; 1713 ts->timestamp = timestamp;
1726 1714
1727 m_menu_timestamps.push_back(ts); 1715 m_menu_timestamps.push_back(ts);
1728 } 1716 }
@@ -1730,12 +1718,10 @@ void Fluxbox::saveMenuFilename(const char *filename) {
1730} 1718}
1731 1719
1732void Fluxbox::clearMenuFilenames() { 1720void Fluxbox::clearMenuFilenames() {
1733 std::list<MenuTimestamp *>::iterator it = m_menu_timestamps.begin(); 1721 while(!m_menu_timestamps.empty()) {
1734 std::list<MenuTimestamp *>::iterator it_end = m_menu_timestamps.end(); 1722 delete m_menu_timestamps.back();
1735 for (; it != it_end; ++it) 1723 m_menu_timestamps.pop_back();
1736 delete *it; 1724 }
1737
1738 m_menu_timestamps.erase(m_menu_timestamps.begin(), m_menu_timestamps.end());
1739} 1725}
1740 1726
1741void Fluxbox::timed_reconfigure() { 1727void Fluxbox::timed_reconfigure() {