From 4495e20cd7f7f2ab062f3b60f19ac4b79f32c350 Mon Sep 17 00:00:00 2001 From: Forkk Date: Thu, 2 Jan 2014 13:25:38 -0600 Subject: Add news checking system and news toolbar --- gui/MainWindow.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'gui/MainWindow.cpp') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 3f086b36..85ad319b 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -116,6 +116,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi renameButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); } + // Add the news label to the news toolbar. + { + newsLabel = new QToolButton(); + newsLabel->setIcon(QIcon(":/icons/toolbar/news")); + newsLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + newsLabel->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + ui->newsToolBar->insertWidget(ui->actionMoreNews, newsLabel); + QObject::connect(MMC->newsChecker().get(), &NewsChecker::newsLoaded, this, &MainWindow::updateNewsLabel); + updateNewsLabel(); + } + // Create the instance list widget { view = new KCategorizedView(ui->centralWidget); @@ -249,6 +260,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi } MMC->newsChecker()->reloadNews(); + updateNewsLabel(); // set up the updater object. auto updater = MMC->updateChecker(); @@ -433,6 +445,30 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *ev) return QMainWindow::eventFilter(obj, ev); } +void MainWindow::updateNewsLabel() +{ + auto newsChecker = MMC->newsChecker(); + if (newsChecker->isLoadingNews()) + { + newsLabel->setText(tr("Loading news...")); + newsLabel->setEnabled(false); + } + else + { + QList entries = 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(QString repo, QString versionName, int versionId) { UpdateDialog dlg; @@ -708,7 +744,7 @@ void MainWindow::on_actionReportBug_triggered() openWebPage(QUrl("http://multimc.myjetbrains.com/youtrack/dashboard#newissue=yes")); } -void MainWindow::on_actionNews_triggered() +void MainWindow::on_actionMoreNews_triggered() { openWebPage(QUrl("http://multimc.org/posts.html")); } -- cgit v1.2.3