Changelog System

This commit is contained in:
EIntemporel
2022-10-27 22:24:07 +02:00
parent 3291f0d98c
commit 97dad6775b
6 changed files with 273 additions and 45 deletions

View File

@@ -0,0 +1,95 @@
#include "Changelog.hpp"
#include <qdir.h>
#include <qtextstream.h>
#include "ui_Changelog.h"
namespace Noggit
{
namespace Ui
{
CChangelog::CChangelog(QWidget* parent) :
QDialog(parent)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
ui = new ::Ui::Changelog;
ui->setupUi(this);
QDir dir;
if (!dir.exists(QDir::currentPath() + ChangelogFolder))
dir.mkdir(QDir::currentPath() + ChangelogFolder);
QDir folder(QDir::currentPath() + ChangelogFolder);
QStringList files = folder.entryList(QStringList() << "*.changelog" << "*.CHANGELOG", QDir::Files);
foreach(QString filename, files)
{
Changelog.push_back(filename);
}
std::sort(Changelog.begin(), Changelog.end(), [](QString& a, QString& b)
{
return (a.toInt() < b.toInt());
});
for (int i = 0; i < Changelog.size(); ++i)
{
QListWidgetItem* item = new QListWidgetItem();
item->setText(GetChangelogName(Changelog[Changelog.size() - 1 - i]));
item->setData(1, Changelog[Changelog.size() - 1 - i]);
item->setTextAlignment(Qt::AlignLeft);
ui->listWidget->addItem(item);
}
SelectFirst();
connect(ui->listWidget, &QListWidget::itemClicked, [&](QListWidgetItem *item)
{
OpenChangelog(item->data(1).toString());
});
}
void CChangelog::SelectFirst()
{
if (ui->listWidget->count() > 0)
{
ui->listWidget->setCurrentRow(0);
OpenChangelog(ui->listWidget->item(0)->data(1).toString());
}
}
QString CChangelog::GetChangelogName(QString name)
{
QFile changelog = QDir::currentPath() + ChangelogFolder + "/" + name;
if (!changelog.exists())
return name;
if (changelog.open(QIODevice::ReadOnly))
{
QTextStream stream(&changelog);
QString stored = stream.readLine();
changelog.close();
if (stored.contains("<!--") && stored.contains("-->"))
{
stored.remove("<!--").remove("-->");
return stored;
}
}
return name;
}
void CChangelog::OpenChangelog(QString name)
{
QFile changelog = QDir::currentPath() + ChangelogFolder + "/" + name;
if (!changelog.exists())
return;
if (changelog.open(QIODevice::ReadOnly))
{
QTextStream stream(&changelog);
ui->textEdit->setHtml(stream.readAll());
changelog.close();
}
}
}
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include <QDialog>
#include "ui_Changelog.h"
namespace Noggit
{
namespace Ui
{
class CChangelog : public QDialog
{
Q_OBJECT
::Ui::Changelog* ui;
public:
CChangelog(QWidget* parent = nullptr);
void SelectFirst();
private:
const QString ChangelogFolder = "/changelog";
const QString AttachmentFolder = "/changelog/attachment";
QString GetChangelogName(QString name);
void OpenChangelog(QString name);
std::vector<QString> Changelog;
};
}
}

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Changelog</class>
<widget class="QDialog" name="Changelog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>804</width>
<height>402</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>402</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>804</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>ChangeLog Noggit Red</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="listWidget">
<property name="minimumSize">
<size>
<width>180</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>180</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="textEdit">
<property name="minimumSize">
<size>
<width>256</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>600</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -30,12 +30,18 @@ NoggitProjectSelectionWindow::NoggitProjectSelectionWindow(Noggit::Application::
_ui->label_2->setStyleSheet("QLabel#title { font-size: 18px; padding: 0px; }"); _ui->label_2->setStyleSheet("QLabel#title { font-size: 18px; padding: 0px; }");
_settings = new Noggit::Ui::settings(this); _settings = new Noggit::Ui::settings(this);
_changelog = new Noggit::Ui::CChangelog(this);
_load_project_component = std::make_unique<Component::LoadProjectComponent>(); _load_project_component = std::make_unique<Component::LoadProjectComponent>();
_ui->settings_button->setIcon(Noggit::Ui::FontAwesomeIcon(Noggit::Ui::FontAwesome::Icons::cog)); _ui->settings_button->setIcon(Noggit::Ui::FontAwesomeIcon(Noggit::Ui::FontAwesome::Icons::cog));
_ui->settings_button->setIconSize(QSize(20,20)); _ui->settings_button->setIconSize(QSize(20,20));
_ui->changelog_button->setIcon(Noggit::Ui::FontAwesomeIcon(Noggit::Ui::FontAwesome::Icons::file));
_ui->changelog_button->setIconSize(QSize(20, 20));
_ui->changelog_button->setText(tr(" Changelog"));
_ui->changelog_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
Component::RecentProjectsComponent::buildRecentProjectsList(this); Component::RecentProjectsComponent::buildRecentProjectsList(this);
QObject::connect(_ui->settings_button, &QToolButton::clicked, [&] QObject::connect(_ui->settings_button, &QToolButton::clicked, [&]
@@ -44,6 +50,12 @@ NoggitProjectSelectionWindow::NoggitProjectSelectionWindow(Noggit::Application::
} }
); );
QObject::connect(_ui->changelog_button, &QToolButton::clicked, [&]()
{
_changelog->SelectFirst();
_changelog->show();
});
QObject::connect(_ui->button_create_new_project, &QPushButton::clicked, [=, this] QObject::connect(_ui->button_create_new_project, &QPushButton::clicked, [=, this]
{ {
ProjectInformation project_reference; ProjectInformation project_reference;
@@ -129,8 +141,8 @@ NoggitProjectSelectionWindow::NoggitProjectSelectionWindow(Noggit::Application::
} }
); );
// disable-update // !disable-update && !force-changelog
if (!_noggit_application->GetCommand(0)) if (!_noggit_application->GetCommand(0) && !_noggit_application->GetCommand(1))
{ {
_updater = new Noggit::Ui::CUpdater(this); _updater = new Noggit::Ui::CUpdater(this);
@@ -141,10 +153,20 @@ NoggitProjectSelectionWindow::NoggitProjectSelectionWindow(Noggit::Application::
}); });
} }
// force-changelog auto _set = new QSettings(this);
if (_noggit_application->GetCommand(1)) auto first_changelog = _set->value("first_changelog", false);
{
// force-changelog
if (_noggit_application->GetCommand(1) || !first_changelog.toBool())
{
_changelog->setModal(true);
_changelog->show();
if (!first_changelog.toBool())
{
_set->setValue("first_changelog", true);
_set->sync();
}
} }
} }

