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>
27 using namespace com::sun::star
;
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::beans
;
32 SvxPersonalizationTabPage::SvxPersonalizationTabPage(weld::Container
* pPage
,
33 weld::DialogController
* pController
,
34 const SfxItemSet
& rSet
)
35 : SfxTabPage(pPage
, pController
, "cui/ui/personalization_tab.ui", "PersonalizationTabPage",
37 , m_xNoPersona(m_xBuilder
->weld_radio_button("no_persona"))
38 , m_xDefaultPersona(m_xBuilder
->weld_radio_button("default_persona"))
40 for (sal_uInt32 i
= 0; i
< MAX_DEFAULT_PERSONAS
; ++i
)
42 OString
sDefaultId("default" + OString::number(i
));
43 m_vDefaultPersonaImages
[i
] = m_xBuilder
->weld_toggle_button(sDefaultId
);
44 m_vDefaultPersonaImages
[i
]->connect_clicked(
45 LINK(this, SvxPersonalizationTabPage
, DefaultPersona
));
51 SvxPersonalizationTabPage::~SvxPersonalizationTabPage() {}
53 std::unique_ptr
<SfxTabPage
> SvxPersonalizationTabPage::Create(weld::Container
* pPage
,
54 weld::DialogController
* pController
,
55 const SfxItemSet
* rSet
)
57 return std::make_unique
<SvxPersonalizationTabPage
>(pPage
, pController
, *rSet
);
60 bool SvxPersonalizationTabPage::FillItemSet(SfxItemSet
*)
63 OUString
aPersona("default");
64 if (m_xNoPersona
->get_active())
67 bool bModified
= false;
68 uno::Reference
<uno::XComponentContext
> xContext(comphelper::getProcessComponentContext());
70 && (aPersona
!= officecfg::Office::Common::Misc::Persona::get(xContext
)
72 != officecfg::Office::Common::Misc::PersonaSettings::get(xContext
)))
78 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(
79 comphelper::ConfigurationChanges::create());
81 m_aPersonaSettings
.clear();
82 officecfg::Office::Common::Misc::Persona::set(aPersona
, batch
);
83 officecfg::Office::Common::Misc::PersonaSettings::set(m_aPersonaSettings
, batch
);
88 // broadcast the change
89 DataChangedEvent
aDataChanged(DataChangedEventType::SETTINGS
, nullptr,
90 AllSettingsFlags::STYLE
);
91 Application::NotifyAllWindows(aDataChanged
);
97 void SvxPersonalizationTabPage::Reset(const SfxItemSet
*)
99 uno::Reference
<uno::XComponentContext
> xContext(comphelper::getProcessComponentContext());
102 OUString
aPersona("default");
105 aPersona
= officecfg::Office::Common::Misc::Persona::get(xContext
);
106 m_aPersonaSettings
= officecfg::Office::Common::Misc::PersonaSettings::get(xContext
);
109 if (aPersona
== "no")
110 m_xNoPersona
->set_active(true);
112 m_xDefaultPersona
->set_active(true);
115 void SvxPersonalizationTabPage::LoadDefaultImages()
117 // Load the pre saved personas
119 OUString gallery
= "$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER
"/gallery/personas/";
120 rtl::Bootstrap::expandMacros(gallery
);
121 OUString aPersonasList
= gallery
+ "personas_list.txt";
122 SvFileStream
aStream(aPersonasList
, StreamMode::READ
);
123 GraphicFilter aFilter
;
125 sal_Int32 nIndex
= 0;
126 bool foundOne
= false;
128 while (aStream
.IsOpen() && !aStream
.eof() && nIndex
< MAX_DEFAULT_PERSONAS
)
131 OUString aPersonaSetting
, aPreviewFile
, aName
;
132 sal_Int32 nParseIndex
= 0;
134 aStream
.ReadLine(aLine
);
135 aPersonaSetting
= OStringToOUString(aLine
, RTL_TEXTENCODING_UTF8
);
136 aName
= aPersonaSetting
.getToken(1, ';', nParseIndex
);
137 aPreviewFile
= aPersonaSetting
.getToken(0, ';', nParseIndex
);
139 if (aPreviewFile
.isEmpty())
142 m_vDefaultPersonaSettings
.push_back(aPersonaSetting
);
144 INetURLObject
aURLObj(gallery
+ aPreviewFile
);
145 aFilter
.ImportGraphic(aGraphic
, aURLObj
);
147 Size
aSize(aGraphic
.GetSizePixel());
148 aSize
.setWidth(aSize
.Width() / 4);
149 aSize
.setHeight(aSize
.Height() / 1.5);
150 ScopedVclPtr
<VirtualDevice
> xVirDev
151 = m_vDefaultPersonaImages
[nIndex
]->create_virtual_device();
152 xVirDev
->SetOutputSizePixel(aSize
);
153 aGraphic
.Draw(xVirDev
.get(), Point(0, 0));
154 m_vDefaultPersonaImages
[nIndex
]->set_image(xVirDev
.get());
155 xVirDev
.disposeAndClear();
157 m_vDefaultPersonaImages
[nIndex
]->set_tooltip_text(aName
);
158 m_vDefaultPersonaImages
[nIndex
++]->show();
162 m_xDefaultPersona
->set_sensitive(foundOne
);
165 IMPL_LINK(SvxPersonalizationTabPage
, DefaultPersona
, weld::Button
&, rButton
, void)
167 m_xDefaultPersona
->set_active(true);
168 for (sal_Int32 nIndex
= 0; nIndex
< MAX_DEFAULT_PERSONAS
; ++nIndex
)
170 if (&rButton
== m_vDefaultPersonaImages
[nIndex
].get())
171 m_aPersonaSettings
= m_vDefaultPersonaSettings
[nIndex
];
173 m_vDefaultPersonaImages
[nIndex
]->set_active(false);
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */