OSDN Git Service

Made getLogFile() function "const" and made sure that we will return a const referenc...
[lamexp/LameXP.git] / src / Model_FileSystem.cpp
index a135408..e42dfde 100644 (file)
@@ -55,6 +55,7 @@ private:
        const QIcon m_musicIcon;
        const QIcon m_moviesIcon;
        const QIcon m_picturesIcon;
+       const QIcon m_heartIcon;
        const QIcon m_emptyIcon;
        const QString m_folderType;
        const QString m_emptyType;
@@ -63,6 +64,7 @@ private:
        const QString m_musicDir;
        const QString m_moviesDir;
        const QString m_picturesDir;
+       const QString m_installDir;
 };
 
 QFileIconProviderEx::QFileIconProviderEx()
@@ -77,11 +79,13 @@ QFileIconProviderEx::QFileIconProviderEx()
        m_musicIcon(":/icons/music.png"),
        m_moviesIcon(":/icons/film.png"),
        m_picturesIcon(":/icons/picture.png"),
+       m_heartIcon(":/icons/heart.png"),
        m_homeDir(QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::HomeLocation))),
        m_desktopDir(QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation))),
        m_musicDir(QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MusicLocation))),
        m_moviesDir(QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation))),
        m_picturesDir(QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation))),
+       m_installDir(QDir::fromNativeSeparators(qApp->applicationDirPath())),
        m_folderType("Folder")
 {
        /* Nothing to do! */
@@ -111,29 +115,37 @@ QIcon QFileIconProviderEx::icon(const QFileInfo &info) const
                        break;
                }
        }
-       else if(!info.filePath().compare(m_homeDir, Qt::CaseInsensitive))
-       {
-               return m_homeIcon;
-       }
-       else if(!info.filePath().compare(m_desktopDir, Qt::CaseInsensitive))
-       {
-               return m_desktopIcon;
-       }
-       else if(!info.filePath().compare(m_musicDir, Qt::CaseInsensitive))
-       {
-               return m_musicIcon;
-       }
-       else if(!info.filePath().compare(m_moviesDir, Qt::CaseInsensitive))
-       {
-               return m_moviesIcon;
-       }
-       else if(!info.filePath().compare(m_picturesDir, Qt::CaseInsensitive))
-       {
-               return m_picturesIcon;
-       }
        else
        {
-               return  m_folderIcon;
+               const QString filePath = info.filePath();
+               if(m_homeDir.compare(filePath, Qt::CaseInsensitive) == 0)
+               {
+                       return m_homeIcon;
+               }
+               else if(m_desktopDir.compare(filePath, Qt::CaseInsensitive) == 0)
+               {
+                       return m_desktopIcon;
+               }
+               else if(m_musicDir.compare(filePath, Qt::CaseInsensitive) == 0)
+               {
+                       return m_musicIcon;
+               }
+               else if(m_moviesDir.compare(filePath, Qt::CaseInsensitive) == 0)
+               {
+                       return m_moviesIcon;
+               }
+               else if(m_picturesDir.compare(filePath, Qt::CaseInsensitive) == 0)
+               {
+                       return m_picturesIcon;
+               }
+               else if(m_installDir.compare(filePath, Qt::CaseInsensitive) == 0)
+               {
+                       return m_heartIcon;
+               }
+               else
+               {
+                       return  m_folderIcon;
+               }
        }
 }
 
@@ -153,6 +165,7 @@ QFileSystemModelEx::QFileSystemModelEx()
 
 QFileSystemModelEx::~QFileSystemModelEx()
 {
+       removeAllFromCache();
        LAMEXP_DELETE(m_myIconProvider);
 }
 
@@ -160,27 +173,16 @@ bool QFileSystemModelEx::hasChildren(const QModelIndex &parent) const
 {
        if(parent.isValid())
        {
-               return /*(QFileSystemModel::rowCount(parent) > 0) ||*/ hasSubfoldersCached(filePath(parent));
+               return hasSubfoldersCached(filePath(parent).toLower()); //return (QDir(QFileSystemModel::filePath(parent)).entryList(QDir::Dirs | QDir::NoDotAndDotDot).count() > 0);
        }
-       
        return true;
 }
 
