LocalizedFileTipProvider.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00029 #include <config.h>
00030 #include "hugin_utils/utils.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 #if !wxCHECK_VERSION(3,0,0)
00075         // Allow a derived class's overrided virtual to modify the tip
00076         // now if so desired.
00077         tip = PreprocessTip(tip);
00078 #endif
00079 
00080         // Break if tip isn't a comment, and isn't an empty string
00081         // (or only stray space characters).
00082         if ( !tip.StartsWith(wxT("#")) && (tip.Trim() != wxEmptyString) )
00083         {
00084             break;
00085         }
00086     }
00087 
00088     // If tip starts with '_(', then it is a gettext string of format
00089     // _("My \"global\" tip text") so first strip off the leading '_("'...
00090     if ( tip.StartsWith(wxT("_(\"" ), &tip))
00091     {
00092         //...and strip off the trailing '")'...
00093         tip = tip.BeforeLast(wxT('\"'));
00094         // ...and replace escaped quotes
00095         tip.Replace(wxT("\\\""), wxT("\""));
00096 
00097         DEBUG_DEBUG("Tip before translation " << tip);
00098         // translate tip
00099         tip = wxGetTranslation(tip);
00100         DEBUG_DEBUG("Tip after translation " << tip);
00101     }
00102 
00103     return tip;
00104 }
00105 
00106 #ifdef ThisNeverHappens
00107 // provide some translatable strings for tip window
00108     wxLogMessage(_("&Next Tip"));
00109     wxLogMessage(_("&Show tips at startup"));
00110     wxLogMessage(_("Tip of the Day"));
00111     wxLogMessage(_("&Close"));
00112     wxLogMessaeg(_("Did you know..."));
00113 #endif

Generated on 29 Aug 2015 for Hugintrunk by  doxygen 1.4.7