Update of /cvsroot/hugin/hugin/src/hugin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27381/hugin
Modified Files:
Makefile.am MainFrame.cpp
Added Files:
LocalizedFileTipProvider.cpp
Log Message:
use gettext for translation of tips of the day
--- NEW FILE: LocalizedFileTipProvider.cpp ---
// -*- c-basic-offset: 4 -*-
/** @file LocalizedFileTipProvider.cpp
*
* @brief FileTipProvider that uses gettext to translate the tips
*
* Based on wxFileTipProvider shipped with wxWidgets.
*
* @author Pablo d'Angelo <pablo.dangelo@...>
*
* $Id: LocalizedFileTipProvider.cpp,v 1.1 2005/08/30 21:22:57 dangelo Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#include "panoinc_WX.h"
#include "hugin/LocalizedFileTipProvider.h"
LocalizedFileTipProvider::LocalizedFileTipProvider(const wxString& filename,
size_t currentTip)
: wxTipProvider(currentTip), m_textfile(filename)
{
m_textfile.Open();
}
wxString LocalizedFileTipProvider::GetTip()
{
size_t count = m_textfile.GetLineCount();
if ( !count )
{
return _("Tips not available, sorry!");
}
wxString tip;
// Comments start with a # symbol.
// Loop reading lines until get the first one that isn't a comment.
// The max number of loop executions is the number of lines in the
// textfile so that can't go into an eternal loop in the [oddball]
// case of a comment-only tips file, or the developer has vetoed
// them all via PreprecessTip().
for ( size_t i=0; i < count; i++ )
{
// The current tip may be at the last line of the textfile, (or
// past it, if the number of lines in the textfile changed, such
// as changing to a different textfile, with less tips). So check
// to see at last line of text file, (or past it)...
if ( m_currentTip >= count )
{
// .. and if so, wrap back to line 0.
m_currentTip = 0;
}
// Read the tip, and increment the current tip counter.
tip = m_textfile.GetLine(m_currentTip++);
// Allow a derived class's overrided virtual to modify the tip
// now if so desired.
tip = PreprocessTip(tip);
// Break if tip isn't a comment, and isn't an empty string
// (or only stray space characters).
if ( !tip.StartsWith(wxT("#")) && (tip.Trim() != wxEmptyString) )
{
break;
}
}
// If tip starts with '_(', then it is a gettext string of format
// _("My \"global\" tip text") so first strip off the leading '_("'...
if ( tip.StartsWith(wxT("_(\"" ), &tip))
{
//...and strip off the trailing '")'...
tip = tip.BeforeLast(wxT('\"'));
// ...and replace escaped quotes
tip.Replace(wxT("\\\""), wxT("\""));
// translate tip
tip = wxGetTranslation(tip);
}
return tip;
}
Index: Makefile.am
===================================================================
RCS file: /cvsroot/hugin/hugin/src/hugin/Makefile.am,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- Makefile.am 18 Jul 2005 12:05:57 -0000 1.15
+++ Makefile.am 30 Aug 2005 21:22:57 -0000 1.16
@@ -17,7 +17,7 @@
PreviewPanel.cpp ImageCenter.cpp OptimizePanel.cpp RunOptimizerFrame.cpp RunStitcherFrame.cpp CPListFrame.cpp \
TextKillFocusHandler.cpp ImageOrientationPanel.cpp ImageOrientationFrame.cpp PanoDruid.cpp \
CPZoomDisplayPanel.cpp CPFineTuneFrame.cpp \
- PreferencesDialog.cpp
+ PreferencesDialog.cpp LocalizedFileTipProvider.cpp
if HAVE_MINGW
WIN_SRC = hugin_rc.rc
Index: MainFrame.cpp
===================================================================
RCS file: /cvsroot/hugin/hugin/src/hugin/MainFrame.cpp,v
retrieving revision 1.161
retrieving revision 1.162
diff -u -d -r1.161 -r1.162
--- MainFrame.cpp 16 Aug 2005 20:43:33 -0000 1.161
+++ MainFrame.cpp 30 Aug 2005 21:22:58 -0000 1.162
@@ -933,46 +933,27 @@
void MainFrame::OnTipOfDay(wxCommandEvent& WXUNUSED(e))
{
- wxString strFile;
- wxString langCode;
- bool bShowAtStartup;
- bool bTipsExist = false;
- int nValue;
+ wxString strFile;
+ bool bShowAtStartup;
+ bool bTipsExist = false;
+ int nValue;
wxConfigBase * config = wxConfigBase::Get();
- nValue = config->Read(wxT("/MainFrame/ShowStartTip"),1l);
+ nValue = config->Read(wxT("/MainFrame/ShowStartTip"),1l);
-#ifndef __WXMAC__
- //if the language is not default, load custom tip file (if exists)
- langCode = huginApp::Get()->GetLocale().GetName().Left(2).Lower();
- DEBUG_INFO("Lang Code: " << langCode.mb_str());
- DEBUG_INFO("Tip index: " << nValue);
- if(langCode != wxString(wxT("en")))
- {
-#ifdef UNICODE
- strFile = m_xrcPrefix + wxT("data/tips_") + langCode + wxT("-UTF8.txt");
-#else
- strFile = m_xrcPrefix + wxT("data/tips_") + langCode + wxT(".txt");
-#endif
- if(wxFile::Exists(strFile))
- bTipsExist = true;
- }
-#elif (defined UNICODE)
- strFile = MacGetPathTOBundledResourceFile(CFSTR("tips-UTF8.txt"));
- if(strFile!=wxT("")) bTipsExist = true;
-#endif
- if(!bTipsExist)
- strFile = m_xrcPrefix + wxT("data/tips.txt"); //load default file
+
+ DEBUG_INFO("Tip index: " << nValue);
+ strFile = m_xrcPrefix + wxT("data/tips.txt"); //load default file
- DEBUG_INFO("Reading tips from " << strFile.mb_str());
- wxTipProvider *tipProvider = wxCreateFileTipProvider(strFile, nValue);
- bShowAtStartup = wxShowTip(this, tipProvider);
+ DEBUG_INFO("Reading tips from " << strFile.mb_str());
+ wxTipProvider *tipProvider = wxCreateFileTipProvider(strFile, nValue);
+ bShowAtStartup = wxShowTip(this, tipProvider);
- //store startup preferences
- nValue = (bShowAtStartup ? tipProvider->GetCurrentTip() : 0);
- DEBUG_INFO("Writing tip index: " << nValue);
+ //store startup preferences
+ nValue = (bShowAtStartup ? tipProvider->GetCurrentTip() : 0);
+ DEBUG_INFO("Writing tip index: " << nValue);
config->Write(wxT("/MainFrame/ShowStartTip"), nValue);
- delete tipProvider;
+ delete tipProvider;
}
void MainFrame::OnKeyboardHelp(wxCommandEvent & e)
|