aboutsummaryrefslogtreecommitdiff
path: root/lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp')
-rw-r--r--lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp133
1 files changed, 73 insertions, 60 deletions
diff --git a/lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp b/lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp
index e60da975..d29d4354 100644
--- a/lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp
+++ b/lumina-desktop/panel-plugins/desktopbar/LDeskBar.cpp
@@ -1,6 +1,6 @@
//===========================================
// Lumina-DE source code
-// Copyright (c) 2012, Ken Moore
+// Copyright (c) 2012-2015, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
@@ -14,17 +14,23 @@ LDeskBarPlugin::LDeskBarPlugin(QWidget *parent, QString id, bool horizontal) : L
if(QFile::exists(QDir::homePath()+"/Desktop")){ desktopPath = QDir::homePath()+"/Desktop"; }
else if(QFile::exists(QDir::homePath()+"/desktop")){ desktopPath = QDir::homePath()+"/desktop"; }
else{ desktopPath=""; }
+ //Make sure the favorites directory exists
+ if(!QFile::exists(QDir::homePath()+"/.lumina/favorites") ){
+ QDir dir;
+ dir.mkpath(QDir::homePath()+"/.lumina/favorites");
+ }
//Setup the filter lists for the different types of files
- audioFilter <<"*.ogg"<<"*.mp3"<<"*.wav"<<"*.aif"<<"*.iff"<<"*.m3u"<<"*.m4a"<<"*.mid"<<"*.mpa"<<"*.ra"<<"*.wma";
+ /*audioFilter <<"*.ogg"<<"*.mp3"<<"*.wav"<<"*.aif"<<"*.iff"<<"*.m3u"<<"*.m4a"<<"*.mid"<<"*.mpa"<<"*.ra"<<"*.wma";
videoFilter <<"*.3g2"<<"*.3gp"<<"*.asf"<<"*.asx"<<"*.avi"<<"*.flv"<<"*.m4v"<<"*.mov"<<"*.mp4"<<"*.mpg"<<"*.rm"<<"*.srt"<<"*.swf"<<"*.vob"<<"*.wmv";
pictureFilter <<"*.bmp"<<"*.dds"<<"*.gif"<<"*.jpg"<<"*.png"<<"*.psd"<<"*.thm"<<"*.tif"<<"*.tiff"<<"*.ai"<<"*.eps"<<"*.ps"<<"*.svg"<<"*.ico";
- docsFilter << "*.txt"<<"*.rtf"<<"*.doc"<<"*.docx"<<"*.odf"<<"*.pdf";
+ docsFilter << "*.txt"<<"*.rtf"<<"*.doc"<<"*.docx"<<"*.odf"<<"*.pdf";*/
//initialize the desktop bar items
initializeDesktop();
//setup the directory watcher
watcher = new QFileSystemWatcher(this);
if(!desktopPath.isEmpty()){
- watcher->addPath(desktopPath);
+ watcher->addPath(desktopPath);
+ watcher->addPath(QDir::homePath()+"/.lumina/favorites");
}
connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(desktopChanged()) );
QTimer::singleShot(1,this, SLOT(desktopChanged()) ); //make sure to load it the first time
@@ -107,7 +113,7 @@ QAction* LDeskBarPlugin::newAction(QString filepath, QString name, QIcon icon){
return act;
}
-void LDeskBarPlugin::updateMenu(QMenu* menu, QFileInfoList files, bool trim){
+/*void LDeskBarPlugin::updateMenu(QMenu* menu, QFileInfoList files, bool trim){
menu->clear();
//re-create the menu (since it is hidden from view)
QStringList filevals;
@@ -122,7 +128,7 @@ void LDeskBarPlugin::updateMenu(QMenu* menu, QFileInfoList files, bool trim){
for(int i=0; i<filevals.length(); i++){
menu->addAction( newAction( filevals[i].section("::::",1,1), filevals[i].section("::::",0,0), "") );
}
-}
+}*/
// =======================
// PRIVATE SLOTS
@@ -135,59 +141,67 @@ void LDeskBarPlugin::ActionTriggered(QAction* act){
}
void LDeskBarPlugin::desktopChanged(){
- if(!desktopPath.isEmpty()){
- QDir dir(desktopPath);
- QDir favdir(QDir::homePath()+"/.lumina/favorites");
- totals = dir.entryInfoList( QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name);
- totals << favdir.entryInfoList( QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name);
- //Update all the special menus (trimming the totals list as we go)
- updateMenu(dirM, QFileInfoList() << dir.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name) << favdir.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name));
- updateMenu(audioM, QFileInfoList() << dir.entryInfoList( audioFilter, QDir::Files, QDir::Name) << favdir.entryInfoList( audioFilter, QDir::Files, QDir::Name));
- updateMenu(videoM, QFileInfoList() << dir.entryInfoList( videoFilter, QDir::Files, QDir::Name) << favdir.entryInfoList( videoFilter, QDir::Files, QDir::Name) );
- updateMenu(pictureM, QFileInfoList() << dir.entryInfoList( pictureFilter, QDir::Files, QDir::Name) << favdir.entryInfoList( pictureFilter, QDir::Files, QDir::Name) );
- updateMenu(docM, QFileInfoList() << dir.entryInfoList( docsFilter, QDir::Files, QDir::Name) << favdir.entryInfoList( docsFilter, QDir::Files, QDir::Name) );
- //Now update the launchers
- QFileInfoList exe = dir.entryInfoList( QStringList() << "*.desktop", QDir::Files, QDir::Name );
- exe << favdir.entryInfoList( QStringList() << "*.desktop", QDir::Files, QDir::Name );
- // - Get a complete list of apps (in alphabetical order)
- QList<XDGDesktop> exeList;
- for(int i=0; i<exe.length(); i++){
- totals.removeAll(exe[i]); //Remove this item from the totals
- bool ok = false;
- XDGDesktop df = LXDG::loadDesktopFile(exe[i].canonicalFilePath(), ok);
- if(ok){
- if( LXDG::checkValidity(df) && !df.isHidden ){ exeList << df; }
- }
- }
- exeList = LXDG::sortDesktopNames(exeList);
- // - Now re-create the menu with the apps
- appM->clear();
- bool listApps = true; //turn this off for the moment (make dynamic later)
- if(!listApps){
- //go through the current items and remove them all
- while( APPLIST.length() > 0){
- delete this->layout()->takeAt(3); //always after the 3 main menu buttons
- }
- }
- for(int i=0; i<exeList.length(); i++){
- if(listApps){ appM->addAction( newAction(exeList[i].filePath, exeList[i].name, LXDG::findIcon(exeList[i].icon, ":/images/default-application.png")) ); }
- else{
- //Create a new LTBWidget for this app
- QToolButton *it = new QToolButton(this);
- it->setWhatsThis(exeList[i].filePath);
- it->setToolTip(exeList[i].name);
- it->setIcon( LXDG::findIcon(exeList[i].icon, "") );
- it->setToolButtonStyle(Qt::ToolButtonIconOnly);
- it->setAutoRaise(true);
- it->setPopupMode(QToolButton::InstantPopup);
- if(it->icon().isNull()){ it->setIcon( LXDG::findIcon("application-x-executable","") ); }
- connect(it, SIGNAL(triggered(QAction*)), this , SLOT(ActionTriggered(QAction*)) );
- APPLIST << it;
- this->layout()->addWidget(it);
+ QStringList newfavs = LUtils::listFavorites();
+ if(lastHomeUpdate.isNull() || (QFileInfo(QDir::homePath()+"/Desktop").lastModified() > lastHomeUpdate) || newfavs!=favs ){
+ favs = newfavs;
+ QDir homedir = QDir( QDir::homePath()+"/Desktop");
+ homefiles = homedir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
+ lastHomeUpdate = QDateTime::currentDateTime();
+ QStringList favitems = favs;
+ //Remember for format for favorites: <name>::::[app/dir/<mimetype>]::::<full path>
+ for(int i=0; i<homefiles.length(); i++){
+ QString type;
+ if(homefiles[i].isDir()){ type="dir"; }
+ else if(homefiles[i].fileName().endsWith(".desktop")){ type="app"; }
+ else{ type=LXDG::findAppMimeForFile(homefiles[i].fileName()); }
+ favitems << homefiles[i].fileName()+"::::"+type+"::::"+homefiles[i].absoluteFilePath();
+ //qDebug() << "Desktop Item:" << favitems.last();
+ }
+
+ favitems.sort(); //sort them alphabetically
+ //Now add the items to the lists
+ appM->clear();
+ dirM->clear();
+ audioM->clear();
+ videoM->clear();
+ pictureM->clear();
+ docM->clear();
+ otherM->clear();
+ for(int i=0; i<favitems.length(); i++){
+ QString type = favitems[i].section("::::",1,1);
+ QString name = favitems[i].section("::::",0,0);
+ QString path = favitems[i].section("::::",2,50);
+ if(type=="app"){
+ //Add it to appM
+ bool ok = false;
+ XDGDesktop df = LXDG::loadDesktopFile(path, ok);
+ if(ok){
+ if( LXDG::checkValidity(df) && !df.isHidden ){
+ appM->addAction( newAction(df.filePath, df.name, LXDG::findIcon(df.icon, ":/images/default-application.png")) );
}
}
- //Now update the other menu with everything else that is left
- updateMenu(otherM, totals, false);
+ }else if(type=="dir"){
+ //Add it to dirM
+ dirM->addAction( newAction(path, name, LXDG::findIcon("folder","")) );
+ }else if(type.startsWith("audio/")){
+ //Add it to audioM
+ audioM->addAction( newAction(path, name, LXDG::findMimeIcon(type)) );
+ }else if(type.startsWith("video/")){
+ //Add it to videoM
+ videoM->addAction( newAction(path, name, LXDG::findMimeIcon(type)) );
+ }else if(type.startsWith("image/")){
+ //Add it to pictureM
+ pictureM->addAction( newAction(path, name, LXDG::findMimeIcon(type)) );
+ }else if(type.startsWith("text/")){
+ //Add it to docM
+ docM->addAction( newAction(path, name, LXDG::findMimeIcon(type)) );
+ }else{
+ //Add it to otherM
+ otherM->addAction( newAction(path, name, LXDG::findMimeIcon(type)) );
+ }
+
+ }
+
//Now update the file menu as appropriate
fileM->clear();
if(!audioM->isEmpty()){ fileM->addMenu(audioM); }
@@ -205,12 +219,11 @@ void LDeskBarPlugin::desktopChanged(){
}else{
fileB->setMenu(fileM);
}
- }
+ } //end of check for if updates are needed
+
//Setup the visibility of the buttons
appB->setVisible( !appM->isEmpty() );
dirB->setVisible( !dirM->isEmpty() );
fileB->setVisible( !fileM->isEmpty() );
- //Clear the totals list (since no longer in use)
- totals.clear();
}
bgstack15