File: TailoringWindow.h

package info (click to toggle)
scap-workbench 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,292 kB
  • sloc: cpp: 7,519; sh: 205; xml: 38; ansic: 15; makefile: 13
file content (238 lines) | stat: -rw-r--r-- 8,205 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
 * Copyright 2013 Red Hat Inc., Durham, North Carolina.
 * All Rights Reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *      Martin Preisler <mpreisle@redhat.com>
 */

#ifndef SCAP_WORKBENCH_TAILORING_WINDOW_H_
#define SCAP_WORKBENCH_TAILORING_WINDOW_H_

#include "ForwardDecls.h"

#include <QMainWindow>
#include <QSettings>
#include <QUndoStack>

extern "C"
{
#include <xccdf_benchmark.h>
#include <xccdf_policy.h>
}

#include "ui_TailoringWindow.h"
#include "ui_ProfilePropertiesDockWidget.h"
#include "ui_XCCDFItemPropertiesDockWidget.h"

/**
 * @brief Tailors given profile by editing it directly
 *
 * If you want to inherit a profile and tailor that, create a new profile,
 * set up the inheritance and then pass the new profile to this class.
 */
class TailoringWindow : public QMainWindow
{
    Q_OBJECT

    public:
        static struct xccdf_item* getXccdfItemFromTreeItem(QTreeWidgetItem* treeItem);

        /**
         * @param newProfile whether the profile in policy was created solely for tailoring
         */
        TailoringWindow(struct xccdf_policy* policy, struct xccdf_benchmark* benchmark, bool newProfile, MainWindow* parent = 0);
        virtual ~TailoringWindow();

        /**
         * @brief Makes sure that given XCCDF item is selected or deselected in the policy and profile
         *
         * This method adds a new select to the policy and profile. This select overrides all
         * previous selects if any.
         */
        void setItemSelected(struct xccdf_item* xccdfItem, bool selected);

        /**
         * @brief Synchronizes the profile item with the profile
         */
        void synchronizeProfileItem();

        void setValueValue(struct xccdf_value* xccdfValue, const QString& newValue);
        void refreshXccdfItemPropertiesDockWidget();

        struct xccdf_item* getXCCDFItemById(const QString& id) const;

        void changeSelectionToXCCDFItemById(const QString& id);

        QString getCurrentValueValue(struct xccdf_value* xccdfValue);
        void setValueValueWithUndoCommand(struct xccdf_value* xccdfValue, const QString& newValue);

        const std::vector<struct xccdf_rule*>& getRulesAffectedByValue(struct xccdf_value* xccdfValue) const;

    public slots:
        /**
         * @brief Traverses the tree into all selected groups and selects all their items
         */
        void selectAllChildrenItems();

        /**
         * @brief Traverses the tree into all selected groups and deselects all their items
         */
        void deselectAllChildrenItems();

    public:

        /**
         * @brief Retrieves ID of profile that is being tailored (in suitable language)
         */
        QString getProfileID() const;

        /**
         * @brief Goes through profile title texts and sets one of them to given title
         *
         * @see TailoringWindow::setProfileTitleWithUndoCommand
         */
        void setProfileTitle(const QString& title);

        /**
         * @brief Retrieves title of profile that is being tailoring (in suitable language)
         */
        QString getProfileTitle() const;

        /**
         * @brief Creates a new undo command that changes title of tailored profile and pushes it onto the undo stack
         *
         * @see TailoringWindow::setProfileTitle
         */
        void setProfileTitleWithUndoCommand(const QString& newTitle);

        /**
         * @brief Goes through profile description texts and sets one of them to given title
         *
         * @see TailoringWindow::setProfileDescriptionWithUndoCommand
         */
        void setProfileDescription(const QString& description);

        /**
         * @brief Retrieves description of profile that is being tailoring (in suitable language)
         */
        QString getProfileDescription() const;

        /**
         * @brief Retrieves readable title of given XCCDF item [in HTML]
         *
         * @internal This method performs substitution using mPolicy
         */
        QString getXCCDFItemTitle(struct xccdf_item* item) const;

        /**
         * @brief Retrieves readable description of given XCCDF item [in HTML]
         *
         * @internal This method performs substitution using mPolicy
         */
        QString getXCCDFItemDescription(struct xccdf_item* item) const;

        /**
         * @brief Creates a new undo command that changes description of tailored profile and pushes it onto the undo stack
         *
         * @see TailoringWindow::setProfileDescription
         */
        void setProfileDescriptionWithUndoCommand(const QString& newDescription);

        /**
         * @brief Refreshes profile properties dock widget to accurately represent tailored profile
         */
        void refreshProfileDockWidget();

    public slots:
        void confirmAndClose();
        void deleteProfileAndDiscard();

    protected:
        /// Reimplemented to refresh profiles and selected rules in the parent main window
        virtual void closeEvent(QCloseEvent* event);

    private:
        QString getQSettingsKey() const;
        void deserializeCollapsedItems();
        void serializeCollapsedItems();

        /// Internal usage only, this method assumes serializeCollapsedItems was called recently
        void removeOldCollapsedLists();

        void syncCollapsedItems();
        void syncCollapsedItem(QTreeWidgetItem* item, QSet<QString>& usedCollapsedIds);

        void createTreeItem(QTreeWidgetItem* treeItem, struct xccdf_item* xccdfItem);
        void synchronizeTreeItemSelections(QTreeWidgetItem* treeItem);

        void createSelectionMacro(QTreeWidgetItem* treeItem, bool checkState, const QString& commandName);

        MainWindow* mParentMainWindow;
        /// Used to remember manually collapsed items for a particular item
        QSet<QString> mCollapsedItemIds;
        /// Used to serialize manually collapsed items between scap-workbench runs
        QSettings* mQSettings;

        /// if > 0, ignore itemChanged signals, these would just excessively add selects and bloat memory
        unsigned int mSynchronizeItemLock;

        /// UI designed in Qt Designer
        Ui_TailoringWindow mUI;

        /// The root profile item in the tree (profile isn't an xccdf_item!)
        QTreeWidgetItem* mProfileItem;
        /// The root benchmark item in the tree
        QTreeWidgetItem* mBenchmarkItem;

        XCCDFItemPropertiesDockWidget* mItemPropertiesDockWidget;
        ProfilePropertiesDockWidget* mProfilePropertiesDockWidget;
        QDockWidget* mUndoViewDockWidget;

        QLineEdit* mSearchBox;
        QPushButton* mSearchButton;
        QLabel* mSearchFeedback;

        struct xccdf_policy* mPolicy;
        struct xccdf_profile* mProfile;
        struct xccdf_benchmark* mBenchmark;

        QUndoStack mUndoStack;

        bool mNewProfile;
        bool mChangesConfirmed;

        unsigned int mSearchSkippedItems;
        QString mSearchCurrentNeedle;

        void generateValueAffectsRulesMap(struct xccdf_item* item);

        typedef std::map<struct xccdf_value*, std::vector<struct xccdf_rule*> > ValueAffectsRulesMap;
        ValueAffectsRulesMap mValueAffectsRulesMap;

        QAction* mSelectAllAction;
        QAction* mDeselectAllAction;

    private slots:
        void searchNext();
        void synchronizeTreeItem();
        void itemSelectionChanged(QTreeWidgetItem* current);
        void itemChanged(QTreeWidgetItem* item);
        void itemExpanded(QTreeWidgetItem* item);
        void itemCollapsed(QTreeWidgetItem* item);
};

#endif