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 #ifndef INCLUDED_DBACCESS_SOURCE_UI_DLG_DBFINDEX_HXX
21 #define INCLUDED_DBACCESS_SOURCE_UI_DLG_DBFINDEX_HXX
22 
23 #include <vcl/weld.hxx>
24 #include <deque>
25 
26 namespace dbaui
27 {
28 
29 // OTableIndex
30 /// represents a single dbf index
31 class OTableIndex
32 {
33 private:
34     OUString aIndexFileName;
35 
36 public:
OTableIndex()37     OTableIndex() { }
OTableIndex(const OUString & rFileName)38     explicit OTableIndex( const OUString& rFileName ) : aIndexFileName( rFileName ) { }
39 
GetIndexFileName() const40     const OUString& GetIndexFileName() const { return aIndexFileName; }
41 };
42 
43 typedef std::deque< OTableIndex >  TableIndexList;
44 
45 // OTableInfo
46 class ODbaseIndexDialog;
47 /** holds the INF file of a table
48 */
49 class OTableInfo
50 {
51     friend class ODbaseIndexDialog;
52 private:
53     OUString aTableName;
54     TableIndexList aIndexList;
55 
56 public:
OTableInfo(const OUString & rName)57     explicit OTableInfo( const OUString& rName ) : aTableName(rName) { }
58 
59     void WriteInfFile( const OUString& rDSN ) const;
60 };
61 
62 typedef std::deque< OTableInfo >   TableInfoList;
63 
64 // IndexDialog
65 class ODbaseIndexDialog : public weld::GenericDialogController
66 {
67 protected:
68     OUString            m_aDSN;
69     TableInfoList       m_aTableInfoList;
70     TableIndexList      m_aFreeIndexList;
71 
72     std::unique_ptr<weld::Button> m_xPB_OK;
73     std::unique_ptr<weld::ComboBox> m_xCB_Tables;
74     std::unique_ptr<weld::Widget> m_xIndexes;
75     std::unique_ptr<weld::TreeView> m_xLB_TableIndexes;
76     std::unique_ptr<weld::TreeView> m_xLB_FreeIndexes;
77 
78     std::unique_ptr<weld::Button> m_xAdd;
79     std::unique_ptr<weld::Button> m_xRemove;
80     std::unique_ptr<weld::Button> m_xAddAll;
81     std::unique_ptr<weld::Button> m_xRemoveAll;
82 
83     DECL_LINK( TableSelectHdl, weld::ComboBox&, void );
84     DECL_LINK( AddClickHdl, weld::Button&, void );
85     DECL_LINK( RemoveClickHdl, weld::Button&, void );
86     DECL_LINK( AddAllClickHdl, weld::Button&, void );
87     DECL_LINK( RemoveAllClickHdl, weld::Button&, void );
88     DECL_LINK( OKClickHdl, weld::Button&, void );
89     DECL_LINK( OnListEntrySelected, weld::TreeView&, void );
90 
91     void        Init();
92     void        SetCtrls();
93 
94     static OTableIndex implRemoveIndex(const OUString& _rName, TableIndexList& _rList, weld::TreeView& _rDisplay, bool _bMustExist);
95     static void implInsertIndex(const OTableIndex& _rIndex, TableIndexList& _rList, weld::TreeView& _rDisplay);
96 
RemoveFreeIndex(const OUString & _rName,bool _bMustExist)97     OTableIndex RemoveFreeIndex( const OUString& _rName, bool _bMustExist ) { return implRemoveIndex(_rName, m_aFreeIndexList, *m_xLB_FreeIndexes, _bMustExist); }
InsertFreeIndex(const OTableIndex & _rIndex)98     void        InsertFreeIndex( const OTableIndex& _rIndex ) { implInsertIndex(_rIndex, m_aFreeIndexList, *m_xLB_FreeIndexes); }
99     OTableIndex RemoveTableIndex( const OUString& _rTableName, const OUString& _rIndexName );
100     void        InsertTableIndex( const OUString& _rTableName, const OTableIndex& _rIndex );
101 
102     void checkButtons();
103 
104 public:
105     ODbaseIndexDialog(weld::Window * pParent, const OUString& rDataSrcName);
106     virtual ~ODbaseIndexDialog() override;
107 };
108 
109 }   // namespace dbaui
110 
111 #endif // INCLUDED_DBACCESS_SOURCE_UI_DLG_DBFINDEX_HXX
112 
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
114