You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
302 lines
8.7 KiB
302 lines
8.7 KiB
15 years ago
|
/***************************************************************************
|
||
|
timecontrol.cpp - description
|
||
|
-------------------
|
||
|
begin : Son Jan 12 2003
|
||
|
copyright : (C) 2003 by Martin Witte
|
||
|
email : witte@kawo1.rwth-aachen.de
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License as published by *
|
||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
12 years ago
|
#include <tdeaboutdata.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
|
||
|
#include "timecontrol.h"
|
||
|
#include "timecontrol-configuration.h"
|
||
|
#include "../../src/include/pluginmanager.h"
|
||
|
#include "../../src/include/aboutwidget.h"
|
||
|
|
||
|
//const char *AlarmListElement = "alarmlist";
|
||
|
//const char *AlarmElement = "alarm";
|
||
|
const char *AlarmDateElement = "date";
|
||
|
const char *AlarmTimeElement = "time";
|
||
|
const char *AlarmDailyElement = "daily";
|
||
|
const char *AlarmWeekdayMaskElement = "weekdayMask";
|
||
|
const char *AlarmEnabledElement = "enabled";
|
||
|
const char *AlarmStationIDElement = "stationID";
|
||
|
//const char *AlarmFrequencyElement = "frequency";
|
||
|
const char *AlarmVolumeElement = "volume";
|
||
|
const char *AlarmTypeElement = "type";
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////
|
||
|
//// plugin library functions
|
||
|
|
||
12 years ago
|
PLUGIN_LIBRARY_FUNCTIONS(TimeControl, "tderadio-timecontrol", i18n("Time Control and Alarm Functions"));
|
||
15 years ago
|
|
||
|
///////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
|
||
14 years ago
|
TimeControl::TimeControl (const TQString &n)
|
||
15 years ago
|
: PluginBase(n, i18n("TimeControl Plugin")),
|
||
|
m_waitingFor(NULL),
|
||
|
m_countdownSeconds(0),
|
||
|
m_alarmTimer(this),
|
||
|
m_countdownTimer(this)
|
||
|
{
|
||
14 years ago
|
TQObject::connect(&m_alarmTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotQTimerAlarmTimeout()));
|
||
|
TQObject::connect(&m_countdownTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotQTimerCountdownTimeout()));
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
TimeControl::~TimeControl ()
|
||
|
{
|
||
|
m_waitingFor = NULL;
|
||
|
}
|
||
|
|
||
|
bool TimeControl::connectI (Interface *i)
|
||
|
{
|
||
|
bool a = ITimeControl::connectI(i);
|
||
|
bool b = PluginBase::connectI(i);
|
||
|
return a || b;
|
||
|
}
|
||
|
|
||
|
bool TimeControl::disconnectI (Interface *i)
|
||
|
{
|
||
|
bool a = ITimeControl::disconnectI(i);
|
||
|
bool b = PluginBase::disconnectI(i);
|
||
|
return a || b;
|
||
|
}
|
||
|
|
||
|
bool TimeControl::setAlarms (const AlarmVector &al)
|
||
|
{
|
||
|
if (m_alarms != al) {
|
||
|
m_waitingFor = NULL;
|
||
|
|
||
|
m_alarms = al;
|
||
|
|
||
14 years ago
|
slotQTimerAlarmTimeout();
|
||
15 years ago
|
|
||
|
notifyAlarmsChanged(m_alarms);
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool TimeControl::setCountdownSeconds(int n)
|
||
|
{
|
||
|
int old = m_countdownSeconds;
|
||
|
m_countdownSeconds = n;
|
||
|
if (old != n)
|
||
|
notifyCountdownSecondsChanged(n);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool TimeControl::startCountdown()
|
||
|
{
|
||
13 years ago
|
m_countdownEnd = TQDateTime::currentDateTime().addSecs(m_countdownSeconds);
|
||
15 years ago
|
m_countdownTimer.start(m_countdownSeconds * 1000, true);
|
||
|
|
||
|
notifyCountdownStarted(getCountdownEnd());
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool TimeControl::stopCountdown()
|
||
|
{
|
||
|
m_countdownTimer.stop();
|
||
14 years ago
|
m_countdownEnd = TQDateTime();
|
||
15 years ago
|
|
||
|
notifyCountdownStopped();
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQDateTime TimeControl::getNextAlarmTime() const
|
||
15 years ago
|
{
|
||
|
const Alarm *a = getNextAlarm();
|
||
|
if (a)
|
||
|
return a->nextAlarm();
|
||
|
else
|
||
14 years ago
|
return TQDateTime();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
const Alarm *TimeControl::getNextAlarm () const
|
||
|
{
|
||
13 years ago
|
TQDateTime now = TQDateTime::currentDateTime(),
|
||
15 years ago
|
next;
|
||
|
|
||
|
const Alarm *retval = NULL;
|
||
|
|
||
|
for (ciAlarmVector i = m_alarms.begin(); i != m_alarms.end(); ++i) {
|
||
14 years ago
|
TQDateTime n = i->nextAlarm();
|
||
15 years ago
|
if (n.isValid() && n > now && ( ! next.isValid() || n < next)) {
|
||
|
next = n;
|
||
|
retval = &(*i);
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDateTime old = m_nextAlarm_tmp;
|
||
15 years ago
|
m_nextAlarm_tmp = next;
|
||
|
if (old != m_nextAlarm_tmp) {
|
||
|
notifyNextAlarmChanged(retval);
|
||
|
}
|
||
|
|
||
|
return retval;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQDateTime TimeControl::getCountdownEnd () const
|
||
15 years ago
|
{
|
||
|
if (m_countdownTimer.isActive())
|
||
|
return m_countdownEnd;
|
||
|
else
|
||
14 years ago
|
return TQDateTime();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void TimeControl::slotQTimerCountdownTimeout()
|
||
15 years ago
|
{
|
||
|
stopCountdown();
|
||
|
|
||
|
notifyCountdownZero();
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void TimeControl::slotQTimerAlarmTimeout()
|
||
15 years ago
|
{
|
||
|
if (m_waitingFor) {
|
||
|
notifyAlarm(*m_waitingFor);
|
||
|
}
|
||
|
|
||
13 years ago
|
TQDateTime now = TQDateTime::currentDateTime();
|
||
15 years ago
|
Alarm const *n = getNextAlarm();
|
||
14 years ago
|
TQDateTime na = getNextAlarmTime();
|
||
15 years ago
|
|
||
|
m_waitingFor = NULL;
|
||
|
|
||
|
if (na.isValid()) {
|
||
|
|
||
|
int days = now.daysTo(na);
|
||
|
int msecs = now.time().msecsTo(na.time());
|
||
|
|
||
|
if (days > 1) {
|
||
|
m_alarmTimer.start(24 * 3600 * 1000, true);
|
||
|
|
||
|
} else if (days >= 0) {
|
||
|
|
||
|
if (days > 0)
|
||
|
msecs += days * 24 * 3600 * 1000;
|
||
|
|
||
|
if (msecs > 0) {
|
||
|
m_waitingFor = n;
|
||
|
m_alarmTimer.start(msecs, true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TimeControl::restoreState (TDEConfig *config)
|
||
15 years ago
|
{
|
||
|
AlarmVector al;
|
||
|
|
||
14 years ago
|
config->setGroup(TQString("timecontrol-") + name());
|
||
15 years ago
|
|
||
|
int nAlarms = config->readNumEntry ("nAlarms", 0);
|
||
|
for (int idx = 1; idx <= nAlarms; ++idx) {
|
||
|
|
||
14 years ago
|
TQString num = TQString().setNum(idx);
|
||
|
TQDateTime d = config->readDateTimeEntry(AlarmTimeElement + num);
|
||
15 years ago
|
bool enable = config->readBoolEntry(AlarmEnabledElement + num, false);
|
||
|
bool daily = config->readBoolEntry(AlarmDailyElement + num, false);
|
||
|
int weekdayMask = config->readNumEntry(AlarmWeekdayMaskElement + num, 0x7F);
|
||
|
float vol = config->readDoubleNumEntry(AlarmVolumeElement + num, 1);
|
||
14 years ago
|
TQString sid = config->readEntry(AlarmStationIDElement + num, TQString());
|
||
15 years ago
|
int type = config->readNumEntry(AlarmTypeElement + num, 0);
|
||
|
|
||
|
enable &= d.isValid();
|
||
|
|
||
|
Alarm a ( d, daily, enable);
|
||
|
a.setVolumePreset(vol);
|
||
|
a.setWeekdayMask(weekdayMask);
|
||
|
a.setStationID(sid);
|
||
|
a.setAlarmType((Alarm::AlarmType)type);
|
||
|
al.push_back(a);
|
||
|
}
|
||
|
|
||
|
setAlarms(al);
|
||
|
setCountdownSeconds(config->readNumEntry("countdownSeconds", 30*60));
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TimeControl::saveState (TDEConfig *config) const
|
||
15 years ago
|
{
|
||
14 years ago
|
config->setGroup(TQString("timecontrol-") + name());
|
||
15 years ago
|
|
||
|
config->writeEntry("nAlarms", m_alarms.size());
|
||
|
int idx = 1;
|
||
|
ciAlarmVector end = m_alarms.end();
|
||
|
for (ciAlarmVector i = m_alarms.begin(); i != end; ++i, ++idx) {
|
||
14 years ago
|
TQString num = TQString().setNum(idx);
|
||
15 years ago
|
config->writeEntry (AlarmTimeElement + num, i->alarmTime());
|
||
|
config->writeEntry (AlarmEnabledElement + num, i->isEnabled());
|
||
|
config->writeEntry (AlarmDailyElement + num, i->isDaily());
|
||
|
config->writeEntry (AlarmWeekdayMaskElement + num, i->weekdayMask());
|
||
|
config->writeEntry (AlarmVolumeElement + num, i->volumePreset());
|
||
|
config->writeEntry (AlarmStationIDElement + num, i->stationID());
|
||
|
config->writeEntry (AlarmTypeElement + num, i->alarmType());
|
||
|
}
|
||
|
|
||
|
config->writeEntry("countdownSeconds", m_countdownSeconds);
|
||
|
}
|
||
|
|
||
|
|
||
|
ConfigPageInfo TimeControl::createConfigurationPage()
|
||
|
{
|
||
|
TimeControlConfiguration *conf = new TimeControlConfiguration(NULL);
|
||
|
connectI(conf);
|
||
12 years ago
|
return ConfigPageInfo (conf, i18n("Alarms"), i18n("Setup Alarms"), "tderadio_kalarm");
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
AboutPageInfo TimeControl::createAboutPage()
|
||
|
{
|
||
12 years ago
|
/* TDEAboutData aboutData("tderadio",
|
||
15 years ago
|
NULL,
|
||
|
NULL,
|
||
12 years ago
|
I18N_NOOP("Time Control Plugin for TDERadio."
|
||
15 years ago
|
"<P>"
|
||
|
"Provides Alarms and Sleep Countdown"
|
||
|
"<P>"),
|
||
12 years ago
|
TDEAboutData::License_GPL,
|
||
15 years ago
|
"(c) 2002-2005 Martin Witte, Klas Kalass",
|
||
|
0,
|
||
12 years ago
|
"http://sourceforge.net/projects/tderadio",
|
||
15 years ago
|
0);
|
||
|
aboutData.addAuthor("Martin Witte", "", "witte@kawo1.rwth-aachen.de");
|
||
|
aboutData.addAuthor("Klas Kalass", "", "klas.kalass@gmx.de");
|
||
|
|
||
|
return AboutPageInfo(
|
||
12 years ago
|
new TDERadioAboutWidget(aboutData, TDERadioAboutWidget::AbtTabbed),
|
||
15 years ago
|
i18n("Alarms"),
|
||
|
i18n("Time Control Plugin"),
|
||
12 years ago
|
"tderadio_kalarm"
|
||
15 years ago
|
);*/
|
||
|
return AboutPageInfo();
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "timecontrol.moc"
|