summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2013-05-13 12:34:01 +0100
committerMichael Meeks <michael.meeks@suse.com>2013-05-15 09:37:40 +0100
commitdcf76c758d764c159b1c3755479ef7164d9233b7 (patch)
treed59f9597705d72bb0bc4ae1a891a5beee199e503 /svx
parentd5051efa3b67129a0eeca16334ea342f7e4107b8 (diff)
gallery: add auxiliary .desktop style translation files.
Change-Id: I2f2f0d5d30fbcab83343f94fd16d9371baa380e5
Diffstat (limited to 'svx')
-rw-r--r--svx/Library_svxcore.mk1
-rw-r--r--svx/source/gallery2/galini.cxx88
-rw-r--r--svx/source/gallery2/gallery1.cxx11
-rw-r--r--svx/source/gallery2/galtheme.cxx1
4 files changed, 100 insertions, 1 deletions
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 03fd18a1b58d..431eedbc0fb3 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -123,6 +123,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/gallery2/galbrws2 \
svx/source/gallery2/galctrl \
svx/source/gallery2/galexpl \
+ svx/source/gallery2/galini \
svx/source/gallery2/gallery1 \
svx/source/gallery2/galmisc \
svx/source/gallery2/galobj \
diff --git a/svx/source/gallery2/galini.cxx b/svx/source/gallery2/galini.cxx
new file mode 100644
index 000000000000..ecb06b0750c1
--- /dev/null
+++ b/svx/source/gallery2/galini.cxx
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+/*
+ * The world's quickest and lamest .desktop / .ini file parser.
+ * Ideally the .thm file would move to a .desktop file in
+ * future.
+ */
+
+#include <sal/config.h>
+
+#include <unotools/streamwrap.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/tempfile.hxx>
+#include <svx/gallery1.hxx>
+#include <i18nlangtag/languagetag.hxx>
+#include <unotools/syslocale.hxx>
+#include <vcl/svapp.hxx>
+
+OUString GalleryThemeEntry::ReadStrFromIni(const OUString &aKeyName )
+{
+ SvStream *pStrm = ::utl::UcbStreamHelper::CreateStream(
+ GetStrURL().GetMainURL( INetURLObject::NO_DECODE ),
+ STREAM_READ );
+
+ const LanguageTag &rLangTag = Application::GetSettings().GetUILanguageTag();
+
+ ::std::vector< OUString > aFallbacks = rLangTag.getFallbackStrings();
+
+ OUString aResult;
+ sal_Int32 nRank = 42;
+
+ if( pStrm )
+ {
+ OString aLine;
+ while( pStrm->ReadLine( aLine ) )
+ {
+ OUString aKey;
+ OUString aLocale;
+ OUString aValue;
+ sal_Int32 n;
+ if( ( n = aLine.indexOf( '=' ) ) >= 1)
+ {
+ aKey = OStringToOUString(
+ aLine.copy( 0, n ).trim(), RTL_TEXTENCODING_ASCII_US );
+ aValue = OStringToOUString(
+ aLine.copy( n + 1 ).trim(), RTL_TEXTENCODING_UTF8 );
+
+ if( ( n = aKey.indexOf( '[' ) ) >= 1 )
+ {
+ aLocale = aKey.copy( n + 1 ).trim();
+ aKey = aKey.copy( 0, n ).trim();
+ if( (n = aLocale.indexOf( ']' ) ) >= 1 )
+ aLocale = aLocale.copy( 0, n ).trim();
+ }
+ }
+ SAL_INFO("svx", "ini file has '" << aKey << "' [ '" << aLocale << "' ] = '" << aValue << "'");
+
+ // grisly language matching, is this not available somewhere else?
+ if( aKey == aKeyName )
+ {
+ n = 0;
+ OUString aLang = aLocale.replace('_','-');
+ for( std::vector< OUString >::const_iterator i = aFallbacks.begin();
+ i != aFallbacks.end(); ++i, ++n )
+ {
+ SAL_INFO( "svx", "compare '" << aLang << "' with '" << *i << "' rank " << nRank << " vs. " << n );
+ if( *i == aLang && n < nRank ) {
+ nRank = n; // try to get the most accurate match
+ aResult = aValue;
+ }
+ }
+ }
+ }
+ delete pStrm;
+ }
+
+ SAL_INFO( "svx", "readStrFromIni returns '" << aResult << "'");
+ return aResult;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/gallery1.cxx b/svx/source/gallery2/gallery1.cxx
index 84553185421a..3d2f9dce3919 100644
--- a/svx/source/gallery2/gallery1.cxx
+++ b/svx/source/gallery2/gallery1.cxx
@@ -64,9 +64,16 @@ GalleryThemeEntry::GalleryThemeEntry( const INetURLObject& rBaseURL, const Strin
aURL.setExtension( "sdv" );
aSdvURL = ImplGetURLIgnoreCase( aURL );
+ aURL.setExtension( "str" );
+ aStrURL = ImplGetURLIgnoreCase( aURL );
+
SetModified( _bNewFile );
- if( nId && bThemeNameFromResource )
+ aName = ReadStrFromIni( "name" );
+
+ // This is awful - we shouldn't use these resources if we
+ // possibly can avoid them
+ if( aName.isEmpty() && nId && bThemeNameFromResource )
aName = GAL_RESSTR( RID_GALLERYSTR_THEME_START + (sal_uInt16) nId );
if( aName.isEmpty() )
@@ -573,12 +580,14 @@ sal_Bool Gallery::RemoveTheme( const String& rThemeName )
INetURLObject aThmURL( pThm->GetThmURL() );
INetURLObject aSdgURL( pThm->GetSdgURL() );
INetURLObject aSdvURL( pThm->GetSdvURL() );
+ INetURLObject aStrURL( pThm->GetSdvURL() );
ReleaseTheme( pThm, aListener );
KillFile( aThmURL );
KillFile( aSdgURL );
KillFile( aSdvURL );
+ KillFile( aStrURL );
}
for ( GalleryThemeList::iterator it = aThemeList.begin(); it != aThemeList.end(); ++it )
diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx
index 81668bd9c513..54c706782bfd 100644
--- a/svx/source/gallery2/galtheme.cxx
+++ b/svx/source/gallery2/galtheme.cxx
@@ -1564,6 +1564,7 @@ void GalleryTheme::ImplSetModified( sal_Bool bModified )
const OUString& GalleryTheme::GetRealName() const { return pThm->GetThemeName(); }
const INetURLObject& GalleryTheme::GetThmURL() const { return pThm->GetThmURL(); }
const INetURLObject& GalleryTheme::GetSdgURL() const { return pThm->GetSdgURL(); }
+const INetURLObject& GalleryTheme::GetStrURL() const { return pThm->GetStrURL(); }
const INetURLObject& GalleryTheme::GetSdvURL() const { return pThm->GetSdvURL(); }
sal_uInt32 GalleryTheme::GetId() const { return pThm->GetId(); }
void GalleryTheme::SetId( sal_uInt32 nNewId, sal_Bool bResetThemeName ) { pThm->SetId( nNewId, bResetThemeName ); }