src/hbcore/effects/hbeffectcontroller.cpp
changeset 5 627c4a0fd0e7
parent 1 f7ac710697a9
child 7 923ff622b8b9
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    38 #include <QFile>
    38 #include <QFile>
    39 #include <QDebug>
    39 #include <QDebug>
    40 
    40 
    41 /*
    41 /*
    42   \class HbEffectController hbeffectcontroller.h
    42   \class HbEffectController hbeffectcontroller.h
    43   \brief HbEffectController is used to read and store effects data. 
    43   \brief HbEffectController is used to read and store effects data.
    44 */
    44 */
    45 
    45 
    46 /* 
    46 /*
    47    Constructs a HbEffectController.
    47    Constructs a HbEffectController.
    48 */
    48 */
    49 HbEffectController::HbEffectController()
    49 HbEffectController::HbEffectController()
    50     : mParser(0),
    50     : mParser(0),
    51       mShared(false),
    51       mShared(false),
    52       mSharingSet(false)
    52       mSharingSet(false)
    53 {
    53 {
    54 }
    54 }
    55 
    55 
    56 /* 
    56 /*
    57    Destructor.
    57    Destructor.
    58 */
    58 */
    59 HbEffectController::~HbEffectController()
    59 HbEffectController::~HbEffectController()
    60 {
    60 {
    61     delete mParser;
    61     delete mParser;
    63 
    63 
    64 HbEffectFxmlData HbEffectController::fetchFxmlData(
    64 HbEffectFxmlData HbEffectController::fetchFxmlData(
    65     const QString &componentType,
    65     const QString &componentType,
    66     QGraphicsItem *component,
    66     QGraphicsItem *component,
    67     const QString &effectEvent,
    67     const QString &effectEvent,
    68     bool shared ) const
    68     bool shared) const
    69 {
    69 {
    70     Q_UNUSED(shared); // not yet needed since we have a list of added items in local process
    70     Q_UNUSED(shared); // not yet needed since we have a list of added items in local process
    71     int componentTypeMatchIndex = -1;
    71     int componentTypeMatchIndex = -1;
    72 
    72 
    73     // Find the definition for the component
    73     // Find the definition for the component
    74     for (int i = 0; i < mEffectEntries.count(); ++i) {
    74     for (int i = 0; i < mEffectEntries.count(); ++i) {
    75         const HbEffectInfo &info = mEffectEntries.at(i);
    75         const HbEffectInfo &info = mEffectEntries.at(i);
    76         // If found a definition matching the graphics item, return that.
    76         // If found a definition matching the graphics item, return that.
    77         if (info.item() // not null
    77         if (info.item() // not null
    78             && info.item() == component // matches the component
    78                 && info.item() == component // matches the component
    79             && info.inUse() // the effect is in use (not removed)
    79                 && info.inUse() // the effect is in use (not removed)
    80             && info.effectEvent() == effectEvent) // matches the event
    80                 && info.effectEvent() == effectEvent) { // matches the event
    81         {
       
    82             // sharing support -  if it's shared get the FxML data from server and return the object
    81             // sharing support -  if it's shared get the FxML data from server and return the object
    83             // with parsed FxML data
    82             // with parsed FxML data
    84             if( info.shared() ) {
    83             if (info.shared()) {
    85                 HbEffectFxmlData *dataFromSrv = HbThemeClient::global()->getSharedEffect(info.mDefFileFullPath);
    84                 HbEffectFxmlData *dataFromSrv = HbThemeClient::global()->getSharedEffect(info.mDefFileFullPath);
    86                 if(dataFromSrv) {
    85                 if (dataFromSrv) {
    87                     return *dataFromSrv;
    86                     return *dataFromSrv;
    88                 }
    87                 }
    89             } else {
    88             } else {
    90                 return info.effectData();
    89                 return info.effectData();
    91             }
    90             }
    98             componentTypeMatchIndex = i;
    97             componentTypeMatchIndex = i;
    99         }
    98         }
   100     }
    99     }
   101     if (componentTypeMatchIndex >= 0) {
   100     if (componentTypeMatchIndex >= 0) {
   102         const HbEffectInfo &info = mEffectEntries.at(componentTypeMatchIndex);
   101         const HbEffectInfo &info = mEffectEntries.at(componentTypeMatchIndex);
   103         if ( info.shared() ) {
   102         if (info.shared()) {
   104             HbEffectFxmlData *dataFromSrv =
   103             HbEffectFxmlData *dataFromSrv =
   105                 HbThemeClient::global()->getSharedEffect(info.mDefFileFullPath);
   104                 HbThemeClient::global()->getSharedEffect(info.mDefFileFullPath);
   106             if(dataFromSrv) {
   105             if (dataFromSrv) {
   107                 return *dataFromSrv;
   106                 return *dataFromSrv;
   108             }
   107             }
   109         } else {
   108         } else {
   110             return mEffectEntries.at(componentTypeMatchIndex).effectData();
   109             return mEffectEntries.at(componentTypeMatchIndex).effectData();
   111         }
   110         }
   129 {
   128 {
   130     QString fullPath = expandFileName(filePath);
   129     QString fullPath = expandFileName(filePath);
   131     for (int i = mEffectEntries.count() - 1; i >= 0; i--) {
   130     for (int i = mEffectEntries.count() - 1; i >= 0; i--) {
   132         const HbEffectInfo &info = mEffectEntries[i];
   131         const HbEffectInfo &info = mEffectEntries[i];
   133         if (info.componentType() == componentType &&
   132         if (info.componentType() == componentType &&
   134             info.xmlFileFullPath() == fullPath &&
   133                 info.xmlFileFullPath() == fullPath &&
   135             info.effectEvent() == effectEvent)
   134                 info.effectEvent() == effectEvent) {
   136         {
       
   137             // Remove the definition for the given component type
   135             // Remove the definition for the given component type
   138             mEffectEntries.removeAt(i);
   136             mEffectEntries.removeAt(i);
   139         }
   137         }
   140     }
   138     }
   141 }
   139 }
   144 {
   142 {
   145     QString fullPath = expandFileName(filePath);
   143     QString fullPath = expandFileName(filePath);
   146     for (int i = mEffectEntries.count() - 1; i >= 0; i--) {
   144     for (int i = mEffectEntries.count() - 1; i >= 0; i--) {
   147         const HbEffectInfo &info = mEffectEntries[i];
   145         const HbEffectInfo &info = mEffectEntries[i];
   148         if (info.item() == item &&
   146         if (info.item() == item &&
   149             info.xmlFileFullPath() == fullPath &&
   147                 info.xmlFileFullPath() == fullPath &&
   150             info.effectEvent() == effectEvent)
   148                 info.effectEvent() == effectEvent) {
   151         {
       
   152             // Remove the definition for the given item
   149             // Remove the definition for the given item
   153             mEffectEntries.removeAt(i);
   150             mEffectEntries.removeAt(i);
   154         }
   151         }
   155     }
   152     }
   156 }
   153 }
   182 }
   179 }
   183 
   180 
   184 QString HbEffectController::expandFileName(const QString &fn, bool *fromTheme, bool *shared)
   181 QString HbEffectController::expandFileName(const QString &fn, bool *fromTheme, bool *shared)
   185 {
   182 {
   186     // Sharing not supported if the file is in Qt resource.
   183     // Sharing not supported if the file is in Qt resource.
   187     if (fn.startsWith(":/") && shared && *shared) {
   184     if (fn.startsWith(QLatin1String(":/")) && shared && *shared) {
   188         *shared = false;
   185         *shared = false;
   189         return fn;
   186         return fn;
   190     } else {
   187     } else {
   191         // Try the theme, will return the same name if not found in the theme.
   188         // Try the theme, will return the same name if not found in the theme.
   192         bool temp;
   189         bool temp;
   200 {
   197 {
   201     if (mSharingSet) {
   198     if (mSharingSet) {
   202         shared = mShared;
   199         shared = mShared;
   203     }
   200     }
   204     // If client is not connected due to any reason, any kind of sharing is not possible
   201     // If client is not connected due to any reason, any kind of sharing is not possible
   205     if ( !HbThemeClient::global()->clientConnected() ) {
   202     if (!HbThemeClient::global()->clientConnected()) {
   206         shared = mShared = mSharingSet = false;
   203         shared = mShared = mSharingSet = false;
   207     }
   204     }
   208     bool fromTheme = false;
   205     bool fromTheme = false;
   209     QString filePath = expandFileName(fileName, &fromTheme, &shared);
   206     QString filePath = expandFileName(fileName, &fromTheme, &shared);
   210 
   207 
   213     for (int i = 0, ie = mEffectEntries.count(); i != ie; ++i) {
   210     for (int i = 0, ie = mEffectEntries.count(); i != ie; ++i) {
   214         // non-const reference needed here to modify the actual data item
   211         // non-const reference needed here to modify the actual data item
   215         HbEffectInfo &info = mEffectEntries[i];
   212         HbEffectInfo &info = mEffectEntries[i];
   216 
   213 
   217         if ((item && info.item() == item)
   214         if ((item && info.item() == item)
   218             || (!componentType.isEmpty() && info.componentType() == componentType))
   215                 || (!componentType.isEmpty() && info.componentType() == componentType)) {
   219         {
   216             if (info.effectEvent() == effectEvent) {
   220             if (info.effectEvent() == effectEvent) {    
       
   221                 if (info.xmlFileFullPath() == filePath) {
   217                 if (info.xmlFileFullPath() == filePath) {
   222                     // parsed already, just set in use
   218                     // parsed already, just set in use
   223                     info.mInUse = true;
   219                     info.mInUse = true;
   224                     return true;
   220                     return true;
   225                 } else {
   221                 } else {
   231                 }
   227                 }
   232             }
   228             }
   233         }
   229         }
   234     }
   230     }
   235 
   231 
   236     if ( shared ) {
   232     if (shared) {
   237         if (!HbThemeClient::global()->addSharedEffect(filePath)) {
   233         if (!HbThemeClient::global()->addSharedEffect(filePath)) {
   238             // Themeserver failed, try to parse locally.
   234             // Themeserver failed, try to parse locally.
   239             shared = false;
   235             shared = false;
   240         }
   236         }
   241     }
   237     }