-int QFileSystemModelEx::rowCount(const QModelIndex &parent) const
-{
-       if(parent.isValid())
-       {
-               removeFromCache(filePath(parent));
-       }
-
-       return QFileSystemModel::rowCount(parent);
-}
-
 void QFileSystemModelEx::fetchMore(const QModelIndex &parent)
 {
        if(parent.isValid())
        {
-               removeFromCache(filePath(parent));
+               removeFromCache(filePath(parent).toLower());
        }
 
        QFileSystemModel::fetchMore(parent);
@@ -191,7 +193,8 @@ QModelIndex QFileSystemModelEx::index(const QString &path, int column) const
        QFileInfo info(path);
        if(info.exists() && info.isDir())
        {
-               QStringList parts = QDir::fromNativeSeparators(info.canonicalFilePath()).split('/', QString::SkipEmptyParts);
+               QString fullPath = QDir::fromNativeSeparators(info.canonicalFilePath());
+               QStringList parts = fullPath.split('/', QString::SkipEmptyParts);
                for(int i = 2; i <= parts.count(); i++)
                {
                        QFileInfo currentPath(((QStringList) parts.mid(0, i)).join("/"));
@@ -200,11 +203,26 @@ QModelIndex QFileSystemModelEx::index(const QString &path, int column) const
                                return QModelIndex();
                        }
                }
-               return QFileSystemModel::index(path, column);
+               QModelIndex index = QFileSystemModel::index(fullPath, column);
+               if(index.isValid())
+               {
+                       QModelIndex temp = index;
+                       while(temp.isValid())
+                       {
+                               removeFromCache(filePath(temp).toLower());
+                               temp = temp.parent();
+                       }
+                       return index;
+               }
        }
        return QModelIndex();
 }
 
+void QFileSystemModelEx::flushCache(void)
+{
+       removeAllFromCache();
+}
+
 /* ------------------------ */
 /*  STATIC FUNCTIONS BELOW  */
 /* ------------------------ */
@@ -219,7 +237,7 @@ bool QFileSystemModelEx::FindFirstFileExInfoBasicOK = false;
 bool QFileSystemModelEx::hasSubfoldersCached(const QString &path)
 {
        QMutexLocker lock(&s_hasSubfolderMutex);
-       
+
        if(s_hasSubfolderCache.contains(path))
        {
                return s_hasSubfolderCache.value(path);
@@ -236,14 +254,23 @@ void QFileSystemModelEx::removeFromCache(const QString &path)
        s_hasSubfolderCache.remove(path);
 }
 
+void QFileSystemModelEx::removeAllFromCache(void)
+{
+       QMutexLocker lock(&s_hasSubfolderMutex);
+       s_hasSubfolderCache.clear();
+}
+
 bool QFileSystemModelEx::hasSubfolders(const QString &path)
 {
        if(!FindFirstFileExInitialized)
        {
-               QLibrary Kernel32Lib("kernel32.dll");
-               FindFirstFileExPtr = Kernel32Lib.resolve("FindFirstFileExW");
-               DWORD osVersionNo = lamexp_get_os_version();
-               FindFirstFileExInfoBasicOK = LAMEXP_MIN_OS_VER(osVersionNo, 6, 1);
+               QLibrary kernel32Lib("kernel32.dll");
+               if(kernel32Lib.load())
+               {
+                       FindFirstFileExPtr = kernel32Lib.resolve("FindFirstFileExW");
+                       const lamexp_os_version_t *osVersionNo = lamexp_get_os_version();
+                       FindFirstFileExInfoBasicOK = LAMEXP_MIN_OS_VER(osVersionNo, 6, 1);
+               }
                FindFirstFileExInitialized = true;
        }