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

taskeditoralarms.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C) Opie Team <opie-devel@handhelds.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #include "taskeditoralarms.h"
00032 
00033 #include <opie2/opimnotifymanager.h>
00034 #include <opie2/oresource.h>
00035 #include <opie2/otimepicker.h>
00036 
00037 #include <qpe/datebookmonth.h>
00038 
00039 #include <qlistview.h>
00040 #include <qlayout.h>
00041 
00042 
00043 using namespace Opie::Ui;
00044 class AlarmItem : public QListViewItem {
00045 public:
00046     AlarmItem( QListView*, const OPimAlarm& );
00047     ~AlarmItem();
00048 
00049     OPimAlarm alarm()const;
00050     void setAlarm( const OPimAlarm& );
00051 private:
00052     QDateTime m_dt;
00053     int m_type;
00054 };
00055 AlarmItem::AlarmItem( QListView* view, const OPimAlarm& dt)
00056     : QListViewItem(view) {
00057     setAlarm( dt );
00058 }
00059 void AlarmItem::setAlarm( const OPimAlarm& dt ) {
00060     m_dt = dt.dateTime();
00061     m_type = dt.sound();
00062     setText( 0, TimeString::dateString( m_dt.date() ) );
00063     setText( 1, TimeString::timeString( m_dt.time() ) );
00064     setText( 2, m_type == 0 ? QObject::tr("silent") : QObject::tr("loud") );
00065 }
00066 AlarmItem::~AlarmItem() {
00067 }
00068 OPimAlarm AlarmItem::alarm()const{
00069     OPimAlarm al( m_type, m_dt );
00070 
00071     return al;
00072 }
00073 
00074 TaskEditorAlarms::TaskEditorAlarms( QWidget* parent,  int, const char* name, WFlags fl )
00075     : QWidget( parent, name, fl )
00076 {
00077     m_date = m_type = m_time = 0;
00078     QGridLayout *layout = new QGridLayout( this, 2, 2, 4, 4 );
00079 
00080     lstAlarms = new QListView( this );
00081     lstAlarms->addColumn( tr("Date") );
00082     lstAlarms->addColumn( tr("Time") );
00083     lstAlarms->addColumn( tr("Type") );
00084 
00085     connect( lstAlarms, SIGNAL(clicked(QListViewItem*,const QPoint&,int) ),
00086              this, SLOT(inlineEdit(QListViewItem*,const QPoint&,int) ) );
00087 
00088     layout->addMultiCellWidget( lstAlarms, 0, 0, 0, 2 );
00089 
00090     QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
00091                                         tr( "New" ), this );
00092     //QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) );
00093     connect( btn, SIGNAL( clicked() ), this, SLOT( slotNew() ) );
00094     layout->addWidget( btn, 1, 0 );
00095 /* use when we've reminders too */
00096 #if 0
00097     btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ),
00098                            tr( "Edit" ), this );
00099     //QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) );
00100     connect( btn, SIGNAL( clicked() ), this, SLOT( slotEdit() ) );
00101     layout->addWidget( btn, 1, 1 );
00102 #endif
00103 
00104     btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ),
00105                            tr( "Delete" ), this );
00106     //QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) );
00107     connect( btn, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
00108     layout->addWidget( btn, 1, 2 );
00109 }
00110 
00111 TaskEditorAlarms::~TaskEditorAlarms(){
00112 }
00113 
00114 void TaskEditorAlarms::slotNew(){
00115     (void)new AlarmItem(lstAlarms, OPimAlarm(0, QDateTime::currentDateTime() ) );
00116 }
00117 
00118 void TaskEditorAlarms::slotEdit(){
00119 }
00120 
00121 void TaskEditorAlarms::slotDelete(){
00122     QListViewItem* item = lstAlarms->currentItem();
00123     if (!item) return;
00124 
00125     lstAlarms->takeItem( item ); delete item;
00126 
00127 
00128 }
00129 
00130 void TaskEditorAlarms::load( const OPimTodo& todo) {
00131     lstAlarms->clear();
00132     if (!todo.hasNotifiers() ) return;
00133 
00134     OPimNotifyManager::Alarms als = todo.notifiers().alarms();
00135 
00136     if (als.isEmpty() ) return;
00137 
00138     OPimNotifyManager::Alarms::Iterator it = als.begin();
00139     for ( ; it != als.end(); ++it )
00140         (void)new AlarmItem( lstAlarms, (*it) );
00141 
00142 
00143 }
00144 void TaskEditorAlarms::save( OPimTodo& todo ) {
00145     if (lstAlarms->childCount() <= 0 ) return;
00146 
00147     OPimNotifyManager::Alarms alarms;
00148 
00149     for ( QListViewItem* item = lstAlarms->firstChild(); item; item = item->nextSibling() ) {
00150         AlarmItem *alItem = static_cast<AlarmItem*>(item);
00151         alarms.append( alItem->alarm() );
00152     }
00153 
00154     OPimNotifyManager& manager = todo.notifiers();
00155     manager.setAlarms( alarms );
00156 }
00157 void TaskEditorAlarms::inlineEdit( QListViewItem* alarm, const QPoint& p, int col ) {
00158     if (!alarm) return;
00159 
00160     AlarmItem* item = static_cast<AlarmItem*>(alarm);
00161     switch( col ) {
00162         // date
00163     case 0:
00164         return inlineSetDate( item, p );
00165         // time
00166     case 1:
00167         return inlineSetTime( item );
00168         // type
00169     case 2:
00170         return inlineSetType( item, p );
00171     }
00172 }
00173 void TaskEditorAlarms::inlineSetDate( AlarmItem* item, const QPoint& p ) {
00174     QPopupMenu* pop = popup( 0 );
00175     m_dbMonth->setDate( item->alarm().dateTime().date() );
00176     pop->exec(p);
00177 
00178     OPimAlarm al = item->alarm();
00179     QDateTime dt = al.dateTime();
00180     dt.setDate( m_dbMonth->selectedDate() );
00181     al.setDateTime( dt );
00182     item->setAlarm( al );
00183 }
00184 void TaskEditorAlarms::inlineSetType( AlarmItem* item, const QPoint& p ) {
00185     int type;
00186     QPopupMenu* pop = popup( 2 );
00187     switch( pop->exec(p) ) {
00188     case 10:
00189         type = 1;
00190         break;
00191     case 20:
00192     default:
00193         type = 0;
00194     }
00195     OPimAlarm al = item->alarm();
00196     al.setSound( type );
00197     item->setAlarm( al );
00198 }
00199 void TaskEditorAlarms::inlineSetTime( AlarmItem* item ) {
00200     OPimAlarm al = item->alarm();
00201     QDateTime dt = al.dateTime();
00202 
00203     OTimePickerDialog dialog;
00204     dialog.setTime( dt.time() );
00205     if ( dialog.exec() == QDialog::Accepted ) {
00206         dt.setTime( dialog.time() );
00207         al.setDateTime( dt );
00208         item->setAlarm( al );
00209     }
00210 }
00211 QPopupMenu* TaskEditorAlarms::popup( int column ) {
00212     QPopupMenu* pop = 0;
00213     switch( column ) {
00214     case 0:{
00215         if (!m_date) {
00216             m_date = new QPopupMenu(this);
00217             m_dbMonth = new DateBookMonth(m_date, 0, TRUE);
00218             m_date->insertItem(m_dbMonth);
00219         }
00220         pop = m_date;
00221     }
00222         break;
00223     case 1:
00224         break;
00225     case 2:{
00226         if (!m_type) {
00227             m_type = new QPopupMenu(this);
00228             m_type->insertItem( QObject::tr("loud"), 10 );
00229             m_type->insertItem( QObject::tr("silent"), 20 );
00230         }
00231         pop = m_type;
00232     }
00233         break;
00234     default:
00235         break;
00236     }
00237     return pop;
00238 }

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