calendarui/views/src/calendayview.cpp
changeset 50 579cc610882e
parent 49 5de72ea7a065
child 53 e08ac1a3ba2b
child 58 ef813d54df51
equal deleted inserted replaced
49:5de72ea7a065 50:579cc610882e
     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:  CalenDayView 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 "calendayview.h"
       
    29 #include "calendocloader.h"
       
    30 #include "calendayviewwidget.h"
       
    31 #include "calenservices.h"
       
    32 #include "calencommon.h"
       
    33 #include "calencontext.h"
       
    34 #include "calendateutils.h"
       
    35 #include "calenconstants.h"
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // CalenDayView::CalenDayView
       
    39 // Rest of the details are commented in the header
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 CalenDayView::CalenDayView(MCalenServices &services):
       
    43 CalenNativeView(services),
       
    44 mSoftKeyAction(NULL),
       
    45 mGoToTodayAction(NULL),
       
    46 mActionTaken(false),
       
    47 mIsAboutToQuitEventConnected(false)
       
    48 {
       
    49     // No implementation yet
       
    50     grabGesture(Qt::SwipeGesture);
       
    51 }
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // CCalenDayView::~CalenDayView
       
    55 // Rest of the details are commented in the header
       
    56 // ----------------------------------------------------------------------------
       
    57 //    
       
    58 CalenDayView::~CalenDayView()
       
    59 {
       
    60     // No implementation yet
       
    61 }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // CCalenDayView::setupView
       
    65 // Rest of the details are commented in the header
       
    66 // ----------------------------------------------------------------------------
       
    67 //    
       
    68 void CalenDayView::setupView(CalenDocLoader *docLoader)
       
    69 {
       
    70     if (!docLoader) {
       
    71         // Nothing can be done. Simply return
       
    72         return;
       
    73     }
       
    74     // Store the document loader for reference later
       
    75 	mDocLoader = docLoader;
       
    76 	
       
    77 	// Listen to orientation change events
       
    78 	connect(&(mServices.MainWindow()), SIGNAL(orientationChanged(Qt::Orientation)),
       
    79 	        this, SLOT(orientationChanged(Qt::Orientation)));
       
    80 	
       
    81 	// Get the pointer to the content widget
       
    82 	mDayViewWidget = qobject_cast<CalenDayViewWidget*>(mDocLoader->findWidget(CALEN_DAYVIEW_WIDGET));
       
    83 	if (!mDayViewWidget) {
       
    84 	    qFatal("calendayview.cpp : Unable to find the content widget");
       
    85 	}
       
    86 	mDayViewWidget->setupWidget(this);
       
    87 	
       
    88 	// Initialize all the menu and toolbar actions
       
    89 	setupActions();
       
    90 	// get a poitner to activity manager
       
    91 	HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
    92 
       
    93 	// clean up any previous versions of this activity, if any, i.e. activityName, from the activity manager. 
       
    94 	// Ignore return value, first boot would always return False. bool declared 
       
    95 	// only for debugging purpose.
       
    96 	bool ok = activityManager->removeActivity(activityName);
       
    97 	
       
    98 }
       
    99 
       
   100 // ----------------------------------------------------------------------------
       
   101 // CCalenDayView::doPopulation
       
   102 // Rest of the details are commented in the header
       
   103 // ----------------------------------------------------------------------------
       
   104 // 
       
   105 void CalenDayView::doPopulation()
       
   106     {
       
   107     // The content widget has not been constructed. Don't do anything
       
   108     if (!mDayViewWidget) {
       
   109         return;
       
   110     }
       
   111     // Get the day for which this view is being shown from the context
       
   112     mDate = mServices.Context().focusDateAndTimeL();
       
   113     
       
   114     // Check if the current day being shown is "Today"
       
   115     if (mGoToTodayAction) {
       
   116         if (mDate.date() == CalenDateUtils::today().date()) {
       
   117             // Hide the "Go to today" option
       
   118             mGoToTodayAction->setVisible(false);
       
   119         } else {
       
   120             mGoToTodayAction->setVisible(true);
       
   121         }
       
   122     }
       
   123     
       
   124     // Set self as the current view
       
   125     // mServices.MainWindow().setCurrentView(this);
       
   126     
       
   127     // Dont override the soft key behavior if day view is the first view
       
   128     if (ECalenDayView != mServices.getFirstView()) {
       
   129 		mSoftKeyAction = new HbAction(Hb::BackNaviAction);
       
   130 		setNavigationAction(mSoftKeyAction);
       
   131 		// Connect to the signal triggered by clicking on back button.
       
   132 		connect(mSoftKeyAction, SIGNAL(triggered()), this,
       
   133 		        SLOT(launchMonthView()));
       
   134 	}
       
   135     // Initialize the content widget
       
   136     mDayViewWidget->showWidget();
       
   137     
       
   138 	//set Current Activity as day view
       
   139     mActivityId = ECalenDayView;
       
   140 
       
   141 	// connect to receive a call back on Day View exit. Call back would result in saveActivity 
       
   142 	// to be called in Native View
       
   143     if (!mIsAboutToQuitEventConnected) // check if already not connected
       
   144         {
       
   145         connect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
   146 		mIsAboutToQuitEventConnected = true;
       
   147         }
       
   148 
       
   149 
       
   150     // Population is complete, issue a notification
       
   151     populationComplete();
       
   152     }
       
   153 
       
   154 /*!
       
   155  Funtion to refresh the current view upon selecting a date
       
   156  from GoToDate popup
       
   157  */
       
   158 void CalenDayView::refreshViewOnGoToDate()
       
   159 {
       
   160 	// Get the day for which this view is being shown from the context
       
   161 	mDate = mServices.Context().focusDateAndTimeL();
       
   162 	
       
   163 	// Check if the current day being shown is "Today"
       
   164 	if (mGoToTodayAction) {
       
   165 		if (mDate.date() == CalenDateUtils::today().date()) {
       
   166 			// Hide the "Go to today" option
       
   167 			mGoToTodayAction->setVisible(false);
       
   168 		} else {
       
   169 			mGoToTodayAction->setVisible(true);
       
   170 		}
       
   171 	}
       
   172 	
       
   173 	// Initialize the content widget
       
   174 	mDayViewWidget->showWidget();
       
   175 }
       
   176 
       
   177 // ----------------------------------------------------------------------------
       
   178 // CCalenDayView::HandleNotification
       
   179 // Rest of the details are commented in the header
       
   180 // ----------------------------------------------------------------------------
       
   181 //    
       
   182 void CalenDayView::HandleNotification(const TCalenNotification notification)
       
   183 {
       
   184     Q_UNUSED(notification)
       
   185     // No implementation yet
       
   186 }
       
   187 
       
   188 // ----------------------------------------------------------------------------
       
   189 // CCalenDayView::docLoader
       
   190 // Rest of the details are commented in the header
       
   191 // ----------------------------------------------------------------------------
       
   192 //    
       
   193 CalenDocLoader* CalenDayView::docLoader()
       
   194 {
       
   195     return mDocLoader;
       
   196 }
       
   197 
       
   198 /*
       
   199 	Function to listen for gestures
       
   200 */
       
   201 void CalenDayView::gestureEvent(QGestureEvent *event)
       
   202 {
       
   203     if(HbSwipeGesture *gesture = qobject_cast<HbSwipeGesture *>(event->gesture(Qt::SwipeGesture))) {
       
   204         if (gesture->state() == Qt::GestureStarted) {
       
   205             if(QSwipeGesture::Left == gesture->horizontalDirection()) {
       
   206                 mServices.IssueCommandL(ECalenShowNextDay);
       
   207                 event->accept(Qt::SwipeGesture);
       
   208             } else if(QSwipeGesture::Right == gesture->horizontalDirection()) {
       
   209                 mServices.IssueCommandL(ECalenShowPrevDay);
       
   210                event->accept(Qt::SwipeGesture);
       
   211             }
       
   212         }
       
   213     } 
       
   214 }
       
   215 
       
   216 // ----------------------------------------------------------------------------
       
   217 // CCalenDayView::createToolBar
       
   218 // Rest of the details are commented in the header
       
   219 // ----------------------------------------------------------------------------
       
   220 //
       
   221 void CalenDayView::setupActions()
       
   222 {
       
   223 	// Get the actions associated with this view
       
   224 	HbAction *newEventAction = qobject_cast<HbAction *>
       
   225                                 (mDocLoader->findObject(CALEN_DAYVIEW_MENU_NEW_EVENT));
       
   226 	if (!newEventAction) {
       
   227 	    qFatal("calendayview.cpp : Unable to find new event action");
       
   228 	}
       
   229 	// Connect to the signal triggered by new event action
       
   230 	connect(newEventAction, SIGNAL(triggered()), mDayViewWidget, SLOT(createNewEvent()));
       
   231 	
       
   232 	mGoToTodayAction = qobject_cast<HbAction *>
       
   233                         (mDocLoader->findObject(CALEN_DAYVIEW_MENU_GO_TO_TODAY));
       
   234 	if (!mGoToTodayAction) {
       
   235 	    qFatal("calendayview.cpp : Unable to find go to today action");
       
   236 	}
       
   237 	// Connect to the signal triggered by new event action
       
   238 	connect(mGoToTodayAction, SIGNAL(triggered()), mDayViewWidget, SLOT(goToToday()));
       
   239 	
       
   240 	HbAction *goToDateAction = qobject_cast<HbAction *>
       
   241                                 (mDocLoader->findObject(CALEN_DAYVIEW_MENU_GO_TO_DATE));
       
   242 	if (!goToDateAction) {
       
   243 	    qFatal("calendayview.cpp : Unable to find go to date action");
       
   244 	}
       
   245 	// Connect to the signal triggered by new event action
       
   246 	connect(goToDateAction, SIGNAL(triggered()), this, SLOT(goToDate()));
       
   247 	
       
   248 	HbAction *settingsAction = qobject_cast<HbAction *>
       
   249                                 (mDocLoader->findObject(CALEN_DAYVIEW_MENU_SETTINGS));
       
   250 	if (!settingsAction) {
       
   251 	    qFatal("calendayview.cpp : Unable to find settings action");
       
   252 	}
       
   253 	// Connect to the signal triggered by new event action
       
   254 	connect(settingsAction, SIGNAL(triggered()), this, SLOT(launchSettingsView()));
       
   255 }
       
   256 
       
   257 // ----------------------------------------------------------------------------
       
   258 // CCalenDayView::onLocaleChanged
       
   259 // Rest of the details are commented in the header
       
   260 // ----------------------------------------------------------------------------
       
   261 //    
       
   262 void CalenDayView::onLocaleChanged(int reason)
       
   263 {
       
   264     Q_UNUSED(reason)
       
   265     // Notify the content widget about the change
       
   266     if(mDayViewWidget) {
       
   267         mDayViewWidget->handleLocaleChange();
       
   268     }
       
   269 }
       
   270 
       
   271 // ----------------------------------------------------------------------------
       
   272 // CCalenDayView::orientationChanged
       
   273 // Rest of the details are commented in the header
       
   274 // ----------------------------------------------------------------------------
       
   275 // 
       
   276 void CalenDayView::orientationChanged(Qt::Orientation orientation)
       
   277 {
       
   278     // Notify the content widget about the change
       
   279     if (mDayViewWidget) {
       
   280         mDayViewWidget->orientationChanged(orientation);
       
   281     }
       
   282 }
       
   283 
       
   284 // ----------------------------------------------------------------------------
       
   285 // CCalenDayView::launchMonthView
       
   286 // ----------------------------------------------------------------------------
       
   287 //    
       
   288 void CalenDayView::launchMonthView()
       
   289 {
       
   290     // Issue the command to launch the month view
       
   291     mServices.IssueCommandL(ECalenMonthView);
       
   292 	// month view launched now, disconnect to get the call backs for saveActivity 
       
   293 	// on aboutToQuit signal
       
   294     disconnectAboutToQuitEvent();
       
   295 }
       
   296 
       
   297 // ----------------------------------------------------------------------------
       
   298 // CCalenDayView::clearListModel
       
   299 // clears the list model 
       
   300 // ----------------------------------------------------------------------------
       
   301 // 
       
   302 void CalenDayView::clearListModel()
       
   303     {
       
   304 	// day view is removed from the list disconnect for aboutToQuit events
       
   305     disconnectAboutToQuitEvent();
       
   306     mDayViewWidget->clearListModel();
       
   307     }
       
   308 
       
   309 // ----------------------------------------------------------------------------
       
   310 // disconnectAboutToQuitEvent disconnects for the aboutToQuit events
       
   311 // ----------------------------------------------------------------------------
       
   312 // 
       
   313 void CalenDayView::disconnectAboutToQuitEvent()
       
   314     {
       
   315     if (mIsAboutToQuitEventConnected)
       
   316         {
       
   317         disconnect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
   318         mIsAboutToQuitEventConnected = false;
       
   319         }
       
   320     }
       
   321 
       
   322 // End of file	--Don't remove this.