fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / dlg / dsselect.cxx
bloba812a6b1afcb51a73fdec8b75ebfd0c7018174de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "dsselect.hxx"
21 #include "dbu_dlg.hrc"
22 #include <vcl/msgbox.hxx>
23 #include "localresaccess.hxx"
24 #include <tools/rcid.h>
26 #include <com/sun/star/sdbcx/XCreateCatalog.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/beans/XPropertySetInfo.hpp>
29 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
30 #include <com/sun/star/awt/XWindow.hpp>
31 #include "dbustrings.hrc"
32 #include <toolkit/helper/vclunohelper.hxx>
33 #include <comphelper/extract.hxx>
34 #include <comphelper/types.hxx>
35 #include <comphelper/processfactory.hxx>
36 #include "dsitems.hxx"
37 #include <svl/stritem.hxx>
38 #include <svl/intitem.hxx>
39 #include <svl/eitem.hxx>
40 #include <svl/itemset.hxx>
42 namespace dbaui
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::beans;
46 using namespace ::com::sun::star::sdbc;
47 using namespace ::com::sun::star::sdbcx;
48 using namespace ::com::sun::star::ui::dialogs;
49 using namespace ::comphelper;
50 ODatasourceSelectDialog::ODatasourceSelectDialog(vcl::Window* _pParent, const StringBag& _rDatasources, SfxItemSet* _pOutputSet)
51 : ModalDialog(_pParent, "ChooseDataSourceDialog",
52 "dbaccess/ui/choosedatasourcedialog.ui")
53 , m_pOutputSet(_pOutputSet)
55 get(m_pDatasource, "treeview");
56 m_pDatasource->set_height_request(m_pDatasource->GetTextHeight() * 6);
57 get(m_pOk, "ok");
58 get(m_pCancel, "cancel");
60 fillListBox(_rDatasources);
61 #ifdef HAVE_ODBC_ADMINISTRATION
62 get(m_pManageDatasources, "organize");
63 m_pManageDatasources->Show();
65 // allow ODBC datasource managenment
66 m_pManageDatasources->Show();
67 m_pManageDatasources->Enable();
68 m_pManageDatasources->SetClickHdl(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
69 #endif
70 m_pDatasource->SetDoubleClickHdl(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
73 ODatasourceSelectDialog::~ODatasourceSelectDialog()
75 disposeOnce();
78 void ODatasourceSelectDialog::dispose()
80 m_pDatasource.clear();
81 m_pOk.clear();
82 m_pCancel.clear();
83 ModalDialog::dispose();
87 IMPL_LINK( ODatasourceSelectDialog, ListDblClickHdl, ListBox *, pListBox )
89 if (pListBox->GetSelectEntryCount())
90 EndDialog(RET_OK);
91 return 0;
94 bool ODatasourceSelectDialog::Close()
96 #ifdef HAVE_ODBC_ADMINISTRATION
97 if ( m_pODBCManagement.get() && m_pODBCManagement->isRunning() )
98 return sal_False;
99 #endif
101 return ModalDialog::Close();
104 #ifdef HAVE_ODBC_ADMINISTRATION
105 IMPL_LINK_NOARG(ODatasourceSelectDialog, ManageClickHdl)
107 if ( !m_pODBCManagement.get() )
108 m_pODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) );
110 if ( !m_pODBCManagement->manageDataSources_async() )
112 // TODO: error message
113 m_pDatasource->GrabFocus();
114 m_pManageDatasources->Disable();
115 return 1L;
118 m_pDatasource->Disable();
119 m_pOk->Disable();
120 m_pCancel->Disable();
121 m_pManageDatasources->Disable();
123 SAL_WARN_IF( !m_pODBCManagement->isRunning(), "dbaccess.ui", "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
124 return 0L;
127 IMPL_LINK_NOARG( ODatasourceSelectDialog, ManageProcessFinished )
129 StringBag aOdbcDatasources;
130 OOdbcEnumeration aEnumeration;
131 aEnumeration.getDatasourceNames( aOdbcDatasources );
132 fillListBox( aOdbcDatasources );
134 m_pDatasource->Enable();
135 m_pOk->Enable();
136 m_pCancel->Enable();
137 m_pManageDatasources->Enable();
139 return 0L;
142 #endif
143 void ODatasourceSelectDialog::fillListBox(const StringBag& _rDatasources)
145 OUString sSelected;
146 if (m_pDatasource->GetEntryCount())
147 sSelected = m_pDatasource->GetSelectEntry();
148 m_pDatasource->Clear();
149 // fill the list
150 for ( StringBag::const_iterator aDS = _rDatasources.begin();
151 aDS != _rDatasources.end();
152 ++aDS
155 m_pDatasource->InsertEntry( *aDS );
158 if (m_pDatasource->GetEntryCount())
160 if (!sSelected.isEmpty())
161 m_pDatasource->SelectEntry(sSelected);
162 else // select the first entry
163 m_pDatasource->SelectEntryPos(0);
167 } // namespace dbaui
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */