refs #883, display of news/about

* use QTextBrowser, external links will be opened in browser
* display about in credits tabs
* added shortcuts for tabs

Remark: Gives us a first (not perfect) version of news/about in launcher
This commit is contained in:
Klaus Basan
2017-02-15 23:43:16 +01:00
committed by Mathew Sutcliffe
parent 8df2fa462f
commit c5b4b01a90
3 changed files with 40 additions and 12 deletions

View File

@@ -116,7 +116,7 @@ void CSwiftLauncher::ps_displayLatestNews(QNetworkReply *reply)
{ {
const QString html = nwReply->readAll().trimmed(); const QString html = nwReply->readAll().trimmed();
if (html.isEmpty()) { return; } if (html.isEmpty()) { return; }
ui->te_LatestNews->setHtml(html); ui->tbr_LatestNews->setHtml(html);
constexpr qint64 newNews = 72 * 3600 * 1000; constexpr qint64 newNews = 72 * 3600 * 1000;
const qint64 deltaT = CNetworkUtils::lastModifiedSinceNow(nwReply.data()); const qint64 deltaT = CNetworkUtils::lastModifiedSinceNow(nwReply.data());
if (deltaT > 0 && deltaT < newNews) if (deltaT > 0 && deltaT < newNews)
@@ -175,6 +175,19 @@ void CSwiftLauncher::loadLatestNews()
sGui->getFromNetwork(newsUrl, { this, &CSwiftLauncher::ps_displayLatestNews}); sGui->getFromNetwork(newsUrl, { this, &CSwiftLauncher::ps_displayLatestNews});
} }
void CSwiftLauncher::loadAbout()
{
// workaround:
// 1) Only reading as HTML gives proper formatting
// 2) Reading the file resource fails (likely because of the style sheet)
static const QString html = CFileUtils::readFileToString(CBuildConfig::getAboutFileLocation());
static const QString legalDir = sGui->getGlobalSetup().getLegalDirectoryUrl().getFullUrl();
// make links absolute
static const QString htmlFixed = QString(html).
replace(QLatin1Literal("href=\"./"), "href=\"" + legalDir);
ui->tbr_About->setHtml(htmlFixed);
}
void CSwiftLauncher::initDBusGui() void CSwiftLauncher::initDBusGui()
{ {
ui->cb_DBusServerAddress->addItem("127.0.0.1"); ui->cb_DBusServerAddress->addItem("127.0.0.1");
@@ -348,6 +361,7 @@ void CSwiftLauncher::ps_loadedUpdateInfo(bool success)
} }
this->loadLatestNews(); this->loadLatestNews();
this->loadAbout();
} }
void CSwiftLauncher::ps_changedUpdateInfoCache() void CSwiftLauncher::ps_changedUpdateInfoCache()

View File

@@ -73,6 +73,7 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override;
private slots: private slots:
//! Display latest news
void ps_displayLatestNews(QNetworkReply *reply); void ps_displayLatestNews(QNetworkReply *reply);
private: private:
@@ -110,9 +111,13 @@ private:
//! Log display //! Log display
void initLogDisplay(); void initLogDisplay();
//! latest news //! Latest news
//! \sa CSwiftLauncher::ps_displayLatestNews
void loadLatestNews(); void loadLatestNews();
//! Load credits and legal info
void loadAbout();
//! Start the core //! Start the core
void startSwiftCore(); void startSwiftCore();

View File

@@ -78,7 +78,7 @@
<item> <item>
<widget class="QToolBox" name="tb_Launcher"> <widget class="QToolBox" name="tb_Launcher">
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>4</number>
</property> </property>
<property name="tabSpacing"> <property name="tabSpacing">
<number>6</number> <number>6</number>
@@ -93,11 +93,11 @@
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
<string>Latest news</string> <string>Latest &amp;news</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="vl_LatestNews"> <layout class="QVBoxLayout" name="vl_LatestNews">
<item> <item>
<widget class="QTextEdit" name="te_LatestNews"> <widget class="QTextBrowser" name="tbr_LatestNews">
<property name="documentTitle"> <property name="documentTitle">
<string>Latest news</string> <string>Latest news</string>
</property> </property>
@@ -107,6 +107,9 @@
<property name="placeholderText"> <property name="placeholderText">
<string>Latest news will go here</string> <string>Latest news will go here</string>
</property> </property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@@ -121,7 +124,7 @@
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
<string>Window type</string> <string>&amp;Window type</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gl_WindowType"> <layout class="QGridLayout" name="gl_WindowType">
<item row="1" column="1" alignment="Qt::AlignHCenter"> <item row="1" column="1" alignment="Qt::AlignHCenter">
@@ -186,7 +189,7 @@
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
<string>Core mode</string> <string>&amp;Core mode</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gl_CoreMode" columnstretch="10,14,14"> <layout class="QGridLayout" name="gl_CoreMode" columnstretch="10,14,14">
<property name="leftMargin"> <property name="leftMargin">
@@ -430,7 +433,7 @@
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
<string>Check for updates</string> <string>Check for &amp;updates</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="vl_Updates"> <layout class="QVBoxLayout" name="vl_Updates">
<property name="leftMargin"> <property name="leftMargin">
@@ -591,7 +594,7 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="pg_CreditsLicense"> <widget class="QWidget" name="pg_About">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@@ -601,21 +604,27 @@
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
<string>Credits and License</string> <string>&amp;About (credits and license)</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="vl_Credits"> <layout class="QVBoxLayout" name="vl_Credits">
<item> <item>
<widget class="QTextEdit" name="te_CreditsLicense"> <widget class="QTextBrowser" name="tbr_About">
<property name="documentTitle">
<string>About swift</string>
</property>
<property name="readOnly"> <property name="readOnly">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="html"> <property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;title&gt;About swift&lt;/title&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:7.875pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:7.875pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8.25pt;&quot;&gt;Credits will go here&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8.25pt;&quot;&gt;Credits will go here&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>