24#include <QtWidgets/QApplication>
26#include <com/sun/star/beans/Optional.hpp>
27#include <com/sun/star/beans/UnknownPropertyException.hpp>
28#include <com/sun/star/beans/XPropertyChangeListener.hpp>
29#include <com/sun/star/beans/XPropertySet.hpp>
30#include <com/sun/star/beans/XPropertySetInfo.hpp>
31#include <com/sun/star/beans/XVetoableChangeListener.hpp>
32#include <com/sun/star/lang/IllegalArgumentException.hpp>
33#include <com/sun/star/lang/XServiceInfo.hpp>
34#include <com/sun/star/uno/Any.hxx>
35#include <com/sun/star/uno/Reference.hxx>
36#include <com/sun/star/uno/Sequence.hxx>
37#include <com/sun/star/uno/XComponentContext.hpp>
38#include <com/sun/star/uno/XCurrentContext.hpp>
41#include <rtl/ustring.hxx>
43#include <uno/current_context.hxx>
46#include <osl/process.h>
47#include <osl/thread.h>
53class Service :
public cppu::WeakImplHelper<css::lang::XServiceInfo, css::beans::XPropertySet>
60 Service(
const Service&) =
delete;
61 Service& operator=(
const Service&) =
delete;
63 virtual ~Service()
override {}
67 return "com.sun.star.comp.configuration.backend.KF5Backend";
77 return {
"com.sun.star.configuration.backend.KF5Backend" };
80 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo()
override
82 return css::uno::Reference<css::beans::XPropertySetInfo>();
85 virtual void SAL_CALL
setPropertyValue(OUString
const&, css::uno::Any
const&)
override;
87 virtual css::uno::Any SAL_CALL
getPropertyValue(OUString
const& PropertyName)
override;
89 virtual void SAL_CALL addPropertyChangeListener(
90 OUString
const&, css::uno::Reference<css::beans::XPropertyChangeListener>
const&)
override
94 virtual void SAL_CALL removePropertyChangeListener(
95 OUString
const&, css::uno::Reference<css::beans::XPropertyChangeListener>
const&)
override
99 virtual void SAL_CALL addVetoableChangeListener(
100 OUString
const&, css::uno::Reference<css::beans::XVetoableChangeListener>
const&)
override
104 virtual void SAL_CALL removeVetoableChangeListener(
105 OUString
const&, css::uno::Reference<css::beans::XVetoableChangeListener>
const&)
override
109 std::map<OUString, css::beans::Optional<css::uno::Any>> m_KDESettings;
112OString getDisplayArg()
115 const sal_uInt32 nParams = osl_getCommandArgCount();
116 for (sal_uInt32 nIdx = 0; nIdx < nParams; ++nIdx)
118 osl_getCommandArg(nIdx, &aParam.pData);
119 if (aParam !=
"-display")
123 osl_getCommandArg(nIdx, &aParam.pData);
129OString getExecutable()
131 OUString aParam, aBin;
132 osl_getExecutableFile(&aParam.pData);
133 osl_getSystemPathFromFileURL(aParam.pData, &aBin.pData);
137void readKDESettings(std::map<OUString, css::beans::Optional<css::uno::Any>>& rSettings)
139 const std::vector<OUString> aKeys
140 = {
"EnableATToolSupport",
"ExternalMailer",
"SourceViewFontHeight",
141 "SourceViewFontName",
"WorkPathVariable",
"ooInetFTPProxyName",
142 "ooInetFTPProxyPort",
"ooInetHTTPProxyName",
"ooInetHTTPProxyPort",
143 "ooInetHTTPSProxyName",
"ooInetHTTPSProxyPort",
"ooInetNoProxy",
146 for (
const OUString& aKey : aKeys)
149 std::pair<OUString, css::beans::Optional<css::uno::Any>> elem
150 = std::make_pair(aKey, aValue);
151 rSettings.insert(elem);
158void initQApp(std::map<OUString, css::beans::Optional<css::uno::Any>>& rSettings)
160 const auto aDisplay = getDisplayArg();
161 int nFakeArgc = aDisplay.isEmpty() ? 2 : 3;
162 char** pFakeArgv =
new char*[nFakeArgc];
164 pFakeArgv[0] = strdup(getExecutable().getStr());
165 pFakeArgv[1] = strdup(
"--nocrashhandler");
166 if (!aDisplay.isEmpty())
167 pFakeArgv[2] = strdup(aDisplay.getStr());
169 char* session_manager =
nullptr;
170 if (
auto* session_manager_env = getenv(
"SESSION_MANAGER"))
172 session_manager = strdup(session_manager_env);
173 unsetenv(
"SESSION_MANAGER");
181 std::unique_ptr<QApplication> app(
new QApplication(nFakeArgc, pFakeArgv));
182 QObject::connect(app.get(), &QObject::destroyed, app.get(), [nFakeArgc, pFakeArgv]() {
183 for (int i = 0; i < nFakeArgc; ++i)
188 readKDESettings(rSettings);
191 if (session_manager !=
nullptr)
194 setenv(
"SESSION_MANAGER", session_manager, 1);
195 free(session_manager);
201 css::uno::Reference<css::uno::XCurrentContext> context(css::uno::getCurrentContext());
206 context->getValueByName(
"system.desktop-environment") >>=
desktop;
213 initQApp(m_KDESettings);
217 readKDESettings(m_KDESettings);
221void Service::setPropertyValue(OUString
const&, css::uno::Any
const&)
223 throw css::lang::IllegalArgumentException(
"setPropertyValue not supported", getXWeak(), -1);
226css::uno::Any Service::getPropertyValue(OUString
const& PropertyName)
228 if (PropertyName ==
"EnableATToolSupport" || PropertyName ==
"ExternalMailer"
229 || PropertyName ==
"SourceViewFontHeight" || PropertyName ==
"SourceViewFontName"
230 || PropertyName ==
"WorkPathVariable" || PropertyName ==
"ooInetFTPProxyName"
231 || PropertyName ==
"ooInetFTPProxyPort" || PropertyName ==
"ooInetHTTPProxyName"
232 || PropertyName ==
"ooInetHTTPProxyPort" || PropertyName ==
"ooInetHTTPSProxyName"
233 || PropertyName ==
"ooInetHTTPSProxyPort" || PropertyName ==
"ooInetNoProxy"
234 || PropertyName ==
"ooInetProxyType")
236 std::map<OUString, css::beans::Optional<css::uno::Any>>::iterator it
237 = m_KDESettings.find(PropertyName);
238 if (it != m_KDESettings.end())
239 return css::uno::Any(it->second);
241 return css::uno::Any(css::beans::Optional<css::uno::Any>());
243 else if (PropertyName ==
"givenname" || PropertyName ==
"sn"
244 || PropertyName ==
"TemplatePathVariable")
246 return css::uno::Any(css::beans::Optional<css::uno::Any>());
249 throw css::beans::UnknownPropertyException(PropertyName, getXWeak());
252extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
253shell_kf5desktop_get_implementation(css::uno::XComponentContext*,
254 css::uno::Sequence<css::uno::Any>
const&)
256 return cppu::acquire(
new Service());
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::beans::Optional< css::uno::Any > getValue(std::u16string_view id)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)