LibreOffice Module cui (master) 1
dbregister.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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/config.h>
21
22#include <string_view>
23
24#include <dbregister.hxx>
26#include <o3tl/safeint.hxx>
27#include <svl/filenotation.hxx>
28#include <helpids.h>
29#include <tools/debug.hxx>
30#include <strings.hrc>
31#include <bitmaps.hlst>
32#include <utility>
33#include <vcl/svapp.hxx>
34#include <vcl/weld.hxx>
35#include <svl/itemset.hxx>
36#include "doclinkdialog.hxx"
37#include <dialmgr.hxx>
40#include <o3tl/string_view.hxx>
41
42#define COL_TYPE 0
43
44namespace svx
45{
46
47
48using namespace ::com::sun::star::lang;
49using namespace ::com::sun::star::ui::dialogs;
50using namespace ::com::sun::star::uno;
51using namespace ::svt;
52
53// class RegistrationItemSetHolder -------------------------------------------------
54
56 :m_aRegistrationItems(std::move( _aMasterSet ))
57{
59}
60
62{
63}
64
65// class DatabaseRegistrationDialog ------------------------------------------------
66
69 , SfxSingleTabDialogController(pParent, &getRegistrationItems())
70{
72 m_xDialog->set_title(CuiResId(RID_CUISTR_REGISTERED_DATABASES));
73}
74
76{
77 short result = SfxSingleTabDialogController::run();
78 if (result == RET_OK)
79 {
80 DBG_ASSERT( GetOutputItemSet(), "DatabaseRegistrationDialog::Execute: no output items!" );
81 if ( GetOutputItemSet() )
83 }
84 return result;
85}
86
87// class DbRegistrationOptionsPage --------------------------------------------------
88
90 : SfxTabPage(pPage, pController, "cui/ui/dbregisterpage.ui", "DbRegisterPage", &rSet)
91 , m_nOldCount(0)
92 , m_bModified(false)
93 , m_xNew(m_xBuilder->weld_button("new"))
94 , m_xEdit(m_xBuilder->weld_button("edit"))
95 , m_xDelete(m_xBuilder->weld_button("delete"))
96 , m_xPathBox(m_xBuilder->weld_tree_view("pathctrl"))
97 , m_xIter(m_xPathBox->make_iterator())
98{
99 Size aControlSize(m_xPathBox->get_approximate_digit_width() * 60,
100 m_xPathBox->get_height_rows(12));
101 m_xPathBox->set_size_request(aControlSize.Width(), aControlSize.Height());
102
103 std::vector<int> aWidths
104 {
105 o3tl::narrowing<int>(m_xPathBox->get_approximate_digit_width() * 20)
106 };
107 m_xPathBox->set_column_fixed_widths(aWidths);
108
109 m_xNew->connect_clicked( LINK( this, DbRegistrationOptionsPage, NewHdl ) );
110 m_xEdit->connect_clicked( LINK( this, DbRegistrationOptionsPage, EditHdl ) );
111 m_xDelete->connect_clicked( LINK( this, DbRegistrationOptionsPage, DeleteHdl ) );
112
113 m_xPathBox->connect_column_clicked(LINK(this, DbRegistrationOptionsPage, HeaderSelect_Impl));
114
115 m_xPathBox->make_sorted();
116 m_xPathBox->connect_row_activated( LINK( this, DbRegistrationOptionsPage, PathBoxDoubleClickHdl ) );
117 m_xPathBox->connect_changed( LINK( this, DbRegistrationOptionsPage, PathSelect_Impl ) );
118
119 m_xPathBox->set_help_id(HID_DBPATH_CTL_PATH);
120}
121
123{
124 for (int i = 0, nCount = m_xPathBox->n_children(); i < nCount; ++i )
125 delete weld::fromId<DatabaseRegistration*>(m_xPathBox->get_id(i));
126}
127
128std::unique_ptr<SfxTabPage> DbRegistrationOptionsPage::Create( weld::Container* pPage, weld::DialogController* pController,
129 const SfxItemSet* rAttrSet )
130{
131 return std::make_unique<DbRegistrationOptionsPage>(pPage, pController, *rAttrSet);
132}
133
135{
136 // the settings for the single drivers
137 bool bModified = false;
138 DatabaseRegistrations aRegistrations;
139 int nCount = m_xPathBox->n_children();
140 for (int i = 0; i < nCount; ++i)
141 {
142 DatabaseRegistration* pRegistration = weld::fromId<DatabaseRegistration*>(m_xPathBox->get_id(i));
143 if ( pRegistration && !pRegistration->sLocation.isEmpty() )
144 {
145 OUString sName(m_xPathBox->get_text(i, 0));
146 OFileNotation aTransformer( pRegistration->sLocation );
147 aRegistrations[ sName ] = DatabaseRegistration( aTransformer.get( OFileNotation::N_URL ), pRegistration->bReadOnly );
148 }
149 }
150 if ( m_nOldCount != aRegistrations.size() || m_bModified )
151 {
152 rCoreSet->Put(DatabaseMapItem( SID_SB_DB_REGISTER, std::move(aRegistrations) ));
153 bModified = true;
154 }
155
156 return bModified;
157}
158
160{
161 // the settings for the single drivers
163 if ( !pRegistrations )
164 return;
165
166 m_xPathBox->clear();
167
168 const DatabaseRegistrations& rRegistrations = pRegistrations->getRegistrations();
169 m_nOldCount = rRegistrations.size();
170 for (auto const& elem : rRegistrations)
171 {
172 OFileNotation aTransformer( elem.second.sLocation );
173 insertNewEntry( elem.first, aTransformer.get( OFileNotation::N_SYSTEM ), elem.second.bReadOnly );
174 }
175
176 OUString aUserData = GetUserData();
177 if ( aUserData.isEmpty() )
178 return;
179
180 sal_Int32 nIdx {0};
181 // restore column width
182 std::vector<int> aWidths
183 {
184 o3tl::toInt32(o3tl::getToken(aUserData, 0, ';', nIdx))
185 };
186 m_xPathBox->set_column_fixed_widths(aWidths);
187 // restore sort direction
188 bool bUp = o3tl::toInt32(o3tl::getToken(aUserData, 0, ';', nIdx)) != 0;
189 m_xPathBox->set_sort_order(bUp);
190 m_xPathBox->set_sort_indicator(bUp ? TRISTATE_TRUE : TRISTATE_FALSE, COL_TYPE);
191}
192
194{
195 OUString aUserData = OUString::number( m_xPathBox->get_column_width(COL_TYPE) ) + ";";
196 bool bUp = m_xPathBox->get_sort_order();
197 aUserData += (bUp ? std::u16string_view(u"1") : std::u16string_view(u"0"));
198 SetUserData( aUserData );
199}
200
202{
203 int nEntry = m_xPathBox->get_selected_index();
204 if (nEntry != -1)
205 {
206 std::unique_ptr<weld::MessageDialog> xQuery(Application::CreateMessageDialog(GetFrameWeld(),
207 VclMessageType::Question, VclButtonsType::YesNo, CuiResId(RID_CUISTR_QUERY_DELETE_CONFIRM)));
208 if (xQuery->run() == RET_YES)
209 m_xPathBox->remove(nEntry);
210 }
211}
212
214{
215 openLinkDialog(OUString(),OUString());
216}
217
219{
220 EditHdl(*m_xEdit);
221 return true;
222}
223
225{
226 int nEntry = m_xPathBox->get_selected_index();
227 if (nEntry == -1)
228 return;
229
230 DatabaseRegistration* pOldRegistration = weld::fromId<DatabaseRegistration*>(m_xPathBox->get_id(nEntry));
231 if (!pOldRegistration || pOldRegistration->bReadOnly)
232 return;
233
234 OUString sOldName = m_xPathBox->get_text(nEntry, 0);
235 openLinkDialog(sOldName, pOldRegistration->sLocation, nEntry);
236}
237
238IMPL_LINK( DbRegistrationOptionsPage, HeaderSelect_Impl, int, nCol, void )
239{
240 if (nCol != COL_TYPE)
241 return;
242
243 bool bSortMode = m_xPathBox->get_sort_order();
244
245 //set new arrow positions in headerbar
246 bSortMode = !bSortMode;
247 m_xPathBox->set_sort_order(bSortMode);
248
249 //sort lists
250 m_xPathBox->set_sort_indicator(bSortMode ? TRISTATE_TRUE : TRISTATE_FALSE, nCol);
251}
252
254{
255 DatabaseRegistration* pRegistration = weld::fromId<DatabaseRegistration*>(m_xPathBox->get_selected_id());
256
257 bool bReadOnly = true;
258 if (pRegistration)
259 {
260 bReadOnly = pRegistration->bReadOnly;
261 }
262
263 m_xEdit->set_sensitive( !bReadOnly );
264 m_xDelete->set_sensitive( !bReadOnly );
265}
266
267void DbRegistrationOptionsPage::insertNewEntry(const OUString& _sName,const OUString& _sLocation, const bool _bReadOnly)
268{
269 OUString sId(weld::toId(new DatabaseRegistration(_sLocation, _bReadOnly)));
270 m_xPathBox->insert(nullptr, -1, &_sName, &sId, nullptr, nullptr, false, m_xIter.get());
271
272 if (_bReadOnly)
273 m_xPathBox->set_image(*m_xIter, RID_SVXBMP_LOCK);
274
275 m_xPathBox->set_text(*m_xIter, _sLocation, 1);
276}
277
278void DbRegistrationOptionsPage::openLinkDialog(const OUString& sOldName, const OUString& sOldLocation, int nEntry)
279{
280 ODocumentLinkDialog aDlg(GetFrameWeld(), nEntry == -1);
281
282 aDlg.setLink(sOldName, sOldLocation);
283 aDlg.setNameValidator(LINK( this, DbRegistrationOptionsPage, NameValidator ) );
284
285 if (aDlg.run() != RET_OK)
286 return;
287
288 OUString sNewName,sNewLocation;
289 aDlg.getLink(sNewName,sNewLocation);
290 if ( nEntry == -1 || sNewName != sOldName || sNewLocation != sOldLocation )
291 {
292 if (nEntry != -1)
293 {
294 delete weld::fromId<DatabaseRegistration*>(m_xPathBox->get_id(nEntry));
295 m_xPathBox->remove(nEntry);
296 }
297 insertNewEntry( sNewName, sNewLocation, false );
298 m_bModified = true;
299 }
300}
301
302IMPL_LINK( DbRegistrationOptionsPage, NameValidator, const OUString&, _rName, bool )
303{
304 int nCount = m_xPathBox->n_children();
305 for (int i = 0; i < nCount; ++i)
306 {
307 if (m_xPathBox->get_text(i, 0) == _rName)
308 return false;
309 }
310 return true;
311}
312
313}
314
315/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxItemSet * GetOutputItemSet() const
void SetTabPage(std::unique_ptr< SfxTabPage > xTabPage)
weld::Container * get_content_area()
void SetUserData(const OUString &rString)
const OUString & GetUserData() const
weld::Window * GetFrameWeld() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const DatabaseRegistrations & getRegistrations() const
virtual short run() override
Definition: dbregister.cxx:75
DatabaseRegistrationDialog(weld::Window *pParent, const SfxItemSet &rAttr)
Definition: dbregister.cxx:67
static void SetOptions(const SfxItemSet &_rSourceItems)
static void GetOptions(SfxItemSet &_rFillItems)
virtual void Reset(const SfxItemSet *rSet) override
Definition: dbregister.cxx:159
virtual ~DbRegistrationOptionsPage() override
Definition: dbregister.cxx:122
std::unique_ptr< weld::Button > m_xDelete
Definition: dbregister.hxx:38
std::unique_ptr< weld::Button > m_xEdit
Definition: dbregister.hxx:37
std::unique_ptr< weld::Button > m_xNew
Definition: dbregister.hxx:36
std::unique_ptr< weld::TreeView > m_xPathBox
Definition: dbregister.hxx:39
DbRegistrationOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: dbregister.cxx:89
void insertNewEntry(const OUString &_sName, const OUString &_sLocation, const bool bReadOnly)
inserts a new entry in the tablistbox
Definition: dbregister.cxx:267
void openLinkDialog(const OUString &sOldName, const OUString &sOldLocation, int nEntry=-1)
opens the LinkDialog to create a register pair
Definition: dbregister.cxx:278
std::unique_ptr< weld::TreeIter > m_xIter
Definition: dbregister.hxx:40
virtual void FillUserData() override
Definition: dbregister.cxx:193
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: dbregister.cxx:128
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: dbregister.cxx:134
dialog for editing document links associated with data sources
void setNameValidator(const Link< const OUString &, bool > &_rValidator)
void setLink(const OUString &_rName, const OUString &_rURL)
void getLink(OUString &_rName, OUString &_rURL) const
helper for DatabaseRegistrationDialog
Definition: dbregister.hxx:87
RegistrationItemSetHolder(SfxItemSet _aMasterSet)
Definition: dbregister.cxx:55
const SfxItemSet & getRegistrationItems() const
Definition: dbregister.hxx:96
virtual short run()
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
int nCount
#define SID_SB_DB_REGISTER
#define COL_TYPE
Definition: dbregister.cxx:42
#define DBG_ASSERT(sCon, aError)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
float u
OUString sName
bool bReadOnly
TRISTATE_FALSE
TRISTATE_TRUE
constexpr OUStringLiteral HID_DBPATH_CTL_PATH
Definition: helpids.h:26
int i
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
IMPL_LINK(ClassificationDialog, SelectClassificationHdl, weld::ComboBox &, rBox, void)
IMPL_LINK_NOARG(ClassificationDialog, OnAsyncExpandHdl, void *, void)
std::map< OUString, DatabaseRegistration > DatabaseRegistrations
OUString toId(const void *pValue)
static SfxItemSet & rSet
Any result
OUString sId
RET_OK
RET_YES