1 /*****************************************************************************/
3 // Written by Michael Wilber
5 // SlideShowConfigView.cpp
7 // This BView based object displays the SlideShowSaver settings options
10 // Copyright (C) Haiku
12 // Permission is hereby granted, free of charge, to any person obtaining a
13 // copy of this software and associated documentation files (the "Software"),
14 // to deal in the Software without restriction, including without limitation
15 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 // and/or sell copies of the Software, and to permit persons to whom the
17 // Software is furnished to do so, subject to the following conditions:
19 // The above copyright notice and this permission notice shall be included
20 // in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 // DEALINGS IN THE SOFTWARE.
29 /*****************************************************************************/
33 #include <FilePanel.h>
34 #include "SlideShowConfigView.h"
37 delay_msg(int32 option
)
39 BMessage
*pMsg
= new BMessage(CHANGE_DELAY
);
40 pMsg
->AddInt32("delay", option
);
44 // ---------------------------------------------------------------
47 // Sets up the view settings
56 // ---------------------------------------------------------------
57 SlideShowConfigView::SlideShowConfigView(const BRect
&frame
, const char *name
,
58 uint32 resize
, uint32 flags
, LiveSettings
*settings
)
59 : BView(frame
, name
, resize
, flags
)
63 SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
68 // Show Caption checkbox
69 pMsg
= new BMessage(CHANGE_CAPTION
);
70 fShowCaption
= new BCheckBox(BRect(10, 45, 180, 62),
71 "Show caption", "Show caption", pMsg
);
72 val
= (fSettings
->SetGetBool(SAVER_SETTING_CAPTION
)) ? 1 : 0;
73 fShowCaption
->SetValue(val
);
74 fShowCaption
->SetViewColor(ViewColor());
75 AddChild(fShowCaption
);
77 // Change Border checkbox
78 pMsg
= new BMessage(CHANGE_BORDER
);
79 fShowBorder
= new BCheckBox(BRect(10, 70, 180, 87),
80 "Show border", "Show border", pMsg
);
81 val
= (fSettings
->SetGetBool(SAVER_SETTING_BORDER
)) ? 1 : 0;
82 fShowBorder
->SetValue(val
);
83 fShowBorder
->SetViewColor(ViewColor());
84 AddChild(fShowBorder
);
87 // setup PNG interlace options menu
88 int32 currentDelay
= fSettings
->SetGetInt32(SAVER_SETTING_DELAY
) / 1000;
89 fDelayMenu
= new BPopUpMenu("Delay menu");
109 {"1 minute", 1 * 60},
110 {"2 minutes", 2 * 60},
111 {"5 minutes", 5 * 60},
112 {"10 minutes", 10 * 60},
113 {"15 minutes", 15 * 60}
115 for (uint32 i
= 0; i
< sizeof(items
) / sizeof(DelayItem
); i
++) {
116 BMenuItem
*menuItem
=
117 new BMenuItem(items
[i
].name
, delay_msg(items
[i
].delay
));
118 fDelayMenu
->AddItem(menuItem
);
119 if (items
[i
].delay
== currentDelay
)
120 menuItem
->SetMarked(true);
122 fDelayMenuField
= new BMenuField(BRect(10, 100, 180, 120),
123 "Delay Menu Field", "Delay:", fDelayMenu
);
124 fDelayMenuField
->SetViewColor(ViewColor());
125 fDelayMenuField
->SetDivider(40);
126 AddChild(fDelayMenuField
);
128 // Choose Image Folder button
129 pMsg
= new BMessage(CHOOSE_DIRECTORY
);
130 fChooseFolder
= new BButton(BRect(50, 160, 180, 180),
131 "Choose Folder", "Choose image folder" B_UTF8_ELLIPSIS
, pMsg
);
132 AddChild(fChooseFolder
);
134 // Setup choose folder file panel
135 pMsg
= new BMessage(CHANGE_DIRECTORY
);
136 fFilePanel
= new BFilePanel(B_OPEN_PANEL
, NULL
, (const entry_ref
*) NULL
,
137 B_DIRECTORY_NODE
, false, pMsg
, NULL
, true, true);
138 fFilePanel
->SetButtonLabel(B_DEFAULT_BUTTON
, "Select");
142 // ---------------------------------------------------------------
145 // Releases the translator settings
154 // ---------------------------------------------------------------
155 SlideShowConfigView::~SlideShowConfigView()
157 fSettings
->Release();
163 // ---------------------------------------------------------------
175 // ---------------------------------------------------------------
177 SlideShowConfigView::AllAttached()
179 BMessenger
msgr(this);
180 fShowCaption
->SetTarget(msgr
);
181 fShowBorder
->SetTarget(msgr
);
182 fChooseFolder
->SetTarget(msgr
);
183 fFilePanel
->SetTarget(msgr
);
185 // Set target for menu items
186 for (int32 i
= 0; i
< fDelayMenu
->CountItems(); i
++) {
187 BMenuItem
*item
= fDelayMenu
->ItemAt(i
);
189 item
->SetTarget(msgr
);
193 // ---------------------------------------------------------------
196 // Handles state changes of the RLE setting checkbox
200 // Parameters: message the actual BMessage that was received
205 // ---------------------------------------------------------------
207 SlideShowConfigView::MessageReceived(BMessage
*message
)
210 switch (message
->what
) {
212 if (fShowCaption
->Value())
216 fSettings
->SetGetBool(SAVER_SETTING_CAPTION
, &bNewVal
);
217 fSettings
->SaveSettings();
221 if (fShowBorder
->Value())
225 fSettings
->SetGetBool(SAVER_SETTING_BORDER
, &bNewVal
);
226 fSettings
->SaveSettings();
229 case CHOOSE_DIRECTORY
:
231 BString strDirectory
;
232 fSettings
->GetString(SAVER_SETTING_DIRECTORY
, strDirectory
);
233 BEntry
entry(strDirectory
.String());
234 if (entry
.InitCheck() != B_OK
)
237 if (entry
.GetRef(&ref
) != B_OK
)
239 fFilePanel
->SetPanelDirectory(&ref
);
245 case CHANGE_DIRECTORY
:
248 if (message
->FindRef("refs", &ref
) != B_OK
)
250 BEntry
entry(&ref
, true);
251 if (entry
.InitCheck() != B_OK
)
254 if (path
.InitCheck() != B_OK
)
256 BString strDirectory
= path
.Path();
258 fSettings
->SetString(SAVER_SETTING_DIRECTORY
, strDirectory
);
259 fSettings
->SaveSettings();
268 if (message
->FindInt32("delay", &newVal
) == B_OK
) {
270 fSettings
->SetGetInt32(SAVER_SETTING_DELAY
, &newVal
);
271 fSettings
->SaveSettings();
277 BView::MessageReceived(message
);
282 // ---------------------------------------------------------------
285 // Draws information about the SlideShowConfigTranslator to this view.
289 // Parameters: area, not used
294 // ---------------------------------------------------------------
296 SlideShowConfigView::Draw(BRect area
)
298 SetFont(be_bold_font
);
302 xbold
= fh
.descent
+ 1;
303 ybold
= fh
.ascent
+ fh
.descent
* 2 + fh
.leading
;
305 char title
[] = "SlideShow Screen Saver";
306 DrawString(title
, BPoint(xbold
, ybold
));
308 SetFont(be_plain_font
);
310 GetFontHeight(&plainh
);
312 yplain
= plainh
.ascent
+ plainh
.descent
* 2 + plainh
.leading
;
314 char writtenby
[] = "Written by Michael Wilber";
315 DrawString(writtenby
, BPoint(xbold
, yplain
* 1 + ybold
));
317 // Draw current folder
319 fSettings
->GetString(SAVER_SETTING_DIRECTORY
, strFolder
);
320 strFolder
.Prepend("Image folder: ");
321 DrawString(strFolder
.String(), BPoint(10, yplain
* 9 + ybold
));