2 * Copyright 2004-2012, Haiku, Inc. All rights reserved.
3 * Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
5 * Distributed under the terms of the MIT License.
9 //! A file configuration view for filters
12 #include <FileConfigView.h>
18 #include <GroupLayout.h>
19 #include <MailSettingsView.h>
23 #include <TextControl.h>
26 #undef B_TRANSLATION_CONTEXT
27 #define B_TRANSLATION_CONTEXT "MailKit"
30 static const uint32 kMsgSelectButton
= 'fsel';
36 FileControl::FileControl(const char* name
, const char* label
,
37 const char* pathOfFile
, uint32 flavors
)
41 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR
));
42 SetLayout(new BGroupLayout(B_HORIZONTAL
));
44 fText
= new BTextControl("file_path", label
, pathOfFile
, NULL
);
47 fButton
= new BButton("select_file", B_TRANSLATE("Select" B_UTF8_ELLIPSIS
),
48 new BMessage(kMsgSelectButton
));
51 fPanel
= new BFilePanel(B_OPEN_PANEL
, NULL
, NULL
, flavors
, false);
55 FileControl::~FileControl()
62 FileControl::AttachedToWindow()
64 fButton
->SetTarget(this);
65 fPanel
->SetTarget(this);
70 FileControl::MessageReceived(BMessage
* msg
)
73 case kMsgSelectButton
:
77 BPath
path(fText
->Text());
78 if (path
.InitCheck() == B_OK
&& path
.GetParent(&path
) == B_OK
)
79 fPanel
->SetPanelDirectory(path
.Path());
87 if (msg
->FindRef("refs", &ref
) == B_OK
) {
89 if (entry
.InitCheck() == B_OK
) {
93 fText
->SetText(path
.Path());
100 BView::MessageReceived(msg
);
107 FileControl::SetText(const char* pathOfFile
)
109 fText
->SetText(pathOfFile
);
114 FileControl::Text() const
116 return fText
->Text();
121 FileControl::SetEnabled(bool enabled
)
123 fText
->SetEnabled(enabled
);
124 fButton
->SetEnabled(enabled
);
131 MailFileConfigView::MailFileConfigView(const char* label
, const char* name
,
132 bool useMeta
, const char* defaultPath
, uint32 flavors
)
134 FileControl(name
, label
, defaultPath
, flavors
),
142 MailFileConfigView::SetTo(const BMessage
* archive
, BMessage
* meta
)
144 SetText((fUseMeta
? meta
: archive
)->FindString(fName
));
150 MailFileConfigView::SaveInto(BMailAddOnSettings
& settings
) const
152 BMessage
* archive
= fUseMeta
? fMeta
: &settings
;
153 return archive
->SetString(fName
, Text());
157 } // namespace BPrivate