Update ooo320-m1
[ooovba.git] / shell / source / backends / gconfbe / gconfbackend.cxx
blobd5ae5915b2bb91d22cd6d26cf577f9ba876893cb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gconfbackend.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
34 #include "gconfbackend.hxx"
35 #include "gconflayer.hxx"
36 #include <com/sun/star/configuration/backend/ComponentChangeEvent.hpp>
38 #ifndef INCLUDED_VECTOR
39 #include <vector>
40 #define INCLUDED_VECTOR
41 #endif
42 #include <osl/process.h>
43 #include <osl/time.h>
44 #include <rtl/ustrbuf.hxx>
45 #include <rtl/byteseq.h>
47 #include <stdio.h>
49 #ifdef ENABLE_LOCKDOWN
50 // each entry should have an identifying ConfigurationSetting
51 static const ConfigurationValue SetupConfigurationValuesList[] =
54 SETTING_WRITER_DEFAULT_DOC_FORMAT,
55 "/apps/openoffice/writer_default_document_format",
56 "org.openoffice.Setup/Office/Factories/com.sun.star.text.TextDocument/ooSetupFactoryDefaultFilter",
57 "string",
58 sal_False,
59 sal_False,
60 SETTINGS_LAST
64 SETTING_IMPRESS_DEFAULT_DOC_FORMAT,
65 "/apps/openoffice/impress_default_document_format",
66 "org.openoffice.Setup/Office/Factories/com.sun.star.presentation.PresentationDocument/ooSetupFactoryDefaultFilter",
67 "string",
68 sal_False,
69 sal_False,
70 SETTINGS_LAST
74 SETTING_CALC_DEFAULT_DOC_FORMAT,
75 "/apps/openoffice/calc_default_document_format",
76 "org.openoffice.Setup/Office/Factories/com.sun.star.sheet.SpreadsheetDocument/ooSetupFactoryDefaultFilter",
77 "string",
78 sal_False,
79 sal_False,
80 SETTINGS_LAST
83 #endif // ENABLE_LOCKDOWN
85 #ifdef ENABLE_LOCKDOWN
86 // each entry should have an identifying ConfigurationSetting
87 static const ConfigurationValue RecoveryConfigurationValuesList[] =
90 SETTING_AUTO_SAVE,
91 GCONF_AUTO_SAVE_KEY,
92 "org.openoffice.Office.Recovery/AutoSave/Enabled",
93 "boolean",
94 sal_False,
95 sal_False,
96 SETTINGS_LAST
100 SETTING_AUTO_SAVE_INTERVAL,
101 "/apps/openoffice/auto_save_interval",
102 "org.openoffice.Office.Recovery/AutoSave/TimeIntervall",
103 "int",
104 sal_False,
105 sal_False,
106 SETTING_AUTO_SAVE
109 #endif // ENABLE_LOCKDOWN
112 * This should be in a different backend actually, but this has to wait ..
115 #ifdef ENABLE_LOCKDOWN
116 // each entry should have an identifying ConfigurationSetting
117 static const ConfigurationValue UserProfileConfigurationValuesList[] =
120 SETTING_USER_GIVENNAME,
121 "/desktop/gnome/url-handlers/mailto/command", // dummy, needed for getTimestamp
122 "org.openoffice.UserProfile/Data/givenname",
123 "string",
124 sal_False,
125 sal_True,
126 SETTING_USER_GIVENNAME
130 SETTING_USER_SURNAME,
131 "/desktop/gnome/url-handlers/mailto/command", // dummy, needed for getTimestamp
132 "org.openoffice.UserProfile/Data/sn",
133 "string",
134 sal_False,
135 sal_True,
136 SETTING_USER_SURNAME
139 #endif // ENABLE_LOCKDOWN
141 // each entry should have an identifying ConfigurationSetting
142 static const ConfigurationValue VCLConfigurationValuesList[] =
145 SETTING_ENABLE_ACCESSIBILITY,
146 "/desktop/gnome/interface/accessibility",
147 "org.openoffice.VCL/Settings/Accessibility/EnableATToolSupport",
148 "string",
149 sal_False,
150 sal_True,
151 SETTINGS_LAST
154 #ifdef ENABLE_LOCKDOWN
157 SETTING_DISABLE_PRINTING,
158 "/desktop/gnome/lockdown/disable_printing",
159 "org.openoffice.VCL/Settings/DesktopManagement/DisablePrinting",
160 "string",
161 sal_False,
162 sal_True,
163 SETTINGS_LAST
166 #endif // ENABLE_LOCKDOWN
170 // each entry should have an identifying ConfigurationSetting
171 static const ConfigurationValue InetConfigurationValuesList[] =
174 SETTING_PROXY_MODE,
175 GCONF_PROXY_MODE_KEY,
176 "org.openoffice.Inet/Settings/ooInetProxyType",
177 "int",
178 sal_False,
179 sal_True,
180 SETTINGS_LAST
184 SETTING_PROXY_HTTP_HOST,
185 "/system/http_proxy/host",
186 "org.openoffice.Inet/Settings/ooInetHTTPProxyName",
187 "string",
188 sal_False,
189 sal_False,
190 SETTING_PROXY_MODE
194 SETTING_PROXY_HTTP_PORT,
195 "/system/http_proxy/port",
196 "org.openoffice.Inet/Settings/ooInetHTTPProxyPort",
197 "int",
198 sal_False,
199 sal_False,
200 SETTING_PROXY_MODE
204 SETTING_PROXY_HTTPS_HOST,
205 "/system/proxy/secure_host",
206 "org.openoffice.Inet/Settings/ooInetHTTPSProxyName",
207 "string",
208 sal_False,
209 sal_False,
210 SETTING_PROXY_MODE
214 SETTING_PROXY_HTTPS_PORT,
215 "/system/proxy/secure_port",
216 "org.openoffice.Inet/Settings/ooInetHTTPSProxyPort",
217 "int",
218 sal_False,
219 sal_False,
220 SETTING_PROXY_MODE
224 SETTING_PROXY_FTP_HOST,
225 "/system/proxy/ftp_host",
226 "org.openoffice.Inet/Settings/ooInetFTPProxyName",
227 "string",
228 sal_False,
229 sal_False,
230 SETTING_PROXY_MODE
234 SETTING_PROXY_FTP_PORT,
235 "/system/proxy/ftp_port",
236 "org.openoffice.Inet/Settings/ooInetFTPProxyPort",
237 "int",
238 sal_False,
239 sal_False,
240 SETTING_PROXY_MODE
244 SETTING_NO_PROXY_FOR,
245 "/system/http_proxy/ignore_hosts",
246 "org.openoffice.Inet/Settings/ooInetNoProxy",
247 "string",
248 sal_False,
249 sal_True,
250 SETTING_PROXY_MODE
254 // each entry should have an identifying ConfigurationSetting
255 static const ConfigurationValue CommonConfigurationValuesList[] =
258 SETTING_MAILER_PROGRAM,
259 "/desktop/gnome/url-handlers/mailto/command",
260 "org.openoffice.Office.Common/ExternalMailer/Program",
261 "string",
262 sal_False,
263 sal_True,
264 SETTINGS_LAST
267 SETTING_SOURCEVIEWFONT_NAME,
268 "/desktop/gnome/interface/monospace_font_name",
269 "org.openoffice.Office.Common/Font/SourceViewFont/FontName",
270 "string",
271 sal_False,
272 sal_True,
273 SETTINGS_LAST
276 SETTING_SOURCEVIEWFONT_HEIGHT,
277 "/desktop/gnome/interface/monospace_font_name",
278 "org.openoffice.Office.Common/Font/SourceViewFont/FontHeight",
279 "short",
280 sal_False,
281 sal_True,
282 SETTINGS_LAST
285 #ifdef ENABLE_LOCKDOWN
288 SETTING_USE_SYSTEM_FILE_DIALOG,
289 "/apps/openoffice/use_system_file_dialog",
290 "org.openoffice.Office.Common/Misc/UseSystemFileDialog",
291 "boolean",
292 sal_False,
293 sal_False,
294 SETTINGS_LAST
298 SETTING_DISABLE_UI_CUSTOMIZATION,
299 "/apps/openoffice/lockdown/disable_ui_customization",
300 "org.openoffice.Office.Common/Misc/DisableUICustomization",
301 "boolean",
302 sal_False,
303 sal_False,
304 SETTINGS_LAST
308 SETTING_PRINTING_MODIFIES_DOCUMENT,
309 "/apps/openoffice/printing_modifies_doc",
310 "org.openoffice.Office.Common/Print/PrintingModifiesDocument",
311 "boolean",
312 sal_False,
313 sal_False,
314 SETTINGS_LAST
318 SETTING_SHOW_ICONS_IN_MENUS,
319 "/apps/openoffice/show_menu_icons",
320 "org.openoffice.Office.Common/View/Menu/ShowIconsInMenues",
321 "boolean",
322 sal_False,
323 sal_False,
324 SETTINGS_LAST
328 SETTING_SHOW_INACTIVE_MENUITEMS,
329 "/apps/openoffice/show_menu_inactive_items",
330 "org.openoffice.Office.Common/View/Menu/DontHideDisabledEntry",
331 "boolean",
332 sal_False,
333 sal_False,
334 SETTINGS_LAST
338 SETTING_SHOW_FONT_PREVIEW,
339 "/apps/openoffice/show_font_preview",
340 "org.openoffice.Office.Common/Font/View/ShowFontBoxWYSIWYG",
341 "boolean",
342 sal_False,
343 sal_False,
344 SETTINGS_LAST
348 SETTING_SHOW_FONT_HISTORY,
349 "/apps/openoffice/show_font_history",
350 "org.openoffice.Office.Common/Font/View/History",
351 "boolean",
352 sal_False,
353 sal_False,
354 SETTINGS_LAST
358 SETTING_ENABLE_OPENGL,
359 "/apps/openoffice/use_opengl",
360 "org.openoffice.Office.Common/_3D_Engine/OpenGL",
361 "boolean",
362 sal_False,
363 sal_False,
364 SETTINGS_LAST
368 SETTING_OPTIMIZE_OPENGL,
369 "/apps/openoffice/optimize_opengl",
370 "org.openoffice.Office.Common/_3D_Engine/OpenGL_Faster",
371 "boolean",
372 sal_False,
373 sal_False,
374 SETTINGS_LAST
378 SETTING_USE_SYSTEM_FONT,
379 "/apps/openoffice/use_system_font",
380 "org.openoffice.Office.Common/Accessibility/IsSystemFont",
381 "boolean",
382 sal_False,
383 sal_False,
384 SETTINGS_LAST
388 SETTING_USE_FONT_ANTI_ALIASING,
389 "/apps/openoffice/use_font_anti_aliasing",
390 "org.openoffice.Office.Common/View/FontAntiAliasing/Enabled",
391 "boolean",
392 sal_False,
393 sal_False,
394 SETTINGS_LAST
398 SETTING_FONT_ANTI_ALIASING_MIN_PIXEL,
399 "/apps/openoffice/font_anti_aliasing_min_pixel",
400 "org.openoffice.Office.Common/View/FontAntiAliasing/MinPixelHeight",
401 "short",
402 sal_False,
403 sal_True,
404 SETTINGS_LAST
408 SETTING_WARN_CREATE_PDF,
409 "/apps/openoffice/lockdown/warn_info_create_pdf",
410 "org.openoffice.Office.Common/Security/Scripting/WarnCreatePDF",
411 "boolean",
412 sal_False,
413 sal_False,
414 SETTINGS_LAST
418 SETTING_WARN_PRINT_DOC,
419 "/apps/openoffice/lockdown/warn_info_printing",
420 "org.openoffice.Office.Common/Security/Scripting/WarnPrintDoc",
421 "boolean",
422 sal_False,
423 sal_False,
424 SETTINGS_LAST
428 SETTING_WARN_SAVEORSEND_DOC,
429 "/apps/openoffice/lockdown/warn_info_saving",
430 "org.openoffice.Office.Common/Security/Scripting/WarnSaveOrSendDoc",
431 "boolean",
432 sal_False,
433 sal_False,
434 SETTINGS_LAST
438 SETTING_WARN_SIGN_DOC,
439 "/apps/openoffice/lockdown/warn_info_signing",
440 "org.openoffice.Office.Common/Security/Scripting/WarnSignDoc",
441 "boolean",
442 sal_False,
443 sal_False,
444 SETTINGS_LAST
448 SETTING_REMOVE_PERSONAL_INFO,
449 "/apps/openoffice/lockdown/remove_personal_info_on_save",
450 "org.openoffice.Office.Common/Security/Scripting/RemovePersonalInfoOnSaving",
451 "boolean",
452 sal_False,
453 sal_False,
454 SETTINGS_LAST
458 SETTING_RECOMMEND_PASSWORD,
459 "/apps/openoffice/lockdown/recommend_password_on_save",
460 "org.openoffice.Office.Common/Security/Scripting/RecommendPasswordProtection",
461 "boolean",
462 sal_False,
463 sal_False,
464 SETTINGS_LAST
468 SETTING_UNDO_STEPS,
469 "/apps/openoffice/undo_steps",
470 "org.openoffice.Office.Common/Undo/Steps",
471 "int",
472 sal_False,
473 sal_False,
474 SETTINGS_LAST
478 SETTING_SYMBOL_SET,
479 "/apps/openoffice/icon_size",
480 "org.openoffice.Office.Common/Misc/SymbolSet",
481 "short",
482 sal_False,
483 sal_True,
484 SETTINGS_LAST
488 SETTING_MACRO_SECURITY_LEVEL,
489 "/apps/openoffice/lockdown/macro_security_level",
490 "org.openoffice.Office.Common/Security/Scripting/MacroSecurityLevel",
491 "int",
492 sal_False,
493 sal_False,
494 SETTINGS_LAST
498 SETTING_CREATE_BACKUP,
499 "/apps/openoffice/create_backup",
500 "org.openoffice.Office.Common/Save/Document/CreateBackup",
501 "boolean",
502 sal_False,
503 sal_False,
504 SETTINGS_LAST
508 SETTING_WARN_ALIEN_FORMAT,
509 "/apps/openoffice/warn_alien_format",
510 "org.openoffice.Office.Common/Save/Document/WarnAlienFormat",
511 "boolean",
512 sal_False,
513 sal_False,
514 SETTINGS_LAST
517 #endif // ENABLE_LOCKDOWN
521 static const ConfigurationValue PathsConfigurationValuesList[] =
524 SETTING_WORK_DIRECTORY,
525 "/desktop/gnome/url-handlers/mailto/command", // dummy, needed for getTimestamp
526 "org.openoffice.Office.Paths/Variables/Work",
527 "string",
528 sal_False,
529 sal_True,
530 SETTING_WORK_DIRECTORY, // so that the existence of the dir can be checked
534 #ifdef ENABLE_LOCKDOWN
535 static const char * SetupPreloadValuesList[] =
537 "/apps/openoffice",
538 NULL
540 #endif // ENABLE_LOCKDOWN
542 #ifdef ENABLE_LOCKDOWN
543 static const char * RecoveryPreloadValuesList[] =
545 "/apps/openoffice",
546 NULL
548 #endif // ENABLE_LOCKDOWN
550 #ifdef ENABLE_LOCKDOWN
551 static const char * UserProfilePreloadValuesList[] =
553 NULL
555 #endif // ENABLE_LOCKDOWN
557 static const char * VCLPreloadValuesList[] =
559 "/desktop/gnome/interface",
560 #ifdef ENABLE_LOCKDOWN
561 "/desktop/gnome/lockdown",
562 #endif // ENABLE_LOCKDOWN
563 NULL
566 static const char * InetPreloadValuesList[] =
568 "/system/proxy",
569 "/system/http_proxy/host",
570 NULL
573 static const char * CommonPreloadValuesList[] =
575 "/desktop/gnome/url-handlers/mailto",
576 #ifdef ENABLE_LOCKDOWN
577 "/apps/openoffice/lockdown",
578 "/apps/openoffice",
579 #endif // ENABLE_LOCKDOWN
580 NULL
583 static const char * PathsPreloadValuesList[] =
585 NULL
588 //==============================================================================
591 void ONotificationThread::run()
593 mLoop= NULL;
594 //Need to start a GMain loop for notifications to work
595 mLoop=g_main_loop_new(g_main_context_default(),FALSE);
596 g_main_loop_run(mLoop);
597 } ;
601 //------------------------------------------------------------------------------
603 GconfBackend* GconfBackend::mInstance= 0;
605 GconfBackend* GconfBackend::createInstance(const uno::Reference<uno::XComponentContext>& xContext)
607 if(mInstance == 0)
609 mInstance = new GconfBackend (xContext);
612 return mInstance;
615 //------------------------------------------------------------------------------
617 GconfBackend::GconfBackend(const uno::Reference<uno::XComponentContext>& xContext)
618 throw (backend::BackendAccessException)
619 : BackendBase(mMutex), m_xContext(xContext)
620 // , mNotificationThread(NULL)
626 //------------------------------------------------------------------------------
628 GconfBackend::~GconfBackend(void) {
631 // delete (mNotificationThread);
632 GconfBackend::mClient = NULL;
636 //------------------------------------------------------------------------------
638 GConfClient* GconfBackend::mClient= 0;
641 GConfClient* GconfBackend::getGconfClient()
644 if (mClient == NULL)
646 /* initialize glib object type library */
647 g_type_init();
649 GError* aError = NULL;
650 if (!gconf_init(0, NULL, &aError))
652 rtl::OUStringBuffer msg;
653 msg.appendAscii("GconfBackend:GconfLayer: Cannot Initialize Gconf connection - " );
654 msg.appendAscii(aError->message);
656 g_error_free(aError);
657 aError = NULL;
658 throw uno::RuntimeException(msg.makeStringAndClear(),NULL);
661 mClient = gconf_client_get_default();
662 if (!mClient)
664 throw uno::RuntimeException(rtl::OUString::createFromAscii
665 ("GconfBackend:GconfLayer: Cannot Initialize Gconf connection"),NULL);
669 return mClient;
672 //------------------------------------------------------------------------------
674 uno::Reference<backend::XLayer> SAL_CALL GconfBackend::getLayer(
675 const rtl::OUString& aComponent, const rtl::OUString& /*aTimestamp*/)
676 throw (backend::BackendAccessException, lang::IllegalArgumentException)
678 uno::Reference<backend::XLayer> xLayer;
680 if( aComponent.equalsAscii("org.openoffice.Office.Common" ) )
682 xLayer = new GconfLayer( m_xContext,
683 CommonConfigurationValuesList,
684 G_N_ELEMENTS( CommonConfigurationValuesList ),
685 CommonPreloadValuesList );
687 else if( aComponent.equalsAscii("org.openoffice.Inet" ) )
689 xLayer = new GconfLayer( m_xContext,
690 InetConfigurationValuesList,
691 G_N_ELEMENTS( InetConfigurationValuesList ),
692 InetPreloadValuesList );
694 else if( aComponent.equalsAscii("org.openoffice.VCL" ) )
696 xLayer = new GconfLayer( m_xContext,
697 VCLConfigurationValuesList,
698 G_N_ELEMENTS( VCLConfigurationValuesList ),
699 VCLPreloadValuesList );
701 else if( aComponent.equalsAscii("org.openoffice.Office.Paths" ) )
703 xLayer = new GconfLayer( m_xContext,
704 PathsConfigurationValuesList,
705 G_N_ELEMENTS( PathsConfigurationValuesList ),
706 PathsPreloadValuesList );
709 #ifdef ENABLE_LOCKDOWN
710 else if( aComponent.equalsAscii("org.openoffice.UserProfile" ) )
712 xLayer = new GconfLayer( m_xContext,
713 UserProfileConfigurationValuesList,
714 G_N_ELEMENTS( UserProfileConfigurationValuesList ),
715 UserProfilePreloadValuesList );
717 else if( aComponent.equalsAscii("org.openoffice.Office.Recovery" ) )
719 xLayer = new GconfLayer( m_xContext,
720 RecoveryConfigurationValuesList,
721 G_N_ELEMENTS( RecoveryConfigurationValuesList ),
722 RecoveryPreloadValuesList );
724 else if( aComponent.equalsAscii("org.openoffice.Setup" ) )
726 xLayer = new GconfLayer( m_xContext,
727 SetupConfigurationValuesList,
728 G_N_ELEMENTS( SetupConfigurationValuesList ),
729 SetupPreloadValuesList );
731 #endif // ENABLE_LOCKDOWN
733 return xLayer;
736 //------------------------------------------------------------------------------
738 uno::Reference<backend::XUpdatableLayer> SAL_CALL
739 GconfBackend::getUpdatableLayer(const rtl::OUString& /*aComponent*/)
740 throw (backend::BackendAccessException,lang::NoSupportException,
741 lang::IllegalArgumentException)
743 throw lang::NoSupportException( rtl::OUString(
744 RTL_CONSTASCII_USTRINGPARAM("GconfBackend: No Update Operation allowed, Read Only access") ),
745 *this) ;
748 //------------------------------------------------------------------------------
750 // currently not used
751 #if 0
752 static void
753 keyChangedCallback(GConfClient* aClient,
754 guint aID,
755 GConfEntry* aEntry,
756 gpointer aBackend)
759 OSL_TRACE("In KeyChangedCallback Function");
760 rtl::OUString aGconfKey= rtl::OUString::createFromAscii(aEntry->key);
761 GconfBackend * aGconfBe = (GconfBackend*) aBackend;
763 aGconfBe->notifyListeners(aGconfKey);
766 #endif
768 //------------------------------------------------------------------------------
770 void GconfBackend::notifyListeners(const rtl::OUString& /*aGconfKey*/)
773 //look up associated component from Map using GconfKey
774 KeyMappingTable::iterator aIter;
775 rtl::OUString aComponent;
776 for( aIter= mKeyMap.begin(); aIter != mKeyMap.end(); aIter++)
778 if (aIter->second.mGconfName == aGconfKey)
780 aComponent = aIter->first;
781 break;
787 //Need to store updated layer TimeStamp as Gconf library
788 //has no access to TimeStamp via its api
789 TimeValue aTimeValue ={0,0} ;
790 osl_getSystemTime(&aTimeValue);
792 oslDateTime aLayerTS;
793 rtl::OUString aTimeStamp;
795 if (osl_getDateTimeFromTimeValue(&aTimeValue, &aLayerTS)) {
796 sal_Char asciiStamp [20] ;
798 sprintf(asciiStamp, "%04d%02d%02d%02d%02d%02dZ",
799 aLayerTS.Year, aLayerTS.Month, aLayerTS.Day,
800 aLayerTS.Hours, aLayerTS.Minutes, aLayerTS.Seconds) ;
801 aTimeStamp = rtl::OUString::createFromAscii(asciiStamp) ;
805 TSMappingTable::iterator aTSIter;
806 aTSIter = mTSMap.find(aComponent);
807 if (aTSIter == mTSMap.end())
809 mTSMap.insert(TSMappingTable::value_type(aComponent,aTimeStamp));
811 else
813 aTSIter->second = aTimeStamp;
816 typedef ListenerList::iterator LLIter;
817 typedef std::pair<LLIter, LLIter> BFRange;
818 BFRange aRange = mListenerList.equal_range(aComponent);
819 while (aRange.first != aRange.second)
821 LLIter cur = aRange.first++;
822 backend::ComponentChangeEvent aEvent;
823 aEvent.Component = aComponent;
824 aEvent.Source = *this;
825 cur->second->componentDataChanged(aEvent);
832 //------------------------------------------------------------------------------
833 void SAL_CALL GconfBackend::addChangesListener(
834 const uno::Reference<backend::XBackendChangesListener>& xListener,
835 const rtl::OUString& aComponent)
836 throw (::com::sun::star::uno::RuntimeException)
839 osl::MutexGuard aGuard(mMutex);
841 GConfClient* aClient = getGconfClient();
843 ListenerList::iterator aIter;
844 aIter = mListenerList.find(aComponent);
845 if (aIter == mListenerList.end())
847 typedef KeyMappingTable::iterator KMTIter;
848 typedef std::pair<KMTIter, KMTIter> BFRange;
850 BFRange aRange = mKeyMap.equal_range(aComponent);
852 while (aRange.first != aRange.second)
854 KMTIter cur = aRange.first++;
856 sal_Int32 nIndex = cur->second.mGconfName.lastIndexOf('/');
857 rtl::OUString aDirectory = cur->second.mGconfName.copy(0, nIndex);
858 rtl::OString aDirectoryStr= rtl::OUStringToOString(aDirectory, RTL_TEXTENCODING_ASCII_US);
859 GError* aError = NULL;
860 gconf_client_add_dir(aClient,
861 aDirectoryStr.getStr(),
862 GCONF_CLIENT_PRELOAD_NONE,
863 &aError);
865 if(aError != NULL)
867 OSL_TRACE("GconfBackend:: Cannot register listener for Component %s",
868 rtl::OUStringToOString(aComponent, RTL_TEXTENCODING_ASCII_US).getStr() );
871 rtl::OString aKey = rtl::OUStringToOString(cur->second.mGconfName,
872 RTL_TEXTENCODING_ASCII_US);
874 GConfClientNotifyFunc aNotifyFunc = &keyChangedCallback;
875 sal_uInt32 aID = gconf_client_notify_add(
876 aClient,
877 aKey.getStr(),
878 aNotifyFunc,
879 this,
880 NULL,
881 &aError);
882 if(aError != NULL)
884 OSL_TRACE("GconfBackend:: Cannot register listener for Component %s",
885 rtl::OUStringToOString(aComponent, RTL_TEXTENCODING_ASCII_US).getStr() );
896 if (mNotificationThread == NULL)
899 mNotificationThread = new ONotificationThread();
901 if ( mNotificationThread == NULL)
903 OSL_ENSURE(false,"Could not start Notification Thread ");
905 else
907 mNotificationThread->create();
911 //Store listener in list
912 mListenerList.insert(ListenerList::value_type(aComponent, xListener));
916 //------------------------------------------------------------------------------
917 void SAL_CALL GconfBackend::removeChangesListener(
918 const uno::Reference<backend::XBackendChangesListener>& /*xListener*/,
919 const rtl::OUString& /*aComponent*/)
920 throw (::com::sun::star::uno::RuntimeException)
923 osl::MutexGuard aGuard(mMutex);
924 GConfClient* aClient = GconfBackend::getGconfClient();
925 ListenerList::iterator aIter;
926 aIter = mListenerList.find(aComponent);
927 if (aIter == mListenerList.end())
930 OSL_TRACE("GconfBackend:: Cannot deregister listener for Component %s - Listner not registered",
931 rtl::OUStringToOString(aComponent, RTL_TEXTENCODING_ASCII_US).getStr() );
933 typedef KeyMappingTable::iterator KMTIter;
934 typedef std::pair<KMTIter, KMTIter> BFRange;
936 BFRange aRange = mKeyMap.equal_range(aComponent);
938 while (aRange.first != aRange.second)
940 KMTIter cur = aRange.first++;
942 sal_Int32 nIndex = cur->second.mGconfName.lastIndexOf('/');
943 rtl::OUString aDirectory = cur->second.mGconfName.copy(0, nIndex);
944 rtl::OString aDirectoryStr= rtl::OUStringToOString(aDirectory, RTL_TEXTENCODING_ASCII_US);
945 GError* aError = NULL;
946 gconf_client_remove_dir(aClient,
947 aDirectoryStr.getStr(),
948 &aError);
950 if(aError != NULL)
952 OSL_TRACE("GconfBackend:: Cannot deRegister listener for Component %s",
953 rtl::OUStringToOString(aComponent, RTL_TEXTENCODING_ASCII_US).getStr() );
960 //------------------------------------------------------------------------------
962 rtl::OUString SAL_CALL GconfBackend::getBackendName(void) {
963 return rtl::OUString(
964 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.configuration.backend.GconfBackend") );
967 //------------------------------------------------------------------------------
969 rtl::OUString SAL_CALL GconfBackend::getImplementationName(void)
970 throw (uno::RuntimeException)
972 return getBackendName() ;
975 //------------------------------------------------------------------------------
977 uno::Sequence<rtl::OUString> SAL_CALL GconfBackend::getBackendServiceNames(void)
979 uno::Sequence<rtl::OUString> aServices(1) ;
980 aServices[0] = rtl::OUString(
981 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.backend.GconfBackend")) ;
983 return aServices ;
986 //------------------------------------------------------------------------------
988 sal_Bool SAL_CALL GconfBackend::supportsService(const rtl::OUString& aServiceName)
989 throw (uno::RuntimeException)
991 uno::Sequence< rtl::OUString > const svc = getBackendServiceNames();
993 for(sal_Int32 i = 0; i < svc.getLength(); ++i )
994 if(svc[i] == aServiceName)
995 return true;
997 return false;
1000 //------------------------------------------------------------------------------
1002 uno::Sequence<rtl::OUString>
1003 SAL_CALL GconfBackend::getSupportedServiceNames(void)
1004 throw (uno::RuntimeException)
1006 return getBackendServiceNames() ;
1009 // ---------------------------------------------------------------------------------------