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( const KABC::Addressee
& ) ), this, SLOT( slotAddresseeSelected( const KABC::Addressee
& ) ) );
103 connect( d
->widget
->m_infoButton
, SIGNAL( clicked() ), this, SLOT( slotInfoClicked() ) );
105 connect( this, SIGNAL(okClicked()) , this , SLOT(slotFinished()));
110 ContactAddedNotifyDialog::~ContactAddedNotifyDialog()
112 // deleting the widget is not needed because it has a parent
113 // which takes care of them
118 bool ContactAddedNotifyDialog::added() const
120 return d
->widget
->m_addCb
->isChecked();
123 bool ContactAddedNotifyDialog::authorized() const
125 return d
->widget
->m_authorizeCb
->isChecked();
128 QString
ContactAddedNotifyDialog::displayName() const
130 return d
->widget
->m_displayNameEdit
->text();
133 Group
*ContactAddedNotifyDialog::group() const
135 QString grpName
=d
->widget
->m_groupList
->currentText();
136 if(grpName
.isEmpty())
137 return Group::topLevel();
139 return ContactList::self()->findGroup( grpName
);
142 MetaContact
*ContactAddedNotifyDialog::addContact() const
144 if(!added() || !d
->account
)
147 MetaContact
*metacontact
=d
->account
->addContact(d
->contactId
, displayName(), group());
151 metacontact
->setMetaContactId(d
->addressbookId
);
156 void ContactAddedNotifyDialog::slotAddresseeSelected( const KABC::Addressee
& addr
)
158 if ( !addr
.isEmpty() )
160 d
->addressbookId
= addr
.uid();
164 void ContactAddedNotifyDialog::slotInfoClicked()
166 emit
infoClicked(d
->contactId
);
169 void ContactAddedNotifyDialog::slotFinished()
171 emit
applyClicked(d
->contactId
);
177 } // namespace Kopete
178 #include "contactaddednotifydialog.moc"