aboutsummaryrefslogtreecommitdiff
path: root/src-qt5
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2017-05-22 21:29:58 -0400
committerKen Moore <ken@ixsystems.com>2017-05-22 21:29:58 -0400
commitb07264e2e749dd79473cf4d8947e2f9c2a0d6023 (patch)
treec8cd2b1eb96d6a0d01caf192fbdfbbca713be502 /src-qt5
parentMerge branch 'master' of github.com:trueos/lumina (diff)
downloadlumina-b07264e2e749dd79473cf4d8947e2f9c2a0d6023.tar.gz
lumina-b07264e2e749dd79473cf4d8947e2f9c2a0d6023.tar.bz2
lumina-b07264e2e749dd79473cf4d8947e2f9c2a0d6023.zip
Clean up the new LIconCache class quite a bit (seems finished - just untested).
Diffstat (limited to 'src-qt5')
-rw-r--r--src-qt5/core/libLumina/LIconCache.cpp62
-rw-r--r--src-qt5/core/libLumina/LIconCache.h6
-rw-r--r--src-qt5/core/libLumina/LIconCache.pri2
3 files changed, 66 insertions, 4 deletions
diff --git a/src-qt5/core/libLumina/LIconCache.cpp b/src-qt5/core/libLumina/LIconCache.cpp
index 8ff4a8d7..18fc48c1 100644
--- a/src-qt5/core/libLumina/LIconCache.cpp
+++ b/src-qt5/core/libLumina/LIconCache.cpp
@@ -7,6 +7,9 @@
#include "LIconCache.h"
#include <LuminaOS.h>
+#include <LUtils.h>
+
+#include <QDir>
LIconCache::LIconCache(QObject *parent = 0{
@@ -105,7 +108,7 @@ QString LIconCache::findFile(QString icon){
}
-void LIconCache::loadIcon(QAbstractButton *button, QString icon, bool noThumb = false){
+void LIconCache::loadIcon(QAbstractButton *button, QString icon, bool noThumb){
//See if the icon has already been loaded into the HASH
if(HASH.contains(icon)){
if(!noThumb && !HASH[icon].thumbnail.isNull()){ button->setIcon( HASH[icon].thumbnail ); return; }
@@ -120,7 +123,7 @@ void LIconCache::loadIcon(QAbstractButton *button, QString icon, bool noThumb =
QtConcurrent::run(this, &LIconCache::ReadFile, this, icon, idata.fullpath);
}
-void LIconCache::loadIcon(QLabel *label, QString icon, bool noThumb = false){
+void LIconCache::loadIcon(QLabel *label, QString icon, bool noThumb){
//See if the icon has already been loaded into the HASH
if(HASH.contains(icon)){
if(!noThumb && !HASH[icon].thumbnail.isNull()){ button->setIcon( HASH[icon].thumbnail ); return; }
@@ -135,6 +138,34 @@ void LIconCache::loadIcon(QLabel *label, QString icon, bool noThumb = false){
QtConcurrent::run(this, &LIconCache::ReadFile, this, icon, idata.fullpath);
}
+void LIconCache::clearIconTheme(){
+ //use when the icon theme changes to refresh all requested icons
+ QStringList keys = HASH.keys();
+ for(int i=0; i<keys.length(); i++){
+ //remove all relative icons (
+ if(!keys.startsWith("/")){ HASH.remove(keys[i]); }
+ }
+}
+
+QIcon LIconCache::loadIcon(QString icon, bool noThumb){
+ if(HASH.contains(icon)){
+ if(!HASH[icon].icon.isNull()){ return HASH[icon].icon; }
+ else if(!HASH[icon].thumbnail.isNull() && !noThumb){ return HASH[icon].thumbnail; }
+ }
+ //Not loaded yet - need to load it right now
+ icon_data idat;
+ if(HASH.contains(icon)){ idat = HASH[icon]; }
+ else{ idat = createData(icon); }
+ idat.icon = QIcon(idat.fullpath);
+ //Now save into the hash and return
+ HASH.insert(icon, idat);
+ emit IconAvailable(icon);
+ return idat.icon;
+}
+
+void LIconCache::clearAll(){
+ HASH.clear();
+}
// === PRIVATE ===
icon_data LIconCache::createData(QString icon){
@@ -192,10 +223,33 @@ QStringList LXDG::getIconThemeDepChain(QString theme, QStringList paths){
}
void LIconCache::ReadFile(LIconCache *obj, QString id, QString path){
-
+ QByteArray *BA = new QByteArray();
+ QDateTime cdt = QDateTime::currentDateTime();
+ QFile file(path);
+ if(file.open(QIODevice::ReadOnly)){
+ BA->append(file.readAll());
+ file.close();
+ }
+ obj->emit InternalIconLoaded(id, cdt, BA);
}
// === PRIVATE SLOTS ===
void LIconCache::IconLoaded(QString id, QDateTime sync, QByteArray *data){
-
+ QPixmap pix = QPixmap::fromRawData(data);
+ delete data; //no longer used - free this up
+ if(!HASH.contains(id)){ return; } //icon loading cancelled - just stop here
+ if(!pix.isValid()){ HASH.remove(id); }
+ else{
+ icon_data idat = HASH[id];
+ idat.lastsync = sync;
+ idat.icon.addPixmap(pix);
+ //Now throw this icon into any pending objects
+ for(int i=0; i<idat.pendingButtons.length(); i++){ idat.pendingButtons[i]->setIcon(idat.icon); }
+ idat.pendingButtons.clear();
+ for(int i=0; i<idat.pendingLabels.length(); i++){ idat.pendingLabels[i]->setPixmap(pix.scaled(idat.pendingLabels[i]->sizeHint(), Qt::KeepAspectRatio, Qt::SmoothTransformation); }
+ idat.pendingLabels.clear();
+ //Now update the hash and let the world know it is available now
+ HASH.insert(id, idat);
+ this->emit IconAvailable(id);
+ }
}
diff --git a/src-qt5/core/libLumina/LIconCache.h b/src-qt5/core/libLumina/LIconCache.h
index 08726399..e2335c01 100644
--- a/src-qt5/core/libLumina/LIconCache.h
+++ b/src-qt5/core/libLumina/LIconCache.h
@@ -35,8 +35,14 @@ public:
bool isLoaded(QString icon);
QString findFile(QString icon); //find the full path of a given file/name (searching the current Icon theme)
+ //Special loading routines for QLabel and QAbstractButton (pushbutton, toolbutton, etc)
void loadIcon(QAbstractButton *button, QString icon, bool noThumb = false);
void loadIcon(QLabel *label, QString icon, bool noThumb = false);
+
+ QIcon loadIcon(QString icon, bool noThumb = false); //generic loading routine - does not background the loading of icons when not in the cache
+
+ void clearIconTheme(); //use when the icon theme changes to refresh all requested icons
+ void clearAll(); //Clear all cached icons
private:
QHash<QString, icon_data> HASH;
diff --git a/src-qt5/core/libLumina/LIconCache.pri b/src-qt5/core/libLumina/LIconCache.pri
index f1f58f16..baf72b01 100644
--- a/src-qt5/core/libLumina/LIconCache.pri
+++ b/src-qt5/core/libLumina/LIconCache.pri
@@ -1,3 +1,5 @@
+QT *= concurrent
+
HEADERS *= $${PWD}/LIconCache.h
SOURCES *= $${PWD}/LIconCache.cpp
bgstack15