diff options
Diffstat (limited to 'lumina-desktop/panel-plugins/userbutton')
4 files changed, 76 insertions, 49 deletions
diff --git a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp index a04c6e43..5a6a9f09 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp +++ b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp @@ -1,15 +1,16 @@ //=========================================== // Lumina-DE source code -// Copyright (c) 2014, Ken Moore +// Copyright (c) 2014-2015, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== #include "UserItemWidget.h" +#include <LuminaUtils.h> -UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, bool isDir, bool goback) : QFrame(parent){ +UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, QString type, bool goback) : QFrame(parent){ createWidget(); //Now fill it appropriately - if(itemPath.endsWith(".desktop")){ + if(itemPath.endsWith(".desktop") || type=="app"){ bool ok = false; XDGDesktop item = LXDG::loadDesktopFile(itemPath, ok); if(ok){ @@ -19,7 +20,7 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, bool isDir, bo icon->setPixmap( LXDG::findIcon("unknown","").pixmap(32,32) ); name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, 180) ); } - }else if(isDir){ + }else if(type=="dir"){ if(itemPath.endsWith("/")){ itemPath.chop(1); } if(goback){ icon->setPixmap( LXDG::findIcon("go-previous","").pixmap(32,32) ); @@ -30,14 +31,17 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, bool isDir, bo } }else{ if(itemPath.endsWith("/")){ itemPath.chop(1); } - icon->setPixmap( LXDG::findMimeIcon(itemPath.section("/",-1)).pixmap(32,32) ); + icon->setPixmap( LXDG::findMimeIcon(type).pixmap(32,32) ); name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, 180) ); } - linkPath = QFile::symLinkTarget(itemPath); icon->setWhatsThis(itemPath); - if(isDir && !linkPath.isEmpty()){ isDir = false; } //not a real directory - just a sym link - isDirectory = isDir; //save this for later - isShortcut = itemPath.contains("/home/") && (itemPath.contains("/Desktop/") || itemPath.contains("/.lumina/favorites/") ); + isDirectory = (type=="dir"); //save this for later + if(LUtils::isFavorite(itemPath)){ + linkPath = itemPath; + isShortcut=true; + }else if( itemPath.section("/",0,-2)==QDir::homePath()+"/Desktop" ){ + isShortcut = true; + } //Now setup the button appropriately setupButton(goback); } @@ -45,8 +49,14 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, bool isDir, bo UserItemWidget::UserItemWidget(QWidget *parent, XDGDesktop item) : QFrame(parent){ createWidget(); isDirectory = false; - linkPath = QFile::symLinkTarget(item.filePath); - isShortcut = item.filePath.contains("/home/") && (item.filePath.contains("/Desktop/") || item.filePath.contains("/.lumina/favorites/") ); + if(LUtils::isFavorite(item.filePath)){ + linkPath = item.filePath; + isShortcut=true; + }else if( item.filePath.section("/",0,-2)==QDir::homePath()+"/Desktop" ){ + isShortcut = true; + }else{ + isShortcut = false; + } //Now fill it appropriately icon->setPixmap( LXDG::findIcon(item.icon,"preferences-system-windows-actions").pixmap(32,32) ); name->setText( this->fontMetrics().elidedText(item.name, Qt::ElideRight, 180) ); @@ -98,8 +108,8 @@ void UserItemWidget::setupButton(bool disable){ button->setToolTip(tr("Delete File")); } connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()) ); - }else if( !QFile::exists( QDir::homePath()+"/Desktop/"+icon->whatsThis().section("/",-1) ) && !QFile::exists( QDir::homePath()+"/.lumina/favorites/"+icon->whatsThis().section("/",-1) ) ){ - //This file does not have a desktop shortcut yet -- allow the user to add it + }else if( !QFile::exists( QDir::homePath()+"/Desktop/"+icon->whatsThis().section("/",-1) ) && !LUtils::isFavorite(icon->whatsThis() ) ){ + //This file does not have a shortcut yet -- allow the user to add it button->setWhatsThis("add"); button->setIcon( LXDG::findIcon("bookmark-toolbar","") ); button->setToolTip(tr("Create Shortcut")); @@ -125,4 +135,4 @@ void UserItemWidget::ItemClicked(){ if(!linkPath.isEmpty()){ emit RunItem(linkPath); } else{ emit RunItem(icon->whatsThis()); } -}
\ No newline at end of file +} diff --git a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h index 1f428ac4..a65d3e83 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h +++ b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h @@ -1,6 +1,6 @@ //=========================================== // Lumina-DE source code -// Copyright (c) 2014, Ken Moore +// Copyright (c) 2014-2015, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== @@ -25,7 +25,7 @@ class UserItemWidget : public QFrame{ Q_OBJECT public: - UserItemWidget(QWidget *parent=0, QString itemPath="", bool isDir=false, bool goback=false); + UserItemWidget(QWidget *parent=0, QString itemPath="", QString type="unknown", bool goback=false); UserItemWidget(QWidget *parent=0, XDGDesktop item= XDGDesktop()); ~UserItemWidget(); @@ -54,4 +54,4 @@ signals: }; -#endif
\ No newline at end of file +#endif diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp index 52d60714..404fcc26 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp +++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp @@ -1,6 +1,6 @@ //=========================================== // Lumina-DE source code -// Copyright (c) 2014, Ken Moore +// Copyright (c) 2014-2015, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== @@ -85,6 +85,7 @@ UserWidget::UserWidget(QWidget* parent) : QTabWidget(parent), ui(new Ui::UserWid ui->tool_qtconfig->setVisible(false); } lastUpdate = QDateTime(); //make sure it refreshes + connect(LSession::handle()->applicationMenu(), SIGNAL(AppMenuUpdated()), this, SLOT(UpdateMenu()) ); QTimer::singleShot(10,this, SLOT(UpdateMenu())); //make sure to load this once after initialization } @@ -147,6 +148,7 @@ void UserWidget::LaunchItem(QString path, bool fix){ void UserWidget::FavChanged(){ //uncheck the current item for a moment + int oldfav = cfav; if(cfav==0){ ui->tool_fav_apps->setChecked(false); } else if(cfav==1){ ui->tool_fav_dirs->setChecked(false); } if(cfav==2){ ui->tool_fav_files->setChecked(false); } @@ -163,31 +165,53 @@ void UserWidget::FavChanged(){ ui->tool_fav_dirs->setChecked(cfav==1); ui->tool_fav_files->setChecked(cfav==2); } - updateFavItems(); + updateFavItems(oldfav!=cfav); } -void UserWidget::updateFavItems(){ - ClearScrollArea(ui->scroll_fav); - QFileInfoList items; - QDir homedir = QDir( QDir::homePath()+"/Desktop"); - QDir favdir = QDir( QDir::homePath()+"/.lumina/favorites"); - if(!favdir.exists()){ favdir.mkpath( QDir::homePath()+"/.lumina/favorites"); } +void UserWidget::updateFavItems(bool newfilter){ + QStringList newfavs = LUtils::listFavorites(); + //qDebug() << "Favorites:" << newfavs; + 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(); + }else if(!newfilter){ return; } //nothing new to change - stop now + QStringList favitems; + //Remember for format for favorites: <name>::::[app/dir/<mimetype>]::::<full path> if(ui->tool_fav_apps->isChecked()){ - items = homedir.entryInfoList(QStringList()<<"*.desktop", QDir::Files | QDir::NoDotAndDotDot, QDir::Name); - items << favdir.entryInfoList(QStringList()<<"*.desktop", QDir::Files | QDir::NoDotAndDotDot, QDir::Name); + favitems = favs.filter("::::app::::"); + for(int i=0; i<homefiles.length(); i++){ + if(homefiles[i].fileName().endsWith(".desktop")){ + favitems << homefiles[i].fileName()+"::::app::::"+homefiles[i].absoluteFilePath(); + } + } }else if(ui->tool_fav_dirs->isChecked()){ - items = homedir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); - items << favdir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); + favitems = favs.filter("::::dir::::"); + for(int i=0; i<homefiles.length(); i++){ + if(homefiles[i].isDir()){ + favitems << homefiles[i].fileName()+"::::dir::::"+homefiles[i].absoluteFilePath(); + } + } }else{ //Files - items = homedir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name); - items << favdir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name); - for(int i=0; i<items.length(); i++){ - if(items[i].suffix()=="desktop"){ items.removeAt(i); i--; } + for(int i=0; i<favs.length(); i++){ + QString type = favs[i].section("::::",1,1); + if(type != "app" && type !="dir"){ + favitems << favs[i]; + } + } + for(int i=0; i<homefiles.length(); i++){ + if(!homefiles[i].isDir() && !homefiles[i].fileName().endsWith(".desktop") ){ + favitems << homefiles[i].fileName()+"::::"+LXDG::findAppMimeForFile(homefiles[i].fileName())+"::::"+homefiles[i].absoluteFilePath(); + } } } - for(int i=0; i<items.length(); i++){ - UserItemWidget *it = new UserItemWidget(ui->scroll_fav->widget(), items[i].absoluteFilePath(), ui->tool_fav_dirs->isChecked()); + ClearScrollArea(ui->scroll_fav); + favitems.sort(); //sort them alphabetically + for(int i=0; i<favitems.length(); i++){ + UserItemWidget *it = new UserItemWidget(ui->scroll_fav->widget(), favitems[i].section("::::",2,50), favitems[i].section("::::",1,1) , ui->tool_fav_dirs->isChecked()); ui->scroll_fav->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) ); connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) ); @@ -195,15 +219,6 @@ void UserWidget::updateFavItems(){ } static_cast<QBoxLayout*>(ui->scroll_fav->widget()->layout())->addStretch(); - //Clean up any broken sym-links in the favorites directory - /*items = favdir.entryInfoList(QDir::System | QDir::NoDotAndDotDot, QDir::Name); - for(int i=0; i<items.length(); i++){ - if(items[i].isSymLink() && !items[i].exists()){ - //Broken sym-link - remove it - QFile::remove(items[i].absoluteFilePath()); - } - }*/ - } //Apps Tab @@ -268,8 +283,8 @@ void UserWidget::updateHome(){ for(int i=0; i<items.length(); i++){ //qDebug() << "New Home subdir:" << homedir.absoluteFilePath(items[i]); UserItemWidget *it; - if(items[i].startsWith("/")){ it = new UserItemWidget(ui->scroll_home->widget(), items[i], true, true); } - else{ it = new UserItemWidget(ui->scroll_home->widget(), homedir.absoluteFilePath(items[i]), true, false); } + if(items[i].startsWith("/")){ it = new UserItemWidget(ui->scroll_home->widget(), items[i], "dir", true); } + else{ it = new UserItemWidget(ui->scroll_home->widget(), homedir.absoluteFilePath(items[i]), "dir", false); } ui->scroll_home->widget()->layout()->addWidget(it); connect(it, SIGNAL(RunItem(QString)), this, SLOT(slotGoToDir(QString)) ); connect(it, SIGNAL(NewShortcut()), this, SLOT(updateFavItems()) ); @@ -300,4 +315,4 @@ void UserWidget::mouseMoveEvent( QMouseEvent *event){ qDebug() << " - Mouse over tab"; this->setCurrentIndex( wid->tabAt(relpos) ); } -}
\ No newline at end of file +} diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.h b/lumina-desktop/panel-plugins/userbutton/UserWidget.h index c7af2a4d..8f5ba852 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserWidget.h +++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.h @@ -42,7 +42,9 @@ public slots: private: Ui::UserWidget *ui; QHash<QString, QList<XDGDesktop> > *sysapps; - QDateTime lastUpdate; + QDateTime lastUpdate, lastHomeUpdate; + QStringList favs; + QFileInfoList homefiles; int cfav; //current favorite category void ClearScrollArea(QScrollArea *area); QIcon rotateIcon(QIcon); @@ -52,7 +54,7 @@ private slots: //Favorites Tab void FavChanged(); //for ensuring radio-button-like behaviour - void updateFavItems(); + void updateFavItems(bool newfilter = true); //if false, will only update if filesystem changes //Apps Tab void updateAppCategories(); |