2 * Copyright 2004-2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
7 * Humdinger <humdingerb@gmail.com>
11 #include "ExpanderPreferences.h"
17 #include <ControlLook.h>
18 #include <LayoutBuilder.h>
22 #include <RadioButton.h>
24 #include <SeparatorView.h>
25 #include <StringView.h>
26 #include <TextControl.h>
28 #include "DirectoryFilePanel.h"
31 static const uint32 MSG_OK
= 'mgOK';
32 static const uint32 MSG_CANCEL
= 'mCan';
33 static const uint32 MSG_LEAVEDEST
= 'mLed';
34 static const uint32 MSG_SAMEDIR
= 'mSad';
35 static const uint32 MSG_DESTUSE
= 'mDeu';
36 static const uint32 MSG_DESTTEXT
= 'mDet';
37 static const uint32 MSG_DESTSELECT
= 'mDes';
40 #undef B_TRANSLATION_CONTEXT
41 #define B_TRANSLATION_CONTEXT "ExpanderPreferences"
44 ExpanderPreferences::ExpanderPreferences(BMessage
* settings
)
46 BWindow(BRect(0, 0, 325, 305), B_TRANSLATE("Expander settings"),
47 B_FLOATING_WINDOW_LOOK
, B_FLOATING_APP_WINDOW_FEEL
,
48 B_NOT_RESIZABLE
| B_NOT_CLOSABLE
| B_NOT_ZOOMABLE
49 | B_AUTO_UPDATE_SIZE_LIMITS
),
53 const float kSpacing
= be_control_look
->DefaultItemSpacing();
55 BStringView
* expansionLabel
= new BStringView("stringViewExpansion",
56 B_TRANSLATE("Expansion"));
57 expansionLabel
->SetFont(be_bold_font
);
58 BStringView
* destinationLabel
= new BStringView("stringViewDestination",
59 B_TRANSLATE("Destination folder"));
60 destinationLabel
->SetFont(be_bold_font
);
61 BStringView
* otherLabel
= new BStringView("stringViewOther",
62 B_TRANSLATE("Other"));
63 otherLabel
->SetFont(be_bold_font
);
65 fAutoExpand
= new BCheckBox("autoExpand",
66 B_TRANSLATE("Automatically expand files"), NULL
);
67 fCloseWindow
= new BCheckBox("closeWindowWhenDone",
68 B_TRANSLATE("Close window when done expanding"), NULL
);
70 fLeaveDest
= new BRadioButton("leaveDest",
71 B_TRANSLATE("Leave destination folder path empty"),
72 new BMessage(MSG_LEAVEDEST
));
73 fSameDest
= new BRadioButton("sameDir",
74 B_TRANSLATE("Same directory as source (archive) file"),
75 new BMessage(MSG_SAMEDIR
));
76 fDestUse
= new BRadioButton("destUse",
77 B_TRANSLATE("Use:"), new BMessage(MSG_DESTUSE
));
78 fDestText
= new BTextControl("destText", "", "",
79 new BMessage(MSG_DESTTEXT
));
80 fDestText
->SetDivider(0);
81 fDestText
->TextView()->MakeEditable(false);
82 fDestText
->SetEnabled(false);
83 fSelect
= new BButton("selectButton", B_TRANSLATE("Select"),
84 new BMessage(MSG_DESTSELECT
));
85 fSelect
->SetEnabled(false);
87 fOpenDest
= new BCheckBox("openDestination",
88 B_TRANSLATE("Open destination folder after extraction"), NULL
);
89 fAutoShow
= new BCheckBox("autoShow",
90 B_TRANSLATE("Automatically show contents listing"), NULL
);
92 BButton
* okbutton
= new BButton("OKButton", B_TRANSLATE("OK"),
93 new BMessage(MSG_OK
));
94 okbutton
->MakeDefault(true);
95 BButton
* cancel
= new BButton("CancelButton", B_TRANSLATE("Cancel"),
96 new BMessage(MSG_CANCEL
));
99 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0)
100 .AddGroup(B_VERTICAL
, 0)
101 .SetInsets(B_USE_WINDOW_SPACING
, B_USE_WINDOW_SPACING
,
102 B_USE_WINDOW_SPACING
, B_USE_DEFAULT_SPACING
)
104 .AddGroup(B_VERTICAL
, 0)
108 .SetInsets(B_USE_SMALL_SPACING
, B_USE_SMALL_SPACING
, 0,
111 .Add(destinationLabel
)
112 .AddGroup(B_VERTICAL
, 0)
116 .AddGroup(B_HORIZONTAL
, 0)
118 .AddStrut(B_USE_ITEM_SPACING
)
120 .SetInsets(kSpacing
* 2, 0, 0, 0)
123 .SetInsets(B_USE_SMALL_SPACING
, B_USE_SMALL_SPACING
, 0,
127 .AddGroup(B_VERTICAL
, 0)
131 .SetInsets(B_USE_SMALL_SPACING
, B_USE_SMALL_SPACING
, 0, 0)
134 .Add(new BSeparatorView(B_HORIZONTAL
))
135 .AddGroup(B_HORIZONTAL
, B_USE_DEFAULT_SPACING
)
136 .SetInsets(0, B_USE_DEFAULT_SPACING
,
137 B_USE_WINDOW_SPACING
, B_USE_WINDOW_SPACING
)
144 fDestText
->SetExplicitAlignment(
145 BAlignment(B_ALIGN_HORIZONTAL_UNSET
, B_ALIGN_VERTICAL_CENTER
));
153 ExpanderPreferences::~ExpanderPreferences()
155 if (fUsePanel
&& fUsePanel
->RefFilter())
156 delete fUsePanel
->RefFilter();
163 ExpanderPreferences::_ReadSettings()
165 bool automatically_expand_files
;
166 bool close_when_done
;
167 int8 destination_folder
;
169 bool open_destination_folder
;
170 bool show_contents_listing
;
171 if ((fSettings
->FindBool("automatically_expand_files",
172 &automatically_expand_files
) == B_OK
)
173 && automatically_expand_files
) {
174 fAutoExpand
->SetValue(B_CONTROL_ON
);
177 if (fSettings
->FindBool("close_when_done", &close_when_done
) == B_OK
178 && close_when_done
) {
179 fCloseWindow
->SetValue(B_CONTROL_ON
);
182 if (fSettings
->FindInt8("destination_folder", &destination_folder
)
184 switch (destination_folder
) {
186 fSameDest
->SetValue(B_CONTROL_ON
);
190 fDestUse
->SetValue(B_CONTROL_ON
);
191 fDestText
->SetEnabled(true);
192 fSelect
->SetEnabled(true);
196 fLeaveDest
->SetValue(B_CONTROL_ON
);
201 if (fSettings
->FindRef("destination_folder_use", &fRef
) == B_OK
) {
203 if (entry
.Exists()) {
205 fDestText
->SetText(path
.Path());
209 if (fSettings
->FindBool("open_destination_folder",
210 &open_destination_folder
) == B_OK
211 && open_destination_folder
) {
212 fOpenDest
->SetValue(B_CONTROL_ON
);
215 if (fSettings
->FindBool("show_contents_listing",
216 &show_contents_listing
) == B_OK
217 && show_contents_listing
) {
218 fAutoShow
->SetValue(B_CONTROL_ON
);
224 ExpanderPreferences::_WriteSettings()
226 fSettings
->ReplaceBool("automatically_expand_files",
227 fAutoExpand
->Value() == B_CONTROL_ON
);
228 fSettings
->ReplaceBool("close_when_done",
229 fCloseWindow
->Value() == B_CONTROL_ON
);
230 fSettings
->ReplaceInt8("destination_folder",
231 (fSameDest
->Value() == B_CONTROL_ON
) ? 0x63
232 : ((fLeaveDest
->Value() == B_CONTROL_ON
) ? 0x66 : 0x65));
233 fSettings
->ReplaceRef("destination_folder_use", &fRef
);
234 fSettings
->ReplaceBool("open_destination_folder",
235 fOpenDest
->Value() == B_CONTROL_ON
);
236 fSettings
->ReplaceBool("show_contents_listing",
237 fAutoShow
->Value() == B_CONTROL_ON
);
242 ExpanderPreferences::MessageReceived(BMessage
* message
)
244 switch (message
->what
) {
248 BMessenger
messenger(this);
249 fUsePanel
= new DirectoryFilePanel(B_OPEN_PANEL
, &messenger
,
250 NULL
, B_DIRECTORY_NODE
, false, NULL
,
251 new DirectoryRefFilter(), true);
260 fUsePanel
->GetPanelDirectory(&ref
);
264 fDestText
->SetText(path
.Path());
269 case B_REFS_RECEIVED
:
271 if (message
->FindRef("refs", 0, &fRef
) == B_OK
) {
272 BEntry
entry(&fRef
, true);
274 fDestText
->SetText(path
.Path());
282 fDestText
->SetEnabled(false);
283 fSelect
->SetEnabled(false);
289 fDestText
->SetEnabled(true);
290 fSelect
->SetEnabled(true);
291 fDestText
->TextView()->MakeEditable(false);
298 if (message
->FindInt32("key", &index
) == B_OK
&& index
!= 1)
301 // fall-through on ESC