src/hbcore/utils/hbdeviceprofile.cpp
changeset 5 627c4a0fd0e7
parent 1 f7ac710697a9
child 7 923ff622b8b9
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    33 #include "hbmainwindow_p.h"
    33 #include "hbmainwindow_p.h"
    34 
    34 
    35 #include <QDebug>
    35 #include <QDebug>
    36 
    36 
    37 // To store the pointer to the deviceProfiles at the client side.
    37 // To store the pointer to the deviceProfiles at the client side.
    38 static HbDeviceProfileList *deviceProfilesList = NULL;
    38 static HbDeviceProfileList *deviceProfilesList = 0;
    39 
    39 
    40 #define MM_PER_INCH 25.4
    40 #define MM_PER_INCH 25.4
    41 
    41 
    42 /*!
    42 /*!
    43 	@stable
    43     @stable
    44     @hbcore
    44     @hbcore
    45     \class HbDeviceProfile
    45     \class HbDeviceProfile
    46     \brief HbDeviceProfile holds read-only device parameters. 
    46     \brief HbDeviceProfile holds read-only device parameters.
    47     
    47 
    48     Instances of this class hold both concrete device specific information 
    48     Instances of this class hold both concrete device specific information
    49     (e.g. physical display size) and aspects that have been configured for 
    49     (e.g. physical display size) and aspects that have been configured for
    50     a specific device (e.g. orientation, unit value).
    50     a specific device (e.g. orientation, unit value).
    51    
    51 
    52 */
    52 */
    53 
    53 
    54 /*!
    54 /*!
    55     Default constructor, a null profile.
    55     Default constructor, a null profile.
    56 */
    56 */
    77 */
    77 */
    78 HbDeviceProfile::HbDeviceProfile(const QString &name) : d_ptr(new HbDeviceProfilePrivate)
    78 HbDeviceProfile::HbDeviceProfile(const QString &name) : d_ptr(new HbDeviceProfilePrivate)
    79 {
    79 {
    80     if (d_ptr->deviceProfiles()) {
    80     if (d_ptr->deviceProfiles()) {
    81         int count = deviceProfilesList->count();
    81         int count = deviceProfilesList->count();
    82         bool found( false );
    82         bool found(false);
    83         for (int i = 0; !found && i < count; i++) {
    83         for (int i = 0; !found && i < count; i++) {
    84             if (deviceProfilesList->at(i).mName == name) {
    84             if (deviceProfilesList->at(i).mName == name) {
    85                 d_ptr->mProfile = deviceProfilesList->at(i);
    85                 d_ptr->mProfile = deviceProfilesList->at(i);
    86                 found = true;
    86                 found = true;
    87             }
    87             }
   172 {
   172 {
   173     return d_ptr->mProfile.mTouch;
   173     return d_ptr->mProfile.mTouch;
   174 }
   174 }
   175 
   175 
   176 /*!
   176 /*!
   177     Returns name of alternate profile. 
   177     Returns name of alternate profile.
   178     
   178 
   179     Currently this holds information of the profile which is activated
   179     Currently this holds information of the profile which is activated
   180     on layout switch. Use this information if you need to optimize
   180     on layout switch. Use this information if you need to optimize
   181     layout switch.
   181     layout switch.
   182 */
   182 */
   183 QString HbDeviceProfile::alternateProfileName() const
   183 QString HbDeviceProfile::alternateProfileName() const
   187 
   187 
   188 /*!
   188 /*!
   189     Returns standard unit value (denoted by 'un').
   189     Returns standard unit value (denoted by 'un').
   190 
   190 
   191     The unit value is a display-specific multiplier. It is used in intenal
   191     The unit value is a display-specific multiplier. It is used in intenal
   192     layout calculation. 
   192     layout calculation.
   193 */
   193 */
   194 qreal HbDeviceProfile::unitValue() const
   194 qreal HbDeviceProfile::unitValue() const
   195 {
   195 {
   196     if (d_ptr->mProfile.mUnitValue <= 1) {
   196     if (d_ptr->mProfile.mUnitValue <= 1) {
   197         return 6.7;
   197         return 6.7;
   207     return d_ptr->mProfile.mPpiValue / MM_PER_INCH;
   207     return d_ptr->mProfile.mPpiValue / MM_PER_INCH;
   208 }
   208 }
   209 
   209 
   210 /*!
   210 /*!
   211     Returns current global profile reflecting properties of primary display.
   211     Returns current global profile reflecting properties of primary display.
   212     
   212 
   213     Usually, you should not use this method. Instead, use one of \c profile
   213     Usually, you should not use this method. Instead, use one of \c profile
   214     methods.
   214     methods.
   215 */
   215 */
   216 HbDeviceProfile HbDeviceProfile::current()
   216 HbDeviceProfile HbDeviceProfile::current()
   217 {
   217 {
   234     return profile;
   234     return profile;
   235 }
   235 }
   236 
   236 
   237 /*!
   237 /*!
   238     Returns current profile for this graphics item.
   238     Returns current profile for this graphics item.
   239     
   239 
   240     Graphics item must be tied to a scene and scene needs to be part of
   240     Graphics item must be tied to a scene and scene needs to be part of
   241     main window. Otherwise, value returned by \c current is provided.
   241     main window. Otherwise, value returned by \c current is provided.
   242 
   242 
   243     \param item item of which profile is needed.
   243     \param item item of which profile is needed.
   244     \return device profile.
   244     \return device profile.
   251     QGraphicsScene *scene = item->scene();
   251     QGraphicsScene *scene = item->scene();
   252     if (!scene) {
   252     if (!scene) {
   253         return current();
   253         return current();
   254     }
   254     }
   255     QList<QGraphicsView *> views = scene->views();
   255     QList<QGraphicsView *> views = scene->views();
   256     foreach(QGraphicsView *view, views) {
   256     foreach(QGraphicsView * view, views) {
   257         HbMainWindow *window = qobject_cast<HbMainWindow *>(view);
   257         HbMainWindow *window = qobject_cast<HbMainWindow *>(view);
   258         if (window) {
   258         if (window) {
   259             HbDeviceProfile profile = 
   259             HbDeviceProfile profile =
   260                 HbMainWindowPrivate::d_ptr(window)->profile();
   260                 HbMainWindowPrivate::d_ptr(window)->profile();
   261 
   261 
   262             if (!profile.isNull()) {
   262             if (!profile.isNull()) {
   263                 return profile;
   263                 return profile;
   264             } else {
   264             } else {
   278 }
   278 }
   279 
   279 
   280 QStringList HbDeviceProfilePrivate::profileNames()
   280 QStringList HbDeviceProfilePrivate::profileNames()
   281 {
   281 {
   282     QStringList profileNames;
   282     QStringList profileNames;
   283     if(deviceProfiles()){
   283     if (deviceProfiles()) {
   284         int profilesCount = deviceProfilesList->count();
   284         int profilesCount = deviceProfilesList->count();
   285         for(int i = 0;i < profilesCount ; i++) {
   285         for (int i = 0; i < profilesCount ; i++) {
   286             profileNames.append(deviceProfilesList->at(i).mName);
   286             profileNames.append(deviceProfilesList->at(i).mName);
   287         }
   287         }
   288     }
   288     }
   289     return profileNames;
   289     return profileNames;
   290 }
   290 }
   297 {
   297 {
   298 }
   298 }
   299 
   299 
   300 HbDeviceProfileList *HbDeviceProfilePrivate::deviceProfiles()
   300 HbDeviceProfileList *HbDeviceProfilePrivate::deviceProfiles()
   301 {
   301 {
   302     if(!deviceProfilesList) {
   302     if (!deviceProfilesList) {
   303 	// Will result in IPC call. gets the shared memory offset from themeserver.
   303         // Will result in IPC call. gets the shared memory offset from themeserver.
   304         deviceProfilesList = HbThemeClient::global()->deviceProfiles();
   304         deviceProfilesList = HbThemeClient::global()->deviceProfiles();
   305     }
   305     }
   306        
   306 
   307     if(!deviceProfilesList) {
   307     if (!deviceProfilesList) {
   308         // This is fall back.Create/Get the HbDeviceProfileDatabase Instance at
   308         // This is fall back.Create/Get the HbDeviceProfileDatabase Instance at
   309         // the client side and read the deviceProfilesList.
   309         // the client side and read the deviceProfilesList.
   310         qDebug()<<"DeviceProfile offset not returned by themeserver .. working in fallback mode";
   310         qDebug() << "DeviceProfile offset not returned by themeserver .. working in fallback mode";
   311         HbDeviceProfileDatabase *deviceProfileDataBase =
   311         HbDeviceProfileDatabase *deviceProfileDataBase =
   312                 HbDeviceProfileDatabase::instance(HbMemoryManager::HeapMemory);
   312             HbDeviceProfileDatabase::instance(HbMemoryManager::HeapMemory);
   313         deviceProfilesList = HbMemoryUtils::getAddress<HbDeviceProfileList>(HbMemoryManager::HeapMemory,
   313         deviceProfilesList = HbMemoryUtils::getAddress<HbDeviceProfileList>(HbMemoryManager::HeapMemory,
   314                                  deviceProfileDataBase->deviceProfilesOffset());
   314                              deviceProfileDataBase->deviceProfilesOffset());
   315     }
   315     }
   316     return deviceProfilesList;
   316     return deviceProfilesList;
   317 }
   317 }
   318 // end of file
   318 // end of file