Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LocalizedFileTipProvider.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
29 #include "hugin_config.h"
30 #include "panoinc_WX.h"
31 #include "base_wx/wxutils.h"
32 
34 
35 
37  size_t currentTip)
38  : wxTipProvider(currentTip), m_textfile(filename)
39 {
40  m_textfile.Open();
41 }
42 
44 {
45  size_t count = m_textfile.GetLineCount();
46  if ( !count )
47  {
48  return _("Tips not available, sorry!");
49  }
50 
51  wxString tip;
52 
53  // Comments start with a # symbol.
54  // Loop reading lines until get the first one that isn't a comment.
55  // The max number of loop executions is the number of lines in the
56  // textfile so that can't go into an eternal loop in the [oddball]
57  // case of a comment-only tips file, or the developer has vetoed
58  // them all via PreprecessTip().
59  for ( size_t i=0; i < count; i++ )
60  {
61  // The current tip may be at the last line of the textfile, (or
62  // past it, if the number of lines in the textfile changed, such
63  // as changing to a different textfile, with less tips). So check
64  // to see at last line of text file, (or past it)...
65  if ( m_currentTip >= count )
66  {
67  // .. and if so, wrap back to line 0.
68  m_currentTip = 0;
69  }
70 
71  // Read the tip, and increment the current tip counter.
72  tip = m_textfile.GetLine(m_currentTip++);
73 
74  // Break if tip isn't a comment, and isn't an empty string
75  // (or only stray space characters).
76  if ( !tip.StartsWith(wxT("#")) && (tip.Trim() != wxEmptyString) )
77  {
78  break;
79  }
80  }
81 
82  // If tip starts with '_(', then it is a gettext string of format
83  // _("My \"global\" tip text") so first strip off the leading '_("'...
84  if ( tip.StartsWith(wxT("_(\"" ), &tip))
85  {
86  //...and strip off the trailing '")'...
87  tip = tip.BeforeLast(wxT('\"'));
88  // ...and replace escaped quotes
89  tip.Replace(wxT("\\\""), wxT("\""));
90 
91  DEBUG_DEBUG("Tip before translation " << tip);
92  // translate tip
93  tip = wxGetTranslation(tip);
94  DEBUG_DEBUG("Tip after translation " << tip);
95  }
96 
97  return tip;
98 }
99 
100 #ifdef ThisNeverHappens
101 // provide some translatable strings for tip window
102  wxLogMessage(_("&Next Tip"));
103  wxLogMessage(_("&Show tips at startup"));
104  wxLogMessage(_("Tip of the Day"));
105  wxLogMessage(_("&Close"));
106  wxLogMessaeg(_("Did you know..."));
107 #endif
include file for the hugin project
LocalizedFileTipProvider(const wxString &filename, size_t currentTip)
#define DEBUG_DEBUG(msg)
Definition: utils.h:68