From f11d2a7d2b38d751d50ecfe6349039447d80fb15 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 29 Sep 2014 10:18:14 -0400 Subject: A few updates to plugins: UserButton: 1) When creating links, always create them in ~/.lumina/favorites 2) Scan both the Desktop and the favorites dir for favorite items 3) Distinguish between removing a link and deleting a file 4) Allow for setting links to directories 5) Allow removing links to directories AppLauncher desktop plugin: 1) Make sure to use the session function for launching an item (makes the mouse cursor show the loading icon). 2) Allow for pre-defining a file path for the launcher (syntax: applauncher::) --- .../panel-plugins/userbutton/UserItemWidget.cpp | 34 +++++++++++++--------- .../panel-plugins/userbutton/UserItemWidget.h | 3 +- .../panel-plugins/userbutton/UserWidget.cpp | 21 ++++++++----- 3 files changed, 37 insertions(+), 21 deletions(-) (limited to 'lumina-desktop/panel-plugins/userbutton') diff --git a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp index c279a2a4..eb6a7db0 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp +++ b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp @@ -15,25 +15,24 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, bool isDir) : if(ok){ icon->setPixmap( LXDG::findIcon(item.icon, "preferences-system-windows-actions").pixmap(30,30) ); name->setText( item.name ); - icon->setWhatsThis(item.filePath); }else{ icon->setPixmap( LXDG::findIcon("unknown","").pixmap(30,30) ); name->setText( itemPath.section("/",-1) ); - icon->setWhatsThis(itemPath); } }else if(isDir){ if(itemPath.endsWith("/")){ itemPath.chop(1); } icon->setPixmap( LXDG::findIcon("folder","").pixmap(30,30) ); - name->setText( itemPath.section("/",-1) ); - icon->setWhatsThis(itemPath); + name->setText( itemPath.section("/",-1) ); }else{ if(itemPath.endsWith("/")){ itemPath.chop(1); } icon->setPixmap( LXDG::findMimeIcon(itemPath.section("/",-1).section(".",-1)).pixmap(30,30) ); name->setText( itemPath.section("/",-1) ); - icon->setWhatsThis(itemPath); } - if(isDir && !QFile::symLinkTarget(itemPath).isEmpty()){ isDir = false; } //not a real directory - just a sym link + 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/") ); //Now setup the button appropriately setupButton(); } @@ -41,6 +40,8 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, bool isDir) : 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/") ); //Now fill it appropriately icon->setPixmap( LXDG::findIcon(item.icon,"preferences-system-windows-actions").pixmap(30,30) ); name->setText( item.name ); @@ -77,13 +78,18 @@ void UserItemWidget::createWidget(){ } void UserItemWidget::setupButton(){ - if( !isDirectory && icon->whatsThis().contains("/home/") && icon->whatsThis().contains("/Desktop/")){ + if( !isDirectory && isShortcut ){ //This is a current desktop shortcut -- allow the user to remove it button->setWhatsThis("remove"); - button->setIcon( LXDG::findIcon("list-remove","") ); - button->setToolTip(tr("Remove Shortcut")); + if(!linkPath.isEmpty()){ + button->setIcon( LXDG::findIcon("list-remove","") ); + button->setToolTip(tr("Remove Shortcut")); + }else{ + button->setIcon( LXDG::findIcon("user-trash","") ); + button->setToolTip(tr("Delete File")); + } connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()) ); - }else if( !isDirectory && !QFile::exists( QDir::homePath()+"/Desktop/"+icon->whatsThis().section("/",-1) ) ){ + }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 button->setWhatsThis("add"); button->setIcon( LXDG::findIcon("favorites","") ); @@ -98,14 +104,16 @@ void UserItemWidget::setupButton(){ void UserItemWidget::buttonClicked(){ button->setVisible(false); if(button->whatsThis()=="add"){ - QFile::link(icon->whatsThis(), QDir::homePath()+"/Desktop/"+icon->whatsThis().section("/",-1) ); + QFile::link(icon->whatsThis(), QDir::homePath()+"/.lumina/favorites/"+icon->whatsThis().section("/",-1) ); emit NewShortcut(); }else if(button->whatsThis()=="remove"){ - QFile::remove(icon->whatsThis()); + QFile::remove(icon->whatsThis()); //never remove the linkPath - since that is the actual file/dir emit RemovedShortcut(); } } void UserItemWidget::ItemClicked(){ - emit RunItem("lumina-open \""+icon->whatsThis()+"\"" ); + if(!linkPath.isEmpty()){ emit RunItem("lumina-open \""+linkPath+"\"" ); } + else{ emit RunItem("lumina-open \""+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 3a4406ac..79baffbb 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h +++ b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h @@ -32,7 +32,8 @@ public: private: QToolButton *button; QLabel *icon, *name; - bool isDirectory; + bool isDirectory, isShortcut; + QString linkPath; void createWidget(); void setupButton(); diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp index f7a932ad..d1cf82d4 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp +++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp @@ -157,19 +157,26 @@ void UserWidget::FavChanged(){ void UserWidget::updateFavItems(){ ClearScrollArea(ui->scroll_fav); - QStringList items; + QFileInfoList items; QDir homedir = QDir( QDir::homePath()+"/Desktop"); - if(ui->tool_fav_apps->isChecked()){ items = homedir.entryList(QStringList()<<"*.desktop", QDir::Files | QDir::NoDotAndDotDot, QDir::Name); } - else if(ui->tool_fav_dirs->isChecked()){ items = homedir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); } - else{ + QDir favdir = QDir( QDir::homePath()+"/.lumina/favorites"); + if(!favdir.exists()){ favdir.mkpath( QDir::homePath()+"/.lumina/favorites"); } + 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); + }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); + }else{ //Files - items = homedir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name); + items = homedir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name); + items << favdir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name); for(int i=0; iscroll_fav->widget(), homedir.absoluteFilePath(items[i]), ui->tool_fav_dirs->isChecked()); + UserItemWidget *it = new UserItemWidget(ui->scroll_fav->widget(), items[i].absoluteFilePath(), 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()) ); -- cgit