1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <config_folders.h>
12 #include "personalization.hxx"
14 #include <comphelper/processfactory.hxx>
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>
25 using namespace com::sun::star
;
26 using namespace ::com::sun::star::uno
;
27 using namespace ::com::sun::star::beans
;
30 SvxPersonalizationTabPage::SvxPersonalizationTabPage(weld::Container
* pPage
,
31 weld::DialogController
* pController
,
32 const SfxItemSet
& rSet
)
33 : SfxTabPage(pPage
, pController
, "cui/ui/personalization_tab.ui", "PersonalizationTabPage",
35 , m_xNoPersona(m_xBuilder
->weld_radio_button("no_persona"))
36 , m_xDefaultPersona(m_xBuilder
->weld_radio_button("default_persona"))
38 for (sal_uInt32 i
= 0; i
< MAX_DEFAULT_PERSONAS
; ++i
)
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
));
49 SvxPersonalizationTabPage::~SvxPersonalizationTabPage() {}
51 std::unique_ptr
<SfxTabPage
> SvxPersonalizationTabPage::Create(weld::Container
* pPage
,
52 weld::DialogController
* pController
,
53 const SfxItemSet
* rSet
)
55 return std::make_unique
<SvxPersonalizationTabPage
>(pPage
, pController
, *rSet
);
58 bool SvxPersonalizationTabPage::FillItemSet(SfxItemSet
*)
61 OUString
aPersona("default");
62 if (m_xNoPersona
->get_active())
65 bool bModified
= false;
66 if (aPersona
!= officecfg::Office::Common::Misc::Persona::get()
67 || m_aPersonaSettings
!= officecfg::Office::Common::Misc::PersonaSettings::get())
73 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(
74 comphelper::ConfigurationChanges::create());
76 m_aPersonaSettings
.clear();
77 officecfg::Office::Common::Misc::Persona::set(aPersona
, batch
);
78 officecfg::Office::Common::Misc::PersonaSettings::set(m_aPersonaSettings
, batch
);
83 // broadcast the change
84 DataChangedEvent
aDataChanged(DataChangedEventType::SETTINGS
, nullptr,
85 AllSettingsFlags::STYLE
);
86 Application::NotifyAllWindows(aDataChanged
);
92 void SvxPersonalizationTabPage::Reset(const SfxItemSet
*)
95 OUString aPersona
= officecfg::Office::Common::Misc::Persona::get();
96 m_aPersonaSettings
= officecfg::Office::Common::Misc::PersonaSettings::get();
99 m_xNoPersona
->set_active(true);
101 m_xDefaultPersona
->set_active(true);
104 void SvxPersonalizationTabPage::LoadDefaultImages()
106 // Load the pre saved personas
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
;
114 sal_Int32 nIndex
= 0;
115 bool foundOne
= false;
118 while (aStream
.IsOpen() && !aStream
.eof() && nIndex
< MAX_DEFAULT_PERSONAS
)
120 OUString aPersonaSetting
, aPreviewFile
, aName
;
121 sal_Int32 nParseIndex
= 0;
123 aStream
.ReadLine(aLine
);
124 aPersonaSetting
= OStringToOUString(aLine
, RTL_TEXTENCODING_UTF8
);
125 aName
= aPersonaSetting
.getToken(1, ';', nParseIndex
);
126 aPreviewFile
= aPersonaSetting
.getToken(0, ';', nParseIndex
);
128 if (aPreviewFile
.isEmpty())
131 m_vDefaultPersonaSettings
.push_back(aPersonaSetting
);
133 INetURLObject
aURLObj(rtl::Concat2View(gallery
+ aPreviewFile
));
134 aFilter
.ImportGraphic(aGraphic
, aURLObj
);
136 Size
aSize(aGraphic
.GetSizePixel());
137 aSize
.setWidth(aSize
.Width() / 4);
138 aSize
.setHeight(aSize
.Height() / 1.5);
139 ScopedVclPtr
<VirtualDevice
> xVirDev
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();
146 m_vDefaultPersonaImages
[nIndex
]->set_tooltip_text(aName
);
147 m_vDefaultPersonaImages
[nIndex
++]->show();
151 m_xDefaultPersona
->set_sensitive(foundOne
);
154 IMPL_LINK(SvxPersonalizationTabPage
, DefaultPersona
, weld::Button
&, rButton
, void)
156 m_xDefaultPersona
->set_active(true);
157 for (sal_Int32 nIndex
= 0; nIndex
< MAX_DEFAULT_PERSONAS
; ++nIndex
)
159 if (&rButton
== m_vDefaultPersonaImages
[nIndex
].get())
160 m_aPersonaSettings
= m_vDefaultPersonaSettings
[nIndex
];
162 m_vDefaultPersonaImages
[nIndex
]->set_active(false);
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */