imeditwidget.cpp
00001 /* 00002 This file is part of KAddressBook. 00003 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of TQt, and distribute the resulting executable, 00021 without including the source code for TQt in the source distribution. 00022 */ 00023 00024 #include <tqcheckbox.h> 00025 #include <tqlabel.h> 00026 #include <tqlayout.h> 00027 #include <tqpainter.h> 00028 #include <tqpushbutton.h> 00029 #include <tqstring.h> 00030 #include <tqtoolbutton.h> 00031 #include <tqtooltip.h> 00032 00033 #include <kaccelmanager.h> 00034 #include <kconfig.h> 00035 #include <kcombobox.h> 00036 #include <kdebug.h> 00037 #include <kdialog.h> 00038 #include <kiconloader.h> 00039 #include <klineedit.h> 00040 #include <klocale.h> 00041 #include <kmessagebox.h> 00042 00043 #include "imeditwidget.h" 00044 #include "imeditorwidget.h" 00045 00046 IMEditWidget::IMEditWidget( TQWidget *parent, KABC::Addressee &addr, const char *name ) 00047 : TQWidget( parent, name ), mAddressee(addr) 00048 { 00049 TQGridLayout *topLayout = new TQGridLayout( this, 2, 2, KDialog::marginHint(), 00050 KDialog::spacingHint() ); 00051 00052 TQLabel *label = new TQLabel( i18n( "IM address:" ), this ); 00053 topLayout->addWidget( label, 0, 0 ); 00054 00055 mIMEdit = new KLineEdit( this ); 00056 connect( mIMEdit, TQT_SIGNAL( textChanged( const TQString& ) ), 00057 TQT_SLOT( textChanged( const TQString& ) ) ); 00058 connect( mIMEdit, TQT_SIGNAL( textChanged( const TQString& ) ), 00059 TQT_SIGNAL( modified() ) ); 00060 label->setBuddy( mIMEdit ); 00061 topLayout->addWidget( mIMEdit, 0, 1 ); 00062 00063 mEditButton = new TQPushButton( i18n( "Edit IM Addresses..." ), this); 00064 connect( mEditButton, TQT_SIGNAL( clicked() ), TQT_SLOT( edit() ) ); 00065 topLayout->addMultiCellWidget( mEditButton, 1, 1, 0, 1 ); 00066 00067 topLayout->activate(); 00068 } 00069 00070 IMEditWidget::~IMEditWidget() 00071 { 00072 } 00073 00074 void IMEditWidget::setReadOnly( bool readOnly ) 00075 { 00076 mIMEdit->setReadOnly( readOnly ); 00077 mReadOnly = readOnly; 00078 // mEditButton->setEnabled( !readOnly ); 00079 } 00080 void IMEditWidget::setPreferredIM( const TQString &addr ) 00081 { 00082 bool blocked = mIMEdit->signalsBlocked(); 00083 mIMEdit->blockSignals( true ); 00084 mIMEdit->setText( addr ); 00085 mIMEdit->blockSignals( blocked ); 00086 } 00087 void IMEditWidget::setIMs( const TQStringList &list ) 00088 { 00089 mIMList = list; 00090 00091 bool blocked = mIMEdit->signalsBlocked(); 00092 mIMEdit->blockSignals( true ); 00093 if ( list.count() > 0 ) 00094 mIMEdit->setText( list[ 0 ] ); 00095 else 00096 mIMEdit->setText( "" ); 00097 mIMEdit->blockSignals( blocked ); 00098 } 00099 00100 TQStringList IMEditWidget::ims() 00101 { 00102 if ( mIMEdit->text().isEmpty() ) { 00103 if ( mIMList.count() > 0 ) 00104 mIMList.remove( mIMList.begin() ); 00105 } else { 00106 if ( mIMList.count() > 0 ) 00107 mIMList.remove( mIMList.begin() ); 00108 00109 mIMList.prepend( mIMEdit->text() ); 00110 } 00111 00112 return mIMList; 00113 } 00114 TQString IMEditWidget::preferredIM() 00115 { 00116 return mIMEdit->text(); 00117 } 00118 void IMEditWidget::edit() 00119 { 00120 IMEditorWidget dlg(this, mIMEdit->text()); 00121 dlg.loadContact(&mAddressee); 00122 dlg.setReadOnly(mReadOnly); 00123 00124 if ( dlg.exec() ) { 00125 if ( dlg.isModified() ) { 00126 //Stores the changes into mAddressee. mAddressee isn't actually saved to the addressbook 00127 //until we save the record. 00128 dlg.storeContact(&mAddressee); 00129 mIMEdit->setText( dlg.preferred() ); 00130 emit modified(); 00131 } 00132 } 00133 } 00134 00135 void IMEditWidget::textChanged( const TQString &text ) 00136 { 00137 if ( mIMList.count() > 0 ) 00138 mIMList.remove( mIMList.begin() ); 00139 00140 mIMList.prepend( text ); 00141 } 00142 00143 00144 #include "imeditwidget.moc" 00145