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/optionsdlg.hxx> 57 #include <unotools/saveopt.hxx> 58 #include <unotools/searchopt.hxx> 59 #include <unotools/securityoptions.hxx> 60 #include <unotools/sourceviewconfig.hxx> 61 #include <unotools/startoptions.hxx> 62 #include <unotools/viewoptions.hxx> 63 #include <unotools/workingsetoptions.hxx> 64 #include <unotools/xmlaccelcfg.hxx> 65 #include <unotools/options.hxx> 66 #include <unotools/syslocaleoptions.hxx> 67 68 //----------------------------------------------- 69 // namespaces 70 71 namespace css = ::com::sun::star; 72 73 //----------------------------------------------- 74 // declarations 75 76 //----------------------------------------------- 77 ItemHolder1::ItemHolder1() 78 : ItemHolderMutexBase() 79 { 80 try 81 { 82 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 83 css::uno::Reference< css::lang::XComponent > xCfg( 84 xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")), 85 css::uno::UNO_QUERY); 86 if (xCfg.is()) 87 xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this)); 88 } 89 // #i37892 got errorhandling from ConfigManager::GetConfigurationProvider() 90 #ifdef DBG_UTIL 91 catch(css::uno::Exception& rEx) 92 { 93 static sal_Bool bMessage = sal_True; 94 if(bMessage) 95 { 96 bMessage = sal_False; 97 ::rtl::OString sMsg("CreateInstance with arguments exception: "); 98 sMsg += ::rtl::OString(rEx.Message.getStr(), 99 rEx.Message.getLength(), 100 RTL_TEXTENCODING_ASCII_US); 101 OSL_ENSURE(sal_False, sMsg.getStr()); 102 } 103 } 104 #else 105 catch(css::uno::Exception&){} 106 #endif 107 } 108 109 //----------------------------------------------- 110 ItemHolder1::~ItemHolder1() 111 { 112 impl_releaseAllItems(); 113 } 114 115 //----------------------------------------------- 116 void ItemHolder1::holdConfigItem(EItem eItem) 117 { 118 static ItemHolder1* pHolder = new ItemHolder1(); 119 pHolder->impl_addItem(eItem); 120 } 121 122 //----------------------------------------------- 123 void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&) 124 throw(css::uno::RuntimeException) 125 { 126 css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY); 127 impl_releaseAllItems(); 128 } 129 130 //----------------------------------------------- 131 void ItemHolder1::impl_addItem(EItem eItem) 132 { 133 ::osl::ResettableMutexGuard aLock(m_aLock); 134 135 TItems::const_iterator pIt; 136 for ( pIt = m_lItems.begin(); 137 pIt != m_lItems.end() ; 138 ++pIt ) 139 { 140 const TItemInfo& rInfo = *pIt; 141 if (rInfo.eItem == eItem) 142 return; 143 } 144 145 TItemInfo aNewItem; 146 aNewItem.eItem = eItem; 147 impl_newItem(aNewItem); 148 if (aNewItem.pItem) 149 m_lItems.push_back(aNewItem); 150 } 151 152 //----------------------------------------------- 153 void ItemHolder1::impl_releaseAllItems() 154 { 155 ::osl::ResettableMutexGuard aLock(m_aLock); 156 157 TItems::iterator pIt; 158 for ( pIt = m_lItems.begin(); 159 pIt != m_lItems.end() ; 160 ++pIt ) 161 { 162 TItemInfo& rInfo = *pIt; 163 impl_deleteItem(rInfo); 164 } 165 m_lItems.clear(); 166 } 167 168 //----------------------------------------------- 169 void ItemHolder1::impl_newItem(TItemInfo& rItem) 170 { 171 switch(rItem.eItem) 172 { 173 case E_ACCELCFG : 174 rItem.pItem = new SvtAcceleratorConfiguration(); 175 break; 176 177 case E_CMDOPTIONS : 178 rItem.pItem = new SvtCommandOptions(); 179 break; 180 181 case E_COMPATIBILITY : 182 rItem.pItem = new SvtCompatibilityOptions(); 183 break; 184 185 case E_DEFAULTOPTIONS : 186 rItem.pItem = new SvtDefaultOptions(); 187 break; 188 189 case E_DYNAMICMENUOPTIONS : 190 rItem.pItem = new SvtDynamicMenuOptions(); 191 break; 192 193 case E_EVENTCFG : 194 //rItem.pItem = new GlobalEventConfig(); 195 break; 196 197 case E_EXTENDEDSECURITYOPTIONS : 198 rItem.pItem = new SvtExtendedSecurityOptions(); 199 break; 200 201 case E_FLTRCFG : 202 // no ref count rItem.pItem = new SvtFilterOptions(); 203 break; 204 205 case E_FONTOPTIONS : 206 rItem.pItem = new SvtFontOptions(); 207 break; 208 209 case E_HISTORYOPTIONS : 210 rItem.pItem = new SvtHistoryOptions(); 211 break; 212 213 case E_INETOPTIONS : 214 rItem.pItem = new SvtInetOptions(); 215 break; 216 217 case E_INTERNALOPTIONS : 218 rItem.pItem = new SvtInternalOptions(); 219 break; 220 221 case E_JAVAOPTIONS : 222 // no ref count rItem.pItem = new SvtJavaOptions(); 223 break; 224 225 case E_LINGUCFG : 226 rItem.pItem = new SvtLinguConfig(); 227 break; 228 229 case E_LOCALISATIONOPTIONS : 230 rItem.pItem = new SvtLocalisationOptions(); 231 break; 232 233 case E_MODULEOPTIONS : 234 rItem.pItem = new SvtModuleOptions(); 235 break; 236 237 case E_OPTIONSDLGOPTIONS : 238 rItem.pItem = new SvtOptionsDialogOptions(); 239 break; 240 241 case E_PATHOPTIONS : 242 rItem.pItem = new SvtPathOptions(); 243 break; 244 245 case E_PRINTWARNINGOPTIONS : 246 rItem.pItem = new SvtPrintWarningOptions(); 247 break; 248 249 case E_MISCCFG : 250 rItem.pItem = new ::utl::MiscCfg(); 251 break; 252 253 case E_SAVEOPTIONS : 254 rItem.pItem = new SvtSaveOptions(); 255 break; 256 257 case E_SEARCHOPT : 258 // no ref count rItem.pItem = new SvtSearchOptions(); 259 break; 260 261 case E_SECURITYOPTIONS : 262 rItem.pItem = new SvtSecurityOptions(); 263 break; 264 265 case E_SOURCEVIEWCONFIG : 266 rItem.pItem = new ::utl::SourceViewConfig(); 267 break; 268 269 case E_STARTOPTIONS : 270 rItem.pItem = new SvtStartOptions(); 271 break; 272 273 case E_VIEWOPTIONS_DIALOG : 274 rItem.pItem = new SvtViewOptions(E_DIALOG, ::rtl::OUString()); 275 break; 276 277 case E_VIEWOPTIONS_TABDIALOG : 278 rItem.pItem = new SvtViewOptions(E_TABDIALOG, ::rtl::OUString()); 279 break; 280 281 case E_VIEWOPTIONS_TABPAGE : 282 rItem.pItem = new SvtViewOptions(E_TABPAGE, ::rtl::OUString()); 283 break; 284 285 case E_VIEWOPTIONS_WINDOW : 286 rItem.pItem = new SvtViewOptions(E_WINDOW, ::rtl::OUString()); 287 break; 288 289 case E_WORKINGSETOPTIONS : 290 rItem.pItem = new SvtWorkingSetOptions(); 291 break; 292 293 case E_XMLACCELCFG : 294 // ??? TODO 295 break; 296 297 case E_UNDOOPTIONS : 298 rItem.pItem = new SvtUndoOptions(); 299 break; 300 301 case E_USEROPTIONS : 302 rItem.pItem = new SvtUserOptions(); 303 break; 304 305 case E_SYSLOCALEOPTIONS : 306 rItem.pItem = new SvtSysLocaleOptions(); 307 break; 308 309 default: 310 OSL_ASSERT( "unknown item type" ); 311 break; 312 } 313 } 314 315 //----------------------------------------------- 316 void ItemHolder1::impl_deleteItem(TItemInfo& rItem) 317 { 318 if (rItem.pItem) 319 { 320 delete rItem.pItem; 321 rItem.pItem = 0; 322 } 323 } 324 325