desktop: added timezone list to CalendarEditDlg
[barry.git] / desktop / src / util.cc
blob48d529f2621c28fff7e0e3a8782fb10707f6749f
1 ///
2 /// \file util.cc
3 /// Utility functions specific to Barry Desktop
4 ///
6 /*
7 Copyright (C) 2009-2012, 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.
22 #include "util.h"
23 #include "barrydesktop.h"
24 #include "windowids.h"
26 const wxChar *ButtonNames[] = {
27 _T("backuprestore"),
28 _T("sync"),
29 _T("modem"),
30 _T("migratedevice"),
31 _T("browsedatabases"),
32 _T("apploader"),
33 _T("media"),
34 _T("misc"),
38 bool ButtonEnabled[] = {
39 true, // backuprestore
40 true, // sync
41 false, // modem
42 true, // migratedevice
43 true, // browsedatabases
44 false, // apploader
45 false, // media
46 false, // misc
47 false
50 const wxChar *StateNames[] = {
51 _T("-normal.png"),
52 _T("-focus.png"),
53 _T("-pushed.png"),
57 //////////////////////////////////////////////////////////////////////////////
58 // Utility functions
60 std::string GetBaseFilename(const std::string &filename)
62 std::string file = BARRYDESKTOP_BASEDATADIR;
63 file += filename;
64 if( wxFileExists(wxString(file.c_str(), wxConvUTF8)) )
65 return file;
67 // fall back to the devel tree
68 return filename;
71 /// Returns full path and filename for given filename.
72 /// 'filename' should have no directory component, as the
73 /// directory will be prepended and returned.
74 wxString GetImageFilename(const wxString &filename)
76 // try the official install directory first
77 wxString file = _T(BARRYDESKTOP_IMAGEDIR);
78 file += filename;
79 if( wxFileExists(file) )
80 return file;
82 // oops, assume we're running from the build directory,
83 // and use the images dir
84 file = wxPathOnly(wxGetApp().argv[0]);
85 file += _T("/../images/");
86 file += filename;
87 if( wxFileExists(file) )
88 return file;
90 // hmmm.... maybe we're running from inside the libtool
91 // build subdirectories
92 file = wxPathOnly(wxGetApp().argv[0]);
93 file += _T("/../../images/");
94 file += filename;
95 return file;
98 wxString GetButtonFilename(int id, int state)
100 return GetImageFilename(
101 wxString(ButtonNames[id - MainMenu_FirstButton]) +
102 StateNames[state]
106 bool IsButtonEnabled(int id)
108 return ButtonEnabled[id - MainMenu_FirstButton];
111 bool IsParsable(const std::string &dbname)
113 #undef HANDLE_PARSER
114 #define HANDLE_PARSER(dbn) \
115 if( dbname == Barry::dbn::GetDBName() ) return true;
117 ALL_KNOWN_PARSER_TYPES
119 return false;
122 bool IsBuildable(const std::string &dbname)
124 #undef HANDLE_BUILDER
125 #define HANDLE_BUILDER(dbn) \
126 if( dbname == Barry::dbn::GetDBName() ) return true;
128 ALL_KNOWN_BUILDER_TYPES
130 return false;