[Libtaskmanager] Add "requestOpenUrls" to open given URLs with the associated application

Differential Revision: https://phabricator.kde.org/D2391
wilder-5.14
Kai Uwe Broulik 10 years ago
parent 9b546d9310
commit 4a8877bab2
  1. 6
      libtaskmanager/abstracttasksmodel.cpp
  2. 11
      libtaskmanager/abstracttasksmodel.h
  3. 9
      libtaskmanager/abstracttasksmodeliface.h
  4. 16
      libtaskmanager/concatenatetasksproxymodel.cpp
  5. 9
      libtaskmanager/concatenatetasksproxymodel.h
  6. 7
      libtaskmanager/flattentaskgroupsproxymodel.cpp
  7. 9
      libtaskmanager/flattentaskgroupsproxymodel.h
  8. 33
      libtaskmanager/launchertasksmodel.cpp
  9. 8
      libtaskmanager/launchertasksmodel.h
  10. 8
      libtaskmanager/taskfilterproxymodel.cpp
  11. 9
      libtaskmanager/taskfilterproxymodel.h
  12. 9
      libtaskmanager/taskgroupingproxymodel.cpp
  13. 9
      libtaskmanager/taskgroupingproxymodel.h
  14. 7
      libtaskmanager/tasksmodel.cpp
  15. 9
      libtaskmanager/tasksmodel.h
  16. 20
      libtaskmanager/waylandtasksmodel.cpp
  17. 10
      libtaskmanager/waylandtasksmodel.h
  18. 7
      libtaskmanager/windowtasksmodel.cpp
  19. 10
      libtaskmanager/windowtasksmodel.h
  20. 15
      libtaskmanager/xwindowtasksmodel.cpp
  21. 10
      libtaskmanager/xwindowtasksmodel.h

@ -62,6 +62,12 @@ void AbstractTasksModel::requestNewInstance(const QModelIndex &index)
Q_UNUSED(index)
}
void AbstractTasksModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls)
{
Q_UNUSED(index)
Q_UNUSED(urls)
}
void AbstractTasksModel::requestClose(const QModelIndex &index)
{
Q_UNUSED(index)

@ -114,6 +114,17 @@ public:
**/
virtual void requestNewInstance(const QModelIndex &index) override;
/**
* Requests to open the given URLs with the application backing the task
* at the given index.
*
* This base implementation does nothing.
*
* @param index An index in this tasks model.
* @param urls The URLs to be passed to the application.
**/
virtual void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls);
/**
* Request the task at the given index be closed.
*

@ -60,6 +60,15 @@ public:
**/
virtual void requestNewInstance(const QModelIndex &index) = 0;
/**
* Requests to open the given URLs with the application backing the task
* at the given index.
*
* @param index An index in this tasks model.
* @param urls The URLs to be passed to the application.
**/
virtual void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) = 0;
/**
* Request the task at the given index be closed.
*

@ -64,6 +64,22 @@ void ConcatenateTasksProxyModel::requestNewInstance(const QModelIndex &index)
}
}
void ConcatenateTasksProxyModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls)
{
if (!index.isValid() || index.model() != this) {
return;
}
const QModelIndex &sourceIndex = mapToSource(index);
const AbstractTasksModelIface *m = dynamic_cast<const AbstractTasksModelIface *>(sourceIndex.model());
if (m) {
// NOTE: KConcatenateRowsProxyModel offers no way to get a non-const pointer
// to one of the source models, so we have to go through a mapped index.
const_cast<AbstractTasksModelIface *>(m)->requestOpenUrls(sourceIndex, urls);
}
}
void ConcatenateTasksProxyModel::requestClose(const QModelIndex &index)
{
if (!index.isValid() || index.model() != this) {

@ -65,6 +65,15 @@ public:
**/
void requestNewInstance(const QModelIndex &index);
/**
* Requests to open the given URLs with the application backing the task
* at the given index.
*
* @param index An index in this tasks model.
* @param urls The URLs to be passed to the application.
**/
virtual void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls);
/**
* Request the task at the given index be closed.
*

@ -70,6 +70,13 @@ void FlattenTaskGroupsProxyModel::requestNewInstance(const QModelIndex &index)
}
}
void FlattenTaskGroupsProxyModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls)
{
if (d->sourceTasksModel && index.isValid() && index.model() == this) {
d->sourceTasksModel->requestOpenUrls(mapToSource(index), urls);
}
}
void FlattenTaskGroupsProxyModel::requestClose(const QModelIndex &index)
{
if (d->sourceTasksModel && index.isValid() && index.model() == this) {

@ -68,6 +68,15 @@ public:
**/
void requestNewInstance(const QModelIndex &index) override;
/**
* Requests to open the given URLs with the application backing the task
* at the given index.
*
* @param index An index in this tasks model.
* @param urls The URLs to be passed to the application.
**/
virtual void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls);
/**
* Request the task at the given index be closed.
*

@ -308,4 +308,37 @@ void LauncherTasksModel::requestNewInstance(const QModelIndex &index)
}
}
void LauncherTasksModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls)
{
if (!index.isValid() || index.model() != this
|| index.row() < 0 || index.row() >= d->launchers.count()
|| urls.isEmpty()) {
return;
}
const QUrl &url = d->launchers.at(index.row());
quint32 timeStamp = 0;
#if HAVE_X11
if (KWindowSystem::isPlatformX11()) {
timeStamp = QX11Info::appUserTime();
}
#endif
KService::Ptr service;
if (url.scheme() == QLatin1String("preferred")) {
service = KService::serviceByStorageId(defaultApplication(url));
} else {
service = KService::serviceByDesktopPath(url.toLocalFile());
}
if (!service) {
return;
}
KRun::runApplication(*service, urls, nullptr, false, {}, KStartupInfo::createNewStartupIdForTimestamp(timeStamp));
}
}

@ -132,6 +132,14 @@ public:
*/
void requestNewInstance(const QModelIndex &index) override;
/**
* Runs the application backing the launcher at the given index with the given URLs.
*
* @param index An index in this launcher tasks model
* @param urls The URLs to be passed to the application
*/
void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
Q_SIGNALS:
void launcherListChanged() const;

