1 /* 2 * Copyright (c) 2007, Haiku, Inc. 3 * Distributed under the terms of the MIT license. 4 * 5 * Author: 6 * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org> 7 */ 8 9 10 #include "PackageStatus.h" 11 12 #include <Autolock.h> 13 #include <Catalog.h> 14 #include <GroupLayout.h> 15 #include <LayoutBuilder.h> 16 #include <Locale.h> 17 18 #include <stdio.h> 19 #include <string.h> 20 21 #undef B_TRANSLATION_CONTEXT 22 #define B_TRANSLATION_CONTEXT "PackageStatus" 23 24 StopButton::StopButton() 25 : 26 BButton(BRect(0, 0, 22, 18), "stop", B_TRANSLATE("Stop"), 27 new BMessage(P_MSG_STOP)) 28 { 29 } 30 31 32 void 33 StopButton::Draw(BRect updateRect) 34 { 35 BButton::Draw(updateRect); 36 37 updateRect = Bounds(); 38 updateRect.InsetBy((updateRect.Width() - 4) / 2, 39 (updateRect.Height() - 4) / 2); 40 //updateRect.InsetBy(9, 7); 41 SetHighColor(0, 0, 0); 42 FillRect(updateRect); 43 } 44 45 46 // #pragma mark - 47 48 49 PackageStatus::PackageStatus(const char *title, const char *label, 50 const char *trailing, BHandler *parent) 51 : 52 BWindow(BRect(200, 200, 550, 255), title, B_TITLED_WINDOW, 53 B_NOT_CLOSABLE | B_NOT_RESIZABLE | B_NOT_ZOOMABLE, 0), 54 fIsStopped(false), 55 fParent(parent) 56 { 57 fStatus = new BStatusBar("status_bar", B_TRANSLATE("Installing package")); 58 fStatus->SetBarHeight(12); 59 60 fButton = new StopButton(); 61 fButton->SetExplicitMaxSize(BSize(22, 18)); 62 63 BLayoutBuilder::Group<>(this, B_HORIZONTAL, 0) 64 .AddStrut(5.0f) 65 .Add(fStatus) 66 .Add(fButton); 67 68 fButton->SetTarget(this); 69 Run(); 70 } 71 72 73 PackageStatus::~PackageStatus() 74 { 75 } 76 77 78 void 79 PackageStatus::MessageReceived(BMessage *msg) 80 { 81 switch (msg->what) { 82 case P_MSG_STOP: 83 fIsStopped = true; 84 if (fParent != NULL) { 85 // If we have a parent defined, forward this message 86 BLooper *loop = fParent->Looper(); 87 if (loop != NULL) { 88 loop->PostMessage(msg, fParent); 89 } 90 } 91 break; 92 default: 93 BWindow::MessageReceived(msg); 94 } 95 } 96 97 98 void 99 PackageStatus::Reset(uint32 stages, const char *label, const char *trailing) 100 { 101 BAutolock lock(this); 102 103 if (lock.IsLocked()) { 104 fStatus->Reset(label, trailing); 105 fStatus->SetMaxValue(stages); 106 fIsStopped = false; 107 } 108 } 109 110 111 void 112 PackageStatus::StageStep(uint32 count, const char *text, const char *trailing) 113 { 114 BAutolock lock(this); 115 116 if (lock.IsLocked()) { 117 fStatus->Update(count, text, trailing); 118 } 119 } 120 121 122 bool 123 PackageStatus::Stopped() 124 { 125 BAutolock lock(this); 126 return fIsStopped; 127 } 128 129