TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

advancedcustomfields.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. This file is part of KAddressbook.
  3. Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
  4. Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. As a special exception, permission is given to link this program
  17. with any edition of TQt, and distribute the resulting executable,
  18. without including the source code for TQt in the source distribution.
  19. */
  20. #include <tqcheckbox.h>
  21. #include <tqcombobox.h>
  22. #include <tqdatetimeedit.h>
  23. #include <tqlayout.h>
  24. #include <tqobjectlist.h>
  25. #include <tqspinbox.h>
  26. #include <tqregexp.h>
  27. #include <tqtextedit.h>
  28. #include <tqwidgetfactory.h>
  29. #include <kdatepicker.h>
  30. #include <kdatetimewidget.h>
  31. #include <kdialog.h>
  32. #include <klineedit.h>
  33. #include <kstandarddirs.h>
  34. #include <libtdepim/designerfields.h>
  35. #include "customfieldswidget.h"
  36. #include "advancedcustomfields.h"
  37. class KABCStorage : public KPIM::DesignerFields::Storage
  38. {
  39. public:
  40. KABCStorage( KABC::Addressee *a, const TQString &ns )
  41. : mAddressee( a ), mNs( ns )
  42. {
  43. }
  44. TQStringList keys()
  45. {
  46. TQStringList keys;
  47. const TQStringList customs = mAddressee->customs();
  48. TQStringList::ConstIterator it;
  49. for ( it = customs.begin(); it != customs.end(); ++it ) {
  50. TQString app, name, value;
  51. splitField( *it, app, name, value );
  52. if ( app == mNs ) keys.append( name );
  53. }
  54. return keys;
  55. }
  56. TQString read( const TQString &key )
  57. {
  58. return mAddressee->custom( mNs, key );
  59. }
  60. void write( const TQString &key, const TQString &value )
  61. {
  62. mAddressee->insertCustom( mNs, key, value );
  63. }
  64. private:
  65. KABC::Addressee *mAddressee;
  66. TQString mNs;
  67. };
  68. AdvancedCustomFields::AdvancedCustomFields( const TQString &uiFile, KABC::AddressBook *ab,
  69. TQWidget *parent, const char *name )
  70. : KAB::ContactEditorWidget( ab, parent, name )
  71. {
  72. initGUI( uiFile );
  73. }
  74. void AdvancedCustomFields::loadContact( KABC::Addressee *addr )
  75. {
  76. TQString ns;
  77. if ( mFields->identifier().upper() == "KADDRESSBOOK" ||
  78. TQRegExp( "^Form\\d\\d?$" ).search( mFields->identifier() ) >= 0 ) {
  79. ns = "KADDRESSBOOK";
  80. } else {
  81. ns = mFields->identifier();
  82. }
  83. KABCStorage storage( addr, ns );
  84. mFields->load( &storage );
  85. }
  86. void AdvancedCustomFields::storeContact( KABC::Addressee *addr )
  87. {
  88. TQString ns;
  89. if ( mFields->identifier().upper() == "KADDRESSBOOK" ||
  90. TQRegExp( "^Form\\d\\d?$" ).search( mFields->identifier() ) >= 0 ) {
  91. ns = "KADDRESSBOOK";
  92. } else {
  93. ns = mFields->identifier();
  94. }
  95. KABCStorage storage( addr, ns );
  96. mFields->save( &storage );
  97. }
  98. void AdvancedCustomFields::setReadOnly( bool readOnly )
  99. {
  100. mFields->setReadOnly( readOnly );
  101. }
  102. void AdvancedCustomFields::initGUI( const TQString &uiFile )
  103. {
  104. TQVBoxLayout *tqlayout = new TQVBoxLayout( this, KDialog::marginHint(),
  105. KDialog::spacingHint() );
  106. mFields = new KPIM::DesignerFields( uiFile, this );
  107. tqlayout->addWidget( mFields );
  108. connect( mFields, TQT_SIGNAL( modified() ), TQT_SLOT( setModified() ) );
  109. }
  110. TQString AdvancedCustomFields::pageIdentifier() const
  111. {
  112. return mFields->identifier();
  113. }
  114. TQString AdvancedCustomFields::pageTitle() const
  115. {
  116. return mFields->title();
  117. }
  118. #include "advancedcustomfields.moc"