22#include <tipoftheday.hrc>
31#include <com/sun/star/frame/XDispatch.hpp>
32#include <com/sun/star/frame/XDispatchProvider.hpp>
33#include <com/sun/star/util/URL.hpp>
34#include <com/sun/star/util/URLTransformer.hpp>
39#include <officecfg/Office/Common.hxx>
40#include <osl/file.hxx>
41#include <rtl/bootstrap.hxx>
45#include <com/sun/star/beans/PropertyValue.hpp>
46#include <bitmaps.hlst>
52 : GenericDialogController(pParent,
"cui/ui/tipofthedaydialog.ui",
"TipOfTheDayDialog")
54 , m_pText(m_xBuilder->weld_label(
"lbText"))
55 , m_pShowTip(m_xBuilder->weld_check_button(
"cbShowTip"))
56 , m_pNext(m_xBuilder->weld_button(
"btnNext"))
57 , m_pLink(m_xBuilder->weld_link_button(
"btnLink"))
58 , m_pPreview(new
weld::CustomWeld(*m_xBuilder,
"imPreview", m_aPreview))
60 m_pShowTip->set_active(officecfg::Office::Common::Misc::ShowTipOfTheDay::get());
62 m_nCurrentTip = officecfg::Office::Common::Misc::LastTipOfTheDayID::get();
65 if (pParent !=
nullptr)
67 css::uno::Reference<css::awt::XWindow> xWindow = pParent->
GetXWindow();
71 if (xVclWin !=
nullptr)
76 const auto t0 = std::chrono::system_clock::now().time_since_epoch();
77 sal_Int32 nDay = std::chrono::duration_cast<std::chrono::hours>(t0).count() / 24;
79 if (nDay > officecfg::Office::Common::Misc::LastTipOfTheDayShown::get())
85 std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
87 officecfg::Office::Common::Misc::LastTipOfTheDayShown::set(nDay, xChanges);
95 if (rEvent.GetId() == VclEventId::ObjectDying)
104 std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
106 officecfg::Office::Common::Misc::LastTipOfTheDayID::set(
m_nCurrentTip, xChanges);
107 officecfg::Office::Common::Misc::ShowTipOfTheDay::set(
m_pShowTip->get_active(), xChanges);
116 if (xVclWin !=
nullptr)
124 ::osl::File aFile(fileName);
125 return aFile.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None;
130 constexpr sal_Int32 nNumberOfTips = std::size(TIPOFTHEDAY_STRINGARRAY);
137 .replaceFirst(
"%CURRENT", OUString::number(
m_nCurrentTip + 1))
138 .replaceFirst(
"%TOTAL", OUString::number(nNumberOfTips)));
145 const OUString aMOD1 =
CuiResId(STR_CMD);
146 const OUString aMOD2 =
CuiResId(STR_Option);
148 const OUString aMOD1 =
CuiResId(STR_CTRL);
149 const OUString aMOD2 =
CuiResId(STR_Alt);
151 m_pText->set_label(
CuiResId(sTip).replaceAll(
"%MOD1", aMOD1).replaceAll(
"%MOD2", aMOD2));
158 else if (sLink.startsWith(
".uno:"))
164 const auto xFrame = pViewFrame->GetFrame().GetFrameInterface();
165 const css::uno::Reference<css::frame::XDispatchProvider> xDispatchProvider(
166 xFrame, css::uno::UNO_QUERY);
167 if (xDispatchProvider.is())
169 css::util::URL aCommandURL;
170 aCommandURL.Complete = sLink;
171 const css::uno::Reference<css::uno::XComponentContext> xContext
173 const css::uno::Reference<css::util::XURLTransformer> xParser
174 = css::util::URLTransformer::create(xContext);
175 xParser->parseStrict(aCommandURL);
176 const css::uno::Reference<css::frame::XDispatch> xDisp
177 = xDispatchProvider->queryDispatch(aCommandURL, OUString(), 0);
183 const OUString aModuleName(
196 else if (sLink.startsWith(
"http"))
201 if (aLang ==
"en" || aLang ==
"pt" || aLang ==
"zh")
203 m_pLink->set_uri(aText.replaceFirst(
"%LANGUAGENAME", aLang));
216 OUString
aURL(
"$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/tipoftheday/");
217 rtl::Bootstrap::expandMacros(
aURL);
218 OUString aImageName = sImage;
225 const OUString sModuleImage[5]
226 = { RID_SVXBMP_TOTD_WRITER, RID_SVXBMP_TOTD_CALC, RID_SVXBMP_TOTD_DRAW,
227 RID_SVXBMP_TOTD_IMPRESS, RID_SVXBMP_TOTD_SOFFICE };
228 const OUString aIconTheme
232 ImageLoadFlags::IgnoreDarkTheme);
247 const OUString sLink = rButton.get_uri();
248 if (sLink.startsWith(
".uno:"))
PropertiesInfo aProperties
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
void SetPreview(const Graphic &rGraphic)
static ErrCode LoadGraphic(const OUString &rPath, const OUString &rFilter, Graphic &rGraphic, GraphicFilter *pFilter=nullptr, sal_uInt16 *pDeterminedFormat=nullptr)
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
virtual bool Start(const OUString &rHelpId, weld::Widget *pWidget=nullptr)
static VCL_DLLPUBLIC ImageTree & get()
VCL_DLLPUBLIC bool loadImage(OUString const &name, OUString const &style, BitmapEx &bitmap, bool localized, const ImageLoadFlags eFlags=ImageLoadFlags::NONE)
OUString getLanguage() const
const OUString & getBcp47(bool bResolveSystem=true) const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
OUString DetermineIconTheme() const
CuiGraphicPreviewWindow m_aPreview
std::unique_ptr< weld::Label > m_pText
TipOfTheDayDialog(weld::Window *pWindow)
std::unique_ptr< weld::LinkButton > m_pLink
std::unique_ptr< weld::CustomWeld > m_pPreview
std::unique_ptr< weld::Button > m_pNext
std::unique_ptr< weld::CheckButton > m_pShowTip
virtual ~TipOfTheDayDialog() override
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
static std::shared_ptr< ConfigurationChanges > create()
static OUString getUILocale()
void response(int nResponse)
std::shared_ptr< weld::Dialog > m_xDialog
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
OUString CuiResId(TranslateId aKey)
#define LINK(Instance, Class, Member)
OUString ExpandVariables(const OUString &rString)
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
Reference< XComponentContext > getProcessComponentContext()
Sequence< beans::PropertyValue > GetCommandProperties(const OUString &rsCommandName, const OUString &rsModuleName)
OUString GetTooltipForCommand(const OUString &rsCommandName, const css::uno::Sequence< css::beans::PropertyValue > &rProperties, const Reference< frame::XFrame > &rxFrame)
OUString GetModuleIdentifier(const Reference< frame::XFrame > &rxFrame)
Reference< XFrame > xFrame
IMPL_LINK_NOARG(TipOfTheDayDialog, OnNextClick, weld::Button &, void)
IMPL_LINK(TipOfTheDayDialog, Terminated, VclWindowEvent &, rEvent, void)
const Size ThumbSize(150, 150)
static bool file_exists(const OUString &fileName)