2
Copyright (c) 2005 Olivier Goffart <ogoffart@kde.org>
4
Kopete (c) 2005-2007 by the Kopete developers <kopete-devel@kde.org>
6
*************************************************************************
8
* This library is free software; you can redistribute it and/or *
9
* modify it under the terms of the GNU Lesser General Public *
10
* License as published by the Free Software Foundation; either *
11
* version 2 of the License, or (at your option) any later version. *
13
*************************************************************************
16
#include "contactaddednotifydialog.h"
20
#include <qcheckbox.h>
21
#include <qapplication.h>
24
#include <kcombobox.h>
25
#include <klineedit.h>
26
#include <kpushbutton.h>
27
#include <kiconloader.h>
29
#include <kabc/addressee.h>
31
#include "kopetegroup.h"
32
#include "kopeteaccount.h"
33
#include "kopeteuiglobal.h"
34
#include "kopeteprotocol.h"
35
#include "kopetecontactlist.h"
36
#include "kopetemetacontact.h"
37
#include "addressbooklinkwidget.h"
38
#include "addressbookselectordialog.h"
39
#include "ui_contactaddednotifywidget.h"
45
struct ContactAddedNotifyDialog::Private
47
Ui::ContactAddedNotifyWidget *widget;
50
QString addressbookId;
54
ContactAddedNotifyDialog::ContactAddedNotifyDialog(const QString& contactId,
55
const QString& contactNick, Kopete::Account *account, const HideWidgetOptions &hide)
56
: KDialog( Global::mainWidget() ), d(new Private())
58
setCaption( i18n("Someone Has Added You") );
59
setButtons( KDialog::Ok | KDialog::Cancel );
60
setAttribute( Qt::WA_DeleteOnClose );
62
d->widget=new Ui::ContactAddedNotifyWidget;
63
QWidget* w = new QWidget(this);
64
d->widget->setupUi(w);
68
d->contactId=contactId;
69
d->widget->m_label->setText(i18n("<qt><img src=\"kopete-account-icon:%1\" /> The contact <b>%2</b> has added you to his/her contact list. (Account %3)</qt>",
70
QString(QUrl::toPercentEncoding( account->protocol()->pluginId() )) + QString::fromLatin1(":")
71
+ QString(QUrl::toPercentEncoding( account->accountId() )) ,
72
contactNick.isEmpty() ? contactId : contactNick + QString::fromLatin1(" < ") + contactId + QString::fromLatin1(" >") ,
73
account->accountLabel() ) );
74
if( hide & InfoButton)
75
d->widget->m_infoButton->hide() ;
76
if( hide & AuthorizeCheckBox )
78
d->widget->m_authorizeCb->hide();
79
d->widget->m_authorizeCb->setChecked(false);
81
if( hide & AddCheckBox )
83
d->widget->m_addCb->hide();
84
d->widget->m_addCb->setChecked(false);
86
if( hide & AddGroupBox )
87
d->widget->m_contactInfoBox->hide();
89
// Populate the groups list
90
QListIterator<Group *> it(Kopete::ContactList::self()->groups());
91
while ( it.hasNext() )
94
QString groupname = g->displayName();
95
if ( g->type() == Group::Normal && !groupname.isEmpty() )
97
d->widget->m_groupList->addItem(groupname);
100
d->widget->m_groupList->setEditText(QString()); //default to top-level
102
connect( d->widget->widAddresseeLink, SIGNAL(addresseeChanged(KABC::Addressee)), this, SLOT(slotAddresseeSelected(KABC::Addressee)) );
103
connect( d->widget->m_infoButton, SIGNAL(clicked()), this, SLOT(slotInfoClicked()) );
105
connect( this, SIGNAL(okClicked()) , this , SLOT(slotFinished()));
110
ContactAddedNotifyDialog::~ContactAddedNotifyDialog()
116
bool ContactAddedNotifyDialog::added() const
118
return d->widget->m_addCb->isChecked();
121
bool ContactAddedNotifyDialog::authorized() const
123
return d->widget->m_authorizeCb->isChecked();
126
QString ContactAddedNotifyDialog::displayName() const
128
return d->widget->m_displayNameEdit->text();
131
Group *ContactAddedNotifyDialog::group() const
133
QString grpName=d->widget->m_groupList->currentText();
134
if(grpName.isEmpty())
135
return Group::topLevel();
137
return ContactList::self()->findGroup( grpName );
140
MetaContact *ContactAddedNotifyDialog::addContact() const
142
if(!added() || !d->account)
145
MetaContact *metacontact=d->account->addContact(d->contactId, displayName(), group());
149
metacontact->setKabcId(d->addressbookId);
154
void ContactAddedNotifyDialog::slotAddresseeSelected( const KABC::Addressee & addr )
156
if ( !addr.isEmpty() )
158
d->addressbookId = addr.uid();
162
void ContactAddedNotifyDialog::slotInfoClicked()
164
emit infoClicked(d->contactId);
167
void ContactAddedNotifyDialog::slotFinished()
169
emit applyClicked(d->contactId);
175
} // namespace Kopete
176
#include "contactaddednotifydialog.moc"