1
/* AppArmor Profile Editor (C) 2006 Novell, Inc.
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.
10
#include "wx/wxprec.h"
16
#include <wx/propdlg.h>
17
#include <wx/config.h>
18
#include <wx/colordlg.h>
19
#include <wx/fontdlg.h>
21
#include "Configuration.h"
22
#include "ProfileTextCtrl.h"
23
#include "Preferences.h"
25
IMPLEMENT_DYNAMIC_CLASS(PreferencesDialog, wxDialog)
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)
40
PreferencesDialog::PreferencesDialog( )
44
PreferencesDialog::PreferencesDialog(wxWindow* parent,
46
const wxString& caption,
51
Create(parent, id, caption, pos, size, style);
54
bool PreferencesDialog::Create(wxWindow* parent,
56
const wxString& caption,
61
mpPrefsNotebook = NULL;
63
mpParserCommand = NULL;
64
mpTemplateTextCtrl = NULL;
65
mpCommentsButton = NULL;
66
mpIncludesButton = NULL;
68
mpCapabilitiesButton = NULL;
70
mpCommentsFontButton = NULL;
71
mpIncludesFontButton = NULL;
72
mpCapabilitiesFontButton = NULL;
73
mpPathsFontButton = NULL;
76
SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
77
wxDialog::Create( parent, id, caption, pos, size, style );
80
GetSizer()->Fit(this);
81
GetSizer()->SetSizeHints(this);
87
void PreferencesDialog::CreateControls()
89
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
92
mpPrefsNotebook = new wxNotebook(this, ID_PREFERENCES_NOTEBOOK, wxDefaultPosition, wxDefaultSize, wxNB_TOP );
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);
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);
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);
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);
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);
111
mpPrefsNotebook->AddPage(pathsPanel, _("Paths"));
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);
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);
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);
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);
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());
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);
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());
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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"));
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);
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);
213
wxButton* cancelButton = new wxButton( this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
214
buttonSizer->AddButton(cancelButton);
215
buttonSizer->Realize();
218
void PreferencesDialog::OnColourButton(wxCommandEvent &event)
220
wxColourData currentData;
221
switch (event.GetId())
223
case ID_COMMENT_COLOUR_BUTTON:
224
currentData.SetColour(mpCommentsButton->GetBackgroundColour());
226
case ID_INCLUDES_COLOUR_BUTTON:
227
currentData.SetColour(mpIncludesButton->GetBackgroundColour());
229
case ID_CAPABILITIES_COLOUR_BUTTON:
230
currentData.SetColour(mpCapabilitiesButton->GetBackgroundColour());
232
case ID_PATHS_COLOUR_BUTTON:
233
currentData.SetColour(mpPathsButton->GetBackgroundColour());
235
case ID_PERMS_COLOUR_BUTTON:
236
currentData.SetColour(mpPermsButton->GetBackgroundColour());
239
currentData.SetColour(*wxWHITE);
242
wxColourDialog *colourPicker = new wxColourDialog(this, ¤tData);
243
if (colourPicker->ShowModal() == wxID_OK)
245
currentData = colourPicker->GetColourData();
246
wxColour currentColour = currentData.GetColour();
247
switch (event.GetId())
249
case ID_COMMENT_COLOUR_BUTTON:
250
mpCommentsButton->SetBackgroundColour(currentColour);
252
case ID_INCLUDES_COLOUR_BUTTON:
253
mpIncludesButton->SetBackgroundColour(currentColour);
255
case ID_CAPABILITIES_COLOUR_BUTTON:
256
mpCapabilitiesButton->SetBackgroundColour(currentColour);
258
case ID_PATHS_COLOUR_BUTTON:
259
mpPathsButton->SetBackgroundColour(currentColour);
261
case ID_PERMS_COLOUR_BUTTON:
262
mpPermsButton->SetBackgroundColour(currentColour);
268
colourPicker->Destroy();
270
void PreferencesDialog::OnFontButton(wxCommandEvent &event)
274
switch (event.GetId())
276
case ID_COMMENT_FONT_BUTTON:
277
fontData.SetInitialFont(mpCommentsFontButton->GetFont());
279
case ID_INCLUDES_FONT_BUTTON:
280
fontData.SetInitialFont(mpIncludesFontButton->GetFont());
282
case ID_CAPABILITIES_FONT_BUTTON:
283
fontData.SetInitialFont(mpCapabilitiesFontButton->GetFont());
285
case ID_PATHS_FONT_BUTTON:
286
fontData.SetInitialFont(mpPathsFontButton->GetFont());
288
case ID_PERMS_FONT_BUTTON:
289
fontData.SetInitialFont(mpPermsFontButton->GetFont());
294
wxFontDialog *fontDialog = new wxFontDialog(this, fontData);
295
if (fontDialog->ShowModal() == wxID_OK)
297
fontData = fontDialog->GetFontData();
298
wxFont newFont = fontData.GetChosenFont();
299
// Write it back to disk
300
switch (event.GetId())
302
case ID_COMMENT_FONT_BUTTON:
303
mpCommentsFontButton->SetFont(newFont);
305
case ID_INCLUDES_FONT_BUTTON:
306
mpIncludesFontButton->SetFont(newFont);
308
case ID_CAPABILITIES_FONT_BUTTON:
309
mpCapabilitiesFontButton->SetFont(newFont);
311
case ID_PATHS_FONT_BUTTON:
312
mpPathsFontButton->SetFont(newFont);
314
case ID_PERMS_FONT_BUTTON:
315
mpPermsFontButton->SetFont(newFont);
321
fontDialog->Destroy();