kaddressbook

imaddresswidget.cpp
1/*
2 IM address editor widget for KAddressbook
3
4 Copyright (c) 2004 Will Stephenson <lists@stevello.free-online.co.uk>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24#include <tqcheckbox.h>
25#include <tqcombobox.h>
26#include <tqlineedit.h>
27#include <tqlabel.h>
28
29#include <kdebug.h>
30#include <kiconloader.h>
31#include <tdelocale.h>
32#include <kplugininfo.h>
33
34#include "imaddresswidget.h"
35
36IMAddressWidget::IMAddressWidget( TQWidget *parent, TQValueList<KPluginInfo *> protocols )
37 : IMAddressBase( parent )
38{
39 mProtocols = protocols;
40 populateProtocols();
41 init();
42}
43
44IMAddressWidget::IMAddressWidget( TQWidget *parent, TQValueList<KPluginInfo *> protocols,
45 KPluginInfo *protocol, const TQString& address,
46 const IMContext& context )
47 : IMAddressBase( parent )
48{
49 Q_UNUSED( context );
50
51 mProtocols = protocols;
52 populateProtocols();
53 cmbProtocol->setCurrentItem( mProtocols.findIndex( protocol ) );
54
55 edtAddress->setText( address.section( TQChar( 0xE120 ), 0, 0 ) );
56 edtNetwork->setText( address.section( TQChar( 0xE120 ), 1 ) );
57
58 init();
59}
60
61void IMAddressWidget::init()
62{
63 connect( cmbProtocol, TQ_SIGNAL( activated( const TQString& ) ),
64 this, TQ_SLOT( slotProtocolChanged() ) );
65 connect( edtAddress, TQ_SIGNAL( textChanged( const TQString& ) ),
66 this, TQ_SLOT( slotAddressChanged( const TQString& ) ) );
67
68 slotProtocolChanged();
69}
70
71void IMAddressWidget::slotAddressChanged( const TQString &text )
72{
73 emit inValidState( !text.stripWhiteSpace().isEmpty() );
74}
75
76KPluginInfo * IMAddressWidget::protocol() const
77{
78 int protocolIndex = cmbProtocol->currentItem();
79
80 return mProtocols[ protocolIndex ];
81}
82
83IMContext IMAddressWidget::context() const
84{
85 IMContext context = Any;
86/* if ( cmbContext->currentItem() )
87 {
88
89 int contextIndex = cmbContext->currentItem();
90 switch ( contextIndex )
91 {
92 case 0:
93 context = Any;
94 break;
95 case 1:
96 context = Home;
97 break;
98 case 2:
99 context = Work;
100 break;
101 }
102 }
103 */
104
105 return context;
106}
107
108TQString IMAddressWidget::address() const
109{
110 // The protocol irc is a special case and hard coded in.
111 // It's not nice, but the simplest way that I can see.
112 if ( protocol()->name() == "IRC" && !edtNetwork->text().stripWhiteSpace().isEmpty() )
113 return edtAddress->text().stripWhiteSpace() + TQChar( 0xE120 ) + edtNetwork->text().stripWhiteSpace();
114 else
115 return edtAddress->text().stripWhiteSpace();
116}
117
119{
120 // insert the protocols in order
121 TQValueList<KPluginInfo *>::ConstIterator it;
122 for ( it = mProtocols.begin(); it != mProtocols.end(); ++it )
123 cmbProtocol->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() );
124}
125
126void IMAddressWidget::slotProtocolChanged()
127{
128 if ( protocol()->name() == "IRC" ) {
129 edtNetwork->show();
130 labelNetwork->show();
131 } else {
132 edtNetwork->hide();
133 labelNetwork->hide();
134 }
135}
136
137#include "imaddresswidget.moc"
void populateProtocols()
Populate combobox with protocols.