diff options
7 files changed, 98 insertions, 72 deletions
diff --git a/lumina-desktop/desktop-plugins/NewDP.h b/lumina-desktop/desktop-plugins/NewDP.h index 0e225cb9..83d035d5 100644 --- a/lumina-desktop/desktop-plugins/NewDP.h +++ b/lumina-desktop/desktop-plugins/NewDP.h @@ -25,7 +25,8 @@ public: plug = new SamplePlugin(parent, plugin); }else if(plugin.section("---",0,0)=="calendar"){ plug = new CalendarPlugin(parent, plugin); - }else if(plugin.section("---",0,0)=="applauncher"){ + }else if(plugin.section("---",0,0).section("::",0,0)=="applauncher"){ + //This plugin can be pre-initialized to a file path after the "::" delimiter plug = new AppLauncherPlugin(parent, plugin); }else{ qWarning() << "Invalid Desktop Plugin:"<<plugin << " -- Ignored"; diff --git a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp new file mode 100644 index 00000000..32937ad4 --- /dev/null +++ b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp @@ -0,0 +1,54 @@ +#include "AppLauncherPlugin.h" +#include "../../LSession.h" + +AppLauncherPlugin::AppLauncherPlugin(QWidget* parent, QString ID) : LDPlugin(parent, ID){ + this->setLayout( new QVBoxLayout()); + this->layout()->setContentsMargins(0,0,0,0); + button = new QToolButton(this); + button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + button->setIconSize(QSize(64,64)); + button->setAutoRaise(true); + this->layout()->addWidget(button); + connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()) ); + watcher = new QFileSystemWatcher(this); + connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT( loadButton()) ); + QTimer::singleShot(1,this, SLOT(loadButton()) ); +} + +void AppLauncherPlugin::loadButton(){ + QString def = this->ID().section("::",1,50).section("---",0,0).simplified(); + QString path = this->settings->value("applicationpath",def).toString(); //use the default if necessary + //qDebug() << "Default Application Launcher:" << def << path; + bool ok = false; + XDGDesktop file = LXDG::loadDesktopFile(path, ok); + if(path.isEmpty() || !QFile::exists(path) || !ok){ + button->setWhatsThis(""); + button->setIcon( LXDG::findIcon("quickopen-file","") ); + button->setText( tr("Click to Set") ); + if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); } + }else{ + button->setWhatsThis(file.filePath); + button->setIcon( LXDG::findIcon(file.icon,"quickopen") ); + button->setText( this->fontMetrics().elidedText(file.name, Qt::ElideRight, 64) ); + if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); } + watcher->addPath(file.filePath); //make sure to update this shortcut if the file changes + } +} + +void AppLauncherPlugin::buttonClicked(){ + QString path = button->whatsThis(); + if(path.isEmpty() || !QFile::exists(path) ){ + //prompt for the user to select an application + QList<XDGDesktop> apps = LXDG::sortDesktopNames( LXDG::systemDesktopFiles() ); + QStringList names; + for(int i=0; i<apps.length(); i++){ names << apps[i].name; } + bool ok = false; + QString app = QInputDialog::getItem(this, tr("Select Application"), tr("Name:"), names, 0, false, &ok); + if(!ok || names.indexOf(app)<0){ return; } //cancelled + this->settings->setValue("applicationpath", apps[ names.indexOf(app) ].filePath); + QTimer::singleShot(0,this, SLOT(loadButton())); + }else{ + LSession::LaunchApplication("lumina-open \""+path+"\""); + } + +}
\ No newline at end of file diff --git a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h index 3a8e5da8..bb21b636 100644 --- a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h +++ b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h @@ -24,20 +24,7 @@ class AppLauncherPlugin : public LDPlugin{ Q_OBJECT public: - AppLauncherPlugin(QWidget* parent, QString ID) : LDPlugin(parent, ID){ - this->setLayout( new QVBoxLayout()); - this->layout()->setContentsMargins(0,0,0,0); - button = new QToolButton(this); - button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - button->setIconSize(QSize(64,64)); - button->setAutoRaise(true); - this->layout()->addWidget(button); - connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()) ); - watcher = new QFileSystemWatcher(this); - connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT( loadButton()) ); - QTimer::singleShot(1,this, SLOT(loadButton()) ); - } - + AppLauncherPlugin(QWidget* parent, QString ID); ~AppLauncherPlugin(){} private: @@ -45,40 +32,7 @@ private: QFileSystemWatcher *watcher; private slots: - void loadButton(){ - QString path = this->settings->value("applicationpath","").toString(); - bool ok = false; - XDGDesktop file = LXDG::loadDesktopFile(path, ok); - if(path.isEmpty() || !QFile::exists(path) || !ok){ - button->setWhatsThis(""); - button->setIcon( LXDG::findIcon("quickopen-file","") ); - button->setText( tr("Click to Set") ); - if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); } - }else{ - button->setWhatsThis(file.filePath); - button->setIcon( LXDG::findIcon(file.icon,"quickopen") ); - button->setText( this->fontMetrics().elidedText(file.name, Qt::ElideRight, 64) ); - if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); } - watcher->addPath(file.filePath); //make sure to update this shortcut if the file changes - } - } - - void buttonClicked(){ - QString path = button->whatsThis(); - if(path.isEmpty() || !QFile::exists(path) ){ - //prompt for the user to select an application - QList<XDGDesktop> apps = LXDG::sortDesktopNames( LXDG::systemDesktopFiles() ); - QStringList names; - for(int i=0; i<apps.length(); i++){ names << apps[i].name; } - bool ok = false; - QString app = QInputDialog::getItem(this, tr("Select Application"), tr("Name:"), names, 0, false, &ok); - if(!ok || names.indexOf(app)<0){ return; } //cancelled - this->settings->setValue("applicationpath", apps[ names.indexOf(app) ].filePath); - QTimer::singleShot(0,this, SLOT(loadButton())); - }else{ - QProcess::startDetached("lumina-open "+path); - } - - } + void loadButton(); + void buttonClicked(); }; #endif diff --git a/lumina-desktop/lumina-desktop.pro b/lumina-desktop/lumina-desktop.pro index f2fa139d..69c81b86 100644 --- a/lumina-desktop/lumina-desktop.pro +++ b/lumina-desktop/lumina-desktop.pro @@ -36,7 +36,8 @@ SOURCES += main.cpp \ panel-plugins/battery/LBattery.cpp \ panel-plugins/desktopswitcher/LDesktopSwitcher.cpp \ panel-plugins/systemdashboard/LSysDashboard.cpp \ - panel-plugins/systemdashboard/SysMenuQuick.cpp + panel-plugins/systemdashboard/SysMenuQuick.cpp \ + desktop-plugins/applauncher/AppLauncherPlugin.cpp # desktop-plugins/desktopview/DesktopViewPlugin.cpp \ # desktop-plugins/desktopview/DeskItem.cpp 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; i<items.length(); i++){ - if(items[i].endsWith(".desktop")){ items.removeAt(i); i--; } + if(items[i].suffix()=="desktop"){ items.removeAt(i); i--; } } } for(int i=0; i<items.length(); i++){ - UserItemWidget *it = new UserItemWidget(ui->scroll_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()) ); |