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::) --- lumina-desktop/desktop-plugins/NewDP.h | 3 +- .../applauncher/AppLauncherPlugin.cpp | 54 ++++++++++++++++++++++ .../applauncher/AppLauncherPlugin.h | 52 ++------------------- 3 files changed, 59 insertions(+), 50 deletions(-) create mode 100644 lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp (limited to 'lumina-desktop/desktop-plugins') 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:"<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 apps = LXDG::sortDesktopNames( LXDG::systemDesktopFiles() ); + QStringList names; + for(int i=0; isettings->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 apps = LXDG::sortDesktopNames( LXDG::systemDesktopFiles() ); - QStringList names; - for(int i=0; isettings->setValue("applicationpath", apps[ names.indexOf(app) ].filePath); - QTimer::singleShot(0,this, SLOT(loadButton())); - }else{ - QProcess::startDetached("lumina-open "+path); - } - - } + void loadButton(); + void buttonClicked(); }; #endif -- cgit