~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to deprecated/management/profile-editor/src/Preferences.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*      AppArmor Profile Editor (C) 2006 Novell, Inc.
 
2
 *
 
3
 *      This program is free software; you can redistribute it and/or modify
 
4
 *      it under the terms of the GNU General Public License as published by
 
5
 *      the Free Software Foundation; either version 2 of the License, or
 
6
 *      (at your option) any later version.
 
7
 * 
 
8
 */
 
9
 
 
10
#include "wx/wxprec.h"
 
11
 
 
12
#ifndef WX_PRECOMP
 
13
#include "wx/wx.h"
 
14
#endif
 
15
 
 
16
#include <wx/propdlg.h>
 
17
#include <wx/config.h>
 
18
#include <wx/colordlg.h>
 
19
#include <wx/fontdlg.h>
 
20
 
 
21
#include "Configuration.h"
 
22
#include "ProfileTextCtrl.h"
 
23
#include "Preferences.h"
 
24
 
 
25
IMPLEMENT_DYNAMIC_CLASS(PreferencesDialog, wxDialog)
 
26
 
 
27
BEGIN_EVENT_TABLE(PreferencesDialog, wxDialog)
 
28
        EVT_BUTTON(ID_COMMENT_COLOUR_BUTTON, PreferencesDialog::OnColourButton)
 
29
        EVT_BUTTON(ID_INCLUDES_COLOUR_BUTTON, PreferencesDialog::OnColourButton)
 
30
        EVT_BUTTON(ID_PERMS_COLOUR_BUTTON, PreferencesDialog::OnColourButton)
 
31
        EVT_BUTTON(ID_CAPABILITIES_COLOUR_BUTTON, PreferencesDialog::OnColourButton)
 
32
        EVT_BUTTON(ID_PATHS_COLOUR_BUTTON, PreferencesDialog::OnColourButton)
 
33
        EVT_BUTTON(ID_COMMENT_FONT_BUTTON, PreferencesDialog::OnFontButton)
 
34
        EVT_BUTTON(ID_INCLUDES_FONT_BUTTON, PreferencesDialog::OnFontButton)
 
35
        EVT_BUTTON(ID_CAPABILITIES_FONT_BUTTON, PreferencesDialog::OnFontButton)
 
36
        EVT_BUTTON(ID_PATHS_FONT_BUTTON, PreferencesDialog::OnFontButton)
 
37
        EVT_BUTTON(ID_PERMS_FONT_BUTTON, PreferencesDialog::OnFontButton)
 
38
END_EVENT_TABLE()
 
39
 
 
40
PreferencesDialog::PreferencesDialog( )
 
41
{
 
42
}
 
43
 
 
44
PreferencesDialog::PreferencesDialog(wxWindow* parent, 
 
45
                                        wxWindowID id, 
 
46
                                        const wxString& caption, 
 
47
                                        const wxPoint& pos, 
 
48
                                        const wxSize& size,
 
49
                                        long style)
 
50
{
 
51
    Create(parent, id, caption, pos, size, style);
 
52
}
 
53
 
 
54
bool PreferencesDialog::Create(wxWindow* parent,
 
55
                                wxWindowID id,
 
56
                                const wxString& caption,
 
57
                                const wxPoint& pos,
 
58
                                const wxSize& size,
 
59
                                long style)
 
60
{
 
61
        mpPrefsNotebook = NULL;
 
62
        mpProfileDir = NULL;
 
63
        mpParserCommand = NULL;
 
64
        mpTemplateTextCtrl = NULL;
 
65
        mpCommentsButton = NULL;
 
66
        mpIncludesButton = NULL;
 
67
        mpPermsButton = NULL;
 
68
        mpCapabilitiesButton = NULL;
 
69
        mpPathsButton = NULL;
 
70
        mpCommentsFontButton = NULL;
 
71
        mpIncludesFontButton = NULL;
 
72
        mpCapabilitiesFontButton = NULL;
 
73
        mpPathsFontButton = NULL;
 
74
        
 
75
        
 
76
        SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
 
77
        wxDialog::Create( parent, id, caption, pos, size, style );
 
78
        
 
79
        CreateControls();
 
80
        GetSizer()->Fit(this);
 
81
        GetSizer()->SetSizeHints(this);
 
82
        Centre();
 
83
        
 
84
        return true;
 
85
}
 
