1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2026 Project Tick
// SPDX-FileContributor: Project Tick Team
/*
* ProjT Launcher - Minecraft Launcher
* Copyright (C) 2026 Project Tick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* === Upstream License Block (Do Not Modify) ==============================
*
*
*
*
*
*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
*
* ======================================================================== */
#include "UpdaterDialogs.h"
#include "ui_SelectReleaseDialog.h"
#include <QPushButton>
#include <QTextBrowser>
#include "Markdown.h"
#include "StringUtils.h"
SelectReleaseDialog::SelectReleaseDialog(const Version& current_version,
const QList<ReleaseInfo>& releases,
QWidget* parent)
: QDialog(parent),
m_releases(releases),
m_currentVersion(current_version),
ui(new Ui::SelectReleaseDialog)
{
ui->setupUi(this);
ui->changelogTextBrowser->setOpenExternalLinks(true);
ui->changelogTextBrowser->setLineWrapMode(QTextBrowser::LineWrapMode::WidgetWidth);
ui->changelogTextBrowser->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
ui->versionsTree->setColumnCount(2);
ui->versionsTree->header()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->versionsTree->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
ui->versionsTree->setHeaderLabels({ tr("Version"), tr("Published Date") });
ui->versionsTree->header()->setStretchLastSection(false);
ui->eplainLabel->setText(tr("Select a version to install.\n"
"\n"
"Currently installed version: %1")
.arg(m_currentVersion.toString()));
loadReleases();
connect(ui->versionsTree, &QTreeWidget::currentItemChanged, this, &SelectReleaseDialog::selectionChanged);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SelectReleaseDialog::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &SelectReleaseDialog::reject);
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK"));
}
SelectReleaseDialog::~SelectReleaseDialog()
{
delete ui;
}
void SelectReleaseDialog::loadReleases()
{
for (auto rls : m_releases)
{
appendRelease(rls);
}
}
void SelectReleaseDialog::appendRelease(ReleaseInfo const& release)
{
auto rls_item = new QTreeWidgetItem(ui->versionsTree);
rls_item->setText(0, release.tag_name);
rls_item->setExpanded(true);
rls_item->setText(1, release.published_at.toString());
rls_item->setData(0, Qt::UserRole, QVariant(release.tag_name));
ui->versionsTree->addTopLevelItem(rls_item);
}
ReleaseInfo SelectReleaseDialog::getRelease(QTreeWidgetItem* item)
{
auto tag_name = item->data(0, Qt::UserRole).toString();
ReleaseInfo release;
for (auto rls : m_releases)
{
if (rls.tag_name == tag_name)
release = rls;
}
return release;
}
void SelectReleaseDialog::selectionChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous)
{
Q_UNUSED(previous)
ReleaseInfo release = getRelease(current);
QString body = markdownToHTML(release.body.toUtf8());
m_selectedRelease = release;
ui->changelogTextBrowser->setHtml(StringUtils::htmlListPatch(body));
}
SelectReleaseAssetDialog::SelectReleaseAssetDialog(const QList<ReleaseAsset>& assets, QWidget* parent)
: QDialog(parent),
m_assets(assets),
ui(new Ui::SelectReleaseDialog)
{
ui->setupUi(this);
ui->changelogTextBrowser->setOpenExternalLinks(true);
ui->changelogTextBrowser->setLineWrapMode(QTextBrowser::LineWrapMode::WidgetWidth);
ui->changelogTextBrowser->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
ui->versionsTree->setColumnCount(2);
ui->versionsTree->header()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->versionsTree->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
ui->versionsTree->setHeaderLabels({ tr("Version"), tr("Published Date") });
ui->versionsTree->header()->setStretchLastSection(false);
ui->eplainLabel->setText(tr("Select a version to install."));
ui->changelogTextBrowser->setHidden(true);
loadAssets();
connect(ui->versionsTree, &QTreeWidget::currentItemChanged, this, &SelectReleaseAssetDialog::selectionChanged);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SelectReleaseAssetDialog::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &SelectReleaseAssetDialog::reject);
}
SelectReleaseAssetDialog::~SelectReleaseAssetDialog()
{
delete ui;
}
void SelectReleaseAssetDialog::loadAssets()
{
for (auto rls : m_assets)
{
appendAsset(rls);
}
}
void SelectReleaseAssetDialog::appendAsset(ReleaseAsset const& asset)
{
auto rls_item = new QTreeWidgetItem(ui->versionsTree);
rls_item->setText(0, asset.name);
rls_item->setExpanded(true);
rls_item->setText(1, asset.updated_at.toString());
rls_item->setData(0, Qt::UserRole, QVariant(asset.download_url.toString()));
ui->versionsTree->addTopLevelItem(rls_item);
}
ReleaseAsset SelectReleaseAssetDialog::getAsset(QTreeWidgetItem* item)
{
auto asset_url = item->data(0, Qt::UserRole).toString();
ReleaseAsset selected_asset;
for (auto asset : m_assets)
{
if (asset.download_url.toString() == asset_url)
selected_asset = asset;
}
return selected_asset;
}
void SelectReleaseAssetDialog::selectionChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous)
{
Q_UNUSED(previous)
ReleaseAsset asset = getAsset(current);
m_selectedAsset = asset;
}
|