diff options
author | Heiko Tietze <tietze.heiko@gmail.com> | 2020-10-15 12:18:28 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-10-20 11:18:35 +0200 |
commit | 1d66b9970b7ecf8d8e144cfa3b2fbb7ce3dd1a08 (patch) | |
tree | ff8951e412dc6c89d92fa90c1ab0c16a0bf38981 | |
parent | cb48b7205cc6cdcf6741bc430266481a8b6b4769 (diff) |
Beautification of code and fix for on-/offline help
Change-Id: I0c731f2c472ceb435f529956011a7fd5a00a27ca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104358
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r-- | cui/inc/tipoftheday.hrc | 1 | ||||
-rw-r--r-- | cui/source/dialogs/tipofthedaydlg.cxx | 81 | ||||
-rw-r--r-- | cui/source/inc/tipofthedaydlg.hxx | 5 |
3 files changed, 33 insertions, 54 deletions
diff --git a/cui/inc/tipoftheday.hrc b/cui/inc/tipoftheday.hrc index acb7bdd15d3e..33b551ecc2fc 100644 --- a/cui/inc/tipoftheday.hrc +++ b/cui/inc/tipoftheday.hrc @@ -272,7 +272,6 @@ const std::tuple<const char*, OUString, OUString> TIPOFTHEDAY_STRINGARRAY[] = #define STR_HELP_LINK NC_("STR_HELP_LINK", "%PRODUCTNAME Help") #define STR_MORE_LINK NC_("STR_MORE_LINK", "More info") #define STR_UNO_LINK NC_("STR_UNO_LINK", "Run this action now...") -#define STR_UNO_EXECUTE NC_("STR_UNO_EXECUTE", "Execute the command %COMMAND") //tooltip for STR_UNO_LINK #define STR_TITLE NC_("STR_TITLE", "Tip of the Day: %CURRENT/%TOTAL") #define STR_CMD NC_("STR_CMD", "⌘ Cmd") //use narrow no-break space U+202F here #define STR_CTRL NC_("STR_CTRL", "Ctrl") diff --git a/cui/source/dialogs/tipofthedaydlg.cxx b/cui/source/dialogs/tipofthedaydlg.cxx index 005584027547..88b61a8d0b2b 100644 --- a/cui/source/dialogs/tipofthedaydlg.cxx +++ b/cui/source/dialogs/tipofthedaydlg.cxx @@ -47,12 +47,12 @@ TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent) m_pShowTip->set_active(officecfg::Office::Common::Misc::ShowTipOfTheDay::get()); m_pNext->connect_clicked(LINK(this, TipOfTheDayDialog, OnNextClick)); - nCurrentTip = officecfg::Office::Common::Misc::LastTipOfTheDayID::get(); + m_nCurrentTip = officecfg::Office::Common::Misc::LastTipOfTheDayID::get(); const auto t0 = std::chrono::system_clock::now().time_since_epoch(); - nDay = std::chrono::duration_cast<std::chrono::hours>(t0).count() / 24; //days since 1970-01-01 - if (nDay > officecfg::Office::Common::Misc::LastTipOfTheDayShown::get()) - nCurrentTip++; + m_nDay = std::chrono::duration_cast<std::chrono::hours>(t0).count() / 24; + if (m_nDay > officecfg::Office::Common::Misc::LastTipOfTheDayShown::get()) + m_nCurrentTip++; UpdateTip(); } @@ -61,8 +61,8 @@ TipOfTheDayDialog::~TipOfTheDayDialog() { std::shared_ptr<comphelper::ConfigurationChanges> xChanges( comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Misc::LastTipOfTheDayShown::set(nDay, xChanges); - officecfg::Office::Common::Misc::LastTipOfTheDayID::set(nCurrentTip, xChanges); + officecfg::Office::Common::Misc::LastTipOfTheDayShown::set(m_nDay, xChanges); + officecfg::Office::Common::Misc::LastTipOfTheDayID::set(m_nCurrentTip, xChanges); officecfg::Office::Common::Misc::ShowTipOfTheDay::set(m_pShowTip->get_active(), xChanges); xChanges->commit(); } @@ -77,16 +77,17 @@ void TipOfTheDayDialog::UpdateTip() { constexpr sal_Int32 nNumberOfTips = SAL_N_ELEMENTS(TIPOFTHEDAY_STRINGARRAY); - if ((nCurrentTip >= nNumberOfTips) || (nCurrentTip < 0)) - nCurrentTip = 0; + if ((m_nCurrentTip >= nNumberOfTips) || (m_nCurrentTip < 0)) + m_nCurrentTip = 0; //title m_xDialog->set_title(CuiResId(STR_TITLE) - .replaceFirst("%CURRENT", OUString::number(nCurrentTip + 1)) + .replaceFirst("%CURRENT", OUString::number(m_nCurrentTip + 1)) .replaceFirst("%TOTAL", OUString::number(nNumberOfTips))); + auto[sTip, sLink, sImage] = TIPOFTHEDAY_STRINGARRAY[m_nCurrentTip]; + // text - OUString aText = CuiResId(std::get<0>(TIPOFTHEDAY_STRINGARRAY[nCurrentTip])); //replace MOD1 & MOD2 shortcuts depending on platform #ifdef MACOSX const OUString aMOD1 = CuiResId(STR_CMD); @@ -95,64 +96,43 @@ void TipOfTheDayDialog::UpdateTip() const OUString aMOD1 = CuiResId(STR_CTRL); const OUString aMOD2 = CuiResId(STR_Alt); #endif - sal_Int32 aPos; - aPos = aText.indexOf("%MOD1"); - while (aPos != -1) - { - aText = aText.replaceAt(aPos, 5, aMOD1); - aPos = aText.indexOf("%MOD1"); - } - aPos = aText.indexOf("%MOD2"); - while (aPos != -1) - { - aText = aText.replaceAt(aPos, 5, aMOD2); - aPos = aText.indexOf("%MOD2"); - } - m_pText->set_label(aText); + m_pText->set_label(CuiResId(sTip).replaceAll("%MOD1", aMOD1).replaceAll("%MOD2", aMOD2)); // hyperlink - aLink = std::get<1>(TIPOFTHEDAY_STRINGARRAY[nCurrentTip]); - if (aLink.isEmpty()) + if (sLink.isEmpty()) { m_pLink->set_visible(false); } - else if (aLink.startsWith(".uno:")) + else if (sLink.startsWith(".uno:")) { - m_pLink->set_uri(CuiResId(STR_UNO_EXECUTE).replaceFirst("%COMMAND", aLink)); + m_pLink->set_uri(sLink); m_pLink->set_label(CuiResId(STR_UNO_LINK)); m_pLink->set_visible(true); m_pLink->connect_activate_link(LINK(this, TipOfTheDayDialog, OnLinkClick)); } - else if (aLink.startsWith("http")) + else if (sLink.startsWith("http")) { // Links may have some %PRODUCTVERSION which need to be expanded - aText = Translate::ExpandVariables(aLink); - aPos = aText.indexOf("%LANGUAGENAME"); - if (aPos != -1) - { - OUString aLang = LanguageTag(utl::ConfigManager::getUILocale()).getLanguage(); - if (aLang == "en" || aLang == "pt" || aLang == "zh") //en-US/GB, pt-BR, zh-CH/TW - aLang = LanguageTag(utl::ConfigManager::getUILocale()).getBcp47(); - aText = aText.replaceAt(aPos, 13, aLang); - } - m_pLink->set_uri(aText); - + OUString aText = Translate::ExpandVariables(sLink); + OUString aLang = LanguageTag(utl::ConfigManager::getUILocale()).getLanguage(); + if (aLang == "en" || aLang == "pt" || aLang == "zh") //en-US/GB, pt-BR, zh-CH/TW + aLang = LanguageTag(utl::ConfigManager::getUILocale()).getBcp47(); + m_pLink->set_uri(aText.replaceFirst("%LANGUAGENAME", aLang)); m_pLink->set_label(CuiResId(STR_MORE_LINK)); m_pLink->set_visible(true); m_pLink->connect_activate_link(Link<weld::LinkButton&, bool>()); } else { - m_pLink->set_uri(""); + m_pLink->set_uri(sLink); m_pLink->set_label(CuiResId(STR_HELP_LINK)); m_pLink->set_visible(true); - //converts aLink into the proper offline/online hyperlink m_pLink->connect_activate_link(LINK(this, TipOfTheDayDialog, OnLinkClick)); } // image OUString aURL("$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/tipoftheday/"); rtl::Bootstrap::expandMacros(aURL); - OUString aImage = std::get<2>(TIPOFTHEDAY_STRINGARRAY[nCurrentTip]); + OUString aImage = sImage; // use default image if none is available with the number if (aImage.isEmpty() || !file_exists(aURL + aImage)) aImage = "tipoftheday.png"; @@ -168,23 +148,24 @@ void TipOfTheDayDialog::UpdateTip() } } -IMPL_LINK_NOARG(TipOfTheDayDialog, OnLinkClick, weld::LinkButton&, bool) +IMPL_LINK(TipOfTheDayDialog, OnLinkClick, weld::LinkButton&, rButton, bool) { - if (aLink.startsWith("http")) + const OUString sLink = rButton.get_uri(); + if (sLink.startsWith(".uno:")) { - Application::GetHelp()->Start(aLink, static_cast<weld::Widget*>(nullptr)); + comphelper::dispatchCommand(sLink, {}); + TipOfTheDayDialog::response(RET_OK); } - else if (aLink.startsWith(".uno:")) + else { - comphelper::dispatchCommand(aLink, {}); - TipOfTheDayDialog::response(RET_OK); + Application::GetHelp()->Start(sLink, static_cast<weld::Widget*>(nullptr)); } return true; } IMPL_LINK_NOARG(TipOfTheDayDialog, OnNextClick, weld::Button&, void) { - nCurrentTip++; //zeroed at updatetip when out of range + m_nCurrentTip++; //zeroed at updatetip when out of range UpdateTip(); } diff --git a/cui/source/inc/tipofthedaydlg.hxx b/cui/source/inc/tipofthedaydlg.hxx index c89694c1c15d..bb417bb2705a 100644 --- a/cui/source/inc/tipofthedaydlg.hxx +++ b/cui/source/inc/tipofthedaydlg.hxx @@ -29,9 +29,8 @@ private: std::unique_ptr<weld::Button> m_pNext; std::unique_ptr<weld::LinkButton> m_pLink; - sal_Int32 nCurrentTip; - sal_Int32 nDay; - OUString aLink; + sal_Int32 m_nCurrentTip; + sal_Int32 m_nDay; void UpdateTip(); DECL_LINK(OnNextClick, weld::Button&, void); DECL_LINK(OnLinkClick, weld::LinkButton&, bool); |