traywindow.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kalarm.h"
00021 #include <stdlib.h>
00022
00023 #include <qtooltip.h>
00024 #include <qlabel.h>
00025
00026 #include <kapplication.h>
00027 #include <klocale.h>
00028 #include <kiconloader.h>
00029 #include <kstdaction.h>
00030 #include <kaboutdata.h>
00031 #include <kpopupmenu.h>
00032 #include <kmessagebox.h>
00033 #include <kstandarddirs.h>
00034 #include <kdebug.h>
00035
00036 #include "kalarmapp.h"
00037 #include "mainwindow.h"
00038 #include "messagewin.h"
00039 #include "daemongui.h"
00040 #include "prefsettings.h"
00041 #include "traywindow.moc"
00042
00043
00044
00045
00046
00047
00048
00049 TrayWindow::TrayWindow(KAlarmMainWindow* parent, const char* name)
00050 : KSystemTray((theApp()->runInSystemTray() ? parent : 0), name),
00051 mAssocMainWindow(parent),
00052 mQuitReplaced(false),
00053 mActionCollection(this)
00054 {
00055 kdDebug(5950) << "TrayWindow::TrayWindow()\n";
00056
00057
00058
00059
00060 mPixmapEnabled = BarIcon("kalarm");
00061 mPixmapDisabled = BarIcon("kalarm_disabled");
00062 if (mPixmapEnabled.isNull() || mPixmapDisabled.isNull())
00063 KMessageBox::sorry(this, i18n("Can't load system tray icon!"),
00064 i18n("%1 Error").arg(kapp->aboutData()->programName()));
00065
00066 mActionQuit = KStdAction::quit(this, SLOT(slotQuit()), &mActionCollection);
00067
00068
00069 ActionAlarmsEnabled* a = theApp()->actionAlarmEnable();
00070 mAlarmsEnabledId = a->itemId(a->plug(contextMenu()));
00071 connect(a, SIGNAL(alarmsEnabledChange(bool)), this, SLOT(setEnabledStatus(bool)));
00072 theApp()->actionPreferences()->plug(contextMenu());
00073 theApp()->actionDaemonControl()->plug(contextMenu());
00074
00075
00076 DaemonGuiHandler* daemonGui = theApp()->daemonGuiHandler();
00077 daemonGui->checkStatus();
00078 setEnabledStatus(daemonGui->monitoringAlarms());
00079
00080 QToolTip::add(this, kapp->aboutData()->programName());
00081 }
00082
00083 TrayWindow::~TrayWindow()
00084 {
00085 kdDebug(5950) << "TrayWindow::~TrayWindow()\n";
00086 theApp()->removeWindow(this);
00087 emit deleted();
00088 }
00089
00090
00091
00092
00093
00094 void TrayWindow::contextMenuAboutToShow(KPopupMenu* menu)
00095 {
00096 if (!mQuitReplaced)
00097 {
00098
00099 QString quitText = mActionQuit->text();
00100 for (unsigned n = 0; n < menu->count(); ++n)
00101 {
00102 QString txt = menu->text(menu->idAt(n));
00103 if (txt.startsWith(quitText))
00104 {
00105 menu->removeItemAt(n);
00106 break;
00107 }
00108 }
00109 mActionQuit->plug(menu);
00110 mQuitReplaced = true;
00111 }
00112
00113
00114 theApp()->daemonGuiHandler()->checkStatus();
00115 }
00116
00117
00118
00119
00120
00121
00122 void TrayWindow::slotQuit()
00123 {
00124 kdDebug(5950)<<"TrayWindow::slotQuit()\n";
00125 if (theApp()->runInSystemTray())
00126 {
00127 if (!MessageWin::instanceCount())
00128 theApp()->quit();
00129 else
00130 KAlarmMainWindow::closeAll();
00131 }
00132 theApp()->displayTrayIcon(false);
00133 }
00134
00135
00136
00137
00138
00139 void TrayWindow::setEnabledStatus(bool status)
00140 {
00141 kdDebug(5950)<<"TrayWindow::setEnabledStatus(" << (int)status << ")\n";
00142 setPixmap(status ? mPixmapEnabled : mPixmapDisabled);
00143 contextMenu()->setItemChecked(mAlarmsEnabledId, status);
00144 }
00145
00146
00147
00148
00149
00150 void TrayWindow::mousePressEvent(QMouseEvent* e)
00151 {
00152
00153 if (e->button() == LeftButton && !theApp()->runInSystemTray())
00154 {
00155
00156 mAssocMainWindow = KAlarmMainWindow::toggleWindow(mAssocMainWindow);
00157 }
00158 else
00159 KSystemTray::mousePressEvent(e);
00160 }
00161
00162
00163
00164
00165
00166
00167 void TrayWindow::mouseReleaseEvent(QMouseEvent* e)
00168 {
00169
00170 if (e->button() == LeftButton && mAssocMainWindow && mAssocMainWindow->isVisible())
00171 {
00172 mAssocMainWindow->raise();
00173 mAssocMainWindow->setActiveWindow();
00174 }
00175 else
00176 KSystemTray::mouseReleaseEvent(e);
00177 }
00178
00179
00180
00181
00182 void TrayWindow::removeWindow(KAlarmMainWindow* win)
00183 {
00184 if (win == mAssocMainWindow)
00185 mAssocMainWindow = 0;
00186 }
This file is part of the documentation for kdelibs Version 3.1.5.