Revert "refactor: remove news feed"
This reverts commit 361ce7818ec8891e9a35bdfac4cdea77a0b6a949.
This commit is contained in:
@ -58,6 +58,7 @@
|
||||
#include <BuildConfig.h>
|
||||
#include <net/NetJob.h>
|
||||
#include <net/Download.h>
|
||||
#include <news/NewsChecker.h>
|
||||
#include <notifications/NotificationChecker.h>
|
||||
#include <tools/BaseProfiler.h>
|
||||
#include <updater/DownloadTask.h>
|
||||
@ -200,6 +201,7 @@ public:
|
||||
//TranslatedAction actionRefresh;
|
||||
TranslatedAction actionCheckUpdate;
|
||||
TranslatedAction actionSettings;
|
||||
TranslatedAction actionMoreNews;
|
||||
TranslatedAction actionManageAccounts;
|
||||
TranslatedAction actionLaunchInstance;
|
||||
TranslatedAction actionRenameInstance;
|
||||
@ -244,6 +246,7 @@ public:
|
||||
|
||||
TranslatedToolbar mainToolBar;
|
||||
TranslatedToolbar instanceToolBar;
|
||||
TranslatedToolbar newsToolBar;
|
||||
QVector<TranslatedToolbar *> all_toolbars;
|
||||
bool m_kill = false;
|
||||
|
||||
@ -426,6 +429,29 @@ public:
|
||||
MainWindow->setStatusBar(statusBar);
|
||||
}
|
||||
|
||||
void createNewsToolbar(QMainWindow *MainWindow)
|
||||
{
|
||||
newsToolBar = TranslatedToolbar(MainWindow);
|
||||
newsToolBar->setObjectName(QStringLiteral("newsToolBar"));
|
||||
newsToolBar->setMovable(false);
|
||||
newsToolBar->setAllowedAreas(Qt::BottomToolBarArea);
|
||||
newsToolBar->setIconSize(QSize(16, 16));
|
||||
newsToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
newsToolBar->setFloatable(false);
|
||||
newsToolBar->setWindowTitle(QT_TRANSLATE_NOOP("MainWindow", "News Toolbar"));
|
||||
|
||||
actionMoreNews = TranslatedAction(MainWindow);
|
||||
actionMoreNews->setObjectName(QStringLiteral("actionMoreNews"));
|
||||
actionMoreNews->setIcon(APPLICATION->getThemedIcon("news"));
|
||||
actionMoreNews.setTextId(QT_TRANSLATE_NOOP("MainWindow", "More news..."));
|
||||
actionMoreNews.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open the development blog to read more news about %1."));
|
||||
all_actions.append(&actionMoreNews);
|
||||
newsToolBar->addAction(actionMoreNews);
|
||||
|
||||
all_toolbars.append(&newsToolBar);
|
||||
MainWindow->addToolBar(Qt::BottomToolBarArea, newsToolBar);
|
||||
}
|
||||
|
||||
void createInstanceToolbar(QMainWindow *MainWindow)
|
||||
{
|
||||
instanceToolBar = TranslatedToolbar(MainWindow);
|
||||
@ -610,6 +636,7 @@ public:
|
||||
MainWindow->setCentralWidget(centralWidget);
|
||||
|
||||
createStatusBar(MainWindow);
|
||||
createNewsToolbar(MainWindow);
|
||||
createInstanceToolbar(MainWindow);
|
||||
|
||||
retranslateUi(MainWindow);
|
||||
@ -664,6 +691,20 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
|
||||
connect(secretEventFilter, &KonamiCode::triggered, this, &MainWindow::konamiTriggered);
|
||||
}
|
||||
|
||||
// Add the news label to the news toolbar.
|
||||
{
|
||||
m_newsChecker.reset(new NewsChecker(APPLICATION->network(), BuildConfig.NEWS_RSS_URL));
|
||||
newsLabel = new QToolButton();
|
||||
newsLabel->setIcon(APPLICATION->getThemedIcon("news"));
|
||||
newsLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
newsLabel->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
newsLabel->setFocusPolicy(Qt::NoFocus);
|
||||
ui->newsToolBar->insertWidget(ui->actionMoreNews, newsLabel);
|
||||
QObject::connect(newsLabel, &QAbstractButton::clicked, this, &MainWindow::newsButtonClicked);
|
||||
QObject::connect(m_newsChecker.get(), &NewsChecker::newsLoaded, this, &MainWindow::updateNewsLabel);
|
||||
updateNewsLabel();
|
||||
}
|
||||
|
||||
// Create the instance list widget
|
||||
{
|
||||
view = new InstanceView(ui->centralWidget);
|
||||
@ -768,6 +809,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
|
||||
// TODO: refresh accounts here?
|
||||
// auto accounts = APPLICATION->accounts();
|
||||
|
||||
// load the news
|
||||
{
|
||||
m_newsChecker->reloadNews();
|
||||
updateNewsLabel();
|
||||
}
|
||||
|
||||
|
||||
if(BuildConfig.UPDATER_ENABLED)
|
||||
{
|
||||
bool updatesAllowed = APPLICATION->updatesAreAllowed();
|
||||
@ -1141,6 +1189,29 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *ev)
|
||||
return QMainWindow::eventFilter(obj, ev);
|
||||
}
|
||||
|
||||
void MainWindow::updateNewsLabel()
|
||||
{
|
||||
if (m_newsChecker->isLoadingNews())
|
||||
{
|
||||
newsLabel->setText(tr("Loading news..."));
|
||||
newsLabel->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<NewsEntryPtr> entries = m_newsChecker->getNewsEntries();
|
||||
if (entries.length() > 0)
|
||||
{
|
||||
newsLabel->setText(entries[0]->title);
|
||||
newsLabel->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
newsLabel->setText(tr("No news available."));
|
||||
newsLabel->setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateAvailable(GoUpdate::Status status)
|
||||
{
|
||||
if(!APPLICATION->updatesAreAllowed())
|
||||
@ -1614,6 +1685,24 @@ void MainWindow::on_actionReportBug_triggered()
|
||||
DesktopServices::openUrl(QUrl(BuildConfig.BUG_TRACKER_URL));
|
||||
}
|
||||
|
||||
void MainWindow::on_actionMoreNews_triggered()
|
||||
{
|
||||
DesktopServices::openUrl(QUrl("https://multimc.org/posts.html"));
|
||||
}
|
||||
|
||||
void MainWindow::newsButtonClicked()
|
||||
{
|
||||
QList<NewsEntryPtr> entries = m_newsChecker->getNewsEntries();
|
||||
if (entries.count() > 0)
|
||||
{
|
||||
DesktopServices::openUrl(QUrl(entries[0]->link));
|
||||
}
|
||||
else
|
||||
{
|
||||
DesktopServices::openUrl(QUrl("https://multimc.org/posts.html"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAbout_triggered()
|
||||
{
|
||||
AboutDialog dialog(this);
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "updater/GoUpdate.h"
|
||||
|
||||
class LaunchController;
|
||||
class NewsChecker;
|
||||
class NotificationChecker;
|
||||
class QToolButton;
|
||||
class InstanceProxyModel;
|
||||
@ -108,6 +109,10 @@ private slots:
|
||||
|
||||
void on_actionReportBug_triggered();
|
||||
|
||||
void on_actionMoreNews_triggered();
|
||||
|
||||
void newsButtonClicked();
|
||||
|
||||
void on_actionLaunchInstance_triggered();
|
||||
|
||||
void on_actionLaunchInstanceOffline_triggered();
|
||||
@ -169,6 +174,8 @@ private slots:
|
||||
|
||||
void repopulateAccountsMenu();
|
||||
|
||||
void updateNewsLabel();
|
||||
|
||||
/*!
|
||||
* Runs the DownloadTask and installs updates.
|
||||
*/
|
||||
@ -198,12 +205,14 @@ private:
|
||||
// these are managed by Qt's memory management model!
|
||||
InstanceView *view = nullptr;
|
||||
InstanceProxyModel *proxymodel = nullptr;
|
||||
QToolButton *newsLabel = nullptr;
|
||||
QLabel *m_statusLeft = nullptr;
|
||||
QLabel *m_statusCenter = nullptr;
|
||||
QMenu *accountMenu = nullptr;
|
||||
QToolButton *accountMenuButton = nullptr;
|
||||
KonamiCode * secretEventFilter = nullptr;
|
||||
|
||||
unique_qobject_ptr<NewsChecker> m_newsChecker;
|
||||
unique_qobject_ptr<NotificationChecker> m_notificationChecker;
|
||||
|
||||
InstancePtr m_selectedInstance;
|
||||
|
Reference in New Issue
Block a user