BPicture: Fix archive constructor.
[haiku.git] / src / kits / mail / FileConfigView.cpp
blob432a889cb73014e07b784bd2a11da820835d1b11
1 /*
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.
6 */
9 //! A file configuration view for filters
12 #include <FileConfigView.h>
14 #include <stdio.h>
16 #include <Button.h>
17 #include <Catalog.h>
18 #include <GroupLayout.h>
19 #include <MailSettingsView.h>
20 #include <Message.h>
21 #include <Path.h>
22 #include <String.h>
23 #include <TextControl.h>
26 #undef B_TRANSLATION_CONTEXT
27 #define B_TRANSLATION_CONTEXT "MailKit"
30 static const uint32 kMsgSelectButton = 'fsel';
33 namespace BPrivate {
36 FileControl::FileControl(const char* name, const char* label,
37 const char* pathOfFile, uint32 flavors)
39 BView(name, 0)
41 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
42 SetLayout(new BGroupLayout(B_HORIZONTAL));
44 fText = new BTextControl("file_path", label, pathOfFile, NULL);
45 AddChild(fText);
47 fButton = new BButton("select_file", B_TRANSLATE("Select" B_UTF8_ELLIPSIS),
48 new BMessage(kMsgSelectButton));
49 AddChild(fButton);
51 fPanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL, flavors, false);
55 FileControl::~FileControl()
57 delete fPanel;
61 void
62 FileControl::AttachedToWindow()
64 fButton->SetTarget(this);
65 fPanel->SetTarget(this);
69 void
70 FileControl::MessageReceived(BMessage* msg)
72 switch (msg->what) {
73 case kMsgSelectButton:
75 fPanel->Hide();
77 BPath path(fText->Text());
78 if (path.InitCheck() == B_OK && path.GetParent(&path) == B_OK)
79 fPanel->SetPanelDirectory(path.Path());
81 fPanel->Show();
82 break;
84 case B_REFS_RECEIVED:
86 entry_ref ref;
87 if (msg->FindRef("refs", &ref) == B_OK) {
88 BEntry entry(&ref);
89 if (entry.InitCheck() == B_OK) {
90 BPath path;
91 entry.GetPath(&path);
93 fText->SetText(path.Path());
96 break;
99 default:
100 BView::MessageReceived(msg);
101 break;
106 void
107 FileControl::SetText(const char* pathOfFile)
109 fText->SetText(pathOfFile);
113 const char*
114 FileControl::Text() const
116 return fText->Text();
120 void
121 FileControl::SetEnabled(bool enabled)
123 fText->SetEnabled(enabled);
124 fButton->SetEnabled(enabled);
128 // #pragma mark -
131 MailFileConfigView::MailFileConfigView(const char* label, const char* name,
132 bool useMeta, const char* defaultPath, uint32 flavors)
134 FileControl(name, label, defaultPath, flavors),
135 fUseMeta(useMeta),
136 fName(name)
141 void
142 MailFileConfigView::SetTo(const BMessage* archive, BMessage* meta)
144 SetText((fUseMeta ? meta : archive)->FindString(fName));
145 fMeta = meta;
149 status_t
150 MailFileConfigView::SaveInto(BMailAddOnSettings& settings) const
152 BMessage* archive = fUseMeta ? fMeta : &settings;
153 return archive->SetString(fName, Text());
157 } // namespace BPrivate