21 #include "ui_identitystatusbase.h"
26 #include <KActionMenu>
32 #include <KColorScheme>
33 #include <kopeteidentity.h>
34 #include <kopeteidentitymanager.h>
35 #include <kopeteaccount.h>
36 #include <kopeteaccountmanager.h>
37 #include <kopetecontact.h>
38 #include <kopeteprotocol.h>
39 #include <kopetestdaction.h>
40 #include <avatardialog.h>
42 #include <kopeteuiglobal.h>
43 #include <KCMultiDialog>
47 class IdentityStatusWidget::Private
51 Ui::IdentityStatusBase ui;
59 :
QWidget(parent), d(new Private())
65 d->timeline->setCurveShape( QTimeLine::EaseInOutCurve );
66 connect( d->timeline, SIGNAL(valueChanged(qreal)),
67 this, SLOT(slotAnimate(qreal)) );
70 d->ui.accounts->setContextMenuPolicy( Qt::CustomContextMenu );
77 this, SLOT(showAccountContextMenu(
QPoint)) );
82 connect( d->ui.photo, SIGNAL(clicked()),
83 this, SLOT(slotPhotoClicked()));
85 connect( Kopete::AccountManager::self(), SIGNAL(accountRegistered(Kopete::Account*)),
86 this, SLOT(slotAccountRegistered(Kopete::Account*)));
87 connect( Kopete::AccountManager::self(), SIGNAL(accountUnregistered(
const Kopete::Account*)),
88 this, SLOT(slotAccountUnregistered(
const Kopete::Account*)));
90 connect( Kopete::IdentityManager::self(), SIGNAL(identityUnregistered(
const Kopete::Identity*)),
91 this, SLOT(slotIdentityUnregistered(
const Kopete::Identity*)));
93 d->ui.accounts->viewport()->installEventFilter(
this );
103 if (d->identity == identity)
110 this, SLOT(slotIdentityPropertyChanged(Kopete::PropertyContainer*)) );
111 disconnect( d->identity, SIGNAL(identityChanged(Kopete::Identity*)),
112 this, SLOT(slotIdentityChanged(Kopete::Identity*)));
121 this, SLOT(slotIdentityPropertyChanged(Kopete::PropertyContainer*)) );
122 connect( d->identity, SIGNAL(identityChanged(Kopete::Identity*)),
123 this, SLOT(slotIdentityChanged(Kopete::Identity*)));
138 d->timeline->setDirection( visible ? QTimeLine::Forward
139 : QTimeLine::Backward );
140 d->timeline->start();
145 if( event->
type() == QEvent::ToolTip && watched == d->ui.accounts->viewport() )
151 const Kopete::Account * account = d->accountHash.value( item, 0 );
153 item->
setToolTip( account->myself()->toolTip() );
159 void IdentityStatusWidget::slotAnimate(qreal amount)
180 void IdentityStatusWidget::load()
183 d->ui.accounts->clear();
184 d->accountHash.clear();
189 Kopete::Global::Properties *props = Kopete::Global::Properties::self();
192 if (d->identity->hasProperty(props->photo().key()))
194 d->photoPath = d->identity->property(props->photo()).value().toString();
195 d->ui.photo->setIcon(
QIcon( d->photoPath ) );
197 d->photoPath.clear();
198 d->ui.photo->setIcon( KIcon(
"user-identity" ) );
201 d->ui.identityName->setText(d->identity->label());
203 foreach(Kopete::Account *a, d->identity->accounts()) {
206 if ( d->identity->accounts().isEmpty() ) {
207 new QListWidgetItem( KIcon(
"configure" ), i18nc(
"Button to open account configuration widget",
"Click to add an account" ), d->ui.accounts );
209 resizeAccountListWidget();
212 void IdentityStatusWidget::slotAccountRegistered( Kopete::Account *account )
214 if (account && account->identity() == d->identity && d->accountHash.isEmpty())
217 d->ui.accounts->clear();
220 addAccountItem( account );
221 resizeAccountListWidget();
224 void IdentityStatusWidget::slotAccountUnregistered(
const Kopete::Account *account )
229 while ( i.hasNext() ) {
231 Kopete::Account * candidate = i.value();
232 if ( candidate == account ) {
238 d->ui.accounts->takeItem( d->ui.accounts->row( item ) );
239 d->accountHash.remove( item );
242 if ( d->identity && d->identity->accounts().isEmpty() ) {
243 new QListWidgetItem( KIcon(
"configure" ), i18nc(
"Button to open account configuration widget",
"Click to add an account" ), d->ui.accounts );
245 resizeAccountListWidget();
248 void IdentityStatusWidget::addAccountItem( Kopete::Account *account )
253 if ( !account || ( account->identity() != d->identity ) ) {
258 SIGNAL(onlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)),
259 this, SLOT(slotAccountStatusIconChanged(Kopete::Contact*)) );
262 d->accountHash.insert( item, account );
264 slotAccountStatusIconChanged( account->myself() );
267 void IdentityStatusWidget::slotAccountStatusIconChanged( Kopete::Contact *contact )
270 Kopete::OnlineStatus status = contact->onlineStatus();
273 while ( i.hasNext() ) {
275 Kopete::Account * candidate = i.value();
276 if ( candidate == contact->account() ) {
283 item->
setIcon ( status.iconFor( contact->account() ) );
286 void IdentityStatusWidget::showAccountContextMenu(
const QPoint & point )
289 if ( item && !d->accountHash.isEmpty() ) {
290 Kopete::Account * account = d->accountHash[ item ];
294 if ( !account->hasCustomStatusMenu() )
297 account->fillActionMenu( actionMenu );
299 actionMenu->menu()->exec( d->ui.accounts->mapToGlobal( point ) );
305 void IdentityStatusWidget::slotAccountClicked(
QListWidgetItem * item )
309 if ( d->identity && d->identity->accounts().isEmpty() )
311 Q_ASSERT(d->accountHash.isEmpty());
319 void IdentityStatusWidget::slotAccountDoubleClicked(
QListWidgetItem * item )
322 if ( item && !d->accountHash.isEmpty() )
324 Kopete::Account * account = d->accountHash[ item ];
326 if ( account->myself()->onlineStatus().status() == Kopete::OnlineStatus::Offline )
328 Kopete::OnlineStatus s(Kopete::OnlineStatus::Online);
329 account->connect( s );
331 account->disconnect();
337 void IdentityStatusWidget::slotPhotoClicked()
342 bool ok, changed =
false;
343 const QString photoPath = Kopete::UI::AvatarDialog::getAvatar(
this, d->photoPath, &ok);
345 Kopete::Global::Properties *props = Kopete::Global::Properties::self();
347 d->identity->removeProperty( props->photo() );
348 d->photoPath.clear();
351 else if ( photoPath != d->photoPath ) {
352 d->identity->setProperty(props->photo(), photoPath);
353 d->photoPath = photoPath;
363 void IdentityStatusWidget::resizeAccountListWidget()
365 int frameWidth = d->ui.accounts->frameWidth();
366 int itemHeight = d->ui.accounts->sizeHintForRow( 0 );
367 int itemCount = d->ui.accounts->count();
368 d->ui.accounts->setFixedHeight( 2 * frameWidth
369 + itemHeight * ( itemCount ? itemCount : 1 ) );
375 void IdentityStatusWidget::slotIdentityUnregistered(
const Kopete::Identity* identity )
377 if ( identity == d->identity )
381 setIdentity( Kopete::IdentityManager::self()->defaultIdentity() );
385 void IdentityStatusWidget::slotIdentityPropertyChanged(Kopete::PropertyContainer *container)
387 Kopete::Identity *identity =
dynamic_cast<Kopete::Identity*
>(container);
389 slotIdentityChanged(identity);
392 void IdentityStatusWidget::slotIdentityChanged(Kopete::Identity *identity)
395 if (identity != d->identity)
401 #include "identitystatuswidget.moc"
virtual void invalidate()
void setSizeConstraint(SizeConstraint)
const QPoint & pos() const
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
static void createAccountStatusActions(Account *account, KActionMenu *parent, QAction *before=0)
insert "setStatus" actions from the given account to the specified actionMenu.
virtual bool eventFilter(QObject *watched, QEvent *event)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)