3 /// Utility functions specific to Barry Desktop
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.
23 #include "barrydesktop.h"
24 #include "windowids.h"
25 #include <wx/datectrl.h>
27 const wxChar
*ButtonNames
[] = {
32 _T("browsedatabases"),
39 bool ButtonEnabled
[] = {
40 true, // backuprestore
43 true, // migratedevice
44 true, // browsedatabases
51 const wxChar
*StateNames
[] = {
58 //////////////////////////////////////////////////////////////////////////////
61 std::string
GetBaseFilename(const std::string
&filename
)
63 std::string file
= BARRYDESKTOP_BASEDATADIR
;
65 if( wxFileExists(wxString(file
.c_str(), wxConvUTF8
)) )
68 // fall back to the devel tree
72 /// Returns full path and filename for given filename.
73 /// 'filename' should have no directory component, as the
74 /// directory will be prepended and returned.
75 wxString
GetImageFilename(const wxString
&filename
)
77 // try the official install directory first
78 wxString file
= _T(BARRYDESKTOP_IMAGEDIR
);
80 if( wxFileExists(file
) )
83 // oops, assume we're running from the build directory,
84 // and use the images dir
85 file
= wxPathOnly(wxGetApp().argv
[0]);
86 file
+= _T("/../images/");
88 if( wxFileExists(file
) )
91 // hmmm.... maybe we're running from inside the libtool
92 // build subdirectories
93 file
= wxPathOnly(wxGetApp().argv
[0]);
94 file
+= _T("/../../images/");
99 wxString
GetButtonFilename(int id
, int state
)
101 return GetImageFilename(
102 wxString(ButtonNames
[id
- MainMenu_FirstButton
]) +
107 bool IsButtonEnabled(int id
)
109 return ButtonEnabled
[id
- MainMenu_FirstButton
];
112 void MakeDateRecent(bool checked
, wxDatePickerCtrl
*picker
)
114 wxDateTime when
= picker
->GetValue();
115 if( checked
&& (!when
.IsValid() ||
116 when
< wxDateTime(1, wxDateTime::Jan
, 1975, 0, 0, 0)) )
118 when
= wxDateTime::Now();
119 picker
->SetValue(when
);
123 bool IsParsable(const std::string
&dbname
)
126 #define HANDLE_PARSER(dbn) \
127 if( dbname == Barry::dbn::GetDBName() ) return true;
129 ALL_KNOWN_PARSER_TYPES
134 bool IsBuildable(const std::string
&dbname
)
136 #undef HANDLE_BUILDER
137 #define HANDLE_BUILDER(dbn) \
138 if( dbname == Barry::dbn::GetDBName() ) return true;
140 ALL_KNOWN_BUILDER_TYPES