tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / preferences / notifications / DisplayView.cpp
blob98bde3c4990a80fe8b9accafca32386457980fcd
1 /*
2 * Copyright 2010, Haiku, Inc. All Rights Reserved.
3 * Copyright 2009, Pier Luigi Fiorini.
4 * Distributed under the terms of the MIT License.
6 * Authors:
7 * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
8 */
10 #include <stdio.h>
11 #include <stdlib.h>
13 #include <Alert.h>
14 #include <Catalog.h>
15 #include <Directory.h>
16 #include <Message.h>
17 #include <FindDirectory.h>
18 #include <GroupLayout.h>
19 #include <GridLayoutBuilder.h>
20 #include <SpaceLayoutItem.h>
21 #include <TextControl.h>
22 #include <Menu.h>
23 #include <MenuItem.h>
24 #include <MenuField.h>
25 #include <Mime.h>
26 #include <Node.h>
27 #include <notification/Notifications.h>
28 #include <Path.h>
30 #include "DisplayView.h"
31 #include "SettingsHost.h"
34 #undef B_TRANSLATION_CONTEXT
35 #define B_TRANSLATION_CONTEXT "DisplayView"
38 DisplayView::DisplayView(SettingsHost* host)
40 SettingsPane("display", host)
42 // Window width
43 fWindowWidth = new BTextControl(B_TRANSLATE("Window width:"), NULL,
44 new BMessage(kSettingChanged));
46 // Icon size
47 fIconSize = new BMenu("iconSize");
48 fIconSize->AddItem(new BMenuItem(B_TRANSLATE("Mini icon"),
49 new BMessage(kSettingChanged)));
50 fIconSize->AddItem(new BMenuItem(B_TRANSLATE("Large icon"),
51 new BMessage(kSettingChanged)));
52 fIconSize->SetLabelFromMarked(true);
53 fIconSizeField = new BMenuField(B_TRANSLATE("Icon size:"), fIconSize);
55 // Calculate inset
56 float inset = ceilf(be_plain_font->Size() * 0.7f);
58 SetLayout(new BGroupLayout(B_VERTICAL));
59 AddChild(BGridLayoutBuilder(inset, inset)
60 .Add(fWindowWidth->CreateLabelLayoutItem(), 0, 0)
61 .Add(fWindowWidth->CreateTextViewLayoutItem(), 1, 0)
62 .Add(fIconSizeField->CreateLabelLayoutItem(), 0, 1)
63 .Add(fIconSizeField->CreateMenuBarLayoutItem(), 1, 1)
64 .Add(BSpaceLayoutItem::CreateGlue(), 0, 2, 2, 1)
65 .SetInsets(inset, inset, inset, inset)
70 void
71 DisplayView::AttachedToWindow()
73 fWindowWidth->SetTarget(this);
74 fIconSize->SetTargetForItems(this);
78 void
79 DisplayView::MessageReceived(BMessage* msg)
81 switch (msg->what) {
82 case kSettingChanged:
83 SettingsPane::MessageReceived(msg);
84 break;
85 default:
86 BView::MessageReceived(msg);
91 status_t
92 DisplayView::Load(BMessage& settings)
94 #if 0
95 BPath path;
97 if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
98 return B_ERROR;
100 path.Append(kSettingsFile);
102 BFile file(path.Path(), B_READ_ONLY);
103 BMessage settings;
104 settings.Unflatten(&file);
105 #endif
107 char buffer[255];
108 int32 setting;
109 BMenuItem* item = NULL;
111 float width;
112 if (settings.FindFloat(kWidthName, &width) != B_OK)
113 width = kDefaultWidth;
114 (void)sprintf(buffer, "%.2f", width);
115 fWindowWidth->SetText(buffer);
117 icon_size iconSize;
118 if (settings.FindInt32(kIconSizeName, &setting) != B_OK)
119 iconSize = kDefaultIconSize;
120 else
121 iconSize = (icon_size)setting;
122 if (iconSize == B_MINI_ICON)
123 item = fIconSize->ItemAt(0);
124 else
125 item = fIconSize->ItemAt(1);
126 if (item)
127 item->SetMarked(true);
129 return B_OK;
133 status_t
134 DisplayView::Save(BMessage& settings)
136 float width = atof(fWindowWidth->Text());
137 settings.AddFloat(kWidthName, width);
139 icon_size iconSize = kDefaultIconSize;
140 switch (fIconSize->IndexOf(fIconSize->FindMarked())) {
141 case 0:
142 iconSize = B_MINI_ICON;
143 break;
144 default:
145 iconSize = B_LARGE_ICON;
147 settings.AddInt32(kIconSizeName, (int32)iconSize);
149 return B_OK;
153 status_t
154 DisplayView::Revert()
156 return B_ERROR;