Commit 61fcf3f4 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Improve exposed actions

If there's no paired devices, show nothing.
If there's one, just one action to send directly from.
If there's more, then show the submenu
parent a2e66327
......@@ -48,23 +48,33 @@ QList<QAction*> SendFileItemAction::actions(const KFileItemListProperties& fileI
{
DevicesModel m;
QAction *menuAction = new QAction(QIcon::fromTheme("preferences-system-network"), i18n("Send via KDE Connect"), parentWidget);
QMenu *menu = new QMenu();
QList<QAction*> actions;
for(int i = 0; i<m.rowCount(); ++i) {
QModelIndex idx = m.index(i);
DeviceDbusInterface* dev = m.getDevice(idx);
if(dev->isReachable() && dev->isPaired()) {
QAction* action = menu->addAction(dev->name(), this, SLOT(sendFile()));
QAction* action = new QAction(dev->name(), parentWidget);
action->setProperty("id", idx.data(DevicesModel::IdModelRole));
action->setProperty("urls", QVariant::fromValue(fileItemInfos.urlList()));
action->setProperty("parentWidget", QVariant::fromValue(parentWidget));
actions += action;
}
}
menuAction->setMenu(menu);
return QList<QAction*>() << menuAction;
if (actions.count() > 1) {
QAction *menuAction = new QAction(QIcon::fromTheme("preferences-system-network"), i18n("Send via KDE Connect"), parentWidget);
QMenu *menu = new QMenu();
menu->addActions(actions);
menuAction->setMenu(menu);
return QList<QAction*>() << menuAction;
} else {
if(actions.count() == 1) {
actions.first()->setText(i18n("Send to '%1' via KDE Connect", actions.first()->text()));
actions.first()->setIcon(QIcon::fromTheme("preferences-system-network"));
}
return actions;
}
}
void SendFileItemAction::sendFile()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment