mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-22 02:32:29 +01:00
Add sort by date for installed content
This commit is contained in:
parent
7fbbbf31f2
commit
6549530258
@ -135,5 +135,7 @@
|
||||
<file>translations/ScreenPlay_zh_cn.qm</file>
|
||||
<file>assets/images/Early_Access.png</file>
|
||||
<file>translations/ScreenPlay_pt_br.qm</file>
|
||||
<file>assets/icons/icon_sort-up-solid.svg</file>
|
||||
<file>assets/icons/icon_sort-down-solid.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
8
ScreenPlay/assets/icons/icon_sort-down-solid.svg
Normal file
8
ScreenPlay/assets/icons/icon_sort-down-solid.svg
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="100%" height="100%" viewBox="0 0 320 320" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||
<g id="ArtBoard1" transform="matrix(1,0,0,1,0,-192)">
|
||||
<rect x="0" y="192" width="320" height="320" style="fill:none;"/>
|
||||
<path d="M41,288L279,288C300.4,288 311.1,313.9 296,329L177,448C167.6,457.4 152.4,457.4 143.1,448L24,329C8.9,313.9 19.6,288 41,288Z" style="fill-rule:nonzero;"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 762 B |
8
ScreenPlay/assets/icons/icon_sort-up-solid.svg
Normal file
8
ScreenPlay/assets/icons/icon_sort-up-solid.svg
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="100%" height="100%" viewBox="0 0 320 320" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||
<rect id="ArtBoard1" x="0" y="0" width="320" height="320" style="fill:none;"/>
|
||||
<g id="ArtBoard11" serif:id="ArtBoard1">
|
||||
<path d="M279,224L41,224C19.6,224 8.9,198.1 24,183L143,64C152.4,54.6 167.6,54.6 176.9,64L295.9,183C311.1,198.1 300.4,224 279,224Z" style="fill-rule:nonzero;"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 757 B |
@ -122,11 +122,38 @@ Item {
|
||||
Common.Search {
|
||||
height: parent.height
|
||||
anchors {
|
||||
right: parent.right
|
||||
rightMargin: 30
|
||||
right: btnSortOrder.left
|
||||
rightMargin: 10
|
||||
top: parent.top
|
||||
}
|
||||
}
|
||||
|
||||
ToolButton {
|
||||
id: btnSortOrder
|
||||
property int sortOrder: Qt.DescendingOrder
|
||||
onClicked: {
|
||||
sortOrder = (sortOrder
|
||||
=== Qt.DescendingOrder) ? Qt.AscendingOrder : Qt.DescendingOrder
|
||||
ScreenPlay.installedListFilter.setSortOrder(sortOrder)
|
||||
}
|
||||
|
||||
icon.source: (sortOrder === Qt.AscendingOrder) ? "qrc:/assets/icons/icon_sort-down-solid.svg" : "qrc:/assets/icons/icon_sort-up-solid.svg"
|
||||
icon.width: 12
|
||||
icon.height: 12
|
||||
anchors {
|
||||
right: parent.right
|
||||
rightMargin: 10
|
||||
top: parent.top
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
hoverEnabled: true
|
||||
|
||||
ToolTip.delay: 100
|
||||
ToolTip.timeout: 5000
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: (sortOrder === Qt.AscendingOrder) ? qsTr("Install Date Ascending") : qsTr(
|
||||
"Install Date Descending")
|
||||
}
|
||||
}
|
||||
|
||||
states: [
|
||||
|
@ -143,7 +143,7 @@ Item {
|
||||
id: screenPlayItemImage
|
||||
anchors.fill: parent
|
||||
enabled: visible
|
||||
visible: m_preview !== "" && m_previewGIF !== ""
|
||||
visible: m_preview !== "" || m_previewGIF !== ""
|
||||
sourceImage: m_preview
|
||||
sourceImageGIF: m_previewGIF
|
||||
type: root.type
|
||||
|
@ -20,6 +20,9 @@ InstalledListFilter::InstalledListFilter(const std::shared_ptr<InstalledListMode
|
||||
{
|
||||
setSourceModel(m_ilm.get());
|
||||
setFilterRole(static_cast<int>(InstalledListModel::ScreenPlayItem::Title));
|
||||
setSortRole(static_cast<int>(InstalledListModel::ScreenPlayItem::LastModified));
|
||||
sort(0, m_sortOrder);
|
||||
emit sortChanged();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -31,12 +34,17 @@ void InstalledListFilter::sortByName(const QString& name)
|
||||
setFilterRole(static_cast<int>(InstalledListModel::ScreenPlayItem::Title));
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
setFilterFixedString(name);
|
||||
sort(0);
|
||||
sort(0, m_sortOrder);
|
||||
emit sortChanged();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief .
|
||||
\brief Sort by:
|
||||
All,
|
||||
Text,
|
||||
Scene, //QML, HTML, Godot, Gif, Website wallpaper
|
||||
Wallpaper,
|
||||
Widget,
|
||||
*/
|
||||
void InstalledListFilter::sortBySearchType(const ScreenPlay::SearchType::SearchType searchType)
|
||||
{
|
||||
@ -47,7 +55,17 @@ void InstalledListFilter::sortBySearchType(const ScreenPlay::SearchType::SearchT
|
||||
}
|
||||
setFilterRole(static_cast<int>(InstalledListModel::ScreenPlayItem::SearchType));
|
||||
setFilterFixedString(QVariant::fromValue(searchType).toString());
|
||||
sort(0);
|
||||
sort(0, m_sortOrder);
|
||||
emit sortChanged();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief sets the sort order by date.
|
||||
*/
|
||||
void InstalledListFilter::setSortOrder(const Qt::SortOrder sortOrder)
|
||||
{
|
||||
m_sortOrder = sortOrder;
|
||||
sort(0, m_sortOrder);
|
||||
emit sortChanged();
|
||||
}
|
||||
|
||||
@ -58,7 +76,7 @@ void InstalledListFilter::resetFilter()
|
||||
{
|
||||
setFilterRole(static_cast<int>(InstalledListModel::ScreenPlayItem::Title));
|
||||
setFilterWildcard("*");
|
||||
sort(0);
|
||||
sort(0, m_sortOrder);
|
||||
emit sortChanged();
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void sortBySearchType(const ScreenPlay::SearchType::SearchType searchType);
|
||||
void setSortOrder(const Qt::SortOrder sortOrder);
|
||||
void sortByName(const QString& name);
|
||||
void resetFilter();
|
||||
|
||||
@ -60,5 +61,6 @@ signals:
|
||||
private:
|
||||
const std::shared_ptr<InstalledListModel> m_ilm;
|
||||
ScreenPlay::SearchType::SearchType m_searchType = ScreenPlay::SearchType::SearchType::All;
|
||||
Qt::SortOrder m_sortOrder = Qt::SortOrder::DescendingOrder;
|
||||
};
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ InstalledListModel::InstalledListModel(
|
||||
: QAbstractListModel(parent)
|
||||
, m_globalVariables { globalVariables }
|
||||
{
|
||||
QObject::connect(this, &InstalledListModel::addInstalledItem,
|
||||
this, &InstalledListModel::append, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -34,8 +32,6 @@ void InstalledListModel::init()
|
||||
qWarning() << "Could not setup file system watcher for changed files with path: " << m_globalVariables->localStoragePath().toLocalFile();
|
||||
}
|
||||
|
||||
loadInstalledContent();
|
||||
|
||||
auto reloadLambda = [this]() {
|
||||
QTimer::singleShot(500, [this]() {
|
||||
reset();
|
||||
@ -47,7 +43,8 @@ void InstalledListModel::init()
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief .
|
||||
\brief Deleted the item from the local storage and removes it from the
|
||||
installed list.
|
||||
*/
|
||||
bool InstalledListModel::deinstallItemAt(const int index)
|
||||
{
|
||||
@ -114,6 +111,8 @@ QVariant InstalledListModel::data(const QModelIndex& index, int role) const
|
||||
return m_screenPlayFiles.at(row).m_publishedFileID;
|
||||
case static_cast<int>(ScreenPlayItem::Tags):
|
||||
return m_screenPlayFiles.at(row).m_tags;
|
||||
case static_cast<int>(ScreenPlayItem::LastModified):
|
||||
return m_screenPlayFiles.at(row).m_lastModified;
|
||||
case static_cast<int>(ScreenPlayItem::SearchType):
|
||||
return QVariant::fromValue(m_screenPlayFiles.at(row).m_searchType);
|
||||
default:
|
||||
@ -138,33 +137,32 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
|
||||
{ static_cast<int>(ScreenPlayItem::PublishedFileID), "m_publishedFileID" },
|
||||
{ static_cast<int>(ScreenPlayItem::Tags), "m_tags" },
|
||||
{ static_cast<int>(ScreenPlayItem::SearchType), "m_searchType" },
|
||||
{ static_cast<int>(ScreenPlayItem::LastModified), "m_lastModified" },
|
||||
};
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief .
|
||||
\brief Append an ProjectFile to the list.
|
||||
*/
|
||||
void InstalledListModel::append(const QJsonObject& obj, const QString& folderName)
|
||||
void InstalledListModel::append(const QJsonObject& obj, const QString& folderName, const QDateTime& lastModified)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_screenPlayFiles.size(), m_screenPlayFiles.size());
|
||||
m_screenPlayFiles.append(ProjectFile(obj, folderName, m_globalVariables->localStoragePath()));
|
||||
m_screenPlayFiles.append(ProjectFile(obj, folderName, m_globalVariables->localStoragePath(), lastModified));
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief .
|
||||
\brief Loads all installed content. Skips projects.json without a "type" field.
|
||||
*/
|
||||
void InstalledListModel::loadInstalledContent()
|
||||
{
|
||||
QtConcurrent::run([this]() {
|
||||
QFileInfoList list = QDir(m_globalVariables->localStoragePath().toLocalFile()).entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs);
|
||||
QString projectItemPath;
|
||||
int counter = 0;
|
||||
|
||||
for (const auto& item : list) {
|
||||
projectItemPath = m_globalVariables->localStoragePath().toLocalFile() + "/" + item.baseName() + "/project.json";
|
||||
|
||||
if (auto obj = ScreenPlayUtil::openJsonFileToObject(projectItemPath)) {
|
||||
if (auto obj = ScreenPlayUtil::openJsonFileToObject(m_globalVariables->localStoragePath().toLocalFile() + "/" + item.baseName() + "/project.json")) {
|
||||
|
||||
if (obj->isEmpty())
|
||||
continue;
|
||||
@ -172,9 +170,10 @@ void InstalledListModel::loadInstalledContent()
|
||||
if (!obj->contains("type"))
|
||||
continue;
|
||||
|
||||
|
||||
if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString())) {
|
||||
if (ScreenPlayUtil::getAvailableTypes().contains(obj->value("type").toString(), Qt::CaseInsensitive)) {
|
||||
emit addInstalledItem(*obj, item.baseName());
|
||||
append(*obj, item.baseName(), item.lastModified());
|
||||
}
|
||||
|
||||
counter += 1;
|
||||
@ -206,6 +205,7 @@ QVariantMap InstalledListModel::get(const QString& folderId) const
|
||||
map.insert("m_type", QVariant::fromValue(m_screenPlayFiles[i].m_type));
|
||||
map.insert("m_absoluteStoragePath", m_screenPlayFiles[i].m_absoluteStoragePath);
|
||||
map.insert("m_publishedFileID", m_screenPlayFiles[i].m_publishedFileID);
|
||||
map.insert("m_lastModified", m_screenPlayFiles[i].m_lastModified);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QByteArray>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
@ -53,9 +54,9 @@
|
||||
#include <QVector>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include "ScreenPlayUtil/projectfile.h"
|
||||
#include "globalvariables.h"
|
||||
#include "profilelistmodel.h"
|
||||
#include "ScreenPlayUtil/projectfile.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <memory>
|
||||
@ -87,6 +88,7 @@ public:
|
||||
PublishedFileID,
|
||||
Tags,
|
||||
SearchType,
|
||||
LastModified,
|
||||
};
|
||||
Q_ENUM(ScreenPlayItem)
|
||||
|
||||
@ -99,7 +101,7 @@ public slots:
|
||||
QVariantMap get(const QString& folderId) const;
|
||||
|
||||
void loadInstalledContent();
|
||||
void append(const QJsonObject&, const QString&);
|
||||
void append(const QJsonObject&, const QString&, const QDateTime& lastModified);
|
||||
void reset();
|
||||
void init();
|
||||
bool deinstallItemAt(const int index);
|
||||
@ -114,7 +116,6 @@ public slots:
|
||||
}
|
||||
|
||||
signals:
|
||||
void addInstalledItem(const QJsonObject, const QString);
|
||||
void installedLoadingFinished();
|
||||
void countChanged(int count);
|
||||
|
||||
|
@ -57,7 +57,8 @@ struct ProjectFile {
|
||||
ProjectFile(
|
||||
const QJsonObject& obj,
|
||||
const QString& folderName,
|
||||
const QUrl& absolutePath)
|
||||
const QUrl& absolutePath,
|
||||
const QDateTime& lastModified)
|
||||
{
|
||||
|
||||
if (obj.contains("description"))
|
||||
@ -113,6 +114,7 @@ struct ProjectFile {
|
||||
m_preview = m_previewGIF;
|
||||
}
|
||||
m_searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(m_type);
|
||||
m_lastModified = lastModified;
|
||||
}
|
||||
|
||||
ProjectFile() { }
|
||||
@ -133,5 +135,6 @@ struct ProjectFile {
|
||||
|
||||
InstalledType::InstalledType m_type = InstalledType::InstalledType::Unknown;
|
||||
SearchType::SearchType m_searchType = SearchType::SearchType::All;
|
||||
QDateTime m_lastModified;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user