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

korgac

  • sources
  • kde-4.12
  • kdepim
  • korgac
alarmdockwindow.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3  This file is part of the KDE reminder agent.
4 
5  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
6  Copyright (c) 2008-2009 Allen Winter <winter@kde.org>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License along
19  with this program; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 
22  As a special exception, permission is given to link this program
23  with any edition of Qt, and distribute the resulting executable,
24  without including the source code for Qt in the source distribution.
25 */
26 
27 #include "alarmdockwindow.h"
28 
29 #include <KAction>
30 #include <KActionCollection>
31 #include <KConfigGroup>
32 #include <KDebug>
33 #include <KIconEffect>
34 #include <KIconLoader>
35 #include <KLocale>
36 #include <KMessageBox>
37 #include <KMenu>
38 #include <KStandardAction>
39 #include <KToolInvocation>
40 
41 AlarmDockWindow::AlarmDockWindow()
42  : KStatusNotifierItem( 0 )
43 {
44  // Read the autostart status from the config file
45  KConfigGroup config( KGlobal::config(), "General" );
46  bool autostartSet = config.hasKey( "Autostart" );
47  bool autostart = config.readEntry( "Autostart", true );
48  bool alarmsEnabled = config.readEntry( "Enabled", true );
49 
50  mName = i18nc( "@title:window", "KOrganizer Reminder Daemon" );
51  setToolTipTitle( mName );
52  setToolTipIconByName( QLatin1String("korgac") );
53 
54  // Set up icons
55  KIconLoader::global()->addAppDir( QLatin1String("korgac") );
56  KIconLoader::global()->addAppDir( QLatin1String("kdepim") );
57  QString iconPath = KIconLoader::global()->iconPath( QLatin1String("korgac"), KIconLoader::Panel );
58  QIcon iconEnabled = QIcon( iconPath );
59  if ( iconEnabled.isNull() ) {
60  KMessageBox::sorry( associatedWidget(),
61  i18nc( "@info", "Cannot load system tray icon." ) );
62  } else {
63  KIconLoader loader;
64  QImage iconDisabled =
65  iconEnabled.pixmap( loader.currentSize( KIconLoader::Panel ) ).toImage();
66  KIconEffect::toGray( iconDisabled, 1.0 );
67  mIconDisabled = QIcon( QPixmap::fromImage( iconDisabled ) );
68  }
69 
70  changeSystrayIcon( alarmsEnabled );
71 
72  // Set up the context menu
73  mSuspendAll =
74  contextMenu()->addAction( i18nc( "@action:inmenu", "Suspend All Reminders" ), this,
75  SLOT(slotSuspendAll()) );
76  mDismissAll =
77  contextMenu()->addAction( i18nc( "@action:inmenu", "Dismiss All Reminders" ), this,
78  SLOT(slotDismissAll()) );
79  mSuspendAll->setEnabled( false );
80  mDismissAll->setEnabled( false );
81 
82  contextMenu()->addSeparator();
83  mAlarmsEnabled =
84  contextMenu()->addAction( i18nc( "@action:inmenu", "Enable Reminders" ) );
85  connect( mAlarmsEnabled, SIGNAL(toggled(bool)), SLOT(toggleAlarmsEnabled(bool)) );
86  mAlarmsEnabled->setCheckable( true );
87 
88  mAutostart =
89  contextMenu()->addAction( i18nc( "@action:inmenu", "Start Reminder Daemon at Login" ) );
90  connect( mAutostart, SIGNAL(toggled(bool)), SLOT(toggleAutostart(bool)) );
91  mAutostart->setCheckable( true );
92 
93  mAlarmsEnabled->setChecked( alarmsEnabled );
94  mAutostart->setChecked( autostart );
95 
96  // Disable standard quit behaviour. We have to intercept the quit even,
97  // if the main window is hidden.
98  KActionCollection *ac = actionCollection();
99  const char *quitName = KStandardAction::name( KStandardAction::Quit );
100  QAction *quit = ac->action( QLatin1String(quitName) );
101  if ( !quit ) {
102  kDebug() << "No Quit standard action.";
103  } else {
104  quit->disconnect( SIGNAL(triggered(bool)), this, SLOT(maybeQuit()) );
105  connect( quit, SIGNAL(activated()), SLOT(slotQuit()) );
106  }
107 
108  mAutostartSet = autostartSet;
109 }
110 
111 AlarmDockWindow::~AlarmDockWindow()
112 {
113 }
114 
115 void AlarmDockWindow::slotUpdate( int reminders )
116 {
117  bool actif = ( reminders > 0 );
118  mSuspendAll->setEnabled( actif );
119  mDismissAll->setEnabled( actif );
120  if ( actif ) {
121  setToolTip( QLatin1String("korgac"), mName, i18ncp( "@info:status",
122  "There is 1 active reminder.",
123  "There are %1 active reminders.", reminders ) );
124  } else {
125  setToolTip( QLatin1String("korgac"), mName, i18nc( "@info:status", "No active reminders." ) );
126  }
127 }
128 
129 void AlarmDockWindow::toggleAlarmsEnabled( bool checked )
130 {
131  changeSystrayIcon( checked );
132 
133  KConfigGroup config( KGlobal::config(), "General" );
134  config.writeEntry( "Enabled", checked );
135  config.sync();
136 }
137 
138 void AlarmDockWindow::toggleAutostart( bool checked )
139 {
140  kDebug();
141  mAutostartSet = true;
142  enableAutostart( checked );
143 }
144 
145 void AlarmDockWindow::slotSuspendAll()
146 {
147  emit suspendAllSignal();
148 }
149 
150 void AlarmDockWindow::slotDismissAll()
151 {
152  emit dismissAllSignal();
153 }
154 
155 void AlarmDockWindow::enableAutostart( bool enable )
156 {
157  KConfigGroup config( KGlobal::config(), "General" );
158  config.writeEntry( "Autostart", enable );
159  config.sync();
160 }
161 
162 void AlarmDockWindow::activate( const QPoint &pos )
163 {
164  Q_UNUSED( pos );
165  KToolInvocation::startServiceByDesktopName( QLatin1String("korganizer"), QString() );
166 }
167 
168 void AlarmDockWindow::slotQuit()
169 {
170  if ( mAutostartSet == true ) {
171  int result = KMessageBox::warningContinueCancel(
172  associatedWidget(),
173  i18nc( "@info",
174  "Do you want to quit the KOrganizer reminder daemon?<nl/>"
175  "<note> you will not get calendar reminders unless the daemon is running.</note>" ),
176  i18nc( "@title:window", "Close KOrganizer Reminder Daemon" ),
177  KStandardGuiItem::quit() );
178 
179  if ( result == KMessageBox::Continue ) {
180  emit quitSignal();
181  }
182  } else {
183  int result = KMessageBox::questionYesNoCancel(
184  associatedWidget(),
185  i18nc( "@info",
186  "Do you want to start the KOrganizer reminder daemon at login?<nl/>"
187  "<note> you will not get calendar reminders unless the daemon is running.</note>" ),
188  i18nc( "@title:window", "Close KOrganizer Reminder Daemon" ),
189  KGuiItem( i18nc( "@action:button start the reminder daemon", "Start" ) ),
190  KGuiItem( i18nc( "@action:button do not start the reminder daemon", "Do Not Start" ) ),
191  KStandardGuiItem::cancel(),
192  QString::fromLatin1( "AskForStartAtLogin" ) );
193 
194  bool autostart = true;
195  if ( result == KMessageBox::No ) {
196  autostart = false;
197  }
198  enableAutostart( autostart );
199 
200  if ( result != KMessageBox::Cancel ) {
201  emit quitSignal();
202  }
203  }
204 }
205 
206 void AlarmDockWindow::changeSystrayIcon( bool alarmsEnabled )
207 {
208  if ( alarmsEnabled ) {
209  setIconByName( QLatin1String("korgac") );
210  } else {
211  setIconByPixmap( mIconDisabled.pixmap( 22, 22 ) );
212  }
213 }
214 
215 #include "alarmdockwindow.moc"
AlarmDockWindow::slotSuspendAll
void slotSuspendAll()
Definition: alarmdockwindow.cpp:145
AlarmDockWindow::quitSignal
void quitSignal()
alarmdockwindow.h
AlarmDockWindow::activate
virtual void activate(const QPoint &pos)
Definition: alarmdockwindow.cpp:162
AlarmDockWindow::slotUpdate
void slotUpdate(int reminders)
Definition: alarmdockwindow.cpp:115
AlarmDockWindow::enableAutostart
void enableAutostart(bool enabled)
Definition: alarmdockwindow.cpp:155
AlarmDockWindow::AlarmDockWindow
AlarmDockWindow()
Definition: alarmdockwindow.cpp:41
AlarmDockWindow::toggleAutostart
void toggleAutostart(bool checked)
Definition: alarmdockwindow.cpp:138
AlarmDockWindow::suspendAllSignal
void suspendAllSignal()
AlarmDockWindow::slotQuit
void slotQuit()
Definition: alarmdockwindow.cpp:168
AlarmDockWindow::slotDismissAll
void slotDismissAll()
Definition: alarmdockwindow.cpp:150
KStatusNotifierItem
AlarmDockWindow::toggleAlarmsEnabled
void toggleAlarmsEnabled(bool checked)
Definition: alarmdockwindow.cpp:129
AlarmDockWindow::dismissAllSignal
void dismissAllSignal()
AlarmDockWindow::~AlarmDockWindow
virtual ~AlarmDockWindow()
Definition: alarmdockwindow.cpp:111
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korgac

Skip menu "korgac"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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