Icon fixes.
[rsibreak.git] / src / rsidock.cpp
blobdcbe1926a35cf1a59d05fe3a26fb16bd2c802340
1 /* This file is part of the KDE project
2 Copyright (C) 2005-2006 Tom Albers <tomalbers@kde.nl>
4 Orginal copied from ksynaptics:
5 Copyright (C) 2004 Nadeem Hasan <nhasan@kde.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "rsidock.h"
23 #include "setup.h"
24 #include "rsistatwidget.h"
25 #include "rsistats.h"
27 #include <QMenu>
28 #include <QSystemTrayIcon>
30 #include <KComponentData>
31 #include <KLocale>
32 #include <KNotifyConfigWidget>
33 #include <KIconLoader>
34 #include <KHelpMenu>
35 #include <KGlobalAccel>
36 #include <KStandardShortcut>
37 #include <KSystemTrayIcon>
38 #include <KMessageBox>
39 #include <KWindowSystem>
41 RSIDock::RSIDock( QWidget *parent )
42 : QSystemTrayIcon( parent ), m_suspended( false )
43 , m_statsDialog( 0 ), m_statsWidget( 0 )
45 m_help = new KHelpMenu( parent, KGlobal::mainComponent().aboutData() );
47 QMenu* menu = new QMenu( parent );
48 menu->addAction( KIcon( "kde" ), i18n( "About &KDE" ), m_help,
49 SLOT( aboutKDE() ) );
50 menu->addAction( i18n( "&About RSIBreak" ), m_help,
51 SLOT( aboutApplication() ) );
52 menu->addAction( KIcon( "help-contents" ),
53 i18n( "RSIBreak &Handbook" ), m_help, SLOT( appHelpActivated() ),
54 KStandardShortcut::shortcut( KStandardShortcut::Help ).primary() );
56 menu->addSeparator();
57 menu->addAction( KIcon( "tools-report-bug" ), i18n( "&Report Bug..." ), m_help, SLOT( reportBug() ) );
58 menu->addAction( i18n( "Switch application &language..." ), m_help,
59 SLOT( switchApplicationLanguage() ) );
61 menu->addSeparator();
62 m_suspendItem = menu->addAction( SmallIcon( "media-playback-pause" ),
63 i18n( "&Suspend RSIBreak" ), this,
64 SLOT( slotSuspend() ) );
65 menu->addAction( SmallIcon( "view-statistics" ),
66 i18n( "&Usage Statistics" ), this,
67 SLOT( slotShowStatistics() ) );
68 menu->addAction( SmallIcon( "preferences-desktop-notification" ),
69 i18n( "Configure &Notifications..." ), this,
70 SLOT( slotConfigureNotifications() ) );
71 menu->addAction( KIcon( "configure" ), i18n( "&Configure RSIBreak..." ),
72 this, SLOT( slotConfigure() ) );
74 menu->addSeparator();
75 menu->addAction( KIcon( "application-exit" ), i18n( "Quit" ), this, SLOT( slotQuit() ),
76 KStandardShortcut::shortcut( KStandardShortcut::Quit ).primary() );
79 setContextMenu( menu );
81 connect( this, SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ),
82 SLOT( slotActivated( QSystemTrayIcon::ActivationReason ) ) );
85 RSIDock::~RSIDock()
87 delete m_statsWidget;
88 delete m_statsDialog;
89 m_statsWidget = 0;
92 void RSIDock::slotActivated( QSystemTrayIcon::ActivationReason reason )
94 if ( reason == QSystemTrayIcon::Trigger )
95 slotShowStatistics();
98 void RSIDock::slotConfigureNotifications()
100 KNotifyConfigWidget::configure( 0 );
103 void RSIDock::slotConfigure()
105 Setup setup( 0 );
106 emit dialogEntered();
107 if ( setup.exec() == QDialog::Accepted )
108 emit configChanged( !m_suspended );
110 if ( !m_suspended )
111 emit dialogLeft();
114 void RSIDock::slotBreakRequest()
116 emit breakRequest();
119 void RSIDock::slotDebugRequest()
121 emit debugRequest();
124 void RSIDock::slotSuspend()
126 if ( m_suspended ) {
127 emit suspend( false );
129 setIcon( KSystemTrayIcon::loadIcon( "rsibreak0" ) );
130 m_suspendItem->setIcon( SmallIcon( "media-playback-pause" ) );
131 m_suspendItem->setText( i18n( "&Suspend RSIBreak" ) );
132 } else {
133 emit suspend( true );
135 setIcon( KSystemTrayIcon::loadIcon( "rsibreakx" ) );
136 m_suspendItem->setIcon( SmallIcon( "media-playback-start" ) );
137 m_suspendItem->setText( i18n( "&Resume RSIBreak" ) );
140 m_suspended = !m_suspended;
143 void RSIDock::mousePressEvent( QMouseEvent *e )
145 if ( e->button() == Qt::RightButton )
146 contextMenu()->exec( e->globalPos() );
148 if ( e->button() == Qt::LeftButton )
149 slotShowStatistics();
152 bool RSIDock::event( QEvent * event )
154 if ( event->type() == QEvent::ToolTip ) {
155 emit showToolTip();
156 return true;
158 return false;
161 void RSIDock::slotShowStatistics()
163 if ( !m_statsDialog ) {
164 m_statsDialog = new KDialog( 0 );
165 m_statsDialog->setCaption( i18n( "Usage Statistics" ) );
166 m_statsDialog->setButtons( KDialog::Ok | KDialog::User1 );
167 m_statsDialog->setButtonText( KDialog::User1, i18n( "Reset" ) );
169 m_statsWidget = new RSIStatWidget( m_statsDialog );
170 connect( m_statsDialog, SIGNAL( user1Clicked() ),
171 this, SLOT( slotResetStats() ) );
173 m_statsDialog->setMainWidget( m_statsWidget );
176 if ( m_statsDialog->isVisible() &&
177 KWindowSystem::windowInfo(
178 m_statsDialog->winId(), NET::CurrentDesktop ).desktop() ==
179 KWindowSystem::currentDesktop() ) {
180 m_statsDialog->hide();
181 } else {
182 m_statsDialog->show();
184 if ( !m_statsDialog->isActiveWindow() )
185 KWindowSystem::forceActiveWindow( m_statsDialog->winId() );
187 m_statsDialog->raise();
191 void RSIDock::slotResetStats()
193 int i = KMessageBox::warningContinueCancel( 0,
194 i18n( "This will reset all statistics to zero. "
195 "Is that what you want?" ),
196 i18n( "Reset the statistics" ),
197 KGuiItem( "Reset" ),
198 KStandardGuiItem::cancel(),
199 "resetStatistics" );
201 if ( i == KMessageBox::Continue )
202 RSIGlobals::instance()->stats()->reset();
205 void RSIDock::slotQuit()
207 exit( 0 );
210 #include "rsidock.moc"