LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
resourceloader.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #pragma once
10 
11 #include <memory>
12 #include <QObject>
13 #include <QStringList>
14 #include <QDir>
15 #include <QCache>
16 #include <QPixmap>
17 #include "sysconfig.h"
18 
19 class QAbstractItemModel;
20 class QStandardItemModel;
21 class QSortFilterProxyModel;
22 class QFileSystemWatcher;
23 class QTimer;
24 
25 namespace LC::Util
26 {
27  using QIODevice_ptr = std::shared_ptr<QIODevice>;
28 
69  class UTIL_SYS_API ResourceLoader : public QObject
70  {
71  Q_OBJECT
72 
73  QStringList LocalPrefixesChain_;
74  QStringList GlobalPrefixesChain_;
75  QString RelativePath_;
76 
77  QHash<QString, QStringList> Entry2Paths_;
78 
79  QStandardItemModel *SubElemModel_;
80  QStringList NameFilters_;
81  QDir::Filters AttrFilters_ = QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable;
82  QSortFilterProxyModel *SortModel_;
83 
84  QFileSystemWatcher *Watcher_;
85 
86  QTimer *CacheFlushTimer_;
87  mutable QCache<QString, QByteArray> CachePathContents_ { 0 };
88  mutable QCache<QString, QPixmap> CachePixmaps_ { 0 };
89 
90  bool Verbose_ = false;
91  public:
98  explicit ResourceLoader (const QString& relPath, QObject* obj = nullptr);
99 
108  void AddGlobalPrefix ();
109 
116  void AddLocalPrefix (QString prefix = QString ());
117 
131  void SetCacheParams (int size, int timeout);
132 
140  void FlushCache ();
141 
157  QFileInfoList List (const QString& option,
158  const QStringList& names = {},
159  QDir::Filters filters = QDir::NoFilter) const;
160 
185  QString GetPath (const QStringList& pathVariants) const;
186 
204  QString GetIconPath (const QString& basename) const;
205 
217  QIODevice_ptr Load (const QStringList& pathVariants, bool open = false) const;
218 
232  QIODevice_ptr Load (const QString& pathVariant, bool open = false) const;
233 
247  QIODevice_ptr GetIconDevice (const QString& basename, bool open = false) const;
248 
265  QPixmap LoadPixmap (const QString& basename) const;
266 
284  QAbstractItemModel* GetSubElemModel () const;
285 
301  void SetAttrFilters (QDir::Filters);
302 
318  void SetNameFilters (const QStringList&);
319 
326  void SetVerbose (bool verbose);
327  private:
328  void ScanPath (const QString&);
329  void HandleDirectoryChanged (const QString&);
330  signals:
331  void watchedDirectoriesChanged ();
332  };
333 }
UTIL_SYS_API
#define UTIL_SYS_API
Definition: sysconfig.h:16
LC::Util::QIODevice_ptr
std::shared_ptr< QIODevice > QIODevice_ptr
Definition: resourceloader.h:27
LC::Util
Definition: icoreproxy.h:33
LC::Util::ResourceLoader
Utility class for loading a file from a set of locations.
Definition: resourceloader.h:69
sysconfig.h