use translators if explicitely specified, fall back to the standard translator-credit...
[wxWidgets.git] / src / gtk / aboutdlg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/aboutdlg.cpp
3 // Purpose: native GTK+ wxAboutBox() implementation
4 // Author: Vadim Zeitlin
5 // Created: 2006-10-08
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #if wxUSE_ABOUTDLG && defined(__WXGTK26__)
23
24 #ifndef WX_PRECOMP
25 #endif //WX_PRECOMP
26
27 #include "wx/aboutdlg.h"
28 #include "wx/generic/aboutdlgg.h"
29
30 #include "wx/gtk/private.h"
31
32 // ----------------------------------------------------------------------------
33 // GtkStr: temporary GTK string
34 // ----------------------------------------------------------------------------
35
36 class GtkStr : public wxGtkString
37 {
38 public:
39 GtkStr(const wxString& s)
40 : wxGtkString(wx_const_cast(char *, wxGTK_CONV_SYS(s).release()))
41 {
42 }
43 };
44
45 // ----------------------------------------------------------------------------
46 // GtkArray: temporary array of GTK strings
47 // ----------------------------------------------------------------------------
48
49 class GtkArray
50 {
51 public:
52 GtkArray(const wxArrayString& a)
53 {
54 m_count = a.size();
55 m_strings = new const gchar *[m_count + 1];
56 for ( size_t n = 0; n < m_count; n++ )
57 m_strings[n] = wxGTK_CONV_SYS(a[n]).release();
58
59 // array must be NULL-terminated
60 m_strings[m_count] = NULL;
61 }
62
63 operator const gchar **() const { return m_strings; }
64
65 ~GtkArray()
66 {
67 for ( size_t n = 0; n < m_count; n++ )
68 free(wx_const_cast(gchar *, m_strings[n]));
69
70 delete [] m_strings;
71 }
72
73 private:
74 const gchar **m_strings;
75 size_t m_count;
76
77 DECLARE_NO_COPY_CLASS(GtkArray)
78 };
79
80 // ============================================================================
81 // implementation
82 // ============================================================================
83
84 void wxAboutBox(const wxAboutDialogInfo& info)
85 {
86 if ( !gtk_check_version(2,6,0) )
87 {
88 GtkAboutDialog * const dlg = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
89 gtk_about_dialog_set_name(dlg, GtkStr(info.GetName()));
90 if ( info.HasVersion() )
91 gtk_about_dialog_set_version(dlg, GtkStr(info.GetVersion()));
92 if ( info.HasCopyright() )
93 gtk_about_dialog_set_copyright(dlg, GtkStr(info.GetCopyright()));
94 if ( info.HasDescription() )
95 gtk_about_dialog_set_comments(dlg, GtkStr(info.GetDescription()));
96 if ( info.HasLicence() )
97 gtk_about_dialog_set_license(dlg, GtkStr(info.GetLicence()));
98
99 wxIcon icon = info.GetIcon();
100 if ( icon.Ok() )
101 gtk_about_dialog_set_logo(dlg, info.GetIcon().GetPixbuf());
102
103 if ( info.HasWebSite() )
104 {
105 gtk_about_dialog_set_website(dlg, GtkStr(info.GetWebSiteURL()));
106 gtk_about_dialog_set_website_label
107 (
108 dlg,
109 GtkStr(info.GetWebSiteDescription())
110 );
111 }
112
113 if ( info.HasDevelopers() )
114 gtk_about_dialog_set_authors(dlg, GtkArray(info.GetDevelopers()));
115 if ( info.HasDocWriters() )
116 gtk_about_dialog_set_documenters(dlg, GtkArray(info.GetDocWriters()));
117 if ( info.HasArtists() )
118 gtk_about_dialog_set_artists(dlg, GtkArray(info.GetArtists()));
119
120 wxString transCredits;
121 if ( info.HasTranslators() )
122 {
123 const wxArrayString& translators = info.GetTranslators();
124 const size_t count = translators.size();
125 for ( size_t n = 0; n < count; n++ )
126 {
127 transCredits << translators[n] << _T('\n');
128 }
129 }
130 else // no translators explicitely specified
131 {
132 // maybe we have translator credits in the message catalog?
133 transCredits = _("translator-credits");
134 }
135
136 gtk_about_dialog_set_translator_credits(dlg, GtkStr(transCredits));
137
138 gtk_widget_show(GTK_WIDGET(dlg));
139 return;
140 }
141
142 // native about dialog not available, fall back to the generic one
143 wxGenericAboutBox(info);
144 }
145
146 #endif // wxUSE_ABOUTDLG && GTK+ 2.6+