LocalizedFileTipProvider.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00029 #include <config.h>
00030 #include "base_wx/wxutils.h"
00031 #include "panoinc_WX.h"
00032 
00033 #include "hugin/LocalizedFileTipProvider.h"
00034 
00035 
00036 LocalizedFileTipProvider::LocalizedFileTipProvider(const wxString& filename,
00037                                                    size_t currentTip)
00038                  : wxTipProvider(currentTip), m_textfile(filename)
00039 {
00040     m_textfile.Open();
00041 }
00042 
00043 wxString LocalizedFileTipProvider::GetTip()
00044 {
00045     size_t count = m_textfile.GetLineCount();
00046     if ( !count )
00047     {
00048         return _("Tips not available, sorry!");
00049     }
00050 
00051     wxString tip;
00052 
00053     // Comments start with a # symbol.
00054     // Loop reading lines until get the first one that isn't a comment.
00055     // The max number of loop executions is the number of lines in the
00056     // textfile so that can't go into an eternal loop in the [oddball]
00057     // case of a comment-only tips file, or the developer has vetoed
00058     // them all via PreprecessTip().
00059     for ( size_t i=0; i < count; i++ )
00060     {
00061         // The current tip may be at the last line of the textfile, (or
00062         // past it, if the number of lines in the textfile changed, such
00063         // as changing to a different textfile, with less tips). So check
00064         // to see at last line of text file, (or past it)...
00065         if ( m_currentTip >= count )
00066         {
00067             // .. and if so, wrap back to line 0.
00068             m_currentTip = 0;
00069         }
00070 
00071         // Read the tip, and increment the current tip counter.
00072         tip = m_textfile.GetLine(m_currentTip++);
00073 
00074         // Break if tip isn't a comment, and isn't an empty string
00075         // (or only stray space characters).
00076         if ( !tip.StartsWith(wxT("#")) && (tip.Trim() != wxEmptyString) )
00077         {
00078             break;
00079         }
00080     }
00081 
00082     // If tip starts with '_(', then it is a gettext string of format
00083     // _("My \"global\" tip text") so first strip off the leading '_("'...
00084     if ( tip.StartsWith(wxT("_(\"" ), &tip))
00085     {
00086         //...and strip off the trailing '")'...
00087         tip = tip.BeforeLast(wxT('\"'));
00088         // ...and replace escaped quotes
00089         tip.Replace(wxT("\\\""), wxT("\""));
00090 
00091         DEBUG_DEBUG("Tip before translation " << tip);
00092         // translate tip
00093         tip = wxGetTranslation(tip);
00094         DEBUG_DEBUG("Tip after translation " << tip);
00095     }
00096 
00097     return tip;
00098 }
00099 
00100 #ifdef ThisNeverHappens
00101 // provide some translatable strings for tip window
00102     wxLogMessage(_("&Next Tip"));
00103     wxLogMessage(_("&Show tips at startup"));
00104     wxLogMessage(_("Tip of the Day"));
00105     wxLogMessage(_("&Close"));
00106     wxLogMessaeg(_("Did you know..."));
00107 #endif

Generated on 24 Jul 2016 for Hugintrunk by  doxygen 1.4.7