Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/inc/autoredactdialog.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10
#ifndef INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX
11
#define INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX
12
13
#include <memory>
14
#include <sal/config.h>
15
#include <sfx2/basedlgs.hxx>
16
#include <sfx2/objsh.hxx>
17
#include <vcl/weld/Button.hxx>
18
#include <vcl/weld/CheckButton.hxx>
19
#include <vcl/weld/ComboBox.hxx>
20
#include <vcl/weld/DialogController.hxx>
21
#include <vcl/weld/Entry.hxx>
22
#include <vcl/weld/Label.hxx>
23
#include <vcl/weld/TreeView.hxx>
24
25
enum RedactionTargetType
26
{
27
    REDACTION_TARGET_TEXT,
28
    REDACTION_TARGET_REGEX,
29
    REDACTION_TARGET_PREDEFINED,
30
    REDACTION_TARGET_IMAGE,
31
    REDACTION_TARGET_UNKNOWN
32
};
33
34
/// Keeps information for a single redaction target
35
struct RedactionTarget
36
{
37
    OUString sName;
38
    RedactionTargetType sType;
39
    OUString sContent;
40
    bool bCaseSensitive;
41
    bool bWholeWords;
42
    sal_uInt32 nID;
43
};
44
45
/// Used to display the targets list
46
class TargetsTable
47
{
48
    std::unique_ptr<weld::TreeView> m_xControl;
49
    int GetRowByTargetName(std::u16string_view sName);
50
51
public:
52
    TargetsTable(std::unique_ptr<weld::TreeView> xControl);
53
    void InsertTarget(RedactionTarget* pTarget);
54
    bool HasTargetType(RedactionTargetType aTargetType);
55
    RedactionTarget* GetTargetByName(std::u16string_view sName);
56
    OUString GetNameProposal() const;
57
58
0
    int get_selected_index() const { return m_xControl->get_selected_index(); }
59
0
    std::vector<int> get_selected_rows() const { return m_xControl->get_selected_rows(); }
60
0
    void clear() { m_xControl->clear(); }
61
0
    void remove(int nRow) { m_xControl->remove(nRow); }
62
0
    OUString get_id(int nRow) const { return m_xControl->get_id(nRow); }
63
64
    // Sync data on the targets box with the data on the target
65
    void setRowData(int nRowIndex, const RedactionTarget* pTarget);
66
67
    void connect_item_activated(const Link<const weld::TreeIter&, bool>& rLink)
68
0
    {
69
0
        m_xControl->connect_item_activated(rLink);
70
0
    };
71
};
72
73
namespace sfx2
74
{
75
class FileDialogHelper;
76
}
77
78
enum class StartFileDialogType
79
{
80
    Open,
81
    SaveAs
82
};
83
84
class SfxAutoRedactDialog final : public SfxDialogController
85
{
86
    SfxObjectShellLock m_xDocShell;
87
    std::vector<std::pair<std::unique_ptr<RedactionTarget>, OUString>> m_aTableTargets;
88
    std::unique_ptr<sfx2::FileDialogHelper> m_pFileDlg;
89
    bool m_bIsValidState;
90
    bool m_bTargetsCopied;
91
92
    TargetsTable m_aTargetsBox;
93
    std::unique_ptr<weld::Button> m_xLoadBtn;
94
    std::unique_ptr<weld::Button> m_xSaveBtn;
95
    std::unique_ptr<weld::Button> m_xAddBtn;
96
    std::unique_ptr<weld::Button> m_xEditBtn;
97
    std::unique_ptr<weld::Button> m_xDeleteBtn;
98
99
    DECL_LINK(Load, weld::Button&, void);
100
    DECL_LINK(Save, weld::Button&, void);
101
    DECL_LINK(AddHdl, weld::Button&, void);
102
    DECL_LINK(EditHdl, weld::Button&, void);
103
    DECL_LINK(DeleteHdl, weld::Button&, void);
104
    DECL_LINK(DoubleClickEditHdl, const weld::TreeIter&, bool);
105
    DECL_LINK(LoadHdl, sfx2::FileDialogHelper*, void);
106
    DECL_LINK(SaveHdl, sfx2::FileDialogHelper*, void);
107
108
    void StartFileDialog(StartFileDialogType nType, const OUString& rTitle);
109
    /// Carry out proper addition both to the targets box, and to the tabletargets vector.
110
    void addTarget(std::unique_ptr<RedactionTarget> pTarget);
111
    /// Clear all targets both visually and from the targets vector
112
    void clearTargets();
113
114
    void ImplDestroy();
115
116
public:
117
    SfxAutoRedactDialog(weld::Window* pParent);
118
    virtual ~SfxAutoRedactDialog() override;
119
120
    /// Check if the dialog has any valid redaction targets.
121
    bool hasTargets() const;
122
    /// Check if the dialog is in a valid state.
123
0
    bool isValidState() const { return m_bIsValidState; }
124
    /** Copies targets vector
125
     *  Does a shallow copy.
126
     *  Returns true if successful.
127
     */
128
    bool getTargets(std::vector<std::pair<RedactionTarget, OUString>>& r_aTargets);
129
};
130
131
class SfxAddTargetDialog final : public weld::GenericDialogController
132
{
133
private:
134
    std::unique_ptr<weld::Entry> m_xName;
135
    std::unique_ptr<weld::ComboBox> m_xType;
136
    std::unique_ptr<weld::Label> m_xLabelContent;
137
    std::unique_ptr<weld::Entry> m_xContent;
138
    std::unique_ptr<weld::Label> m_xLabelPredefContent;
139
    std::unique_ptr<weld::ComboBox> m_xPredefContent;
140
    std::unique_ptr<weld::CheckButton> m_xCaseSensitive;
141
    std::unique_ptr<weld::CheckButton> m_xWholeWords;
142
143
    DECL_LINK(SelectTypeHdl, weld::ComboBox&, void);
144
145
public:
146
    SfxAddTargetDialog(weld::Window* pWindow, const OUString& rName);
147
    SfxAddTargetDialog(weld::Window* pWindow, const OUString& sName,
148
                       const RedactionTargetType& eTargetType, const OUString& sContent,
149
                       bool bCaseSensitive, bool bWholeWords);
150
151
0
    OUString getName() const { return m_xName->get_text(); }
152
    RedactionTargetType getType() const;
153
    OUString getContent() const;
154
    bool isCaseSensitive() const
155
0
    {
156
0
        return m_xCaseSensitive->get_state() == TriState::TRISTATE_TRUE;
157
0
    }
158
0
    bool isWholeWords() const { return m_xWholeWords->get_state() == TriState::TRISTATE_TRUE; }
159
};
160
161
#endif
162
163
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */