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.

addresseeeditorwidget.cpp 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. /*
  2. This file is part of KAddressBook.
  3. Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. As a special exception, permission is given to link this program
  16. with any edition of TQt, and distribute the resulting executable,
  17. without including the source code for TQt in the source distribution.
  18. */
  19. #include <tqcheckbox.h>
  20. #include <tqhbox.h>
  21. #include <tqlabel.h>
  22. #include <tqlayout.h>
  23. #include <tqlistbox.h>
  24. #include <tqpushbutton.h>
  25. #include <tqtabwidget.h>
  26. #include <tqtextedit.h>
  27. #include <tqtoolbutton.h>
  28. #include <tqtooltip.h>
  29. #include <kabc/resource.h>
  30. #include <kabc/stdaddressbook.h>
  31. #include <kaccelmanager.h>
  32. #include <kapplication.h>
  33. #include <kconfig.h>
  34. #include <kcombobox.h>
  35. #include <kdebug.h>
  36. #include <kdialogbase.h>
  37. #include <kglobal.h>
  38. #include <kiconloader.h>
  39. #include <klineedit.h>
  40. #include <klocale.h>
  41. #include <kmessagebox.h>
  42. #include <kseparator.h>
  43. #include <ksqueezedtextlabel.h>
  44. #include <kstandarddirs.h>
  45. #include <libtdepim/addresseelineedit.h>
  46. #include <libtdepim/categoryeditdialog.h>
  47. #include <libtdepim/categoryselectdialog.h>
  48. #include <libtdepim/kdateedit.h>
  49. #include <libtdepim/resourceabc.h>
  50. #include "addresseditwidget.h"
  51. #include "advancedcustomfields.h"
  52. #include "emaileditwidget.h"
  53. #include "imeditwidget.h"
  54. #include "kabprefs.h"
  55. #include "keywidget.h"
  56. #include "nameeditdialog.h"
  57. #include "phoneeditwidget.h"
  58. #include "secrecywidget.h"
  59. #include "addresseeeditorwidget.h"
  60. AddresseeEditorWidget::AddresseeEditorWidget( TQWidget *parent, const char *name )
  61. : AddresseeEditorBase( parent, name ),
  62. mBlockSignals( false ), mReadOnly( false )
  63. {
  64. kdDebug(5720) << "AddresseeEditorWidget()" << endl;
  65. initGUI();
  66. mCategorySelectDialog = 0;
  67. mCategoryEditDialog = 0;
  68. // Load the empty addressee as defaults
  69. load();
  70. mDirty = false;
  71. }
  72. AddresseeEditorWidget::~AddresseeEditorWidget()
  73. {
  74. kdDebug(5720) << "~AddresseeEditorWidget()" << endl;
  75. }
  76. void AddresseeEditorWidget::setAddressee( const KABC::Addressee &addr )
  77. {
  78. if ( mAddressee.uid() == addr.uid() )
  79. return;
  80. mAddressee = addr;
  81. bool readOnly = false;
  82. if ( KABC::Resource *res = addr.resource() ) {
  83. if ( res->readOnly() ) {
  84. readOnly = true;
  85. //Kolab resources have finer access control than planned in the overall design.
  86. } else if ( res->inherits( "KPIM::ResourceABC" ) ) {
  87. KPIM::ResourceABC *resAbc = static_cast<KPIM::ResourceABC *>( res );
  88. TQString subresource = resAbc->uidToResourceMap()[ addr.uid() ];
  89. if ( !subresource.isEmpty() )
  90. readOnly |= !resAbc->subresourceWritable( subresource );
  91. }
  92. }
  93. setReadOnly( readOnly );
  94. load();
  95. }
  96. const KABC::Addressee &AddresseeEditorWidget::addressee()
  97. {
  98. return mAddressee;
  99. }
  100. void AddresseeEditorWidget::textChanged( const TQString& )
  101. {
  102. emitModified();
  103. }
  104. void AddresseeEditorWidget::initGUI()
  105. {
  106. TQVBoxLayout *tqlayout = new TQVBoxLayout( this );
  107. mTabWidget = new TQTabWidget( this );
  108. tqlayout->addWidget( mTabWidget );
  109. setupTab1();
  110. setupTab2();
  111. setupAdditionalTabs();
  112. setupCustomFieldsTabs();
  113. connect( mTabWidget, TQT_SIGNAL( currentChanged(TQWidget*) ),
  114. TQT_SLOT( pageChanged(TQWidget*) ) );
  115. }
  116. void AddresseeEditorWidget::setupTab1()
  117. {
  118. // This is the General tab
  119. TQWidget *tab1 = new TQWidget( mTabWidget );
  120. TQGridLayout *tqlayout = new TQGridLayout( tab1, 11, 7 );
  121. tqlayout->setMargin( KDialogBase::marginHint() );
  122. tqlayout->setSpacing( KDialogBase::spacingHint() );
  123. TQLabel *label;
  124. KSeparator* bar;
  125. TQPushButton *button;
  126. //////////////////////////////////
  127. // Upper left group (person info)
  128. // Person icon
  129. label = new TQLabel( tab1 );
  130. label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop,
  131. KIcon::SizeMedium ) );
  132. tqlayout->addMultiCellWidget( label, 0, 1, 0, 0 );
  133. // First name
  134. button = new TQPushButton( i18n( "Edit Name..." ), tab1 );
  135. TQToolTip::add( button, i18n( "Edit the contact's name" ) );
  136. mNameEdit = new KLineEdit( tab1, "mNameEdit" );
  137. connect( mNameEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  138. TQT_SLOT( nameTextChanged( const TQString& ) ) );
  139. connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( nameButtonClicked() ) );
  140. mNameLabel = new KSqueezedTextLabel( tab1 );
  141. if ( KABPrefs::instance()->automaticNameParsing() ) {
  142. mNameLabel->hide();
  143. mNameEdit->show();
  144. } else {
  145. mNameEdit->hide();
  146. mNameLabel->show();
  147. }
  148. tqlayout->addWidget( button, 0, 1 );
  149. tqlayout->addWidget( mNameEdit, 0, 2 );
  150. tqlayout->addWidget( mNameLabel, 0, 2 );
  151. label = new TQLabel( i18n( "<roleLabel>:", "%1:" ).tqarg( KABC::Addressee::roleLabel() ), tab1 );
  152. mRoleEdit = new KLineEdit( tab1 );
  153. connect( mRoleEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  154. TQT_SLOT( textChanged( const TQString& ) ) );
  155. label->setBuddy( mRoleEdit );
  156. tqlayout->addWidget( label, 1, 1 );
  157. tqlayout->addWidget( mRoleEdit, 1, 2 );
  158. // Organization
  159. label = new TQLabel( i18n( "<organizationLabel>:", "%1:" ).tqarg( KABC::Addressee::organizationLabel() ), tab1 );
  160. mOrgEdit = new KLineEdit( tab1 );
  161. label->setBuddy( mOrgEdit );
  162. connect( mOrgEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  163. TQT_SLOT( organizationTextChanged( const TQString& ) ) );
  164. tqlayout->addWidget( label, 2, 1 );
  165. tqlayout->addWidget( mOrgEdit, 2, 2 );
  166. // File as (formatted name)
  167. label = new TQLabel( i18n( "Formatted name:" ), tab1 );
  168. mFormattedNameLabel = new KSqueezedTextLabel( tab1 );
  169. tqlayout->addWidget( label, 3, 1 );
  170. tqlayout->addWidget( mFormattedNameLabel, 3, 2 );
  171. // Left hand separator. This separator doesn't go all the way
  172. // across so the dialog still flows from top to bottom
  173. bar = new KSeparator( KSeparator::HLine, tab1 );
  174. tqlayout->addMultiCellWidget( bar, 4, 4, 0, 2 );
  175. //////////////////////////////////////
  176. // Phone numbers (upper right)
  177. label = new TQLabel( tab1 );
  178. label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook",
  179. KIcon::Desktop, KIcon::SizeMedium ) );
  180. tqlayout->addMultiCellWidget( label, 0, 1, 3, 3 );
  181. mPhoneEditWidget = new PhoneEditWidget( tab1 );
  182. connect( mPhoneEditWidget, TQT_SIGNAL( modified() ), TQT_SLOT( emitModified() ) );
  183. tqlayout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 );
  184. bar = new KSeparator( KSeparator::HLine, tab1 );
  185. tqlayout->addMultiCellWidget( bar, 4, 4, 3, 6 );
  186. //////////////////////////////////////
  187. // Addresses (lower left)
  188. label = new TQLabel( tab1 );
  189. label->setPixmap( KGlobal::iconLoader()->loadIcon( "kfm_home", KIcon::Desktop,
  190. KIcon::SizeMedium ) );
  191. tqlayout->addMultiCellWidget( label, 5, 6, 0, 0 );
  192. mAddressEditWidget = new AddressEditWidget( tab1 );
  193. connect( mAddressEditWidget, TQT_SIGNAL( modified() ), TQT_SLOT( emitModified() ) );
  194. tqlayout->addMultiCellWidget( mAddressEditWidget, 5, 10, 1, 2 );
  195. //////////////////////////////////////
  196. // Email / Web (lower right)
  197. label = new TQLabel( tab1 );
  198. label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop,
  199. KIcon::SizeMedium ) );
  200. tqlayout->addMultiCellWidget( label, 5, 6, 3, 3 );
  201. mEmailWidget = new EmailEditWidget( tab1 );
  202. connect( mEmailWidget, TQT_SIGNAL( modified() ), TQT_SLOT( emitModified() ) );
  203. tqlayout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 );
  204. // add the separator
  205. bar = new KSeparator( KSeparator::HLine, tab1 );
  206. tqlayout->addMultiCellWidget( bar, 7, 7, 3, 6 );
  207. TQHBoxLayout *homePageLayout = new TQHBoxLayout( 0, 11, 7 );
  208. label = new TQLabel( tab1 );
  209. label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop,
  210. KIcon::SizeMedium ) );
  211. homePageLayout->addWidget( label );
  212. label = new TQLabel( i18n( "<urlLabel>:", "%1:" ).tqarg( KABC::Addressee::urlLabel() ), tab1 );
  213. mURLEdit = new KLineEdit( tab1 );
  214. connect( mURLEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  215. TQT_SLOT( textChanged( const TQString& ) ) );
  216. label->setBuddy( mURLEdit );
  217. homePageLayout->addWidget( label );
  218. homePageLayout->addWidget( mURLEdit );
  219. tqlayout->addMultiCellLayout( homePageLayout, 8, 8, 3, 6 );
  220. TQHBoxLayout *blogLayout = new TQHBoxLayout( 0, 11, 7 );
  221. label = new TQLabel( i18n("Blog feed:"), tab1 );
  222. blogLayout->addWidget( label );
  223. mBlogEdit = new KLineEdit( tab1 );
  224. blogLayout->addWidget( mBlogEdit );
  225. connect( mBlogEdit, TQT_SIGNAL( textChanged( const TQString & ) ),
  226. TQT_SLOT( textChanged( const TQString & ) ) );
  227. label->setBuddy( mBlogEdit );
  228. tqlayout->addMultiCellLayout( blogLayout, 9, 9, 4, 6 );
  229. mIMWidget = new IMEditWidget( tab1, mAddressee );
  230. connect( mIMWidget, TQT_SIGNAL( modified() ), TQT_SLOT( emitModified() ) );
  231. tqlayout->addMultiCellWidget( mIMWidget, 10, 10, 4, 6 );
  232. tqlayout->addColSpacing( 6, 50 );
  233. bar = new KSeparator( KSeparator::HLine, tab1 );
  234. tqlayout->addMultiCellWidget( bar, 11, 11, 0, 6 );
  235. ///////////////////////////////////////
  236. TQHBox *categoryBox = new TQHBox( tab1 );
  237. categoryBox->setSpacing( KDialogBase::spacingHint() );
  238. // Categories
  239. mCategoryButton = new TQPushButton( i18n( "Select Categories..." ), categoryBox );
  240. connect( mCategoryButton, TQT_SIGNAL( clicked() ), TQT_SLOT( selectCategories() ) );
  241. mCategoryEdit = new KLineEdit( categoryBox );
  242. mCategoryEdit->setReadOnly( true );
  243. connect( mCategoryEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  244. TQT_SLOT( textChanged( const TQString& ) ) );
  245. mSecrecyWidget = new SecrecyWidget( categoryBox );
  246. connect( mSecrecyWidget, TQT_SIGNAL( changed() ), TQT_SLOT( emitModified() ) );
  247. tqlayout->addMultiCellWidget( categoryBox, 12, 12, 0, 6 );
  248. // Build the tqlayout and add to the tab widget
  249. tqlayout->activate(); // required
  250. mTabWidget->addTab( tab1, i18n( "&General" ) );
  251. }
  252. void AddresseeEditorWidget::setupTab2()
  253. {
  254. // This is the Details tab
  255. TQWidget *tab2 = new TQWidget( mTabWidget );
  256. TQGridLayout *tqlayout = new TQGridLayout( tab2, 6, 6 );
  257. tqlayout->setMargin( KDialogBase::marginHint() );
  258. tqlayout->setSpacing( KDialogBase::spacingHint() );
  259. TQLabel *label;
  260. KSeparator* bar;
  261. ///////////////////////
  262. // Office info
  263. // Department
  264. label = new TQLabel( tab2 );
  265. label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop,
  266. KIcon::SizeMedium ) );
  267. tqlayout->addMultiCellWidget( label, 0, 1, 0, 0 );
  268. label = new TQLabel( i18n( "Department:" ), tab2 );
  269. tqlayout->addWidget( label, 0, 1 );
  270. mDepartmentEdit = new KLineEdit( tab2 );
  271. connect( mDepartmentEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  272. TQT_SLOT( textChanged( const TQString& ) ) );
  273. label->setBuddy( mDepartmentEdit );
  274. tqlayout->addWidget( mDepartmentEdit, 0, 2 );
  275. label = new TQLabel( i18n( "Office:" ), tab2 );
  276. tqlayout->addWidget( label, 1, 1 );
  277. mOfficeEdit = new KLineEdit( tab2 );
  278. connect( mOfficeEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  279. TQT_SLOT( textChanged( const TQString& ) ) );
  280. label->setBuddy( mOfficeEdit );
  281. tqlayout->addWidget( mOfficeEdit, 1, 2 );
  282. label = new TQLabel( i18n( "Profession:" ), tab2 );
  283. tqlayout->addWidget( label, 2, 1 );
  284. mProfessionEdit = new KLineEdit( tab2 );
  285. connect( mProfessionEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  286. TQT_SLOT( textChanged( const TQString& ) ) );
  287. label->setBuddy( mProfessionEdit );
  288. tqlayout->addWidget( mProfessionEdit, 2, 2 );
  289. label = new TQLabel( i18n( "Manager\'s name:" ), tab2 );
  290. tqlayout->addWidget( label, 0, 3 );
  291. mManagerEdit = new KPIM::AddresseeLineEdit( tab2 );
  292. connect( mManagerEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  293. TQT_SLOT( textChanged( const TQString& ) ) );
  294. label->setBuddy( mManagerEdit );
  295. tqlayout->addMultiCellWidget( mManagerEdit, 0, 0, 4, 5 );
  296. label = new TQLabel( i18n( "Assistant's name:" ), tab2 );
  297. tqlayout->addWidget( label, 1, 3 );
  298. mAssistantEdit = new KPIM::AddresseeLineEdit( tab2 );
  299. connect( mAssistantEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  300. TQT_SLOT( textChanged( const TQString& ) ) );
  301. label->setBuddy( mAssistantEdit );
  302. tqlayout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 );
  303. label = new TQLabel( i18n( "<titleLabel>:", "%1:" ).tqarg( KABC::Addressee::titleLabel() ), tab2 );
  304. tqlayout->addWidget( label, 2, 3 );
  305. mTitleEdit = new KLineEdit( tab2 );
  306. connect( mTitleEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  307. TQT_SLOT( textChanged( const TQString& ) ) );
  308. label->setBuddy( mTitleEdit );
  309. tqlayout->addMultiCellWidget( mTitleEdit, 2, 2, 4, 5 );
  310. bar = new KSeparator( KSeparator::HLine, tab2 );
  311. tqlayout->addMultiCellWidget( bar, 3, 3, 0, 5 );
  312. /////////////////////////////////////////////////
  313. // Personal info
  314. label = new TQLabel( tab2 );
  315. label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop,
  316. KIcon::SizeMedium ) );
  317. tqlayout->addMultiCellWidget( label, 4, 5, 0, 0 );
  318. label = new TQLabel( i18n( "Nickname:" ), tab2 );
  319. tqlayout->addWidget( label, 4, 1 );
  320. mNicknameEdit = new KLineEdit( tab2 );
  321. connect( mNicknameEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  322. TQT_SLOT( textChanged( const TQString& ) ) );
  323. label->setBuddy( mNicknameEdit );
  324. tqlayout->addWidget( mNicknameEdit, 4, 2 );
  325. label = new TQLabel( i18n( "Partner's name:" ), tab2 );
  326. tqlayout->addWidget( label, 5, 1 );
  327. mSpouseEdit = new KPIM::AddresseeLineEdit( tab2 );
  328. connect( mSpouseEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  329. TQT_SLOT( textChanged( const TQString& ) ) );
  330. label->setBuddy( mSpouseEdit );
  331. tqlayout->addWidget( mSpouseEdit, 5, 2 );
  332. label = new TQLabel( i18n( "Birthdate:" ), tab2 );
  333. tqlayout->addWidget( label, 4, 3 );
  334. mBirthdayPicker = new KDateEdit( tab2 );
  335. connect( mBirthdayPicker, TQT_SIGNAL( dateChanged( const TQDate& ) ),
  336. TQT_SLOT( dateChanged( const TQDate& ) ) );
  337. connect( mBirthdayPicker, TQT_SIGNAL( textChanged( const TQString& ) ),
  338. TQT_SLOT( emitModified() ) );
  339. label->setBuddy( mBirthdayPicker );
  340. tqlayout->addWidget( mBirthdayPicker, 4, 4 );
  341. label = new TQLabel( i18n( "Anniversary:" ), tab2 );
  342. tqlayout->addWidget( label, 5, 3 );
  343. mAnniversaryPicker = new KDateEdit( tab2 );
  344. connect( mAnniversaryPicker, TQT_SIGNAL( dateChanged( const TQDate& ) ),
  345. TQT_SLOT( dateChanged( const TQDate& ) ) );
  346. connect( mAnniversaryPicker, TQT_SIGNAL( textChanged( const TQString& ) ),
  347. TQT_SLOT( emitModified() ) );
  348. label->setBuddy( mAnniversaryPicker );
  349. tqlayout->addWidget( mAnniversaryPicker, 5, 4 );
  350. bar = new KSeparator( KSeparator::HLine, tab2 );
  351. tqlayout->addMultiCellWidget( bar, 6, 6, 0, 5 );
  352. //////////////////////////////////////
  353. // Notes
  354. label = new TQLabel( i18n( "Note:" ), tab2 );
  355. label->tqsetAlignment( TQt::AlignTop | TQt::AlignLeft );
  356. tqlayout->addWidget( label, 7, 0 );
  357. mNoteEdit = new TQTextEdit( tab2 );
  358. mNoteEdit->setWordWrap( TQTextEdit::WidgetWidth );
  359. mNoteEdit->setMinimumSize( mNoteEdit->tqsizeHint() );
  360. connect( mNoteEdit, TQT_SIGNAL( textChanged() ), TQT_SLOT( emitModified() ) );
  361. label->setBuddy( mNoteEdit );
  362. tqlayout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 );
  363. // Build the tqlayout and add to the tab widget
  364. tqlayout->activate(); // required
  365. mTabWidget->addTab( tab2, i18n( "&Details" ) );
  366. }
  367. void AddresseeEditorWidget::setupAdditionalTabs()
  368. {
  369. ContactEditorWidgetManager *manager = ContactEditorWidgetManager::self();
  370. // create all tab pages and add the widgets
  371. for ( int i = 0; i < manager->count(); ++i ) {
  372. TQString pageIdentifier = manager->factory( i )->pageIdentifier();
  373. TQString pageTitle = manager->factory( i )->pageTitle();
  374. if ( pageIdentifier == "misc" )
  375. pageTitle = i18n( "Misc" );
  376. ContactEditorTabPage *page = mTabPages[ pageIdentifier ];
  377. if ( page == 0 ) { // tab not yet available, create one
  378. page = new ContactEditorTabPage( mTabWidget );
  379. mTabPages.insert( pageIdentifier, page );
  380. mTabWidget->addTab( page, pageTitle );
  381. connect( page, TQT_SIGNAL( changed() ), TQT_SLOT( emitModified() ) );
  382. }
  383. KAB::ContactEditorWidget *widget
  384. = manager->factory( i )->createWidget( KABC::StdAddressBook::self( true ),
  385. page );
  386. if ( widget )
  387. page->addWidget( widget );
  388. }
  389. // query the tqlayout update
  390. TQDictIterator<ContactEditorTabPage> it( mTabPages );
  391. for ( ; it.current(); ++it )
  392. it.current()->updateLayout();
  393. }
  394. void AddresseeEditorWidget::setupCustomFieldsTabs()
  395. {
  396. TQStringList activePages = KABPrefs::instance()->advancedCustomFields();
  397. const TQStringList list = KGlobal::dirs()->findAllResources( "data", "kaddressbook/contacteditorpages/*.ui", true, true );
  398. for ( TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
  399. if ( activePages.find( (*it).mid( (*it).findRev('/') + 1 ) ) == activePages.end() )
  400. continue;
  401. ContactEditorTabPage *page = new ContactEditorTabPage( mTabWidget );
  402. AdvancedCustomFields *wdg = new AdvancedCustomFields( *it, KABC::StdAddressBook::self( true ), page );
  403. if ( wdg ) {
  404. mTabPages.insert( wdg->pageIdentifier(), page );
  405. mTabWidget->addTab( page, wdg->pageTitle() );
  406. page->addWidget( wdg );
  407. page->updateLayout();
  408. connect( page, TQT_SIGNAL( changed() ), TQT_SLOT( emitModified() ) );
  409. } else
  410. delete page;
  411. }
  412. }
  413. void AddresseeEditorWidget::load()
  414. {
  415. kdDebug(5720) << "AddresseeEditorWidget::load()" << endl;
  416. // Block signals in case anything tries to emit modified
  417. // CS: This doesn't seem to work.
  418. bool block = signalsBlocked();
  419. blockSignals( true );
  420. mBlockSignals = true; // used for internal signal blocking
  421. mNameEdit->blockSignals( true );
  422. mNameEdit->setText( mAddressee.assembledName() );
  423. mNameEdit->blockSignals( false );
  424. if ( mAddressee.formattedName().isEmpty() ) {
  425. KConfig config( "kaddressbookrc" );
  426. config.setGroup( "General" );
  427. mFormattedNameType = config.readNumEntry( "FormattedNameType", 1 );
  428. mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
  429. } else {
  430. if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::SimpleName ) )
  431. mFormattedNameType = NameEditDialog::SimpleName;
  432. else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::FullName ) )
  433. mFormattedNameType = NameEditDialog::FullName;
  434. else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseNameWithComma ) )
  435. mFormattedNameType = NameEditDialog::ReverseNameWithComma;
  436. else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseName ) )
  437. mFormattedNameType = NameEditDialog::ReverseName;
  438. else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::Organization ) )
  439. mFormattedNameType = NameEditDialog::Organization;
  440. else
  441. mFormattedNameType = NameEditDialog::CustomName;
  442. }
  443. mFormattedNameLabel->setText( mAddressee.formattedName() );
  444. mRoleEdit->setText( mAddressee.role() );
  445. mOrgEdit->setText( mAddressee.organization() );
  446. #if KDE_IS_VERSION(3,5,8)
  447. mDepartmentEdit->setText( mAddressee.department() );
  448. // compatibility with older versions
  449. if ( mAddressee.department().isEmpty() )
  450. #endif
  451. mDepartmentEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Department" ) );
  452. mURLEdit->setURL( mAddressee.url() );
  453. mURLEdit->home( false );
  454. mBlogEdit->setURL( mAddressee.custom( "KADDRESSBOOK", "BlogFeed" ) );
  455. mNoteEdit->setText( mAddressee.note() );
  456. mEmailWidget->setEmails( mAddressee.emails() );
  457. mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() );
  458. mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() );
  459. mBirthdayPicker->setDate( mAddressee.birthday().date() );
  460. TQString anniversaryStr = mAddressee.custom( "KADDRESSBOOK", "X-Anniversary" );
  461. TQDate anniversary = (anniversaryStr.isEmpty() ? TQDate() : TQDate::fromString( anniversaryStr, Qt::ISODate ));
  462. mAnniversaryPicker->setDate( anniversary );
  463. mNicknameEdit->setText( mAddressee.nickName() );
  464. mCategoryEdit->setText( mAddressee.categories().join( "," ) );
  465. mSecrecyWidget->setSecrecy( mAddressee.secrecy() );
  466. // Load customs
  467. mIMWidget->setPreferredIM( mAddressee.custom( "KADDRESSBOOK", "X-IMAddress" ) );
  468. mSpouseEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ) );
  469. mManagerEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-ManagersName" ) );
  470. mAssistantEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-AssistantsName" ) );
  471. mOfficeEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Office" ) );
  472. mProfessionEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Profession" ) );
  473. mTitleEdit->setText( mAddressee.title() );
  474. TQDictIterator<ContactEditorTabPage> it( mTabPages );
  475. for ( ; it.current(); ++it )
  476. it.current()->loadContact( &mAddressee );
  477. blockSignals( block );
  478. mBlockSignals = false;
  479. mDirty = false;
  480. }
  481. void AddresseeEditorWidget::save()
  482. {
  483. if ( !mDirty ) return;
  484. mAddressee.setRole( mRoleEdit->text() );
  485. mAddressee.setOrganization( mOrgEdit->text() );
  486. #if KDE_IS_VERSION(3,5,8)
  487. mAddressee.setDepartment( mDepartmentEdit->text() );
  488. #else
  489. if ( !mDepartmentEdit->text().isEmpty() )
  490. mAddressee.insertCustom( "KADDRESSBOOK", "X-Department", mDepartmentEdit->text() );
  491. else
  492. mAddressee.removeCustom( "KADDRESSBOOK", "X-Department" );
  493. #endif
  494. TQString homepage = mURLEdit->text().stripWhiteSpace();
  495. if ( homepage.isEmpty() )
  496. mAddressee.setUrl( KURL() );
  497. else {
  498. if( !homepage.startsWith("http") )
  499. homepage = "http://" + homepage;
  500. mAddressee.setUrl( KURL( homepage ) );
  501. }
  502. if ( !mBlogEdit->text().isEmpty() )
  503. mAddressee.insertCustom( "KADDRESSBOOK", "BlogFeed", mBlogEdit->text() );
  504. else
  505. mAddressee.removeCustom( "KADDRESSBOOK", "BlogFeed" );
  506. mAddressee.setNote( mNoteEdit->text() );
  507. if ( mBirthdayPicker->date().isValid() )
  508. mAddressee.setBirthday( TQDateTime( mBirthdayPicker->date() ) );
  509. else
  510. mAddressee.setBirthday( TQDateTime() );
  511. mAddressee.setNickName( mNicknameEdit->text() );
  512. mAddressee.setCategories( TQStringList::split( ",", mCategoryEdit->text() ) );
  513. mAddressee.setSecrecy( mSecrecyWidget->secrecy() );
  514. // save custom fields
  515. if ( !mIMWidget->preferredIM().isEmpty() )
  516. mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMWidget->preferredIM() );
  517. else
  518. mAddressee.removeCustom( "KADDRESSBOOK", "X-IMAddress" );
  519. if ( !mSpouseEdit->text().isEmpty() )
  520. mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() );
  521. else
  522. mAddressee.removeCustom( "KADDRESSBOOK", "X-SpousesName" );
  523. if ( !mManagerEdit->text().isEmpty() )
  524. mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() );
  525. else
  526. mAddressee.removeCustom( "KADDRESSBOOK", "X-ManagersName" );
  527. if ( !mAssistantEdit->text().isEmpty() )
  528. mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() );
  529. else
  530. mAddressee.removeCustom( "KADDRESSBOOK", "X-AssistantsName" );
  531. if ( !mOfficeEdit->text().isEmpty() )
  532. mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() );
  533. else
  534. mAddressee.removeCustom( "KADDRESSBOOK", "X-Office" );
  535. if ( !mProfessionEdit->text().isEmpty() )
  536. mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() );
  537. else
  538. mAddressee.removeCustom( "KADDRESSBOOK", "X-Profession" );
  539. if ( mAnniversaryPicker->date().isValid() )
  540. mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary",
  541. mAnniversaryPicker->date().toString( Qt::ISODate ) );
  542. else
  543. mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" );
  544. mAddressee.setTitle( mTitleEdit->text() );
  545. // Save the email addresses
  546. mAddressee.setEmails( mEmailWidget->emails() );
  547. // Save the phone numbers
  548. KABC::PhoneNumber::List phoneNumbers;
  549. KABC::PhoneNumber::List::ConstIterator phoneIter;
  550. phoneNumbers = mAddressee.phoneNumbers();
  551. for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
  552. ++phoneIter )
  553. mAddressee.removePhoneNumber( *phoneIter );
  554. phoneNumbers = mPhoneEditWidget->phoneNumbers();
  555. for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
  556. ++phoneIter )
  557. mAddressee.insertPhoneNumber( *phoneIter );
  558. // Save the addresses
  559. KABC::Address::List addresses;
  560. KABC::Address::List::ConstIterator addressIter;
  561. addresses = mAddressee.addresses();
  562. for ( addressIter = addresses.begin(); addressIter != addresses.end();
  563. ++addressIter )
  564. mAddressee.removeAddress( *addressIter );
  565. addresses = mAddressEditWidget->addresses();
  566. for ( addressIter = addresses.begin(); addressIter != addresses.end();
  567. ++addressIter )
  568. mAddressee.insertAddress( *addressIter );
  569. TQDictIterator<ContactEditorTabPage> it( mTabPages );
  570. for ( ; it.current(); ++it )
  571. it.current()->storeContact( &mAddressee );
  572. mDirty = false;
  573. }
  574. bool AddresseeEditorWidget::dirty()
  575. {
  576. return mDirty;
  577. }
  578. void AddresseeEditorWidget::nameTextChanged( const TQString &text )
  579. {
  580. // use the addressee class to parse the name for us
  581. AddresseeConfig config( mAddressee );
  582. if ( config.automaticNameParsing() ) {
  583. if ( !mAddressee.formattedName().isEmpty() ) {
  584. TQString fn = mAddressee.formattedName();
  585. mAddressee.setNameFromString( text );
  586. mAddressee.setFormattedName( fn );
  587. } else {
  588. // use extra addressee to avoid a formatted name assignment
  589. Addressee addr;
  590. addr.setNameFromString( text );
  591. mAddressee.setPrefix( addr.prefix() );
  592. mAddressee.setGivenName( addr.givenName() );
  593. mAddressee.setAdditionalName( addr.additionalName() );
  594. mAddressee.setFamilyName( addr.familyName() );
  595. mAddressee.setSuffix( addr.suffix() );
  596. }
  597. }
  598. nameBoxChanged();
  599. emitModified();
  600. }
  601. void AddresseeEditorWidget::organizationTextChanged( const TQString &text )
  602. {
  603. AddresseeConfig config( mAddressee );
  604. if ( config.automaticNameParsing() )
  605. mAddressee.setOrganization( text );
  606. nameBoxChanged();
  607. mAddressEditWidget->updateAddressee( mAddressee );
  608. emitModified();
  609. }
  610. void AddresseeEditorWidget::nameBoxChanged()
  611. {
  612. KABC::Addressee addr;
  613. AddresseeConfig config( mAddressee );
  614. if ( config.automaticNameParsing() ) {
  615. addr.setNameFromString( mNameEdit->text() );
  616. mNameLabel->hide();
  617. mNameEdit->show();
  618. } else {
  619. addr = mAddressee;
  620. mNameEdit->hide();
  621. mNameLabel->setText( mNameEdit->text() );
  622. mNameLabel->show();
  623. }
  624. if ( mFormattedNameType != NameEditDialog::CustomName ) {
  625. mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
  626. mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
  627. }
  628. mAddressEditWidget->updateAddressee( mAddressee );
  629. }
  630. void AddresseeEditorWidget::nameButtonClicked()
  631. {
  632. // show the name dialog.
  633. NameEditDialog dialog( mAddressee, mFormattedNameType, mReadOnly, this );
  634. if ( dialog.exec() ) {
  635. if ( dialog.changed() ) {
  636. mAddressee.setFamilyName( dialog.familyName() );
  637. mAddressee.setGivenName( dialog.givenName() );
  638. mAddressee.setPrefix( dialog.prefix() );
  639. mAddressee.setSuffix( dialog.suffix() );
  640. mAddressee.setAdditionalName( dialog.additionalName() );
  641. mFormattedNameType = dialog.formattedNameType();
  642. if ( mFormattedNameType == NameEditDialog::CustomName ) {
  643. mFormattedNameLabel->setText( dialog.customFormattedName() );
  644. mAddressee.setFormattedName( dialog.customFormattedName() );
  645. }
  646. // Update the name edit.
  647. bool block = mNameEdit->signalsBlocked();
  648. mNameEdit->blockSignals( true );
  649. mNameEdit->setText( mAddressee.assembledName() );
  650. mNameEdit->blockSignals( block );
  651. // Update the combo box.
  652. nameBoxChanged();
  653. emitModified();
  654. }
  655. }
  656. }
  657. void AddresseeEditorWidget::selectCategories()
  658. {
  659. // Show the category dialog
  660. if ( mCategorySelectDialog == 0 ) {
  661. mCategorySelectDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this );
  662. connect( mCategorySelectDialog, TQT_SIGNAL( categoriesSelected( const TQStringList& ) ),
  663. this, TQT_SLOT( categoriesSelected( const TQStringList& ) ) );
  664. connect( mCategorySelectDialog, TQT_SIGNAL( editCategories() ),
  665. this, TQT_SLOT( editCategories() ) );
  666. }
  667. mCategorySelectDialog->setSelected( TQStringList::split( ",", mCategoryEdit->text() ) );
  668. mCategorySelectDialog->exec();
  669. }
  670. void AddresseeEditorWidget::categoriesSelected( const TQStringList &list )
  671. {
  672. mCategoryEdit->setText( list.join( "," ) );
  673. }
  674. void AddresseeEditorWidget::editCategories()
  675. {
  676. if ( mCategoryEditDialog == 0 ) {
  677. mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this );
  678. connect( mCategoryEditDialog, TQT_SIGNAL( categoryConfigChanged() ),
  679. mCategorySelectDialog, TQT_SLOT( updateCategoryConfig() ) );
  680. }
  681. mCategoryEditDialog->exec();
  682. }
  683. void AddresseeEditorWidget::emitModified()
  684. {
  685. if ( mBlockSignals )
  686. return;
  687. mDirty = true;
  688. emit modified();
  689. }
  690. void AddresseeEditorWidget::dateChanged( const TQDate& )
  691. {
  692. emitModified();
  693. }
  694. void AddresseeEditorWidget::invalidDate()
  695. {
  696. KMessageBox::sorry( this, i18n( "You must specify a valid date" ) );
  697. }
  698. void AddresseeEditorWidget::pageChanged( TQWidget *wdg )
  699. {
  700. if ( wdg )
  701. KAcceleratorManager::manage( wdg );
  702. }
  703. void AddresseeEditorWidget::setInitialFocus()
  704. {
  705. mNameEdit->setFocus();
  706. }
  707. bool AddresseeEditorWidget::readyToClose()
  708. {
  709. bool ok = true;
  710. TQDate date = mBirthdayPicker->date();
  711. if ( !date.isValid() && !mBirthdayPicker->currentText().isEmpty() ) {
  712. KMessageBox::error( this, i18n( "You have to enter a valid birthdate." ) );
  713. ok = false;
  714. }
  715. date = mAnniversaryPicker->date();
  716. if ( !date.isValid() && !mAnniversaryPicker->currentText().isEmpty() ) {
  717. KMessageBox::error( this, i18n( "You have to enter a valid anniversary." ) );
  718. ok = false;
  719. }
  720. return ok;
  721. }
  722. void AddresseeEditorWidget::setReadOnly( bool readOnly )
  723. {
  724. mReadOnly = readOnly;
  725. mNameEdit->setReadOnly( readOnly );
  726. mRoleEdit->setReadOnly( readOnly );
  727. mOrgEdit->setReadOnly( readOnly );
  728. mPhoneEditWidget->setReadOnly( readOnly );
  729. mAddressEditWidget->setReadOnly( readOnly );
  730. mEmailWidget->setReadOnly( readOnly );
  731. mURLEdit->setReadOnly( readOnly );
  732. mBlogEdit->setReadOnly( readOnly );
  733. mIMWidget->setReadOnly( readOnly );
  734. mCategoryButton->setEnabled( !readOnly );
  735. mSecrecyWidget->setReadOnly( readOnly );
  736. mDepartmentEdit->setReadOnly( readOnly );
  737. mOfficeEdit->setReadOnly( readOnly );
  738. mProfessionEdit->setReadOnly( readOnly );
  739. mManagerEdit->setReadOnly( readOnly );
  740. mAssistantEdit->setReadOnly( readOnly );
  741. mTitleEdit->setReadOnly( readOnly );
  742. mNicknameEdit->setReadOnly( readOnly );
  743. mSpouseEdit->setReadOnly( readOnly );
  744. mBirthdayPicker->setEnabled( !readOnly );
  745. mAnniversaryPicker->setEnabled( !readOnly );
  746. mNoteEdit->setReadOnly( mReadOnly );
  747. TQDictIterator<ContactEditorTabPage> it( mTabPages );
  748. for ( ; it.current(); ++it )
  749. it.current()->setReadOnly( readOnly );
  750. }
  751. #include "addresseeeditorwidget.moc"