• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/kopete

  • sources
  • kde-4.12
  • kdenetwork
  • kopete
  • kopete
infoeventwidget.cpp
Go to the documentation of this file.
1 /*
2  infoeventwidget.cpp - Info Event Widget
3 
4  Copyright (c) 2008 by Roman Jarosz <kedgedev@centrum.cz>
5  Kopete (c) 2008 by the Kopete developers <kopete-devel@kde.org>
6 
7  *************************************************************************
8  * *
9  * This library is free software; you can redistribute it and/or *
10  * modify it under the terms of the GNU Lesser General Public *
11  * License as published by the Free Software Foundation; either *
12  * version 2 of the License, or (at your option) any later version. *
13  * *
14  *************************************************************************
15 */
16 #include "infoeventwidget.h"
17 #include "ui_infoeventbase.h"
18 
19 #include <QPointer>
20 #include <QHash>
21 #include <QTimeLine>
22 #include <QLayout>
23 #include <QTextDocument>
24 
25 #include <knotification.h>
26 
27 #include <kopeteinfoeventmanager.h>
28 #include <kopeteinfoevent.h>
29 #include <kopetestatusmanager.h>
30 #include <kopeteonlinestatusmanager.h>
31 
32 class InfoEventWidget::Private
33 {
34 public:
35  QPointer<Kopete::InfoEvent> currentEvent;
36  int currentEventIndex;
37  QTimeLine *timeline;
38  Ui::InfoEventBase ui;
39  bool enableUpdates;
40  QHash<KNotification*, QPointer<Kopete::InfoEvent> > notifyEventHash;
41 };
42 
43 InfoEventWidget::InfoEventWidget(QWidget *parent)
44 : QWidget(parent), d( new Private() )
45 {
46  d->timeline = new QTimeLine( 150, this );
47  d->timeline->setCurveShape( QTimeLine::EaseInOutCurve );
48  connect( d->timeline, SIGNAL(valueChanged(qreal)),
49  this, SLOT(slotAnimate(qreal)) );
50 
51  d->ui.setupUi(this);
52  static_cast<KSqueezedTextLabel*>(d->ui.lblTitle)->setTextElideMode( Qt::ElideRight );
53  d->ui.buttonPrev->setIcon( KIcon( "arrow-left" ) );
54  d->ui.buttonNext->setIcon( KIcon( "arrow-right" ) );
55  d->ui.buttonClose->setIcon( KIcon( "window-close" ) );
56  d->ui.lblInfo->setTextInteractionFlags(Qt::TextSelectableByMouse);
57  QWidget::setVisible( false );
58 
59  d->currentEventIndex = 0;
60  d->enableUpdates = false;
61  connect( Kopete::InfoEventManager::self(), SIGNAL(changed()), this, SLOT(updateInfo()) );
62  connect( Kopete::InfoEventManager::self(), SIGNAL(eventAdded(Kopete::InfoEvent*)), this, SLOT(eventAdded(Kopete::InfoEvent*)) );
63  connect( d->ui.lblActions, SIGNAL(linkActivated(QString)), this, SLOT(linkClicked(QString)) );
64  connect( d->ui.buttonPrev, SIGNAL(clicked(bool)), this, SLOT(prevInfoEvent()) );
65  connect( d->ui.buttonNext, SIGNAL(clicked(bool)), this, SLOT(nextInfoEvent()) );
66  connect( d->ui.buttonClose, SIGNAL(clicked(bool)), this, SLOT(closeInfoEvent()) );
67 }
68 
69 
70 InfoEventWidget::~InfoEventWidget()
71 {
72  delete d;
73 }
74 
75 void InfoEventWidget::setVisible( bool visible )
76 {
77  if ( visible == isVisible() )
78  return;
79 
80  d->enableUpdates = visible;
81  if ( visible )
82  updateInfo();
83 
84  // animate the widget disappearing
85  d->timeline->setDirection( visible ? QTimeLine::Forward
86  : QTimeLine::Backward );
87  d->timeline->start();
88 }
89 
90 void InfoEventWidget::prevInfoEvent()
91 {
92  if ( d->currentEventIndex > 0 )
93  {
94  d->currentEventIndex--;
95  updateInfo();
96  }
97 }
98 
99 void InfoEventWidget::nextInfoEvent()
100 {
101  if ( d->currentEventIndex + 1 < Kopete::InfoEventManager::self()->eventCount() )
102  {
103  d->currentEventIndex++;
104  updateInfo();
105  }
106 }
107 
108 void InfoEventWidget::closeInfoEvent()
109 {
110  Kopete::InfoEventManager* ie = Kopete::InfoEventManager::self();
111  if ( ie->eventCount() > 0 )
112  {
113  Kopete::InfoEvent* event = ie->event( d->currentEventIndex );
114 
115  Q_ASSERT( event );
116  event->close();
117  }
118 
119  if ( ie->eventCount() == 0 )
120  setVisible( false );
121 }
122 
123 void InfoEventWidget::slotAnimate( qreal amount )
124 {
125  if ( amount == 0 )
126  {
127  QWidget::setVisible( false );
128  return;
129  }
130 
131  if ( amount == 1.0 )
132  {
133  layout()->setSizeConstraint( QLayout::SetDefaultConstraint );
134  setFixedHeight( sizeHintHeight() );
135  return;
136  }
137 
138  setFixedHeight( sizeHintHeight() * amount );
139 
140  if ( !isVisible() )
141  QWidget::setVisible( true );
142 }
143 
144 void InfoEventWidget::linkClicked( const QString& link )
145 {
146  Kopete::InfoEvent* event = Kopete::InfoEventManager::self()->event( d->currentEventIndex );
147  Q_ASSERT( event );
148 
149  event->activate( link.toInt() );
150 }
151 
152 void InfoEventWidget::updateInfo()
153 {
154  if ( !d->enableUpdates )
155  return;
156 
157  Kopete::InfoEventManager* ie = Kopete::InfoEventManager::self();
158 
159  if ( ie->eventCount() == 0 )
160  {
161  d->currentEventIndex = 0;
162  d->ui.lblInfo->clear();
163  d->ui.lblActions->clear();
164  // Can't use clear
165  static_cast<KSqueezedTextLabel*>(d->ui.lblTitle)->setText(QString());
166  d->ui.lblEvent->setText( "0/0" );
167  d->ui.buttonPrev->setEnabled( false );
168  d->ui.buttonNext->setEnabled( false );
169  return;
170  }
171 
172  if ( d->currentEventIndex >= ie->eventCount() )
173  d->currentEventIndex = ie->eventCount() - 1;
174 
175  d->ui.buttonPrev->setEnabled( (d->currentEventIndex > 0) );
176  d->ui.buttonNext->setEnabled( (d->currentEventIndex + 1 < ie->eventCount()) );
177 
178  Kopete::InfoEvent* event = ie->event( d->currentEventIndex );
179  Q_ASSERT( event );
180 
181  if ( d->currentEvent != event )
182  {
183  if ( !d->currentEvent )
184  disconnect( d->currentEvent, SIGNAL(changed()), this , SLOT(updateInfo()) );
185 
186  d->currentEvent = event;
187  connect( d->currentEvent, SIGNAL(changed()), this , SLOT(updateInfo()) );
188  }
189 
190  static_cast<KSqueezedTextLabel*>(d->ui.lblTitle)->setText( Qt::escape( event->title() ) );
191  d->ui.lblEvent->setText( QString("%1/%2").arg( d->currentEventIndex + 1 ).arg( ie->eventCount() ) );
192 
193  d->ui.lblInfo->setVisible( !event->text().isEmpty() );
194  if ( !event->text().isEmpty() )
195  {
196  QString text = QString( "<p>%1</p>" ).arg( event->text() );
197  if ( !event->additionalText().isEmpty() )
198  text += QString( "<p>%1</p>" ).arg( event->additionalText() );
199 
200  d->ui.lblInfo->setText( text );
201  }
202  else
203  {
204  d->ui.lblInfo->clear();
205  }
206 
207  d->ui.lblActions->setVisible( !event->actions().isEmpty() );
208  if ( !event->actions().isEmpty() )
209  {
210  QString linkCode = QString::fromLatin1( "<p align=\"right\">" );
211 
212  QMap<uint, QString> actions = event->actions();
213  QMapIterator<uint, QString> it(actions);
214  while ( it.hasNext() )
215  {
216  it.next();
217  linkCode += QString::fromLatin1( "<a href=\"%1\">%2</a> " ).arg( it.key() ).arg( Qt::escape(it.value()) );
218  }
219 
220  d->ui.lblActions->setText( linkCode );
221  }
222 
223  // Redo the layout otherwise sizeHint() won't be correct.
224  layout()->activate();
225  if ( sizeHintHeight() > height() )
226  setFixedHeight( sizeHintHeight() );
227 }
228 
229 void InfoEventWidget::eventAdded( Kopete::InfoEvent* event )
230 {
231  if ( Kopete::StatusManager::self()->globalStatusCategory() != Kopete::OnlineStatusManager::Busy )
232  {
233  KNotification *notify = new KNotification( QString("kopete_info_event") , 0l );
234  notify->setActions( QStringList( i18n( "View" ) ) );
235  notify->setText( event->text() );
236 
237  d->notifyEventHash.insert( notify, event );
238 
239  connect( notify, SIGNAL(activated(uint)), this, SLOT(notificationActivated()) );
240  connect( notify, SIGNAL(closed()), this, SLOT(notificationClosed()) );
241 
242  notify->sendEvent();
243  }
244 
245  if ( event->showOnSend() )
246  {
247  int index = Kopete::InfoEventManager::self()->events().indexOf( event );
248  if ( index != -1 )
249  {
250  d->currentEventIndex = index;
251  updateInfo();
252  }
253  emit showRequest();
254  }
255 }
256 
257 void InfoEventWidget::notificationActivated()
258 {
259  KNotification *notify = dynamic_cast<KNotification *>(sender());
260 
261  Kopete::InfoEvent* event = d->notifyEventHash.value( notify, 0 );
262  if ( !event )
263  return;
264 
265  int index = Kopete::InfoEventManager::self()->events().indexOf( event );
266  if ( index != -1 )
267  {
268  d->currentEventIndex = index;
269  updateInfo();
270  }
271  emit showRequest();
272 }
273 
274 void InfoEventWidget::notificationClosed()
275 {
276  KNotification *notify = dynamic_cast<KNotification *>(sender());
277  d->notifyEventHash.remove( notify );
278 }
279 
280 int InfoEventWidget::sizeHintHeight() const
281 {
282  return qMin( sizeHint().height(), 250 );
283 }
284 
285 #include "infoeventwidget.moc"
InfoEventWidget::prevInfoEvent
void prevInfoEvent()
Show previous info event from info event list.
Definition: infoeventwidget.cpp:90
InfoEventWidget::InfoEventWidget
InfoEventWidget(QWidget *parent=0)
Info event widget constructor.
Definition: infoeventwidget.cpp:43
QWidget
infoeventwidget.h
InfoEventWidget::~InfoEventWidget
~InfoEventWidget()
Definition: infoeventwidget.cpp:70
InfoEventWidget::closeInfoEvent
void closeInfoEvent()
Close current info event from info event list.
Definition: infoeventwidget.cpp:108
InfoEventWidget::showRequest
void showRequest()
InfoEventWidget::nextInfoEvent
void nextInfoEvent()
Show next info event from info event list.
Definition: infoeventwidget.cpp:99
InfoEventWidget::setVisible
virtual void setVisible(bool visible)
Definition: infoeventwidget.cpp:75
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

Skip menu "kopete/kopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal