1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-10-06 09:17:07 +02:00

Fix installed list sorting because of missing LastModified

Fix ScreenPlayItem isNew location
This commit is contained in:
Elias Steurer 2021-08-29 12:19:28 +02:00
parent 3675170d06
commit a8152b5ab0
5 changed files with 61 additions and 70 deletions

View File

@ -18,23 +18,23 @@ Item {
property int itemIndex property int itemIndex
property bool isScrolling: false property bool isScrolling: false
property bool isNew: false property bool isNew: false
Component.onCompleted:print(isNew)
signal openContextMenu(point position) signal openContextMenu(point position)
width: 320 width: 320
height: 180 height: 180
onTypeChanged: { onTypeChanged: {
if (JSUtil.isWidget(type)) { if (JSUtil.isWidget(type)) {
icnType.source = "qrc:/assets/icons/icon_widgets.svg"; icnType.source = "qrc:/assets/icons/icon_widgets.svg"
return ; return
} }
if (JSUtil.isScene(type)) { if (JSUtil.isScene(type)) {
icnType.source = "qrc:/assets/icons/icon_code.svg"; icnType.source = "qrc:/assets/icons/icon_code.svg"
return ; return
} }
if (JSUtil.isVideo(type)) { if (JSUtil.isVideo(type)) {
icnType.source = "qrc:/assets/icons/icon_movie.svg"; icnType.source = "qrc:/assets/icons/icon_movie.svg"
return ; return
} }
} }
@ -42,11 +42,11 @@ Item {
running: true running: true
onTriggered: showAnim.start() onTriggered: showAnim.start()
interval: { interval: {
var itemIndexMax = itemIndex; var itemIndexMax = itemIndex
if (itemIndex > 30) if (itemIndex > 30)
itemIndexMax = 3; itemIndexMax = 3
5 * itemIndexMax * Math.random(); 5 * itemIndexMax * Math.random()
} }
} }
@ -79,7 +79,6 @@ Item {
duration: 200 duration: 200
easing.type: Easing.OutCirc easing.type: Easing.OutCirc
} }
} }
OpacityAnimator { OpacityAnimator {
@ -89,7 +88,6 @@ Item {
duration: 800 duration: 800
easing.type: Easing.OutCirc easing.type: Easing.OutCirc
} }
} }
RectangularGlow { RectangularGlow {
@ -108,7 +106,6 @@ Item {
top: parent.top top: parent.top
topMargin: 3 topMargin: 3
} }
} }
Item { Item {
@ -175,7 +172,6 @@ Item {
left: parent.left left: parent.left
margins: 10 margins: 10
} }
} }
Rectangle { Rectangle {
@ -188,26 +184,30 @@ Item {
left: parent.left left: parent.left
bottom: parent.bottom bottom: parent.bottom
} }
} }
Image { Image {
id: new_banner id: newBanner
source: "qrc:/assets/icons/item_banner_new.svg" source: "qrc:/assets/icons/item_banner_new.svg"
visible: root.isNew visible: root.isNew
Text Text {
{ font.family: ScreenPlay.settings.font
font.bold: true
font.family:"Helvetica";font.bold: true;font.pointSize:9.5; font.italic: true font.pointSize: 10
color: "#AAffffff" color: "white"
text: qsTr("NEW") text: qsTr("NEW")
anchors{ smooth: true
right: new_banner.right antialiasing: true
top: new_banner.TopLeft
}
transform: Rotation{ origin.y:12; angle:45}
visible: root.isNew visible: root.isNew
anchors {
right: newBanner.right
top: newBanner.top
rightMargin: 3
topMargin: 10
}
transform: Rotation {
angle: 45
}
} }
} }
} }
@ -223,25 +223,23 @@ Item {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
onEntered: { onEntered: {
root.state = "hover"; root.state = "hover"
screenPlayItemImage.state = "hover"; screenPlayItemImage.state = "hover"
screenPlayItemImage.enter(); screenPlayItemImage.enter()
} }
onExited: { onExited: {
root.state = ""; root.state = ""
screenPlayItemImage.state = "loaded"; screenPlayItemImage.state = "loaded"
screenPlayItemImage.exit(); screenPlayItemImage.exit()
} }
onClicked: { onClicked: {
if (mouse.button === Qt.LeftButton) if (mouse.button === Qt.LeftButton)
ScreenPlay.util.setSidebarItem(root.screenId, root.type); ScreenPlay.util.setSidebarItem(root.screenId, root.type)
else if (mouse.button === Qt.RightButton) else if (mouse.button === Qt.RightButton)
root.openContextMenu(Qt.point(mouseX, mouseY)); root.openContextMenu(Qt.point(mouseX, mouseY))
} }
} }
} }
} }
transitions: [ transitions: [
@ -276,7 +274,6 @@ Item {
from: 0.6 from: 0.6
to: 1 to: 1
} }
}, },
Transition { Transition {
from: "hover" from: "hover"
@ -309,7 +306,6 @@ Item {
from: 1 from: 1
to: 0.5 to: 0.5
} }
} }
] ]
} }

