2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-11 09:51:50 +01: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 .
|
|
|
|
*/
|
2006-09-17 13:30:50 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2009-10-06 07:38:24 +02:00
|
|
|
#include <unotools/useroptions.hxx>
|
2008-12-09 11:54:53 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <unotools/configmgr.hxx>
|
|
|
|
#include <com/sun/star/uno/Any.hxx>
|
|
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
2010-10-16 03:20:00 -05:00
|
|
|
#include <osl/mutex.hxx>
|
2004-06-25 16:25:36 +00:00
|
|
|
#include <rtl/instance.hxx>
|
2009-10-06 07:38:24 +02:00
|
|
|
#include "itemholder1.hxx"
|
2004-11-15 16:24:12 +00:00
|
|
|
|
2008-12-09 11:54:53 +00:00
|
|
|
#include <com/sun/star/beans/Property.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/beans/PropertyAttribute.hpp>
|
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
|
|
#include <com/sun/star/container/XNameContainer.hpp>
|
|
|
|
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
2009-08-06 12:44:16 +00:00
|
|
|
#include <com/sun/star/util/XChangesListener.hpp>
|
|
|
|
#include <com/sun/star/util/XChangesNotifier.hpp>
|
|
|
|
#include <com/sun/star/util/ChangesEvent.hpp>
|
2008-12-09 11:54:53 +00:00
|
|
|
#include <comphelper/configurationhelper.hxx>
|
2011-11-14 11:49:31 +01:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2008-12-09 11:54:53 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
using namespace utl;
|
2009-08-06 12:44:16 +00:00
|
|
|
using namespace com::sun::star;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2012-03-28 11:35:55 +01:00
|
|
|
namespace
|
|
|
|
{
|
2009-08-06 12:44:16 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
// vOptionNames[] -- names of the user option entries
|
|
|
|
// The order corresponds to the #define USER_OPT_* list in useroptions.hxx.
|
2012-11-13 17:53:42 +01:00
|
|
|
char const * const vOptionNames[] = {
|
|
|
|
"l", // USER_OPT_CITY
|
|
|
|
"o", // USER_OPT_COMPANY
|
|
|
|
"c", // USER_OPT_COUNTRY
|
|
|
|
"mail", // USER_OPT_EMAIL
|
|
|
|
"facsimiletelephonenumber", // USER_OPT_FAX
|
|
|
|
"givenname", // USER_OPT_FIRSTNAME
|
|
|
|
"sn", // USER_OPT_LASTNAME
|
|
|
|
"position", // USER_OPT_POSITION
|
|
|
|
"st", // USER_OPT_STATE
|
|
|
|
"street", // USER_OPT_STREET
|
|
|
|
"homephone", // USER_OPT_TELEPHONEHOME
|
|
|
|
"telephonenumber", // USER_OPT_TELEPHONEWORK
|
|
|
|
"title", // USER_OPT_TITLE
|
|
|
|
"initials", // USER_OPT_ID
|
|
|
|
"postalcode", // USER_OPT_ZIP
|
|
|
|
"fathersname", // USER_OPT_FATHERSNAME
|
|
|
|
"apartment", // USER_OPT_APARTMENT
|
|
|
|
"customernumber" // USER_OPT_CUSTOMERNUMBER
|
2009-08-06 12:44:16 +00:00
|
|
|
};
|
2012-08-29 23:55:45 +01:00
|
|
|
const sal_uInt16 nOptionNameCount = SAL_N_ELEMENTS(vOptionNames);
|
2000-09-25 09:00:42 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
} // namespace
|
2000-09-25 09:00:42 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
boost::weak_ptr<SvtUserOptions::Impl> SvtUserOptions::pSharedImpl;
|
2008-12-09 11:54:53 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
class SvtUserOptions::ChangeListener : public cppu::WeakImplHelper1<util::XChangesListener>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ChangeListener (Impl& rParent): m_rParent(rParent) { }
|
2008-12-09 11:54:53 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
// XChangesListener
|
|
|
|
virtual void SAL_CALL changesOccurred (util::ChangesEvent const& Event) throw(uno::RuntimeException);
|
|
|
|
// XEventListener
|
|
|
|
virtual void SAL_CALL disposing (lang::EventObject const& Source) throw(uno::RuntimeException);
|
2008-12-09 11:54:53 +00:00
|
|
|
|
|
|
|
private:
|
2012-08-17 10:20:17 +02:00
|
|
|
Impl& m_rParent;
|
2000-09-25 09:00:42 +00:00
|
|
|
};
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
class SvtUserOptions::Impl : public utl::ConfigurationBroadcaster
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Impl ();
|
2000-09-25 09:00:42 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
OUString GetFullName () const;
|
2000-09-25 09:00:42 +00:00
|
|
|
|
2014-02-19 12:30:34 +01:00
|
|
|
bool IsTokenReadonly (sal_uInt16 nToken) const;
|
2012-08-17 10:20:17 +02:00
|
|
|
OUString GetToken (sal_uInt16 nToken) const;
|
|
|
|
void SetToken (sal_uInt16 nToken, OUString const& rNewToken);
|
|
|
|
void Notify ();
|
2003-04-01 13:15:09 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
private:
|
|
|
|
uno::Reference<util::XChangesListener> m_xChangeListener;
|
|
|
|
uno::Reference<container::XNameAccess> m_xCfg;
|
|
|
|
uno::Reference<beans::XPropertySet> m_xData;
|
|
|
|
};
|
2009-08-06 12:44:16 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
void SvtUserOptions::ChangeListener::changesOccurred (util::ChangesEvent const& rEvent) throw(uno::RuntimeException)
|
2009-08-06 12:44:16 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
if (rEvent.Changes.getLength())
|
2009-08-06 12:44:16 +00:00
|
|
|
m_rParent.Notify();
|
|
|
|
}
|
2000-09-25 09:00:42 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
void SvtUserOptions::ChangeListener::disposing (lang::EventObject const& rSource) throw(uno::RuntimeException)
|
2004-06-25 16:25:36 +00:00
|
|
|
{
|
2009-08-06 12:44:16 +00:00
|
|
|
try
|
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
uno::Reference<util::XChangesNotifier> xChgNot(rSource.Source, uno::UNO_QUERY_THROW);
|
2009-08-06 12:44:16 +00:00
|
|
|
xChgNot->removeChangesListener(this);
|
|
|
|
}
|
2012-08-17 10:20:17 +02:00
|
|
|
catch (uno::Exception&)
|
2009-08-06 12:44:16 +00:00
|
|
|
{
|
|
|
|
}
|
2004-06-25 16:25:36 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
SvtUserOptions::Impl::Impl() :
|
|
|
|
m_xChangeListener( new ChangeListener(*this) )
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
m_xCfg = uno::Reference<container::XNameAccess>(
|
|
|
|
comphelper::ConfigurationHelper::openConfig(
|
2012-10-16 14:05:41 +02:00
|
|
|
comphelper::getProcessComponentContext(),
|
2012-11-13 17:53:42 +01:00
|
|
|
"org.openoffice.UserProfile/Data",
|
2012-08-17 10:20:17 +02:00
|
|
|
comphelper::ConfigurationHelper::E_STANDARD
|
|
|
|
),
|
|
|
|
uno::UNO_QUERY
|
|
|
|
);
|
2008-12-09 11:54:53 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
m_xData = uno::Reference<beans::XPropertySet>(m_xCfg, uno::UNO_QUERY);
|
|
|
|
uno::Reference<util::XChangesNotifier> xChgNot(m_xCfg, uno::UNO_QUERY);
|
2009-08-06 12:44:16 +00:00
|
|
|
try
|
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
xChgNot->addChangesListener(m_xChangeListener);
|
2009-08-06 12:44:16 +00:00
|
|
|
}
|
2012-08-17 10:20:17 +02:00
|
|
|
catch (uno::RuntimeException&)
|
2009-08-06 12:44:16 +00:00
|
|
|
{
|
|
|
|
}
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
2012-08-17 10:20:17 +02:00
|
|
|
catch (uno::Exception const& ex)
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
|
|
|
m_xCfg.clear();
|
2013-02-23 13:31:09 +01:00
|
|
|
SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
OUString SvtUserOptions::Impl::GetToken (sal_uInt16 nToken) const
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
OUString sToken;
|
|
|
|
if (nToken < nOptionNameCount)
|
2001-06-21 17:01:26 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (m_xData.is())
|
2012-11-13 17:53:42 +01:00
|
|
|
m_xData->getPropertyValue(OUString::createFromAscii(vOptionNames[nToken])) >>= sToken;
|
2012-08-17 10:20:17 +02:00
|
|
|
}
|
|
|
|
catch (uno::Exception const& ex)
|
|
|
|
{
|
2013-02-23 13:31:09 +01:00
|
|
|
SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
|
2012-08-17 10:20:17 +02:00
|
|
|
}
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
2012-08-17 10:20:17 +02:00
|
|
|
else
|
|
|
|
SAL_WARN("unotools.config", "SvtUserOptions::Impl::GetToken(): invalid token");
|
|
|
|
return sToken;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
void SvtUserOptions::Impl::SetToken (sal_uInt16 nToken, OUString const& sToken)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
if (nToken < nOptionNameCount)
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (m_xData.is())
|
2012-11-13 17:53:42 +01:00
|
|
|
m_xData->setPropertyValue(OUString::createFromAscii(vOptionNames[nToken]), uno::makeAny(sToken));
|
2012-08-17 10:20:17 +02:00
|
|
|
comphelper::ConfigurationHelper::flush(m_xCfg);
|
|
|
|
}
|
|
|
|
catch (uno::Exception const& ex)
|
|
|
|
{
|
2013-02-23 13:31:09 +01:00
|
|
|
SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
|
2012-08-17 10:20:17 +02:00
|
|
|
}
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
2012-08-17 10:20:17 +02:00
|
|
|
else
|
|
|
|
SAL_WARN("unotools.config", "SvtUserOptions::Impl::GetToken(): invalid token");
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
OUString SvtUserOptions::Impl::GetFullName () const
|
2000-10-09 05:30:33 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
// TODO international name
|
|
|
|
OUString sFullName = GetToken(USER_OPT_FIRSTNAME).trim();
|
|
|
|
if (!sFullName.isEmpty())
|
|
|
|
sFullName += " ";
|
|
|
|
sFullName += GetToken(USER_OPT_LASTNAME).trim();
|
|
|
|
return sFullName;
|
2000-10-09 05:30:33 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
void SvtUserOptions::Impl::Notify ()
|
2001-09-28 08:54:56 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
NotifyListeners(0);
|
2001-09-28 08:54:56 +00:00
|
|
|
}
|
2004-04-29 15:48:13 +00:00
|
|
|
|
2014-02-19 12:30:34 +01:00
|
|
|
bool SvtUserOptions::Impl::IsTokenReadonly (sal_uInt16 nToken) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
if (nToken < nOptionNameCount)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
uno::Reference<beans::XPropertySet> xData(m_xCfg, uno::UNO_QUERY);
|
|
|
|
uno::Reference<beans::XPropertySetInfo> xInfo = xData->getPropertySetInfo();
|
2012-11-13 17:53:42 +01:00
|
|
|
beans::Property aProp = xInfo->getPropertyByName(OUString::createFromAscii(vOptionNames[nToken]));
|
2012-08-17 10:20:17 +02:00
|
|
|
return ((aProp.Attributes & beans::PropertyAttribute::READONLY) ==
|
|
|
|
beans::PropertyAttribute::READONLY);
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
2012-08-17 10:20:17 +02:00
|
|
|
else
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
SAL_WARN("unotools.config", "SvtUserOptions::Impl::IsTokenReadonly(): invalid token");
|
2014-02-19 12:30:34 +01:00
|
|
|
return false;
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
SvtUserOptions::SvtUserOptions ()
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
// Global access, must be guarded (multithreading)
|
|
|
|
osl::MutexGuard aGuard(GetInitMutex());
|
2008-12-09 11:54:53 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
if (pSharedImpl.expired())
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
pImpl.reset(new Impl);
|
|
|
|
pSharedImpl = pImpl;
|
|
|
|
ItemHolder1::holdConfigItem(E_USEROPTIONS);
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
2012-08-17 10:20:17 +02:00
|
|
|
pImpl = pSharedImpl.lock();
|
|
|
|
pImpl->AddListener(this);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
SvtUserOptions::~SvtUserOptions()
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
// Global access, must be guarded (multithreading)
|
|
|
|
osl::MutexGuard aGuard( GetInitMutex() );
|
|
|
|
pImpl->RemoveListener(this);
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
2003-04-01 13:15:09 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
namespace
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
class theUserOptionsMutex : public rtl::Static<osl::Mutex, theUserOptionsMutex>{};
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
osl::Mutex& SvtUserOptions::GetInitMutex()
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
return theUserOptionsMutex::get();
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
OUString SvtUserOptions::GetCompany () const { return GetToken(USER_OPT_COMPANY); }
|
|
|
|
OUString SvtUserOptions::GetFirstName () const { return GetToken(USER_OPT_FIRSTNAME); }
|
|
|
|
OUString SvtUserOptions::GetLastName () const { return GetToken(USER_OPT_LASTNAME); }
|
|
|
|
OUString SvtUserOptions::GetID () const { return GetToken(USER_OPT_ID); }
|
|
|
|
OUString SvtUserOptions::GetStreet () const { return GetToken(USER_OPT_STREET); }
|
|
|
|
OUString SvtUserOptions::GetCity () const { return GetToken(USER_OPT_CITY); }
|
|
|
|
OUString SvtUserOptions::GetState () const { return GetToken(USER_OPT_STATE); }
|
|
|
|
OUString SvtUserOptions::GetZip () const { return GetToken(USER_OPT_ZIP); }
|
|
|
|
OUString SvtUserOptions::GetCountry () const { return GetToken(USER_OPT_COUNTRY); }
|
|
|
|
OUString SvtUserOptions::GetPosition () const { return GetToken(USER_OPT_POSITION); }
|
|
|
|
OUString SvtUserOptions::GetTitle () const { return GetToken(USER_OPT_TITLE); }
|
|
|
|
OUString SvtUserOptions::GetTelephoneHome () const { return GetToken(USER_OPT_TELEPHONEHOME); }
|
|
|
|
OUString SvtUserOptions::GetTelephoneWork () const { return GetToken(USER_OPT_TELEPHONEWORK); }
|
|
|
|
OUString SvtUserOptions::GetFax () const { return GetToken(USER_OPT_FAX); }
|
|
|
|
OUString SvtUserOptions::GetEmail () const { return GetToken(USER_OPT_EMAIL); }
|
|
|
|
OUString SvtUserOptions::GetCustomerNumber () const { return GetToken(USER_OPT_CUSTOMERNUMBER); }
|
2008-12-09 11:54:53 +00:00
|
|
|
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
void SvtUserOptions::SetCustomerNumber (OUString const& sToken) { SetToken(USER_OPT_CUSTOMERNUMBER, sToken); }
|
2008-12-09 11:54:53 +00:00
|
|
|
|
2014-02-19 12:30:34 +01:00
|
|
|
bool SvtUserOptions::IsTokenReadonly (sal_uInt16 nToken) const
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
osl::MutexGuard aGuard(GetInitMutex());
|
|
|
|
return pImpl->IsTokenReadonly(nToken);
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
OUString SvtUserOptions::GetToken (sal_uInt16 nToken) const
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
osl::MutexGuard aGuard(GetInitMutex());
|
|
|
|
return pImpl->GetToken(nToken);
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
void SvtUserOptions::SetToken (sal_uInt16 nToken, OUString const& rNewToken)
|
2008-12-09 11:54:53 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
osl::MutexGuard aGuard(GetInitMutex());
|
|
|
|
pImpl->SetToken(nToken, rNewToken);
|
2008-12-09 11:54:53 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 10:20:17 +02:00
|
|
|
OUString SvtUserOptions::GetFullName () const
|
2004-04-29 15:48:13 +00:00
|
|
|
{
|
2012-08-17 10:20:17 +02:00
|
|
|
osl::MutexGuard aGuard(GetInitMutex());
|
|
|
|
return pImpl->GetFullName();
|
2004-04-29 15:48:13 +00:00
|
|
|
}
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|