kaddressbook

imeditwidget.cpp
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4
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
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.
14
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.
18
19 As a special exception, permission is given to link this program
20 with any edition of TQt, and distribute the resulting executable,
21 without including the source code for TQt in the source distribution.
22*/
23
24#include <tqcheckbox.h>
25#include <tqlabel.h>
26#include <tqlayout.h>
27#include <tqpainter.h>
28#include <tqpushbutton.h>
29#include <tqstring.h>
30#include <tqtoolbutton.h>
31#include <tqtooltip.h>
32
33#include <tdeaccelmanager.h>
34#include <tdeconfig.h>
35#include <kcombobox.h>
36#include <kdebug.h>
37#include <kdialog.h>
38#include <kiconloader.h>
39#include <klineedit.h>
40#include <tdelocale.h>
41#include <tdemessagebox.h>
42
43#include "imeditwidget.h"
44#include "imeditorwidget.h"
45
46IMEditWidget::IMEditWidget( TQWidget *parent, TDEABC::Addressee &addr, const char *name )
47 : TQWidget( parent, name ), mAddressee(addr)
48{
49 TQGridLayout *topLayout = new TQGridLayout( this, 2, 2, KDialog::marginHint(),
50 KDialog::spacingHint() );
51
52 TQLabel *label = new TQLabel( i18n( "IM address:" ), this );
53 topLayout->addWidget( label, 0, 0 );
54
55 mIMEdit = new KLineEdit( this );
56 connect( mIMEdit, TQ_SIGNAL( textChanged( const TQString& ) ),
57 TQ_SLOT( textChanged( const TQString& ) ) );
58 connect( mIMEdit, TQ_SIGNAL( textChanged( const TQString& ) ),
59 TQ_SIGNAL( modified() ) );
60 label->setBuddy( mIMEdit );
61 topLayout->addWidget( mIMEdit, 0, 1 );
62
63 mEditButton = new TQPushButton( i18n( "Edit IM Addresses..." ), this);
64 connect( mEditButton, TQ_SIGNAL( clicked() ), TQ_SLOT( edit() ) );
65 topLayout->addMultiCellWidget( mEditButton, 1, 1, 0, 1 );
66
67 topLayout->activate();
68}
69
70IMEditWidget::~IMEditWidget()
71{
72}
73
74void IMEditWidget::setReadOnly( bool readOnly )
75{
76 mIMEdit->setReadOnly( readOnly );
77 mReadOnly = readOnly;
78// mEditButton->setEnabled( !readOnly );
79}
80void IMEditWidget::setPreferredIM( const TQString &addr )
81{
82 bool blocked = mIMEdit->signalsBlocked();
83 mIMEdit->blockSignals( true );
84 mIMEdit->setText( addr );
85 mIMEdit->blockSignals( blocked );
86}
87void IMEditWidget::setIMs( const TQStringList &list )
88{
89 mIMList = list;
90
91 bool blocked = mIMEdit->signalsBlocked();
92 mIMEdit->blockSignals( true );
93 if ( list.count() > 0 )
94 mIMEdit->setText( list[ 0 ] );
95 else
96 mIMEdit->setText( "" );
97 mIMEdit->blockSignals( blocked );
98}
99
100TQStringList IMEditWidget::ims()
101{
102 if ( mIMEdit->text().isEmpty() ) {
103 if ( mIMList.count() > 0 )
104 mIMList.remove( mIMList.begin() );
105 } else {
106 if ( mIMList.count() > 0 )
107 mIMList.remove( mIMList.begin() );
108
109 mIMList.prepend( mIMEdit->text() );
110 }
111
112 return mIMList;
113}
114TQString IMEditWidget::preferredIM()
115{
116 return mIMEdit->text();
117}
118void IMEditWidget::edit()
119{
120 IMEditorWidget dlg(this, mIMEdit->text());
121 dlg.loadContact(&mAddressee);
122 dlg.setReadOnly(mReadOnly);
123
124 if ( dlg.exec() ) {
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() );
130 emit modified();
131 }
132 }
133}
134
135void IMEditWidget::textChanged( const TQString &text )
136{
137 if ( mIMList.count() > 0 )
138 mIMList.remove( mIMList.begin() );
139
140 mIMList.prepend( text );
141}
142
143
144#include "imeditwidget.moc"
145
The widget we add to KAddressbook's contact editor dialog.