diff options
author | heiko tietze <tietze.heiko@gmail.com> | 2019-03-21 10:14:07 +0100 |
---|---|---|
committer | Heiko Tietze <tietze.heiko@gmail.com> | 2019-04-10 16:54:37 +0200 |
commit | a1700d52a47184ee07b91b461a846dc5435f0022 (patch) | |
tree | 31e05614ca9133846bef8fd5219ada1191d48414 /cui/source | |
parent | 3d7a67cdd465956206f881304bbcbaf47ccfcd83 (diff) |
tdf#124238 - Show a Tip-Of-The-Day dialog on startup
New dialog
Change-Id: If1e501de26eb5a9c20a59e621f9e805c3b5e2cf8
Reviewed-on: https://gerrit.libreoffice.org/69498
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <tietze.heiko@gmail.com>
Diffstat (limited to 'cui/source')
-rw-r--r-- | cui/source/dialogs/tipofthedaydlg.cxx | 119 | ||||
-rw-r--r-- | cui/source/factory/cuiexp.cxx | 1 | ||||
-rw-r--r-- | cui/source/factory/dlgfact.cxx | 12 | ||||
-rw-r--r-- | cui/source/factory/dlgfact.hxx | 16 | ||||
-rw-r--r-- | cui/source/inc/tipofthedaydlg.hxx | 46 | ||||
-rw-r--r-- | cui/source/options/optgdlg.cxx | 9 | ||||
-rw-r--r-- | cui/source/options/optgdlg.hxx | 1 |
7 files changed, 204 insertions, 0 deletions
diff --git a/cui/source/dialogs/tipofthedaydlg.cxx b/cui/source/dialogs/tipofthedaydlg.cxx new file mode 100644 index 000000000000..430ae484d08a --- /dev/null +++ b/cui/source/dialogs/tipofthedaydlg.cxx @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <tipofthedaydlg.hxx> + +#include <config_folders.h> +#include <dialmgr.hxx> +#include <officecfg/Office/Common.hxx> +#include <osl/file.hxx> +#include <rtl/bootstrap.hxx> +#include <tipoftheday.hrc> +#include <vcl/graphicfilter.hxx> +#include <vcl/virdev.hxx> + +TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent) + : GenericDialogController(pParent, "cui/ui/tipofthedaydialog.ui", "TipOfTheDayDialog") + , m_pImage(m_xBuilder->weld_image("imImage")) + , m_pText(m_xBuilder->weld_label("lbText")) + , m_pShowTip(m_xBuilder->weld_check_button("cbShowTip")) + , m_pNext(m_xBuilder->weld_button("btnNext")) + , m_pLink(m_xBuilder->weld_link_button("btnLink")) +{ + m_pShowTip->connect_toggled(LINK(this, TipOfTheDayDialog, OnShowTipToggled)); + m_pNext->connect_clicked(LINK(this, TipOfTheDayDialog, OnNextClick)); + + nNumberOfTips = SAL_N_ELEMENTS(TIPOFTHEDAY_STRINGARRAY); + nCurrentTip = rand() % nNumberOfTips; + UpdateTip(); +} + +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); + xChanges->commit(); +} + +static bool file_exists(const OUString& fileName) +{ + ::osl::File aFile(fileName); + return aFile.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None; +} + +void TipOfTheDayDialog::UpdateTip() +{ + //get string + OUString aText; + aText = CuiResId(TIPOFTHEDAY_STRINGARRAY[nCurrentTip]); + //move hyperlink into linkbutton + sal_Int32 nPos = aText.indexOf("http"); + if (nPos > 0) + { + m_pLink->set_visible(true); + if (aText.getLength() - nPos > 40) + m_pLink->set_label(aText.copy(nPos, 40) + "..."); + else + m_pLink->set_label(aText.copy(nPos)); + m_pLink->set_uri(aText.copy(nPos)); + aText = aText.copy(0, nPos - 1); + } + else + m_pLink->set_visible(false); + m_pText->set_label(aText); + + // import the image + OUString aURL("$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/tipoftheday/"); + rtl::Bootstrap::expandMacros(aURL); + OUString aName = "tipoftheday_" + OUString::number(nCurrentTip) + ".png"; + // use default image if none is available with the number + if (!file_exists(aURL + aName)) + aName = "tipoftheday.png"; + // draw image + Graphic aGraphic; + if (GraphicFilter::LoadGraphic(aURL + aName, OUString(), aGraphic) == ERRCODE_NONE) + { + ScopedVclPtr<VirtualDevice> m_pVirDev; + m_pVirDev = m_pImage->create_virtual_device(); + m_pVirDev->SetOutputSizePixel(aGraphic.GetSizePixel()); + m_pVirDev->DrawBitmapEx(Point(0, 0), aGraphic.GetBitmapEx()); + m_pImage->set_image(m_pVirDev.get()); + m_pVirDev.disposeAndClear(); + } +} + +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, OnNextClick, weld::Button&, void) +{ + nCurrentTip = rand() % nNumberOfTips; + UpdateTip(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file diff --git a/cui/source/factory/cuiexp.cxx b/cui/source/factory/cuiexp.cxx index 09cddbf04044..e3c13320172f 100644 --- a/cui/source/factory/cuiexp.cxx +++ b/cui/source/factory/cuiexp.cxx @@ -50,6 +50,7 @@ #include <thesdlg.hxx> #include <hangulhanjadlg.hxx> #include <dstribut.hxx> +#include <tipofthedaydlg.hxx> #include "dlgfact.hxx" #include <sal/types.h> diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx index a862bea608ab..4669f431df56 100644 --- a/cui/source/factory/dlgfact.cxx +++ b/cui/source/factory/dlgfact.cxx @@ -88,6 +88,7 @@ #include <hyphen.hxx> #include <thesdlg.hxx> #include <about.hxx> +#include <tipofthedaydlg.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::frame; @@ -1344,6 +1345,11 @@ short SvxMacroAssignDialog::Execute() return m_xDialog->run(); } +short AbstractTipOfTheDayDialog_Impl::Execute() +{ + return m_xDlg->run(); +} + VclPtr<VclAbstractDialog> AbstractDialogFactory_Impl::CreateSvxMacroAssignDlg( weld::Window* _pParent, const Reference< XFrame >& _rxDocumentFrame, const bool _bUnoDialogMode, const Reference< XNameReplace >& _rxEvents, const sal_uInt16 _nInitiallySelectedEvent ) @@ -1588,4 +1594,10 @@ AbstractDialogFactory_Impl::CreateSignSignatureLineDialog(weld::Window* pParent, std::make_unique<SignSignatureLineDialog>(pParent, xModel)); } +VclPtr<AbstractTipOfTheDayDialog> +AbstractDialogFactory_Impl::CreateTipOfTheDayDialog(weld::Window* pParent) +{ + return VclPtr<AbstractTipOfTheDayDialog_Impl>::Create(std::make_unique<TipOfTheDayDialog>(pParent)); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx index 6d263ea3a70a..65b2f4337760 100644 --- a/cui/source/factory/dlgfact.hxx +++ b/cui/source/factory/dlgfact.hxx @@ -658,6 +658,20 @@ public: virtual short Execute() override; }; +class TipOfTheDayDialog; +class AbstractTipOfTheDayDialog_Impl : public AbstractTipOfTheDayDialog +{ +protected: + std::unique_ptr<TipOfTheDayDialog> m_xDlg; + +public: + explicit AbstractTipOfTheDayDialog_Impl(std::unique_ptr<TipOfTheDayDialog> p) + : m_xDlg(std::move(p)) + { + } + virtual short Execute() override; +}; + //AbstractDialogFactory_Impl implementations class AbstractDialogFactory_Impl : public SvxAbstractDialogFactory { @@ -836,6 +850,8 @@ public: virtual VclPtr<AbstractSignSignatureLineDialog> CreateSignSignatureLineDialog(weld::Window* pParent, const css::uno::Reference<css::frame::XModel> xModel) override; + + virtual VclPtr<AbstractTipOfTheDayDialog> CreateTipOfTheDayDialog(weld::Window* pParent) override; }; #endif diff --git a/cui/source/inc/tipofthedaydlg.hxx b/cui/source/inc/tipofthedaydlg.hxx new file mode 100644 index 000000000000..1e7b1eba8c07 --- /dev/null +++ b/cui/source/inc/tipofthedaydlg.hxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CUI_SOURCE_INC_TIPOFTHEDAYDLG_HXX +#define INCLUDED_CUI_SOURCE_INC_TIPOFTHEDAYDLG_HXX + +#include <vcl/weld.hxx> + +class TipOfTheDayDialog : public weld::GenericDialogController +{ +private: + std::unique_ptr<weld::Image> m_pImage; + std::unique_ptr<weld::Label> m_pText; + std::unique_ptr<weld::CheckButton> m_pShowTip; + std::unique_ptr<weld::Button> m_pNext; + std::unique_ptr<weld::LinkButton> m_pLink; + + sal_uInt32 nCurrentTip; + sal_uInt32 nNumberOfTips; + void UpdateTip(); + DECL_STATIC_LINK(TipOfTheDayDialog, OnShowTipToggled, weld::ToggleButton&, void); + DECL_LINK(OnNextClick, weld::Button&, void); + +public: + TipOfTheDayDialog(weld::Window* pWindow); + virtual ~TipOfTheDayDialog() override; +}; + +#endif // INCLUDED_CUI_SOURCE_INC_TIPOFTHEDAYDLG_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/options/optgdlg.cxx b/cui/source/options/optgdlg.cxx index 6c31ddbcdc60..c1ae769a0eb4 100644 --- a/cui/source/options/optgdlg.cxx +++ b/cui/source/options/optgdlg.cxx @@ -260,6 +260,7 @@ OfaMiscTabPage::OfaMiscTabPage(TabPageParent pParent, const SfxItemSet& rSet) : SfxTabPage(pParent, "cui/ui/optgeneralpage.ui", "OptGeneralPage", &rSet) , m_xExtHelpCB(m_xBuilder->weld_check_button("exthelp")) , m_xPopUpNoHelpCB(m_xBuilder->weld_check_button("popupnohelp")) + , m_xShowTipOfTheDay(m_xBuilder->weld_check_button("cbShowTipOfTheDay")) , m_xFileDlgFrame(m_xBuilder->weld_widget("filedlgframe")) , m_xPrintDlgFrame(m_xBuilder->weld_widget("printdlgframe")) , m_xFileDlgROImage(m_xBuilder->weld_widget("lockimage")) @@ -329,6 +330,12 @@ bool OfaMiscTabPage::FillItemSet( SfxItemSet* rSet ) if ( m_xExtHelpCB->get_state_changed_from_saved() ) aHelpOptions.SetExtendedHelp( m_xExtHelpCB->get_active() ); + if ( m_xShowTipOfTheDay->get_state_changed_from_saved() ) + { + officecfg::Office::Common::Misc::ShowTipOfTheDay::set(m_xShowTipOfTheDay->get_active(), batch); + bModified = true; + } + if ( m_xFileDlgCB->get_state_changed_from_saved() ) { SvtMiscOptions aMiscOpt; @@ -382,6 +389,8 @@ void OfaMiscTabPage::Reset( const SfxItemSet* rSet ) m_xExtHelpCB->save_state(); m_xPopUpNoHelpCB->set_active( aHelpOptions.IsOfflineHelpPopUp() ); m_xPopUpNoHelpCB->save_state(); + m_xShowTipOfTheDay->set_active( officecfg::Office::Common::Misc::ShowTipOfTheDay::get() ); + m_xShowTipOfTheDay->save_state(); SvtMiscOptions aMiscOpt; m_xFileDlgCB->set_active( !aMiscOpt.UseSystemFileDialog() ); m_xFileDlgCB->save_state(); diff --git a/cui/source/options/optgdlg.hxx b/cui/source/options/optgdlg.hxx index 52cf72ef3b6e..f5c02d20da2d 100644 --- a/cui/source/options/optgdlg.hxx +++ b/cui/source/options/optgdlg.hxx @@ -44,6 +44,7 @@ private: std::unique_ptr<weld::CheckButton> m_xExtHelpCB; std::unique_ptr<weld::CheckButton> m_xPopUpNoHelpCB; + std::unique_ptr<weld::CheckButton> m_xShowTipOfTheDay; std::unique_ptr<weld::Widget> m_xFileDlgFrame; std::unique_ptr<weld::Widget> m_xPrintDlgFrame; std::unique_ptr<weld::Widget> m_xFileDlgROImage; |