Files
libreoffice/svtools/source/config/helpopt.cxx

336 lines
9.5 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patch contributed by: Jurgen Schmidt remove onlineregistration with dependencies http://svn.apache.org/viewvc?view=revision&revision=1240245 imported patch package_eventlistener.patch http://svn.apache.org/viewvc?view=revision&revision=1172103 Patch contributed by Pedro Giffuni Accept Google Chrome OS fonts as equivalent to MS fonts. http://svn.apache.org/viewvc?view=revision&revision=1233155 http://svn.apache.org/viewvc?view=revision&revision=1233408 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i114600#: remove forbidden characters from list of unencoded characters http://svn.apache.org/viewvc?view=revision&revision=1172370 Patches contributed by Oliver Rainer-Wittman some clean up in JPEGReader due to memory constraints http://svn.apache.org/viewvc?view=revision&revision=1299729 119114 - method <UpdateDialog::addSpecificError(..)> - create entry with correct type http://svn.apache.org/viewvc?view=revision&revision=1305265 Patches contributed by Ariel Constenla-Haile i118707 - make toolbar control's popup window grab focus http://svn.apache.org/viewvc?view=revision&revision=1225846 Patches contributed by Herbert Duerr #i118662# remove usage of BerkeleyDB in desktop module http://svn.apache.org/viewvc?view=revision&revision=1213171 minor cleanups in dp_persmap.* http://svn.apache.org/viewvc?view=revision&revision=1215064 flush early to prevent problem with extension manager not cleaning up its objects http://svn.apache.org/viewvc?view=revision&revision=1228147 i118726 do not flush *pmap file while reading it http://svn.apache.org/viewvc?view=revision&revision=1230614 #i119048# migrate BDB extension entries using a simple heuristic http://svn.apache.org/viewvc?view=revision&revision=1300972 #i119048# handle edge cases when importing BDB hash files http://svn.apache.org/viewvc?view=revision&revision=1301428 #i119113# fix of-by-one when importing BDB files http://svn.apache.org/viewvc?view=revision&revision=1305420 restore our encryption settings, icon themes, and dictionaries. removed wrapper hacks, kill obsolete bundled extension blob / pre-registration handling, remove duplicated quickstart code. remove OS/2 conditionals.
2012-11-15 17:28:16 +00:00
/*
* 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-28 10:22:41 +00:00
#include <sal/config.h>
#include <map>
#include <svtools/helpopt.hxx>
2000-09-28 10:22:41 +00:00
#include <unotools/configmgr.hxx>
#include <unotools/configitem.hxx>
#include <tools/debug.hxx>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <vcl/help.hxx>
2000-09-28 10:22:41 +00:00
#include <osl/mutex.hxx>
#include "itemholder2.hxx"
2000-09-28 10:22:41 +00:00
using namespace utl;
using namespace com::sun::star::uno;
using namespace com::sun::star;
2000-09-28 10:22:41 +00:00
2011-02-27 17:05:28 +01:00
2000-09-28 10:22:41 +00:00
static SvtHelpOptions_Impl* pOptions = NULL;
static sal_Int32 nRefCount = 0;
#define EXTENDEDHELP 0
#define HELPTIPS 1
#define LOCALE 2
#define SYSTEM 3
#define STYLESHEET 4
2000-09-28 10:22:41 +00:00
class SvtHelpOptions_Impl : public utl::ConfigItem
{
bool bExtendedHelp;
bool bHelpTips;
bool bWelcomeScreen;
OUString aLocale;
OUString aSystem;
OUString sHelpStyleSheet;
2000-09-28 10:22:41 +00:00
typedef std::map <OUString, sal_Int32> MapString2Int;
MapString2Int aURLIgnoreCounters;
static Sequence< OUString > GetPropertyNames();
virtual void ImplCommit() SAL_OVERRIDE;
2000-09-28 10:22:41 +00:00
public:
SvtHelpOptions_Impl();
virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames ) SAL_OVERRIDE;
void Load( const ::com::sun::star::uno::Sequence< OUString>& aPropertyNames);
2000-09-28 10:22:41 +00:00
void SetExtendedHelp( bool b ) { bExtendedHelp= b; SetModified(); }
bool IsExtendedHelp() const { return bExtendedHelp; }
void SetHelpTips( bool b ) { bHelpTips = b; SetModified(); }
bool IsHelpTips() const { return bHelpTips; }
void SetWelcomeScreen( bool b ) { bWelcomeScreen = b; SetModified(); }
bool IsWelcomeScreen() const { return bWelcomeScreen; }
OUString GetSystem() const { return aSystem; }
const OUString& GetHelpStyleSheet()const{return sHelpStyleSheet;}
void SetHelpStyleSheet(const OUString& rStyleSheet){sHelpStyleSheet = rStyleSheet; SetModified();}
static ::osl::Mutex & getInitMutex();
2000-09-28 10:22:41 +00:00
};
Sequence< OUString > SvtHelpOptions_Impl::GetPropertyNames()
2000-09-28 10:22:41 +00:00
{
static const char* aPropNames[] =
{
"ExtendedTip",
"Tip",
"Locale",
"System",
"HelpStyleSheet"
2000-09-28 10:22:41 +00:00
};
const int nCount = sizeof( aPropNames ) / sizeof( const char* );
Sequence< OUString > aNames( nCount );
OUString* pNames = aNames.getArray();
for ( int i = 0; i < nCount; i++ )
pNames[i] = OUString::createFromAscii( aPropNames[i] );
return aNames;
}
::osl::Mutex & SvtHelpOptions_Impl::getInitMutex()
{
static ::osl::Mutex *pMutex = 0;
if( ! pMutex )
{
::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
if( ! pMutex )
{
static ::osl::Mutex mutex;
pMutex = &mutex;
}
}
return *pMutex;
}
2000-09-28 10:22:41 +00:00
SvtHelpOptions_Impl::SvtHelpOptions_Impl()
: ConfigItem( OUString( "Office.Common/Help" ) )
, bExtendedHelp( false )
, bHelpTips( true )
, bWelcomeScreen( false )
2000-09-28 10:22:41 +00:00
{
Sequence< OUString > aNames = GetPropertyNames();
Load( aNames );
2000-09-28 10:22:41 +00:00
EnableNotification( aNames );
}
static int lcl_MapPropertyName( const OUString& rCompare,
const uno::Sequence< OUString>& aInternalPropertyNames)
{
for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
{
if( aInternalPropertyNames[nProp] == rCompare )
return nProp;
}
return -1;
}
void SvtHelpOptions_Impl::Load(const uno::Sequence< OUString>& rPropertyNames)
{
const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
Sequence< Any > aValues = GetProperties( rPropertyNames );
2000-09-28 10:22:41 +00:00
const Any* pValues = aValues.getConstArray();
DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" );
if ( aValues.getLength() == rPropertyNames.getLength() )
2000-09-28 10:22:41 +00:00
{
for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
2000-09-28 10:22:41 +00:00
{
2011-05-22 21:57:07 +01:00
#if OSL_DEBUG_LEVEL > 1
2011-07-26 14:11:04 +02:00
DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
2011-05-22 21:57:07 +01:00
#endif
2000-09-28 10:22:41 +00:00
if ( pValues[nProp].hasValue() )
{
bool bTmp;
OUString aTmpStr;
sal_Int32 nTmpInt = 0;
2000-09-28 10:22:41 +00:00
if ( pValues[nProp] >>= bTmp )
{
switch ( lcl_MapPropertyName(rPropertyNames[nProp], aInternalPropertyNames) )
2000-09-28 10:22:41 +00:00
{
case EXTENDEDHELP :
bExtendedHelp = bTmp;
break;
case HELPTIPS :
bHelpTips = bTmp;
break;
default:
SAL_WARN( "svtools.config", "Wrong Member!" );
break;
}
}
else if ( pValues[nProp] >>= aTmpStr )
{
switch ( nProp )
{
case LOCALE:
aLocale = aTmpStr;
break;
case SYSTEM:
aSystem = aTmpStr;
break;
case STYLESHEET :
sHelpStyleSheet = aTmpStr;
break;
default:
SAL_WARN( "svtools.config", "Wrong Member!" );
break;
}
}
else if ( pValues[nProp] >>= nTmpInt )
{
SAL_WARN( "svtools.config", "Wrong Member!" );
2000-09-28 10:22:41 +00:00
}
else
2008-10-28 15:03:16 +00:00
{
SAL_WARN( "svtools.config", "Wrong Type!" );
2011-05-22 21:57:07 +01:00
}
2000-09-28 10:22:41 +00:00
}
}
if ( IsHelpTips() != Help::IsQuickHelpEnabled() )
IsHelpTips() ? Help::EnableQuickHelp() : Help::DisableQuickHelp();
if ( IsExtendedHelp() != Help::IsBalloonHelpEnabled() )
IsExtendedHelp() ? Help::EnableBalloonHelp() : Help::DisableBalloonHelp();
2000-09-28 10:22:41 +00:00
}
}
void SvtHelpOptions_Impl::ImplCommit()
2000-09-28 10:22:41 +00:00
{
Sequence< OUString > aNames = GetPropertyNames();
2000-09-28 10:22:41 +00:00
Sequence< Any > aValues( aNames.getLength() );
Any* pValues = aValues.getArray();
for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
{
switch ( nProp )
{
case EXTENDEDHELP :
pValues[nProp] <<= bExtendedHelp;
break;
2000-09-28 10:22:41 +00:00
case HELPTIPS :
pValues[nProp] <<= bHelpTips;
break;
case LOCALE:
pValues[nProp] <<= OUString(aLocale);
break;
case SYSTEM:
pValues[nProp] <<= OUString(aSystem);
break;
case STYLESHEET :
pValues[nProp] <<= OUString(sHelpStyleSheet);
break;
2000-09-28 10:22:41 +00:00
}
}
PutProperties( aNames, aValues );
}
2000-09-28 10:22:41 +00:00
void SvtHelpOptions_Impl::Notify( const Sequence<OUString>& aPropertyNames )
2000-09-28 10:22:41 +00:00
{
Load( aPropertyNames );
2000-09-28 10:22:41 +00:00
}
SvtHelpOptions::SvtHelpOptions()
{
// Global access, must be guarded (multithreading)
::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
++nRefCount;
2000-09-28 10:22:41 +00:00
if ( !pOptions )
{
2000-09-28 10:22:41 +00:00
pOptions = new SvtHelpOptions_Impl;
svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS);
}
2000-09-28 10:22:41 +00:00
pImp = pOptions;
}
2000-09-28 10:22:41 +00:00
SvtHelpOptions::~SvtHelpOptions()
{
// Global access, must be guarded (multithreading)
::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
2000-09-28 10:22:41 +00:00
if ( !--nRefCount )
2000-10-26 11:58:47 +00:00
{
if ( pOptions->IsModified() )
pOptions->Commit();
2000-09-28 10:22:41 +00:00
DELETEZ( pOptions );
2000-10-26 11:58:47 +00:00
}
2000-09-28 10:22:41 +00:00
}
void SvtHelpOptions::SetExtendedHelp( bool b )
2000-09-28 10:22:41 +00:00
{
pImp->SetExtendedHelp( b );
}
bool SvtHelpOptions::IsExtendedHelp() const
2000-09-28 10:22:41 +00:00
{
return pImp->IsExtendedHelp();
}
void SvtHelpOptions::SetHelpTips( bool b )
2000-09-28 10:22:41 +00:00
{
pImp->SetHelpTips( b );
}
bool SvtHelpOptions::IsHelpTips() const
2000-09-28 10:22:41 +00:00
{
return pImp->IsHelpTips();
}
void SvtHelpOptions::SetWelcomeScreen( bool b )
2000-09-28 10:22:41 +00:00
{
pImp->SetWelcomeScreen( b );
}
bool SvtHelpOptions::IsWelcomeScreen() const
2000-09-28 10:22:41 +00:00
{
return pImp->IsWelcomeScreen();
}
OUString SvtHelpOptions::GetSystem() const
{
return pImp->GetSystem();
}
const OUString& SvtHelpOptions::GetHelpStyleSheet()const
{
return pImp->GetHelpStyleSheet();
}
void SvtHelpOptions::SetHelpStyleSheet(const OUString& rStyleSheet)
{
pImp->SetHelpStyleSheet(rStyleSheet);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */