• 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
systemtray.cpp
Go to the documentation of this file.
1 /*
2  systemtray.cpp - Kopete Tray Dock Icon
3 
4  Copyright (c) 2002 by Nick Betcher <nbetcher@kde.org>
5  Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org>
6  Copyright (c) 2003-2004 by Olivier Goffart <ogoffart@kde.org>
7 
8  Kopete (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>
9 
10  *************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  *************************************************************************
18 */
19 
20 #include "systemtray.h"
21 
22 #include <qtimer.h>
23 
24 #include <kaboutdata.h>
25 #include <kactioncollection.h>
26 #include <kaction.h>
27 #include <kmenu.h>
28 #include <klocale.h>
29 #include <kdebug.h>
30 #include "kopetechatsessionmanager.h"
31 #include "kopetebehaviorsettings.h"
32 #include "kopetemetacontact.h"
33 #include "kopeteaccount.h"
34 #include "kopeteaccountmanager.h"
35 #include "kopetecontact.h"
36 #include "kopetewindow.h"
37 
38 KopeteSystemTray* KopeteSystemTray::s_systemTray = 0;
39 
40 KopeteSystemTray* KopeteSystemTray::systemTray( QWidget *parent )
41 {
42  if( !s_systemTray )
43  s_systemTray = new KopeteSystemTray( parent );
44 
45  return s_systemTray;
46 }
47 
48 KopeteSystemTray::KopeteSystemTray(QWidget* parent)
49  : KStatusNotifierItem(parent)
50 {
51  kDebug(14010) ;
52  setCategory(Communications);
53  setToolTip("kopete", "Kopete", KGlobal::mainComponent().aboutData()->shortDescription());
54  setStatus(Passive);
55 
56  mIsBlinkIcon = false;
57  mBlinkTimer = new QTimer(this);
58  mBlinkTimer->setObjectName("mBlinkTimer");
59 
60  mKopeteIcon = "kopete";
61 
62  connect(contextMenu(), SIGNAL(aboutToShow()), this, SLOT(slotAboutToShowMenu()));
63 
64  connect(mBlinkTimer, SIGNAL(timeout()), this, SLOT(slotBlink()));
65  connect(Kopete::ChatSessionManager::self() , SIGNAL(newEvent(Kopete::MessageEvent*)),
66  this, SLOT(slotNewEvent(Kopete::MessageEvent*)));
67  connect(Kopete::BehaviorSettings::self(), SIGNAL(configChanged()), this, SLOT(slotConfigChanged()));
68 
69  connect(Kopete::AccountManager::self(),
70  SIGNAL(accountOnlineStatusChanged(Kopete::Account *,
71  const Kopete::OnlineStatus &, const Kopete::OnlineStatus &)),
72  this, SLOT(slotReevaluateAccountStates()));
73 
74  // the slot called by default by the quit action, KSystemTray::maybeQuit(),
75  // just closes the parent window, which is hard to distinguish in that window's closeEvent()
76  // from a click on the window's close widget
77  // in the quit case, we want to quit the application
78  // in the close widget click case, we only want to hide the parent window
79  // so instead, we make it call our general purpose quit slot on the window, which causes a window close and everything else we need
80  // KDE4 - app will have to listen for quitSelected instead
81  QAction *quit = actionCollection()->action( "file_quit" );
82  quit->disconnect();
83  KopeteWindow *myParent = static_cast<KopeteWindow *>( parent );
84  connect( quit, SIGNAL(activated()), myParent, SLOT(slotQuit()) );
85 
86  setIconByName(mKopeteIcon);
87  setAttentionMovieByName( QLatin1String( "newmessage" ) );
88  slotReevaluateAccountStates();
89  slotConfigChanged();
90 }
91 
92 KopeteSystemTray::~KopeteSystemTray()
93 {
94  kDebug(14010) ;
95 // delete mBlinkTimer;
96 }
97 
98 void KopeteSystemTray::slotAboutToShowMenu()
99 {
100  emit aboutToShowMenu(qobject_cast<KMenu *>(contextMenu()));
101 }
102 
103 void KopeteSystemTray::activate(const QPoint &pos)
104 {
105  if ( isBlinking() && Kopete::BehaviorSettings::self()->trayflashNotifyLeftClickOpensMessage() )
106  {
107  if ( !mEventList.isEmpty() )
108  mEventList.first()->apply();
109  }
110  else
111  {
112  KStatusNotifierItem::activate(pos);
113  }
114 }
115 
116 // void KopeteSystemTray::contextMenuAboutToShow( KMenu *me )
117 // {
118 // //kDebug(14010) << "Called.";
119 // emit aboutToShowMenu( me );
120 // }
121 
122 
123 void KopeteSystemTray::startBlink( const QString &icon )
124 {
125  mBlinkIcon = icon;
126  if ( mBlinkTimer->isActive() )
127  {
128  mBlinkTimer->stop();
129  }
130  mIsBlinkIcon = true;
131  mBlinkTimer->setSingleShot( false );
132  mBlinkTimer->start( 1000 );
133 }
134 
135 void KopeteSystemTray::startBlink()
136 {
137  setStatus(NeedsAttention);
138 }
139 
140 void KopeteSystemTray::stopBlink()
141 {
142  setStatus(Passive);
143 
144  if ( mBlinkTimer->isActive() )
145  mBlinkTimer->stop();
146 
147  mIsBlinkIcon = false;
148  //setPixmap( mKopeteIcon );
149  slotReevaluateAccountStates();
150 }
151 
152 void KopeteSystemTray::slotBlink()
153 {
154  setIconByName( mIsBlinkIcon ? mKopeteIcon : mBlinkIcon );
155 
156  mIsBlinkIcon = !mIsBlinkIcon;
157 }
158 
159 void KopeteSystemTray::slotNewEvent( Kopete::MessageEvent *event )
160 {
161  mEventList.append( event );
162 
163  connect(event, SIGNAL(done(Kopete::MessageEvent*)),
164  this, SLOT(slotEventDone(Kopete::MessageEvent*)));
165 
166  // tray animation
167  if ( Kopete::BehaviorSettings::self()->trayflashNotify() )
168  startBlink();
169 }
170 
171 void KopeteSystemTray::slotEventDone(Kopete::MessageEvent *event)
172 {
173  mEventList.removeAll(event);
174 
175  if(mEventList.isEmpty())
176  stopBlink();
177 }
178 
179 void KopeteSystemTray::slotConfigChanged()
180 {
181 #if 0
182 // kDebug(14010) << "called.";
183  if ( Kopete::BehaviorSettings::self()->showSystemTray() )
184  show();
185  else
186  hide(); // for users without kicker or a similar docking app
187 #endif
188 }
189 
190 void KopeteSystemTray::slotReevaluateAccountStates()
191 {
192  // If there is a pending message, we don't need to refresh the system tray now.
193  // This function will even be called when the animation will stop.
194  if ( mBlinkTimer->isActive() )
195  return;
196 
197  Kopete::OnlineStatus highestStatus;
198  foreach ( Kopete::Account *account, Kopete::AccountManager::self()->accounts())
199  {
200  if ( account->myself() && account->myself()->onlineStatus() > highestStatus )
201  {
202  highestStatus = account->myself()->onlineStatus();
203  }
204  }
205 
206  switch ( highestStatus.status() )
207  {
208  case Kopete::OnlineStatus::Unknown:
209  case Kopete::OnlineStatus::Offline:
210  case Kopete::OnlineStatus::Connecting:
211  {
212  setIconByName("kopete-offline");
213  setOverlayIconByName("user-offline");
214  break;
215  }
216  case Kopete::OnlineStatus::Invisible:
217  {
218  setIconByName(mKopeteIcon);
219  setOverlayIconByName("user-invisible");
220  break;
221  }
222  case Kopete::OnlineStatus::Away:
223  {
224  setIconByName(mKopeteIcon);
225  setOverlayIconByName("user-away");
226  break;
227  }
228  case Kopete::OnlineStatus::Busy:
229  {
230  setIconByName(mKopeteIcon);
231  setOverlayIconByName("user-busy");
232  break;
233  }
234  case Kopete::OnlineStatus::Online:
235  {
236  setIconByName(mKopeteIcon);
237  setOverlayIconByName(QString());
238  break;
239  }
240  }
241 }
242 
243 
244 bool KopeteSystemTray::isBlinking() const
245 {
246  return mBlinkTimer->isActive() || (status() == NeedsAttention);
247 }
248 
249 
250 #include "systemtray.moc"
251 // vim: set noet ts=4 sts=4 sw=4:
KopeteSystemTray::startBlink
void startBlink()
Definition: systemtray.cpp:135
kopetewindow.h
QWidget
KopeteSystemTray
Definition: systemtray.h:36
KopeteSystemTray::~KopeteSystemTray
virtual ~KopeteSystemTray()
Definition: systemtray.cpp:92
KopeteSystemTray::systemTray
static KopeteSystemTray * systemTray(QWidget *parent=0)
Retrieve the system tray instance.
Definition: systemtray.cpp:40
KopeteSystemTray::aboutToShowMenu
void aboutToShowMenu(KMenu *am)
KopeteSystemTray::stopBlink
void stopBlink()
Definition: systemtray.cpp:140
KopeteSystemTray::isBlinking
bool isBlinking() const
Definition: systemtray.cpp:244
KStatusNotifierItem
KopeteWindow
Definition: kopetewindow.h:48
systemtray.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:41 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