View File

@@ -7,11 +7,13 @@
#include <qgraphicseffect.h> #include <qgraphicseffect.h>
#include <QString> #include <QString>
#include <QToolButton> #include <QToolButton>
#include <QSettings>
#include <noggit/application/NoggitApplication.hpp> #include <noggit/application/NoggitApplication.hpp>
#include <noggit/ui/windows/noggitWindow/NoggitWindow.hpp> #include <noggit/ui/windows/noggitWindow/NoggitWindow.hpp>
#include <noggit/ui/windows/projectCreation/NoggitProjectCreationDialog.h> #include <noggit/ui/windows/projectCreation/NoggitProjectCreationDialog.h>
#include <noggit/ui/windows/settingsPanel/SettingsPanel.h> #include <noggit/ui/windows/settingsPanel/SettingsPanel.h>
#include <noggit/ui/windows/updater/Updater.h> #include <noggit/ui/windows/updater/Updater.h>
#include <noggit/ui/windows/changelog/Changelog.hpp>
#include <ui_NoggitProjectSelectionWindow.h> #include <ui_NoggitProjectSelectionWindow.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@@ -35,7 +37,7 @@ namespace Noggit::Ui::Windows
class NoggitProjectSelectionWindow : public QMainWindow class NoggitProjectSelectionWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
friend Component::RecentProjectsComponent; friend Component::RecentProjectsComponent;
friend Component::CreateProjectComponent; friend Component::CreateProjectComponent;
friend Component::LoadProjectComponent; friend Component::LoadProjectComponent;
public: public:
@@ -47,6 +49,7 @@ namespace Noggit::Ui::Windows
Noggit::Application::NoggitApplication* _noggit_application; Noggit::Application::NoggitApplication* _noggit_application;
Noggit::Ui::settings* _settings; Noggit::Ui::settings* _settings;
Noggit::Ui::CUpdater* _updater; Noggit::Ui::CUpdater* _updater;
Noggit::Ui::CChangelog* _changelog;
std::unique_ptr<Noggit::Ui::Windows::NoggitWindow> _project_selection_page; std::unique_ptr<Noggit::Ui::Windows::NoggitWindow> _project_selection_page;
std::unique_ptr<Component::LoadProjectComponent> _load_project_component; std::unique_ptr<Component::LoadProjectComponent> _load_project_component;

View File

@@ -69,18 +69,18 @@
</item> </item>
<item> <item>
<widget class="QListWidget" name="listView"> <widget class="QListWidget" name="listView">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>380</width> <width>380</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
@@ -241,33 +241,40 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0"> <item row="6" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<spacer name="horizontalSpacer_2"> <widget class="QToolButton" name="changelog_button">
<property name="orientation"> <property name="text">
<enum>Qt::Horizontal</enum> <string>...</string>
</property> </property>
<property name="sizeType"> </widget>
<enum>QSizePolicy::Expanding</enum> </item>
</property> <item>
<property name="sizeHint" stdset="0"> <spacer name="horizontalSpacer_2">
<size> <property name="orientation">
<width>40</width> <enum>Qt::Horizontal</enum>
<height>20</height> </property>
</size> <property name="sizeType">
</property> <enum>QSizePolicy::Expanding</enum>
</spacer> </property>
</item> <property name="sizeHint" stdset="0">
<item> <size>
<widget class="QToolButton" name="settings_button"> <width>40</width>
<property name="text"> <height>20</height>
<string>...</string> </size>
</property> </property>
</widget> </spacer>
</item> </item>
</layout> <item>
</item> <widget class="QToolButton" name="settings_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>