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