Hello to everyone,
I just found what I believe to be a problem with the service selection of
KParts::BrowserOpenOrSaveQuestion in KF-5.104 (installed from Gentoo
packages). Before creating a bug report, I'd like to be sure that this isn't a
problem related to my system and that I'm not misunderstanding how this class
works, so I'd like to know whether someone is experiencing the same problem or
can spot what I'm doing wrong. I've attached the code of a minimal program
which shows this issue.
The problem is the following: KParts::BrowserOpenOrSaveQuestion has a feature
which allows the user to choose the service to use to open the given URL,
which is enabled calling
setFeatures(KParts::BrowserOpenOrSaveQuestion::ServiceSelection) on the
dialog. This adds a button to the dialog; when this button is pressed, the
user is shown a menu with a list of available services for opening the URL;
the last entry is "Open with..." and it should display a "Choose application"
dialog so that the user can choose a service which isn't listed. However, on
my system, pressing this menu entry immediately closes the dialog.
The minimal example I created contains a button which, when clicked, creates
the KParts::BrowserOpenOrSaveQuestion dialog and shows it. When the dialog is
closed, a message box with the dialog result and the service chosen by the
user is shown. Clicking the "Open" button or the "Open with..." button and
choosing one of the suggested services works correctly, but choosing the "Open
with..." menu entry produces the behavior I described above: the dialog closes
with no possibility to choose another application.
KParts::BrowserOpenOrSaveQuestion::selectedService returns nullptr. Note that
this doesn't depend on the URL or the mimetypes passed to the dialog.
To build the minimal example, put the CMakeList.txt main.cpp in the same
directory and run cmake as usual.
I'd be grateful to anyone which can help me investigate this issue.
Thanks in advance
Stefano
/*
SPDX-FileCopyrightText: %{CURRENT_YEAR} %{AUTHOR} <%{EMAIL}>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include <QApplication>
#include <KParts/BrowserOpenOrSaveQuestion>
#include <QPushButton>
#include <QMessageBox>
#include <KService>
int main(int argc, char **argv)
{
QApplication application(argc, argv);
QPushButton *btn = new QPushButton("Test", nullptr);
auto callback = [](){
KParts::BrowserOpenOrSaveQuestion dlg(nullptr, QUrl::fromLocalFile("/tmp/test"), "text/plain");
dlg.setFeatures(KParts::BrowserOpenOrSaveQuestion::ServiceSelection);
auto res = dlg.askOpenOrSave();
QString resultString;
switch (res) {
case KParts::BrowserOpenOrSaveQuestion::Save:
resultString = "Save";
break;
case KParts::BrowserOpenOrSaveQuestion::Open:
resultString = "Open";
break;
case KParts::BrowserOpenOrSaveQuestion::Embed:
resultString = "Embed";
break;
case KParts::BrowserOpenOrSaveQuestion::Cancel:
resultString = "Cancel";
break;
}
KService::Ptr service = dlg.selectedService();
QString msg = QString("Return value was %1; Chosen service was: %2").arg(resultString).arg(service ? service->name() : "NONE");
QMessageBox::information(nullptr, QString(), msg);
};
btn->connect(btn, &QPushButton::clicked, btn, callback);
btn->show();
return application.exec();
}
cmake_minimum_required(VERSION 3.16)
project(testopenwith)
set(QT_MIN_VERSION "5.15.0")
set(KF_MIN_VERSION "5.83.0")
find_package(ECM ${KF_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(FeatureSummary)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Widgets)
find_package(KF5 ${KF_MIN_VERSION} REQUIRED COMPONENTS Parts)
add_executable(testopenwith)
target_sources(testopenwith PRIVATE main.cpp)
target_link_libraries(testopenwith
Qt5::Widgets
KF5::Parts
)
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)