desktop: added modem support
[barry.git] / desktop / src / util.cc
blob729f0b005b1000dd8ce57796ae144c4a439154f6
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"
25 #include <wx/datectrl.h>
27 const wxChar *ButtonNames[] = {
28 _T("backuprestore"),
29 _T("sync"),
30 _T("modem"),
31 _T("migratedevice"),
32 _T("browsedatabases"),
33 _T("apploader"),
34 _T("media"),
35 _T("misc"),
39 bool ButtonEnabled[] = {
40 true, // backuprestore
41 true, // sync
42 true, // modem
43 true, // migratedevice
44 true, // browsedatabases
45 false, // apploader
46 false, // media
47 false, // misc
48 false
51 const wxChar *StateNames[] = {
52 _T("-normal.png"),
53 _T("-focus.png"),
54 _T("-pushed.png"),
58 //////////////////////////////////////////////////////////////////////////////
59 // Utility functions
61 std::string GetBaseFilename(const std::string &filename)
63 std::string file = BARRYDESKTOP_BASEDATADIR;
64 file += filename;
65 if( wxFileExists(wxString(file.c_str(), wxConvUTF8)) )
66 return file;
68 // fall back to the devel tree
69 return filename;
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);
79 file += filename;
80 if( wxFileExists(file) )
81 return 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/");
87 file += filename;
88 if( wxFileExists(file) )
89 return file;
91 // hmmm.... maybe we're running from inside the libtool
92 // build subdirectories
93 file = wxPathOnly(wxGetApp().argv[0]);
94 file += _T("/../../images/");
95 file += filename;
96 return file;
99 wxString GetButtonFilename(int id, int state)
101 return GetImageFilename(
102 wxString(ButtonNames[id - MainMenu_FirstButton]) +
103 StateNames[state]
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)
125 #undef HANDLE_PARSER
126 #define HANDLE_PARSER(dbn) \
127 if( dbname == Barry::dbn::GetDBName() ) return true;
129 ALL_KNOWN_PARSER_TYPES
131 return false;
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
142 return false;