36 #include <kalarmcal/alarmtext.h>
38 #include <kactioncollection.h>
39 #include <ktoggleaction.h>
40 #include <kapplication.h>
42 #include <kaboutdata.h>
44 #include <kmessagebox.h>
45 #include <kstandarddirs.h>
46 #include <kstandardaction.h>
47 #include <kstandardguiitem.h>
48 #include <kiconeffect.h>
58 using namespace KAlarmCal;
74 mAssocMainWindow(parent),
78 mStatusUpdateTimer(new
QTimer(this)),
79 mHaveDisabledAlarms(false)
83 setToolTipTitle(KGlobal::mainComponent().aboutData()->programName());
87 mIconDisabled.
addPixmap(KIconLoader::global()->loadIcon(
QLatin1String(
"kalarm-disabled"), KIconLoader::Panel));
88 setStatus(KStatusNotifierItem::Active);
91 KActionCollection* actions = actionCollection();
92 mActionEnabled = KAlarm::createAlarmEnableAction(
this);
93 actions->addAction(
QLatin1String(
"tAlarmsEnable"), mActionEnabled);
94 contextMenu()->addAction(mActionEnabled);
95 connect(
theApp(), SIGNAL(alarmEnabledToggled(
bool)), SLOT(setEnabledStatus(
bool)));
96 contextMenu()->addSeparator();
98 mActionNew =
new NewAlarmAction(
false, i18nc(
"@action",
"&New Alarm"),
this);
100 contextMenu()->addAction(mActionNew);
102 connect(mActionNew->
fromTemplateAlarmAction(), SIGNAL(selected(
const KAEvent*)), SLOT(slotNewFromTemplate(
const KAEvent*)));
103 contextMenu()->addSeparator();
105 KAction* a = KAlarm::createStopPlayAction(
this);
107 contextMenu()->addAction(a);
111 a = KAlarm::createSpreadWindowsAction(
this);
113 contextMenu()->addAction(a);
114 contextMenu()->addSeparator();
115 contextMenu()->addAction(KStandardAction::preferences(
this, SLOT(slotPreferences()), actions));
118 const char* quitName = KStandardAction::name(KStandardAction::Quit);
120 disconnect(qa, SIGNAL(triggered(
bool)), 0, 0);
121 connect(qa, SIGNAL(triggered(
bool)), SLOT(slotQuit()));
124 setEnabledStatus(
theApp()->alarmsEnabled());
127 connect(
this, SIGNAL(activateRequested(
bool,
QPoint)), SLOT(slotActivateRequested()));
128 connect(
this, SIGNAL(secondaryActivateRequested(
QPoint)), SLOT(slotSecondaryActivateRequested()));
135 mToolTipUpdateTimer =
new QTimer(
this);
138 connect(mToolTipUpdateTimer, SIGNAL(timeout()), SLOT(updateToolTip()));
146 mToolTipUpdateTimer, SLOT(start()));
148 mToolTipUpdateTimer, SLOT(start()));
150 mToolTipUpdateTimer, SLOT(start()));
152 mToolTipUpdateTimer, SLOT(start()));
154 mToolTipUpdateTimer, SLOT(start()));
157 mToolTipUpdateTimer, SLOT(start()));
159 mToolTipUpdateTimer, SLOT(start()));
161 mToolTipUpdateTimer, SLOT(start()));
163 mToolTipUpdateTimer, SLOT(start()));
165 mToolTipUpdateTimer, SLOT(start()));
170 connect(mStatusUpdateTimer, SIGNAL(timeout()), SLOT(updateStatus()));
191 KAlarm::editNewAlarm(type);
198 void TrayWindow::slotNewFromTemplate(
const KAEvent* event)
200 KAlarm::editNewAlarm(event);
206 void TrayWindow::slotPreferences()
219 void TrayWindow::slotQuit()
224 void TrayWindow::slotQuitAfter()
233 void TrayWindow::setEnabledStatus(
bool status)
235 kDebug() << (int)status;
245 void TrayWindow::slotHaveDisabledAlarms(
bool haveDisabled)
247 kDebug() << haveDisabled;
248 mHaveDisabledAlarms = haveDisabled;
256 void TrayWindow::slotActivateRequested()
259 if (mAssocMainWindow && mAssocMainWindow->isVisible())
261 mAssocMainWindow->raise();
262 mAssocMainWindow->activateWindow();
269 void TrayWindow::slotSecondaryActivateRequested()
271 if (mActionNew->isEnabled())
272 mActionNew->trigger();
280 void TrayWindow::updateStatus()
282 mStatusUpdateTimer->
stop();
283 int period = Preferences::autoHideSystemTray();
294 active =
static_cast<bool>(event);
295 if (event && period > 0)
297 KDateTime dt =
event->nextTrigger(KAEvent::ALL_TRIGGER).effectiveKDateTime();
298 qint64 delay = KDateTime::currentLocalDateTime().secsTo_long(dt);
299 delay -=
static_cast<qint64
>(period) * 60;
300 active = (delay <= 0);
306 int delay_int =
static_cast<int>(delay);
307 if (delay_int != delay)
310 mStatusUpdateTimer->
start();
315 setStatus(active ? Active : Passive);
323 void TrayWindow::updateToolTip()
327 if (enabled && Preferences::tooltipAlarmCount())
328 subTitle = tooltipAlarmText();
331 subTitle = i18n(
"Disabled");
332 else if (mHaveDisabledAlarms)
336 subTitle += i18nc(
"@info:tooltip Brief: some alarms are disabled",
"(Some alarms disabled)");
338 setToolTipSubTitle(subTitle);
344 void TrayWindow::updateIcon()
346 if (
theApp()->alarmsEnabled())
349 setIconByPixmap(mIconDisabled);
356 QString TrayWindow::tooltipAlarmText()
const
359 const QString& prefix = Preferences::tooltipTimeToPrefix();
360 int maxCount = Preferences::tooltipAlarmCount();
361 KDateTime now = KDateTime::currentLocalDateTime();
362 KDateTime tomorrow = now.addDays(1);
368 QVector<KAEvent> events = KAlarm::getSortedActiveEvents(const_cast<TrayWindow*>(
this), &mAlarmsModel);
370 KAEvent::List events = KAlarm::getSortedActiveEvents(KDateTime(now.date(),
QTime(0,0,0), KDateTime::LocalZone), tomorrow);
372 for (i = 0, iend = events.count(); i < iend; ++i)
375 KAEvent*
event = &events[i];
377 KAEvent*
event = events[i];
379 if (event->actionSubType() == KAEvent::MESSAGE)
382 QDateTime dateTime =
event->nextTrigger(KAEvent::DISPLAY_TRIGGER).effectiveKDateTime().toLocalZone().dateTime();
383 if (dateTime > tomorrow.dateTime())
389 item.dateTime = dateTime;
392 if (Preferences::showTooltipAlarmTime())
394 item.text += KGlobal::locale()->formatTime(item.dateTime.time());
397 if (Preferences::showTooltipTimeToAlarm())
399 int mins = (now.dateTime().secsTo(item.dateTime) + 59) / 60;
402 char minutes[3] =
"00";
403 minutes[0] =
static_cast<char>((mins%60) / 10 +
'0');
404 minutes[1] =
static_cast<char>((mins%60) % 10 +
'0');
405 if (Preferences::showTooltipAlarmTime())
406 item.text += i18nc(
"@info/plain prefix + hours:minutes",
"(%1%2:%3)", prefix, mins/60,
QLatin1String(minutes));
408 item.text += i18nc(
"@info/plain prefix + hours:minutes",
"%1%2:%3", prefix, mins/60,
QLatin1String(minutes));
411 item.text += AlarmText::summary(*event);
415 for (
int itend = items.
count(); it < itend; ++it)
417 if (item.dateTime <= items[it].dateTime)
426 for (i = 0, iend = items.
count(); i < iend; ++i)
428 kDebug() <<
"--" << (count+1) <<
")" << items[i].text;
431 text += items[i].text;
432 if (++count == maxCount)
443 if (win == mAssocMainWindow)
444 mAssocMainWindow = 0;
446 #include "moc_traywindow.cpp"
void setInterval(int msec)
static EventListModel * alarms()
bool alarmsEnabled() const
static bool isAudioPlaying()
virtual QByteArray text(quint32 serialNumber) const =0
static AlarmCalendar * resources()
TemplateMenuAction * fromTemplateAlarmAction() const
the KAlarm application object
void removeWindow(MainWindow *)
KAEvent * earliestAlarm() const
int count(const T &value) const
void removeWindow(TrayWindow *)
displays an alarm message
void addPixmap(const QPixmap &pixmap, Mode mode, State state)
static void connect(QObject *receiver, const char *member)
static void connect(const char *signal, const QObject *receiver, const char *member)
void insert(int i, const T &value)
TrayWindow(MainWindow *parent)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void doQuit(QWidget *parent)
static AlarmListModel * all()
Return the model containing all active and archived alarms.
void setSingleShot(bool singleShot)