aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libLumina/LuminaXDG.cpp88
-rw-r--r--libLumina/LuminaXDG.h45
2 files changed, 132 insertions, 1 deletions
diff --git a/libLumina/LuminaXDG.cpp b/libLumina/LuminaXDG.cpp
index 473d8620..ca20eef5 100644
--- a/libLumina/LuminaXDG.cpp
+++ b/libLumina/LuminaXDG.cpp
@@ -1,6 +1,6 @@
//===========================================
// Lumina-DE source code
-// Copyright (c) 2013, Ken Moore
+// Copyright (c) 2013-2015, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
@@ -13,6 +13,92 @@
static QStringList mimeglobs;
static qint64 mimechecktime;
+//==== LFileInfo Functions ====
+//Need some extra information not usually available by a QFileInfo
+void LFileInfo::loadExtraInfo(){
+ //Now load the extra information
+ if(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->isReadable() ){ icon = "folder-locked"; }
+ }else if( this->suffix()=="desktop"){
+ mime = "application/x-desktop";
+ icon = "application-x-desktop"; //default value
+ bool ok = false;
+ desk = LXDG::loadDesktopFile(this->absoluteFilePath(), ok);
+ if(ok){
+ //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());
+ }
+}
+LFileInfo::LFileInfo(QString filepath){ //overloaded contructor
+ this->setFile(filepath);
+ loadExtraInfo();
+}
+LFileInfo::LFileInfo(QFileInfo info){ //overloaded contructor
+ this->swap(info); //use the given QFileInfo without re-loading it
+ loadExtraInfo();
+}
+
+//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(){
+ return (!desk.filePath.isEmpty());
+}
+
+// -- Allow access to the XDG desktop data structure
+const XDGDesktop* LFileInfo::XDG(){
+ return &desk;
+}
+
+// -- Check if this is a readable image file (for thumbnail support)
+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/") );
+}
+
+
//==== LXDG Functions ====
XDGDesktop LXDG::loadDesktopFile(QString filePath, bool& ok){
//Create the outputs
diff --git a/libLumina/LuminaXDG.h b/libLumina/LuminaXDG.h
index b99b3015..9f2f75ab 100644
--- a/libLumina/LuminaXDG.h
+++ b/libLumina/LuminaXDG.h
@@ -30,6 +30,10 @@
#include <QDateTime>
#include <QDebug>
+
+// ======================
+// FreeDesktop Desktop Actions Framework (data structure)
+// ======================
class XDGDesktopAction{
public:
//Admin variables
@@ -38,6 +42,9 @@ public:
QString name, icon, exec;
};
+// ======================
+// FreeDesktop Desktop Entry Framework (data structure)
+// ======================
class XDGDesktop{
public:
enum XDGDesktopType { BAD, APP, LINK, DIR };
@@ -62,7 +69,45 @@ public:
~XDGDesktop(){}
};
+// ========================
+// File Information simplification class (combine QFileInfo with XDGDesktop)
+// Need some extra information not usually available by a QFileInfo
+// ========================
+class LFileInfo : public QFileInfo{
+private:
+ QString mime, icon;
+ XDGDesktop desk;
+
+ void loadExtraInfo();
+
+public:
+ //Couple overloaded contructors
+ 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
+ const XDGDesktop* XDG();
+
+ //Other file type identification routines
+ bool isImage(); //Is a readable image file (for thumbnail support)
+ bool isAVFile(); //Is an audio/video file
+};
+typedef QList<LFileInfo> LFileInfoList;
+// ================================
+// Collection of FreeDesktop standards interaction routines
+// ================================
class LXDG{
public:
//Read/write a *.desktop file
bgstack15