userguide/src/HelpMainWindow.cpp
changeset 26 97d7f0705d0a
parent 15 c0dfc135a46c
child 27 0a93cba9d57a
equal deleted inserted replaced
25:57d77d90783b 26:97d7f0705d0a
    16 */
    16 */
    17 
    17 
    18 #include <hbtoolbar.h>
    18 #include <hbtoolbar.h>
    19 #include <hbnotificationdialog.h>
    19 #include <hbnotificationdialog.h>
    20 #include <hbaction.h>
    20 #include <hbaction.h>
       
    21 #include <hbapplication.h>
       
    22 #include <hbactivitymanager.h>
    21 
    23 
       
    24 #include "HelpBaseView.h"
    22 #include "HelpCategoryView.h"
    25 #include "HelpCategoryView.h"
       
    26 #include "HelpKeywordView.h"
    23 #include "HelpContentsView.h"
    27 #include "HelpContentsView.h"
    24 
    28 
    25 #include "HelpMainWindow.h"
    29 #include "HelpMainWindow.h"
    26 #include "HelpDataProvider.h"
    30 #include "HelpDataProvider.h"
    27 
    31 
    28 HelpMainWindow::HelpMainWindow() : 
    32 HelpMainWindow::HelpMainWindow() : 
    29 mCategoryView(NULL),
    33 mCategoryView(NULL),
       
    34 mKeywordView(NULL),
    30 mContentsView(NULL)
    35 mContentsView(NULL)
    31 {
    36 {
    32 	connect(this, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(onOrientationChanged(Qt::Orientation)));
    37     QObject::connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
    33 	initToolbar();
       
    34     activateCategoryView();
    38     activateCategoryView();
    35 }
    39 }
    36 
    40 
    37 HelpMainWindow::~HelpMainWindow()
    41 HelpMainWindow::~HelpMainWindow()
    38 {
    42 {
    39     HelpDataProvider::destroyInstance();
    43     HelpDataProvider::destroyInstance();
    40 }
       
    41 
       
    42 void HelpMainWindow::initToolbar()
       
    43 {
       
    44 	mBuilder.load(QRC_DOCML_TOOLBAR);
       
    45 	mToolBar = mBuilder.findWidget<HbToolBar*>(DOCML_TOOLBAR);
       
    46 
       
    47     HbAction* allAction = mBuilder.findObject<HbAction*>(DOCML_ACTION_ALL);
       
    48     HbAction* findAction = mBuilder.findObject<HbAction*>(DOCML_ACTION_SEARCH);
       
    49 	HbAction* onLineSupportAction = mBuilder.findObject<HbAction*>(DOCML_ACTION_LINK_NOKIA);
       
    50 
       
    51 	connect(allAction, SIGNAL(triggered()), this, SLOT(onToolbarAll()));
       
    52 	connect(findAction, SIGNAL(triggered()), this, SLOT(onToolbarFind()));
       
    53 	connect(onLineSupportAction, SIGNAL(triggered()), this, SLOT(onToolbarOnlineSupport()));
       
    54 }
    44 }
    55 
    45 
    56 void HelpMainWindow::onActivateView(HelpViewName viewName)
    46 void HelpMainWindow::onActivateView(HelpViewName viewName)
    57 {
    47 {
    58 	switch(viewName)
    48 	switch(viewName)
    59 	{
    49 	{
    60 	    case HelpViewCategory:
    50 	    case HelpViewCategory:
    61             activateCategoryView();
    51             activateCategoryView();
    62 			break;
    52 			break;
    63 
    53 	    case HelpViewKeyword:
       
    54             activateKeywordView();
       
    55 			break;
    64 	    case HelpViewContents:
    56 	    case HelpViewContents:
    65             activateContentsView();
    57             activateContentsView();
    66 			break;
    58 			break;
    67 
    59 		case PreviousView:
       
    60 			{
       
    61 				onActivateView(mPreviousViewName);
       
    62 			}
       
    63 			break;
    68 	    default:
    64 	    default:
    69 	        break;
    65 	        break;
    70 	}
    66 	}
    71 }
    67 }
    72 
    68 
    75     if(!mCategoryView)
    71     if(!mCategoryView)
    76     {
    72     {
    77         mCategoryView = new HelpCategoryView();
    73         mCategoryView = new HelpCategoryView();
    78         addView(mCategoryView);
    74         addView(mCategoryView);
    79         mCategoryView->init();
    75         mCategoryView->init();
    80 		mCategoryView->setToolBar(mToolBar);
       
    81         emit currentViewChanged(mCategoryView);
    76         emit currentViewChanged(mCategoryView);
    82 		connectViewSignal(mCategoryView);
    77 		connectViewSignal(mCategoryView);
    83     }
    78     }
    84 
    79 
       
    80 	mPreviousViewName = HelpViewCategory;
    85     setCurrentView(mCategoryView);
    81     setCurrentView(mCategoryView);
       
    82 }
       
    83 
       
    84 void HelpMainWindow::activateKeywordView()
       
    85 {
       
    86     if(!mKeywordView)
       
    87     {
       
    88         mKeywordView = new HelpKeywordView();
       
    89 		addView(mKeywordView);
       
    90         mKeywordView->init();
       
    91 		connectViewSignal(mKeywordView);
       
    92     }
       
    93 
       
    94 	mPreviousViewName = HelpViewKeyword;	
       
    95     setCurrentView(mKeywordView);	
    86 }
    96 }
    87 
    97 
    88 void HelpMainWindow::activateContentsView()
    98 void HelpMainWindow::activateContentsView()
    89 {
    99 {
    90     if(!mContentsView)
   100     if(!mContentsView)
    91     {
   101     {
    92 		mContentsView = new HelpContentsView();
   102 		mContentsView = new HelpContentsView();
    93         addView(mContentsView);
   103 		addView(mContentsView);
    94         mContentsView->init();
   104         mContentsView->init();
    95 		mContentsView->setToolBar(mToolBar);
       
    96 
   105 
    97         connectViewSignal(mContentsView);
   106         connectViewSignal(mContentsView);
    98     }
   107     }
    99 
       
   100     setCurrentView(mContentsView);
   108     setCurrentView(mContentsView);
   101 }
   109 }
   102 
   110 
   103 void HelpMainWindow::connectViewSignal(const QObject *object)
   111 void HelpMainWindow::connectViewSignal(const HelpBaseView *view)
   104 {
   112 {
   105     connect(object, SIGNAL(activateView(HelpViewName)), this, SLOT(onActivateView(HelpViewName)));
   113 	connect(this, SIGNAL(orientationChanged(Qt::Orientation)), view, SLOT(onOrientationChanged(Qt::Orientation)));
       
   114     connect(view, SIGNAL(activateView(HelpViewName)), this, SLOT(onActivateView(HelpViewName)));
       
   115     
       
   116     connect(view, SIGNAL(showAllList()), this, SLOT(onShowAllList()));
       
   117     connect(view, SIGNAL(showFindList()), this, SLOT(onShowFindList()));
   106 }
   118 }
   107 
   119 
   108 
   120 
   109 ////////////////////////////////////////////////////////////////////////////////////
   121 ////////////////////////////////////////////////////////////////////////////////////
   110 // handle view event
   122 // handle view event
   111 
   123 
   112 void HelpMainWindow::onToolbarAll()
   124 void HelpMainWindow::onShowAllList()
   113 {
   125 {
   114     activateCategoryView();
   126     activateCategoryView();
   115     mCategoryView->switchViewMode(HelpCategoryView::ViewModeAll);
       
   116 }
   127 }
   117 
   128 
   118 void HelpMainWindow::onToolbarFind()
   129 void HelpMainWindow::onShowFindList()
   119 {
   130 {	
   120     activateCategoryView();
   131     activateKeywordView();
   121     mCategoryView->switchViewMode(HelpCategoryView::ViewModeSearch);
   132 	mKeywordView->loadAllContent();
   122 }
   133 }
   123 
   134 
   124 void HelpMainWindow::onToolbarOnlineSupport()
   135 void HelpMainWindow::saveActivity()
   125 {
   136 {
   126     HbNotificationDialog *notificationDialog = new HbNotificationDialog();
   137   HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
   127     notificationDialog->setParent(this);
       
   128     notificationDialog->setTitle(URL_LINK_SUPPORT);
       
   129     notificationDialog->show();
       
   130 }
       
   131 
   138 
   132 void HelpMainWindow::onOrientationChanged(Qt::Orientation orientation)
   139   // clean up any previous versions of this activity from the activity manager.
   133 {
   140   bool ok = activityManager->removeActivity("UserGuideMainView");
   134     RefreshToolbarText(orientation);
   141   if ( !ok )
   135 }
   142       {
       
   143       //qFatal("Remove failed" );
       
   144       }
   136 
   145 
   137 void HelpMainWindow::RefreshToolbarText(Qt::Orientation orientation)
   146   // get a screenshot for saving to the activity manager
   138 {
   147   QVariantHash metadata;
   139 	bool isLandscape = (Qt::Horizontal==orientation);
   148   metadata.insert("screenshot", QPixmap::grabWidget(this, rect()));
   140     HbAction* tollbarAction = mBuilder.findObject<HbAction*>(DOCML_ACTION_ALL);
       
   141     tollbarAction->setText(isLandscape ? qtTrId(TXT_BUTTON_ALL) : QString());
       
   142 
   149 
   143     tollbarAction = mBuilder.findObject<HbAction*>(DOCML_ACTION_SEARCH);
   150   // save any data necessary to save the state
   144     tollbarAction->setText(isLandscape ? qtTrId(TXT_BUTTON_FIND) : QString());
   151   QByteArray serializedActivity;
       
   152   QDataStream stream(&serializedActivity, QIODevice::WriteOnly | QIODevice::Append);
       
   153   stream << "whatever data you need to save the state adequately";
   145 
   154 
   146     tollbarAction = mBuilder.findObject<HbAction*>(DOCML_ACTION_LINK_NOKIA);
   155   // add the activity to the activity manager
   147     tollbarAction->setText(isLandscape ? qtTrId(TXT_BUTTON_LINK_SUPPORT) : QString());
   156   ok = activityManager->addActivity("UserGuideMainView", serializedActivity, metadata);
       
   157   if ( !ok )
       
   158       {
       
   159       qFatal("Add failed" );
       
   160       }
   148 }
   161 }
   149 
   162 
   150 // end of file
   163 // end of file
   151 
   164