1 /* 2 * Copyright 2010, Haiku, Inc. All Rights Reserved. 3 * Copyright 2009, Pier Luigi Fiorini. 4 * Distributed under the terms of the MIT License. 5 * 6 * Authors: 7 * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com 8 */ 9 10 #include <Application.h> 11 #include <GroupLayout.h> 12 #include <GroupLayoutBuilder.h> 13 #include <Button.h> 14 #include <Catalog.h> 15 16 #include "PrefletWin.h" 17 #include "PrefletView.h" 18 19 20 #undef B_TRANSLATE_CONTEXT 21 #define B_TRANSLATE_CONTEXT "PrefletWin" 22 23 24 const int32 kRevert = '_RVT'; 25 const int32 kSave = '_SAV'; 26 27 28 PrefletWin::PrefletWin() 29 : 30 BWindow(BRect(0, 0, 1, 1), B_TRANSLATE_SYSTEM_NAME("Notifications"), 31 B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE 32 | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) 33 { 34 // Preflet container view 35 fMainView = new PrefletView(this); 36 37 // Save and revert buttons 38 fRevert = new BButton("revert", B_TRANSLATE("Revert"), 39 new BMessage(kRevert)); 40 fRevert->SetEnabled(false); 41 fSave = new BButton("save", B_TRANSLATE("Save"), new BMessage(kSave)); 42 fSave->SetEnabled(false); 43 44 // Calculate inset 45 float inset = ceilf(be_plain_font->Size() * 0.7f); 46 47 // Build the layout 48 SetLayout(new BGroupLayout(B_VERTICAL)); 49 50 // Add childs 51 AddChild(BGroupLayoutBuilder(B_VERTICAL, inset) 52 .Add(fMainView) 53 54 .AddGroup(B_HORIZONTAL, inset) 55 .AddGlue() 56 .Add(fRevert) 57 .Add(fSave) 58 .End() 59 60 .SetInsets(inset, inset, inset, inset) 61 ); 62 63 // Center this window on screen and show it 64 CenterOnScreen(); 65 Show(); 66 } 67 68 69 void 70 PrefletWin::MessageReceived(BMessage* msg) 71 { 72 switch (msg->what) { 73 case kSave: 74 for (int32 i = 0; i < fMainView->CountPages(); i++) { 75 SettingsPane* pane = 76 dynamic_cast<SettingsPane*>(fMainView->PageAt(i)); 77 if (pane) { 78 if (pane->Save() == B_OK) { 79 fSave->SetEnabled(false); 80 fRevert->SetEnabled(true); 81 } else 82 break; 83 } 84 } 85 break; 86 case kRevert: 87 for (int32 i = 0; i < fMainView->CountPages(); i++) { 88 SettingsPane* pane = 89 dynamic_cast<SettingsPane*>(fMainView->PageAt(i)); 90 if (pane) { 91 if (pane->Revert() == B_OK) 92 fRevert->SetEnabled(false); 93 } 94 } 95 break; 96 default: 97 BWindow::MessageReceived(msg); 98 } 99 } 100 101 102 bool 103 PrefletWin::QuitRequested() 104 { 105 be_app_messenger.SendMessage(B_QUIT_REQUESTED); 106 return true; 107 } 108 109 110 void 111 PrefletWin::SettingChanged() 112 { 113 fSave->SetEnabled(true); 114 } 115