libopie PIM API Documentation

opimmainwindow.cpp

Go to the documentation of this file.
00001 #include <qapplication.h>
00002 #include <qdatetime.h>
00003 #include <qcopchannel_qws.h>
00004 
00005 #include <qpe/sound.h>
00006 #include <qpe/qcopenvelope_qws.h>
00007 #include <qpe/qpeapplication.h>
00008 
00009 #include "opimresolver.h"
00010 #include "opimmainwindow.h"
00011 
00012 OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent,
00013                                 const char* name, WFlags flag )
00014     : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) {
00015 
00016     /*
00017      * let's generate our QCopChannel
00018      */
00019     m_str = QString("QPE/"+m_service).local8Bit();
00020     m_channel= new QCopChannel(m_str, this );
00021     connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ),
00022             this, SLOT( appMessage( const QCString&, const QByteArray& ) ) );
00023     connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ),
00024             this, SLOT( appMessage( const QCString&, const QByteArray& ) ) );
00025 
00026     /* connect flush and reload */
00027     connect(qApp, SIGNAL(flush() ),
00028             this, SLOT(flush() ) );
00029     connect(qApp, SIGNAL(reload() ),
00030             this, SLOT(reload() ) );
00031 }
00032 OPimMainWindow::~OPimMainWindow() {
00033     delete m_channel;
00034 }
00035 QCopChannel* OPimMainWindow::channel() {
00036     return m_channel;
00037 }
00038 void OPimMainWindow::doSetDocument( const QString&  ) {
00039 
00040 }
00041 void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) {
00042     bool needShow = false;
00043     /*
00044      * create demands to create
00045      * a new record...
00046      */
00047     QDataStream stream(array, IO_ReadOnly);
00048     if ( cmd == "create()" ) {
00049         raise();
00050         int uid = create();
00051         QCopEnvelope e(m_str, "created(int)" );
00052         e << uid;
00053         needShow = true;
00054     }else if ( cmd == "remove(int)" ) {
00055         int uid;
00056         stream >> uid;
00057         bool rem = remove( uid );
00058         QCopEnvelope e(m_str, "removed(bool)" );
00059         e << rem;
00060         needShow = true;
00061     }else if ( cmd == "beam(int)" ) {
00062         int uid;
00063         stream >> uid;
00064         beam( uid);
00065     }else if ( cmd == "show(int)" ) {
00066         raise();
00067         int uid;
00068         stream >> uid;
00069         show( uid );
00070         needShow = true;
00071     }else if ( cmd == "edit(int)" ) {
00072         raise();
00073         int uid;
00074         stream >> uid;
00075         edit( uid );
00076     }else if ( cmd == "add(int,QByteArray)" ) {
00077         int rtti;
00078         QByteArray array;
00079         stream >> rtti;
00080         stream >> array;
00081         m_fallBack = record(rtti, array );
00082         if (!m_fallBack) return;
00083         add( *m_fallBack );
00084         delete m_fallBack;
00085     }else if ( cmd == "alarm(QDateTime,int)" ) {
00086         raise();
00087         QDateTime dt; int uid;
00088         stream >> dt;
00089         stream >> uid;
00090         qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid );
00091         QDateTime current = QDateTime::currentDateTime();
00092         if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() )
00093             return;
00094         doAlarm( dt,  uid );
00095         needShow = true;
00096     }
00097 
00098     if (needShow )
00099         QPEApplication::setKeepRunning();
00100 }
00101 /* implement the url scripting here */
00102 void OPimMainWindow::setDocument( const QString& str) {
00103     doSetDocument( str );
00104 }
00105 /*
00106  * we now try to get the array demarshalled
00107  * check if the rtti matches this one
00108  */
00109 OPimRecord* OPimMainWindow::record( int rtti,  const QByteArray& array ) {
00110     if ( service() != rtti )
00111         return 0l;
00112 
00113     OPimRecord* record = OPimResolver::self()->record( rtti );
00114     QDataStream str(array, IO_ReadOnly );
00115     if ( !record || !record->loadFromStream(str) ) {
00116         delete record;
00117         record = 0l;
00118     }
00119 
00120     return record;
00121 }
00122 /*
00123  * get the rtti for the service
00124  */
00125 int OPimMainWindow::service() {
00126     if ( m_rtti == -1 )
00127         m_rtti  =  OPimResolver::self()->serviceId( m_service );
00128 
00129     return m_rtti;
00130 }
00131 void OPimMainWindow::doAlarm( const QDateTime&, int  ) {
00132 
00133 }
00134 void OPimMainWindow::startAlarm(int count  ) {
00135     m_alarmCount = count;
00136     m_playedCount = 0;
00137     Sound::soundAlarm();
00138     m_timerId = startTimer( 5000 );
00139 }
00140 void OPimMainWindow::killAlarm() {
00141     killTimer( m_timerId );
00142 }
00143 void OPimMainWindow::timerEvent( QTimerEvent* e) {
00144     if ( m_playedCount <m_alarmCount ) {
00145         m_playedCount++;
00146         Sound::soundAlarm();
00147     }else {
00148         killTimer( e->timerId() );
00149     }
00150 }
KDE Logo
This file is part of the documentation for OPIE Version 1.1.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:25:20 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001