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 
25 using namespace com::sun::star;
26 using namespace ::com::sun::star::uno;
27 using 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  OString sDefaultId("default" + OString::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 
51 std::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  uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
67  if (xContext.is()
68  && (aPersona != officecfg::Office::Common::Misc::Persona::get(xContext)
70  != officecfg::Office::Common::Misc::PersonaSettings::get(xContext)))
71  {
72  bModified = true;
73  }
74 
75  // write
76  std::shared_ptr<comphelper::ConfigurationChanges> batch(
78  if (aPersona == "no")
79  m_aPersonaSettings.clear();
80  officecfg::Office::Common::Misc::Persona::set(aPersona, batch);
81  officecfg::Office::Common::Misc::PersonaSettings::set(m_aPersonaSettings, batch);
82  batch->commit();
83 
84  if (bModified)
85  {
86  // broadcast the change
87  DataChangedEvent aDataChanged(DataChangedEventType::SETTINGS, nullptr,
88  AllSettingsFlags::STYLE);
89  Application::NotifyAllWindows(aDataChanged);
90  }
91 
92  return bModified;
93 }
94 
96 {
97  uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
98 
99  // persona
100  OUString aPersona("default");
101  if (xContext.is())
102  {
103  aPersona = officecfg::Office::Common::Misc::Persona::get(xContext);
104  m_aPersonaSettings = officecfg::Office::Common::Misc::PersonaSettings::get(xContext);
105  }
106 
107  if (aPersona == "no")
108  m_xNoPersona->set_active(true);
109  else
110  m_xDefaultPersona->set_active(true);
111 }
112 
114 {
115  // Load the pre saved personas
116 
117  OUString gallery = "$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/gallery/personas/";
118  rtl::Bootstrap::expandMacros(gallery);
119  OUString aPersonasList = gallery + "personas_list.txt";
120  SvFileStream aStream(aPersonasList, StreamMode::READ);
121  GraphicFilter aFilter;
122  Graphic aGraphic;
123  sal_Int32 nIndex = 0;
124  bool foundOne = false;
125 
126  while (aStream.IsOpen() && !aStream.eof() && nIndex < MAX_DEFAULT_PERSONAS)
127  {
128  OString aLine;
129  OUString aPersonaSetting, aPreviewFile, aName;
130  sal_Int32 nParseIndex = 0;
131 
132  aStream.ReadLine(aLine);
133  aPersonaSetting = OStringToOUString(aLine, RTL_TEXTENCODING_UTF8);
134  aName = aPersonaSetting.getToken(1, ';', nParseIndex);
135  aPreviewFile = aPersonaSetting.getToken(0, ';', nParseIndex);
136 
137  if (aPreviewFile.isEmpty())
138  break;
139 
140  m_vDefaultPersonaSettings.push_back(aPersonaSetting);
141 
142  INetURLObject aURLObj(gallery + aPreviewFile);
143  aFilter.ImportGraphic(aGraphic, aURLObj);
144 
145  Size aSize(aGraphic.GetSizePixel());
146  aSize.setWidth(aSize.Width() / 4);
147  aSize.setHeight(aSize.Height() / 1.5);
149  = m_vDefaultPersonaImages[nIndex]->create_virtual_device();
150  xVirDev->SetOutputSizePixel(aSize);
151  aGraphic.Draw(xVirDev.get(), Point(0, 0));
152  m_vDefaultPersonaImages[nIndex]->set_image(xVirDev.get());
153  xVirDev.disposeAndClear();
154 
155  m_vDefaultPersonaImages[nIndex]->set_tooltip_text(aName);
156  m_vDefaultPersonaImages[nIndex++]->show();
157  foundOne = true;
158  }
159 
160  m_xDefaultPersona->set_sensitive(foundOne);
161 }
162 
163 IMPL_LINK(SvxPersonalizationTabPage, DefaultPersona, weld::Button&, rButton, void)
164 {
165  m_xDefaultPersona->set_active(true);
166  for (sal_Int32 nIndex = 0; nIndex < MAX_DEFAULT_PERSONAS; ++nIndex)
167  {
168  if (&rButton == m_vDefaultPersonaImages[nIndex].get())
169  m_aPersonaSettings = m_vDefaultPersonaSettings[nIndex];
170  else
171  m_vDefaultPersonaImages[nIndex]->set_active(false);
172  }
173 }
174 
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::RadioButton > m_xNoPersona
Just the default look, without any bitmap.
sal_Int32 nIndex
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
void setWidth(tools::Long nWidth)
static void NotifyAllWindows(DataChangedEvent &rDCEvt)
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
virtual void Reset(const SfxItemSet *rSet) override
Reset to default settings ([Revert] button).
OUString m_aPersonaSettings
Header and footer images + color to be set in the settings.
bool eof() const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
bool ReadLine(OString &rStr, sal_Int32 nMaxBytesToRead=0xFFFE)
static std::shared_ptr< ConfigurationChanges > create(css::uno::Reference< css::uno::XComponentContext > const &context=comphelper::getProcessComponentContext())
void Draw(OutputDevice *pOutDev, const Point &rDestPt) const
int i
exports com.sun.star. gallery
SvxPersonalizationTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
std::unique_ptr< weld::ToggleButton > m_vDefaultPersonaImages[MAX_DEFAULT_PERSONAS]
Buttons to show the default persona images.
std::vector< OUString > m_vDefaultPersonaSettings
#define MAX_DEFAULT_PERSONAS
virtual bool FillItemSet(SfxItemSet *rSet) override
Apply the settings ([OK] button).
OUString aName
virtual ~SvxPersonalizationTabPage() override
IMPL_LINK(SvxPersonalizationTabPage, DefaultPersona, weld::Button &, rButton, void)
Reference< XComponentContext > getProcessComponentContext()
VirtualDevice * get() const
std::unique_ptr< weld::RadioButton > m_xDefaultPersona
Use the built-in bitmap.
bool IsOpen() const