summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorHeiko Tietze <tietze.heiko@gmail.com>2019-09-06 10:34:54 +0200
committerHeiko Tietze <heiko.tietze@documentfoundation.org>2019-09-23 07:51:01 +0200
commit97bcd0e416b1fb725b5aaade811e80d46fdaf1e2 (patch)
tree9d841bf31e56faf32c83e6f2518919af4c6b212d /cui
parentc8e2675ebde04ab814fe0bc8f800a502280f4689 (diff)
Resolves tdf#127400 - Allow to show tip of the day again
* UNO command TipOfTheDay and slot SID_TIPOFTHEDAY introduced and added to help menus * Tip ID introduced to keep the current tip over the day * Tip ID updates after 24h * Randomization of tips replaced by sequential order * Tip ID added to the dialog title Change-Id: I69b72b80d6d6afa25a1c4f01fa05bc60b5741db8 Reviewed-on: https://gerrit.libreoffice.org/78693 Tested-by: Jenkins Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Diffstat (limited to 'cui')
-rw-r--r--cui/inc/tipoftheday.hrc1
-rw-r--r--cui/source/dialogs/tipofthedaydlg.cxx31
-rw-r--r--cui/source/inc/tipofthedaydlg.hxx6
3 files changed, 20 insertions, 18 deletions
diff --git a/cui/inc/tipoftheday.hrc b/cui/inc/tipoftheday.hrc
index 16f79af26497..8977f718f945 100644
--- a/cui/inc/tipoftheday.hrc
+++ b/cui/inc/tipoftheday.hrc
@@ -263,6 +263,7 @@ 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_TITLE NC_("STR_TITLE", "Tip of the Day")
#endif //INCLUDED_CUI_INC_TIPOFTHEDAY_HRC
diff --git a/cui/source/dialogs/tipofthedaydlg.cxx b/cui/source/dialogs/tipofthedaydlg.cxx
index 2ee5518c5274..55e9b51b9003 100644
--- a/cui/source/dialogs/tipofthedaydlg.cxx
+++ b/cui/source/dialogs/tipofthedaydlg.cxx
@@ -28,7 +28,6 @@
#include <vcl/help.hxx>
#include <vcl/virdev.hxx>
#include <vcl/svapp.hxx>
-#include <comphelper/random.hxx>
TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent)
: GenericDialogController(pParent, "cui/ui/tipofthedaydialog.ui", "TipOfTheDayDialog")
@@ -38,11 +37,17 @@ TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent)
, m_pNext(m_xBuilder->weld_button("btnNext"))
, m_pLink(m_xBuilder->weld_link_button("btnLink"))
{
- m_pShowTip->connect_toggled(LINK(this, TipOfTheDayDialog, OnShowTipToggled));
+ m_pShowTip->set_active(officecfg::Office::Common::Misc::ShowTipOfTheDay::get());
m_pNext->connect_clicked(LINK(this, TipOfTheDayDialog, OnNextClick));
nNumberOfTips = SAL_N_ELEMENTS(TIPOFTHEDAY_STRINGARRAY);
- nCurrentTip = comphelper::rng::uniform_int_distribution(0, nNumberOfTips - 1);
+ 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++;
+
UpdateTip();
}
@@ -50,10 +55,9 @@ TipOfTheDayDialog::~TipOfTheDayDialog()
{
std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
comphelper::ConfigurationChanges::create());
- const auto t0 = std::chrono::system_clock::now().time_since_epoch();
- const sal_Int32 nDay
- = std::chrono::duration_cast<std::chrono::hours>(t0).count() / 24; // days since 1970-01-01
officecfg::Office::Common::Misc::LastTipOfTheDayShown::set(nDay, xChanges);
+ officecfg::Office::Common::Misc::LastTipOfTheDayID::set(nCurrentTip, xChanges);
+ officecfg::Office::Common::Misc::ShowTipOfTheDay::set(m_pShowTip->get_active(), xChanges);
xChanges->commit();
}
@@ -65,6 +69,11 @@ static bool file_exists(const OUString& fileName)
void TipOfTheDayDialog::UpdateTip()
{
+ if ((nCurrentTip + 1 > nNumberOfTips) || (nCurrentTip < 0))
+ nCurrentTip = 0;
+ m_xDialog->set_title(CuiResId(STR_TITLE) + ": " + OUString::number(nCurrentTip + 1) + "/"
+ + OUString::number(nNumberOfTips));
+
// text
OUString aText = CuiResId(std::get<0>(TIPOFTHEDAY_STRINGARRAY[nCurrentTip]));
m_pText->set_label(aText);
@@ -110,14 +119,6 @@ void TipOfTheDayDialog::UpdateTip()
}
}
-IMPL_STATIC_LINK(TipOfTheDayDialog, OnShowTipToggled, weld::ToggleButton&, rButton, void)
-{
- std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
- comphelper::ConfigurationChanges::create());
- officecfg::Office::Common::Misc::ShowTipOfTheDay::set(rButton.get_active(), xChanges);
- xChanges->commit();
-}
-
IMPL_LINK_NOARG(TipOfTheDayDialog, OnLinkClick, weld::LinkButton&, void)
{
Application::GetHelp()->Start(aLink, static_cast<weld::Widget*>(nullptr));
@@ -125,7 +126,7 @@ IMPL_LINK_NOARG(TipOfTheDayDialog, OnLinkClick, weld::LinkButton&, void)
IMPL_LINK_NOARG(TipOfTheDayDialog, OnNextClick, weld::Button&, void)
{
- nCurrentTip = (nCurrentTip + 1) % nNumberOfTips;
+ nCurrentTip++; //zeroed at updatetip when out of range
UpdateTip();
}
diff --git a/cui/source/inc/tipofthedaydlg.hxx b/cui/source/inc/tipofthedaydlg.hxx
index 1f55df1156da..d013665a4055 100644
--- a/cui/source/inc/tipofthedaydlg.hxx
+++ b/cui/source/inc/tipofthedaydlg.hxx
@@ -30,11 +30,11 @@ private:
std::unique_ptr<weld::Button> m_pNext;
std::unique_ptr<weld::LinkButton> m_pLink;
- sal_uInt32 nCurrentTip;
- sal_uInt32 nNumberOfTips;
+ sal_Int32 nCurrentTip;
+ sal_Int32 nNumberOfTips;
+ sal_Int32 nDay;
OUString aLink;
void UpdateTip();
- DECL_STATIC_LINK(TipOfTheDayDialog, OnShowTipToggled, weld::ToggleButton&, void);
DECL_LINK(OnNextClick, weld::Button&, void);
DECL_LINK(OnLinkClick, weld::LinkButton&, void);