View File

@ -1,7 +1,6 @@
#include "installedlistmodel.h" #include "installedlistmodel.h"
#include <QDebug> #include <QDebug>
namespace ScreenPlay { namespace ScreenPlay {
/*! /*!
@ -115,12 +114,13 @@ QVariant InstalledListModel::data(const QModelIndex& index, int role) const
return m_screenPlayFiles.at(row).m_tags; return m_screenPlayFiles.at(row).m_tags;
case static_cast<int>(ScreenPlayItem::IsNew): case static_cast<int>(ScreenPlayItem::IsNew):
return m_screenPlayFiles.at(row).m_isNew; return m_screenPlayFiles.at(row).m_isNew;
case static_cast<int>(ScreenPlayItem::LastModified):
return m_screenPlayFiles.at(row).m_lastModified;
case static_cast<int>(ScreenPlayItem::SearchType): case static_cast<int>(ScreenPlayItem::SearchType):
return QVariant::fromValue(m_screenPlayFiles.at(row).m_searchType); return QVariant::fromValue(m_screenPlayFiles.at(row).m_searchType);
default:
return QVariant();
} }
qWarning() << "Unable to fetch value for row type:" << role;
return QVariant(); return QVariant();
} }
@ -140,18 +140,18 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
{ static_cast<int>(ScreenPlayItem::PublishedFileID), "m_publishedFileID" }, { static_cast<int>(ScreenPlayItem::PublishedFileID), "m_publishedFileID" },
{ static_cast<int>(ScreenPlayItem::Tags), "m_tags" }, { static_cast<int>(ScreenPlayItem::Tags), "m_tags" },
{ static_cast<int>(ScreenPlayItem::SearchType), "m_searchType" }, { static_cast<int>(ScreenPlayItem::SearchType), "m_searchType" },
{ static_cast<int>(ScreenPlayItem::IsNew), "m_isNew" } { static_cast<int>(ScreenPlayItem::IsNew), "m_isNew" },
{ static_cast<int>(ScreenPlayItem::LastModified), "m_lastModified" }
}; };
} }
/*! /*!
\brief Append an ProjectFile to the list. \brief Append an ProjectFile to the list.
*/ */
void InstalledListModel::append(const QJsonObject& obj, const QString& folderName, const bool isNew) void InstalledListModel::append(const QJsonObject& obj, const QString& folderName, const bool isNew, const QDateTime& lastModified)
{ {
beginInsertRows(QModelIndex(), m_screenPlayFiles.size(), m_screenPlayFiles.size()); beginInsertRows(QModelIndex(), m_screenPlayFiles.size(), m_screenPlayFiles.size());
m_screenPlayFiles.append(ProjectFile(obj, folderName, m_globalVariables->localStoragePath(), isNew)); m_screenPlayFiles.append(ProjectFile(obj, folderName, m_globalVariables->localStoragePath(), isNew, lastModified));
endInsertRows(); endInsertRows();
} }
@ -169,15 +169,11 @@ void InstalledListModel::loadInstalledContent()
if (!QFile::exists(absoluteFilePath)) if (!QFile::exists(absoluteFilePath))
continue; continue;
bool isNew = false; bool isNew = false;
QDateTime date=QDateTime::currentDateTime();
qDebug()<<date.date(); if (item.birthTime().date() == QDateTime::currentDateTime().date())
if(item.birthTime().date()==date.date())
{
qDebug()<<item.birthTime()<<date.date();
isNew = true; isNew = true;
qDebug()<<isNew;
}
if (auto obj = ScreenPlayUtil::openJsonFileToObject(absoluteFilePath)) { if (auto obj = ScreenPlayUtil::openJsonFileToObject(absoluteFilePath)) {
@ -189,15 +185,12 @@ void InstalledListModel::loadInstalledContent()
if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString())) { if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString())) {
if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString(), Qt::CaseInsensitive)) { if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString(), Qt::CaseInsensitive)) {
append(*obj, item.baseName(),isNew); append(*obj, item.baseName(), isNew, item.lastModified());
} }
counter += 1; counter += 1;
} }
} }
} }
setCount(counter); setCount(counter);
emit installedLoadingFinished(); emit installedLoadingFinished();
@ -225,6 +218,7 @@ QVariantMap InstalledListModel::get(const QString& folderId) const
map.insert("m_absoluteStoragePath", m_screenPlayFiles[i].m_absoluteStoragePath); map.insert("m_absoluteStoragePath", m_screenPlayFiles[i].m_absoluteStoragePath);
map.insert("m_publishedFileID", m_screenPlayFiles[i].m_publishedFileID); map.insert("m_publishedFileID", m_screenPlayFiles[i].m_publishedFileID);
map.insert("m_isNew", m_screenPlayFiles[i].m_isNew); map.insert("m_isNew", m_screenPlayFiles[i].m_isNew);
map.insert("m_lastModified", m_screenPlayFiles[i].m_lastModified);
return map; return map;
} }
} }

