From 633dee064e847e9bd9857193f7ae861e10ab21ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Fri, 30 Sep 2005 14:58:05 +0000 Subject: [PATCH] fix packages view, added a copy engine class git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14283 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/installer/CopyEngine.cpp | 85 ++++++++++++++++++++++++++ src/apps/installer/CopyEngine.h | 32 ++++++++++ src/apps/installer/InstallerWindow.cpp | 20 ++++-- src/apps/installer/InstallerWindow.h | 4 ++ src/apps/installer/Jamfile | 2 + src/apps/installer/PackageViews.cpp | 60 +++++++++--------- src/apps/installer/PackageViews.h | 22 +++---- 7 files changed, 181 insertions(+), 44 deletions(-) create mode 100644 src/apps/installer/CopyEngine.cpp create mode 100644 src/apps/installer/CopyEngine.h diff --git a/src/apps/installer/CopyEngine.cpp b/src/apps/installer/CopyEngine.cpp new file mode 100644 index 0000000000..a19893eb31 --- /dev/null +++ b/src/apps/installer/CopyEngine.cpp @@ -0,0 +1,85 @@ +/* + * Copyright 2005, Jérôme DUVAL. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include "CopyEngine.h" +#include "InstallerWindow.h" +#include +#include + +CopyEngine::CopyEngine(InstallerWindow *window) + : BLooper("copy_engine"), + fWindow(window) +{ + +} + + +void +CopyEngine::LaunchInitScript(BVolume *volume) +{ + fWindow->SetStatusMessage("Starting Installation."); +} + + +void +CopyEngine::LaunchFinishScript(BVolume *volume) +{ + fWindow->SetStatusMessage("Finishing Installation."); +} + + +void +CopyEngine::Start() +{ + BVolume *volume; + // check not installing on boot volume + + + // check if target is initialized + + // ask if init ou mount as is + + LaunchInitScript(volume); + + // copy source volume + + // copy selected packages + + LaunchFinishScript(volume); +} + + +void +CopyEngine::ScanDisksPartitions(BMenu *srcMenu, BMenu *dstMenu) +{ + BDiskDeviceRoster roster; + BDiskDevice device; + roster.VisitEachDevice(this, &device); + + BPartition *partition; + roster.VisitEachPartition(this, &device, &partition); +} + + +bool +CopyEngine::Visit(BDiskDevice *device) +{ + BPath path; + if (device->GetPath(&path)==B_OK) + printf("CopyEngine::Visit(BDiskDevice *) : %s\n", path.Path()); + return false; +} + + +bool +CopyEngine::Visit(BPartition *partition, int32 level) +{ + BPath path; + if (partition->GetPath(&path)==B_OK) + printf("CopyEngine::Visit(BPartition *) : %s\n", path.Path()); + printf("CopyEngine::Visit(BPartition *) : %s\n", partition->Name()); + return false; +} + diff --git a/src/apps/installer/CopyEngine.h b/src/apps/installer/CopyEngine.h new file mode 100644 index 0000000000..f2c0c5091e --- /dev/null +++ b/src/apps/installer/CopyEngine.h @@ -0,0 +1,32 @@ +/* + * Copyright 2005, Jérôme DUVAL. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#ifndef _CopyEngine_h +#define _CopyEngine_h + +#include +#include +#include +#include +#include +#include + +class InstallerWindow; + +class CopyEngine : public BLooper, BDiskDeviceVisitor { +public: + CopyEngine(InstallerWindow *window); + void Start(); + void ScanDisksPartitions(BMenu *srcMenu, BMenu *dstMenu); + + virtual bool Visit(BDiskDevice *device); + virtual bool Visit(BPartition *partition, int32 level); +private: + void LaunchInitScript(BVolume *volume); + void LaunchFinishScript(BVolume *volume); + InstallerWindow *fWindow; +}; + +#endif /* _CopyEngine_h */ diff --git a/src/apps/installer/InstallerWindow.cpp b/src/apps/installer/InstallerWindow.cpp index 2db1287080..b998deb75c 100644 --- a/src/apps/installer/InstallerWindow.cpp +++ b/src/apps/installer/InstallerWindow.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -28,7 +29,8 @@ const uint32 PACKAGE_CHECKBOX = 'iPCB'; InstallerWindow::InstallerWindow(BRect frame_rect) : BWindow(frame_rect, "Installer", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE), - fDriveSetupLaunched(false) + fDriveSetupLaunched(false), + fCopyEngine(this) { BRect bounds = Bounds(); @@ -119,6 +121,7 @@ InstallerWindow::MessageReceived(BMessage *msg) StartScan(); break; case BEGIN_MESSAGE: + fCopyEngine.Start(); break; case SHOW_BOTTOM_MESSAGE: ShowBottom(); @@ -209,14 +212,14 @@ InstallerWindow::DisableInterface(bool disable) fSrcMenuField->SetEnabled(!disable); fDestMenuField->SetEnabled(!disable); if (disable) - fStatusView->SetText("Running DriveSetup" B_UTF8_ELLIPSIS "\nClose DriveSetup to continue with the\ninstallation."); + SetStatusMessage("Running DriveSetup" B_UTF8_ELLIPSIS "\nClose DriveSetup to continue with the\ninstallation."); } void InstallerWindow::StartScan() { - fStatusView->SetText("Scanning for disks" B_UTF8_ELLIPSIS); + SetStatusMessage("Scanning for disks" B_UTF8_ELLIPSIS); BMenuItem *item; while ((item = fSrcMenu->RemoveItem((int32)0))) @@ -224,6 +227,8 @@ InstallerWindow::StartScan() while ((item = fDestMenu->RemoveItem((int32)0))) delete item; + fCopyEngine.ScanDisksPartitions(fSrcMenu, fDestMenu); + fSrcMenu->AddItem(new PartitionMenuItem("BeOS 5 PE Max Edition V3.1 beta", new BMessage(SRC_PARTITION), "/BeOS 5 PE Max Edition V3.1 beta")); @@ -231,7 +236,7 @@ InstallerWindow::StartScan() fSrcMenu->ItemAt(0)->SetMarked(true); PublishPackages(); } - fStatusView->SetText("Choose the disk you want to install onto\nfrom the pop-up menu. Then click \"Begin\"."); + SetStatusMessage("Choose the disk you want to install onto\nfrom the pop-up menu. Then click \"Begin\"."); } @@ -281,3 +286,10 @@ InstallerWindow::ComparePackages(const void *firstArg, const void *secondArg) return strcmp(package1->Name(), package2->Name()); } + +void +InstallerWindow::SetStatusMessage(char *text) +{ + BAutolock(this); + fStatusView->SetText(text); +} diff --git a/src/apps/installer/InstallerWindow.h b/src/apps/installer/InstallerWindow.h index 1ca2303de6..665c4197b7 100644 --- a/src/apps/installer/InstallerWindow.h +++ b/src/apps/installer/InstallerWindow.h @@ -13,6 +13,7 @@ #include #include #include +#include "CopyEngine.h" #include "DrawButton.h" #include "PackageViews.h" @@ -23,6 +24,7 @@ public: virtual void MessageReceived(BMessage *msg); virtual bool QuitRequested(); + void SetStatusMessage(char *text); private: void DisableInterface(bool disable); void LaunchDriveSetup(); @@ -40,6 +42,8 @@ private: PackagesView *fPackagesView; BScrollView *fPackagesScrollView; BStringView *fSizeView; + + CopyEngine fCopyEngine; }; #endif /* _InstallerWindow_h */ diff --git a/src/apps/installer/Jamfile b/src/apps/installer/Jamfile index 667e166df0..2c382738fd 100644 --- a/src/apps/installer/Jamfile +++ b/src/apps/installer/Jamfile @@ -1,10 +1,12 @@ SubDir OBOS_TOP src apps installer ; UsePrivateHeaders shared ; +UsePrivateHeaders storage ; UsePrivateHeaders tracker ; SubDirHdrs [ FDirName $(OBOS_TOP) src kits tracker ] ; App Installer : + CopyEngine.cpp DrawButton.cpp InstallerApp.cpp InstallerCopyLoopControl.cpp diff --git a/src/apps/installer/PackageViews.cpp b/src/apps/installer/PackageViews.cpp index 51867826c9..58d7888131 100644 --- a/src/apps/installer/PackageViews.cpp +++ b/src/apps/installer/PackageViews.cpp @@ -32,8 +32,6 @@ SizeAsString(int32 size, char *string) Package::Package() : Group(), - fName(NULL), - fDescription(NULL), fSize(0), fIcon(NULL) { @@ -43,8 +41,6 @@ Package::Package() Package::~Package() { - free(fName); - free(fDescription); delete fIcon; } @@ -56,17 +52,16 @@ Package::PackageFromEntry(BEntry &entry) if (directory.InitCheck()!=B_OK) return NULL; Package *package = new Package(); - char name[255]; - char group[255]; - char description[255]; bool alwaysOn; bool onByDefault; int32 size; - if (directory.ReadAttr("INSTALLER PACKAGE: NAME", B_STRING_TYPE, 0, name, 255)<0) + char group[64]; + memset(group, 0, 64); + if (directory.ReadAttr("INSTALLER PACKAGE: NAME", B_STRING_TYPE, 0, package->fName, 64)<0) goto err; - if (directory.ReadAttr("INSTALLER PACKAGE: GROUP", B_STRING_TYPE, 0, group, 255)<0) + if (directory.ReadAttr("INSTALLER PACKAGE: GROUP", B_STRING_TYPE, 0, group, 64)<0) goto err; - if (directory.ReadAttr("INSTALLER PACKAGE: DESCRIPTION", B_STRING_TYPE, 0, description, 255)<0) + if (directory.ReadAttr("INSTALLER PACKAGE: DESCRIPTION", B_STRING_TYPE, 0, package->fDescription, 64)<0) goto err; if (directory.ReadAttr("INSTALLER PACKAGE: ON_BY_DEFAULT", B_BOOL_TYPE, 0, &onByDefault, sizeof(onByDefault))<0) goto err; @@ -74,9 +69,7 @@ Package::PackageFromEntry(BEntry &entry) goto err; if (directory.ReadAttr("INSTALLER PACKAGE: SIZE", B_INT32_TYPE, 0, &size, sizeof(size))<0) goto err; - package->SetName(name); package->SetGroupName(group); - package->SetDescription(description); package->SetSize(size); package->SetAlwaysOn(alwaysOn); package->SetOnByDefault(onByDefault); @@ -105,19 +98,17 @@ Package::GetSizeAsString(char *string) Group::Group() - : fGroup(NULL) { } Group::~Group() { - free(fGroup); } -PackageCheckBox::PackageCheckBox(BRect rect, Package &item) - : BCheckBox(rect.OffsetBySelf(7,0), "pack_cb", item.Name(), NULL), +PackageCheckBox::PackageCheckBox(BRect rect, Package *item) + : BCheckBox(rect.OffsetBySelf(7,0), "pack_cb", item->Name(), NULL), fPackage(item) { } @@ -125,6 +116,7 @@ PackageCheckBox::PackageCheckBox(BRect rect, Package &item) PackageCheckBox::~PackageCheckBox() { + delete fPackage; } @@ -133,17 +125,17 @@ PackageCheckBox::Draw(BRect update) { BCheckBox::Draw(update); char string[15]; - fPackage.GetSizeAsString(string); + fPackage->GetSizeAsString(string); float width = StringWidth(string); DrawString(string, BPoint(Bounds().right - width - 8, 11)); - const BBitmap *icon = fPackage.Icon(); + const BBitmap *icon = fPackage->Icon(); if (icon) DrawBitmap(icon, BPoint(Bounds().right - 92, 0)); } -GroupView::GroupView(BRect rect, Group &group) - : BStringView(rect, "group", group.GroupName()), +GroupView::GroupView(BRect rect, Group *group) + : BStringView(rect, "group", group->GroupName()), fGroup(group) { SetFont(be_bold_font); @@ -152,6 +144,7 @@ GroupView::GroupView(BRect rect, Group &group) GroupView::~GroupView() { + delete fGroup; } @@ -170,7 +163,14 @@ PackagesView::~PackagesView() void PackagesView::Clean() { - + BView *view; + while ((view = ChildAt(0))) { + if (dynamic_cast(view) || dynamic_cast(view)) { + RemoveChild(view); + delete view; + } + } + ScrollTo(0,0); } @@ -182,6 +182,7 @@ PackagesView::AddPackages(BList &packages, BMessage *msg) BRect bounds = rect; rect.left = 1; rect.bottom = 15; + rect.top = 0; BString lastGroup = ""; for (int32 i=0; iGroupName(); Group *group = new Group(); group->SetGroupName(package->GroupName()); - GroupView *view = new GroupView(rect, *group); + GroupView *view = new GroupView(rect, group); AddChild(view); rect.OffsetBy(0, 17); } - PackageCheckBox *checkBox = new PackageCheckBox(rect, *package); + PackageCheckBox *checkBox = new PackageCheckBox(rect, package); checkBox->SetValue(package->OnByDefault() ? B_CONTROL_ON : B_CONTROL_OFF); checkBox->SetEnabled(!package->AlwaysOn()); - checkBox->SetMessage(msg); + checkBox->SetMessage(new BMessage(*msg)); AddChild(checkBox); rect.OffsetBy(0, 20); } - ResizeTo(bounds.Width(), rect.bottom); + ResizeTo(bounds.Width(), rect.top); BScrollBar *vertScroller = ScrollBar(B_VERTICAL); - if (bounds.Height() > rect.top) { + if (vertScroller->Bounds().Height() > rect.top) { vertScroller->SetRange(0.0f, 0.0f); vertScroller->SetValue(0.0f); } else { - vertScroller->SetRange(0.0f, rect.top - bounds.Height()); - vertScroller->SetProportion(bounds.Height () / rect.top); + vertScroller->SetRange(0.0f, rect.top - vertScroller->Bounds().Height()); + vertScroller->SetProportion(vertScroller->Bounds().Height() / rect.top); } - vertScroller->SetSteps(15, bounds.Height()); + vertScroller->SetSteps(15, vertScroller->Bounds().Height()); Invalidate(); } @@ -232,3 +233,4 @@ PackagesView::GetTotalSizeAsString(char *string) } SizeAsString(size, string); } + diff --git a/src/apps/installer/PackageViews.h b/src/apps/installer/PackageViews.h index 0ae4238971..015097c115 100644 --- a/src/apps/installer/PackageViews.h +++ b/src/apps/installer/PackageViews.h @@ -17,10 +17,10 @@ class Group { public: Group(); virtual ~Group(); - void SetGroupName(const char *group) { free(fGroup); fGroup=strdup(group);}; + void SetGroupName(const char *group) { strcpy(fGroup, group); }; const char * GroupName() const { return fGroup; }; private: - char *fGroup; + char fGroup[64]; }; @@ -28,8 +28,8 @@ class Package : public Group { public: Package(); virtual ~Package(); - void SetName(const char *name) { free(fName); fName=strdup(name);}; - void SetDescription(const char *description) { free(fDescription); fDescription=strdup(description);}; + void SetName(const char *name) { strcpy(fName, name);}; + void SetDescription(const char *description) { strcpy(fDescription, description);}; void SetSize(const int32 size) { fSize = size; }; void SetIcon(BBitmap * icon) { delete fIcon; fIcon = icon; }; void SetOnByDefault(bool onByDefault) { fOnByDefault = onByDefault; }; @@ -44,8 +44,8 @@ public: static Package *PackageFromEntry(BEntry &dir); private: - char *fName; - char *fDescription; + char fName[64]; + char fDescription[64]; int32 fSize; BBitmap *fIcon; bool fAlwaysOn, fOnByDefault; @@ -54,20 +54,20 @@ private: class PackageCheckBox : public BCheckBox { public: - PackageCheckBox(BRect rect, Package &item); + PackageCheckBox(BRect rect, Package *item); virtual ~PackageCheckBox(); virtual void Draw(BRect update); - Package *GetPackage() { return &fPackage; }; + Package *GetPackage() { return fPackage; }; private: - Package &fPackage; + Package *fPackage; }; class GroupView : public BStringView { public: - GroupView(BRect rect, Group &group); + GroupView(BRect rect, Group *group); virtual ~GroupView(); private: - Group &fGroup; + Group *fGroup; };