stifui/qt/src/uisetting.cpp
branchRCL_3
changeset 9 404ad6c9bc20
child 12 aefcba28a3e0
equal deleted inserted replaced
8:87e9ebfbe96a 9:404ad6c9bc20
       
     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: QT C++ based Class.
       
    15  *
       
    16  */
       
    17 
       
    18 #include <QFile>
       
    19 #include <QTextStream>
       
    20 #include <QDateTime>
       
    21 #include "uisetting.h"
       
    22 const QString SETTINGFILE = "c:\\TestFramework\\StfQtUISetting.ini";
       
    23 
       
    24 UiSetting::UiSetting()
       
    25     {
       
    26     if(!load())
       
    27         {
       
    28         loadDefault();
       
    29         }
       
    30     }
       
    31 
       
    32 UiSetting::~UiSetting()
       
    33     {
       
    34     }
       
    35 
       
    36 QString UiSetting::ReadSetting(const QString& item)
       
    37     {
       
    38     QString value = "";
       
    39     if(settingList.contains(item))
       
    40         {
       
    41         value = settingList.value(item);
       
    42         }
       
    43     return value;
       
    44     }
       
    45 
       
    46 
       
    47 void UiSetting::SetSetting(const QString& item, const QString& value)
       
    48     {
       
    49     if(settingList.contains(item))
       
    50         {
       
    51         settingList.remove(item);
       
    52         }
       
    53     settingList.insert(item, value);
       
    54     save();
       
    55     }
       
    56 
       
    57 
       
    58 void UiSetting::loadDefault()
       
    59     {
       
    60     settingList.clear();
       
    61     settingList.insert("showoutput", "true");
       
    62     //add mor default setting here.
       
    63     }
       
    64 
       
    65 
       
    66 bool UiSetting::load()
       
    67     {
       
    68     QFile file(SETTINGFILE);
       
    69     if(!file.open(QIODevice::ReadOnly))
       
    70         {
       
    71         return false;
       
    72         }
       
    73     QTextStream in(&file);
       
    74     QString line, item, value;
       
    75     int index;
       
    76     while(!in.atEnd())
       
    77         {
       
    78         line = in.readLine().trimmed().toLower();
       
    79         if(!line.startsWith("//"))
       
    80             {
       
    81             index = line.indexOf("=");
       
    82             if(index > 0 && index < line.length() - 1)
       
    83                 {
       
    84                 item = line.left(index).trimmed();
       
    85                 value = line.right(line.length() - index  -1);
       
    86                 settingList.insert(item, value);
       
    87                 }
       
    88             }
       
    89         //end while.
       
    90         }
       
    91     return true;
       
    92     }
       
    93 
       
    94 bool UiSetting::save()
       
    95     {
       
    96     QFile file(SETTINGFILE);
       
    97     if(!file.open(QIODevice::WriteOnly))
       
    98         {
       
    99         return false;
       
   100         }
       
   101     QTextStream in(&file);
       
   102     in << "//STFQtUI Setting.\r\n";
       
   103     in << "//Created at: " + QDateTime::currentDateTime().toString("yyyy.mm.dd hh:mm::ss");
       
   104     in << "\r\n";
       
   105     for(int i=0;i< settingList.size();i++)
       
   106         {
       
   107         in << settingList.keys()[i];
       
   108         in << "=";
       
   109         in << settingList.value(settingList.keys()[i]);
       
   110         in << "\r\n";
       
   111         }
       
   112     return true;    
       
   113     }
       
   114