Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

opimmainwindow.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
00004               =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 
00030 #include "opimmainwindow.h"
00031 
00032 /* OPIE */
00033 #include <opie2/odebug.h>
00034 #include <opie2/opimresolver.h>
00035 #include <opie2/oresource.h>
00036 
00037 #include <qpe/categoryselect.h>
00038 #include <qpe/ir.h>
00039 #include <qpe/qcopenvelope_qws.h>
00040 #include <qpe/qpeapplication.h>
00041 #include <qpe/sound.h>
00042 
00043 /* QT */
00044 #include <qaction.h>
00045 #include <qapplication.h>
00046 #include <qcombobox.h>
00047 #include <qcopchannel_qws.h>
00048 #include <qdatetime.h>
00049 #include <qmenubar.h>
00050 #include <qobjectlist.h>
00051 #include <qpopupmenu.h>
00052 #include <qtoolbar.h>
00053 #include <qwhatsthis.h>
00054 
00055 namespace Opie {
00056 OPimMainWindow::OPimMainWindow( const QString &serviceName, const QString &catName,
00057                                 const QString &itemName, const QString &configName,
00058                                 QWidget *parent, const char* name, WFlags f )
00059     : QMainWindow( parent, name, f ), m_rtti(-1), m_service( serviceName ), m_fallBack( 0l ),
00060       m_catGroupName( catName ), m_config( configName ), m_itemContextMenu( 0l )
00061 {
00062 
00063     /*
00064      * let's generate our QCopChannel
00065      */
00066     m_str = QString("QPE/"+m_service).local8Bit();
00067     m_channel= new QCopChannel(m_str, this );
00068     connect(m_channel, SIGNAL(received(const QCString&,const QByteArray&)),
00069             this, SLOT(appMessage(const QCString&,const QByteArray&)) );
00070     connect(qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
00071             this, SLOT(appMessage(const QCString&,const QByteArray&)) );
00072 
00073     /* connect flush and reload */
00074     connect(qApp, SIGNAL(flush() ),
00075             this, SLOT(flush() ) );
00076     connect(qApp, SIGNAL(reload() ),
00077             this, SLOT(reload() ) );
00078 
00079     initBars( itemName );
00080 }
00081 
00082 OPimMainWindow::~OPimMainWindow() {
00083     delete m_channel;
00084 }
00085 
00086 QCopChannel* OPimMainWindow::channel() {
00087     return m_channel;
00088 }
00089 
00090 void OPimMainWindow::doSetDocument( const QString&  ) {
00091 
00092 }
00093 
00094 void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) {
00095     bool needShow = false;
00096     /*
00097      * create demands to create
00098      * a new record...
00099      */
00100     QDataStream stream(array, IO_ReadOnly);
00101     if ( cmd == "create()" ) {
00102         raise();
00103         int uid = create();
00104         QCopEnvelope e(m_str, "created(int)" );
00105         e << uid;
00106         needShow = true;
00107     }else if ( cmd == "remove(int)" ) {
00108         int uid;
00109         stream >> uid;
00110         bool rem = remove( uid );
00111         QCopEnvelope e(m_str, "removed(bool)" );
00112         e << rem;
00113         needShow = true;
00114     }else if ( cmd == "beam(int)" ) {
00115         int uid;
00116         stream >> uid;
00117         beam( uid);
00118     }else if ( cmd == "show(int)" ) {
00119         raise();
00120         int uid;
00121         stream >> uid;
00122         show( uid );
00123         needShow = true;
00124     }else if ( cmd == "edit(int)" ) {
00125         raise();
00126         int uid;
00127         stream >> uid;
00128         edit( uid );
00129     }else if ( cmd == "add(int,QByteArray)" ) {
00130         int rtti;
00131         QByteArray array;
00132         stream >> rtti;
00133         stream >> array;
00134         m_fallBack = record(rtti, array );
00135         if (!m_fallBack) return;
00136         add( *m_fallBack );
00137         delete m_fallBack;
00138     }else if ( cmd == "alarm(QDateTime,int)" ) {
00139         raise();
00140         QDateTime dt; int uid;
00141         stream >> dt;
00142         stream >> uid;
00143         QDateTime current = QDateTime::currentDateTime();
00144         if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() )
00145             return;
00146         doAlarm( dt,  uid );
00147         needShow = true;
00148     }
00149 
00150     if (needShow )
00151         QPEApplication::setKeepRunning();
00152 }
00153 
00154 /* implement the url scripting here */
00155 void OPimMainWindow::setDocument( const QString& str) {
00156     doSetDocument( str );
00157 }
00158 
00159 /*
00160  * we now try to get the array demarshalled
00161  * check if the rtti matches this one
00162  */
00163 OPimRecord* OPimMainWindow::record( int rtti,  const QByteArray& array ) {
00164     if ( service() != rtti )
00165         return 0l;
00166 
00167     OPimRecord* record = OPimResolver::self()->record( rtti );
00168     QDataStream str(array, IO_ReadOnly );
00169     if ( !record || !record->loadFromStream(str) ) {
00170         delete record;
00171         record = 0l;
00172     }
00173 
00174     return record;
00175 }
00176 
00177 /*
00178  * get the rtti for the service
00179  */
00180 int OPimMainWindow::service() {
00181     if ( m_rtti == -1 )
00182         m_rtti  =  OPimResolver::self()->serviceId( m_service );
00183 
00184     return m_rtti;
00185 }
00186 
00187 void OPimMainWindow::doAlarm( const QDateTime&, int  ) {
00188 
00189 }
00190 
00191 void OPimMainWindow::startAlarm(int count  ) {
00192     m_alarmCount = count;
00193     m_playedCount = 0;
00194     Sound::soundAlarm();
00195     m_timerId = startTimer( 5000 );
00196 }
00197 
00198 void OPimMainWindow::killAlarm() {
00199     killTimer( m_timerId );
00200 }
00201 
00202 void OPimMainWindow::timerEvent( QTimerEvent* e) {
00203     if ( m_playedCount <m_alarmCount ) {
00204         m_playedCount++;
00205         Sound::soundAlarm();
00206     }else {
00207         killTimer( e->timerId() );
00208     }
00209 }
00210 
00211 QPopupMenu *OPimMainWindow::itemContextMenu() {
00212     if ( !m_itemContextMenu ) {
00213         // Create context menu if hasn't been done before
00214         m_itemContextMenu = new QPopupMenu( this );
00215         m_itemEditAction->addTo( m_itemContextMenu );
00216         m_itemDuplicateAction->addTo( m_itemContextMenu );
00217         m_itemBeamAction->addTo( m_itemContextMenu );
00218         m_itemDeleteAction->addTo( m_itemContextMenu );
00219     }
00220 
00221     return m_itemContextMenu;
00222 }
00223 
00224 void OPimMainWindow::insertItemMenuItems( QActionGroup *items ) {
00225     // Insert menu items into Item menu
00226     if ( items ) {
00227         // Rebuild Item menu
00228         m_itemMenu->clear();
00229         m_itemMenuGroup1->addTo( m_itemMenu );
00230         m_itemMenu->insertSeparator();
00231         items->addTo( m_itemMenu );
00232         m_itemMenu->insertSeparator();
00233         m_itemMenuGroup2->addTo( m_itemMenu );
00234     }
00235 }
00236 
00237 void OPimMainWindow::insertViewMenuItems( QActionGroup *items ) {
00238     // Insert menu items into View menu
00239     if ( items ) {
00240         // Rebuild Item menu
00241         m_viewMenu->clear();
00242 //        m_viewMenuGroup->addTo( m_viewMenu );
00243 //        m_viewMenu->insertSeparator();
00244         m_viewMenuAppGroup = items;
00245         m_viewMenuAppGroup->addTo( m_viewMenu );
00246     }
00247 }
00248 
00249 void OPimMainWindow::setViewCategory( const QString &category ) {
00250     // Find category in list
00251     for ( int i = 0; i < m_catSelect->count(); i++ ) {
00252         if ( m_catSelect->text( i ) == category ) {
00253             m_catSelect->setCurrentItem( i );
00254             emit categorySelected( category );
00255             return;
00256         }
00257     }
00258 }
00259 
00260 void OPimMainWindow::reloadCategories() {
00261     QString selected = m_catSelect->currentText();
00262 
00263     // Remove old categories from list
00264     m_catSelect->clear();
00265 
00266     // Add categories to list
00267     Categories cats;
00268     cats.load( categoryFileName() );
00269     m_catSelect->insertItem( tr( "All" ) );
00270     m_catSelect->insertStringList( cats.labels( m_catGroupName ) );
00271     m_catSelect->insertItem( tr( "Unfiled" ) );
00272 }
00273 
00274 void OPimMainWindow::setItemNewEnabled( bool enable ) {
00275     m_itemNewAction->setEnabled( enable );
00276 }
00277 
00278 void OPimMainWindow::setItemEditEnabled( bool enable ) {
00279     m_itemEditAction->setEnabled( enable );
00280 }
00281 
00282 void OPimMainWindow::setItemDuplicateEnabled( bool enable ) {
00283     m_itemDuplicateAction->setEnabled( enable );
00284 }
00285 
00286 void OPimMainWindow::setItemDeleteEnabled( bool enable ) {
00287     m_itemDeleteAction->setEnabled( enable );
00288 }
00289 
00290 void OPimMainWindow::setItemBeamEnabled( bool enable ) {
00291     m_itemBeamAction->setEnabled( enable );
00292 }
00293 
00294 void OPimMainWindow::setConfigureEnabled( bool enable ) {
00295     m_configureAction->setEnabled( enable );
00296 }
00297 
00298 void OPimMainWindow::setShowCategories( bool show ) {
00299     show ? m_catSelect->show()
00300          : m_catSelect->hide();
00301 }
00302 
00303 void OPimMainWindow::initBars( const QString &itemName ) {
00304     QString itemStr = itemName.lower();
00305 
00306     setToolBarsMovable( false );
00307 
00308     // Create application menu bar
00309     QToolBar *mbHold = new QToolBar( this );
00310     mbHold->setHorizontalStretchable( true );
00311     QMenuBar *menubar = new QMenuBar( mbHold );
00312     menubar->setMargin( 0 );
00313 
00314     // Create application menu bar
00315     QToolBar *toolbar = new QToolBar( this );
00316 
00317     // Create sub-menus
00318     m_itemMenu = new QPopupMenu( this );
00319     m_itemMenu->setCheckable( true );
00320     menubar->insertItem( itemName, m_itemMenu );
00321     m_viewMenu = new QPopupMenu( this );
00322     m_viewMenu->setCheckable( true );
00323     menubar->insertItem( tr( "View" ), m_viewMenu );
00324 
00325     m_viewMenuAppGroup = 0l;
00326 
00327     // Item menu
00328     m_itemMenuGroup1 = new QActionGroup( this, QString::null, false );
00329 
00330     m_itemNewAction = new QAction( tr( "New" ),
00331                                   Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
00332                                   QString::null, 0, m_itemMenuGroup1, 0 );
00333     connect( m_itemNewAction, SIGNAL(activated()), this, SLOT(slotItemNew()) );
00334     m_itemNewAction->setWhatsThis( tr( "Click here to create a new item." ) );
00335     m_itemNewAction->addTo( toolbar );
00336 
00337     m_itemEditAction = new QAction( tr( "Edit" ),
00338                                     Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ),
00339                                     QString::null, 0, m_itemMenuGroup1, 0 );
00340     connect( m_itemEditAction, SIGNAL(activated()), this, SLOT(slotItemEdit()) );
00341     m_itemEditAction->setWhatsThis( tr( "Click here to edit the selected item." ) );
00342     m_itemEditAction->addTo( toolbar );
00343 
00344     m_itemDuplicateAction = new QAction( tr( "Duplicate" ),
00345                                          Opie::Core::OResource::loadPixmap( "copy", Opie::Core::OResource::SmallIcon ),
00346                                          QString::null, 0, m_itemMenuGroup1, 0 );
00347     connect( m_itemDuplicateAction, SIGNAL(activated()), this, SLOT(slotItemDuplicate()) );
00348     m_itemDuplicateAction->setWhatsThis( tr( "Click here to duplicate the selected item." ) );
00349 
00350     if ( Ir::supported() ) {
00351         m_itemBeamAction = new QAction( tr( "Beam" ),
00352                                         Opie::Core::OResource::loadPixmap( "beam", Opie::Core::OResource::SmallIcon ),
00353                                         QString::null, 0, m_itemMenuGroup1, 0 );
00354         connect( m_itemBeamAction, SIGNAL(activated()), this, SLOT(slotItemBeam()) );
00355         m_itemBeamAction->setWhatsThis( tr( "Click here to transmit the selected item." ) );
00356         m_itemBeamAction->addTo( toolbar );
00357     }
00358 
00359     m_itemDeleteAction = new QAction( tr( "Delete" ),
00360                                       Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ),
00361                                       QString::null, 0, m_itemMenuGroup1, 0 );
00362     connect( m_itemDeleteAction, SIGNAL(activated()), this, SLOT(slotItemDelete()) );
00363     m_itemDeleteAction->setWhatsThis( tr( "Click here to delete the selected item." ) );
00364     m_itemDeleteAction->addTo( toolbar );
00365 
00366     m_itemMenuGroup1->addTo( m_itemMenu );
00367 
00368     m_itemMenu->insertSeparator();
00369 
00370     m_itemMenuGroup2 = new QActionGroup( this, QString::null, false );
00371 
00372     m_configureAction = new QAction( tr( "Configure" ),
00373                                      Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ),
00374                                      QString::null, 0, m_itemMenuGroup2, 0 );
00375     connect( m_configureAction, SIGNAL(activated()), this, SLOT(slotConfigure()) );
00376     m_configureAction->setWhatsThis( tr( "Click here to set your preferences for this application." ) );
00377 
00378     m_itemMenuGroup2->addTo( m_itemMenu );
00379 
00380     // View menu
00381 //    m_viewMenuGroup = new QActionGroup( this, QString::null, false );
00382 
00383 //     QAction *a = new QAction( tr( "Filter" ), QString::null, 0, m_viewMenuGroup, 0 );
00384 //     connect( a, SIGNAL(activated()), this, SLOT(slotViewFilter()) );
00385 //     a->setWhatsThis( tr( "Click here to filter the items displayed." ) );
00386 //
00387 //     a = new QAction( tr( "Filter Settings" ), QString::null, 0, m_viewMenuGroup, 0 );
00388 //     connect( a, SIGNAL(activated()), this, SLOT(slotViewFilterSettings()) );
00389 //     a->setWhatsThis( tr( "Click here to modify the current filter settings." ) );
00390 
00391     // Create view toolbar
00392     toolbar = new QToolBar( this );
00393     m_catSelect = new QComboBox( toolbar );
00394     connect( m_catSelect, SIGNAL(activated(const QString&)), this, SIGNAL(categorySelected(const QString&)) );
00395     QWhatsThis::add( m_catSelect, tr( "Click here to filter items by category." ) );
00396 
00397     // Do initial load of categories
00398     reloadCategories();
00399 }
00400 
00401 } // namespace Opie

Generated on Sat Nov 5 16:16:23 2005 for OPIE by  doxygen 1.4.2