86
 
 
87
void PreferencesDialog::CreateControls()
 
88
{    
 
89
        wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
 
90
        SetSizer(mainSizer);
 
91
        
 
92
        mpPrefsNotebook = new wxNotebook(this, ID_PREFERENCES_NOTEBOOK, wxDefaultPosition, wxDefaultSize, wxNB_TOP );
 
93
        
 
94
        // The paths pane
 
95
        wxPanel* pathsPanel = new wxPanel( mpPrefsNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
 
96
        wxGridSizer* prefsGridSizer = new wxGridSizer(2, 2, 0, 0);
 
97
        pathsPanel->SetSizer(prefsGridSizer);
 
98
        
 
99
        wxStaticText* profileDirectoryText = new wxStaticText( pathsPanel, wxID_ANY, _("Profile Directory:"), wxDefaultPosition, wxDefaultSize, 0 );
 
100
        prefsGridSizer->Add(profileDirectoryText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
101
        
 
102
        mpProfileDir = new wxTextCtrl( pathsPanel, wxID_ANY, Configuration::GetProfileDirectory(), wxDefaultPosition, wxSize(200, -1), 0 );
 
103
        prefsGridSizer->Add(mpProfileDir, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
104
        
 
105
        wxStaticText* parserCommandText = new wxStaticText( pathsPanel, wxID_ANY, _("Path to apparmor_parser:"), wxDefaultPosition, wxDefaultSize, 0 );
 
106
        prefsGridSizer->Add(parserCommandText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
107
        
 
108
        mpParserCommand = new wxTextCtrl( pathsPanel, wxID_ANY, Configuration::GetParserCommand(), wxDefaultPosition, wxSize(200, -1), 0 );
 
109
        prefsGridSizer->Add(mpParserCommand, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
110
        
 
111
        mpPrefsNotebook->AddPage(pathsPanel, _("Paths"));
 
112
        
 
113
        // The colours pane //
 
114
        wxPanel* coloursPanel = new wxPanel( mpPrefsNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
 
115
        wxBoxSizer* colorFontBoxSizer = new wxBoxSizer(wxHORIZONTAL);
 
116
        coloursPanel->SetSizer(colorFontBoxSizer);
 
117
        
 
118
        wxStaticBox* colourBoxSizer = new wxStaticBox(coloursPanel, wxID_ANY, _("Colours"));
 
119
        wxStaticBoxSizer* colourStaticBoxSizer = new wxStaticBoxSizer(colourBoxSizer, wxVERTICAL);
 
120
        colorFontBoxSizer->Add(colourStaticBoxSizer, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
121
        wxGridSizer* colourSubSizer = new wxGridSizer(4, 2, 0, 0);
 
122
        colourStaticBoxSizer->Add(colourSubSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
 
123
        wxStaticText* commentsText = new wxStaticText( coloursPanel, wxID_STATIC, _("Comments"), wxDefaultPosition, wxDefaultSize, 0 );
 
124
        colourSubSizer->Add(commentsText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
125
        
 
126
        mpCommentsButton = new wxButton( coloursPanel, ID_COMMENT_COLOUR_BUTTON, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
 
127
        mpCommentsButton->SetBackgroundColour(Configuration::GetCommentColour());
 
128
        colourSubSizer->Add(mpCommentsButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
129
        
 
130
        wxStaticText* includesText = new wxStaticText( coloursPanel, wxID_STATIC, _("Includes"), wxDefaultPosition, wxDefaultSize, 0 );
 
131
        colourSubSizer->Add(includesText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
132
        
 
133
        mpIncludesButton = new wxButton( coloursPanel, ID_INCLUDES_COLOUR_BUTTON, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
 
134
        colourSubSizer->Add(mpIncludesButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
135
        mpIncludesButton->SetBackgroundColour(Configuration::GetIncludeColour());
 
136
 
 
137
        wxStaticText* capabilitiesText = new wxStaticText( coloursPanel, wxID_STATIC, _("Capabilities"), wxDefaultPosition, wxDefaultSize, 0 );
 
138
        colourSubSizer->Add(capabilitiesText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
139
        
 
140
        mpCapabilitiesButton = new wxButton( coloursPanel, ID_CAPABILITIES_COLOUR_BUTTON, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
 
141
        colourSubSizer->Add(mpCapabilitiesButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
142
        mpCapabilitiesButton->SetBackgroundColour(Configuration::GetCapColour());
 
143
 
 
144
        wxStaticText* pathsText = new wxStaticText( coloursPanel, wxID_STATIC, _("Paths"), wxDefaultPosition, wxDefaultSize, 0 );
 
145
        colourSubSizer->Add(pathsText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
146
        
 
147
        mpPathsButton = new wxButton( coloursPanel, ID_PATHS_COLOUR_BUTTON, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
 
148
        mpPathsButton->SetBackgroundColour(Configuration::GetPathColour());
 
149
        colourSubSizer->Add(mpPathsButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
150
        
 
151
        wxStaticText* permsText = new wxStaticText( coloursPanel, wxID_STATIC, _("Permissions"), wxDefaultPosition, wxDefaultSize, 0 );
 
152
        colourSubSizer->Add(permsText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
153
 
 
154
        mpPermsButton = new wxButton( coloursPanel, ID_PERMS_COLOUR_BUTTON, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
 
155
        mpPermsButton->SetBackgroundColour(Configuration::GetPermColour());
 
156
        colourSubSizer->Add(mpPermsButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
157
 
 
158
        // Fonts pane //
 
159
        wxStaticBox* fontSubSizer = new wxStaticBox(coloursPanel, wxID_ANY, _("Fonts"));
 
160
        wxStaticBoxSizer* fontBoxSizer = new wxStaticBoxSizer(fontSubSizer, wxVERTICAL);
 
161
        colorFontBoxSizer->Add(fontBoxSizer, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
162
        wxGridSizer* fontsGridSizer = new wxGridSizer(4, 2, 0, 0);
 
163
        fontBoxSizer->Add(fontsGridSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
 
164
        wxStaticText* commentFontText = new wxStaticText( coloursPanel, wxID_STATIC, _("Comments"), wxDefaultPosition, wxDefaultSize, 0 );
 
165
        fontsGridSizer->Add(commentFontText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
166
        
 
167
        mpCommentsFontButton = new wxButton( coloursPanel, ID_COMMENT_FONT_BUTTON, _("ABCdef"), wxDefaultPosition, wxDefaultSize, 0 );
 
168
        mpCommentsFontButton->SetFont(Configuration::GetCommentFont());
 
169
        fontsGridSizer->Add(mpCommentsFontButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
170
        
 
171
        wxStaticText* includesFontText = new wxStaticText( coloursPanel, wxID_STATIC, _("Includes"), wxDefaultPosition, wxDefaultSize, 0 );
 
172
        fontsGridSizer->Add(includesFontText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
173
        
 
174
        mpIncludesFontButton = new wxButton( coloursPanel, ID_INCLUDES_FONT_BUTTON, _("ABCdef"), wxDefaultPosition, wxDefaultSize, 0 );
 
175
        mpIncludesFontButton->SetFont(Configuration::GetIncludeFont());
 
176
        fontsGridSizer->Add(mpIncludesFontButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
177
        
 
178
        wxStaticText* capabilitiesFontText = new wxStaticText( coloursPanel, wxID_STATIC, _("Capabilities"), wxDefaultPosition, wxDefaultSize, 0 );
 
179
        fontsGridSizer->Add(capabilitiesFontText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
180
        
 
181
        mpCapabilitiesFontButton = new wxButton( coloursPanel, ID_CAPABILITIES_FONT_BUTTON, _("ABCdef"), wxDefaultPosition, wxDefaultSize, 0 );
 
182
        mpCapabilitiesFontButton->SetFont(Configuration::GetCapabilityFont());
 
183
        fontsGridSizer->Add(mpCapabilitiesFontButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
184
        
 
185
        wxStaticText* pathsFontText = new wxStaticText( coloursPanel, wxID_STATIC, _("Paths"), wxDefaultPosition, wxDefaultSize, 0 );
 
186
        fontsGridSizer->Add(pathsFontText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
187
        
 
188
        mpPathsFontButton = new wxButton( coloursPanel, ID_PATHS_FONT_BUTTON, _("ABCdef"), wxDefaultPosition, wxDefaultSize, 0 );
 
189
        mpPathsFontButton->SetFont(Configuration::GetPathFont());
 
190
        fontsGridSizer->Add(mpPathsFontButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
191
        
 
192
        wxStaticText* permsFontText = new wxStaticText( coloursPanel, wxID_STATIC, _("Permissions"), wxDefaultPosition, wxDefaultSize, 0 );
 
193
        fontsGridSizer->Add(permsFontText, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
 
194
        
 
195
        mpPermsFontButton = new wxButton( coloursPanel, ID_PERMS_FONT_BUTTON, _("ABCdef"), wxDefaultPosition, wxDefaultSize, 0 );
 
196
        mpPermsFontButton->SetFont(Configuration::GetPermFont());
 
197
        fontsGridSizer->Add(mpPermsFontButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
198
        mpPrefsNotebook->AddPage(coloursPanel, _("Colours & Fonts"));
 
199
 
 
200
        // Templates pane //    
 
201
        mpTemplateTextCtrl = new ProfileTextCtrl (mpPrefsNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
 
202
        mpTemplateTextCtrl->SetText(Configuration::GetTemplateText());
 
203
        mpPrefsNotebook->AddPage(mpTemplateTextCtrl, _("New Profile Template"));
 
204
        mainSizer->Add(mpPrefsNotebook, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
 
205
        wxBoxSizer* buttonBoxSizer = new wxBoxSizer(wxHORIZONTAL);
 
206
        mainSizer->Add(buttonBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
 
207
        
 
208
        wxStdDialogButtonSizer* buttonSizer = new wxStdDialogButtonSizer;
 
209
        buttonBoxSizer->Add(buttonSizer, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
210
        wxButton* okButton = new wxButton( this, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
 
211
        buttonSizer->AddButton(okButton);
 
212
 
 
213
        wxButton* cancelButton = new wxButton( this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
 
214
        buttonSizer->AddButton(cancelButton);   
 
215
        buttonSizer->Realize();
 
216
}
 
217
 
 
218
void PreferencesDialog::OnColourButton(wxCommandEvent &event)
 
219
{       
 
220
        wxColourData currentData;
 
221
        switch (event.GetId())
 
222
        {
 
223
                case ID_COMMENT_COLOUR_BUTTON:
 
224
                        currentData.SetColour(mpCommentsButton->GetBackgroundColour());
 
225
                        break;
 
226
                case ID_INCLUDES_COLOUR_BUTTON:
 
227
                        currentData.SetColour(mpIncludesButton->GetBackgroundColour());
 
228
                        break;
 
229
                case ID_CAPABILITIES_COLOUR_BUTTON:
 
230
                        currentData.SetColour(mpCapabilitiesButton->GetBackgroundColour());
 
231
                        break;
 
232
                case ID_PATHS_COLOUR_BUTTON:
 
233
                        currentData.SetColour(mpPathsButton->GetBackgroundColour());
 
234
                        break;
 
235
                case ID_PERMS_COLOUR_BUTTON:
 
236
                        currentData.SetColour(mpPermsButton->GetBackgroundColour());
 
237
                        break;
 
238
                default:
 
239
                        currentData.SetColour(*wxWHITE);
 
240
                        break;
 
241
        }
 
242
        wxColourDialog *colourPicker = new wxColourDialog(this, &currentData);
 
243
        if (colourPicker->ShowModal() == wxID_OK)
 
244
        {
 
245
                currentData = colourPicker->GetColourData();
 
246
                wxColour currentColour = currentData.GetColour();
 
247
                switch (event.GetId())
 
248
                {
 
249
                        case ID_COMMENT_COLOUR_BUTTON:
 
250
                                mpCommentsButton->SetBackgroundColour(currentColour);
 
251
                                break;
 
252
                        case ID_INCLUDES_COLOUR_BUTTON: 
 
253
                                mpIncludesButton->SetBackgroundColour(currentColour);
 
254
                                break;
 
255
                        case ID_CAPABILITIES_COLOUR_BUTTON:
 
256
                                mpCapabilitiesButton->SetBackgroundColour(currentColour);
 
257
                                break;
 
258
                        case ID_PATHS_COLOUR_BUTTON:
 
259
                                mpPathsButton->SetBackgroundColour(currentColour);
 
260
                                break;
 
261
                        case ID_PERMS_COLOUR_BUTTON:
 
262
                                mpPermsButton->SetBackgroundColour(currentColour);
 
263
                                break;
 
264
                        default:
 
265
                                break;
 
266
                }
 
267
        }
 
268
        colourPicker->Destroy();
 
269
}
 
270
void PreferencesDialog::OnFontButton(wxCommandEvent &event)
 
271
{
 
272
 
 
273
        wxFontData fontData;
 
274
        switch (event.GetId())
 
275
        {
 
276
                case ID_COMMENT_FONT_BUTTON:
 
277
                        fontData.SetInitialFont(mpCommentsFontButton->GetFont());
 
278
                        break;
 
279
                case ID_INCLUDES_FONT_BUTTON:
 
280
                        fontData.SetInitialFont(mpIncludesFontButton->GetFont());
 
281
                        break;
 
282
                case ID_CAPABILITIES_FONT_BUTTON:
 
283
                        fontData.SetInitialFont(mpCapabilitiesFontButton->GetFont());
 
284
                        break;
 
285
                case ID_PATHS_FONT_BUTTON:
 
286
                        fontData.SetInitialFont(mpPathsFontButton->GetFont());
 
287
                        break;
 
288
                case ID_PERMS_FONT_BUTTON:
 
289
                        fontData.SetInitialFont(mpPermsFontButton->GetFont());
 
290
                        break;
 
291
                default:
 
292
                        break;
 
293
        }
 
294
        wxFontDialog *fontDialog = new wxFontDialog(this, fontData);
 
295
        if (fontDialog->ShowModal() == wxID_OK)
 
296
        {
 
297
                fontData = fontDialog->GetFontData();
 
298
                wxFont newFont = fontData.GetChosenFont();
 
299
                // Write it back to disk
 
300
                switch (event.GetId())
 
301
                {
 
302
                        case ID_COMMENT_FONT_BUTTON:
 
303
                                mpCommentsFontButton->SetFont(newFont);
 
304
                                break;
 
305
                        case ID_INCLUDES_FONT_BUTTON:   
 
306
                                mpIncludesFontButton->SetFont(newFont);
 
307
                                break;
 
308
                        case ID_CAPABILITIES_FONT_BUTTON:
 
309
                                mpCapabilitiesFontButton->SetFont(newFont);
 
310
                                break;
 
311
                        case ID_PATHS_FONT_BUTTON:
 
312
                                mpPathsFontButton->SetFont(newFont);
 
313
                                break;
 
314
                        case ID_PERMS_FONT_BUTTON:
 
315
                                mpPermsFontButton->SetFont(newFont);
 
316
                                break;
 
317
                        default:
 
318
                                break;
 
319
                }
 
320
        }
 
321
        fontDialog->Destroy();
 
322
}