From b38f4f6ce26fd50cc7fac1d1b0c09ab22ee4e3ea Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 22 Jul 2015 16:10:11 -0400 Subject: Finish up the XDG "Actions" specification for *.desktop files, and integrate it into the AppMenu and UserButton. Also add a new flag to lumina-open so that we can specify which action to use when starting an app. --- .../panel-plugins/userbutton/UserItemWidget.cpp | 35 ++++++++++++++++++++-- .../panel-plugins/userbutton/UserItemWidget.h | 5 +++- .../panel-plugins/userbutton/UserWidget.cpp | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) (limited to 'lumina-desktop/panel-plugins') diff --git a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp index ff77121e..76a0b4cf 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp +++ b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.cpp @@ -6,6 +6,7 @@ //=========================================== #include "UserItemWidget.h" #include +#include #define TEXTCUTOFF 165 UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, QString type, bool goback) : QFrame(parent){ @@ -19,11 +20,14 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, QString type, if(ok){ icon->setPixmap( LXDG::findIcon(item.icon, "preferences-system-windows-actions").pixmap(32,32) ); name->setText( this->fontMetrics().elidedText(item.name, Qt::ElideRight, TEXTCUTOFF) ); + setupActions(item); }else{ icon->setPixmap( LXDG::findIcon("unknown","").pixmap(32,32) ); name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, TEXTCUTOFF) ); + actButton->setVisible(false); } }else if(type=="dir"){ + actButton->setVisible(false); if(itemPath.endsWith("/")){ itemPath.chop(1); } if(goback){ icon->setPixmap( LXDG::findIcon("go-previous","").pixmap(32,32) ); @@ -33,6 +37,7 @@ UserItemWidget::UserItemWidget(QWidget *parent, QString itemPath, QString type, name->setText( this->fontMetrics().elidedText(itemPath.section("/",-1), Qt::ElideRight, TEXTCUTOFF) ); } }else{ + actButton->setVisible(false); if(itemPath.endsWith("/")){ itemPath.chop(1); } if(QFileInfo(itemPath).isDir()){ type = "dir"; @@ -75,9 +80,9 @@ UserItemWidget::UserItemWidget(QWidget *parent, XDGDesktop item) : QFrame(parent name->setText( this->fontMetrics().elidedText(item.name, Qt::ElideRight, TEXTCUTOFF) ); this->setWhatsThis(name->text()); icon->setWhatsThis(item.filePath); - //Now setup the button appropriately + //Now setup the buttons appropriately setupButton(); - + setupActions(item); } UserItemWidget::~UserItemWidget(){ @@ -93,12 +98,17 @@ void UserItemWidget::createWidget(){ button = new QToolButton(this); button->setIconSize( QSize(14,14) ); button->setAutoRaise(true); + actButton = new QToolButton(this); + actButton->setPopupMode(QToolButton::InstantPopup); + actButton->setFixedSize( QSize(17,34) ); + actButton->setArrowType(Qt::DownArrow); icon = new QLabel(this); icon->setFixedSize( QSize(34,34) ); name = new QLabel(this); //Add them to the layout this->setLayout(new QHBoxLayout()); this->layout()->setContentsMargins(1,1,1,1); + this->layout()->addWidget(actButton); this->layout()->addWidget(icon); this->layout()->addWidget(name); this->layout()->addWidget(button); @@ -138,6 +148,19 @@ void UserItemWidget::setupButton(bool disable){ } } +void UserItemWidget::setupActions(XDGDesktop app){ + if(app.actions.isEmpty()){ actButton->setVisible(false); return; } + //Actions Available - go ahead and list them all + actButton->setMenu( new QMenu(this) ); + for(int i=0; isetToolTip(app.actions[i].ID); + act->setWhatsThis(app.actions[i].ID); + actButton->menu()->addAction(act); + } + connect(actButton->menu(), SIGNAL(triggered(QAction*)), this, SLOT(actionClicked(QAction*)) ); +} + void UserItemWidget::buttonClicked(){ button->setVisible(false); if(button->whatsThis()=="add"){ @@ -161,3 +184,11 @@ void UserItemWidget::ItemClicked(){ if(!linkPath.isEmpty()){ emit RunItem(linkPath); } else{ emit RunItem(icon->whatsThis()); } } + +void UserItemWidget::actionClicked(QAction *act){ + actButton->menu()->hide(); + QString cmd = "lumina-open -action \""+act->whatsThis()+"\" \"%1\""; + if(!linkPath.isEmpty()){ cmd = cmd.arg(linkPath); } + else{ cmd = cmd.arg(icon->whatsThis()); } + emit RunItem(cmd); +} \ 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 a65d3e83..b3c5aea7 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h +++ b/lumina-desktop/panel-plugins/userbutton/UserItemWidget.h @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -30,17 +31,19 @@ public: ~UserItemWidget(); private: - QToolButton *button; + QToolButton *button, *actButton; QLabel *icon, *name; bool isDirectory, isShortcut; QString linkPath; void createWidget(); void setupButton(bool disable = false); + void setupActions(XDGDesktop); private slots: void buttonClicked(); void ItemClicked(); + void actionClicked(QAction*); protected: void mouseReleaseEvent(QMouseEvent *event){ diff --git a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp index 92f6178b..5d1a2bc9 100644 --- a/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp +++ b/lumina-desktop/panel-plugins/userbutton/UserWidget.cpp @@ -188,7 +188,7 @@ void UserWidget::UpdateMenu(bool forceall){ void UserWidget::LaunchItem(QString path, bool fix){ if(!path.isEmpty()){ qDebug() << "Launch Application:" << path; - if(fix){ LSession::LaunchApplication("lumina-open \""+path+"\""); } + if( fix && !path.startsWith("lumina-open") ){ LSession::LaunchApplication("lumina-open \""+path+"\""); } else{ LSession::LaunchApplication(path); } emit CloseMenu(); //so the menu container will close } -- cgit