Skip to content
Snippets Groups Projects
Commit 56c1e420 authored by Burak Hançerli's avatar Burak Hançerli :headphones:
Browse files

QDS-11424 Update user projects automatically

parent 839b726a
No related branches found
No related tags found
1 merge request!25QDS-11424 Update user projects automatically
Pipeline #65107 passed
......@@ -72,7 +72,54 @@ void Backend::initialize()
updateUserProjectList();
}
qDebug("Initialization complete");
// Check if updateInBackground is enabled
updateInBackground(settings.value("system/updateInBackground").toBool());
qDebug() << "Initialization complete";
}
void Backend::updateInBackground(const bool &enabled)
{
QSettings().setValue("system/updateInBackground", enabled);
if (enabled) {
qDebug() << "Update in background is enabled";
m_backgroundTimer.setInterval(1000 * 10);
connect(&m_backgroundTimer, &QTimer::timeout, this, [&] {
qDebug() << "Checking for updates in background";
if (m_userHash.isEmpty())
return;
m_serviceConnector.reset(new ServiceConnector);
QJsonArray projectList = m_serviceConnector->fetchUserProjectList(m_userHash);
if (projectList.isEmpty())
return;
qDebug() << "New projects available. Updating project list";
updateUserProjectList();
});
m_backgroundTimer.start();
} else {
qDebug() << "Update in background is disabled";
m_backgroundTimer.stop();
}
}
void Backend::cacheDemoProjects(const bool &enabled)
{
QSettings().setValue("system/cacheDemoProjects", enabled);
if (enabled) {
qDebug() << "Caching demo projects is enabled";
} else {
qDebug() << "Caching demo projects is disabled";
}
}
void Backend::cacheUserProjects(const bool &enabled)
{
QSettings().setValue("system/cacheUserProjects", enabled);
if (enabled) {
qDebug() << "Caching user projects is enabled";
} else {
qDebug() << "Caching user projects is disabled";
}
}
void Backend::updatePopup(const QString &text, bool indeterminate)
......@@ -322,6 +369,16 @@ void Backend::updateUserProjectList()
m_serviceConnector.reset(new ServiceConnector);
QJsonArray projectList = m_serviceConnector->fetchUserProjectList(m_userHash);
if (projectList.isEmpty()) {
qCritical("Could not fetch available project list");
return;
}
if (projectList == m_projectListArray) {
qDebug("No new projects available");
return;
}
m_projectListArray = projectList;
m_projectList.clear();
qDebug("List of available projects fetched:");
for (const auto &project : projectList) {
......
......@@ -54,6 +54,7 @@ private:
// UI data
QString m_logs;
QStringList m_projectList;
QJsonArray m_projectListArray;
// Other members
QString m_userHash;
......@@ -62,6 +63,8 @@ private:
QScopedPointer<DesignStudioConnector> m_designStudioConnector;
QThread m_dsConnectorThread;
QTimer m_backgroundTimer;
// member functions
void updateUserProjectList();
void updatePopup(const QString &text, bool indeterminate = true);
......@@ -91,6 +94,12 @@ public slots:
void parseDesignViewerUrl(const QUrl &url);
void registerUser(const QUrl &url);
// settings
void updateInBackground(const bool &enabled);
void cacheDemoProjects(const bool &enabled);
void cacheUserProjects(const bool &enabled);
private slots:
void initializeProjectManager();
};
......
import QtQuick
import QtQuick.Controls 6.4
import QtQuick.Layouts
Item {
id: settingsPage
ColumnLayout {
anchors.fill: parent
Item {
id: item2
Layout.preferredWidth: 10
Layout.preferredHeight: 10
Layout.fillWidth: true
Layout.fillHeight: true
}
ColumnLayout {
id: column2
Layout.fillWidth: true
CheckBox {
id: checkBox
text: qsTr("Update user projects in the backgroud")
font.pointSize: 15
onCheckStateChanged: backend.updateInBackground(checkState)
}
Text{
leftPadding: 45
text: qsTr("Checks new projects in each 10 seconds")
font.pointSize: 12
}
// CheckBox {
// id: checkBox2
// text: qsTr("Cache user projects")
// font.pointSize: 15
// onCheckStateChanged: backend.cacheUserProjects(checkState)
// }
// Text{
// leftPadding: 45
// text: qsTr("Downloads the user projects each time if disabled")
// font.pointSize: 12
// }
// CheckBox {
// id: checkBox3
// text: qsTr("Cache demo projects")
// font.pointSize: 15
// onCheckStateChanged: backend.cacheDemoProjects(checkState)
// }
// Text{
// leftPadding: 45
// text: qsTr("Downloads the demo projects each time if disabled")
// font.pointSize: 12
// }
}
Item {
id: item3
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredHeight: 10
Layout.preferredWidth: 10
}
// Button {
// id: downloadButton
// text: qsTr("Save")
// onClicked: backend.saveSettings(checkBox.checked)
// Layout.fillWidth: true
// Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
// }
}
}
File added
......@@ -111,6 +111,11 @@ Rectangle {
Layout.fillWidth: true
}
SettingsPage {
id: settingsPage
Layout.fillWidth: true
}
AboutHeader {
id: headerPage
Layout.fillWidth: true
......@@ -207,6 +212,21 @@ Rectangle {
}
}
TabButton {
id: settings
text: qsTr("Settings")
Layout.fillWidth: true
checkable: true
autoExclusive: true
Connections {
target: settings
function onClicked(){
stackLayout.currentIndex = 4
}
}
}
TabButton {
id: about
......@@ -218,7 +238,7 @@ Rectangle {
Connections {
target: about
function onClicked(){
stackLayout.currentIndex = 4
stackLayout.currentIndex = 5
}
}
}
......
......@@ -7,5 +7,6 @@
<file>Network.qml</file>
<file>ExamplesPage.qml</file>
<file>AboutHeader.qml</file>
<file>SettingsPage.qml</file>
</qresource>
</RCC>
<RCC>
<qresource>
<file>AboutHeader.qml</file>
<file>content/images/appicon.png</file>
<file>DesignViewer.qmlproject</file>
<file>ExamplesPage.qml</file>
<file>HomePage.qml</file>
<file>imports/DesignViewer/Constants.qml</file>
<file>imports/DesignViewer/DirectoryFontLoader.qml</file>
<file>imports/DesignViewer/EventListModel.qml</file>
<file>imports/DesignViewer/EventListSimulator.qml</file>
<file>imports/DesignViewer/qmldir</file>
<file>Logs.qml</file>
<file>main.qml</file>
<file>Network.qml</file>
<file>qtquickcontrols2.conf</file>
<file>SettingsPage.qml</file>
</qresource>
</RCC>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment