diff options
author | Forkk <forkk@forkk.net> | 2014-01-02 13:25:38 -0600 |
---|---|---|
committer | Forkk <forkk@forkk.net> | 2014-01-02 13:25:38 -0600 |
commit | 4495e20cd7f7f2ab062f3b60f19ac4b79f32c350 (patch) | |
tree | f5bbc9d40ea49fcfd52e3d310c7c1e0ce4c8c6a2 | |
parent | 9d8006b597aead06f1d51dacbdb346ebab3d5e8f (diff) | |
download | MultiMC-4495e20cd7f7f2ab062f3b60f19ac4b79f32c350.tar MultiMC-4495e20cd7f7f2ab062f3b60f19ac4b79f32c350.tar.gz MultiMC-4495e20cd7f7f2ab062f3b60f19ac4b79f32c350.tar.lz MultiMC-4495e20cd7f7f2ab062f3b60f19ac4b79f32c350.tar.xz MultiMC-4495e20cd7f7f2ab062f3b60f19ac4b79f32c350.zip |
Add news checking system and news toolbar
-rw-r--r-- | gui/MainWindow.cpp | 38 | ||||
-rw-r--r-- | gui/MainWindow.h | 5 | ||||
-rw-r--r-- | gui/MainWindow.ui | 44 | ||||
-rw-r--r-- | logic/news/NewsChecker.cpp | 5 | ||||
-rw-r--r-- | logic/news/NewsChecker.h | 6 |
5 files changed, 87 insertions, 11 deletions
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<NewsEntryPtr> 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")); } diff --git a/gui/MainWindow.h b/gui/MainWindow.h index befe93e6..60fde281 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -84,7 +84,7 @@ slots: void on_actionReportBug_triggered(); - void on_actionNews_triggered(); + void on_actionMoreNews_triggered(); void on_mainToolBar_visibilityChanged(bool); @@ -162,6 +162,8 @@ slots: void changeActiveAccount(); void repopulateAccountsMenu(); + + void updateNewsLabel(); /*! * Runs the DownloadUpdateTask and installs updates. @@ -181,6 +183,7 @@ private: ConsoleWindow *console; LabeledToolButton *renameButton; QToolButton *changeIconButton; + QToolButton* newsLabel; BaseInstance *m_selectedInstance; diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 82e3b05f..1a3f53cd 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>688</width> - <height>650</height> + <height>460</height> </rect> </property> <property name="windowTitle"> @@ -72,7 +72,6 @@ <addaction name="actionSettings"/> <addaction name="separator"/> <addaction name="actionReportBug"/> - <addaction name="actionNews"/> <addaction name="actionAbout"/> <addaction name="separator"/> <addaction name="actionCAT"/> @@ -121,6 +120,36 @@ <addaction name="separator"/> <addaction name="actionDeleteInstance"/> </widget> + <widget class="QToolBar" name="newsToolBar"> + <property name="windowTitle"> + <string>News Toolbar</string> + </property> + <property name="movable"> + <bool>false</bool> + </property> + <property name="allowedAreas"> + <set>Qt::BottomToolBarArea</set> + </property> + <property name="iconSize"> + <size> + <width>16</width> + <height>16</height> + </size> + </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonTextBesideIcon</enum> + </property> + <property name="floatable"> + <bool>false</bool> + </property> + <attribute name="toolBarArea"> + <enum>BottomToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + <addaction name="actionMoreNews"/> + </widget> <action name="actionAddInstance"> <property name="icon"> <iconset resource="../graphics.qrc"> @@ -229,19 +258,22 @@ <string>Open the bug tracker to report a bug with MultiMC.</string> </property> </action> - <action name="actionNews"> + <action name="actionMoreNews"> <property name="icon"> <iconset resource="../graphics.qrc"> <normaloff>:/icons/toolbar/news</normaloff>:/icons/toolbar/news</iconset> </property> <property name="text"> - <string>News</string> + <string>More News</string> + </property> + <property name="iconText"> + <string>More...</string> </property> <property name="toolTip"> - <string>Open the MultiMC dev blog to read news about MultiMC.</string> + <string>Open the MultiMC development blog to read more news about MultiMC.</string> </property> <property name="statusTip"> - <string>Open the MultiMC dev blog to read news about MultiMC.</string> + <string>Open the MultiMC development blog to read more news about MultiMC.</string> </property> </action> <action name="actionAbout"> diff --git a/logic/news/NewsChecker.cpp b/logic/news/NewsChecker.cpp index 08d4ef23..8fc44fa9 100644 --- a/logic/news/NewsChecker.cpp +++ b/logic/news/NewsChecker.cpp @@ -102,6 +102,11 @@ void NewsChecker::rssDownloadFailed() } +QList<NewsEntryPtr> NewsChecker::getNewsEntries() const +{ + return m_newsEntries; +} + bool NewsChecker::isLoadingNews() const { return m_newsNetJob.get() != nullptr; diff --git a/logic/news/NewsChecker.h b/logic/news/NewsChecker.h index 6d1fb935..820fe626 100644 --- a/logic/news/NewsChecker.h +++ b/logic/news/NewsChecker.h @@ -42,6 +42,9 @@ public: * Returns true if the news has been loaded successfully. */ bool isNewsLoaded() const; + + //! True if the news is currently loading. If true, reloadNews() will do nothing. + bool isLoadingNews() const; /*! * Returns a list of news entries. @@ -78,9 +81,6 @@ protected: //! The network job to use to load the news. NetJobPtr m_newsNetJob; - - //! True if the news is currently loading. If true, reloadNews() will do nothing. - bool isLoadingNews() const; //! True if news has been loaded. bool m_loadedNews; |