Diffstat (limited to 'libopie/pim/opimmainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/opimmainwindow.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/libopie/pim/opimmainwindow.cpp b/libopie/pim/opimmainwindow.cpp index 4044bc1..2739e26 100644 --- a/libopie/pim/opimmainwindow.cpp +++ b/libopie/pim/opimmainwindow.cpp | |||
@@ -1,138 +1,150 @@ | |||
1 | #include <qapplication.h> | 1 | #include <qapplication.h> |
2 | #include <qdatetime.h> | 2 | #include <qdatetime.h> |
3 | #include <qcopchannel_qws.h> | 3 | #include <qcopchannel_qws.h> |
4 | 4 | ||
5 | #include <qpe/sound.h> | 5 | #include <qpe/sound.h> |
6 | #include <qpe/qcopenvelope_qws.h> | 6 | #include <qpe/qcopenvelope_qws.h> |
7 | #include <qpe/qpeapplication.h> | ||
7 | 8 | ||
8 | #include "opimresolver.h" | 9 | #include "opimresolver.h" |
9 | #include "opimmainwindow.h" | 10 | #include "opimmainwindow.h" |
10 | 11 | ||
11 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, | 12 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, |
12 | const char* name, WFlags flag ) | 13 | const char* name, WFlags flag ) |
13 | : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { | 14 | : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { |
14 | 15 | ||
15 | /* | 16 | /* |
16 | * let's generate our QCopChannel | 17 | * let's generate our QCopChannel |
17 | */ | 18 | */ |
18 | m_str = QString("QPE/"+m_service).local8Bit(); | 19 | m_str = QString("QPE/"+m_service).local8Bit(); |
19 | m_channel= new QCopChannel(m_str, this ); | 20 | m_channel= new QCopChannel(m_str, this ); |
20 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), | 21 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), |
21 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 22 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
22 | connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), | 23 | connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), |
23 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 24 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
24 | 25 | ||
25 | /* connect flush and reload */ | 26 | /* connect flush and reload */ |
26 | connect(qApp, SIGNAL(flush() ), | 27 | connect(qApp, SIGNAL(flush() ), |
27 | this, SLOT(flush() ) ); | 28 | this, SLOT(flush() ) ); |
28 | connect(qApp, SIGNAL(reload() ), | 29 | connect(qApp, SIGNAL(reload() ), |
29 | this, SLOT(reload() ) ); | 30 | this, SLOT(reload() ) ); |
30 | } | 31 | } |
31 | OPimMainWindow::~OPimMainWindow() { | 32 | OPimMainWindow::~OPimMainWindow() { |
32 | delete m_channel; | 33 | delete m_channel; |
33 | } | 34 | } |
34 | QCopChannel* OPimMainWindow::channel() { | 35 | QCopChannel* OPimMainWindow::channel() { |
35 | return m_channel; | 36 | return m_channel; |
36 | } | 37 | } |
37 | void OPimMainWindow::doSetDocument( const QString& ) { | 38 | void OPimMainWindow::doSetDocument( const QString& ) { |
38 | 39 | ||
39 | } | 40 | } |
40 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { | 41 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { |
42 | bool needShow = false; | ||
41 | /* | 43 | /* |
42 | * create demands to create | 44 | * create demands to create |
43 | * a new record... | 45 | * a new record... |
44 | */ | 46 | */ |
45 | QDataStream stream(array, IO_ReadOnly); | 47 | QDataStream stream(array, IO_ReadOnly); |
46 | if ( cmd == "create()" ) { | 48 | if ( cmd == "create()" ) { |
49 | raise(); | ||
47 | int uid = create(); | 50 | int uid = create(); |
48 | QCopEnvelope e(m_str, "created(int)" ); | 51 | QCopEnvelope e(m_str, "created(int)" ); |
49 | e << uid; | 52 | e << uid; |
53 | needShow = true; | ||
50 | }else if ( cmd == "remove(int)" ) { | 54 | }else if ( cmd == "remove(int)" ) { |
51 | int uid; | 55 | int uid; |
52 | stream >> uid; | 56 | stream >> uid; |
53 | bool rem = remove( uid ); | 57 | bool rem = remove( uid ); |
54 | QCopEnvelope e(m_str, "removed(bool)" ); | 58 | QCopEnvelope e(m_str, "removed(bool)" ); |
55 | e << rem; | 59 | e << rem; |
60 | needShow = true; | ||
56 | }else if ( cmd == "beam(int)" ) { | 61 | }else if ( cmd == "beam(int)" ) { |
57 | int uid; | 62 | int uid; |
58 | stream >> uid; | 63 | stream >> uid; |
59 | beam( uid); | 64 | beam( uid); |
60 | }else if ( cmd == "show(int)" ) { | 65 | }else if ( cmd == "show(int)" ) { |
66 | raise(); | ||
61 | int uid; | 67 | int uid; |
62 | stream >> uid; | 68 | stream >> uid; |
63 | show( uid ); | 69 | show( uid ); |
70 | needShow = true; | ||
64 | }else if ( cmd == "edit(int)" ) { | 71 | }else if ( cmd == "edit(int)" ) { |
72 | raise(); | ||
65 | int uid; | 73 | int uid; |
66 | stream >> uid; | 74 | stream >> uid; |
67 | edit( uid ); | 75 | edit( uid ); |
68 | }else if ( cmd == "add(int,QByteArray)" ) { | 76 | }else if ( cmd == "add(int,QByteArray)" ) { |
69 | int rtti; | 77 | int rtti; |
70 | QByteArray array; | 78 | QByteArray array; |
71 | stream >> rtti; | 79 | stream >> rtti; |
72 | stream >> array; | 80 | stream >> array; |
73 | m_fallBack = record(rtti, array ); | 81 | m_fallBack = record(rtti, array ); |
74 | if (!m_fallBack) return; | 82 | if (!m_fallBack) return; |
75 | add( *m_fallBack ); | 83 | add( *m_fallBack ); |
76 | delete m_fallBack; | 84 | delete m_fallBack; |
77 | }else if ( cmd == "alarm(QDateTime,int)" ) { | 85 | }else if ( cmd == "alarm(QDateTime,int)" ) { |
86 | raise(); | ||
78 | QDateTime dt; int uid; | 87 | QDateTime dt; int uid; |
79 | stream >> dt; | 88 | stream >> dt; |
80 | stream >> uid; | 89 | stream >> uid; |
81 | qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid ); | 90 | qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid ); |
82 | QDateTime current = QDateTime::currentDateTime(); | 91 | QDateTime current = QDateTime::currentDateTime(); |
83 | if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() ) | 92 | if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() ) |
84 | return; | 93 | return; |
85 | doAlarm( dt, uid ); | 94 | doAlarm( dt, uid ); |
86 | 95 | needShow = true; | |
87 | } | 96 | } |
97 | |||
98 | if (needShow ) | ||
99 | QPEApplication::setKeepRunning(); | ||
88 | } | 100 | } |
89 | /* implement the url scripting here */ | 101 | /* implement the url scripting here */ |
90 | void OPimMainWindow::setDocument( const QString& str) { | 102 | void OPimMainWindow::setDocument( const QString& str) { |
91 | doSetDocument( str ); | 103 | doSetDocument( str ); |
92 | } | 104 | } |
93 | /* | 105 | /* |
94 | * we now try to get the array demarshalled | 106 | * we now try to get the array demarshalled |
95 | * check if the rtti matches this one | 107 | * check if the rtti matches this one |
96 | */ | 108 | */ |
97 | OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { | 109 | OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { |
98 | if ( service() != rtti ) | 110 | if ( service() != rtti ) |
99 | return 0l; | 111 | return 0l; |
100 | 112 | ||
101 | OPimRecord* record = OPimResolver::self()->record( rtti ); | 113 | OPimRecord* record = OPimResolver::self()->record( rtti ); |
102 | QDataStream str(array, IO_ReadOnly ); | 114 | QDataStream str(array, IO_ReadOnly ); |
103 | if ( !record || !record->loadFromStream(str) ) { | 115 | if ( !record || !record->loadFromStream(str) ) { |
104 | delete record; | 116 | delete record; |
105 | record = 0l; | 117 | record = 0l; |
106 | } | 118 | } |
107 | 119 | ||
108 | return record; | 120 | return record; |
109 | } | 121 | } |
110 | /* | 122 | /* |
111 | * get the rtti for the service | 123 | * get the rtti for the service |
112 | */ | 124 | */ |
113 | int OPimMainWindow::service() { | 125 | int OPimMainWindow::service() { |
114 | if ( m_rtti == -1 ) | 126 | if ( m_rtti == -1 ) |
115 | m_rtti = OPimResolver::self()->serviceId( m_service ); | 127 | m_rtti = OPimResolver::self()->serviceId( m_service ); |
116 | 128 | ||
117 | return m_rtti; | 129 | return m_rtti; |
118 | } | 130 | } |
119 | void OPimMainWindow::doAlarm( const QDateTime&, int ) { | 131 | void OPimMainWindow::doAlarm( const QDateTime&, int ) { |
120 | 132 | ||
121 | } | 133 | } |
122 | void OPimMainWindow::startAlarm(int count ) { | 134 | void OPimMainWindow::startAlarm(int count ) { |
123 | m_alarmCount = count; | 135 | m_alarmCount = count; |
124 | m_playedCount = 0; | 136 | m_playedCount = 0; |
125 | Sound::soundAlarm(); | 137 | Sound::soundAlarm(); |
126 | m_timerId = startTimer( 5000 ); | 138 | m_timerId = startTimer( 5000 ); |
127 | } | 139 | } |
128 | void OPimMainWindow::killAlarm() { | 140 | void OPimMainWindow::killAlarm() { |
129 | killTimer( m_timerId ); | 141 | killTimer( m_timerId ); |
130 | } | 142 | } |
131 | void OPimMainWindow::timerEvent( QTimerEvent* e) { | 143 | void OPimMainWindow::timerEvent( QTimerEvent* e) { |
132 | if ( m_playedCount <m_alarmCount ) { | 144 | if ( m_playedCount <m_alarmCount ) { |
133 | m_playedCount++; | 145 | m_playedCount++; |
134 | Sound::soundAlarm(); | 146 | Sound::soundAlarm(); |
135 | }else { | 147 | }else { |
136 | killTimer( e->timerId() ); | 148 | killTimer( e->timerId() ); |
137 | } | 149 | } |
138 | } | 150 | } |