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