24 #include <kaboutdata.h>
25 #include <kactioncollection.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"
48 KopeteSystemTray::KopeteSystemTray(
QWidget* parent)
52 setCategory(Communications);
53 setToolTip(
"kopete",
"Kopete", KGlobal::mainComponent().aboutData()->shortDescription());
57 mBlinkTimer =
new QTimer(
this);
60 mKopeteIcon =
"kopete";
62 connect(contextMenu(), SIGNAL(aboutToShow()),
this, SLOT(slotAboutToShowMenu()));
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()));
69 connect(Kopete::AccountManager::self(),
70 SIGNAL(accountOnlineStatusChanged(Kopete::Account *,
71 const Kopete::OnlineStatus &,
const Kopete::OnlineStatus &)),
72 this, SLOT(slotReevaluateAccountStates()));
81 QAction *quit = actionCollection()->action(
"file_quit" );
84 connect( quit, SIGNAL(activated()), myParent, SLOT(slotQuit()) );
86 setIconByName(mKopeteIcon);
88 slotReevaluateAccountStates();
98 void KopeteSystemTray::slotAboutToShowMenu()
103 void KopeteSystemTray::activate(
const QPoint &pos)
105 if (
isBlinking() && Kopete::BehaviorSettings::self()->trayflashNotifyLeftClickOpensMessage() )
108 mEventList.
first()->apply();
112 KStatusNotifierItem::activate(pos);
132 mBlinkTimer->
start( 1000 );
137 setStatus(NeedsAttention);
147 mIsBlinkIcon =
false;
149 slotReevaluateAccountStates();
152 void KopeteSystemTray::slotBlink()
154 setIconByName( mIsBlinkIcon ? mKopeteIcon : mBlinkIcon );
156 mIsBlinkIcon = !mIsBlinkIcon;
159 void KopeteSystemTray::slotNewEvent( Kopete::MessageEvent *event )
161 mEventList.
append( event );
163 connect(event, SIGNAL(done(Kopete::MessageEvent*)),
164 this, SLOT(slotEventDone(Kopete::MessageEvent*)));
167 if ( Kopete::BehaviorSettings::self()->trayflashNotify() )
171 void KopeteSystemTray::slotEventDone(Kopete::MessageEvent *event)
179 void KopeteSystemTray::slotConfigChanged()
183 if ( Kopete::BehaviorSettings::self()->showSystemTray() )
190 void KopeteSystemTray::slotReevaluateAccountStates()
197 Kopete::OnlineStatus highestStatus;
198 foreach ( Kopete::Account *account, Kopete::AccountManager::self()->accounts())
200 if ( account->myself() && account->myself()->onlineStatus() > highestStatus )
202 highestStatus = account->myself()->onlineStatus();
206 switch ( highestStatus.status() )
208 case Kopete::OnlineStatus::Unknown:
209 case Kopete::OnlineStatus::Offline:
210 case Kopete::OnlineStatus::Connecting:
212 setIconByName(
"kopete-offline");
213 setOverlayIconByName(
"user-offline");
216 case Kopete::OnlineStatus::Invisible:
218 setIconByName(mKopeteIcon);
219 setOverlayIconByName(
"user-invisible");
222 case Kopete::OnlineStatus::Away:
224 setIconByName(mKopeteIcon);
225 setOverlayIconByName(
"user-away");
228 case Kopete::OnlineStatus::Busy:
230 setIconByName(mKopeteIcon);
231 setOverlayIconByName(
"user-busy");
234 case Kopete::OnlineStatus::Online:
236 setIconByName(mKopeteIcon);
237 setOverlayIconByName(
QString());
246 return mBlinkTimer->
isActive() || (status() == NeedsAttention);
250 #include "systemtray.moc"
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
void append(const T &value)
void setObjectName(const QString &name)
int removeAll(const T &value)
virtual ~KopeteSystemTray()
static KopeteSystemTray * systemTray(QWidget *parent=0)
Retrieve the system tray instance.
void aboutToShowMenu(KMenu *am)
void setSingleShot(bool singleShot)