author | zecke <zecke> | 2005-01-13 21:41:55 (UTC) |
---|---|---|
committer | zecke <zecke> | 2005-01-13 21:41:55 (UTC) |
commit | 4177963b2f0211c3fa9b15a1af227c8217187b72 (patch) (unidiff) | |
tree | d6d222f97a3d02caa50ee1f3663bcd7ad790bd0a | |
parent | e1a1079f4b12d70a946761443492592236012f79 (diff) | |
download | opie-4177963b2f0211c3fa9b15a1af227c8217187b72.zip opie-4177963b2f0211c3fa9b15a1af227c8217187b72.tar.gz opie-4177963b2f0211c3fa9b15a1af227c8217187b72.tar.bz2 |
-Use const char array instead of writing QPE/Application/clock at many applications
-Use const char array for the message the AlarmServer should send
-Try to remove the issue with 'sticky' alarms. Remove all
alarms with the internal ids
-rw-r--r-- | noncore/tools/clock/clock.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp index e681650..0ad69d9 100644 --- a/noncore/tools/clock/clock.cpp +++ b/noncore/tools/clock/clock.cpp | |||
@@ -57,16 +57,18 @@ | |||
57 | #include <qhbox.h> | 57 | #include <qhbox.h> |
58 | #include <qlineedit.h> | 58 | #include <qlineedit.h> |
59 | 59 | ||
60 | static const int sw_prec = 2; | 60 | static const int sw_prec = 2; |
61 | static const int magic_daily = 2292922; | 61 | static const int magic_daily = 2292922; |
62 | static const int magic_countdown = 2292923; | 62 | static const int magic_countdown = 2292923; |
63 | static const int magic_snooze = 2292924; | 63 | static const int magic_snooze = 2292924; |
64 | static const int magic_playmp = 2292925; | 64 | static const int magic_playmp = 2292925; |
65 | static const char ALARM_CLOCK_CHANNEL [] = "QPE/Application/clock"; | ||
66 | static const char ALARM_CLOCK_MESSAGE [] = "alarm(QDateTime,int)"; | ||
65 | 67 | ||
66 | #include <math.h> | 68 | #include <math.h> |
67 | #include <unistd.h> | 69 | #include <unistd.h> |
68 | #include <sys/types.h> | 70 | #include <sys/types.h> |
69 | 71 | ||
70 | #include <pthread.h> | 72 | #include <pthread.h> |
71 | 73 | ||
72 | 74 | ||
@@ -122,25 +124,25 @@ AlarmDlg::setText(const QString &txt) | |||
122 | // | 124 | // |
123 | // | 125 | // |
124 | void | 126 | void |
125 | AlarmDlg::checkSnooze(void) | 127 | AlarmDlg::checkSnooze(void) |
126 | { | 128 | { |
127 | // | 129 | // |
128 | // Ensure we have only one snooze alarm. | 130 | // Ensure we have only one snooze alarm. |
129 | // | 131 | // |
130 | AlarmServer::deleteAlarm(QDateTime(), "QPE/Application/clock", | 132 | AlarmServer::deleteAlarm(QDateTime(), ALARM_CLOCK_CHANNEL, |
131 | "alarm(QDateTime,int)", magic_snooze); | 133 | ALARM_CLOCK_MESSAGE, magic_snooze); |
132 | 134 | ||
133 | if (snoozeTime->value() > 0) { | 135 | if (snoozeTime->value() > 0) { |
134 | QDateTime wake = QDateTime::currentDateTime(); | 136 | QDateTime wake = QDateTime::currentDateTime(); |
135 | wake = wake.addSecs(snoozeTime->value() * 60); // snoozeTime in minutes | 137 | wake = wake.addSecs(snoozeTime->value() * 60); // snoozeTime in minutes |
136 | 138 | ||
137 | AlarmServer::addAlarm(wake, "QPE/Application/clock", | 139 | AlarmServer::addAlarm(wake, ALARM_CLOCK_CHANNEL, |
138 | "alarm(QDateTime,int)", magic_snooze); | 140 | ALARM_CLOCK_MESSAGE, magic_snooze); |
139 | } | 141 | } |
140 | accept(); | 142 | accept(); |
141 | } | 143 | } |
142 | 144 | ||
143 | 145 | ||
144 | 146 | ||
145 | void | 147 | void |
146 | AlarmDlg::changePrompt(int mins) | 148 | AlarmDlg::changePrompt(int mins) |
@@ -566,17 +568,17 @@ void Clock::dailyEdited() | |||
566 | 568 | ||
567 | void Clock::enableDaily( bool ) | 569 | void Clock::enableDaily( bool ) |
568 | { | 570 | { |
569 | scheduleApplyDailyAlarm(); | 571 | scheduleApplyDailyAlarm(); |
570 | } | 572 | } |
571 | 573 | ||
572 | void Clock::appMessage( const QCString &msg, const QByteArray &data ) | 574 | void Clock::appMessage( const QCString &msg, const QByteArray &data ) |
573 | { | 575 | { |
574 | if ( msg == "alarm(QDateTime,int)" ) { | 576 | if ( msg == ALARM_CLOCK_MESSAGE ) { |
575 | QDataStream ds(data,IO_ReadOnly); | 577 | QDataStream ds(data,IO_ReadOnly); |
576 | QDateTime when; | 578 | QDateTime when; |
577 | int t; | 579 | int t; |
578 | ds >> when >> t; | 580 | ds >> when >> t; |
579 | QTime theTime( when.time() ); | 581 | QTime theTime( when.time() ); |
580 | if ( t == magic_daily || t == magic_snooze || | 582 | if ( t == magic_daily || t == magic_snooze || |
581 | t == magic_playmp ) { | 583 | t == magic_playmp ) { |
582 | QString msg = tr("<b>Daily Alarm:</b><p>"); | 584 | QString msg = tr("<b>Daily Alarm:</b><p>"); |
@@ -711,42 +713,45 @@ void Clock::applyDailyAlarm() | |||
711 | } | 713 | } |
712 | 714 | ||
713 | Config config( "Clock" ); | 715 | Config config( "Clock" ); |
714 | config.setGroup( "Daily Alarm" ); | 716 | config.setGroup( "Daily Alarm" ); |
715 | config.writeEntry( "Hour", hour ); | 717 | config.writeEntry( "Hour", hour ); |
716 | config.writeEntry( "Minute", minute ); | 718 | config.writeEntry( "Minute", minute ); |
717 | 719 | ||
718 | bool enableDaily = dailyEnabled->isChecked(); | 720 | bool enableDaily = dailyEnabled->isChecked(); |
719 | bool wasSound = config.readEntry( "SoundEnabled" ); | ||
720 | bool isSound = sndCheck->isChecked(); | 721 | bool isSound = sndCheck->isChecked(); |
721 | int oldMagic = wasSound ? magic_playmp : magic_daily; | ||
722 | int isMagic = isSound ? magic_playmp : magic_daily; | 722 | int isMagic = isSound ? magic_playmp : magic_daily; |
723 | config.writeEntry( "Enabled", enableDaily ); | 723 | config.writeEntry( "Enabled", enableDaily ); |
724 | config.writeEntry( "SoundEnabled", isSound ); | 724 | config.writeEntry( "SoundEnabled", isSound ); |
725 | 725 | ||
726 | QString exclDays; | 726 | QString exclDays; |
727 | int exclCount = 0; | 727 | int exclCount = 0; |
728 | for ( int i = 1; i <= 7; i++ ) { | 728 | for ( int i = 1; i <= 7; i++ ) { |
729 | if ( !dayBtn[dayBtnIdx(i)]->isOn() ) { | 729 | if ( !dayBtn[dayBtnIdx(i)]->isOn() ) { |
730 | if ( !exclDays.isEmpty() ) | 730 | if ( !exclDays.isEmpty() ) |
731 | exclDays += ","; | 731 | exclDays += ","; |
732 | exclDays += QString::number( i ); | 732 | exclDays += QString::number( i ); |
733 | exclCount++; | 733 | exclCount++; |
734 | } | 734 | } |
735 | } | 735 | } |
736 | config.writeEntry( "ExcludeDays", exclDays ); | 736 | config.writeEntry( "ExcludeDays", exclDays ); |
737 | 737 | ||
738 | /* try to delete both */ | 738 | /* try to delete all */ |
739 | AlarmServer::deleteAlarm(QDateTime(), "QPE/Application/clock", | 739 | AlarmServer::deleteAlarm(QDateTime(), ALARM_CLOCK_CHANNEL, |
740 | "alarm(QDateTime,int)", oldMagic); | 740 | ALARM_CLOCK_MESSAGE, magic_daily); |
741 | AlarmServer::deleteAlarm(QDateTime(), ALARM_CLOCK_CHANNEL, | ||
742 | ALARM_CLOCK_MESSAGE, magic_playmp ); | ||
743 | AlarmServer::deleteAlarm(QDateTime(), ALARM_CLOCK_CHANNEL, | ||
744 | ALARM_CLOCK_MESSAGE, magic_snooze); | ||
745 | |||
741 | if ( enableDaily && exclCount < 7 ) { | 746 | if ( enableDaily && exclCount < 7 ) { |
742 | QDateTime when = nextAlarm( hour, minute ); | 747 | QDateTime when = nextAlarm( hour, minute ); |
743 | AlarmServer::addAlarm(when, "QPE/Application/clock", | 748 | AlarmServer::addAlarm(when, ALARM_CLOCK_CHANNEL, |
744 | "alarm(QDateTime,int)", isMagic); | 749 | ALARM_CLOCK_MESSAGE, isMagic); |
745 | } | 750 | } |
746 | } | 751 | } |
747 | 752 | ||
748 | bool Clock::validDaysSelected(void) | 753 | bool Clock::validDaysSelected(void) |
749 | { | 754 | { |
750 | for ( int i = 1; i <= 7; i++ ) { | 755 | for ( int i = 1; i <= 7; i++ ) { |
751 | if ( dayBtn[dayBtnIdx(i)]->isOn() ) { | 756 | if ( dayBtn[dayBtnIdx(i)]->isOn() ) { |
752 | return TRUE; | 757 | return TRUE; |