25 #include "alarmdockwindow.h"
26 #include "koalarmclient.h"
28 #include <tdeapplication.h>
30 #include <tdeversion.h>
31 #include <tdelocale.h>
32 #include <kiconloader.h>
33 #include <tdeconfig.h>
35 #include <kstandarddirs.h>
36 #include <dcopclient.h>
37 #include <tdepopupmenu.h>
38 #include <tdemessagebox.h>
39 #include <tdeaction.h>
40 #include <kstdaction.h>
42 #include <tqtooltip.h>
47 AlarmDockWindow::AlarmDockWindow(
const char *name )
48 : KSystemTray( 0, name )
51 TDEConfig *config = kapp->config();
52 config->setGroup(
"General");
53 bool autostart = config->readBoolEntry(
"Autostart",
true );
54 bool alarmsEnabled = config->readBoolEntry(
"Enabled",
true );
56 mName = i18n(
"KOrganizer Reminder Daemon" );
60 TDEGlobal::iconLoader()->addAppDir(
"korgac" );
61 mPixmapEnabled = loadIcon(
"korgac" );
62 mPixmapDisabled = loadIcon(
"korgac_disabled" );
64 setPixmap( alarmsEnabled ? mPixmapEnabled : mPixmapDisabled );
67 mSuspendAll = contextMenu()->insertItem( i18n(
"Suspend All"),
this, TQ_SLOT( slotSuspendAll() ) );
68 mDismissAll = contextMenu()->insertItem( i18n(
"Dismiss All"),
this, TQ_SLOT( slotDismissAll() ) );
69 contextMenu()->setItemEnabled( mSuspendAll,
false );
70 contextMenu()->setItemEnabled( mDismissAll,
false );
72 contextMenu()->insertSeparator();
73 mAlarmsEnabledId = contextMenu()->insertItem( i18n(
"Reminders Enabled"),
this,
74 TQ_SLOT( toggleAlarmsEnabled() ) );
75 mAutostartId = contextMenu()->insertItem( i18n(
"Start Reminder Daemon at Login"),
this,
76 TQ_SLOT( toggleAutostart() ) );
77 contextMenu()->setItemChecked( mAutostartId, autostart );
78 contextMenu()->setItemChecked( mAlarmsEnabledId, alarmsEnabled );
82 TDEActionCollection *ac = actionCollection();
83 const char *quitName = KStdAction::name( KStdAction::Quit );
84 TDEAction *quit = ac->action( quitName );
86 kdDebug(5890) <<
"No Quit standard action." << endl;
88 #if KDE_IS_VERSION(3,3,90)
89 quit->disconnect( TQ_SIGNAL( activated() ),
this,
90 TQ_SLOT( maybeQuit() ) );
91 connect( quit, TQ_SIGNAL( activated() ), TQ_SLOT( slotQuit() ) );
94 quit->disconnect( TQ_SIGNAL( activated() ), tqApp,
95 TQ_SLOT( closeAllWindows() ) );
97 connect(
this, TQ_SIGNAL( quitSelected() ), TQ_SLOT( slotQuit() ) );
100 TQToolTip::add(
this, mName );
103 AlarmDockWindow::~AlarmDockWindow()
107 void AlarmDockWindow::resizeTrayIcon ()
110 mPixmapEnabled = loadSizedIcon(
"korgac", width() );
111 mPixmapDisabled = loadSizedIcon(
"korgac_disabled", width() );
113 TDEConfig *config = kapp->config();
114 bool alarmsEnabled = config->readBoolEntry(
"Enabled",
true );
115 setPixmap( alarmsEnabled ? mPixmapEnabled : mPixmapDisabled );
118 void AlarmDockWindow::resizeEvent ( TQResizeEvent * )
123 void AlarmDockWindow::showEvent ( TQShowEvent *se )
126 KSystemTray::showEvent(se);
129 void AlarmDockWindow::slotUpdate(
int reminders )
131 TQToolTip::remove(
this );
134 TQToolTip::add(
this, i18n(
"There is 1 active reminder.",
135 "There are %n active reminders.", reminders ) );
136 contextMenu()->setItemEnabled( mSuspendAll,
true );
137 contextMenu()->setItemEnabled( mDismissAll,
true );
141 TQToolTip::add(
this, mName );
142 contextMenu()->setItemEnabled( mSuspendAll,
false );
143 contextMenu()->setItemEnabled( mDismissAll,
false );
147 void AlarmDockWindow::toggleAlarmsEnabled()
149 kdDebug(5890) <<
"AlarmDockWindow::toggleAlarmsEnabled()" << endl;
151 TDEConfig *config = kapp->config();
152 config->setGroup(
"General" );
154 bool enabled = !contextMenu()->isItemChecked( mAlarmsEnabledId );
155 contextMenu()->setItemChecked( mAlarmsEnabledId, enabled );
156 setPixmap( enabled ? mPixmapEnabled : mPixmapDisabled );
158 config->writeEntry(
"Enabled", enabled );
162 void AlarmDockWindow::toggleAutostart()
164 bool autostart = !contextMenu()->isItemChecked( mAutostartId );
166 enableAutostart( autostart );
169 void AlarmDockWindow::slotSuspendAll()
171 emit suspendAllSignal();
174 void AlarmDockWindow::slotDismissAll()
176 emit dismissAllSignal();
179 void AlarmDockWindow::enableAutostart(
bool enable )
181 TDEConfig *config = kapp->config();
182 config->setGroup(
"General" );
183 config->writeEntry(
"Autostart", enable );
186 contextMenu()->setItemChecked( mAutostartId, enable );
189 void AlarmDockWindow::mousePressEvent( TQMouseEvent *e )
191 if ( e->button() == TQt::LeftButton ) {
192 kapp->startServiceByDesktopName(
"korganizer", TQString() );
194 KSystemTray::mousePressEvent( e );
199 void AlarmDockWindow::slotQuit()
201 int result = KMessageBox::questionYesNoCancel(
this,
202 i18n(
"Do you want to start the KOrganizer reminder daemon at login "
203 "(note that you will not get reminders whilst the daemon is not running)?"),
204 i18n(
"Close KOrganizer Reminder Daemon"),
205 i18n(
"Start"), i18n(
"Do Not Start"),
206 TQString::fromLatin1(
"AskForStartAtLogin")
209 bool autostart =
true;
210 if ( result == KMessageBox::No ) autostart =
false;
211 enableAutostart( autostart );
213 if ( result != KMessageBox::Cancel )
217 #include "alarmdockwindow.moc"