00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00093 connect( btn, SIGNAL( clicked() ), this, SLOT( slotNew() ) );
00094 layout->addWidget( btn, 1, 0 );
00095
00096 #if 0
00097 btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ),
00098 tr( "Edit" ), this );
00099
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
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
00163 case 0:
00164 return inlineSetDate( item, p );
00165
00166 case 1:
00167 return inlineSetTime( item );
00168
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 }