LibreOffice Module cui (master) 1
personalization.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#include <config_folders.h>
11
12#include "personalization.hxx"
13
15#include <officecfg/Office/Common.hxx>
16#include <rtl/bootstrap.hxx>
17#include <tools/urlobj.hxx>
18#include <tools/stream.hxx>
19#include <vcl/event.hxx>
20#include <vcl/svapp.hxx>
21#include <vcl/settings.hxx>
22#include <vcl/graphicfilter.hxx>
23#include <vcl/virdev.hxx>
24
25using namespace com::sun::star;
26using namespace ::com::sun::star::uno;
27using namespace ::com::sun::star::beans;
28
29// persona
31 weld::DialogController* pController,
32 const SfxItemSet& rSet)
33 : SfxTabPage(pPage, pController, "cui/ui/personalization_tab.ui", "PersonalizationTabPage",
34 &rSet)
35 , m_xNoPersona(m_xBuilder->weld_radio_button("no_persona"))
36 , m_xDefaultPersona(m_xBuilder->weld_radio_button("default_persona"))
37{
38 for (sal_uInt32 i = 0; i < MAX_DEFAULT_PERSONAS; ++i)
39 {
40 OUString sDefaultId("default" + OUString::number(i));
41 m_vDefaultPersonaImages[i] = m_xBuilder->weld_toggle_button(sDefaultId);
42 m_vDefaultPersonaImages[i]->connect_clicked(
43 LINK(this, SvxPersonalizationTabPage, DefaultPersona));
44 }
45
47}
48
50
51std::unique_ptr<SfxTabPage> SvxPersonalizationTabPage::Create(weld::Container* pPage,
52 weld::DialogController* pController,
53 const SfxItemSet* rSet)
54{
55 return std::make_unique<SvxPersonalizationTabPage>(pPage, pController, *rSet);
56}
57
59{
60 // persona
61 OUString aPersona("default");
62 if (m_xNoPersona->get_active())
63 aPersona = "no";
64
65 bool bModified = false;
66 if (aPersona != officecfg::Office::Common::Misc::Persona::get()
67 || m_aPersonaSettings != officecfg::Office::Common::Misc::PersonaSettings::get())
68 {
69 bModified = true;
70 }
71
72 // write
73 std::shared_ptr<comphelper::ConfigurationChanges> batch(
75 if (aPersona == "no")
76 m_aPersonaSettings.clear();
77 officecfg::Office::Common::Misc::Persona::set(aPersona, batch);
78 officecfg::Office::Common::Misc::PersonaSettings::set(m_aPersonaSettings, batch);
79 batch->commit();
80
81 if (bModified)
82 {
83 // broadcast the change
84 DataChangedEvent aDataChanged(DataChangedEventType::SETTINGS, nullptr,
85 AllSettingsFlags::STYLE);
87 }
88
89 return bModified;
90}
91
93{
94 // persona
95 OUString aPersona = officecfg::Office::Common::Misc::Persona::get();
96 m_aPersonaSettings = officecfg::Office::Common::Misc::PersonaSettings::get();
97
98 if (aPersona == "no")
99 m_xNoPersona->set_active(true);
100 else
101 m_xDefaultPersona->set_active(true);
102}
103
105{
106 // Load the pre saved personas
107
108 OUString gallery = "$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/gallery/personas/";
109 rtl::Bootstrap::expandMacros(gallery);
110 OUString aPersonasList = gallery + "personas_list.txt";
111 SvFileStream aStream(aPersonasList, StreamMode::READ);
112 GraphicFilter aFilter;
113 Graphic aGraphic;
114 sal_Int32 nIndex = 0;
115 bool foundOne = false;
116
117 OStringBuffer aLine;
118 while (aStream.IsOpen() && !aStream.eof() && nIndex < MAX_DEFAULT_PERSONAS)
119 {
120 OUString aPersonaSetting, aPreviewFile, aName;
121 sal_Int32 nParseIndex = 0;
122
123 aStream.ReadLine(aLine);
124 aPersonaSetting = OStringToOUString(aLine, RTL_TEXTENCODING_UTF8);
125 aName = aPersonaSetting.getToken(1, ';', nParseIndex);
126 aPreviewFile = aPersonaSetting.getToken(0, ';', nParseIndex);
127
128 if (aPreviewFile.isEmpty())
129 break;
130
131 m_vDefaultPersonaSettings.push_back(aPersonaSetting);
132
133 INetURLObject aURLObj(rtl::Concat2View(gallery + aPreviewFile));
134 aFilter.ImportGraphic(aGraphic, aURLObj);
135
136 Size aSize(aGraphic.GetSizePixel());
137 aSize.setWidth(aSize.Width() / 4);
138 aSize.setHeight(aSize.Height() / 1.5);
140 = m_vDefaultPersonaImages[nIndex]->create_virtual_device();
141 xVirDev->SetOutputSizePixel(aSize);
142 aGraphic.Draw(*xVirDev, Point(0, 0));
143 m_vDefaultPersonaImages[nIndex]->set_image(xVirDev.get());
144 xVirDev.disposeAndClear();
145
146 m_vDefaultPersonaImages[nIndex]->set_tooltip_text(aName);
148 foundOne = true;
149 }
150
151 m_xDefaultPersona->set_sensitive(foundOne);
152}
153
154IMPL_LINK(SvxPersonalizationTabPage, DefaultPersona, weld::Button&, rButton, void)
155{
156 m_xDefaultPersona->set_active(true);
157 for (sal_Int32 nIndex = 0; nIndex < MAX_DEFAULT_PERSONAS; ++nIndex)
158 {
159 if (&rButton == m_vDefaultPersonaImages[nIndex].get())
160 m_aPersonaSettings = m_vDefaultPersonaSettings[nIndex];
161 else
162 m_vDefaultPersonaImages[nIndex]->set_active(false);
163 }
164}
165
166/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void NotifyAllWindows(DataChangedEvent &rDCEvt)
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
void Draw(OutputDevice &rOutDev, const Point &rDestPt) const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
bool IsOpen() const
bool eof() const
bool ReadLine(OStringBuffer &rStr, sal_Int32 nMaxBytesToRead=0xFFFE)
SvxPersonalizationTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
virtual void Reset(const SfxItemSet *rSet) override
Reset to default settings ([Revert] button).
std::unique_ptr< weld::ToggleButton > m_vDefaultPersonaImages[MAX_DEFAULT_PERSONAS]
Buttons to show the default persona images.
virtual ~SvxPersonalizationTabPage() override
std::unique_ptr< weld::RadioButton > m_xDefaultPersona
Use the built-in bitmap.
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
OUString m_aPersonaSettings
Header and footer images + color to be set in the settings.
std::unique_ptr< weld::RadioButton > m_xNoPersona
Just the default look, without any bitmap.
virtual bool FillItemSet(SfxItemSet *rSet) override
Apply the settings ([OK] button).
std::vector< OUString > m_vDefaultPersonaSettings
void disposeAndClear()
reference_type * get() const
static std::shared_ptr< ConfigurationChanges > create()
sal_Int32 nIndex
OUString aName
int i
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
IMPL_LINK(SvxPersonalizationTabPage, DefaultPersona, weld::Button &, rButton, void)
#define MAX_DEFAULT_PERSONAS
static SfxItemSet & rSet