screengrabber/src/settingsview.cpp
changeset 15 e11368ed4880
child 17 4f2773374eff
equal deleted inserted replaced
11:4df3a095718c 15:e11368ed4880
       
     1 /*
       
     2 * Copyright (c) 2010 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbdataform.h>
       
    19 #include <hbdataformmodelitem.h>
       
    20 #include <hbdataformmodel.h>
       
    21 #include <hbdataformviewitem.h>
       
    22 #include <hbaction.h>
       
    23 #include <hbmenu.h>
       
    24 #include <hbtoolbar.h>
       
    25 #include <hbabstractviewitem.h>
       
    26 #include <hbaction.h>
       
    27 
       
    28 
       
    29 #include "settingsview.h"
       
    30 #include "enginewrapper.h"
       
    31 #include "sgengine.h"
       
    32 #include "hbslider.h"
       
    33 #include "notifications.h"
       
    34 
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 
       
    39 SettingsView::SettingsView(HbView &mainView, HbMainWindow &mainWindow, EngineWrapper &engineWrapper): 
       
    40     mEngineWrapper(engineWrapper), 
       
    41     mMainWindow(mainWindow), 
       
    42     mMainView(mainView)
       
    43 {
       
    44     // Set title and add this view to main window
       
    45     setTitle("Settings");
       
    46     
       
    47     HbAction *actionSaveSettings = menu()->addAction(QString("Save & close"));
       
    48     HbAction *actionCancel = menu()->addAction("Cancel & close");
       
    49     
       
    50     toolBar()->addAction(actionSaveSettings);
       
    51     toolBar()->addAction(actionCancel);
       
    52   
       
    53     
       
    54     //create setting form
       
    55     mSettingForm = new HbDataForm();
       
    56     
       
    57     //create a model class
       
    58     mModel = new HbDataFormModel(this);
       
    59     
       
    60     // DataFormItem for mode selection
       
    61     mModeItem = mModel->appendDataFormItem(
       
    62             HbDataFormModelItem::RadioButtonListItem, QString("Capture mode"), 0);
       
    63     //setting the text property of check box.
       
    64     mModeItem->setData(HbDataFormModelItem::KeyRole, QString("mode"));
       
    65     mModeItem->setContentWidgetData(QString("items"), CAPTUREMODES);
       
    66     
       
    67     // Create setting model
       
    68      createSingleCaptureComponents(mModel, 0);
       
    69      createSequentialCaptureComponents(mModel, 0);
       
    70      createVideoCaptureComponents(mModel, 0);
       
    71  
       
    72     // Set created model model to form
       
    73     mSettingForm->setModel(mModel);
       
    74     setWidget(mSettingForm);//takes ownership
       
    75     
       
    76     // Get view item of mode selection item
       
    77     HbDataFormViewItem *viewItemVideoPage = mSettingForm->dataFormViewItem(mModel->indexFromItem(mModeItem));
       
    78 
       
    79     loadSettings();
       
    80     
       
    81     // Connect signals from item modifications and close with this form's slots
       
    82    
       
    83 //    connect(viewItemVideoPage, SIGNAL(itemModified(QPersistentModelIndex, QVariant)), this, SLOT(updateShownItems()));
       
    84     connect(actionSaveSettings, SIGNAL(triggered()), this, SLOT(saveAndClose()));
       
    85     connect(actionCancel, SIGNAL(triggered()), this, SLOT(close()));
       
    86 	
       
    87 	HbAction *mDefaultNavigationAction = new HbAction(Hb::QuitNaviAction, this);
       
    88 	connect(mDefaultNavigationAction,SIGNAL(triggered()), this, SLOT(saveAndClose()));
       
    89 	setNavigationAction(mDefaultNavigationAction);
       
    90 	
       
    91 
       
    92 
       
    93 }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 
       
    98 SettingsView::~SettingsView()
       
    99 {
       
   100 
       
   101 }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 
       
   105 void SettingsView::loadSettings()
       
   106 {
       
   107 
       
   108     // get settings from engine;
       
   109     mSettings = mEngineWrapper.getGrabSettings();
       
   110     
       
   111     //Capture mode
       
   112     mModeItem->setContentWidgetData("selected", mSettings.mCaptureMode);
       
   113     
       
   114     // Still image 
       
   115     mImageHotKeyItem->setContentWidgetData("selected", mSettings.mSingleCaptureHotkey);
       
   116     mImageFormatItem->setContentWidgetData("selected", mSettings.mSingleCaptureImageFormat);
       
   117     mImageMemoryInUseItem->setContentWidgetData("selected", mSettings.mSingleCaptureMemoryInUseMultiDrive);
       
   118     mImageFileNameItem->setContentWidgetData("text", mSettings.mSingleCaptureFileName);
       
   119        
       
   120     // Seguantial image components
       
   121     mSequantialHotKeyItem->setContentWidgetData("selected", mSettings.mSequantialCaptureHotkey);
       
   122     mSequantialFormatItem->setContentWidgetData("selected", mSettings.mSequantialCaptureImageFormat);
       
   123     mSequantialDelayItem->setContentWidgetData("text", mSettings.mSequantialCaptureDelay);
       
   124     mSequantialMemoryInUseItem->setContentWidgetData("selected", mSettings.mSequantialCaptureMemoryInUseMultiDrive);
       
   125     mSequantialFileNameItem->setContentWidgetData("text", mSettings.mSequantialCaptureFileName);
       
   126     
       
   127     // Video capture components
       
   128     mVideoHotKeyItem->setContentWidgetData("selected", mSettings.mVideoCaptureHotkey);
       
   129     mVideoFormatItem->setContentWidgetData("selected", mSettings.mVideoCaptureVideoFormat);
       
   130     mVideoMemoryInUseItem->setContentWidgetData("selected", mSettings.mVideoCaptureMemoryInUseMultiDrive);
       
   131     mVideoFileNameItem->setContentWidgetData("text", mSettings.mVideoCaptureFileName);
       
   132     
       
   133 	
       
   134 }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 
       
   138 void SettingsView::createSingleCaptureComponents(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   139 {
       
   140     
       
   141     // Create Group for single image components
       
   142     mGroupImageCapture = model->appendDataFormGroup(QString("Single image settings"), parent);
       
   143 
       
   144     // DataFormItem for hotkey selection
       
   145     mImageHotKeyItem = model->appendDataFormItem(
       
   146             HbDataFormModelItem::RadioButtonListItem, QString("Capture hotkey"), mGroupImageCapture);
       
   147     //setting the text property of check box.
       
   148     mImageHotKeyItem->setData(HbDataFormModelItem::KeyRole, QString("image_hotkey"));
       
   149     mImageHotKeyItem->setContentWidgetData(QString("items"), KEYS);
       
   150 
       
   151     // DataFormItem for image format selection
       
   152     mImageFormatItem = model->appendDataFormItem(
       
   153             HbDataFormModelItem::RadioButtonListItem, QString("Image format"), mGroupImageCapture);
       
   154     //setting the text property of check box.
       
   155     mImageFormatItem->setData(HbDataFormModelItem::KeyRole, QString("image_format"));
       
   156     mImageFormatItem->setContentWidgetData(QString("items"), IMAGEFORMATS);
       
   157     
       
   158     // DataFormItem for memory in use selection
       
   159     mImageMemoryInUseItem = model->appendDataFormItem(
       
   160             HbDataFormModelItem::RadioButtonListItem, QString("Memory in use"), mGroupImageCapture);
       
   161     //setting the text property of check box.
       
   162     mImageMemoryInUseItem->setData(HbDataFormModelItem::KeyRole, QString("image_memory"));
       
   163     mImageMemoryInUseItem->setContentWidgetData(QString("items"), MEMORYMODES);
       
   164     
       
   165     // DataFormItem for file name
       
   166     mImageFileNameItem = model->appendDataFormItem(
       
   167             HbDataFormModelItem::TextItem, QString("File name"), mGroupImageCapture);
       
   168     //setting the text property of check box.
       
   169     mImageFileNameItem->setData(HbDataFormModelItem::KeyRole, QString("image_name"));
       
   170     mImageFileNameItem->setContentWidgetData(QString("text"), QString("Shot"));
       
   171     
       
   172 }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 
       
   176 void SettingsView::createSequentialCaptureComponents(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   177 {
       
   178     
       
   179     
       
   180     // Create Group for sequential image components
       
   181     mGroupSeguantialCapture = model->appendDataFormGroup(QString("Sequential image settings"), parent);
       
   182     
       
   183     // DataFormItem for hotkey selection
       
   184     mSequantialHotKeyItem = model->appendDataFormItem(
       
   185             HbDataFormModelItem::RadioButtonListItem, QString("Capture hotkey"), mGroupSeguantialCapture);
       
   186     //setting the text property of check box.
       
   187     mSequantialHotKeyItem->setData(HbDataFormModelItem::KeyRole, QString("seguential_hotkey"));
       
   188     mSequantialHotKeyItem->setContentWidgetData(QString("items"), KEYS);
       
   189     
       
   190     // DataFormItem for image format selection
       
   191     mSequantialFormatItem = model->appendDataFormItem(
       
   192             HbDataFormModelItem::RadioButtonListItem, QString("Image format"), mGroupSeguantialCapture);
       
   193     //setting the text property of check box.
       
   194     mSequantialFormatItem->setData(HbDataFormModelItem::KeyRole, QString("seguential_format"));
       
   195     mSequantialFormatItem->setContentWidgetData(QString("items"), IMAGEFORMATS);
       
   196     
       
   197     // DataFormItem for delay between images selection
       
   198     mSequantialDelayItem = model->appendDataFormItem(
       
   199             HbDataFormModelItem::TextItem, QString("Delay between two images(ms)"), mGroupSeguantialCapture);
       
   200     //setting the text property of check box.
       
   201     mSequantialDelayItem->setData(HbDataFormModelItem::KeyRole, QString("seguential_name"));
       
   202     mSequantialDelayItem->setContentWidgetData(QString("text"), QString("Shot"));
       
   203     
       
   204     // DataFormItem for memory selection
       
   205     mSequantialMemoryInUseItem = model->appendDataFormItem(
       
   206             HbDataFormModelItem::RadioButtonListItem, QString("Memory in use"), mGroupSeguantialCapture);
       
   207     //setting the text property of check box.
       
   208     mSequantialMemoryInUseItem->setData(HbDataFormModelItem::KeyRole, QString("seguential_memory"));
       
   209     mSequantialMemoryInUseItem->setContentWidgetData(QString("items"), MEMORYMODES);
       
   210     
       
   211     // DataFormItem for file name
       
   212     mSequantialFileNameItem = model->appendDataFormItem(
       
   213             HbDataFormModelItem::TextItem, QString("File name"), mGroupSeguantialCapture);
       
   214     //setting the text property of check box.
       
   215     mSequantialFileNameItem->setData(HbDataFormModelItem::KeyRole, QString("seguential_name"));
       
   216     mSequantialFileNameItem->setContentWidgetData(QString("text"), QString("Shot"));
       
   217     
       
   218 }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 
       
   222 void SettingsView::createVideoCaptureComponents(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   223 {
       
   224 
       
   225     // Create Group for video capturing components
       
   226     mGroupVideoCapture = model->appendDataFormGroup(QString("Video settings"), parent);
       
   227     
       
   228     // DataFormItem for hotkey selection
       
   229     mVideoHotKeyItem = model->appendDataFormItem(
       
   230             HbDataFormModelItem::RadioButtonListItem, QString("Start/Stop hotkey"), mGroupVideoCapture);
       
   231     //setting the text property of check box.
       
   232     mVideoHotKeyItem->setData(HbDataFormModelItem::KeyRole, QString("video_hotkey"));
       
   233     mVideoHotKeyItem->setContentWidgetData(QString("items"), KEYS);
       
   234     
       
   235     // DataFormItem for video format selection
       
   236     mVideoFormatItem = model->appendDataFormItem(
       
   237             HbDataFormModelItem::RadioButtonListItem, QString("Video format"), mGroupVideoCapture);
       
   238     //setting the text property of check box.
       
   239     mVideoFormatItem->setData(HbDataFormModelItem::KeyRole, QString("video_format"));
       
   240     mVideoFormatItem->setContentWidgetData(QString("items"), VIDEOFORMATS);
       
   241     
       
   242     // DataFormItem for memory selection
       
   243     mVideoMemoryInUseItem = model->appendDataFormItem(
       
   244             HbDataFormModelItem::RadioButtonListItem, QString("Memory in use"), mGroupVideoCapture);
       
   245     //setting the text property of check box.mGroupVideoCapture
       
   246     mVideoMemoryInUseItem->setData(HbDataFormModelItem::KeyRole, QString("video_memory"));
       
   247     mVideoMemoryInUseItem->setContentWidgetData(QString("items"), MEMORYMODES);
       
   248     
       
   249     // DataFormItem for file name
       
   250     mVideoFileNameItem = model->appendDataFormItem(
       
   251             HbDataFormModelItem::TextItem, QString("File name"), mGroupVideoCapture);
       
   252     //setting the text property of check box.
       
   253     mVideoFileNameItem->setData(HbDataFormModelItem::KeyRole, QString("video_name"));
       
   254     mVideoFileNameItem->setContentWidgetData(QString("text"), QString("Video"));
       
   255     
       
   256 }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 
       
   260 void SettingsView::saveAndClose()
       
   261 {
       
   262 
       
   263     readFormItems();
       
   264     if (!mEngineWrapper.saveSettings(mSettings)) {
       
   265         Notifications::error("Unable to save settings");
       
   266     }    
       
   267     
       
   268     mEngineWrapper.EnableRcpOfFoc(EFalse);
       
   269     mMainWindow.setCurrentView(&mMainView);
       
   270 	
       
   271 }
       
   272 
       
   273 
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 
       
   277 void SettingsView::readFormItems()
       
   278 {
       
   279     
       
   280     //TODO this does not work correctly with WK38 ( Text box items )
       
   281 
       
   282     mSettings.mCaptureMode = mModeItem->contentWidgetData("selected").toInt();
       
   283 
       
   284     mSettings.mSingleCaptureImageFormat = mImageFormatItem->contentWidgetData("selected").toInt();
       
   285     mSettings.mSingleCaptureHotkey = mImageHotKeyItem->contentWidgetData("selected").toInt();
       
   286     mSettings.mSingleCaptureMemoryInUseMultiDrive = mImageMemoryInUseItem->contentWidgetData("selected").toInt(); 
       
   287     mSettings.mSingleCaptureFileName = mImageFileNameItem->contentWidgetData("text").toString();
       
   288     
       
   289     mSettings.mSequantialCaptureImageFormat = mSequantialFormatItem->contentWidgetData("selected").toInt();
       
   290     mSettings.mSequantialCaptureHotkey = mSequantialHotKeyItem ->contentWidgetData("selected").toInt();
       
   291     mSettings.mSequantialCaptureMemoryInUseMultiDrive = mSequantialMemoryInUseItem ->contentWidgetData("selected").toInt();
       
   292     mSettings.mSequantialCaptureFileName = mSequantialFileNameItem->contentWidgetData("text").toString();
       
   293     mSettings.mSequantialCaptureDelay = mSequantialDelayItem->contentWidgetData("text").toInt();
       
   294     
       
   295 
       
   296     mSettings.mVideoCaptureVideoFormat = mVideoFormatItem->contentWidgetData("selected").toInt();
       
   297     mSettings.mVideoCaptureHotkey = mVideoHotKeyItem ->contentWidgetData("selected").toInt();
       
   298     mSettings.mVideoCaptureMemoryInUseMultiDrive = mVideoMemoryInUseItem ->contentWidgetData("selected").toInt();
       
   299     mSettings.mVideoCaptureFileName = mVideoFileNameItem ->contentWidgetData("text").toString();
       
   300 	
       
   301    
       
   302 }
       
   303 
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 /*
       
   307 void SettingsView::updateShownItems()
       
   308 { 
       
   309 
       
   310     if (mMainWindow.currentView() == this) {
       
   311         // Get view items of each group
       
   312         HbDataFormViewItem *viewItemImageGroup = mSettingForm->dataFormViewItem(mModel->indexFromItem(mGroupImageCapture));
       
   313         HbDataFormViewItem *viewItemSequantialGroup = mSettingForm->dataFormViewItem(mModel->indexFromItem(mGroupSeguantialCapture));
       
   314         HbDataFormViewItem *viewItemVideoGroup = mSettingForm->dataFormViewItem(mModel->indexFromItem(mGroupVideoCapture));
       
   315 
       
   316     
       
   317         // Set certain group expanded according to selected mode. 
       
   318         // TODO this does not work correctly with WK38(selectedItem is for some reason always 1)
       
   319     
       
   320         int selectedItem = mModeItem->contentWidgetData("selected").toInt();
       
   321         
       
   322         if (selectedItem == SINGLE){
       
   323             viewItemImageGroup->setExpanded(true);
       
   324             viewItemSequantialGroup->setExpanded(false);
       
   325             viewItemVideoGroup->setExpanded(false);
       
   326     
       
   327         }
       
   328         else if (selectedItem == SEQUENTIAL){
       
   329             viewItemImageGroup->setExpanded(false);
       
   330             viewItemSequantialGroup->setExpanded(true);
       
   331             viewItemVideoGroup->setExpanded(false);    
       
   332         }
       
   333         
       
   334         else if (selectedItem == VIDEO){
       
   335             viewItemImageGroup->setExpanded(false);
       
   336             viewItemSequantialGroup->setExpanded(false);
       
   337             viewItemVideoGroup->setExpanded(true);
       
   338         }
       
   339         
       
   340         
       
   341     }
       
   342     
       
   343 }
       
   344 */
       
   345 // ---------------------------------------------------------------------------
       
   346 
       
   347 void SettingsView::close()
       
   348 {
       
   349     mEngineWrapper.EnableRcpOfFoc(EFalse);
       
   350     mMainWindow.setCurrentView(&mMainView);
       
   351 }