Commit 6ea1371c authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Improve refresh behavior

Implement pull to refresh on the updates view (although it will only work
on touch screens.
Make the update action the only one that the ResourcesModel offers and make
it globally available
parent 83a2715c
import QtQuick 2.1
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.1
import QtQuick.Controls 2.1 as QQC2
......@@ -84,6 +84,19 @@ Kirigami.ApplicationWindow
shortcut: "Alt+S"
}
Action {
id: refreshAction
readonly property QtObject action: ResourcesModel.updateAction
text: action.text
onTriggered: action.trigger()
enabled: action.enabled
tooltip: seq.nativeText
shortcut: Shortcut {
id: seq
sequence: "Ctrl+R"
}
}
Connections {
target: app
onOpenApplicationInternal: {
......
......@@ -48,27 +48,8 @@ DiscoverPage {
Layout.fillWidth: true
}
Repeater {
model: ActionsModel {
actions: ResourcesModel.actions
}
delegate: RowLayout {
Kirigami.Icon {
source: modelData.icon
}
visible: theAction.action && theAction.action.visible
ToolButton {
height: parent.height
action: Action {
id: theAction
readonly property QtObject action: modelData
text: action.text
onTriggered: action.trigger()
enabled: action.enabled
}
}
}
ToolButton {
action: refreshAction
}
ToolButton {
......
......@@ -96,7 +96,11 @@ DiscoverPage
}
}
//TODO: use supportsRefreshing to fetch updates
supportsRefreshing: true
onRefreshingChanged: {
showPassiveNotification("Fetching updates...")
ResourcesModel.updateAction.triggered()
}
ListView
{
id: updatesView
......
......@@ -68,16 +68,14 @@ void ResourcesModel::init(bool load)
QMetaObject::invokeMethod(this, "registerAllBackends", Qt::QueuedConnection);
QAction* updateAction = new QAction(this);
updateAction->setIcon(QIcon::fromTheme(QStringLiteral("system-software-update")));
updateAction->setText(i18nc("@action Checks the Internet for updates", "Check for Updates"));
updateAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
connect(this, &ResourcesModel::fetchingChanged, updateAction, [updateAction](bool fetching) {
updateAction->setEnabled(!fetching);
m_updateAction = new QAction(this);
m_updateAction->setIcon(QIcon::fromTheme(QStringLiteral("system-software-update")));
m_updateAction->setText(i18nc("@action Checks the Internet for updates", "Check for Updates"));
m_updateAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
connect(this, &ResourcesModel::fetchingChanged, m_updateAction, [this](bool fetching) {
m_updateAction->setEnabled(!fetching);
});
connect(updateAction, &QAction::triggered, this, &ResourcesModel::checkForUpdates);
m_ownActions += updateAction;
connect(m_updateAction, &QAction::triggered, this, &ResourcesModel::checkForUpdates);
}
ResourcesModel::ResourcesModel(const QString& backendName, QObject* parent)
......
......@@ -58,7 +58,7 @@ class DISCOVERCOMMON_EXPORT ResourcesModel : public QObject
Q_PROPERTY(bool isFetching READ isFetching NOTIFY fetchingChanged)
Q_PROPERTY(QVariantList applicationBackends READ applicationBackendsVariant NOTIFY backendsChanged)
Q_PROPERTY(AbstractResourcesBackend* currentApplicationBackend READ currentApplicationBackend WRITE setCurrentApplicationBackend NOTIFY currentApplicationBackendChanged)
Q_PROPERTY(QList<QAction*> actions READ actions CONSTANT)
Q_PROPERTY(QAction* updateAction READ updateAction CONSTANT)
public:
/** This constructor should be only used by unit tests.
* @p backendName defines what backend will be loaded when the backend is constructed.
......@@ -86,7 +86,7 @@ class DISCOVERCOMMON_EXPORT ResourcesModel : public QObject
void setCurrentApplicationBackend(AbstractResourcesBackend* backend, bool writeConfig = true);
AbstractResourcesBackend* currentApplicationBackend() const;
QList<QAction*> actions() const { return m_ownActions; }
QAction* updateAction() const { return m_updateAction; }
public Q_SLOTS:
void installApplication(AbstractResource* app, const AddonList& addons);
......@@ -121,7 +121,7 @@ class DISCOVERCOMMON_EXPORT ResourcesModel : public QObject
bool m_isFetching;
QVector< AbstractResourcesBackend* > m_backends;
int m_initializingBackends;
QList<QAction*> m_ownActions;
QAction* m_updateAction = nullptr;
AbstractResourcesBackend* m_currentApplicationBackend;
static ResourcesModel* s_self;
......
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