3 /// GUI utility functions
7 Copyright (C) 2007-2008, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
23 #include <sys/types.h>
29 Glib::RefPtr
<Gnome::Glade::Xml
> LoadXml(const char *filename
)
31 // try loading from global glade directory first
33 std::string file
= BARRYBACKUP_GLADEDIR
;
36 Glib::RefPtr
<Gnome::Glade::Xml
> ref
= Gnome::Glade::Xml::create(file
);
39 catch( Gnome::Glade::XmlError
&e
) {
40 // oops... let's fall through, and try the local directory
43 // this will throw XmlError on failure, and we let the caller worry
45 return Gnome::Glade::Xml::create(filename
);
48 /// Checks that the path in path exists, and if not, creates it.
49 /// Returns false if unable to create path, true if ok.
50 bool CheckPath(const std::string
&path
, std::string
*perr
)
52 if( path
.size() == 0 ) {
54 *perr
= "path is empty!";
58 if( access(path
.c_str(), F_OK
) == 0 )
62 std::string::size_type slash
= 0;
63 while( (slash
= path
.find('/', slash
+ 1)) != std::string::npos
) {
64 base
= path
.substr(0, slash
);
65 if( access(base
.c_str(), F_OK
) != 0 ) {
66 if( mkdir(base
.c_str(), 0755) == -1 ) {
68 *perr
= "mkdir(" + base
+ ") failed: ";
69 *perr
+= strerror(errno
);
75 if( mkdir(path
.c_str(), 0755) == -1 ) {
77 *perr
= "last mkdir(" + path
+ ") failed: ";
78 *perr
+= strerror(errno
);
85 std::string
GetPath(const std::string
&filename
)
88 std::string::size_type pos
= filename
.rfind('/');
89 if( pos
!= std::string::npos
) {
90 path
= filename
.substr(0, pos
);