25 #include "alarmdockwindow.h"
26 #include "koalarmclient.h"
28 #include <kapplication.h>
30 #include <kdeversion.h>
32 #include <kiconloader.h>
35 #include <kstandarddirs.h>
36 #include <dcopclient.h>
37 #include <kpopupmenu.h>
38 #include <kmessagebox.h>
40 #include <kstdaction.h>
42 #include <tqtooltip.h>
47 AlarmDockWindow::AlarmDockWindow(
const char *name )
48 : KSystemTray( 0, name )
51 KConfig *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 KGlobal::iconLoader()->addAppDir(
"korgac" );
61 mPixmapEnabled = loadSizedIcon(
"korgac", width() );
62 mPixmapDisabled = loadSizedIcon(
"korgac_disabled", width() );
64 setPixmap( alarmsEnabled ? mPixmapEnabled : mPixmapDisabled );
67 mSuspendAll = contextMenu()->insertItem( i18n(
"Suspend All"),
this, TQT_SLOT( slotSuspendAll() ) );
68 mDismissAll = contextMenu()->insertItem( i18n(
"Dismiss All"),
this, TQT_SLOT( slotDismissAll() ) );
69 contextMenu()->setItemEnabled( mSuspendAll,
false );
70 contextMenu()->setItemEnabled( mDismissAll,
false );
72 contextMenu()->insertSeparator();
73 mAlarmsEnabledId = contextMenu()->insertItem( i18n(
"Reminders Enabled"),
this,
74 TQT_SLOT( toggleAlarmsEnabled() ) );
75 mAutostartId = contextMenu()->insertItem( i18n(
"Start Reminder Daemon at Login"),
this,
76 TQT_SLOT( toggleAutostart() ) );
77 contextMenu()->setItemChecked( mAutostartId, autostart );
78 contextMenu()->setItemChecked( mAlarmsEnabledId, alarmsEnabled );
82 KActionCollection *ac = actionCollection();
83 const char *quitName = KStdAction::name( KStdAction::Quit );
84 KAction *quit = ac->action( quitName );
86 kdDebug(5890) <<
"No Quit standard action." << endl;
88 #if KDE_IS_VERSION(3,3,90)
89 quit->disconnect( TQT_SIGNAL( activated() ),
this,
90 TQT_SLOT( maybeQuit() ) );
91 connect( quit, TQT_SIGNAL( activated() ), TQT_SLOT( slotQuit() ) );
93 #else //FIXME: remove for KDE 4.0
94 quit->disconnect( TQT_SIGNAL( activated() ), tqApp,
95 TQT_SLOT( closeAllWindows() ) );
97 connect(
this, TQT_SIGNAL( quitSelected() ), TQT_SLOT( slotQuit() ) );
100 TQToolTip::add(
this, mName );
103 AlarmDockWindow::~AlarmDockWindow()
107 void AlarmDockWindow::resizeEvent ( TQResizeEvent * )
110 mPixmapEnabled = loadSizedIcon(
"korgac", width() );
111 mPixmapDisabled = loadSizedIcon(
"korgac_disabled", width() );
113 KConfig *config = kapp->config();
114 bool alarmsEnabled = config->readBoolEntry(
"Enabled",
true );
115 setPixmap( alarmsEnabled ? mPixmapEnabled : mPixmapDisabled );
118 void AlarmDockWindow::slotUpdate(
int reminders )
120 TQToolTip::remove(
this );
123 TQToolTip::add(
this, i18n(
"There is 1 active reminder.",
124 "There are %n active reminders.", reminders ) );
125 contextMenu()->setItemEnabled( mSuspendAll,
true );
126 contextMenu()->setItemEnabled( mDismissAll,
true );
130 TQToolTip::add(
this, mName );
131 contextMenu()->setItemEnabled( mSuspendAll,
false );
132 contextMenu()->setItemEnabled( mDismissAll,
false );
136 void AlarmDockWindow::toggleAlarmsEnabled()
138 kdDebug(5890) <<
"AlarmDockWindow::toggleAlarmsEnabled()" << endl;
140 KConfig *config = kapp->config();
141 config->setGroup(
"General" );
143 bool enabled = !contextMenu()->isItemChecked( mAlarmsEnabledId );
144 contextMenu()->setItemChecked( mAlarmsEnabledId, enabled );
145 setPixmap( enabled ? mPixmapEnabled : mPixmapDisabled );
147 config->writeEntry(
"Enabled", enabled );
151 void AlarmDockWindow::toggleAutostart()
153 bool autostart = !contextMenu()->isItemChecked( mAutostartId );
155 enableAutostart( autostart );
158 void AlarmDockWindow::slotSuspendAll()
160 emit suspendAllSignal();
163 void AlarmDockWindow::slotDismissAll()
165 emit dismissAllSignal();
168 void AlarmDockWindow::enableAutostart(
bool enable )
170 KConfig *config = kapp->config();
171 config->setGroup(
"General" );
172 config->writeEntry(
"Autostart", enable );
175 contextMenu()->setItemChecked( mAutostartId, enable );
178 void AlarmDockWindow::mousePressEvent( TQMouseEvent *e )
180 if ( e->button() == Qt::LeftButton ) {
181 kapp->startServiceByDesktopName(
"korganizer", TQString() );
183 KSystemTray::mousePressEvent( e );
188 void AlarmDockWindow::slotQuit()
190 int result = KMessageBox::questionYesNoCancel(
this,
191 i18n(
"Do you want to start the KOrganizer reminder daemon at login "
192 "(note that you will not get reminders whilst the daemon is not running)?"),
193 i18n(
"Close KOrganizer Reminder Daemon"),
194 i18n(
"Start"), i18n(
"Do Not Start"),
195 TQString::fromLatin1(
"AskForStartAtLogin")
198 bool autostart =
true;
199 if ( result == KMessageBox::No ) autostart =
false;
200 enableAutostart( autostart );
202 if ( result != KMessageBox::Cancel )
206 #include "alarmdockwindow.moc"