2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
24 #include <qcheckbox.h>
28 #include <qpushbutton.h>
30 #include <qtoolbutton.h>
33 #include <kaccelmanager.h>
35 #include <kcombobox.h>
38 #include <kiconloader.h>
39 #include <klineedit.h>
41 #include <kmessagebox.h>
43 #include "imeditwidget.h"
44 #include "imeditorwidget.h"
46 IMEditWidget::IMEditWidget( QWidget
*parent
, KABC::Addressee
&addr
, const char *name
)
47 : QWidget( parent
, name
), mAddressee(addr
)
49 QGridLayout
*topLayout
= new QGridLayout( this, 2, 2, KDialog::marginHint(),
50 KDialog::spacingHint() );
52 QLabel
*label
= new QLabel( i18n( "IM address:" ), this );
53 topLayout
->addWidget( label
, 0, 0 );
55 mIMEdit
= new KLineEdit( this );
56 connect( mIMEdit
, SIGNAL( textChanged( const QString
& ) ),
57 SLOT( textChanged( const QString
& ) ) );
58 connect( mIMEdit
, SIGNAL( textChanged( const QString
& ) ),
59 SIGNAL( modified() ) );
60 label
->setBuddy( mIMEdit
);
61 topLayout
->addWidget( mIMEdit
, 0, 1 );
63 mEditButton
= new QPushButton( i18n( "Edit IM Addresses..." ), this);
64 connect( mEditButton
, SIGNAL( clicked() ), SLOT( edit() ) );
65 topLayout
->addMultiCellWidget( mEditButton
, 1, 1, 0, 1 );
67 topLayout
->activate();
70 IMEditWidget::~IMEditWidget()
74 void IMEditWidget::setReadOnly( bool readOnly
)
76 mIMEdit
->setReadOnly( readOnly
);
78 // mEditButton->setEnabled( !readOnly );
80 void IMEditWidget::setPreferredIM( const QString
&addr
)
82 bool blocked
= mIMEdit
->signalsBlocked();
83 mIMEdit
->blockSignals( true );
84 mIMEdit
->setText( addr
);
85 mIMEdit
->blockSignals( blocked
);
87 void IMEditWidget::setIMs( const QStringList
&list
)
91 bool blocked
= mIMEdit
->signalsBlocked();
92 mIMEdit
->blockSignals( true );
93 if ( list
.count() > 0 )
94 mIMEdit
->setText( list
[ 0 ] );
96 mIMEdit
->setText( "" );
97 mIMEdit
->blockSignals( blocked
);
100 QStringList
IMEditWidget::ims()
102 if ( mIMEdit
->text().isEmpty() ) {
103 if ( mIMList
.count() > 0 )
104 mIMList
.remove( mIMList
.begin() );
106 if ( mIMList
.count() > 0 )
107 mIMList
.remove( mIMList
.begin() );
109 mIMList
.prepend( mIMEdit
->text() );
114 QString
IMEditWidget::preferredIM()
116 return mIMEdit
->text();
118 void IMEditWidget::edit()
120 IMEditorWidget
dlg(this, mIMEdit
->text());
121 dlg
.loadContact(&mAddressee
);
122 dlg
.setReadOnly(mReadOnly
);
125 if ( dlg
.isModified() ) {
126 //Stores the changes into mAddressee. mAddressee isn't actually saved to the addressbook
127 //until we save the record.
128 dlg
.storeContact(&mAddressee
);
129 mIMEdit
->setText( dlg
.preferred() );
135 void IMEditWidget::textChanged( const QString
&text
)
137 if ( mIMList
.count() > 0 )
138 mIMList
.remove( mIMList
.begin() );
140 mIMList
.prepend( text
);
144 #include "imeditwidget.moc"