diff options
author | Ken Moore <ken@ixsystems.com> | 2017-11-15 08:30:47 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-11-15 08:30:47 -0500 |
commit | 74aee7244060e588031735eabae05c47efde48aa (patch) | |
tree | ea827afd2f924410dc60021ade1afc12b1603d8f /src-qt5/core/libLumina | |
parent | Enable the auto-archive functionality in lumina-fm. (diff) | |
download | lumina-74aee7244060e588031735eabae05c47efde48aa.tar.gz lumina-74aee7244060e588031735eabae05c47efde48aa.tar.bz2 lumina-74aee7244060e588031735eabae05c47efde48aa.zip |
Split the LFileInfo class into it's own files.
Diffstat (limited to 'src-qt5/core/libLumina')
-rw-r--r-- | src-qt5/core/libLumina/LFileInfo.cpp | 109 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LFileInfo.h | 51 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LuminaXDG.cpp | 4 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LuminaXDG.h | 4 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LuminaXDG.pri | 8 |
5 files changed, 169 insertions, 7 deletions
diff --git a/src-qt5/core/libLumina/LFileInfo.cpp b/src-qt5/core/libLumina/LFileInfo.cpp new file mode 100644 index 00000000..f7a7fbe3 --- /dev/null +++ b/src-qt5/core/libLumina/LFileInfo.cpp @@ -0,0 +1,109 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2013-2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "LFileInfo.h" +#include <LUtils.h> + +LFileInfo::LFileInfo() : QFileInfo(){ + desk = 0; +} + +LFileInfo::LFileInfo(QString filepath) : QFileInfo(){ //overloaded contructor + this->setFile(filepath); + loadExtraInfo(); +} + +LFileInfo::LFileInfo(QFileInfo info) : QFileInfo(){ //overloaded contructor + this->swap(info); //use the given QFileInfo without re-loading it + loadExtraInfo(); +} +LFileInfo::~LFileInfo(){ + if(desk!=0){ desk->deleteLater(); } +} + +//Need some extra information not usually available by a QFileInfo +void LFileInfo::loadExtraInfo(){ + if(desk!=0){ desk->deleteLater(); } + desk = 0; + //Now load the extra information + if(this->absoluteFilePath().startsWith("/net/") || this->isDir() ){ + mime = "inode/directory"; + //Special directory icons + QString name = this->fileName().toLower(); + if(name=="desktop"){ icon = "user-desktop"; } + else if(name=="tmp"){ icon = "folder-temp"; } + else if(name=="video" || name=="videos"){ icon = "folder-video"; } + else if(name=="music" || name=="audio"){ icon = "folder-sound"; } + else if(name=="projects" || name=="devel"){ icon = "folder-development"; } + else if(name=="notes"){ icon = "folder-txt"; } + else if(name=="downloads"){ icon = "folder-downloads"; } + else if(name=="documents"){ icon = "folder-documents"; } + else if(name=="images" || name=="pictures"){ icon = "folder-image"; } + else if(this->absoluteFilePath().startsWith("/net/")){ icon = "folder-shared"; } + else if( !this->isReadable() ){ icon = "folder-locked"; } + }else if( this->suffix()=="desktop"){ + mime = "application/x-desktop"; + icon = "application-x-desktop"; //default value + desk = new XDGDesktop(this->absoluteFilePath(), 0); + if(desk->type!=XDGDesktop::BAD){ + //use the specific desktop file info (if possible) + if(!desk->icon.isEmpty()){ icon = desk->icon; } + } + }else{ + //Generic file, just determine the mimetype + mime = LXDG::findAppMimeForFile(this->fileName()); + } +} + +//Functions for accessing the extra information +// -- Return the mimetype for the file +QString LFileInfo::mimetype(){ + if(mime=="inode/directory"){ return ""; } + else{ return mime; } +} + +// -- Return the icon to use for this file +QString LFileInfo::iconfile(){ + if(!icon.isEmpty()){ + return icon; + }else if(!mime.isEmpty()){ + QString tmp = mime; + tmp.replace("/","-"); + return tmp; + }else if(this->isExecutable()){ + return "application-x-executable"; + } + return ""; //Fall back to nothing +} + +// -- Check if this is an XDG desktop file +bool LFileInfo::isDesktopFile(){ + if(desk==0){ return false; } + return (!desk->filePath.isEmpty()); +} + +// -- Allow access to the XDG desktop data structure +XDGDesktop* LFileInfo::XDG(){ + return desk; +} + +// -- Check if this is a readable video file (for thumbnail support) +bool LFileInfo::isVideo(){ + if(!mime.startsWith("video/")){ return false; } + //Check the hardcoded list of known supported video formats to see if the thumbnail can be generated + return ( !LUtils::videoExtensions().filter(this->suffix().toLower()).isEmpty() ); +} + +// -- Check if this is a readable image file +bool LFileInfo::isImage(){ + if(!mime.startsWith("image/")){ return false; } //quick return for non-image files + //Check the Qt subsystems to see if this image file can be read + return ( !LUtils::imageExtensions().filter(this->suffix().toLower()).isEmpty() ); +} + +bool LFileInfo::isAVFile(){ + return (mime.startsWith("audio/") || mime.startsWith("video/") ); +} diff --git a/src-qt5/core/libLumina/LFileInfo.h b/src-qt5/core/libLumina/LFileInfo.h new file mode 100644 index 00000000..4fbf6353 --- /dev/null +++ b/src-qt5/core/libLumina/LFileInfo.h @@ -0,0 +1,51 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2013-2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// File Information simplification class (combine QFileInfo with XDGDesktop) +// Need some extra information not usually available by a QFileInfo +// ======================== +#ifndef _LUMINA_LIBRARY_FILE_INFO_H +#define _LUMINA_LIBRARY_FILE_INFO_H + +#include <LuminaXDG.h> +#include <QString> +#include <QFileInfo> + +class LFileInfo : public QFileInfo{ +private: + QString mime, icon; + XDGDesktop *desk; + + void loadExtraInfo(); + +public: + //Couple overloaded contructors + LFileInfo(); + LFileInfo(QString filepath); + LFileInfo(QFileInfo info); + ~LFileInfo(); + + //Functions for accessing the extra information + // -- Return the mimetype for the file + QString mimetype(); + + // -- Return the icon file to use for this file + QString iconfile(); //Note: This string is auto-formatted for use in the LXDG::findIcon() routine. + + // -- Check if this is an XDG desktop file + bool isDesktopFile(); + + // -- Allow access to the internal XDG desktop data structure + XDGDesktop* XDG(); + + //Other file type identification routines + bool isImage(); //Is a readable image file (for thumbnail support) + bool isVideo(); //Is a readable video file (for thumbnail support) + bool isAVFile(); //Is an audio/video file +}; +typedef QList<LFileInfo> LFileInfoList; + +#endif diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index cf9e0af2..1991a82d 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -629,7 +629,7 @@ void XDGDesktopList::populateMenu(QMenu *topmenu, bool byCategory){ //==== LFileInfo Functions ==== //Need some extra information not usually available by a QFileInfo -void LFileInfo::loadExtraInfo(){ +/*void LFileInfo::loadExtraInfo(){ desk = 0; //Now load the extra information if( this->suffix().isEmpty() && (this->absoluteFilePath().startsWith("/net/") || this->isDir()) ){ @@ -722,7 +722,7 @@ bool LFileInfo::isImage(){ bool LFileInfo::isAVFile(){ return (mime.startsWith("audio/") || mime.startsWith("video/") ); -} +}*/ //==== LXDG Functions ==== diff --git a/src-qt5/core/libLumina/LuminaXDG.h b/src-qt5/core/libLumina/LuminaXDG.h index 0f7e7c48..066f0462 100644 --- a/src-qt5/core/libLumina/LuminaXDG.h +++ b/src-qt5/core/libLumina/LuminaXDG.h @@ -128,7 +128,7 @@ signals: // File Information simplification class (combine QFileInfo with XDGDesktop) // Need some extra information not usually available by a QFileInfo // ======================== -class LFileInfo : public QFileInfo{ +/*class LFileInfo : public QFileInfo{ private: QString mime, icon; XDGDesktop *desk; @@ -162,7 +162,7 @@ public: bool isVideo(); //Is a readable video file (for thumbnail support) bool isAVFile(); //Is an audio/video file }; -typedef QList<LFileInfo> LFileInfoList; +typedef QList<LFileInfo> LFileInfoList;*/ // ================================ // Collection of FreeDesktop standards interaction routines diff --git a/src-qt5/core/libLumina/LuminaXDG.pri b/src-qt5/core/libLumina/LuminaXDG.pri index 6f3a2b7c..1a8a8368 100644 --- a/src-qt5/core/libLumina/LuminaXDG.pri +++ b/src-qt5/core/libLumina/LuminaXDG.pri @@ -1,10 +1,12 @@ QT *= multimedia svg #LUtils Files -SOURCES *= $${PWD}/LuminaXDG.cpp -HEADERS *= $${PWD}/LuminaXDG.h +SOURCES *= $${PWD}/LuminaXDG.cpp \ + $${PWD}/LFileInfo.cpp +HEADERS *= $${PWD}/LuminaXDG.h \ + $${PWD}/LFileInfo.h -INCLUDEPATH *= ${PWD} +INCLUDEPATH *= $${PWD} #include LUtils and LuminaOS include(LUtils.pri) |