homescreenapp/hsdomainmodel/src/hswidgetcomponent.cpp
changeset 62 341166945d65
parent 55 03646e8da489
child 81 7dd137878ff8
equal deleted inserted replaced
57:2e2dc3d30ca8 62:341166945d65
    21 #include "hswidgetcomponent.h"
    21 #include "hswidgetcomponent.h"
    22 #include "hsapp_defs.h"
    22 #include "hsapp_defs.h"
    23 #include "caservice.h"
    23 #include "caservice.h"
    24 #include "caquery.h"
    24 #include "caquery.h"
    25 
    25 
    26 
    26 /*!
    27 /*!
    27     \class HsWidgetComponent
    28 
    28     \ingroup group_hsdomainmodel
       
    29     \brief Widget component represent a widget package.
       
    30 
       
    31     Widget component is accessed through a HsWidgetComponentRegistry. All widget instances from same type 
       
    32     are refering to one HsWidgetComponent and can listen component state changes
       
    33     
       
    34 */
       
    35 
       
    36 
       
    37 /*!
       
    38     Destructor
    29 */
    39 */
    30 HsWidgetComponent::~HsWidgetComponent()
    40 HsWidgetComponent::~HsWidgetComponent()
    31 {
    41 {
    32 }
    42 }
    33 
    43 
    34 /*!
    44 /*!
    35 
    45     Widget component installation path
    36 */
    46 */
    37 QString HsWidgetComponent::rootPath() const
    47 QString HsWidgetComponent::rootPath() const
    38 {
    48 {
    39     return mRootPath;
    49     return mRootPath;
    40 }
    50 }
    41 
    51 
    42 /*!
    52 /*!
    43 
    53     Widget unique identifier
    44 */
    54 */
    45 QString HsWidgetComponent::uri() const
    55 QString HsWidgetComponent::uri() const
    46 {
    56 {
    47     return mUri;
    57     return mUri;
    48 }
    58 }
    49 
    59 
    50 
    60 /*!
       
    61     Returns true if widget is available thus it's root path exists
       
    62 */
    51 bool HsWidgetComponent::isAvailable() const
    63 bool HsWidgetComponent::isAvailable() const
    52 {
    64 {
    53     bool ret(true);
    65     bool ret(true);
    54     if (mRootPath.isEmpty() || !QDir(mRootPath).exists()) {
    66     if (mRootPath.isEmpty() || !QDir(mRootPath).exists()) {
    55         ret = false;
    67         ret = false;
    56     }
    68     }
    57     return  ret;
    69     return  ret;
    58 }
    70 }
    59 /*!
    71 /*!
    60 
    72     \fn HsWidgetComponent::aboutToUninstall()
       
    73 
       
    74     This signal is emitted before component is uninstalled. 
       
    75     System may delete widget instances and release all resources 
       
    76     related to component. Component installation will fail, if installer 
       
    77     can't remove and install some file if someone has handle to it.
       
    78 
       
    79 */
       
    80 
       
    81 /*!
       
    82     \fn HsWidgetComponent::uninstalled()
       
    83 
       
    84     This signal is emitted after component is uninstalled from device.
       
    85 */
       
    86 
       
    87 /*!
       
    88     \fn HsWidgetComponent::updated()
       
    89 
       
    90     This signal is emitted when component is updated.
       
    91 */
       
    92 
       
    93 /*!
       
    94     \fn HsWidgetComponent::unavailable()
       
    95 
       
    96     This signal is emitted when component comes unavailable i.e media is removed.
       
    97 */
       
    98 
       
    99 /*!
       
   100     \fn HsWidgetComponent::available()
       
   101 
       
   102     This signal is emitted when component comes available i.e media is attached.
       
   103 */
       
   104 
       
   105 
       
   106 /*!
       
   107     Constructor
    61 */
   108 */
    62 HsWidgetComponent::HsWidgetComponent(const QString &uri, QObject *parent)
   109 HsWidgetComponent::HsWidgetComponent(const QString &uri, QObject *parent)
    63   : QObject(parent),
   110   : QObject(parent),
    64     mUri(uri),
   111     mUri(uri),
    65     mState(Available)
   112     mState(Available)
    66 {
   113 {
    67 	resolveRootPath();
   114     resolveRootPathAndTranslationFilename();
    68 	installTranslator();
   115 	installTranslator();
    69 	
   116 	
    70 }
   117 }
    71 
   118 
    72 
   119 
    73 /*!
   120 /*!
    74 
   121     Resolves component's root path and translation file name if any
    75 */
   122 */
    76 void HsWidgetComponent::resolveRootPath()
   123 void HsWidgetComponent::resolveRootPathAndTranslationFilename()
    77 {
   124 {
    78 	CaQuery query;
   125 	CaQuery query;
    79     query.setEntryTypeNames(QStringList(widgetTypeName()));
   126     query.setEntryTypeNames(QStringList(widgetTypeName()));
    80 	query.setAttribute(widgetUriAttributeName(), mUri);
   127 	query.setAttribute(widgetUriAttributeName(), mUri);
    81 	QList< QSharedPointer<CaEntry> > widgetEntries = CaService::instance()->getEntries(query);
   128 	QList< QSharedPointer<CaEntry> > widgetEntries = CaService::instance()->getEntries(query);
    85 	}
   132 	}
    86     QSharedPointer<CaEntry> entry = widgetEntries.first();
   133     QSharedPointer<CaEntry> entry = widgetEntries.first();
    87     mRootPath = entry->attribute(widgetPathAttributeName());
   134     mRootPath = entry->attribute(widgetPathAttributeName());
    88     if (mRootPath.isEmpty() || !QDir(mRootPath).exists()) {
   135     if (mRootPath.isEmpty() || !QDir(mRootPath).exists()) {
    89         mState = Unavailable;
   136         mState = Unavailable;
    90     }
   137     } else {
    91 }
   138         mTranslationFilename = entry->attribute(translationFilename());
    92 
   139     }
    93 /*!
   140 }
    94 
   141 
       
   142 /*!
       
   143     Search component's translation dile and installs translator to application
    95 */
   144 */
    96 void HsWidgetComponent::installTranslator()
   145 void HsWidgetComponent::installTranslator()
    97 {
   146 {
    98     QStringList possiblePaths;
   147     QStringList possiblePaths;
    99 #ifdef Q_OS_WIN32
   148 #ifdef Q_OS_WIN32
   109     drive.append("resource/qt/translations");
   158     drive.append("resource/qt/translations");
   110     possiblePaths << drive;
   159     possiblePaths << drive;
   111     // if it is not in installed,then check z drive
   160     // if it is not in installed,then check z drive
   112     possiblePaths << "z:/resource/qt/translations";
   161     possiblePaths << "z:/resource/qt/translations";
   113 #endif
   162 #endif
   114     
   163 
   115     for(int i=0; i<possiblePaths.count(); ++i) {
   164     for(int i=0; i<possiblePaths.count(); ++i) {
   116         QString candidate = QDir::toNativeSeparators(possiblePaths.at(i));   
   165         QString candidate = QDir::toNativeSeparators(possiblePaths.at(i));   
   117         if (QDir(candidate).exists()) {
   166         if (QDir(candidate).exists()) {
   118             QString fileName(mUri);
   167             QString fileName(mTranslationFilename);
   119 		    fileName.append("_");
   168             fileName.append("_");
   120 		    fileName.append(QLocale::system().name());
   169             fileName.append(QLocale::system().name());
   121             if (mTranslator.load(fileName, candidate)) {
   170             if (mTranslator.load(fileName, candidate)) {
   122                 QCoreApplication::installTranslator(&mTranslator);
   171                 QCoreApplication::installTranslator(&mTranslator);
   123 		        break;
   172                 break;
   124             }
   173             }
   125 	    }
   174         }
   126     }
   175     }        
   127 }
   176 }
   128 
   177 
   129 /*!
   178 /*!
   130 
   179     Unistall translator from application 
   131 */
   180 */
   132 void HsWidgetComponent::uninstallTranslator()
   181 void HsWidgetComponent::uninstallTranslator()
   133 {
   182 {
   134     QCoreApplication::removeTranslator(&mTranslator);
   183     QCoreApplication::removeTranslator(&mTranslator);
   135 }
   184 }
   136 
   185 
       
   186 /*!
       
   187     Emit aboutToUninstall signal 
       
   188 */
   137 void HsWidgetComponent::emitAboutToUninstall()
   189 void HsWidgetComponent::emitAboutToUninstall()
   138 {
   190 {
   139     if (mState == Available) {
   191     if (mState == Available) {
   140         mState = Uninstalling;
   192         mState = Uninstalling;
   141         emit aboutToUninstall();
   193         emit aboutToUninstall();
   142     }
   194     }
   143 }
   195 }
       
   196 /*!
       
   197     Emit uninstalled signal 
       
   198 */
   144 void HsWidgetComponent::emitUninstalled()
   199 void HsWidgetComponent::emitUninstalled()
   145 {
   200 {
   146     if (mState == Uninstalling) {
   201     if (mState == Uninstalling) {
   147         mState = Available;
   202         mState = Available;
   148         emit uninstalled();
   203         emit uninstalled();
   149     }
   204     }
   150 }
   205 }
       
   206 /*!
       
   207     Emit updated signal 
       
   208 */
   151 void HsWidgetComponent::emitUpdated()
   209 void HsWidgetComponent::emitUpdated()
   152 {
   210 {
   153     if (mState == Uninstalling) {
   211     if (mState == Uninstalling) {
   154         mState = Available;
   212         mState = Available;
   155         emit updated();
   213         emit updated();
   156     }
   214     }
   157 }
   215 }
       
   216 /*!
       
   217     Emit unavailable signal 
       
   218 */
   158 void HsWidgetComponent::emitUnavailable()
   219 void HsWidgetComponent::emitUnavailable()
   159 {
   220 {
   160     if (mState == Available) {
   221     if (mState == Available) {
   161         mState = Unavailable;
   222         mState = Unavailable;
   162         emit unavailable();
   223         emit unavailable();
   163     }
   224     }
   164 }
   225 }
       
   226 /*!
       
   227     Emit available signal 
       
   228 */
   165 void HsWidgetComponent::emitAvailable()
   229 void HsWidgetComponent::emitAvailable()
   166 {
   230 {
   167     if (mState == Unavailable) {
   231     if (mState == Unavailable) {
   168         mState = Available;
   232         mState = Available;
   169         emit available();
   233         emit available();