utilityapps/screengrabber/src/settingsview.cpp
changeset 55 2d9cac8919d3
equal deleted inserted replaced
53:819e59dfc032 55:2d9cac8919d3
       
     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     mModeItem->setContentWidgetData(QString("items"), CAPTUREMODES);
       
    64     
       
    65     // Create setting model
       
    66      createSingleCaptureComponents(mModel, 0);
       
    67      createSequentialCaptureComponents(mModel, 0);
       
    68      createVideoCaptureComponents(mModel, 0);
       
    69  
       
    70     // Set created model model to form
       
    71     mSettingForm->setModel(mModel);
       
    72     setWidget(mSettingForm);//takes ownership
       
    73     
       
    74     loadSettings();
       
    75     
       
    76     // Connect signals from item modifications and close with this form's slots
       
    77     connect(actionSaveSettings, SIGNAL(triggered()), this, SLOT(saveAndClose()));
       
    78     connect(actionCancel, SIGNAL(triggered()), this, SLOT(close()));
       
    79 	
       
    80 	HbAction *mDefaultNavigationAction = new HbAction(Hb::QuitNaviAction, this);
       
    81 	connect(mDefaultNavigationAction,SIGNAL(triggered()), this, SLOT(saveAndClose()));
       
    82 	setNavigationAction(mDefaultNavigationAction);
       
    83 	
       
    84 
       
    85 
       
    86 }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 
       
    91 SettingsView::~SettingsView()
       
    92 {
       
    93 
       
    94 }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 
       
    98 void SettingsView::loadSettings()
       
    99 {
       
   100 
       
   101     // get settings from engine;
       
   102     mSettings = mEngineWrapper.getGrabSettings();
       
   103     
       
   104     //Capture mode
       
   105     mModeItem->setContentWidgetData("selected", mSettings.mCaptureMode);
       
   106     
       
   107     // Still image 
       
   108     mImageHotKeyItem->setContentWidgetData("selected", mSettings.mSingleCaptureHotkey);
       
   109     mImageFormatItem->setContentWidgetData("selected", mSettings.mSingleCaptureImageFormat);
       
   110     mImageMemoryInUseItem->setContentWidgetData("selected", mSettings.mSingleCaptureMemoryInUseMultiDrive);
       
   111     mImageFileNameItem->setContentWidgetData("text", mSettings.mSingleCaptureFileName);
       
   112        
       
   113     // Seguantial image components
       
   114     mSequantialHotKeyItem->setContentWidgetData("selected", mSettings.mSequantialCaptureHotkey);
       
   115     mSequantialFormatItem->setContentWidgetData("selected", mSettings.mSequantialCaptureImageFormat);
       
   116     mSequantialDelayItem->setContentWidgetData("text", mSettings.mSequantialCaptureDelay);
       
   117     mSequantialMemoryInUseItem->setContentWidgetData("selected", mSettings.mSequantialCaptureMemoryInUseMultiDrive);
       
   118     mSequantialFileNameItem->setContentWidgetData("text", mSettings.mSequantialCaptureFileName);
       
   119     
       
   120     // Video capture components
       
   121     mVideoHotKeyItem->setContentWidgetData("selected", mSettings.mVideoCaptureHotkey);
       
   122     mVideoFormatItem->setContentWidgetData("selected", mSettings.mVideoCaptureVideoFormat);
       
   123     mVideoMemoryInUseItem->setContentWidgetData("selected", mSettings.mVideoCaptureMemoryInUseMultiDrive);
       
   124     mVideoFileNameItem->setContentWidgetData("text", mSettings.mVideoCaptureFileName);
       
   125     
       
   126 	
       
   127 }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 
       
   131 void SettingsView::createSingleCaptureComponents(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   132 {
       
   133     
       
   134     // Create Group for single image components
       
   135     mGroupImageCapture = model->appendDataFormGroup(QString("Single image settings"), parent);
       
   136 
       
   137     // DataFormItem for hotkey selection
       
   138     mImageHotKeyItem = model->appendDataFormItem(
       
   139             HbDataFormModelItem::RadioButtonListItem, QString("Capture hotkey"), mGroupImageCapture);
       
   140     mImageHotKeyItem->setContentWidgetData(QString("items"), KEYS);
       
   141 
       
   142     // DataFormItem for image format selection
       
   143     mImageFormatItem = model->appendDataFormItem(
       
   144             HbDataFormModelItem::RadioButtonListItem, QString("Image format"), mGroupImageCapture);
       
   145     mImageFormatItem->setContentWidgetData(QString("items"), IMAGEFORMATS);
       
   146     
       
   147     // DataFormItem for memory in use selection
       
   148     mImageMemoryInUseItem = model->appendDataFormItem(
       
   149             HbDataFormModelItem::RadioButtonListItem, QString("Memory in use"), mGroupImageCapture);
       
   150     mImageMemoryInUseItem->setContentWidgetData(QString("items"), MEMORYMODES);
       
   151     
       
   152     // DataFormItem for file name
       
   153     mImageFileNameItem = model->appendDataFormItem(
       
   154             HbDataFormModelItem::TextItem, QString("File name"), mGroupImageCapture);
       
   155     mImageFileNameItem->setContentWidgetData(QString("text"), QString("Shot"));
       
   156     
       
   157 }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 
       
   161 void SettingsView::createSequentialCaptureComponents(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   162 {
       
   163     
       
   164     
       
   165     // Create Group for sequential image components
       
   166     mGroupSeguantialCapture = model->appendDataFormGroup(QString("Sequential image settings"), parent);
       
   167     
       
   168     // DataFormItem for hotkey selection
       
   169     mSequantialHotKeyItem = model->appendDataFormItem(
       
   170             HbDataFormModelItem::RadioButtonListItem, QString("Capture hotkey"), mGroupSeguantialCapture);
       
   171     mSequantialHotKeyItem->setContentWidgetData(QString("items"), KEYS);
       
   172     
       
   173     // DataFormItem for image format selection
       
   174     mSequantialFormatItem = model->appendDataFormItem(
       
   175             HbDataFormModelItem::RadioButtonListItem, QString("Image format"), mGroupSeguantialCapture);
       
   176     mSequantialFormatItem->setContentWidgetData(QString("items"), IMAGEFORMATS);
       
   177     
       
   178     // DataFormItem for delay between images selection
       
   179     mSequantialDelayItem = model->appendDataFormItem(
       
   180             HbDataFormModelItem::TextItem, QString("Delay between two images(ms)"), mGroupSeguantialCapture);
       
   181     mSequantialDelayItem->setContentWidgetData(QString("text"), QString("Shot"));
       
   182     
       
   183     // DataFormItem for memory selection
       
   184     mSequantialMemoryInUseItem = model->appendDataFormItem(
       
   185             HbDataFormModelItem::RadioButtonListItem, QString("Memory in use"), mGroupSeguantialCapture);
       
   186     mSequantialMemoryInUseItem->setContentWidgetData(QString("items"), MEMORYMODES);
       
   187     
       
   188     // DataFormItem for file name
       
   189     mSequantialFileNameItem = model->appendDataFormItem(
       
   190             HbDataFormModelItem::TextItem, QString("File name"), mGroupSeguantialCapture);
       
   191     mSequantialFileNameItem->setContentWidgetData(QString("text"), QString("Shot"));
       
   192     
       
   193 }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 
       
   197 void SettingsView::createVideoCaptureComponents(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   198 {
       
   199 
       
   200     // Create Group for video capturing components
       
   201     mGroupVideoCapture = model->appendDataFormGroup(QString("Video settings"), parent);
       
   202     
       
   203     // DataFormItem for hotkey selection
       
   204     mVideoHotKeyItem = model->appendDataFormItem(
       
   205             HbDataFormModelItem::RadioButtonListItem, QString("Start/Stop hotkey"), mGroupVideoCapture);
       
   206     mVideoHotKeyItem->setContentWidgetData(QString("items"), KEYS);
       
   207     
       
   208     // DataFormItem for video format selection
       
   209     mVideoFormatItem = model->appendDataFormItem(
       
   210             HbDataFormModelItem::RadioButtonListItem, QString("Video format"), mGroupVideoCapture);
       
   211     mVideoFormatItem->setContentWidgetData(QString("items"), VIDEOFORMATS);
       
   212     
       
   213     // DataFormItem for memory selection
       
   214     mVideoMemoryInUseItem = model->appendDataFormItem(
       
   215             HbDataFormModelItem::RadioButtonListItem, QString("Memory in use"), mGroupVideoCapture);
       
   216     mVideoMemoryInUseItem->setContentWidgetData(QString("items"), MEMORYMODES);
       
   217     
       
   218     // DataFormItem for file name
       
   219     mVideoFileNameItem = model->appendDataFormItem(
       
   220             HbDataFormModelItem::TextItem, QString("File name"), mGroupVideoCapture);
       
   221     mVideoFileNameItem->setContentWidgetData(QString("text"), QString("Video"));
       
   222     
       
   223 }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 
       
   227 void SettingsView::saveAndClose()
       
   228 {
       
   229 
       
   230     readFormItems();
       
   231     if (!mEngineWrapper.saveSettings(mSettings)) {
       
   232         Notifications::error("Unable to save settings");
       
   233     }    
       
   234     
       
   235     mEngineWrapper.EnableRcpOfFoc(EFalse);
       
   236     mMainWindow.setCurrentView(&mMainView);
       
   237 	
       
   238 }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 
       
   242 void SettingsView::readFormItems()
       
   243 {
       
   244     
       
   245     //TODO this does not work correctly with WK38 ( Text box items )
       
   246 
       
   247     mSettings.mCaptureMode = mModeItem->contentWidgetData("selected").toInt();
       
   248 
       
   249     mSettings.mSingleCaptureImageFormat = mImageFormatItem->contentWidgetData("selected").toInt();
       
   250     mSettings.mSingleCaptureHotkey = mImageHotKeyItem->contentWidgetData("selected").toInt();
       
   251     mSettings.mSingleCaptureMemoryInUseMultiDrive = mImageMemoryInUseItem->contentWidgetData("selected").toInt(); 
       
   252     mSettings.mSingleCaptureFileName = mImageFileNameItem->contentWidgetData("text").toString();
       
   253     
       
   254     mSettings.mSequantialCaptureImageFormat = mSequantialFormatItem->contentWidgetData("selected").toInt();
       
   255     mSettings.mSequantialCaptureHotkey = mSequantialHotKeyItem ->contentWidgetData("selected").toInt();
       
   256     mSettings.mSequantialCaptureMemoryInUseMultiDrive = mSequantialMemoryInUseItem ->contentWidgetData("selected").toInt();
       
   257     mSettings.mSequantialCaptureFileName = mSequantialFileNameItem->contentWidgetData("text").toString();
       
   258     mSettings.mSequantialCaptureDelay = mSequantialDelayItem->contentWidgetData("text").toInt();
       
   259     
       
   260 
       
   261     mSettings.mVideoCaptureVideoFormat = mVideoFormatItem->contentWidgetData("selected").toInt();
       
   262     mSettings.mVideoCaptureHotkey = mVideoHotKeyItem ->contentWidgetData("selected").toInt();
       
   263     mSettings.mVideoCaptureMemoryInUseMultiDrive = mVideoMemoryInUseItem ->contentWidgetData("selected").toInt();
       
   264     mSettings.mVideoCaptureFileName = mVideoFileNameItem ->contentWidgetData("text").toString();
       
   265 	
       
   266    
       
   267 }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 
       
   271 void SettingsView::close()
       
   272 {
       
   273     mEngineWrapper.EnableRcpOfFoc(EFalse);
       
   274     mMainWindow.setCurrentView(&mMainView);
       
   275 }