Commit 4312fba0610f73dbe282b2314de50cecf68d0d7d

Reset alarms when changing system time / syncing

  If alarms are registered when the user changes the system time, they don't
  expect nor want to have to deal with a huge stream of alarms triggered
  due to the time change. This change adds a generic "sysevents" system
  that allows applications to be registered globally to be notified when some
  event occurs (currently three events - after syncing, before and after
  system time change). Applications wishing to register to respond to such
  events simply need to add a line to /etc/opie_sysevents.conf.

  Since these notifications are done via QCop, they are processed
  asynchronously - there's no waiting around for the application to handle
  the event before the code triggering the event continues on; this presented
  a problem for the pre-system time change event which is expected to delete
  all alarms for each application before changing the time. The easiest
  solution was to simply delete the alarms directly in the sysevent code so
  that it happens synchronously (instead of sending a message to the
  application and have it do the same thing). This needs to be explicitly
  requested for each application (as a line in opie_sysevents.conf with
  no message field).
  
4242#include <opie2/odevicebutton.h>
4343#include <opie2/odevice.h>
4444#include <opie2/oprocess.h>
45#include <opie2/osysevent.h>
4546
4647#include <qtopia/applnk.h>
4748#include <qtopia/private/categories.h>
500500 delete syncDialog;
501501 syncDialog = 0;
502502 transferServer->syncAccessManager()->reset();
503 notifyPostSync();
503 OSysEvent::sendSysEvent(SYSEVENT_POST_SYNC);
504504 }
505505 else if (msg == "setSyncPeerInfo(QString,QString)") {
506506 QString peerId, peerName;
623623 if (!appName.isEmpty()) {
624624 cfg.writeEntry("Apps", appName);
625625 cfg.writeEntry("Delay", delay);
626 }
627 }
628 }
629#endif
630}
631
632void Server::notifyPostSync()
633{
634#ifndef QT_NO_COP
635 QFile f( QPEApplication::qpeDir() + "etc/post_sync" );
636 if( f.open( IO_ReadOnly ) ) {
637 QTextStream ts(&f);
638 while( !ts.atEnd() ) {
639 QString s = ts.readLine();
640 if(!s.startsWith("#")) {
641 QStringList sl = QStringList::split( ' ', s );
642 // Lines should be:
643 // uniqueid appname channel message
644 // (where appname is the sync appname, for future filtering)
645 // e.g.
646 // datebook_alarm datebook QPE/Application/datebook registerAllAlarms()
647 if( sl.count() > 3 ) {
648 QCString channel( sl[2] );
649 QCString message( sl[3] );
650 QCopEnvelope e( channel, message );
651 }
652626 }
653627 }
654628 }
  
8989 void preloadApps();
9090 void prepareDirectAccess();
9191 void postDirectAccess();
92 void notifyPostSync();
9392 QString cardInfoString();
9493 QString installLocationsString();
9594
  
1datebook_postsync postsync datebook QPE/Application/datebook registerAllAlarms()
2datebook_pretime presystemtimechange datebook QPE/Application/datebook
3datebook_posttime postsystemtimechange datebook QPE/Application/datebook registerAllAlarms()
  
1515 osharedpointer.h \
1616 osmartpointer.h \
1717 ostorageinfo.h \
18 osysevent.h \
1819 xmltree.h
1920
2021SOURCES = oapplication.cpp \
3131 oresource.cpp \
3232 osmartpointer.cpp \
3333 ostorageinfo.cpp \
34 osysevent.cpp \
3435 xmltree.cpp
3536
3637
  
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2010 Paul Eggleton <bluelightning@bluelightning.org>
4 =.
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "osysevent.h"
31
32#include <qstring.h>
33#include <qfile.h>
34#include <qtextstream.h>
35
36#include <qtopia/qcopenvelope_qws.h>
37#include <qpe/qpeapplication.h>
38#include <qpe/alarmserver.h>
39
40#include <opie2/odebug.h>
41#include <opie2/oprocess.h>
42
43using namespace Opie;
44using namespace Opie::Core;
45
46void OSysEvent::sendSysEvent( int eventtype )
47{
48#ifndef QT_NO_COP
49 QString event;
50 switch( eventtype ) {
51 case SYSEVENT_POST_SYNC:
52 event = "postsync";
53 break;
54 case SYSEVENT_PRE_SYS_TIME_CHANGE:
55 event = "presystemtimechange";
56 break;
57 case SYSEVENT_POST_SYS_TIME_CHANGE:
58 event = "postsystemtimechange";
59 break;
60 default:
61 return;
62 }
63
64 QFile f( QPEApplication::qpeDir() + "etc/opie_sysevents.conf" );
65 if( f.open( IO_ReadOnly ) ) {
66 QTextStream ts(&f);
67 while( !ts.atEnd() ) {
68 QString s = ts.readLine();
69 if(!s.startsWith("#")) {
70 QStringList sl = QStringList::split( ' ', s );
71 // Lines should be:
72 // uniqueid event appname channel message
73 // e.g.
74 // datebook_postsync postsync datebook QPE/Application/datebook registerAllAlarms()
75 if( sl.count() > 3 ) {
76 if( sl[1] == event ) {
77 QCString channel( sl[3] );
78 if( sl.count() > 4 ) {
79 QCString message( sl[4] );
80 QCopEnvelope e( channel, message );
81 // FIXME message args
82 }
83 else if( eventtype == SYSEVENT_PRE_SYS_TIME_CHANGE ) {
84 // Special event - just delete alarms for the specified channel
85 AlarmServer::deleteAlarm( QDateTime(), channel, QCString(), -1 );
86 }
87 }
88 }
89 }
90 }
91 f.close();
92 }
93
94#endif
95}
  
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2010 Paul Eggleton <bluelightning@bluelightning.org>
4 =.
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OSYSEVENT_H
31#define OSYSEVENT_H
32
33#include <qobject.h>
34#include <qcstring.h>
35
36#define SYSEVENT_POST_SYNC 1
37#define SYSEVENT_PRE_SYS_TIME_CHANGE 2
38#define SYSEVENT_POST_SYS_TIME_CHANGE 3
39
40namespace Opie {
41namespace Core {
42/**
43 *\brief OSysEvent system event handling
44 *
45 * Contains functions for sending and handling system events.
46 *
47 * @author bluelightning
48 */
49class OSysEvent
50{
51public:
52 static void sendSysEvent( int eventtype );
53};
54
55}
56}
57
58#endif
  
3636#include "predicttabwidget.h"
3737
3838#include <qpe/config.h>
39#include <qpe/datebookdb.h>
4039#include <qpe/qpeapplication.h>
4140#include <qpe/qpedialog.h>
41#include <qpe/timeconversion.h>
4242
4343#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
4444#include <qpe/qcopenvelope_qws.h>
4545#endif
4646
47#include <opie2/osysevent.h>
48
4749#include <qlayout.h>
4850#include <qmessagebox.h>
4951#include <qsocket.h>
130130 disableScreenSaver << 0 << 0 << 0;
131131 }
132132
133 // Pre time change system event
134 OSysEvent::sendSysEvent(SYSEVENT_PRE_SYS_TIME_CHANGE);
135
133136 // Update the systemtime
134137 timeTab->saveSettings( true );
135138
142142 // Save settings options
143143 settingsTab->saveSettings();
144144
145 // Since time has changed quickly load in the DateBookDB to allow the alarm server to get a better
146 // grip on itself (example re-trigger alarms for when we travel back in time).
147 DateBookDB db;
145 // Post time change system event
146 OSysEvent::sendSysEvent(SYSEVENT_POST_SYS_TIME_CHANGE);
148147
149148 // Turn back on the screensaver
150149 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );