homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsmainwindow.cpp
changeset 77 4b195f3bea29
parent 61 2b1b11a301d2
child 92 6727c5d0afc7
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
    19 #include <HbView>
    19 #include <HbView>
    20 #include <HbInstance>
    20 #include <HbInstance>
    21 #include "hsmainwindow.h"
    21 #include "hsmainwindow.h"
    22 #include "hsmenuview.h"
    22 #include "hsmenuview.h"
    23 
    23 
    24 #include <qservicemanager.h>
    24 
    25 /*!
    25 /*!
    26  Constructor
    26  Constructor
    27  */
    27  */
    28 QTM_USE_NAMESPACE
    28 
    29 
    29 
    30 
    30 
    31 /*
    31 /*
    32  * A word about HsMainWindow class.
    32  * A word about HsMainWindow class.
    33  * This is not an utility class. It was designed to isolate HbMainWindow connected code, so
    33  * This is not an utility class. It was designed to isolate HbMainWindow connected code, so
    34  * it can be substitued in MT for application library. Unfortunately it seems to be the best
    34  * it can be substitued in MT for application library. Unfortunately it seems to be the best
    35  * way to cope with HbMainWindow problem in MT.  
    35  * way to cope with HbMainWindow problem in MT.  
    36  */
    36  */
    37 
    37 
    38 
    38 
    39 HsMainWindow::HsMainWindow() : mActivityClient(NULL)
    39 HsMainWindow::HsMainWindow() 
    40 {
    40 {
    41 }
    41 }
    42 
    42 
    43 /*!
    43 /*!
    44  Destructor
    44  Destructor
    49 
    49 
    50 /*!
    50 /*!
    51  Add the \menuView to first instance of HbMainWindow registered in HbInstance.
    51  Add the \menuView to first instance of HbMainWindow registered in HbInstance.
    52  \param view View to be added to HbMainWindow.
    52  \param view View to be added to HbMainWindow.
    53 */
    53 */
    54 void HsMainWindow::setCurrentView(const HsMenuView &menuView)
    54 void HsMainWindow::setCurrentView(HbView *view)
    55 {
    55 {
    56     HbMainWindow *const hbW(
    56     HbMainWindow *const hbW(
    57         HbInstance::instance()->allMainWindows().value(0));
    57         HbInstance::instance()->allMainWindows().value(0));
    58     
    58     
    59     connect( hbW, SIGNAL(viewReady()), SIGNAL(viewIsReady()),
       
    60         Qt::UniqueConnection );
       
    61 
       
    62     HbView *const view = menuView.view();
       
    63     
       
    64     if (!hbW->views().contains(view)) {
    59     if (!hbW->views().contains(view)) {
    65         hbW->addView(view);
    60         hbW->addView(view);
    66     }
    61     }
    67     hbW->setCurrentView(view);
    62     bool animate  = !hbW->isObscured();       
       
    63     hbW->setCurrentView(view, animate);
    68 }
    64 }
    69 
       
    70 
       
    71 /*!
       
    72  Grabs screenshot from actual main window
       
    73  \retval QPixmap& containing screenshot
       
    74 */
       
    75 QPixmap HsMainWindow::grabScreenshot()
       
    76 	{
       
    77 	HbMainWindow *const hbW(
       
    78 	    HbInstance::instance()->allMainWindows().value(0));
       
    79 	return QPixmap::grabWidget(hbW, hbW->rect()); 
       
    80 	}
       
    81 
       
    82 /*!
       
    83  Saves applib activity with current view screenshot
       
    84 */
       
    85 void HsMainWindow::saveActivity()
       
    86 {
       
    87 #ifdef Q_OS_SYMBIAN
       
    88 
       
    89     if (!mActivityClient) {
       
    90         QServiceManager serviceManager;
       
    91         mActivityClient = serviceManager.loadInterface("com.nokia.qt.activities.ActivityClient");
       
    92         if (!mActivityClient) {
       
    93             qWarning("Cannot initialize critical com.nokia.qt.activities.ActivityClient service.");
       
    94         }
       
    95     }
       
    96 
       
    97     if (mActivityClient) {
       
    98         bool retok;
       
    99         bool ok = QMetaObject::invokeMethod(mActivityClient, "removeActivity",
       
   100             Q_RETURN_ARG(bool, retok), Q_ARG(QString, appLibActivity()));
       
   101         if (!ok) {
       
   102             qWarning("remove appLibActivity failed");
       
   103         }
       
   104 
       
   105         QVariant variant;
       
   106         QVariantHash metadata;
       
   107         metadata.insert("screenshot", grabScreenshot());
       
   108 
       
   109         ok = QMetaObject::invokeMethod(mActivityClient, "addActivity", Q_RETURN_ARG(bool, retok),
       
   110             Q_ARG(QString, appLibActivity() ), Q_ARG(QVariant, QVariant(variant)),
       
   111             Q_ARG(QVariantHash, metadata));
       
   112         if (!ok) {
       
   113             qWarning("add appLibActivity failed");
       
   114         }
       
   115     }
       
   116 #endif//Q_OS_SYMBIAN   
       
   117 }
       
   118