summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/ui/addressbooklinkwidget.cpp
blob: e34518b734d8edc906a8470a98a35da698c8216e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
    AddressBookLinkWidget

    A compact widget for showing and changing which address book item a
    particular Kopete::MetaContact is related to.

    Comprises a label showing the contact's name, a Clear button, and a Change
    button that usually invokes the AddressBookSelectorWidget.

    Copyright (c) 2006 by Will Stephenson <wstephenson@kde.org>

    Kopete    (c) 2002-2006 by the Kopete developers  <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * This program is free software; you can redistribute it and/or modify  *
    * it under the terms of the GNU General Public License as published by  *
    * the Free Software Foundation; either version 2 of the License, or     *
    * (at your option) any later version.                                   *
    *                                                                       *
    *************************************************************************
*/

#include <tqapplication.h>
#include <klineedit.h>
#include <klocale.h>
#include <kpushbutton.h>

#include <kiconloader.h>

#include <kopetemetacontact.h>

#include "addressbooklinkwidget.h"
#include "addressbookselectordialog.h"
#include "addressbookselectorwidget.h"

namespace Kopete {
namespace UI {


AddressBookLinkWidget::AddressBookLinkWidget( TQWidget * tqparent, const char * name ) : AddressBookLinkWidgetBase( tqparent, name ), mMetaContact( 0 )
{
	btnClear->setIconSet( SmallIconSet( TQApplication::reverseLayout() ? TQString::tqfromLatin1( "locationbar_erase" ) : TQString::tqfromLatin1( "clear_left") ) );
	connect( btnClear, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotClearAddressee() ) );
	connect( btnSelectAddressee, TQT_SIGNAL( clicked() ), TQT_SLOT( slotSelectAddressee() ) );
}

void AddressBookLinkWidget::setAddressee( const KABC::Addressee& addr )
{
	edtAddressee->setText( addr.realName() );
	btnClear->setEnabled( !addr.isEmpty() );
}

void AddressBookLinkWidget::setMetaContact( const Kopete::MetaContact * mc )
{
	mMetaContact = mc;
}

TQString AddressBookLinkWidget::uid() const
{
	return mSelectedUid;
}

void AddressBookLinkWidget::slotClearAddressee()
{
	edtAddressee->clear();
	btnClear->setEnabled( false );
	KABC::Addressee mrEmpty;
	mSelectedUid = TQString();
	emit addresseeChanged( mrEmpty );
}

void AddressBookLinkWidget::slotSelectAddressee()
{
	TQString message;
	if ( mMetaContact )
		message = i18n("Choose the corresponding entry for '%1'" ).tqarg( mMetaContact->displayName() );
 	else
		message = i18n("Choose the corresponding entry in the address book" );

	Kopete::UI::AddressBookSelectorDialog dialog( i18n("Addressbook Association"), message, ( mMetaContact ? mMetaContact->metaContactId() : TQString() ), this );
	int result = dialog.exec();

	KABC::Addressee addr;
	if ( result == TQDialog::Accepted )
	{
		addr = dialog.addressBookSelectorWidget()->addressee();

		edtAddressee->setText( addr.realName() );
		btnClear->setEnabled( !addr.isEmpty() );
		mSelectedUid = ( addr.isEmpty() ? TQString() : addr.uid() );
		emit addresseeChanged( addr );
	}
}

} // end namespace UI
} // end namespace Kopete

#include "addressbooklinkwidget.moc"