Changelog System
This commit is contained in:
95
src/noggit/ui/windows/changelog/Changelog.cpp
Normal file
95
src/noggit/ui/windows/changelog/Changelog.cpp
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
30
src/noggit/ui/windows/changelog/Changelog.hpp
Normal file
30
src/noggit/ui/windows/changelog/Changelog.hpp
Normal 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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
71
src/noggit/ui/windows/changelog/Changelog.ui
Normal file
71
src/noggit/ui/windows/changelog/Changelog.ui
Normal 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>
|
||||
@@ -30,12 +30,18 @@ NoggitProjectSelectionWindow::NoggitProjectSelectionWindow(Noggit::Application::
|
||||
_ui->label_2->setStyleSheet("QLabel#title { font-size: 18px; padding: 0px; }");
|
||||
|
||||
_settings = new Noggit::Ui::settings(this);
|
||||
_changelog = new Noggit::Ui::CChangelog(this);
|
||||
|
||||
_load_project_component = std::make_unique<Component::LoadProjectComponent>();
|
||||
|
||||
_ui->settings_button->setIcon(Noggit::Ui::FontAwesomeIcon(Noggit::Ui::FontAwesome::Icons::cog));
|
||||
_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);
|
||||
|
||||
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]
|
||||
{
|
||||
ProjectInformation project_reference;
|
||||
@@ -129,8 +141,8 @@ NoggitProjectSelectionWindow::NoggitProjectSelectionWindow(Noggit::Application::
|
||||
}
|
||||
);
|
||||
|
||||
// disable-update
|
||||
if (!_noggit_application->GetCommand(0))
|
||||
// !disable-update && !force-changelog
|
||||
if (!_noggit_application->GetCommand(0) && !_noggit_application->GetCommand(1))
|
||||
{
|
||||
_updater = new Noggit::Ui::CUpdater(this);
|
||||
|
||||
@@ -141,10 +153,20 @@ NoggitProjectSelectionWindow::NoggitProjectSelectionWindow(Noggit::Application::
|
||||
});
|
||||
}
|
||||
|
||||
// force-changelog
|
||||
if (_noggit_application->GetCommand(1))
|
||||
{
|
||||
auto _set = new QSettings(this);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
#include <qgraphicseffect.h>
|
||||
#include <QString>
|
||||
#include <QToolButton>
|
||||
#include <QSettings>
|
||||
#include <noggit/application/NoggitApplication.hpp>
|
||||
#include <noggit/ui/windows/noggitWindow/NoggitWindow.hpp>
|
||||
#include <noggit/ui/windows/projectCreation/NoggitProjectCreationDialog.h>
|
||||
#include <noggit/ui/windows/settingsPanel/SettingsPanel.h>
|
||||
#include <noggit/ui/windows/updater/Updater.h>
|
||||
#include <noggit/ui/windows/changelog/Changelog.hpp>
|
||||
#include <ui_NoggitProjectSelectionWindow.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@@ -47,6 +49,7 @@ namespace Noggit::Ui::Windows
|
||||
Noggit::Application::NoggitApplication* _noggit_application;
|
||||
Noggit::Ui::settings* _settings;
|
||||
Noggit::Ui::CUpdater* _updater;
|
||||
Noggit::Ui::CChangelog* _changelog;
|
||||
|
||||
std::unique_ptr<Noggit::Ui::Windows::NoggitWindow> _project_selection_page;
|
||||
std::unique_ptr<Component::LoadProjectComponent> _load_project_component;
|
||||
|
||||
@@ -243,6 +243,13 @@
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QToolButton" name="changelog_button">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
|
||||
Reference in New Issue
Block a user