00001
00002 #include <qcopchannel_qws.h>
00003 #include <qwidgetstack.h>
00004 #include <qlabel.h>
00005 #include <qaction.h>
00006 #include <qpopupmenu.h>
00007 #include <qtimer.h>
00008
00009 #include <qpe/qpeapplication.h>
00010 #include <qpe/ir.h>
00011 #include <qmenubar.h>
00012 #include <qtoolbar.h>
00013 #include <qpe/qpemessagebox.h>
00014 #include <qpe/resource.h>
00015
00016 #include "editor.h"
00017 #include "show.h"
00018 #include "templatemanager.h"
00019 #include "bookmanager.h"
00020 #include "mainwindow.h"
00021
00022
00023 using namespace Datebook;
00024
00025 MainWindow::MainWindow()
00026 : OPimMainWindow( "Datebook", 0, 0 ), m_descMan( "Descriptions" ), m_locMan( "Locations" )
00027 {
00028 setIcon( Resource::loadPixmap( "datebook_icon" ) );
00029 initUI();
00030 initManagers();
00031 initView();
00032 initConfig();
00033
00034 QTimer::singleShot(0, this, SLOT(populate() ) );
00035
00036 QCopChannel* chan = new QCopChannel( "QPE/System", this );
00037 connect( chan, SIGNAL( received(const QCString&,const QByteArray&) ),
00038 this, SLOT( slotReceive(const QCString&,const QByteArray&) ) );
00039
00040 chan = new QCopChannel( "QPE/Datebook", this );
00041 connect( chan, SIGNAL( received(const QCString&,const QByteArray&) ),
00042 this, SLOT( slotReceive(const QCString&,const QByteArray&) ) );
00043 }
00044 MainWindow::~MainWindow() {
00045 m_tempMan.save();
00046 m_locMan.save();
00047 m_descMan.save();
00048
00049 manager()->save();
00050 delete m_manager;
00051 }
00052 void MainWindow::doSetDocument( const QString& str ) {
00053
00054 }
00055 void MainWindow::flush() {
00056 manager()->save();
00057 }
00058 void MainWindow::reload() {
00059 manager()->reload();
00060 }
00061 int MainWindow::create() {
00062 return 0;
00063 }
00064 bool MainWindow::remove( int uid ) {
00065 manager()->remove( uid );
00066 return true;
00067 }
00068 void MainWindow::beam( int uid ) {
00069
00070 }
00071 void MainWindow::show( int uid ) {
00072
00073 eventShow()->show( manager()->event( uid ) );
00074 }
00075 void MainWindow::add( const OPimRecord& ad) {
00076 manager()->add( ad );
00077 }
00078 void MainWindow::edit() {
00079 edit ( currentView()->currentItem() );
00080 }
00081 void MainWindow::edit( int uid ) {
00082
00083 }
00084
00085
00086
00087 void MainWindow::initUI() {
00088 setToolBarsMovable( false );
00089
00090 m_stack = new QWidgetStack( this );
00091 setCentralWidget( m_stack );
00092
00093 m_toolBar = new QToolBar( this );
00094 m_toolBar->setHorizontalStretchable( TRUE );
00095
00096 QMenuBar* mb = new QMenuBar( m_toolBar );
00097
00098 m_popView = new QPopupMenu( this );
00099 m_popSetting = new QPopupMenu( this );
00100
00101 mb->insertItem( tr("View"), m_popView );
00102 mb->insertItem( tr("Settings" ), m_popSetting );
00103
00104 m_popTemplate = new QPopupMenu( this );
00105 m_popTemplate->setCheckable( TRUE );
00106 connect( m_popTemplate, SIGNAL(activated(int) ),
00107 this, SLOT(slotNewFromTemplate(int) ) );
00108 m_popView->insertItem(tr("New from template"), m_popTemplate, -1, 0);
00109
00110
00111 QAction* a = new QAction( tr("New Event"), Resource::loadPixmap("new"),
00112 QString::null, 0, this, 0 );
00113 a->addTo( m_toolBar );
00114 a->addTo( m_popView );
00115 connect(a, SIGNAL( activated() ), this, SLOT( create() ) );
00116
00117 a = new QAction( tr("Edit Event"), Resource::loadPixmap("edit"),
00118 QString::null, 0, this, 0 );
00119 a->addTo( m_popView );
00120 connect(a, SIGNAL( activated() ), this, SLOT( edit() ) );
00121
00122 a = new QAction( tr("Today" ), Resource::loadPixmap( "datebook/to_day"),
00123 QString::null, 0, this, 0 );
00124 a->addTo( m_toolBar );
00125 connect(a, SIGNAL( activated() ), this, SLOT( slotGoToNow() ) );
00126
00127 a = new QAction( tr("Find"), Resource::loadPixmap( "mag" ),
00128 QString::null, 0, this, 0 );
00129 a->addTo( m_toolBar );
00130 connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) );
00131
00132 a = new QAction( tr("Configure"), QString::null, 0, 0 );
00133 a->addTo( m_popSetting );
00134 connect(a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) );
00135
00136 a = new QAction( tr("Configure Locations"), QString::null, 0, 0 );
00137 a->addTo( m_popSetting );
00138 connect(a, SIGNAL( activated() ), this, SLOT( slotConfigureLocs() ) );
00139
00140 a = new QAction( tr("Configure Descriptions"), QString::null, 0, 0 );
00141 a->addTo( m_popSetting );
00142 connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureDesc() ) );
00143
00144 a = new QAction( tr("Configure Templates"), QString::null, 0, 0 );
00145 a->addTo( m_popSetting );
00146 connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureTemp() ) );
00147
00148 connect( qApp, SIGNAL(clockChanged(bool) ),
00149 this, SLOT(slotClockChanged(bool) ) );
00150 connect( qApp, SIGNAL(weekChanged(bool) ),
00151 this, SLOT(slotWeekChanged(bool) ) );
00152
00153 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&) ),
00154 this, SLOT(slotAppMessage(const QCString&,const QByteArray&) ) );
00155 }
00156 void MainWindow::initConfig() {
00157
00158 }
00159 void MainWindow::initView() {
00160
00161 }
00162 void MainWindow::initManagers() {
00163 m_manager = new BookManager;
00164
00165 m_tempMan.load();
00166 m_locMan.load();
00167 m_descMan.load();
00168
00169 setTemplateMenu();
00170 }
00171 void MainWindow::raiseCurrentView() {
00172
00173 }
00174
00175
00176
00177 void MainWindow::populate() {
00178 if (!manager()->isLoaded() )
00179 manager()->load();
00180 }
00181 void MainWindow::slotGoToNow() {
00182
00183 }
00184 View* MainWindow::currentView() {
00185
00186 }
00187 void MainWindow::slotFind() {
00188
00189 }
00190 void MainWindow::slotConfigure() {
00191
00192 }
00193 void MainWindow::slotClockChanged( bool ) {
00194
00195 }
00196 void MainWindow::slotWeekChanged(bool ) {
00197
00198 }
00199 void MainWindow::slotAppMessage( const QCString&, const QByteArray& ) {
00200
00201 }
00202 void MainWindow::slotReceive( const QCString&, const QByteArray& ) {
00203
00204 }
00205 BookManager* MainWindow::manager() {
00206 return m_manager;
00207 }
00208 TemplateManager MainWindow::templateManager() {
00209 return m_tempMan;
00210 }
00211 LocationManager MainWindow::locationManager() {
00212 return m_locMan;
00213 }
00214 DescriptionManager MainWindow::descriptionManager() {
00215 return m_descMan;
00216 }
00217 void MainWindow::setLocationManager( const LocationManager& loc) {
00218 m_locMan = loc;
00219 }
00220 void MainWindow::setDescriptionManager( const DescriptionManager& dsc ) {
00221 m_descMan = dsc;
00222 }
00223 Show* MainWindow::eventShow() {
00224 return m_show;
00225 }
00226 void MainWindow::slotAction( QAction* act ) {
00227
00228 }
00229 void MainWindow::slotConfigureLocs() {
00230 LocationManagerDialog dlg( locationManager() );
00231 dlg.setCaption( tr("Configure Locations") );
00232 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) {
00233 setLocationManager( dlg.manager() );
00234 }
00235 }
00236 void MainWindow::slotConfigureDesc() {
00237 DescriptionManagerDialog dlg( descriptionManager() );
00238 dlg.setCaption( tr("Configure Descriptions") );
00239 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) {
00240 setDescriptionManager( dlg.manager() );
00241 }
00242 }
00243 void MainWindow::slotConfigureTemp() {
00244 TemplateDialog dlg( templateManager(), editor() );
00245 dlg.setCaption( tr("Configure Templates") );
00246 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) {
00247 m_tempMan = dlg.manager();
00248 setTemplateMenu();
00249 }
00250 }
00251 void MainWindow::hideShow() {
00252
00253 }
00254 void MainWindow::viewPopup(int ) {
00255
00256 }
00257 void MainWindow::viewAdd(const QDate& ) {
00258
00259 }
00260 void MainWindow::viewAdd( const QDateTime&, const QDateTime& ) {
00261
00262 }
00263 bool MainWindow::viewAP()const{
00264 }
00265 bool MainWindow::viewStartMonday()const {
00266
00267 }
00268 void MainWindow::setTemplateMenu() {
00269 m_popTemplate->clear();
00270
00271 QStringList list = templateManager().names();
00272 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
00273 m_popTemplate->insertItem( (*it) );
00274 }
00275 }
00276
00277
00278
00279
00280 void MainWindow::slotNewFromTemplate(int id ) {
00281 QString name = m_popTemplate->text( id );
00282
00283 OEvent ev = templateManager().value( name );
00284
00285 if ( editor()->edit( ev ) ) {
00286 ev = editor()->event();
00287 ev.setUid( -1 );
00288 manager()->add( ev );
00289
00290
00291
00292
00293
00294
00295
00296 currentView()->reschedule();
00297 raiseCurrentView();
00298 }
00299 }
00300 Editor* MainWindow::editor() {
00301 return m_edit;
00302 }