memspyui/ui/hb/src/memspysettingsview.cpp
branchRCL_3
changeset 19 b3cee849fa46
equal deleted inserted replaced
18:48060abbbeaf 19:b3cee849fa46
       
     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:
       
    15  *  
       
    16  */
       
    17 
       
    18 #include <HbToolBar>
       
    19 #include <HbAction>
       
    20 #include <HbDataForm>
       
    21 #include <HbDataFormModel>
       
    22 #include <HbProgressDialog>
       
    23 
       
    24 #include "memspysettingsview.h"
       
    25 #include "enginewrapper.h"
       
    26 
       
    27 const QStringList MODE_ITEMS = QStringList() << 
       
    28 	MemSpySettingsView::tr("RDebug") << 
       
    29 	MemSpySettingsView::tr("File");
       
    30 	
       
    31 MemSpySettingsView::MemSpySettingsView(EngineWrapper &engine) :
       
    32 	mForm(new HbDataForm(this)),
       
    33 	mModel(0),
       
    34 	mModeItem(0),
       
    35 	mPathItem(0),
       
    36 	mCustomPathItem(0),
       
    37 	mEngine(engine)
       
    38 {
       
    39 	setTitle(tr("Settings"));
       
    40 	
       
    41 	toolBar()->addAction(tr("OK"), this, SLOT(accept()));
       
    42 	toolBar()->addAction(tr("Cancel"), this, SLOT(reject()));
       
    43 	
       
    44 	mModel = new HbDataFormModel(this);
       
    45 		
       
    46 	mModeItem = mModel->appendDataFormItem(
       
    47 		HbDataFormModelItem::ComboBoxItem, tr("Output"));
       
    48 	mModeItem->setContentWidgetData("items", MODE_ITEMS);
       
    49 	mModeItem->setContentWidgetData("currentIndex", mEngine.settings().outputMode());
       
    50 	
       
    51 	updateModel();
       
    52 		
       
    53 	
       
    54 	mForm->setModel(mModel);
       
    55 	mForm->addConnection(mModeItem, SIGNAL(currentIndexChanged(int)), this, SLOT(updateModel()));
       
    56 	setWidget(mForm);
       
    57 	
       
    58 	// change navigation action
       
    59 	HbAction* action = new HbAction(Hb::BackNaviAction, this);
       
    60 	connect(action, SIGNAL(triggered()), this, SLOT(reject()));
       
    61 	setNavigationAction(action);
       
    62 }
       
    63 
       
    64 MemSpySettingsView::~MemSpySettingsView()
       
    65 {
       
    66 }
       
    67 
       
    68 void MemSpySettingsView::updateModel()
       
    69 {
       
    70 	OutputMode mode = static_cast<OutputMode>(mModeItem->contentWidgetData("currentIndex").toInt());
       
    71 	if (mode == OutputModeTrace) {
       
    72 		// remove both path item and custom path item
       
    73 		if (mPathItem)
       
    74 			mModel->removeItem(mPathItem);
       
    75 		if (mCustomPathItem)
       
    76 			mModel->removeItem(mCustomPathItem);
       
    77 		
       
    78 		mPathItem = mCustomPathItem = 0;
       
    79 	} else if (mode == OutputModeFile) {
       
    80 		if (!mPathItem) {
       
    81 			// create path item
       
    82 			mPathItem = mModel->appendDataFormItem(
       
    83 					HbDataFormModelItem::CheckBoxItem, tr("Path"));
       
    84 			mPathItem->setContentWidgetData("text", tr("Use Default Path (\\MemSpy)"));
       
    85 			mPathItem->setContentWidgetData("checkState", 
       
    86 					mEngine.settings().outputPath().isEmpty() ? Qt::Checked : Qt::Unchecked);
       
    87 			
       
    88 			mForm->addConnection(mPathItem, SIGNAL(stateChanged(int)), 
       
    89 					this, SLOT(updateModel()));
       
    90 		}
       
    91 		
       
    92 		if (mPathItem->contentWidgetData("checkState").toInt() == Qt::Unchecked && !mCustomPathItem) {
       
    93 			// create custom path item
       
    94 			mCustomPathItem = mModel->appendDataFormItem(
       
    95 					HbDataFormModelItem::TextItem, tr("Custom Path"));
       
    96 			mCustomPathItem->setContentWidgetData("text", 
       
    97 					mEngine.settings().outputPath().isEmpty() ? "\\MemSpy" : mEngine.settings().outputPath());
       
    98 		}
       
    99 		
       
   100 		if (mPathItem->contentWidgetData("checkState").toInt() == Qt::Checked && mCustomPathItem) {
       
   101 			// remove cusom path item
       
   102 			mModel->removeItem(mCustomPathItem);
       
   103 			mCustomPathItem = 0;
       
   104 		}
       
   105 	}
       
   106 }
       
   107 
       
   108 void MemSpySettingsView::accept()
       
   109 {
       
   110 	OutputMode mode = static_cast<OutputMode>(mModeItem->contentWidgetData("currentIndex").toInt());
       
   111 	
       
   112 	mEngine.settings().setOutputMode(mode);
       
   113 	
       
   114 	if (mode == OutputModeFile) {
       
   115 		QString path = mPathItem->contentWidgetData("checkState").toInt() == Qt::Checked ? 
       
   116 				"" :
       
   117 				mCustomPathItem->contentWidgetData("text").toString();
       
   118 		mEngine.settings().setOutputPath(path);
       
   119 	}
       
   120 	emit finished(true);
       
   121 }
       
   122 
       
   123 void MemSpySettingsView::reject()
       
   124 {
       
   125 	emit finished(false);
       
   126 }
       
   127