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 <unotools/useroptions.hxx> 28 #include <unotools/useroptions_const.hxx> 29 30 #include <unotools/configmgr.hxx> 31 #include <tools/debug.hxx> 32 #include <com/sun/star/uno/Any.hxx> 33 #include <com/sun/star/uno/Sequence.hxx> 34 #include <vos/mutex.hxx> 35 #include <rtl/instance.hxx> 36 #include <rtl/logfile.hxx> 37 #include "itemholder1.hxx" 38 39 #include <com/sun/star/beans/Property.hpp> 40 #include <com/sun/star/beans/XPropertySet.hpp> 41 #include <com/sun/star/beans/PropertyAttribute.hpp> 42 #include <com/sun/star/container/XNameAccess.hpp> 43 #include <com/sun/star/container/XNameContainer.hpp> 44 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 45 #include <com/sun/star/util/XChangesListener.hpp> 46 #include <com/sun/star/util/XChangesNotifier.hpp> 47 #include <com/sun/star/util/ChangesEvent.hpp> 48 #include <comphelper/configurationhelper.hxx> 49 #include <unotools/processfactory.hxx> 50 #include <unotools/loghelper.hxx> 51 52 using namespace utl; 53 using namespace rtl; 54 using namespace com::sun::star; 55 using namespace com::sun::star::uno; 56 57 namespace css = ::com::sun::star; 58 59 // class SvtUserOptions_Impl --------------------------------------------- 60 class SvtUserOptions_Impl; 61 class SvtUserConfigChangeListener_Impl : public cppu::WeakImplHelper1 62 < 63 com::sun::star::util::XChangesListener 64 > 65 { 66 SvtUserOptions_Impl& m_rParent; 67 public: 68 SvtUserConfigChangeListener_Impl(SvtUserOptions_Impl& rParent); 69 ~SvtUserConfigChangeListener_Impl(); 70 71 //XChangesListener 72 virtual void SAL_CALL changesOccurred( const util::ChangesEvent& Event ) throw(RuntimeException); 73 //XEventListener 74 virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw(RuntimeException); 75 }; 76 77 class SvtUserOptions_Impl : public utl::ConfigurationBroadcaster 78 { 79 public: 80 SvtUserOptions_Impl(); 81 ~SvtUserOptions_Impl(); 82 83 // get the user token 84 ::rtl::OUString GetCompany() const; 85 ::rtl::OUString GetFirstName() const; 86 ::rtl::OUString GetLastName() const; 87 ::rtl::OUString GetID() const; 88 ::rtl::OUString GetStreet() const; 89 ::rtl::OUString GetCity() const; 90 ::rtl::OUString GetState() const; 91 ::rtl::OUString GetZip() const; 92 ::rtl::OUString GetCountry() const; 93 ::rtl::OUString GetPosition() const; 94 ::rtl::OUString GetTitle() const; 95 ::rtl::OUString GetTelephoneHome() const; 96 ::rtl::OUString GetTelephoneWork() const; 97 ::rtl::OUString GetFax() const; 98 ::rtl::OUString GetEmail() const; 99 ::rtl::OUString GetCustomerNumber() const; 100 ::rtl::OUString GetFathersName() const; 101 ::rtl::OUString GetApartment() const; 102 103 ::rtl::OUString GetFullName() const; 104 ::rtl::OUString GetLocale() const { return m_aLocale; } 105 106 // set the address token 107 void SetCompany( const ::rtl::OUString& rNewToken ); 108 void SetFirstName( const ::rtl::OUString& rNewToken ); 109 void SetLastName( const ::rtl::OUString& rNewToken ); 110 void SetID( const ::rtl::OUString& rNewToken ); 111 void SetStreet( const ::rtl::OUString& rNewToken ); 112 void SetCity( const ::rtl::OUString& rNewToken ); 113 void SetState( const ::rtl::OUString& rNewToken ); 114 void SetZip( const ::rtl::OUString& rNewToken ); 115 void SetCountry( const ::rtl::OUString& rNewToken ); 116 void SetPosition( const ::rtl::OUString& rNewToken ); 117 void SetTitle( const ::rtl::OUString& rNewToken ); 118 void SetTelephoneHome( const ::rtl::OUString& rNewToken ); 119 void SetTelephoneWork( const ::rtl::OUString& rNewToken ); 120 void SetFax( const ::rtl::OUString& rNewToken ); 121 void SetEmail( const ::rtl::OUString& rNewToken ); 122 void SetCustomerNumber( const ::rtl::OUString& rNewToken ); 123 void SetFathersName( const ::rtl::OUString& rNewToken ); 124 void SetApartment( const ::rtl::OUString& rNewToken ); 125 126 sal_Bool IsTokenReadonly( sal_uInt16 nToken ) const; 127 ::rtl::OUString GetToken(sal_uInt16 nToken) const; 128 void Notify(); 129 130 private: 131 uno::Reference< util::XChangesListener > m_xChangeListener; 132 css::uno::Reference< css::container::XNameAccess > m_xCfg; 133 css::uno::Reference< css::beans::XPropertySet > m_xData; 134 ::rtl::OUString m_aLocale; 135 }; 136 137 // global ---------------------------------------------------------------- 138 139 static SvtUserOptions_Impl* pOptions = NULL; 140 static sal_Int32 nRefCount = 0; 141 142 #define READONLY_DEFAULT sal_False 143 144 /*-- 16.06.2009 14:22:56--------------------------------------------------- 145 146 -----------------------------------------------------------------------*/ 147 SvtUserConfigChangeListener_Impl::SvtUserConfigChangeListener_Impl(SvtUserOptions_Impl& rParent) : 148 m_rParent( rParent ) 149 { 150 } 151 /*-- 16.06.2009 14:22:56--------------------------------------------------- 152 153 -----------------------------------------------------------------------*/ 154 SvtUserConfigChangeListener_Impl::~SvtUserConfigChangeListener_Impl() 155 { 156 } 157 /*-- 16.06.2009 14:22:56--------------------------------------------------- 158 159 -----------------------------------------------------------------------*/ 160 void SvtUserConfigChangeListener_Impl::changesOccurred( const util::ChangesEvent& rEvent ) throw(RuntimeException) 161 { 162 if(rEvent.Changes.getLength()) 163 m_rParent.Notify(); 164 } 165 /*-- 16.06.2009 14:22:56--------------------------------------------------- 166 167 -----------------------------------------------------------------------*/ 168 void SvtUserConfigChangeListener_Impl::disposing( const lang::EventObject& rSource ) throw(RuntimeException) 169 { 170 try 171 { 172 uno::Reference< util::XChangesNotifier > xChgNot( rSource.Source, UNO_QUERY_THROW); 173 xChgNot->removeChangesListener(this); 174 } 175 catch(Exception& ) 176 { 177 } 178 } 179 180 // class SvtUserOptions_Impl --------------------------------------------- 181 182 // ----------------------------------------------------------------------- 183 SvtUserOptions_Impl::SvtUserOptions_Impl() : 184 m_xChangeListener( new SvtUserConfigChangeListener_Impl(*this) ) 185 { 186 try 187 { 188 m_xCfg = Reference< css::container::XNameAccess > ( 189 ::comphelper::ConfigurationHelper::openConfig( 190 utl::getProcessServiceFactory(), 191 s_sData, 192 ::comphelper::ConfigurationHelper::E_STANDARD), 193 css::uno::UNO_QUERY ); 194 195 m_xData = css::uno::Reference< css::beans::XPropertySet >(m_xCfg, css::uno::UNO_QUERY); 196 uno::Reference< util::XChangesNotifier > xChgNot( m_xCfg, UNO_QUERY); 197 try 198 { 199 xChgNot->addChangesListener( m_xChangeListener ); 200 } 201 catch(RuntimeException& ) 202 { 203 } 204 } 205 catch(const css::uno::Exception& ex) 206 { 207 m_xCfg.clear(); 208 LogHelper::logIt(ex); 209 } 210 211 Any aAny = ConfigManager::GetConfigManager()->GetDirectConfigProperty( ConfigManager::LOCALE ); 212 ::rtl::OUString aLocale; 213 if ( aAny >>= aLocale ) 214 m_aLocale = aLocale; 215 else 216 { 217 DBG_ERRORFILE( "SvtUserOptions_Impl::SvtUserOptions_Impl(): no locale found" ); 218 } 219 } 220 221 // ----------------------------------------------------------------------- 222 223 SvtUserOptions_Impl::~SvtUserOptions_Impl() 224 { 225 } 226 227 ::rtl::OUString SvtUserOptions_Impl::GetCompany() const 228 { 229 ::rtl::OUString sCompany; 230 231 try 232 { 233 m_xData->getPropertyValue(s_so) >>= sCompany; 234 } 235 catch ( const css::uno::Exception& ex ) 236 { 237 LogHelper::logIt(ex); 238 } 239 240 return sCompany; 241 } 242 243 ::rtl::OUString SvtUserOptions_Impl::GetFirstName() const 244 { 245 ::rtl::OUString sFirstName; 246 247 try 248 { 249 m_xData->getPropertyValue(s_sgivenname) >>= sFirstName; 250 } 251 catch ( const css::uno::Exception& ex ) 252 { 253 LogHelper::logIt(ex); 254 } 255 256 return sFirstName; 257 } 258 259 ::rtl::OUString SvtUserOptions_Impl::GetLastName() const 260 { 261 ::rtl::OUString sLastName; 262 263 try 264 { 265 m_xData->getPropertyValue(s_ssn) >>= sLastName; 266 } 267 catch ( const css::uno::Exception& ex ) 268 { 269 LogHelper::logIt(ex); 270 } 271 272 return sLastName; 273 } 274 275 ::rtl::OUString SvtUserOptions_Impl::GetID() const 276 { 277 ::rtl::OUString sID; 278 279 try 280 { 281 m_xData->getPropertyValue(s_sinitials) >>= sID; 282 } 283 catch ( const css::uno::Exception& ex ) 284 { 285 LogHelper::logIt(ex); 286 } 287 288 return sID; 289 } 290 291 ::rtl::OUString SvtUserOptions_Impl::GetStreet() const 292 { 293 ::rtl::OUString sStreet; 294 295 try 296 { 297 m_xData->getPropertyValue(s_sstreet) >>= sStreet; 298 } 299 catch ( const css::uno::Exception& ex ) 300 { 301 LogHelper::logIt(ex); 302 } 303 304 return sStreet; 305 } 306 307 ::rtl::OUString SvtUserOptions_Impl::GetCity() const 308 { 309 ::rtl::OUString sCity; 310 311 try 312 { 313 m_xData->getPropertyValue(s_sl) >>= sCity; 314 } 315 catch ( const css::uno::Exception& ex ) 316 { 317 LogHelper::logIt(ex); 318 } 319 320 return sCity; 321 } 322 323 ::rtl::OUString SvtUserOptions_Impl::GetState() const 324 { 325 ::rtl::OUString sState; 326 327 try 328 { 329 m_xData->getPropertyValue(s_sst) >>= sState; 330 } 331 catch ( const css::uno::Exception& ex ) 332 { 333 LogHelper::logIt(ex); 334 } 335 336 return sState; 337 } 338 339 ::rtl::OUString SvtUserOptions_Impl::GetZip() const 340 { 341 ::rtl::OUString sZip; 342 343 try 344 { 345 m_xData->getPropertyValue(s_spostalcode) >>= sZip; 346 } 347 catch ( const css::uno::Exception& ex ) 348 { 349 LogHelper::logIt(ex); 350 } 351 352 return sZip; 353 } 354 355 ::rtl::OUString SvtUserOptions_Impl::GetCountry() const 356 { 357 ::rtl::OUString sCountry; 358 359 try 360 { 361 m_xData->getPropertyValue(s_sc) >>= sCountry; 362 } 363 catch ( const css::uno::Exception& ex ) 364 { 365 LogHelper::logIt(ex); 366 } 367 368 return sCountry; 369 } 370 371 ::rtl::OUString SvtUserOptions_Impl::GetPosition() const 372 { 373 ::rtl::OUString sPosition; 374 375 try 376 { 377 m_xData->getPropertyValue(s_sposition) >>= sPosition; 378 } 379 catch ( const css::uno::Exception& ex ) 380 { 381 LogHelper::logIt(ex); 382 } 383 384 return sPosition; 385 } 386 387 ::rtl::OUString SvtUserOptions_Impl::GetTitle() const 388 { 389 ::rtl::OUString sTitle; 390 391 try 392 { 393 m_xData->getPropertyValue(s_stitle) >>= sTitle; 394 } 395 catch ( const css::uno::Exception& ex ) 396 { 397 LogHelper::logIt(ex); 398 } 399 400 return sTitle; 401 } 402 403 ::rtl::OUString SvtUserOptions_Impl::GetTelephoneHome() const 404 { 405 ::rtl::OUString sTelephoneHome; 406 407 try 408 { 409 m_xData->getPropertyValue(s_shomephone) >>= sTelephoneHome; 410 } 411 catch ( const css::uno::Exception& ex ) 412 { 413 LogHelper::logIt(ex); 414 } 415 416 return sTelephoneHome; 417 } 418 419 ::rtl::OUString SvtUserOptions_Impl::GetTelephoneWork() const 420 { 421 ::rtl::OUString sTelephoneWork; 422 423 try 424 { 425 m_xData->getPropertyValue(s_stelephonenumber) >>= sTelephoneWork; 426 } 427 catch ( const css::uno::Exception& ex ) 428 { 429 LogHelper::logIt(ex); 430 } 431 432 return sTelephoneWork; 433 } 434 435 ::rtl::OUString SvtUserOptions_Impl::GetFax() const 436 { 437 ::rtl::OUString sFax; 438 439 try 440 { 441 m_xData->getPropertyValue(s_sfacsimiletelephonenumber) >>= sFax; 442 } 443 catch ( const css::uno::Exception& ex ) 444 { 445 LogHelper::logIt(ex); 446 } 447 448 return sFax; 449 } 450 451 ::rtl::OUString SvtUserOptions_Impl::GetEmail() const 452 { 453 ::rtl::OUString sEmail; 454 455 try 456 { 457 m_xData->getPropertyValue(s_smail) >>= sEmail; 458 } 459 catch ( const css::uno::Exception& ex ) 460 { 461 LogHelper::logIt(ex); 462 } 463 464 return sEmail; 465 } 466 467 ::rtl::OUString SvtUserOptions_Impl::GetCustomerNumber() const 468 { 469 ::rtl::OUString sCustomerNumber; 470 471 try 472 { 473 m_xData->getPropertyValue(s_scustomernumber) >>= sCustomerNumber; 474 } 475 catch ( const css::uno::Exception& ex ) 476 { 477 LogHelper::logIt(ex); 478 } 479 480 return sCustomerNumber; 481 } 482 483 ::rtl::OUString SvtUserOptions_Impl::GetFathersName() const 484 { 485 ::rtl::OUString sFathersName; 486 487 try 488 { 489 m_xData->getPropertyValue(s_sfathersname) >>= sFathersName; 490 } 491 catch ( const css::uno::Exception& ex ) 492 { 493 LogHelper::logIt(ex); 494 } 495 496 return sFathersName; 497 } 498 499 ::rtl::OUString SvtUserOptions_Impl::GetApartment() const 500 { 501 ::rtl::OUString sApartment; 502 503 try 504 { 505 m_xData->getPropertyValue(s_sapartment) >>= sApartment; 506 } 507 catch ( const css::uno::Exception& ex ) 508 { 509 LogHelper::logIt(ex); 510 } 511 512 return sApartment; 513 } 514 515 void SvtUserOptions_Impl::SetCompany( const ::rtl::OUString& sCompany ) 516 { 517 try 518 { 519 m_xData->setPropertyValue(s_so, css::uno::makeAny(::rtl::OUString(sCompany))); 520 ::comphelper::ConfigurationHelper::flush(m_xCfg); 521 } 522 catch ( const css::uno::Exception& ex) 523 { 524 LogHelper::logIt(ex); 525 } 526 } 527 528 void SvtUserOptions_Impl::SetFirstName( const ::rtl::OUString& sFirstName ) 529 { 530 try 531 { 532 m_xData->setPropertyValue(s_sgivenname, css::uno::makeAny(::rtl::OUString(sFirstName))); 533 ::comphelper::ConfigurationHelper::flush(m_xCfg); 534 } 535 catch ( const css::uno::Exception& ex) 536 { 537 LogHelper::logIt(ex); 538 } 539 } 540 541 void SvtUserOptions_Impl::SetLastName( const ::rtl::OUString& sLastName ) 542 { 543 try 544 { 545 m_xData->setPropertyValue(s_ssn, css::uno::makeAny(::rtl::OUString(sLastName))); 546 ::comphelper::ConfigurationHelper::flush(m_xCfg); 547 } 548 catch ( const css::uno::Exception& ex) 549 { 550 LogHelper::logIt(ex); 551 } 552 } 553 void SvtUserOptions_Impl::SetID( const ::rtl::OUString& sID ) 554 { 555 try 556 { 557 m_xData->setPropertyValue(s_sinitials, css::uno::makeAny(::rtl::OUString(sID))); 558 ::comphelper::ConfigurationHelper::flush(m_xCfg); 559 } 560 catch ( const css::uno::Exception& ex) 561 { 562 LogHelper::logIt(ex); 563 } 564 } 565 566 void SvtUserOptions_Impl::SetStreet( const ::rtl::OUString& sStreet ) 567 { 568 try 569 { 570 m_xData->setPropertyValue(s_sstreet, css::uno::makeAny(::rtl::OUString(sStreet))); 571 ::comphelper::ConfigurationHelper::flush(m_xCfg); 572 } 573 catch ( const css::uno::Exception& ex) 574 { 575 LogHelper::logIt(ex); 576 } 577 } 578 579 void SvtUserOptions_Impl::SetCity( const ::rtl::OUString& sCity ) 580 { 581 try 582 { 583 m_xData->setPropertyValue(s_sl, css::uno::makeAny(::rtl::OUString(sCity))); 584 ::comphelper::ConfigurationHelper::flush(m_xCfg); 585 } 586 catch ( const css::uno::Exception& ex) 587 { 588 LogHelper::logIt(ex); 589 } 590 } 591 592 void SvtUserOptions_Impl::SetState( const ::rtl::OUString& sState ) 593 { 594 try 595 { 596 m_xData->setPropertyValue(s_sst, css::uno::makeAny(::rtl::OUString(sState))); 597 ::comphelper::ConfigurationHelper::flush(m_xCfg); 598 } 599 catch ( const css::uno::Exception& ex) 600 { 601 LogHelper::logIt(ex); 602 } 603 } 604 605 void SvtUserOptions_Impl::SetZip( const ::rtl::OUString& sZip ) 606 { 607 try 608 { 609 m_xData->setPropertyValue(s_spostalcode, css::uno::makeAny(::rtl::OUString(sZip))); 610 ::comphelper::ConfigurationHelper::flush(m_xCfg); 611 } 612 catch ( const css::uno::Exception& ex) 613 { 614 LogHelper::logIt(ex); 615 } 616 } 617 618 void SvtUserOptions_Impl::SetCountry( const ::rtl::OUString& sCountry ) 619 { 620 try 621 { 622 m_xData->setPropertyValue(s_sc, css::uno::makeAny(::rtl::OUString(sCountry))); 623 ::comphelper::ConfigurationHelper::flush(m_xCfg); 624 } 625 catch ( const css::uno::Exception& ex) 626 { 627 LogHelper::logIt(ex); 628 } 629 } 630 631 void SvtUserOptions_Impl::SetPosition( const ::rtl::OUString& sPosition ) 632 { 633 try 634 { 635 m_xData->setPropertyValue(s_sposition, css::uno::makeAny(::rtl::OUString(sPosition))); 636 ::comphelper::ConfigurationHelper::flush(m_xCfg); 637 } 638 catch ( const css::uno::Exception& ex) 639 { 640 LogHelper::logIt(ex); 641 } 642 } 643 644 void SvtUserOptions_Impl::SetTitle( const ::rtl::OUString& sTitle ) 645 { 646 try 647 { 648 m_xData->setPropertyValue(s_stitle, css::uno::makeAny(::rtl::OUString(sTitle))); 649 ::comphelper::ConfigurationHelper::flush(m_xCfg); 650 } 651 catch ( const css::uno::Exception& ex) 652 { 653 LogHelper::logIt(ex); 654 } 655 } 656 657 void SvtUserOptions_Impl::SetTelephoneHome( const ::rtl::OUString& sTelephoneHome ) 658 { 659 try 660 { 661 m_xData->setPropertyValue(s_shomephone, css::uno::makeAny(::rtl::OUString(sTelephoneHome))); 662 ::comphelper::ConfigurationHelper::flush(m_xCfg); 663 } 664 catch ( const css::uno::Exception& ex) 665 { 666 LogHelper::logIt(ex); 667 } 668 } 669 670 void SvtUserOptions_Impl::SetTelephoneWork( const ::rtl::OUString& sTelephoneWork ) 671 { 672 try 673 { 674 m_xData->setPropertyValue(s_stelephonenumber, css::uno::makeAny(::rtl::OUString(sTelephoneWork))); 675 ::comphelper::ConfigurationHelper::flush(m_xCfg); 676 } 677 catch ( const css::uno::Exception& ex) 678 { 679 LogHelper::logIt(ex); 680 } 681 } 682 683 void SvtUserOptions_Impl::SetFax( const ::rtl::OUString& sFax ) 684 { 685 try 686 { 687 m_xData->setPropertyValue(s_sfacsimiletelephonenumber, css::uno::makeAny(::rtl::OUString(sFax))); 688 ::comphelper::ConfigurationHelper::flush(m_xCfg); 689 } 690 catch ( const css::uno::Exception& ex) 691 { 692 LogHelper::logIt(ex); 693 } 694 } 695 696 void SvtUserOptions_Impl::SetEmail( const ::rtl::OUString& sEmail ) 697 { 698 try 699 { 700 m_xData->setPropertyValue(s_smail, css::uno::makeAny(::rtl::OUString(sEmail))); 701 ::comphelper::ConfigurationHelper::flush(m_xCfg); 702 } 703 catch ( const css::uno::Exception& ex) 704 { 705 LogHelper::logIt(ex); 706 } 707 } 708 709 void SvtUserOptions_Impl::SetCustomerNumber( const ::rtl::OUString& sCustomerNumber ) 710 { 711 try 712 { 713 m_xData->setPropertyValue(s_scustomernumber, css::uno::makeAny(::rtl::OUString(sCustomerNumber))); 714 ::comphelper::ConfigurationHelper::flush(m_xCfg); 715 } 716 catch ( const css::uno::Exception& ex) 717 { 718 LogHelper::logIt(ex); 719 } 720 } 721 722 void SvtUserOptions_Impl::SetFathersName( const ::rtl::OUString& sFathersName ) 723 { 724 try 725 { 726 m_xData->setPropertyValue(s_sfathersname, css::uno::makeAny(::rtl::OUString(sFathersName))); 727 ::comphelper::ConfigurationHelper::flush(m_xCfg); 728 } 729 catch ( const css::uno::Exception& ex) 730 { 731 LogHelper::logIt(ex); 732 } 733 } 734 735 void SvtUserOptions_Impl::SetApartment( const ::rtl::OUString& sApartment ) 736 { 737 try 738 { 739 m_xData->setPropertyValue(s_sapartment, css::uno::makeAny(::rtl::OUString(sApartment))); 740 ::comphelper::ConfigurationHelper::flush(m_xCfg); 741 } 742 catch ( const css::uno::Exception& ex) 743 { 744 LogHelper::logIt(ex); 745 } 746 } 747 748 // ----------------------------------------------------------------------- 749 750 ::rtl::OUString SvtUserOptions_Impl::GetFullName() const 751 { 752 ::rtl::OUString sFullName; 753 754 sFullName = GetFirstName(); 755 sFullName.trim(); 756 if ( sFullName.getLength() ) 757 sFullName += ::rtl::OUString::createFromAscii(" "); 758 sFullName += GetLastName(); 759 sFullName.trim(); 760 761 return sFullName; 762 } 763 764 // ----------------------------------------------------------------------- 765 766 void SvtUserOptions_Impl::Notify() 767 { 768 NotifyListeners(0); 769 } 770 771 // ----------------------------------------------------------------------- 772 773 sal_Bool SvtUserOptions_Impl::IsTokenReadonly( sal_uInt16 nToken ) const 774 { 775 css::uno::Reference< css::beans::XPropertySet > xData(m_xCfg, css::uno::UNO_QUERY); 776 css::uno::Reference< css::beans::XPropertySetInfo > xInfo = xData->getPropertySetInfo(); 777 css::beans::Property aProp; 778 sal_Bool bRet = sal_False; 779 780 switch ( nToken ) 781 { 782 case USER_OPT_COMPANY: 783 { 784 aProp = xInfo->getPropertyByName(s_so); 785 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 786 break; 787 } 788 case USER_OPT_FIRSTNAME: 789 { 790 aProp = xInfo->getPropertyByName(s_sgivenname); 791 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 792 break; 793 } 794 case USER_OPT_LASTNAME: 795 { 796 aProp = xInfo->getPropertyByName(s_ssn); 797 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 798 break; 799 } 800 case USER_OPT_ID: 801 { 802 aProp = xInfo->getPropertyByName(s_sinitials); 803 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 804 break; 805 } 806 case USER_OPT_STREET: 807 { 808 aProp = xInfo->getPropertyByName(s_sstreet); 809 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 810 break; 811 } 812 case USER_OPT_CITY: 813 { 814 aProp = xInfo->getPropertyByName(s_sl); 815 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 816 break; 817 } 818 case USER_OPT_STATE: 819 { 820 aProp = xInfo->getPropertyByName(s_sst); 821 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 822 break; 823 } 824 case USER_OPT_ZIP: 825 { 826 aProp = xInfo->getPropertyByName(s_spostalcode); 827 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 828 break; 829 } 830 case USER_OPT_COUNTRY: 831 { 832 aProp = xInfo->getPropertyByName(s_sc); 833 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 834 break; 835 } 836 case USER_OPT_POSITION: 837 { 838 aProp = xInfo->getPropertyByName(s_sposition); 839 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 840 break; 841 } 842 case USER_OPT_TITLE: 843 { 844 aProp = xInfo->getPropertyByName(s_stitle); 845 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 846 break; 847 } 848 case USER_OPT_TELEPHONEHOME: 849 { 850 aProp = xInfo->getPropertyByName(s_shomephone); 851 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 852 break; 853 } 854 case USER_OPT_TELEPHONEWORK: 855 { 856 aProp = xInfo->getPropertyByName(s_stelephonenumber); 857 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 858 break; 859 } 860 case USER_OPT_FAX: 861 { 862 aProp = xInfo->getPropertyByName(s_sfacsimiletelephonenumber); 863 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 864 break; 865 } 866 case USER_OPT_EMAIL: 867 { 868 aProp = xInfo->getPropertyByName(s_smail); 869 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 870 break; 871 } 872 case USER_OPT_FATHERSNAME: 873 { 874 aProp = xInfo->getPropertyByName(s_sfathersname); 875 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 876 break; 877 } 878 case USER_OPT_APARTMENT: 879 { 880 aProp = xInfo->getPropertyByName(s_sapartment); 881 bRet = ((aProp.Attributes & css::beans::PropertyAttribute::READONLY) == css::beans::PropertyAttribute::READONLY); 882 break; 883 } 884 default: 885 DBG_ERRORFILE( "SvtUserOptions_Impl::IsTokenReadonly(): invalid token" ); 886 } 887 888 return bRet; 889 } 890 891 //------------------------------------------------------------------------ 892 ::rtl::OUString SvtUserOptions_Impl::GetToken(sal_uInt16 nToken) const 893 { 894 ::rtl::OUString pRet; 895 switch(nToken) 896 { 897 case USER_OPT_COMPANY: pRet = GetCompany(); break; 898 case USER_OPT_FIRSTNAME: pRet = GetFirstName(); break; 899 case USER_OPT_LASTNAME: pRet = GetLastName(); break; 900 case USER_OPT_ID: pRet = GetID(); break; 901 case USER_OPT_STREET: pRet = GetStreet(); break; 902 case USER_OPT_CITY: pRet = GetCity(); break; 903 case USER_OPT_STATE: pRet = GetState(); break; 904 case USER_OPT_ZIP: pRet = GetZip(); break; 905 case USER_OPT_COUNTRY: pRet = GetCountry(); break; 906 case USER_OPT_POSITION: pRet = GetPosition(); break; 907 case USER_OPT_TITLE: pRet = GetTitle(); break; 908 case USER_OPT_TELEPHONEHOME: pRet = GetTelephoneHome(); break; 909 case USER_OPT_TELEPHONEWORK: pRet = GetTelephoneWork(); break; 910 case USER_OPT_FAX: pRet = GetFax(); break; 911 case USER_OPT_EMAIL: pRet = GetEmail(); break; 912 case USER_OPT_FATHERSNAME: pRet = GetFathersName(); break; 913 case USER_OPT_APARTMENT: pRet = GetApartment(); break; 914 default: 915 DBG_ERRORFILE( "SvtUserOptions_Impl::GetToken(): invalid token" ); 916 } 917 return pRet; 918 } 919 920 // class SvtUserOptions -------------------------------------------------- 921 922 SvtUserOptions::SvtUserOptions() 923 { 924 // Global access, must be guarded (multithreading) 925 ::osl::MutexGuard aGuard( GetInitMutex() ); 926 927 if ( !pOptions ) 928 { 929 RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtUserOptions_Impl::ctor()"); 930 pOptions = new SvtUserOptions_Impl; 931 932 ItemHolder1::holdConfigItem(E_USEROPTIONS); 933 } 934 ++nRefCount; 935 pImp = pOptions; 936 pImp->AddListener(this); 937 } 938 939 // ----------------------------------------------------------------------- 940 941 SvtUserOptions::~SvtUserOptions() 942 { 943 // Global access, must be guarded (multithreading) 944 ::osl::MutexGuard aGuard( GetInitMutex() ); 945 pImp->RemoveListener(this); 946 if ( !--nRefCount ) 947 { 948 //if ( pOptions->IsModified() ) 949 // pOptions->Commit(); 950 DELETEZ( pOptions ); 951 } 952 } 953 954 // ----------------------------------------------------------------------- 955 956 ::osl::Mutex& SvtUserOptions::GetInitMutex() 957 { 958 // Initialize static mutex only for one time! 959 static ::osl::Mutex* pMutex = NULL; 960 // If these method first called (Mutex not already exist!) ... 961 if ( pMutex == NULL ) 962 { 963 // ... we must create a new one. Protect follow code with the global mutex - 964 // It must be - we create a static variable! 965 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 966 // We must check our pointer again - 967 // because another instance of our class will be faster then this instance! 968 if ( pMutex == NULL ) 969 { 970 // Create the new mutex and set it for return on static variable. 971 static ::osl::Mutex aMutex; 972 pMutex = &aMutex; 973 } 974 } 975 // Return new created or already existing mutex object. 976 return *pMutex; 977 } 978 979 // ----------------------------------------------------------------------- 980 981 ::rtl::OUString SvtUserOptions::GetCompany() const 982 { 983 ::osl::MutexGuard aGuard( GetInitMutex() ); 984 return pImp->GetCompany(); 985 } 986 987 // ----------------------------------------------------------------------- 988 989 ::rtl::OUString SvtUserOptions::GetFirstName() const 990 { 991 ::osl::MutexGuard aGuard( GetInitMutex() ); 992 return pImp->GetFirstName(); 993 } 994 995 // ----------------------------------------------------------------------- 996 997 ::rtl::OUString SvtUserOptions::GetLastName() const 998 { 999 ::osl::MutexGuard aGuard( GetInitMutex() ); 1000 return pImp->GetLastName(); 1001 } 1002 1003 // ----------------------------------------------------------------------- 1004 1005 ::rtl::OUString SvtUserOptions::GetID() const 1006 { 1007 ::osl::MutexGuard aGuard( GetInitMutex() ); 1008 return pImp->GetID(); 1009 } 1010 1011 // ----------------------------------------------------------------------- 1012 1013 ::rtl::OUString SvtUserOptions::GetStreet() const 1014 { 1015 ::osl::MutexGuard aGuard( GetInitMutex() ); 1016 return pImp->GetStreet(); 1017 } 1018 1019 // ----------------------------------------------------------------------- 1020 1021 ::rtl::OUString SvtUserOptions::GetCity() const 1022 { 1023 ::osl::MutexGuard aGuard( GetInitMutex() ); 1024 return pImp->GetCity(); 1025 } 1026 1027 // ----------------------------------------------------------------------- 1028 1029 ::rtl::OUString SvtUserOptions::GetState() const 1030 { 1031 ::osl::MutexGuard aGuard( GetInitMutex() ); 1032 return pImp->GetState(); 1033 } 1034 1035 // ----------------------------------------------------------------------- 1036 1037 ::rtl::OUString SvtUserOptions::GetZip() const 1038 { 1039 ::osl::MutexGuard aGuard( GetInitMutex() ); 1040 return pImp->GetZip(); 1041 } 1042 1043 // ----------------------------------------------------------------------- 1044 1045 ::rtl::OUString SvtUserOptions::GetCountry() const 1046 { 1047 ::osl::MutexGuard aGuard( GetInitMutex() ); 1048 return pImp->GetCountry(); 1049 } 1050 1051 // ----------------------------------------------------------------------- 1052 1053 ::rtl::OUString SvtUserOptions::GetPosition() const 1054 { 1055 ::osl::MutexGuard aGuard( GetInitMutex() ); 1056 return pImp->GetPosition(); 1057 } 1058 1059 // ----------------------------------------------------------------------- 1060 1061 ::rtl::OUString SvtUserOptions::GetTitle() const 1062 { 1063 ::osl::MutexGuard aGuard( GetInitMutex() ); 1064 return pImp->GetTitle(); 1065 } 1066 1067 // ----------------------------------------------------------------------- 1068 1069 ::rtl::OUString SvtUserOptions::GetTelephoneHome() const 1070 { 1071 ::osl::MutexGuard aGuard( GetInitMutex() ); 1072 return pImp->GetTelephoneHome(); 1073 } 1074 1075 // ----------------------------------------------------------------------- 1076 1077 ::rtl::OUString SvtUserOptions::GetTelephoneWork() const 1078 { 1079 ::osl::MutexGuard aGuard( GetInitMutex() ); 1080 return pImp->GetTelephoneWork(); 1081 } 1082 1083 // ----------------------------------------------------------------------- 1084 1085 ::rtl::OUString SvtUserOptions::GetFax() const 1086 { 1087 ::osl::MutexGuard aGuard( GetInitMutex() ); 1088 return pImp->GetFax(); 1089 } 1090 1091 // ----------------------------------------------------------------------- 1092 1093 ::rtl::OUString SvtUserOptions::GetEmail() const 1094 { 1095 ::osl::MutexGuard aGuard( GetInitMutex() ); 1096 return pImp->GetEmail(); 1097 } 1098 1099 // ----------------------------------------------------------------------- 1100 1101 ::rtl::OUString SvtUserOptions::GetCustomerNumber() const 1102 { 1103 ::osl::MutexGuard aGuard( GetInitMutex() ); 1104 return pImp->GetCustomerNumber(); 1105 } 1106 // ----------------------------------------------------------------------- 1107 1108 ::rtl::OUString SvtUserOptions::GetFathersName() const 1109 { 1110 ::osl::MutexGuard aGuard( GetInitMutex() ); 1111 return pImp->GetFathersName() ; 1112 } 1113 1114 // ----------------------------------------------------------------------- 1115 1116 ::rtl::OUString SvtUserOptions::GetApartment() const 1117 { 1118 ::osl::MutexGuard aGuard( GetInitMutex() ); 1119 return pImp->GetApartment(); 1120 } 1121 1122 // ----------------------------------------------------------------------- 1123 1124 ::rtl::OUString SvtUserOptions::GetFullName() const 1125 { 1126 ::osl::MutexGuard aGuard( GetInitMutex() ); 1127 return pImp->GetFullName(); 1128 } 1129 1130 // ----------------------------------------------------------------------- 1131 1132 ::rtl::OUString SvtUserOptions::GetLocale() const 1133 { 1134 ::osl::MutexGuard aGuard( GetInitMutex() ); 1135 return pImp->GetLocale(); 1136 } 1137 1138 // ----------------------------------------------------------------------- 1139 1140 void SvtUserOptions::SetCompany( const ::rtl::OUString& rNewToken ) 1141 { 1142 ::osl::MutexGuard aGuard( GetInitMutex() ); 1143 pImp->SetCompany( rNewToken ); 1144 } 1145 1146 // ----------------------------------------------------------------------- 1147 1148 void SvtUserOptions::SetFirstName( const ::rtl::OUString& rNewToken ) 1149 { 1150 ::osl::MutexGuard aGuard( GetInitMutex() ); 1151 pImp->SetFirstName( rNewToken ); 1152 } 1153 1154 // ----------------------------------------------------------------------- 1155 1156 void SvtUserOptions::SetLastName( const ::rtl::OUString& rNewToken ) 1157 { 1158 ::osl::MutexGuard aGuard( GetInitMutex() ); 1159 pImp->SetLastName( rNewToken ); 1160 } 1161 1162 // ----------------------------------------------------------------------- 1163 1164 void SvtUserOptions::SetID( const ::rtl::OUString& rNewToken ) 1165 { 1166 ::osl::MutexGuard aGuard( GetInitMutex() ); 1167 pImp->SetID( rNewToken ); 1168 } 1169 1170 // ----------------------------------------------------------------------- 1171 1172 void SvtUserOptions::SetStreet( const ::rtl::OUString& rNewToken ) 1173 { 1174 ::osl::MutexGuard aGuard( GetInitMutex() ); 1175 pImp->SetStreet( rNewToken ); 1176 } 1177 1178 // ----------------------------------------------------------------------- 1179 1180 void SvtUserOptions::SetCity( const ::rtl::OUString& rNewToken ) 1181 { 1182 ::osl::MutexGuard aGuard( GetInitMutex() ); 1183 pImp->SetCity( rNewToken ); 1184 } 1185 1186 // ----------------------------------------------------------------------- 1187 1188 void SvtUserOptions::SetState( const ::rtl::OUString& rNewToken ) 1189 { 1190 ::osl::MutexGuard aGuard( GetInitMutex() ); 1191 pImp->SetState( rNewToken ); 1192 } 1193 1194 // ----------------------------------------------------------------------- 1195 1196 void SvtUserOptions::SetZip( const ::rtl::OUString& rNewToken ) 1197 { 1198 ::osl::MutexGuard aGuard( GetInitMutex() ); 1199 pImp->SetZip( rNewToken ); 1200 } 1201 1202 // ----------------------------------------------------------------------- 1203 1204 void SvtUserOptions::SetCountry( const ::rtl::OUString& rNewToken ) 1205 { 1206 ::osl::MutexGuard aGuard( GetInitMutex() ); 1207 pImp->SetCountry( rNewToken ); 1208 } 1209 1210 // ----------------------------------------------------------------------- 1211 1212 void SvtUserOptions::SetPosition( const ::rtl::OUString& rNewToken ) 1213 { 1214 ::osl::MutexGuard aGuard( GetInitMutex() ); 1215 pImp->SetPosition( rNewToken ); 1216 } 1217 1218 // ----------------------------------------------------------------------- 1219 1220 void SvtUserOptions::SetTitle( const ::rtl::OUString& rNewToken ) 1221 { 1222 ::osl::MutexGuard aGuard( GetInitMutex() ); 1223 pImp->SetTitle( rNewToken ); 1224 } 1225 1226 // ----------------------------------------------------------------------- 1227 1228 void SvtUserOptions::SetTelephoneHome( const ::rtl::OUString& rNewToken ) 1229 { 1230 ::osl::MutexGuard aGuard( GetInitMutex() ); 1231 pImp->SetTelephoneHome( rNewToken ); 1232 } 1233 1234 // ----------------------------------------------------------------------- 1235 1236 void SvtUserOptions::SetTelephoneWork( const ::rtl::OUString& rNewToken ) 1237 { 1238 ::osl::MutexGuard aGuard( GetInitMutex() ); 1239 pImp->SetTelephoneWork( rNewToken ); 1240 } 1241 1242 // ----------------------------------------------------------------------- 1243 1244 void SvtUserOptions::SetFax( const ::rtl::OUString& rNewToken ) 1245 { 1246 ::osl::MutexGuard aGuard( GetInitMutex() ); 1247 pImp->SetFax( rNewToken ); 1248 } 1249 1250 // ----------------------------------------------------------------------- 1251 1252 void SvtUserOptions::SetEmail( const ::rtl::OUString& rNewToken ) 1253 { 1254 ::osl::MutexGuard aGuard( GetInitMutex() ); 1255 pImp->SetEmail( rNewToken ); 1256 } 1257 1258 // ----------------------------------------------------------------------- 1259 1260 void SvtUserOptions::SetCustomerNumber( const ::rtl::OUString& rNewToken ) 1261 { 1262 ::osl::MutexGuard aGuard( GetInitMutex() ); 1263 pImp->SetCustomerNumber( rNewToken ); 1264 } 1265 // ----------------------------------------------------------------------- 1266 1267 void SvtUserOptions::SetFathersName( const ::rtl::OUString& rNewToken ) 1268 { 1269 ::osl::MutexGuard aGuard( GetInitMutex() ); 1270 pImp->SetFathersName( rNewToken ); 1271 } 1272 1273 // ----------------------------------------------------------------------- 1274 1275 void SvtUserOptions::SetApartment( const ::rtl::OUString& rNewToken ) 1276 { 1277 ::osl::MutexGuard aGuard( GetInitMutex() ); 1278 pImp->SetApartment( rNewToken ); 1279 } 1280 1281 // ----------------------------------------------------------------------- 1282 1283 sal_Bool SvtUserOptions::IsTokenReadonly( sal_uInt16 nToken ) const 1284 { 1285 ::osl::MutexGuard aGuard( GetInitMutex() ); 1286 return pImp->IsTokenReadonly( nToken ); 1287 } 1288 //------------------------------------------------------------------------ 1289 ::rtl::OUString SvtUserOptions::GetToken(sal_uInt16 nToken) const 1290 { 1291 ::osl::MutexGuard aGuard( GetInitMutex() ); 1292 return pImp->GetToken( nToken ); 1293 } 1294