calendarui/views/src/calenagendaview.cpp
changeset 45 b6db4fd4947b
child 51 0b38fc5b94c6
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CalenAgendaView implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <QGraphicsSceneEvent>
       
    20 #include <hbmainwindow.h>
       
    21 #include <hbaction.h>
       
    22 #include <hbpangesture.h>
       
    23 #include <hbswipegesture.h>
       
    24 #include <hbapplication.h> // hbapplication
       
    25 #include <hbactivitymanager.h> // Activity Manager
       
    26 
       
    27 // User includes
       
    28 #include "calenagendaview.h"
       
    29 #include "calendocloader.h"
       
    30 #include "calenagendaviewwidget.h"
       
    31 #include "calenservices.h"
       
    32 #include "calencommon.h"
       
    33 #include "calencontext.h"
       
    34 #include "calendateutils.h"
       
    35 #include "calenconstants.h"
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // CalenAgendaView::CalenAgendaView
       
    39 // Rest of the details are commented in the header
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 CalenAgendaView::CalenAgendaView(MCalenServices &services):
       
    43 CalenNativeView(services),
       
    44 mSoftKeyAction(NULL),
       
    45 mGoToTodayAction(NULL),
       
    46 mSwitchToDayViewAction(NULL),
       
    47 mActionTaken(false),
       
    48 mIsAboutToQuitEventConnected(false)
       
    49 {
       
    50     // No implementation yet
       
    51     grabGesture(Qt::SwipeGesture);
       
    52 }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CalenAgendaView::~CalenAgendaView
       
    56 // Rest of the details are commented in the header
       
    57 // ----------------------------------------------------------------------------
       
    58 //    
       
    59 CalenAgendaView::~CalenAgendaView()
       
    60 {
       
    61     // No implementation yet
       
    62 }
       
    63 
       
    64 // ----------------------------------------------------------------------------
       
    65 // CalenAgendaView::setupView
       
    66 // Rest of the details are commented in the header
       
    67 // ----------------------------------------------------------------------------
       
    68 //    
       
    69 void CalenAgendaView::setupView(CalenDocLoader *docLoader)
       
    70 {
       
    71     if (!docLoader) {
       
    72         // Nothing can be done. Simply return
       
    73         return;
       
    74     }
       
    75     // Store the document loader for reference later
       
    76 	mDocLoader = docLoader;
       
    77 	
       
    78 	// Listen to orientation change events
       
    79 	connect(&(mServices.MainWindow()), SIGNAL(orientationChanged(Qt::Orientation)),
       
    80 	        this, SLOT(orientationChanged(Qt::Orientation)));
       
    81 	
       
    82 	// Get the pointer to the content widget
       
    83 	mAgendaViewWidget = qobject_cast<CalenAgendaViewWidget*>(mDocLoader->findWidget(CALEN_AGENDAVIEW_WIDGET));
       
    84 	if (!mAgendaViewWidget) {
       
    85 	    qFatal("calenagendaview.cpp : Unable to find the content widget");
       
    86 	}
       
    87 	mAgendaViewWidget->setupWidget(this);
       
    88 	
       
    89 	// Initialize all the menu and toolbar actions
       
    90 	setupActions();
       
    91 	// get a poitner to activity manager
       
    92 	HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
    93 
       
    94 	// clean up any previous versions of this activity, if any, i.e. activityName, from the activity manager. 
       
    95 	// Ignore return value, first boot would always return False. bool declared 
       
    96 	// only for debugging purpose.
       
    97 	bool ok = activityManager->removeActivity(activityName);
       
    98 	
       
    99 }
       
   100 
       
   101 // ----------------------------------------------------------------------------
       
   102 // CalenAgendaView::doPopulation
       
   103 // Rest of the details are commented in the header
       
   104 // ----------------------------------------------------------------------------
       
   105 // 
       
   106 void CalenAgendaView::doPopulation()
       
   107     {
       
   108     // The content widget has not been constructed. Don't do anything
       
   109     if (!mAgendaViewWidget) {
       
   110         return;
       
   111     }
       
   112     // Get the day for which this view is being shown from the context
       
   113     mDate = mServices.Context().focusDateAndTime();
       
   114     
       
   115     // Check if the current day being shown is "Today"
       
   116     if (mGoToTodayAction) {
       
   117         if (mDate.date() == CalenDateUtils::today().date()) {
       
   118             // Hide the "Go to today" option
       
   119             mGoToTodayAction->setVisible(false);
       
   120         } else {
       
   121             mGoToTodayAction->setVisible(true);
       
   122         }
       
   123     }
       
   124     
       
   125     // Set self as the current view
       
   126     // mServices.MainWindow().setCurrentView(this);
       
   127     
       
   128     // Dont override the soft key behavior if day view is the first view
       
   129     if (ECalenAgendaView != mServices.getFirstView()) {
       
   130 		mSoftKeyAction = new HbAction(Hb::BackNaviAction);
       
   131 		setNavigationAction(mSoftKeyAction);
       
   132 		// Connect to the signal triggered by clicking on back button.
       
   133 		connect(mSoftKeyAction, SIGNAL(triggered()), this,
       
   134 		        SLOT(launchMonthView()));
       
   135 		if (mSwitchToDayViewAction) {
       
   136 			mSwitchToDayViewAction->setVisible(true);
       
   137 				}
       
   138 	} else {
       
   139 		if (mSwitchToDayViewAction) {
       
   140 			mSwitchToDayViewAction->setVisible(false);
       
   141 		}
       
   142 	}
       
   143     // Initialize the content widget
       
   144     mAgendaViewWidget->showWidget();
       
   145     
       
   146 	//set Current Activity as day view
       
   147     mActivityId = ECalenAgendaView;
       
   148 
       
   149 	// connect to receive a call back on Day View exit. Call back would result in saveActivity 
       
   150 	// to be called in Native View
       
   151     if (!mIsAboutToQuitEventConnected) // check if already not connected
       
   152         {
       
   153         connect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
   154 		mIsAboutToQuitEventConnected = true;
       
   155         }
       
   156 
       
   157 
       
   158     // Population is complete, issue a notification
       
   159     populationComplete();
       
   160     }
       
   161 
       
   162 /*!
       
   163  Funtion to refresh the current view upon selecting a date
       
   164  from GoToDate popup
       
   165  */
       
   166 void CalenAgendaView::refreshViewOnGoToDate()
       
   167 {
       
   168 	// Get the day for which this view is being shown from the context
       
   169 	mDate = mServices.Context().focusDateAndTime();
       
   170 	
       
   171 	// Check if the current day being shown is "Today"
       
   172 	if (mGoToTodayAction) {
       
   173 		if (mDate.date() == CalenDateUtils::today().date()) {
       
   174 			// Hide the "Go to today" option
       
   175 			mGoToTodayAction->setVisible(false);
       
   176 		} else {
       
   177 			mGoToTodayAction->setVisible(true);
       
   178 		}
       
   179 	}
       
   180 	
       
   181 	// Initialize the content widget
       
   182 	mAgendaViewWidget->showWidget();
       
   183 }
       
   184 
       
   185 // ----------------------------------------------------------------------------
       
   186 // CalenAgendaView::HandleNotification
       
   187 // Rest of the details are commented in the header
       
   188 // ----------------------------------------------------------------------------
       
   189 //    
       
   190 void CalenAgendaView::HandleNotification(const TCalenNotification notification)
       
   191 {
       
   192     Q_UNUSED(notification)
       
   193     // No implementation yet
       
   194 }
       
   195 
       
   196 // ----------------------------------------------------------------------------
       
   197 // CalenAgendaView::docLoader
       
   198 // Rest of the details are commented in the header
       
   199 // ----------------------------------------------------------------------------
       
   200 //    
       
   201 CalenDocLoader* CalenAgendaView::docLoader()
       
   202 {
       
   203     return mDocLoader;
       
   204 }
       
   205 
       
   206 /*
       
   207 	Function to listen for gestures
       
   208 */
       
   209 void CalenAgendaView::gestureEvent(QGestureEvent *event)
       
   210 {
       
   211     if(HbSwipeGesture *gesture = qobject_cast<HbSwipeGesture *>(event->gesture(Qt::SwipeGesture))) {
       
   212         if (gesture->state() == Qt::GestureStarted) {
       
   213             if(QSwipeGesture::Left == gesture->sceneHorizontalDirection()) {
       
   214                 mServices.IssueCommandL(ECalenShowNextDay);
       
   215                 event->accept(Qt::SwipeGesture);
       
   216             } else if(QSwipeGesture::Right == gesture->sceneHorizontalDirection()) {
       
   217                 mServices.IssueCommandL(ECalenShowPrevDay);
       
   218                event->accept(Qt::SwipeGesture);
       
   219             }
       
   220         }
       
   221     } 
       
   222 }
       
   223 
       
   224 // ----------------------------------------------------------------------------
       
   225 // CalenAgendaView::createToolBar
       
   226 // Rest of the details are commented in the header
       
   227 // ----------------------------------------------------------------------------
       
   228 //
       
   229 void CalenAgendaView::setupActions()
       
   230 {
       
   231 	// Get the actions associated with this view
       
   232 	HbAction *newEventAction = qobject_cast<HbAction *>
       
   233                                 (mDocLoader->findObject(CALEN_AGENDAVIEW_MENU_NEW_EVENT));
       
   234 	if (!newEventAction) {
       
   235 	    qFatal("calenagendaview.cpp : Unable to find new event action");
       
   236 	}
       
   237 	// Connect to the signal triggered by new event action
       
   238 	connect(newEventAction, SIGNAL(triggered()), mAgendaViewWidget, SLOT(createNewEvent()));
       
   239 	
       
   240 	mGoToTodayAction = qobject_cast<HbAction *>
       
   241                         (mDocLoader->findObject(CALEN_AGENDAVIEW_MENU_GO_TO_TODAY));
       
   242 	if (!mGoToTodayAction) {
       
   243 	    qFatal("calenagendaview.cpp : Unable to find go to today action");
       
   244 	}
       
   245 	// Connect to the signal triggered by go to Today action
       
   246 	connect(mGoToTodayAction, SIGNAL(triggered()), mAgendaViewWidget, SLOT(goToToday()));
       
   247 	
       
   248 	HbAction *goToDateAction = qobject_cast<HbAction *>
       
   249                                 (mDocLoader->findObject(CALEN_AGENDAVIEW_MENU_GO_TO_DATE));
       
   250 	if (!goToDateAction) {
       
   251 	    qFatal("calenagendaview.cpp : Unable to find go to date action");
       
   252 	}
       
   253 	// Connect to the signal triggered by go to Date action
       
   254 	connect(goToDateAction, SIGNAL(triggered()), this, SLOT(goToDate()));
       
   255 	
       
   256 	mSwitchToDayViewAction = qobject_cast<HbAction *>
       
   257 	                                (mDocLoader->findObject(CALEN_AGENDAVIEW_MENU_SWITCH_TO_DAYVIEW));
       
   258 	if (!mSwitchToDayViewAction) {
       
   259 		    qFatal("calenagendaview.cpp : Unable to find go to date action");
       
   260 		}
       
   261 	// Connect to the signal triggered by switch to dayview action
       
   262 	connect(mSwitchToDayViewAction, SIGNAL(triggered()), this, SLOT(launchDayView()));
       
   263 	
       
   264 	HbAction *settingsAction = qobject_cast<HbAction *>
       
   265                                 (mDocLoader->findObject(CALEN_AGENDAVIEW_MENU_SETTINGS));
       
   266 	if (!settingsAction) {
       
   267 	    qFatal("calenagendaview.cpp : Unable to find settings action");
       
   268 	}
       
   269 	// Connect to the signal triggered by settings action
       
   270 	connect(settingsAction, SIGNAL(triggered()), this, SLOT(launchSettingsView()));
       
   271 }
       
   272 
       
   273 // ----------------------------------------------------------------------------
       
   274 // CalenAgendaView::onLocaleChanged
       
   275 // Rest of the details are commented in the header
       
   276 // ----------------------------------------------------------------------------
       
   277 //    
       
   278 void CalenAgendaView::onLocaleChanged(int reason)
       
   279 {
       
   280     Q_UNUSED(reason)
       
   281     // Notify the content widget about the change
       
   282     if(mAgendaViewWidget) {
       
   283     mAgendaViewWidget->handleLocaleChange();
       
   284     }
       
   285 }
       
   286 
       
   287 // ----------------------------------------------------------------------------
       
   288 // CalenAgendaView::orientationChanged
       
   289 // Rest of the details are commented in the header
       
   290 // ----------------------------------------------------------------------------
       
   291 // 
       
   292 void CalenAgendaView::orientationChanged(Qt::Orientation orientation)
       
   293 {
       
   294     // Notify the content widget about the change
       
   295     if (mAgendaViewWidget) {
       
   296     mAgendaViewWidget->orientationChanged(orientation);
       
   297     }
       
   298 }
       
   299 
       
   300 // ----------------------------------------------------------------------------
       
   301 // CalenAgendaView::launchMonthView
       
   302 // ----------------------------------------------------------------------------
       
   303 //    
       
   304 void CalenAgendaView::launchMonthView()
       
   305 {
       
   306     // Issue the command to launch the month view
       
   307     mServices.IssueCommandL(ECalenMonthView);
       
   308 	// month view launched now, disconnect to get the call backs for saveActivity 
       
   309 	// on aboutToQuit signal
       
   310     disconnectAboutToQuitEvent();
       
   311 }
       
   312 
       
   313 // ----------------------------------------------------------------------------
       
   314 // CalenAgendaView::launchDayView
       
   315 // ----------------------------------------------------------------------------
       
   316 //    
       
   317 void CalenAgendaView::launchDayView()
       
   318 {
       
   319     // Issue the command to launch the day view
       
   320     mServices.IssueCommandL(ECalenDayView);
       
   321 }
       
   322 
       
   323 // ----------------------------------------------------------------------------
       
   324 // clears the list model 
       
   325 // ----------------------------------------------------------------------------
       
   326 // 
       
   327 void CalenAgendaView::clearListModel()
       
   328     {
       
   329 	// day view is removed from the list disconnect for aboutToQuit events
       
   330     disconnectAboutToQuitEvent();
       
   331     mAgendaViewWidget->clearListModel();
       
   332     }
       
   333 
       
   334 // ----------------------------------------------------------------------------
       
   335 // disconnectAboutToQuitEvent disconnects for the aboutToQuit events
       
   336 // ----------------------------------------------------------------------------
       
   337 // 
       
   338 void CalenAgendaView::disconnectAboutToQuitEvent()
       
   339     {
       
   340     if (mIsAboutToQuitEventConnected)
       
   341         {
       
   342         disconnect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
   343         mIsAboutToQuitEventConnected = false;
       
   344         }
       
   345     }
       
   346 
       
   347 // End of file	--Don't remove this.