Verified Commit ee375e8a authored by Jonah Brüchert's avatar Jonah Brüchert 🌳
Browse files

appchooserdialog: Replace context properties

parent 0b0655b2
......@@ -57,16 +57,18 @@ AppChooserDialog::AppChooserDialog(const QStringList &choices, const QString &de
AppFilterModel *filterModel = new AppFilterModel(this);
filterModel->setSourceModel(m_model);
m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("myModel"), filterModel);
m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("fileName"), fileName);
m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("defaultApp"), defaultApp);
auto *data = new AppChooserData(this);
data->setFileName(fileName);
data->setDefaultApp(defaultApp);
qmlRegisterSingletonInstance<AppFilterModel>("org.kde.xdgdesktopportal", 1, 0, "AppModel", filterModel);
qmlRegisterSingletonInstance<AppChooserData>("org.kde.xdgdesktopportal", 1, 0, "AppChooserData", data);
m_dialog->quickWidget->setClearColor(Qt::transparent);
m_dialog->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
m_dialog->quickWidget->setSource(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("xdg-desktop-portal-kde/qml/AppChooserDialog.qml"))));
QObject *rootItem = m_dialog->quickWidget->rootObject();
connect(rootItem, SIGNAL(openDiscover()), this, SLOT(onOpenDiscover()));
connect(rootItem, SIGNAL(applicationSelected(QString)), this, SLOT(onApplicationSelected(QString)));
connect(data, &AppChooserData::openDiscover, this, &AppChooserDialog::onOpenDiscover);
connect(data, &AppChooserData::applicationSelected, this, &AppChooserDialog::onApplicationSelected);
setWindowTitle(i18n("Open with..."));
}
......@@ -210,6 +212,33 @@ bool AppFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right)
return QString::localeAwareCompare(leftName, rightName) > 0;
}
QString AppChooserData::defaultApp() const
{
return m_defaultApp;
}
void AppChooserData::setDefaultApp(const QString &defaultApp)
{
m_defaultApp = defaultApp;
Q_EMIT defaultAppChanged();
}
AppChooserData::AppChooserData(QObject *parent)
: QObject(parent)
{
}
QString AppChooserData::fileName() const
{
return m_fileName;
}
void AppChooserData::setFileName(const QString &fileName)
{
m_fileName = fileName;
Q_EMIT fileNameChanged();
}
AppModel::AppModel(QObject *parent)
: QAbstractListModel(parent)
{
......
......@@ -85,6 +85,30 @@ private:
QString m_filter;
};
class AppChooserData : public QObject {
Q_OBJECT
Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
Q_PROPERTY(QString defaultApp READ defaultApp WRITE setDefaultApp NOTIFY defaultAppChanged)
public:
AppChooserData(QObject *parent = nullptr);
QString fileName() const;
void setFileName(const QString &fileName);
Q_SIGNAL void fileNameChanged();
QString defaultApp() const;
void setDefaultApp(const QString &defaultApp);
Q_SIGNAL void defaultAppChanged();
Q_SIGNAL void applicationSelected(const QString &desktopFile);
Q_SIGNAL void openDiscover();
private:
QString m_defaultApp;
QString m_fileName;
};
class AppModel : public QAbstractListModel
{
Q_OBJECT
......
......@@ -24,12 +24,11 @@ import QtQuick.Layouts 1.12
import org.kde.plasma.core 2.0
import org.kde.kirigami 2.9 as Kirigami
import org.kde.xdgdesktopportal 1.0
Item {
id: root
signal applicationSelected(string name)
signal openDiscover()
Rectangle {
id: background
anchors.fill: parent
......@@ -42,12 +41,12 @@ Item {
Label {
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
text: i18n("Select an application to open <b>%1</b>. More applications are available in <a href=#discover>Discover</a>.", fileName)
text: i18n("Select an application to open <b>%1</b>. More applications are available in <a href=#discover>Discover</a>.", AppChooserData.fileName)
textFormat: Text.RichText
wrapMode: Text.WordWrap
onLinkActivated: {
openDiscover()
AppChooserData.openDiscover()
}
}
......@@ -69,7 +68,7 @@ Item {
anchors.fill: parent
cellHeight: 110
cellWidth: 150
model: myModel
model: AppModel
delegate: appDelegate
}
......@@ -84,7 +83,7 @@ Item {
onClicked: {
visible = false
myModel.showOnlyPreferredApps = false
AppModel.showOnlyPreferredApps = false
}
}
......@@ -94,7 +93,7 @@ Item {
visible: !showAllAppsButton.visible
opacity: visible
placeholderText: i18n("Search...");
onTextChanged: myModel.filter = text
onTextChanged: AppModel.filter = text
}
}
......@@ -108,7 +107,7 @@ Item {
Rectangle {
anchors.fill: parent
color: Kirigami.Theme.highlightColor
visible: ApplicationDesktopFile == defaultApp
visible: ApplicationDesktopFile == AppChooserData.defaultApp
radius: 2
}
......@@ -118,7 +117,7 @@ Item {
hoverEnabled: true
onContainsMouseChanged: cursorShape = containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
onClicked: applicationSelected(ApplicationDesktopFile)
onClicked: AppChooserData.applicationSelected(ApplicationDesktopFile)
}
Column {
......
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