1 | // |
---|
2 | // aboutdlg.cc |
---|
3 | // |
---|
4 | // About box handling for Aven. |
---|
5 | // |
---|
6 | // Copyright (C) 2001-2003 Mark R. Shinwell. |
---|
7 | // Copyright (C) 2001,2002,2003,2004,2005,2010 Olly Betts |
---|
8 | // |
---|
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. |
---|
13 | // |
---|
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. See the |
---|
17 | // GNU General Public License for more details. |
---|
18 | // |
---|
19 | // You should have received a copy of the GNU General Public License |
---|
20 | // along with this program; if not, write to the Free Software |
---|
21 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | // |
---|
23 | |
---|
24 | #ifdef HAVE_CONFIG_H |
---|
25 | #include <config.h> |
---|
26 | #endif |
---|
27 | |
---|
28 | #include "aboutdlg.h" |
---|
29 | #include "aven.h" |
---|
30 | #include "message.h" |
---|
31 | |
---|
32 | #include <stdio.h> // for popen |
---|
33 | |
---|
34 | #include <wx/confbase.h> |
---|
35 | |
---|
36 | BEGIN_EVENT_TABLE(AboutDlg, wxDialog) |
---|
37 | END_EVENT_TABLE() |
---|
38 | |
---|
39 | AboutDlg::AboutDlg(wxWindow* parent, const wxString & icon_path) : |
---|
40 | wxDialog(parent, 500, wxString::Format(msg(/*About %s*/205), APP_NAME)) |
---|
41 | { |
---|
42 | wxBoxSizer* horiz = new wxBoxSizer(wxHORIZONTAL); |
---|
43 | wxBoxSizer* vert = new wxBoxSizer(wxVERTICAL); |
---|
44 | |
---|
45 | if (!bitmap.Ok()) { |
---|
46 | bitmap.LoadFile(icon_path + "aven-about.png", wxBITMAP_TYPE_PNG); |
---|
47 | bitmap_icon.LoadFile(icon_path + "aven.png", wxBITMAP_TYPE_PNG); |
---|
48 | } |
---|
49 | if (bitmap.Ok()) { |
---|
50 | wxStaticBitmap* static_bitmap = new wxStaticBitmap(this, 501, bitmap); |
---|
51 | horiz->Add(static_bitmap, 0 /* horizontally unstretchable */, wxALL, |
---|
52 | 2 /* border width */); |
---|
53 | } |
---|
54 | horiz->Add(vert, 0, wxALL, 2); |
---|
55 | |
---|
56 | wxString id = wxString(APP_NAME" "VERSION"\n"); |
---|
57 | id += msg(/*Survey visualisation tool*/209); |
---|
58 | wxBoxSizer* title = new wxBoxSizer(wxHORIZONTAL); |
---|
59 | if (bitmap_icon.Ok()) { |
---|
60 | title->Add(new wxStaticBitmap(this, 599, bitmap_icon), 0, wxALIGN_CENTRE_VERTICAL|wxRIGHT, 8); |
---|
61 | } |
---|
62 | title->Add(new wxStaticText(this, 502, id), 0, wxALL, 2); |
---|
63 | |
---|
64 | wxString copyright_msg = COPYRIGHT_MSG"\n"AVEN_COPYRIGHT_MSG; |
---|
65 | const char * csign = msg(/*©*/0); |
---|
66 | if (strcmp(csign, "(C)") != 0) { |
---|
67 | size_t csign_len = strlen(csign); |
---|
68 | size_t i = 0; |
---|
69 | while ((i = copyright_msg.find("(C)", i)) != wxString::npos) { |
---|
70 | copyright_msg.replace(i, 3, csign, csign_len); |
---|
71 | i += csign_len; |
---|
72 | } |
---|
73 | } |
---|
74 | wxStaticText* copyright = new wxStaticText(this, 503, copyright_msg); |
---|
75 | |
---|
76 | wxString licence_str; |
---|
77 | wxString l(msg(/*This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public Licence as published by the Free Software Foundation; either version 2 of the Licence, or (at your option) any later version.*/219)); |
---|
78 | wxClientDC dc(this); |
---|
79 | dc.SetFont(this->GetFont()); |
---|
80 | do { |
---|
81 | unsigned int a = 72; |
---|
82 | if (a >= l.length()) { |
---|
83 | a = l.length(); |
---|
84 | } else { |
---|
85 | while (a > 1 && l[a] != ' ') --a; |
---|
86 | } |
---|
87 | |
---|
88 | while (a > 1) { |
---|
89 | wxCoord w, h; |
---|
90 | dc.GetTextExtent(l.substr(0, a), &w, &h); |
---|
91 | if (w <= 380) break; |
---|
92 | do { --a; } while (a > 1 && l[a] != ' '); |
---|
93 | } |
---|
94 | |
---|
95 | if (!licence_str.empty()) licence_str += '\n'; |
---|
96 | licence_str += l.substr(0, a); |
---|
97 | if (a < l.length() && l[a] == ' ') ++a; |
---|
98 | l = l.substr(a); |
---|
99 | } while (!l.empty()); |
---|
100 | |
---|
101 | wxStaticText* licence = new wxStaticText(this, 504, licence_str); |
---|
102 | wxButton* ok = new wxButton(this, wxID_OK, wxGetTranslation("OK")); |
---|
103 | ok->SetDefault(); |
---|
104 | |
---|
105 | vert->Add(10, 5, 0, wxTOP, 5); |
---|
106 | vert->Add(title, 0, wxLEFT | wxRIGHT, 20); |
---|
107 | vert->Add(10, 5, 0, wxTOP, 5); |
---|
108 | |
---|
109 | vert->Add(copyright, 0, wxLEFT | wxRIGHT, 20); |
---|
110 | vert->Add(10, 5, 0, wxTOP, 5); |
---|
111 | |
---|
112 | vert->Add(new wxStaticText(this, 505, msg(/*System Information:*/390)), |
---|
113 | 0, wxLEFT | wxRIGHT, 20); |
---|
114 | |
---|
115 | #if defined __UNIX__ && !wxCHECK_VERSION(2,5,4) |
---|
116 | // On Unix, older wx versions report the OS that we were *built* on, which |
---|
117 | // may be a different OS or kernel version to what we're running on. |
---|
118 | // I submitted a patch to fix this which was applied in 2.5.4. |
---|
119 | wxString info; |
---|
120 | { |
---|
121 | char buf[80]; |
---|
122 | FILE *f = popen("uname -s -r", "r"); |
---|
123 | if (f) { |
---|
124 | size_t c = fread(buf, 1, sizeof(buf), f); |
---|
125 | if (c > 0) { |
---|
126 | if (buf[c - 1] == '\n') --c; |
---|
127 | info = wxString(buf, c); |
---|
128 | } |
---|
129 | fclose(f); |
---|
130 | } |
---|
131 | if (info.empty()) info = wxGetOsDescription(); |
---|
132 | } |
---|
133 | #else |
---|
134 | wxString info(wxGetOsDescription()); |
---|
135 | #endif |
---|
136 | info += '\n'; |
---|
137 | info += wxVERSION_STRING; |
---|
138 | #ifdef __WXGTK__ |
---|
139 | #if defined __WXGTK26__ |
---|
140 | info += " (GTK+ >= 2.6)"; |
---|
141 | #elif defined __WXGTK24__ |
---|
142 | info += " (GTK+ >= 2.4)"; |
---|
143 | #elif defined __WXGTK20__ |
---|
144 | info += " (GTK+ >= 2.0)"; |
---|
145 | #elif defined __WXGTK12__ |
---|
146 | info += " (GTK+ >= 1.2)"; |
---|
147 | #else |
---|
148 | info += " (GTK+ < 1.2)"; |
---|
149 | #endif |
---|
150 | #elif defined __WXMOTIF__ |
---|
151 | #if defined __WXMOTIF20__ |
---|
152 | info += " (Motif >= 2.0)"; |
---|
153 | #else |
---|
154 | info += " (Motif < 2.0)"; |
---|
155 | #endif |
---|
156 | #elif defined __WXX11__ |
---|
157 | info += " (X11)"; |
---|
158 | #endif |
---|
159 | info += '\n'; |
---|
160 | int bpp = wxDisplayDepth(); |
---|
161 | info += wxString::Format("Display Depth: %d bpp", bpp); |
---|
162 | if (wxColourDisplay()) info += " (colour)"; |
---|
163 | |
---|
164 | // Use a readonly multiline text edit for the system info so users can |
---|
165 | // easily cut and paste it into an email when reporting bugs. |
---|
166 | vert->Add(new wxTextCtrl(this, 506, info, wxDefaultPosition, |
---|
167 | wxSize(360, 64), wxTE_MULTILINE|wxTE_READONLY), |
---|
168 | 0, wxLEFT | wxRIGHT, 20); |
---|
169 | |
---|
170 | vert->Add(10, 5, 0, wxTOP, 15); |
---|
171 | |
---|
172 | vert->Add(licence, 0, wxLEFT | wxRIGHT, 20); |
---|
173 | vert->Add(10, 5, 1, wxALIGN_BOTTOM | wxTOP, 5); |
---|
174 | |
---|
175 | wxBoxSizer* bottom = new wxBoxSizer(wxHORIZONTAL); |
---|
176 | bottom->Add(5, 5, 1); |
---|
177 | bottom->Add(ok, 0, wxRIGHT | wxBOTTOM, 15); |
---|
178 | vert->Add(bottom, 0, wxEXPAND | wxLEFT | wxRIGHT, 0); |
---|
179 | vert->SetMinSize(0, bitmap.GetHeight()); |
---|
180 | |
---|
181 | SetAutoLayout(true); |
---|
182 | SetSizer(horiz); |
---|
183 | |
---|
184 | horiz->Fit(this); |
---|
185 | horiz->SetSizeHints(this); |
---|
186 | } |
---|