LeechCraft 0.6.70-17609-g3dde4097dd
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
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
19class QAbstractItemModel;
20class QStandardItemModel;
21class QSortFilterProxyModel;
22class QFileSystemWatcher;
23class QTimer;
24
25namespace 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:
332 };
333}
void SetCacheParams(int size, int timeout)
Sets the caching parameters of this loader.
QAbstractItemModel * GetSubElemModel() const
Returns the subelement model with the contents of registered paths.
void FlushCache()
Forcefully flushes the cache.
QIODevice_ptr Load(const QStringList &pathVariants, bool open=false) const
Returns the QIODevice for the corresponding resource.
void SetAttrFilters(QDir::Filters)
Sets the attribute filters for the subelement model.
QString GetPath(const QStringList &pathVariants) const
Returns the first found path for the list of variants.
void AddGlobalPrefix()
Registers global OS-dependent prefixes.
ResourceLoader(const QString &relPath, QObject *obj=nullptr)
Initializes the loader with the given path.
QFileInfoList List(const QString &option, const QStringList &names={}, QDir::Filters filters=QDir::NoFilter) const
Lists the available files for the given option.
QString GetIconPath(const QString &basename) const
Calls GetPath() with standard variants for the icon extensions.
QPixmap LoadPixmap(const QString &basename) const
Returns the pixmap for the given basename.
QIODevice_ptr GetIconDevice(const QString &basename, bool open=false) const
Returns the QIODevice for the corresponding icon.
void SetNameFilters(const QStringList &)
Sets the name filters for the subelement model.
void SetVerbose(bool verbose)
Control whether the ResourceLoader prints what it is doing to the logs.
void AddLocalPrefix(QString prefix=QString())
Registers a local search prefix.
std::shared_ptr< QIODevice > QIODevice_ptr
#define UTIL_SYS_API
Definition sysconfig.h:16