mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-22 04:37:46 +00:00
Add options for hiding news list or banners
This commit is contained in:
parent
56710be2ff
commit
9ed269c697
6 changed files with 123 additions and 59 deletions
|
@ -81,6 +81,8 @@ struct ProfileSettings {
|
||||||
|
|
||||||
struct AppSettings {
|
struct AppSettings {
|
||||||
bool closeWhenLaunched = true;
|
bool closeWhenLaunched = true;
|
||||||
|
bool showBanners = true;
|
||||||
|
bool showNewsList = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LoginInformation {
|
struct LoginInformation {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
|
#include <QGridLayout>
|
||||||
|
|
||||||
#include "launchercore.h"
|
#include "launchercore.h"
|
||||||
#include "headline.h"
|
#include "headline.h"
|
||||||
|
@ -29,6 +30,8 @@ private:
|
||||||
|
|
||||||
bool currentlyReloadingControls = false;
|
bool currentlyReloadingControls = false;
|
||||||
|
|
||||||
|
QGridLayout* layout;
|
||||||
|
|
||||||
QLabel* bannerImageView;
|
QLabel* bannerImageView;
|
||||||
QTreeWidget* newsListView;
|
QTreeWidget* newsListView;
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ private:
|
||||||
|
|
||||||
// general
|
// general
|
||||||
QCheckBox* closeWhenLaunched = nullptr;
|
QCheckBox* closeWhenLaunched = nullptr;
|
||||||
|
QCheckBox* showBanner = nullptr;
|
||||||
|
QCheckBox* showNewsList = nullptr;
|
||||||
|
|
||||||
// game
|
// game
|
||||||
QLineEdit* nameEdit = nullptr;
|
QLineEdit* nameEdit = nullptr;
|
||||||
|
|
|
@ -278,7 +278,10 @@ QString LauncherCore::readVersion(QString path) {
|
||||||
void LauncherCore::readInitialInformation() {
|
void LauncherCore::readInitialInformation() {
|
||||||
defaultProfileIndex = settings.value("defaultProfile", 0).toInt();
|
defaultProfileIndex = settings.value("defaultProfile", 0).toInt();
|
||||||
|
|
||||||
appSettings.closeWhenLaunched = settings.value("closeWhenLaunched", true).toBool();
|
auto defaultAppSettings = AppSettings();
|
||||||
|
appSettings.closeWhenLaunched = settings.value("closeWhenLaunched", defaultAppSettings.closeWhenLaunched).toBool();
|
||||||
|
appSettings.showBanners = settings.value("showBanners", defaultAppSettings.showBanners).toBool();
|
||||||
|
appSettings.showNewsList = settings.value("showNewsList", defaultAppSettings.showNewsList).toBool();
|
||||||
|
|
||||||
gamescopeAvailable = checkIfInPath("gamescope");
|
gamescopeAvailable = checkIfInPath("gamescope");
|
||||||
gamemodeAvailable = checkIfInPath("gamemoderun");
|
gamemodeAvailable = checkIfInPath("gamemoderun");
|
||||||
|
@ -549,6 +552,8 @@ int LauncherCore::deleteProfile(QString name) {
|
||||||
void LauncherCore::saveSettings() {
|
void LauncherCore::saveSettings() {
|
||||||
settings.setValue("defaultProfile", defaultProfileIndex);
|
settings.setValue("defaultProfile", defaultProfileIndex);
|
||||||
settings.setValue("closeWhenLaunched", appSettings.closeWhenLaunched);
|
settings.setValue("closeWhenLaunched", appSettings.closeWhenLaunched);
|
||||||
|
settings.setValue("showBanners", appSettings.showBanners);
|
||||||
|
settings.setValue("showNewsList", appSettings.showNewsList);
|
||||||
|
|
||||||
for(int i = 0; i < profileSettings.size(); i++) {
|
for(int i = 0; i < profileSettings.size(); i++) {
|
||||||
const auto& profile = profileSettings[i];
|
const auto& profile = profileSettings[i];
|
||||||
|
|
|
@ -95,10 +95,9 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo
|
||||||
QMessageBox::aboutQt(this);
|
QMessageBox::aboutQt(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
auto layout = new QGridLayout();
|
layout = new QGridLayout();
|
||||||
|
|
||||||
bannerImageView = new QLabel();
|
bannerImageView = new QLabel();
|
||||||
layout->addWidget(bannerImageView, 0, 0);
|
|
||||||
|
|
||||||
newsListView = new QTreeWidget();
|
newsListView = new QTreeWidget();
|
||||||
newsListView->setColumnCount(2);
|
newsListView->setColumnCount(2);
|
||||||
|
@ -110,7 +109,6 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo
|
||||||
qInfo() << "clicked" << url;
|
qInfo() << "clicked" << url;
|
||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
});
|
});
|
||||||
layout->addWidget(newsListView, 1, 0);
|
|
||||||
|
|
||||||
auto loginLayout = new QFormLayout();
|
auto loginLayout = new QFormLayout();
|
||||||
layout->addLayout(loginLayout, 0, 1, 1, 1);
|
layout->addLayout(loginLayout, 0, 1, 1, 1);
|
||||||
|
@ -206,61 +204,6 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo
|
||||||
});
|
});
|
||||||
|
|
||||||
reloadControls();
|
reloadControls();
|
||||||
|
|
||||||
getHeadline(core, [&](Headline headline) {
|
|
||||||
this->headline = headline;
|
|
||||||
|
|
||||||
if(!headline.banner.empty()) {
|
|
||||||
auto request = QNetworkRequest(headline.banner[0].bannerImage);
|
|
||||||
core.buildRequest(currentProfile(), request);
|
|
||||||
|
|
||||||
auto reply = core.mgr->get(request);
|
|
||||||
connect(reply, &QNetworkReply::finished, [=] {
|
|
||||||
QPixmap pixmap;
|
|
||||||
pixmap.loadFromData(reply->readAll());
|
|
||||||
bannerImageView->setPixmap(pixmap);
|
|
||||||
});
|
|
||||||
|
|
||||||
QTreeWidgetItem* newsItem = new QTreeWidgetItem((QTreeWidgetItem*)nullptr, QStringList("News"));
|
|
||||||
for(auto news : headline.news) {
|
|
||||||
QTreeWidgetItem* item = new QTreeWidgetItem();
|
|
||||||
item->setText(0, news.title);
|
|
||||||
item->setText(1, QLocale().toString(news.date, QLocale::ShortFormat));
|
|
||||||
item->setData(0, Qt::UserRole, news.url);
|
|
||||||
|
|
||||||
newsItem->addChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
QTreeWidgetItem* pinnedItem = new QTreeWidgetItem((QTreeWidgetItem*)nullptr, QStringList("Pinned"));
|
|
||||||
for(auto pinned : headline.pinned) {
|
|
||||||
QTreeWidgetItem* item = new QTreeWidgetItem();
|
|
||||||
item->setText(0, pinned.title);
|
|
||||||
item->setText(1, QLocale().toString(pinned.date, QLocale::ShortFormat));
|
|
||||||
item->setData(0, Qt::UserRole, pinned.url);
|
|
||||||
|
|
||||||
pinnedItem->addChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
QTreeWidgetItem* topicsItem = new QTreeWidgetItem((QTreeWidgetItem*)nullptr, QStringList("Topics"));
|
|
||||||
for(auto news : headline.topics) {
|
|
||||||
QTreeWidgetItem* item = new QTreeWidgetItem();
|
|
||||||
item->setText(0, news.title);
|
|
||||||
item->setText(1, QLocale().toString(news.date, QLocale::ShortFormat));
|
|
||||||
item->setData(0, Qt::UserRole, news.url);
|
|
||||||
|
|
||||||
qInfo() << news.url;
|
|
||||||
|
|
||||||
topicsItem->addChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
newsListView->insertTopLevelItems(0, QList<QTreeWidgetItem*>({newsItem, pinnedItem, topicsItem}));
|
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
|
||||||
newsListView->expandItem(newsListView->topLevelItem(i));
|
|
||||||
newsListView->resizeColumnToContents(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileSettings LauncherWindow::currentProfile() const {
|
ProfileSettings LauncherWindow::currentProfile() const {
|
||||||
|
@ -344,6 +287,95 @@ void LauncherWindow::reloadControls() {
|
||||||
wineCfg->setEnabled(currentProfile().isWineInstalled());
|
wineCfg->setEnabled(currentProfile().isWineInstalled());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
layout->removeWidget(bannerImageView);
|
||||||
|
bannerImageView->hide();
|
||||||
|
layout->removeWidget(newsListView);
|
||||||
|
newsListView->hide();
|
||||||
|
|
||||||
|
if(core.appSettings.showBanners || core.appSettings.showNewsList) {
|
||||||
|
int totalRow = 0;
|
||||||
|
if(core.appSettings.showBanners) {
|
||||||
|
bannerImageView->show();
|
||||||
|
layout->addWidget(bannerImageView, totalRow++, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(core.appSettings.showNewsList) {
|
||||||
|
newsListView->show();
|
||||||
|
layout->addWidget(newsListView, totalRow++, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
newsListView->clear();
|
||||||
|
|
||||||
|
getHeadline(core, [&](Headline headline) {
|
||||||
|
this->headline = headline;
|
||||||
|
|
||||||
|
if (!headline.banner.empty()) {
|
||||||
|
if(core.appSettings.showBanners) {
|
||||||
|
auto request =
|
||||||
|
QNetworkRequest(headline.banner[0].bannerImage);
|
||||||
|
core.buildRequest(currentProfile(), request);
|
||||||
|
|
||||||
|
auto reply = core.mgr->get(request);
|
||||||
|
connect(reply, &QNetworkReply::finished, [=] {
|
||||||
|
QPixmap pixmap;
|
||||||
|
pixmap.loadFromData(reply->readAll());
|
||||||
|
bannerImageView->setPixmap(pixmap);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(core.appSettings.showNewsList) {
|
||||||
|
QTreeWidgetItem* newsItem = new QTreeWidgetItem(
|
||||||
|
(QTreeWidgetItem*)nullptr, QStringList("News"));
|
||||||
|
for (auto news : headline.news) {
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
||||||
|
item->setText(0, news.title);
|
||||||
|
item->setText(1, QLocale().toString(
|
||||||
|
news.date, QLocale::ShortFormat));
|
||||||
|
item->setData(0, Qt::UserRole, news.url);
|
||||||
|
|
||||||
|
newsItem->addChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTreeWidgetItem* pinnedItem = new QTreeWidgetItem(
|
||||||
|
(QTreeWidgetItem*)nullptr, QStringList("Pinned"));
|
||||||
|
for (auto pinned : headline.pinned) {
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
||||||
|
item->setText(0, pinned.title);
|
||||||
|
item->setText(1,
|
||||||
|
QLocale().toString(pinned.date,
|
||||||
|
QLocale::ShortFormat));
|
||||||
|
item->setData(0, Qt::UserRole, pinned.url);
|
||||||
|
|
||||||
|
pinnedItem->addChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTreeWidgetItem* topicsItem = new QTreeWidgetItem(
|
||||||
|
(QTreeWidgetItem*)nullptr, QStringList("Topics"));
|
||||||
|
for (auto news : headline.topics) {
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
||||||
|
item->setText(0, news.title);
|
||||||
|
item->setText(1, QLocale().toString(
|
||||||
|
news.date, QLocale::ShortFormat));
|
||||||
|
item->setData(0, Qt::UserRole, news.url);
|
||||||
|
|
||||||
|
qInfo() << news.url;
|
||||||
|
|
||||||
|
topicsItem->addChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
newsListView->insertTopLevelItems(
|
||||||
|
0, QList<QTreeWidgetItem*>(
|
||||||
|
{newsItem, pinnedItem, topicsItem}));
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
newsListView->expandItem(newsListView->topLevelItem(i));
|
||||||
|
newsListView->resizeColumnToContents(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
currentlyReloadingControls = false;
|
currentlyReloadingControls = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,24 @@ SettingsWindow::SettingsWindow(int defaultTab, LauncherWindow& window, LauncherC
|
||||||
core.saveSettings();
|
core.saveSettings();
|
||||||
});
|
});
|
||||||
layout->addWidget(closeWhenLaunched);
|
layout->addWidget(closeWhenLaunched);
|
||||||
|
|
||||||
|
showBanner = new QCheckBox("Show news banners");
|
||||||
|
connect(showBanner, &QCheckBox::stateChanged, [&](int state) {
|
||||||
|
core.appSettings.showBanners = state;
|
||||||
|
|
||||||
|
core.saveSettings();
|
||||||
|
window.reloadControls();
|
||||||
|
});
|
||||||
|
layout->addWidget(showBanner);
|
||||||
|
|
||||||
|
showNewsList = new QCheckBox("Show news list");
|
||||||
|
connect(showNewsList, &QCheckBox::stateChanged, [&](int state) {
|
||||||
|
core.appSettings.showNewsList = state;
|
||||||
|
|
||||||
|
core.saveSettings();
|
||||||
|
window.reloadControls();
|
||||||
|
});
|
||||||
|
layout->addWidget(showNewsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
// profile tab
|
// profile tab
|
||||||
|
@ -409,6 +427,8 @@ void SettingsWindow::reloadControls() {
|
||||||
profileWidget->setCurrentRow(oldRow);
|
profileWidget->setCurrentRow(oldRow);
|
||||||
|
|
||||||
closeWhenLaunched->setChecked(core.appSettings.closeWhenLaunched);
|
closeWhenLaunched->setChecked(core.appSettings.closeWhenLaunched);
|
||||||
|
showBanner->setChecked(core.appSettings.showBanners);
|
||||||
|
showNewsList->setChecked(core.appSettings.showNewsList);
|
||||||
|
|
||||||
// deleting the main profile is unsupported behavior
|
// deleting the main profile is unsupported behavior
|
||||||
deleteProfileButton->setEnabled(core.profileList().size() > 1);
|
deleteProfileButton->setEnabled(core.profileList().size() > 1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue