QTfrontend/util/DataManager.cpp
changeset 6937 7f77fa908a4e
parent 6931 86c951cd0f3f
child 6938 217ed62e872c
equal deleted inserted replaced
6936:8af2bf10ee62 6937:7f77fa908a4e
    32 #include "DataManager.h"
    32 #include "DataManager.h"
    33 
    33 
    34 
    34 
    35 DataManager::DataManager()
    35 DataManager::DataManager()
    36 {
    36 {
    37     userData = new QDir(cfgdir->absolutePath());
    37     m_userData = new QDir(cfgdir->absolutePath());
    38     if (!userData->cd("Data"))
    38     if (!m_userData->cd("Data"))
    39         userData = NULL;
    39         m_userData = NULL;
    40 
    40 
    41     defaultData = new QDir(datadir->absolutePath());
    41     m_defaultData = new QDir(datadir->absolutePath());
       
    42 
       
    43     m_themeModel = NULL;
    42 }
    44 }
    43 
    45 
    44 
    46 
    45 DataManager & DataManager::instance()
    47 DataManager & DataManager::instance()
    46 {
    48 {
    55     const QStringList & nameFilters
    57     const QStringList & nameFilters
    56 ) const
    58 ) const
    57 {
    59 {
    58     QStringList result;
    60     QStringList result;
    59 
    61 
    60     if (userData != NULL)
    62     if (m_userData != NULL)
    61     {
    63     {
    62         QDir tmpDir(*userData);
    64         QDir tmpDir(*m_userData);
    63         if (tmpDir.cd(subDirectory))
    65         if (tmpDir.cd(subDirectory))
    64             result.append(tmpDir.entryList(nameFilters, filters));
    66             result.append(tmpDir.entryList(nameFilters, filters));
    65     }
    67     }
    66 
    68 
    67     QDir tmpDir(*defaultData);
    69     QDir tmpDir(*m_defaultData);
    68     if (tmpDir.cd(subDirectory))
    70     if (tmpDir.cd(subDirectory))
    69         result.append(tmpDir.entryList(nameFilters, filters));
    71         result.append(tmpDir.entryList(nameFilters, filters));
    70 
    72 
    71     result.removeDuplicates();
    73     result.removeDuplicates();
    72 
    74 
    85 QString DataManager::findFileForRead(
    87 QString DataManager::findFileForRead(
    86     const QString & relativeDataFilePath) const
    88     const QString & relativeDataFilePath) const
    87 {
    89 {
    88     QString path;
    90     QString path;
    89 
    91 
    90     if (userData != NULL)
    92     if (m_userData != NULL)
    91         path = userData->absolutePath()+"/"+relativeDataFilePath;
    93         path = m_userData->absolutePath()+"/"+relativeDataFilePath;
    92 
    94 
    93     if ((!path.isEmpty()) && (!QFile::exists(path)))
    95     if ((!path.isEmpty()) && (!QFile::exists(path)))
    94         path = defaultData->absolutePath()+"/"+relativeDataFilePath;
    96         path = m_defaultData->absolutePath()+"/"+relativeDataFilePath;
    95 
    97 
    96     return path;
    98     return path;
    97 }
    99 }
    98 
   100 
    99 
   101 
   100 QString DataManager::findFileForWrite(
   102 QString DataManager::findFileForWrite(
   101     const QString & relativeDataFilePath) const
   103     const QString & relativeDataFilePath) const
   102 {
   104 {
   103     if (userData != NULL)
   105     if (m_userData != NULL)
   104     {
   106     {
   105         QString path = userData->absolutePath()+"/"+relativeDataFilePath;
   107         QString path = m_userData->absolutePath()+"/"+relativeDataFilePath;
   106 
   108 
   107         // create folders if needed
   109         // create folders if needed
   108         QDir tmp;
   110         QDir tmp;
   109         tmp.mkpath(QFileInfo(path).absolutePath());
   111         tmp.mkpath(QFileInfo(path).absolutePath());
   110 
   112 
   113 
   115 
   114 
   116 
   115     return "";
   117     return "";
   116 }
   118 }
   117 
   119 
       
   120 ThemeModel * DataManager::themeModel()
       
   121 {
       
   122     if (m_themeModel == NULL) {
       
   123         m_themeModel = new ThemeModel();
       
   124         m_themeModel->loadThemes();
       
   125     }
       
   126     return m_themeModel;
       
   127 }
       
   128 
   118 void DataManager::reload()
   129 void DataManager::reload()
   119 {
   130 {
       
   131     m_themeModel->loadThemes();
   120     emit updated();
   132     emit updated();
   121 }
   133 }