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

Generated on Sat Apr 19 01:25:33 2014 for Hugintrunk by  doxygen 1.3.9.1