1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_unotools.hxx" 30 31 #include "itemholder1.hxx" 32 33 //----------------------------------------------- 34 // includes 35 #include <comphelper/processfactory.hxx> 36 #include <com/sun/star/lang/XComponent.hpp> 37 38 #include <unotools/misccfg.hxx> 39 #include <unotools/undoopt.hxx> 40 #include <unotools/useroptions.hxx> 41 #include <unotools/accelcfg.hxx> 42 #include <unotools/cacheoptions.hxx> 43 #include <unotools/cmdoptions.hxx> 44 #include <unotools/compatibility.hxx> 45 #include <unotools/defaultoptions.hxx> 46 #include <unotools/dynamicmenuoptions.hxx> 47 #include <unotools/eventcfg.hxx> 48 #include <unotools/extendedsecurityoptions.hxx> 49 #include <unotools/fltrcfg.hxx> 50 #include <unotools/fontoptions.hxx> 51 #include <unotools/historyoptions.hxx> 52 #include <unotools/inetoptions.hxx> 53 #include <unotools/internaloptions.hxx> 54 #include <unotools/javaoptions.hxx> 55 #include <unotools/lingucfg.hxx> 56 #include <unotools/localisationoptions.hxx> 57 #include <unotools/moduleoptions.hxx> 58 #include <unotools/pathoptions.hxx> 59 #include <unotools/printwarningoptions.hxx> 60 #include <unotools/regoptions.hxx> 61 #include <unotools/optionsdlg.hxx> 62 #include <unotools/saveopt.hxx> 63 #include <unotools/searchopt.hxx> 64 #include <unotools/securityoptions.hxx> 65 #include <unotools/sourceviewconfig.hxx> 66 #include <unotools/startoptions.hxx> 67 #include <unotools/viewoptions.hxx> 68 #include <unotools/workingsetoptions.hxx> 69 #include <unotools/xmlaccelcfg.hxx> 70 #include <unotools/options.hxx> 71 #include <unotools/syslocaleoptions.hxx> 72 73 //----------------------------------------------- 74 // namespaces 75 76 namespace css = ::com::sun::star; 77 78 //----------------------------------------------- 79 // declarations 80 81 //----------------------------------------------- 82 ItemHolder1::ItemHolder1() 83 : ItemHolderMutexBase() 84 { 85 try 86 { 87 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 88 css::uno::Reference< css::lang::XComponent > xCfg( 89 xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")), 90 css::uno::UNO_QUERY); 91 if (xCfg.is()) 92 xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this)); 93 } 94 // #i37892 got errorhandling from ConfigManager::GetConfigurationProvider() 95 #ifdef DBG_UTIL 96 catch(css::uno::Exception& rEx) 97 { 98 static sal_Bool bMessage = sal_True; 99 if(bMessage) 100 { 101 bMessage = sal_False; 102 ::rtl::OString sMsg("CreateInstance with arguments exception: "); 103 sMsg += ::rtl::OString(rEx.Message.getStr(), 104 rEx.Message.getLength(), 105 RTL_TEXTENCODING_ASCII_US); 106 OSL_ENSURE(sal_False, sMsg.getStr()); 107 } 108 } 109 #else 110 catch(css::uno::Exception&){} 111 #endif 112 } 113 114 //----------------------------------------------- 115 ItemHolder1::~ItemHolder1() 116 { 117 impl_releaseAllItems(); 118 } 119 120 //----------------------------------------------- 121 void ItemHolder1::holdConfigItem(EItem eItem) 122 { 123 static ItemHolder1* pHolder = new ItemHolder1(); 124 pHolder->impl_addItem(eItem); 125 } 126 127 //----------------------------------------------- 128 void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&) 129 throw(css::uno::RuntimeException) 130 { 131 css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY); 132 impl_releaseAllItems(); 133 } 134 135 //----------------------------------------------- 136 void ItemHolder1::impl_addItem(EItem eItem) 137 { 138 ::osl::ResettableMutexGuard aLock(m_aLock); 139 140 TItems::const_iterator pIt; 141 for ( pIt = m_lItems.begin(); 142 pIt != m_lItems.end() ; 143 ++pIt ) 144 { 145 const TItemInfo& rInfo = *pIt; 146 if (rInfo.eItem == eItem) 147 return; 148 } 149 150 TItemInfo aNewItem; 151 aNewItem.eItem = eItem; 152 impl_newItem(aNewItem); 153 if (aNewItem.pItem) 154 m_lItems.push_back(aNewItem); 155 } 156 157 //----------------------------------------------- 158 void ItemHolder1::impl_releaseAllItems() 159 { 160 ::osl::ResettableMutexGuard aLock(m_aLock); 161 162 TItems::iterator pIt; 163 for ( pIt = m_lItems.begin(); 164 pIt != m_lItems.end() ; 165 ++pIt ) 166 { 167 TItemInfo& rInfo = *pIt; 168 impl_deleteItem(rInfo); 169 } 170 m_lItems.clear(); 171 } 172 173 //----------------------------------------------- 174 void ItemHolder1::impl_newItem(TItemInfo& rItem) 175 { 176 switch(rItem.eItem) 177 { 178 case E_ACCELCFG : 179 rItem.pItem = new SvtAcceleratorConfiguration(); 180 break; 181 182 case E_CMDOPTIONS : 183 rItem.pItem = new SvtCommandOptions(); 184 break; 185 186 case E_COMPATIBILITY : 187 rItem.pItem = new SvtCompatibilityOptions(); 188 break; 189 190 case E_DEFAULTOPTIONS : 191 rItem.pItem = new SvtDefaultOptions(); 192 break; 193 194 case E_DYNAMICMENUOPTIONS : 195 rItem.pItem = new SvtDynamicMenuOptions(); 196 break; 197 198 case E_EVENTCFG : 199 //rItem.pItem = new GlobalEventConfig(); 200 break; 201 202 case E_EXTENDEDSECURITYOPTIONS : 203 rItem.pItem = new SvtExtendedSecurityOptions(); 204 break; 205 206 case E_FLTRCFG : 207 // no ref count rItem.pItem = new SvtFilterOptions(); 208 break; 209 210 case E_FONTOPTIONS : 211 rItem.pItem = new SvtFontOptions(); 212 break; 213 214 case E_HISTORYOPTIONS : 215 rItem.pItem = new SvtHistoryOptions(); 216 break; 217 218 case E_INETOPTIONS : 219 rItem.pItem = new SvtInetOptions(); 220 break; 221 222 case E_INTERNALOPTIONS : 223 rItem.pItem = new SvtInternalOptions(); 224 break; 225 226 case E_JAVAOPTIONS : 227 // no ref count rItem.pItem = new SvtJavaOptions(); 228 break; 229 230 case E_LINGUCFG : 231 rItem.pItem = new SvtLinguConfig(); 232 break; 233 234 case E_LOCALISATIONOPTIONS : 235 rItem.pItem = new SvtLocalisationOptions(); 236 break; 237 238 case E_MODULEOPTIONS : 239 rItem.pItem = new SvtModuleOptions(); 240 break; 241 242 case E_OPTIONSDLGOPTIONS : 243 rItem.pItem = new SvtOptionsDialogOptions(); 244 break; 245 246 case E_PATHOPTIONS : 247 rItem.pItem = new SvtPathOptions(); 248 break; 249 250 case E_PRINTWARNINGOPTIONS : 251 rItem.pItem = new SvtPrintWarningOptions(); 252 break; 253 254 case E_MISCCFG : 255 rItem.pItem = new ::utl::MiscCfg(); 256 break; 257 258 case E_SAVEOPTIONS : 259 rItem.pItem = new SvtSaveOptions(); 260 break; 261 262 case E_SEARCHOPT : 263 // no ref count rItem.pItem = new SvtSearchOptions(); 264 break; 265 266 case E_SECURITYOPTIONS : 267 rItem.pItem = new SvtSecurityOptions(); 268 break; 269 270 case E_SOURCEVIEWCONFIG : 271 rItem.pItem = new ::utl::SourceViewConfig(); 272 break; 273 274 case E_STARTOPTIONS : 275 rItem.pItem = new SvtStartOptions(); 276 break; 277 278 case E_VIEWOPTIONS_DIALOG : 279 rItem.pItem = new SvtViewOptions(E_DIALOG, ::rtl::OUString()); 280 break; 281 282 case E_VIEWOPTIONS_TABDIALOG : 283 rItem.pItem = new SvtViewOptions(E_TABDIALOG, ::rtl::OUString()); 284 break; 285 286 case E_VIEWOPTIONS_TABPAGE : 287 rItem.pItem = new SvtViewOptions(E_TABPAGE, ::rtl::OUString()); 288 break; 289 290 case E_VIEWOPTIONS_WINDOW : 291 rItem.pItem = new SvtViewOptions(E_WINDOW, ::rtl::OUString()); 292 break; 293 294 case E_WORKINGSETOPTIONS : 295 rItem.pItem = new SvtWorkingSetOptions(); 296 break; 297 298 case E_XMLACCELCFG : 299 // ??? TODO 300 break; 301 302 case E_UNDOOPTIONS : 303 rItem.pItem = new SvtUndoOptions(); 304 break; 305 306 case E_USEROPTIONS : 307 rItem.pItem = new SvtUserOptions(); 308 break; 309 310 case E_SYSLOCALEOPTIONS : 311 rItem.pItem = new SvtSysLocaleOptions(); 312 break; 313 314 default: 315 OSL_ASSERT( "unknown item type" ); 316 break; 317 } 318 } 319 320 //----------------------------------------------- 321 void ItemHolder1::impl_deleteItem(TItemInfo& rItem) 322 { 323 if (rItem.pItem) 324 { 325 delete rItem.pItem; 326 rItem.pItem = 0; 327 } 328 } 329 330