@ -215,6 +215,14 @@ void TaskFilterProxyModel::requestNewInstance(const QModelIndex &index)
}
}
void TaskFilterProxyModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls)
{
if (d->sourceTasksModel && index.isValid() && index.model() == this) {
d->sourceTasksModel->requestOpenUrls(mapToSource(index), urls);
}
}
void TaskFilterProxyModel::requestClose(const QModelIndex &index)
{
if (d->sourceTasksModel && index.isValid() && index.model() == this) {

@ -247,6 +247,15 @@ public:
**/
void requestNewInstance(const QModelIndex &index) override;
/**
* Requests to open the given URLs with the application backing the task
* at the given index.
*
* @param index An index in this tasks model.
* @param urls The URLs to be passed to the application.
**/
virtual void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls);
/**
* Request the task at the given index be closed.
*

@ -938,6 +938,15 @@ void TaskGroupingProxyModel::requestNewInstance(const QModelIndex &index)
d->abstractTasksSourceModel->requestNewInstance(mapToSource(index));
}
void TaskGroupingProxyModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls)
{
if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) {
return;
}
d->abstractTasksSourceModel->requestOpenUrls(mapToSource(index), urls);
}
void TaskGroupingProxyModel::requestClose(const QModelIndex &index)
{
if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) {

@ -211,6 +211,15 @@ public:
**/
void requestNewInstance(const QModelIndex &index) override;
/**
* Requests to open the given URLs with the application backing the task
* at the given index.
*
* @param index An index in this tasks model.
* @param urls The URLs to be passed to the application.
**/
virtual void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls);
/**
* Request the task at the given index be closed.
*

@ -1175,6 +1175,13 @@ void TasksModel::requestNewInstance(const QModelIndex &index)
}
}
void TasksModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls)
{
if (index.isValid() && index.model() == this) {
d->abstractTasksSourceModel->requestOpenUrls(mapToSource(index), urls);
}
}
void TasksModel::requestClose(const QModelIndex &index)
{
if (index.isValid() && index.model() == this) {

@ -576,6 +576,15 @@ public:
**/
Q_INVOKABLE void requestNewInstance(const QModelIndex &index) override;
/**
* Requests to open the given URLs with the application backing the task
* at the given index.
*
* @param index An index in this tasks model.
* @param urls The URLs to be passed to the application.
**/
Q_INVOKABLE void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls);
/**
* Request the task at the given index be closed.
*

@ -375,6 +375,26 @@ void WaylandTasksModel::requestNewInstance(const QModelIndex &index)
}
}
void WaylandTasksModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls)
{
if (!index.isValid() || index.model() != this || index.row() < 0
|| index.row() >= d->windows.count()
|| urls.isEmpty()) {
return;
}
KWayland::Client::PlasmaWindow *window = d->windows.at(index.row());
if (d->serviceCache.contains(window)) {
const KService::Ptr service = d->serviceCache.value(window);
KRun::runApplication(*service, urls, nullptr, false);
KActivities::ResourceInstance::notifyAccessed(QUrl("applications:" + service->storageId()),
"org.kde.libtaskmanager");
}
}
void WaylandTasksModel::requestClose(const QModelIndex &index)
{
if (!index.isValid() || index.model() != this || index.row() < 0 || index.row() >= d->windows.count()) {

@ -80,6 +80,16 @@ public:
**/
void requestNewInstance(const QModelIndex &index) override;
/**
* Runs the application backing the launcher at the given index with the given URLs.
* Success depends on whether a AbstractTasksModel::LauncherUrl could be
* derived from window metadata and a KService could be found from that.
*
* @param index An index in this launcher tasks model
* @param urls The URLs to be passed to the application
*/
void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
/**
* Request the window at the given index be closed.
*

@ -116,6 +116,13 @@ void WindowTasksModel::requestNewInstance(const QModelIndex &index)
}
}
void WindowTasksModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls)
{
if (d->sourceTasksModel && index.isValid() && index.model() == this) {
d->sourceTasksModel->requestOpenUrls(mapToSource(index), urls);
}
}
void WindowTasksModel::requestClose(const QModelIndex &index)
{
if (d->sourceTasksModel && index.isValid() && index.model() == this) {

@ -66,6 +66,16 @@ public:
**/
void requestNewInstance(const QModelIndex &index) override;
/**
* Runs the application backing the launcher at the given index with the given URLs.
* Success depends on whether a AbstractTasksModel::LauncherUrl could be
* derived from window metadata and a KService could be found from that.
*
* @param index An index in this launcher tasks model
* @param urls The URLs to be passed to the application
*/
void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
/**
* Request the window at the given index be closed.
*

@ -943,6 +943,21 @@ void XWindowTasksModel::requestNewInstance(const QModelIndex &index)
}
}
void XWindowTasksModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls)
{
if (!index.isValid() || index.model() != this || index.row() < 0
|| index.row() >= d->windows.count()
|| urls.isEmpty()) {
return;
}
const QUrl &url = d->appData(d->windows.at(index.row())).url;
const KService::Ptr service = KService::serviceByDesktopPath(url.toLocalFile());
if (service) {
KRun::runApplication(*service, urls, nullptr, false, {}, KStartupInfo::createNewStartupIdForTimestamp(QX11Info::appUserTime()));
}
}
void XWindowTasksModel::requestClose(const QModelIndex &index)
{
if (!index.isValid() || index.model() != this || index.row() < 0 || index.row() >= d->windows.count()) {

@ -79,6 +79,16 @@ public:
**/
void requestNewInstance(const QModelIndex &index) override;
/**
* Runs the application backing the launcher at the given index with the given URLs.
* Success depends on whether a AbstractTasksModel::LauncherUrl could be
* derived from window metadata and a KService could be found from that.
*
* @param index An index in this launcher tasks model
* @param urls The URLs to be passed to the application
*/
void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
/**
* Request the window at the given index be closed.
*

Loading…
Cancel
Save