View File

@ -102,7 +102,7 @@ public slots:
QVariantMap get(const QString& folderId) const; QVariantMap get(const QString& folderId) const;
void loadInstalledContent(); void loadInstalledContent();
void append(const QJsonObject&, const QString&,const bool isNew); void append(const QJsonObject&, const QString&, const bool isNew, const QDateTime& lastModified);
void reset(); void reset();
void init(); void init();
bool deinstallItemAt(const int index); bool deinstallItemAt(const int index);

View File

@ -34,6 +34,7 @@
#pragma once #pragma once
#include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
@ -42,7 +43,6 @@
#include <QUrl> #include <QUrl>
#include <QVariant> #include <QVariant>
#include <QVariantList> #include <QVariantList>
#include <QDateTime>
#include "ScreenPlayUtil/util.h" #include "ScreenPlayUtil/util.h"
@ -59,7 +59,8 @@ struct ProjectFile {
const QJsonObject& obj, const QJsonObject& obj,
const QString& folderName, const QString& folderName,
const QUrl& absolutePath, const QUrl& absolutePath,
const bool isNew) const bool isNew,
const QDateTime& lastModified)
{ {
if (obj.contains("description")) if (obj.contains("description"))
@ -101,8 +102,6 @@ struct ProjectFile {
m_folderId = folderName; m_folderId = folderName;
if (!obj.contains("type")) if (!obj.contains("type"))
return; return;
@ -118,6 +117,7 @@ struct ProjectFile {
} }
m_searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(m_type); m_searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(m_type);
m_isNew = isNew; m_isNew = isNew;
m_lastModified = lastModified;
} }
ProjectFile() { } ProjectFile() { }
@ -139,5 +139,6 @@ struct ProjectFile {
InstalledType::InstalledType m_type = InstalledType::InstalledType::Unknown; InstalledType::InstalledType m_type = InstalledType::InstalledType::Unknown;
SearchType::SearchType m_searchType = SearchType::SearchType::All; SearchType::SearchType m_searchType = SearchType::SearchType::All;
bool m_isNew = false; bool m_isNew = false;
QDateTime m_lastModified;
}; };
} }

View File

@ -82,7 +82,7 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
void InstalledListModel::append(const QJsonObject& obj, const QString& folderName, const QDateTime& lastModified) void InstalledListModel::append(const QJsonObject& obj, const QString& folderName, const QDateTime& lastModified)
{ {
beginInsertRows(QModelIndex(), m_screenPlayFiles.size(), m_screenPlayFiles.size()); beginInsertRows(QModelIndex(), m_screenPlayFiles.size(), m_screenPlayFiles.size());
m_screenPlayFiles.append(ScreenPlay::ProjectFile(obj, folderName, m_absoluteStoragePath, lastModified)); m_screenPlayFiles.append(ScreenPlay::ProjectFile(obj, folderName, m_absoluteStoragePath, false, lastModified));
endInsertRows(); endInsertRows();
} }