src/hbservers/hbthemeserver/hbthemeserver_generic.cpp
changeset 5 627c4a0fd0e7
parent 3 11d3954df52a
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    28 
    28 
    29 #include <QLabel>
    29 #include <QLabel>
    30 #include <QLocalServer>
    30 #include <QLocalServer>
    31 #include <QLocalSocket>
    31 #include <QLocalSocket>
    32 #include <QSharedMemory>
    32 #include <QSharedMemory>
    33 #include <QSettings>
       
    34 #include <QDebug>
    33 #include <QDebug>
    35 #include <QList>
    34 #include <QList>
    36 #include <QIcon>
    35 #include <QIcon>
    37 #include <QFile>
    36 #include <QFile>
    38 #include <QCoreApplication>
    37 #include <QCoreApplication>
    54 #include "hbpixmapiconprocessor_p.h"
    53 #include "hbpixmapiconprocessor_p.h"
    55 #include "hblayeredstyleloader_p.h"
    54 #include "hblayeredstyleloader_p.h"
    56 #include "hbthemesystemeffect_p.h"
    55 #include "hbthemesystemeffect_p.h"
    57 #include "hbsharedmemorymanager_p.h"
    56 #include "hbsharedmemorymanager_p.h"
    58 #include "hbtypefaceinfodatabase_p.h"
    57 #include "hbtypefaceinfodatabase_p.h"
       
    58 #include "hbthemeutils_p.h"
    59 
    59 
    60 static const int CLOSE_TIMEOUT = 3000;
    60 static const int CLOSE_TIMEOUT = 3000;
    61 
    61 
    62 /*!
    62 /*!
    63   @hbserver
    63   @hbserver
    83     : QMainWindow(parent), server(new QLocalServer(this))
    83     : QMainWindow(parent), server(new QLocalServer(this))
    84 #else
    84 #else
    85 HbThemeServerPrivate::HbThemeServerPrivate(): server(new QLocalServer(this))
    85 HbThemeServerPrivate::HbThemeServerPrivate(): server(new QLocalServer(this))
    86 #endif
    86 #endif
    87 {
    87 {
    88     iThemeSelectionClient = 0;
       
    89     sessionList.clear();
    88     sessionList.clear();
    90 #ifdef QT_DEBUG
    89 #ifdef QT_DEBUG
    91     setWindowTitle("Theme Server");
    90     setWindowTitle("Theme Server");
    92     setCentralWidget(&statusLabel);
    91     setCentralWidget(&statusLabel);
    93 #endif
    92 #endif
    97     iconCache = tempIconCache.take();
    96     iconCache = tempIconCache.take();
    98     cssCache = tempCssCache.take();
    97     cssCache = tempCssCache.take();
    99     setMaxGpuCacheSize(GPU_CACHE_SIZE);
    98     setMaxGpuCacheSize(GPU_CACHE_SIZE);
   100     setMaxCpuCacheSize(CPU_CACHE_SIZE);
    99     setMaxCpuCacheSize(CPU_CACHE_SIZE);
   101 
   100 
       
   101     // Store the active theme name in a member string
       
   102     iCurrentThemeName = HbThemeUtils::getThemeSetting(HbThemeUtils::CurrentThemeSetting);    
       
   103 
       
   104     if (iCurrentThemeName.isEmpty()) {
       
   105         iCurrentThemeName = HbThemeUtils::defaultTheme().name;
       
   106     }
       
   107     
       
   108     // Resolve the path of the current theme
       
   109     QDir path(iCurrentThemeName);
       
   110     if (!path.isAbsolute()) {
       
   111         // Resolve the path of the current theme
       
   112         resolveThemePath(iCurrentThemeName, iCurrentThemePath);
       
   113     } else {
       
   114         iCurrentThemeName = path.dirName();
       
   115         iCurrentThemePath = path.absolutePath();
       
   116     }          
       
   117     // Process base theme index, it is used as parent index also when the current theme is something else
       
   118     QString basePath;
       
   119     resolveThemePath(HbThemeUtils::getThemeSetting(HbThemeUtils::BaseThemeSetting), basePath);
       
   120     HbThemeServerUtils::createThemeIndex(basePath, BaseTheme);
       
   121     // Process operator theme indexes
       
   122     QString operatorName = HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting);
       
   123     if (!operatorName.isEmpty()) {
       
   124         QString operatorPath( HbThemeUtils::baseTheme().rootDir + '/' +
       
   125             QLatin1String(HbThemeUtils::operatorHierarchy) + '/' +
       
   126             QLatin1String(HbThemeUtils::iconsResourceFolder) + '/' +
       
   127             operatorName );
       
   128         
       
   129         HbThemeServerUtils::createThemeIndex(operatorPath, OperatorC);
       
   130         // Operator Z not used in generic themeserver.
       
   131     }
       
   132     // Process current theme index
       
   133     HbThemeServerUtils::createThemeIndex(iCurrentThemePath, ActiveTheme);
       
   134 
       
   135     // Register theme system effects in construction
       
   136     // TODO: fix parameter
       
   137     HbThemeSystemEffect::handleThemeChange(iCurrentThemeName);
       
   138 
   102     connect(server, SIGNAL(newConnection()), this, SLOT(newClientConnected()));
   139     connect(server, SIGNAL(newConnection()), this, SLOT(newClientConnected()));
       
   140     HbThemeUtils::setThemeSetting(HbThemeUtils::CurrentThemeSetting, iCurrentThemePath);    
   103 }
   141 }
   104 
   142 
   105 /*!
   143 /*!
   106   \fn HbThemeServerPrivate::~HbThemeServerPrivate()
   144   \fn HbThemeServerPrivate::~HbThemeServerPrivate()
   107   Destructor
   145   Destructor
   271 void HbThemeServerPrivate::handleThemeSelection(const QString &newTheme)
   309 void HbThemeServerPrivate::handleThemeSelection(const QString &newTheme)
   272 {
   310 {
   273 #ifdef THEME_SERVER_TRACES
   311 #ifdef THEME_SERVER_TRACES
   274     qDebug() << Q_FUNC_INFO << "  theme=" << newTheme;
   312     qDebug() << Q_FUNC_INFO << "  theme=" << newTheme;
   275 #endif
   313 #endif
   276     // Modify the QSettings to store the applied theme
       
   277     QSettings settings(QLatin1String(ORGANIZATION), QLatin1String(THEME_COMPONENT));
       
   278 
   314 
   279     // Clear cached icons and session data
   315     // Clear cached icons and session data
   280     clearIconCache();
   316     clearIconCache();
   281     HbThemeServerSession *session;
   317     HbThemeServerSession *session;
   282     foreach(session, sessionList) {
   318     foreach(session, sessionList) {
   283         session->clearSessionIconData();
   319         session->clearSessionIconData();
   284     }
   320     }
   285 
   321 
   286     QString cleanThemeName = newTheme.trimmed();
   322     iCurrentThemeName = newTheme.trimmed();
   287     settings.remove("currenttheme"); //temporary
   323 
   288     settings.setValue(CURRENT_THEME_KEY, cleanThemeName);
   324     // Resolve the path of the current theme
   289     settings.sync();
   325     QDir path(iCurrentThemeName);
       
   326     if (!path.isAbsolute()) {
       
   327         // Resolve the path of the current theme
       
   328         resolveThemePath(iCurrentThemeName, iCurrentThemePath);
       
   329     } else {
       
   330         iCurrentThemeName = path.dirName();
       
   331         iCurrentThemePath = path.absolutePath();
       
   332     }          
       
   333 
       
   334     // Set the new theme in theme settings
       
   335     HbThemeUtils::setThemeSetting(HbThemeUtils::CurrentThemeSetting, iCurrentThemeName);    
       
   336 
       
   337     // Process operator Drive C theme index
       
   338     QString operatorName = HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting);
       
   339     if (!operatorName.isEmpty()) {
       
   340         QString operatorPath( HbThemeUtils::baseTheme().rootDir + '/' +
       
   341             QLatin1String(HbThemeUtils::operatorHierarchy) + '/' +
       
   342             QLatin1String(HbThemeUtils::iconsResourceFolder) + '/' +
       
   343             operatorName );
       
   344         
       
   345         HbThemeServerUtils::createThemeIndex(operatorPath, OperatorC);
       
   346     }
       
   347     // Process current theme index
       
   348     HbThemeServerUtils::createThemeIndex(iCurrentThemePath, ActiveTheme);
   290 
   349 
   291     // Register new system effects
   350     // Register new system effects
   292     HbThemeSystemEffect::handleThemeChange(cleanThemeName);
   351     HbThemeSystemEffect::handleThemeChange(iCurrentThemeName);
   293 
   352 
   294     HbThemeServerRequest requestType;
   353     HbThemeServerRequest requestType;
   295     requestType = EThemeSelection;
   354     requestType = EThemeSelection;
   296     QByteArray block;
   355     QByteArray block;
   297     QDataStream out(&block, QIODevice::WriteOnly);
   356     QDataStream out(&block, QIODevice::WriteOnly);
   298     out << (int)requestType;
   357     out << (int)requestType;
   299     out << cleanThemeName;
   358     out << iCurrentThemeName;
   300     writeToClients(block);
   359     writeToClients(block);
       
   360 }
       
   361 
       
   362 bool HbThemeServerPrivate::resolveThemePath(const QString &themeName, QString &themePath)
       
   363 {
       
   364     static QString mainThemesDir = QDir::fromNativeSeparators(qgetenv("HB_THEMES_DIR"));
       
   365 
       
   366     if (themeName == "hbdefault") {
       
   367         themePath = ":/themes/icons/hbdefault";
       
   368         return true;
       
   369     } else {
       
   370         QString themeLookupPath = mainThemesDir + "/themes/icons/" + themeName;
       
   371         if (QFile::exists(themeLookupPath + "/index.theme")) {
       
   372             themePath = themeLookupPath;
       
   373             return true;
       
   374         }
       
   375     }
       
   376 
       
   377     return false;
   301 }
   378 }
   302 
   379 
   303 void HbThemeServerPrivate::handleContentUpdate(const QStringList &fileNames)
   380 void HbThemeServerPrivate::handleContentUpdate(const QStringList &fileNames)
   304 {
   381 {
   305     // If list is empty clear all themed content
   382     // If list is empty clear all themed content
   372 #ifdef THEME_SERVER_TRACES
   449 #ifdef THEME_SERVER_TRACES
   373     qDebug() << Q_FUNC_INFO << "socketlist count: " << sessionList.count();
   450     qDebug() << Q_FUNC_INFO << "socketlist count: " << sessionList.count();
   374 #endif
   451 #endif
   375     foreach(session, sessionList) {
   452     foreach(session, sessionList) {
   376         QLocalSocket * curSocket = session->clientConnection();
   453         QLocalSocket * curSocket = session->clientConnection();
   377         if (iThemeSelectionClient != curSocket) {
   454         curSocket->write(block);
   378             curSocket->write(block);
   455     }
   379         }
       
   380     }
       
   381 }
       
   382 
       
   383 /*!
       
   384   \fn HbThemeServerPrivate::setThemeSelectionClient()
       
   385   Set the theme selection client
       
   386   \a socket
       
   387 */
       
   388 void HbThemeServerPrivate::setThemeSelectionClient(QLocalSocket *socket)
       
   389 {
       
   390     iThemeSelectionClient = socket;
       
   391 }
   456 }
   392 
   457 
   393 /*!
   458 /*!
   394   \fn HbThemeServerPrivate::newClientConnected()
   459   \fn HbThemeServerPrivate::newClientConnected()
   395   Creates a new session with the server.
   460   Creates a new session with the server.
   699             static_cast<QLocalSocket *>(sender())->write(output);
   764             static_cast<QLocalSocket *>(sender())->write(output);
   700             break;
   765             break;
   701         }
   766         }
   702         case EThemeSelection: {
   767         case EThemeSelection: {
   703             QString themename;
   768             QString themename;
   704             QLocalSocket *themeSelectionClient = static_cast<QLocalSocket *>(sender());
       
   705             inputDataStream >> themename;
   769             inputDataStream >> themename;
   706             iServer->setThemeSelectionClient(themeSelectionClient);
       
   707             iServer->handleThemeSelection(themename);
   770             iServer->handleThemeSelection(themename);
   708             break;
   771             break;
   709         }
   772         }
   710         case EThemeContentUpdate: {
   773         case EThemeContentUpdate: {
   711             QStringList themedItems;
   774             QStringList themedItems;
   761                           iServer->currentRenderingMode());
   824                           iServer->currentRenderingMode());
   762             QByteArray output = handleIconLookup(key, data, options);
   825             QByteArray output = handleIconLookup(key, data, options);
   763             static_cast<QLocalSocket *>(sender())->write(output);
   826             static_cast<QLocalSocket *>(sender())->write(output);
   764             break;
   827             break;
   765         }
   828         }
   766         case EIconDefaultSize:
       
   767             break; //todo
       
   768         case EMultiPieceIcon: {
   829         case EMultiPieceIcon: {
   769             HbMultiIconParams frameItemParams;
   830             HbMultiIconParams frameItemParams;
   770             inputDataStream >> frameItemParams.multiPartIconList;
   831             inputDataStream >> frameItemParams.multiPartIconList;
   771             inputDataStream >> frameItemParams.multiPartIconData.multiPartIconId;
   832             inputDataStream >> frameItemParams.multiPartIconData.multiPartIconId;
   772 
   833