homescreenapp/hsdomainmodel/src/hswidgetcomponent.cpp
changeset 46 23b5d6a29cce
parent 39 4e8ebe173323
child 55 03646e8da489
equal deleted inserted replaced
39:4e8ebe173323 46:23b5d6a29cce
    16 */
    16 */
    17 
    17 
    18 #include <QCoreApplication>
    18 #include <QCoreApplication>
    19 #include <QDir>
    19 #include <QDir>
    20 
    20 
       
    21 #include "hswidgetcomponent.h"
       
    22 #include "hswidgetcomponentdescriptor.h"
    21 #include "hswidgetcomponentregistry.h"
    23 #include "hswidgetcomponentregistry.h"
    22 #include "hswidgetcomponent.h"
       
    23 #include "hsapp_defs.h"
    24 #include "hsapp_defs.h"
    24 #include "caservice.h"
    25 #include "caservice.h"
    25 #include "caquery.h"
    26 #include "caquery.h"
    26 #include "canotifier.h"
    27 
    27 
    28 
    28 /*!
    29 /*!
    29 
    30 
    30 */
    31 */
    31 HsWidgetComponent::~HsWidgetComponent()
    32 HsWidgetComponent::~HsWidgetComponent()
    46 QString HsWidgetComponent::uri() const
    47 QString HsWidgetComponent::uri() const
    47 {
    48 {
    48     return mUri;
    49     return mUri;
    49 }
    50 }
    50 
    51 
       
    52 
       
    53 bool HsWidgetComponent::isAvailable() const
       
    54 {
       
    55     bool ret(true);
       
    56     if (mRootPath.isEmpty() || !QDir(mRootPath).exists()) {
       
    57         ret = false;
       
    58     }
       
    59     return  ret;
       
    60 }
    51 /*!
    61 /*!
    52 
    62 
    53 */
    63 */
    54 HsWidgetComponent::HsWidgetComponent(const QString &uri, QObject *parent)
    64 HsWidgetComponent::HsWidgetComponent(const QString &uri, QObject *parent)
    55   : QObject(parent),
    65   : QObject(parent),
    56     mUri(uri)
    66     mUri(uri),
       
    67     mState(Available)
    57 {
    68 {
    58     listenChangeEvents();
       
    59 	resolveRootPath();
    69 	resolveRootPath();
    60 	installTranslator();
    70 	installTranslator();
       
    71 	
    61 }
    72 }
    62 
    73 
    63 /*!
       
    64 
       
    65 */
       
    66 void HsWidgetComponent::listenChangeEvents()
       
    67 {
       
    68 	CaQuery query;
       
    69     query.setEntryTypeNames(QStringList(widgetTypeName()));
       
    70 	CaNotifierFilter filter(query);  
       
    71     CaNotifier *notifier = CaService::instance()->createNotifier(filter);
       
    72     notifier->setParent(this);
       
    73     connect(notifier,
       
    74             SIGNAL(entryChanged(CaEntry,ChangeType)),
       
    75             SLOT(onEntryChanged(CaEntry,ChangeType)));
       
    76 }
       
    77 
    74 
    78 /*!
    75 /*!
    79 
    76 
    80 */
    77 */
    81 void HsWidgetComponent::resolveRootPath()
    78 void HsWidgetComponent::resolveRootPath()
    84     query.setEntryTypeNames(QStringList(widgetTypeName()));
    81     query.setEntryTypeNames(QStringList(widgetTypeName()));
    85 	query.setAttribute(widgetUriAttributeName(), mUri);
    82 	query.setAttribute(widgetUriAttributeName(), mUri);
    86 	QList< QSharedPointer<CaEntry> > widgetEntries = CaService::instance()->getEntries(query);
    83 	QList< QSharedPointer<CaEntry> > widgetEntries = CaService::instance()->getEntries(query);
    87 	
    84 	
    88     if (widgetEntries.isEmpty()) {
    85     if (widgetEntries.isEmpty()) {
    89 		return;
    86         return;
    90 	}
    87 	}
    91     QSharedPointer<CaEntry> entry = widgetEntries.first();
    88     QSharedPointer<CaEntry> entry = widgetEntries.first();
    92     mRootPath = entry->attribute(widgetPathAttributeName());
    89     mRootPath = entry->attribute(widgetPathAttributeName());
       
    90     if (mRootPath.isEmpty() || !QDir(mRootPath).exists()) {
       
    91         mState = Unavailable;
       
    92     }
    93 }
    93 }
    94 
    94 
    95 /*!
    95 /*!
    96 
    96 
    97 */
    97 */
   134 void HsWidgetComponent::uninstallTranslator()
   134 void HsWidgetComponent::uninstallTranslator()
   135 {
   135 {
   136     QCoreApplication::removeTranslator(&mTranslator);
   136     QCoreApplication::removeTranslator(&mTranslator);
   137 }
   137 }
   138 
   138 
   139 /*!
   139 void HsWidgetComponent::emitAboutToUninstall()
   140     This slot reacts to \a entry change that is described with 
       
   141     \a changeType. On remove change type, aboutToUninstall() signal is
       
   142     emitted.
       
   143 */
       
   144 void HsWidgetComponent::onEntryChanged(const CaEntry &entry, ChangeType changeType)
       
   145 {
   140 {
   146     if (changeType == RemoveChangeType) {
   141     if (mState == Available) {
   147         QString uri = entry.attribute(widgetUriAttributeName());
   142         mState = Uninstalling;
   148         if (uri == mUri) {
   143         emit aboutToUninstall();
   149            	uninstallTranslator();
       
   150 			emit aboutToUninstall();
       
   151         }
       
   152     }
   144     }
   153 }
   145 }
       
   146 void HsWidgetComponent::emitUninstalled()
       
   147 {
       
   148     if (mState == Uninstalling) {
       
   149         mState = Available;
       
   150         emit uninstalled();
       
   151     }
       
   152 }
       
   153 void HsWidgetComponent::emitUpdated()
       
   154 {
       
   155     if (mState == Uninstalling) {
       
   156         mState = Available;
       
   157         emit updated();
       
   158     }
       
   159 }
       
   160 void HsWidgetComponent::emitUnavailable()
       
   161 {
       
   162     if (mState == Available) {
       
   163         mState = Unavailable;
       
   164         emit unavailable();
       
   165     }
       
   166 }
       
   167 void HsWidgetComponent::emitAvailable()
       
   168 {
       
   169     if (mState == Unavailable) {
       
   170         mState = Available;
       
   171         emit available();
       
   172     }
       
   173 }
       
   174 
       
   175 
       
   176 
       
   177 
       
   178     
       
   179