controlpanelplugins/aboutplugin/src/cpaboututils.cpp
changeset 36 2fee987ebaff
equal deleted inserted replaced
33:0cfa53de576f 36:2fee987ebaff
       
     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 "CpAboutUtils.h"
       
    19 #include <sysversioninfo.h>
       
    20 #include <sysutil.h>
       
    21 
       
    22 #include <HbTextEdit>
       
    23 #include <XQConversions>
       
    24 
       
    25 /*!
       
    26     Create the readonly text edit. 
       
    27 */
       
    28 HbTextEdit *CpAboutUtils::createTextEdit()
       
    29 {
       
    30     HbTextEdit *edit = new HbTextEdit();
       
    31     edit->setReadOnly(true);
       
    32     edit->setCursorVisibility(Hb::TextCursorHidden);  
       
    33     edit->clearContextMenuFlag(Hb::ShowTextContextMenuOnSelectionClicked);
       
    34     edit->clearContextMenuFlag(Hb::ShowTextContextMenuOnLongPress);
       
    35     return edit;
       
    36 }
       
    37 
       
    38 /*! 
       
    39     Return the localized string by logic string connecting \a prefixString and
       
    40     \a index 
       
    41 */
       
    42 QString CpAboutUtils::contentString(const QString &prefixString, int index)
       
    43 {
       
    44     QString contentString;       
       
    45     QString localization(prefixString);
       
    46     localization.append(QString::number(index));
       
    47     contentString.append(QString(hbTrId(localization.toAscii().constData())));   
       
    48     contentString.replace(lineBreak, htmlLineBreak);    
       
    49     return contentString;
       
    50 }
       
    51 
       
    52 /*!
       
    53     Returns html link for \a textContent with content text.
       
    54 */
       
    55 QString CpAboutUtils::linkHtmlContent(const QString &textContent)
       
    56 {
       
    57     QString link(htmlLinkStart);
       
    58     link.append(textContent);
       
    59     link.append(htmlLinkEnd);    
       
    60     return link;
       
    61 }
       
    62 
       
    63 /*!
       
    64      Trim the html address \a string, also replace \n with <br>
       
    65  */
       
    66 QString CpAboutUtils::preprocessText(const QString &string)
       
    67 {
       
    68     QString str(string.trimmed());    
       
    69     str.replace(lineBreak, htmlLineBreak);    
       
    70     return str;
       
    71 }
       
    72 
       
    73 /*!
       
    74     Replace html link in \a stringwith anchor. 
       
    75  */
       
    76 QString CpAboutUtils::findAndReplaceWithLink(const QString &string)
       
    77 {
       
    78     //stands for the web address.
       
    79     QRegExp regExp("[a-zA-z]+://[^\\s]*");
       
    80     
       
    81     QString str(string);
       
    82     if (string.indexOf(regExp) != KErrNotFound) {
       
    83         foreach(const QString &match, regExp.capturedTexts()) {
       
    84             QString originalString(match.trimmed());
       
    85             if (originalString.endsWith('.')) {
       
    86                 originalString = originalString.left(originalString.length()-1); 
       
    87             }
       
    88             QString replaceString("<a href = \"" + originalString + "\">"+ originalString + "</a>");
       
    89             str.replace(originalString, replaceString);                
       
    90         }
       
    91     }    
       
    92     return str;
       
    93 }
       
    94 
       
    95 /*!
       
    96     Returns the phone's model.
       
    97 */
       
    98 QString CpAboutUtils::getPhoneModel()
       
    99 {
       
   100     TBuf<100> phoneName;
       
   101     TInt error = SysVersionInfo::GetVersionInfo(SysVersionInfo::EModelVersion, phoneName);
       
   102     QString model;
       
   103     if (error == KErrNone) {
       
   104         if (phoneName.Length() > 0) {            
       
   105             model = XQConversions::s60DescToQString(phoneName);
       
   106             
       
   107         }
       
   108     }
       
   109     return model;
       
   110 }
       
   111 
       
   112 /*!
       
   113     Returns the produce release.
       
   114 */
       
   115 QString CpAboutUtils::getProductRelease()
       
   116 {
       
   117 
       
   118     TBuf<sysUtilVersionTextLength> productRelease;
       
   119     productRelease.Zero();
       
   120     QString release;
       
   121     if (SysUtil::GetPRInformation(productRelease) == KErrNone) {
       
   122         release = XQConversions::s60DescToQString(productRelease);
       
   123     }
       
   124     return release;
       
   125 }
       
   126 
       
   127 /*!
       
   128     Returns the software version.
       
   129 */
       
   130 QString CpAboutUtils::getSoftwareVersion()
       
   131 {
       
   132     TBuf<sysUtilVersionTextLength> swVersion;
       
   133     TBuf<sysUtilVersionTextLength> version;
       
   134     swVersion.Zero();
       
   135     version.Zero();
       
   136     QString versionText;
       
   137     if (SysUtil::GetSWVersion(version) == KErrNone) {
       
   138         TInt len = version.Length();
       
   139         TInt pos1 = version.Find(KEol);
       
   140         if (pos1 != KErrNotFound && len > pos1) {
       
   141             TBuf<sysUtilVersionTextLength> version1;
       
   142             version1.Zero();
       
   143             swVersion.Append(version.Left(pos1));
       
   144             versionText = XQConversions::s60DescToQString(swVersion);
       
   145         }
       
   146     } 
       
   147     return versionText;
       
   148 }
       
   149 
       
   150 /*!
       
   151      Returns the phone type.
       
   152 */
       
   153 QString CpAboutUtils::getPhoneType()
       
   154 {
       
   155     TBuf<sysUtilVersionTextLength> swVersion;
       
   156     TBuf<sysUtilVersionTextLength> swVersionDate;
       
   157     TBuf<sysUtilVersionTextLength> typeDesignator;
       
   158     TBuf<sysUtilVersionTextLength> version;
       
   159     swVersion.Zero();
       
   160     version.Zero();
       
   161     typeDesignator.Zero();
       
   162     swVersionDate.Zero();
       
   163     QString type;
       
   164     if (SysUtil::GetSWVersion(version) == KErrNone) {
       
   165         TInt len = version.Length();
       
   166         TInt pos1 = version.Find(KEol);
       
   167         if (pos1 != KErrNotFound && len > pos1) {
       
   168             TBuf<sysUtilVersionTextLength> version1;
       
   169             version1.Zero();
       
   170             swVersion.Append(version.Left(pos1));
       
   171             version1.Append(version.Right(len - pos1 - 1));
       
   172             len = version1.Length();
       
   173             pos1 = version1.Find(KEol);
       
   174             if (pos1 != KErrNotFound  && len > pos1) {
       
   175                 swVersionDate.Append(version1.Left(pos1));
       
   176                 version.Zero();
       
   177                 version.Append(version1.Right(len - pos1 - 1));
       
   178                 len= version.Length();
       
   179                 pos1 = version.Find(KEol);
       
   180                 if (pos1 != KErrNotFound  && len > pos1 ) {
       
   181                     typeDesignator.Append(version.Left(pos1)); 
       
   182                     if (typeDesignator.Length() > 0) { 
       
   183                         type = XQConversions::s60DescToQString(typeDesignator);
       
   184                     }
       
   185                 }
       
   186             }
       
   187         }
       
   188     } 
       
   189     return type;
       
   190 }