displays package list
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14234 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
482a9b5d8c
commit
8d71ca3e25
src/apps/installer
@ -6,11 +6,13 @@
|
||||
#include <Alert.h>
|
||||
#include <Application.h>
|
||||
#include <Box.h>
|
||||
#include <ClassInfo.h>
|
||||
#include <Directory.h>
|
||||
#include <Path.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Roster.h>
|
||||
#include <string.h>
|
||||
#include <String.h>
|
||||
#include "InstallerWindow.h"
|
||||
#include "PartitionMenuItem.h"
|
||||
|
||||
@ -202,8 +204,10 @@ InstallerWindow::StartScan()
|
||||
fSrcMenu->AddItem(new PartitionMenuItem("BeOS 5 PE Max Edition V3.1 beta",
|
||||
new BMessage(SRC_PARTITION), "/BeOS 5 PE Max Edition V3.1 beta"));
|
||||
|
||||
if (fSrcMenu->ItemAt(0))
|
||||
if (fSrcMenu->ItemAt(0)) {
|
||||
fSrcMenu->ItemAt(0)->SetMarked(true);
|
||||
PublishPackages();
|
||||
}
|
||||
fStatusView->SetText("Choose the disk you want to install onto\nfrom the pop-up menu. Then click \"Begin\".");
|
||||
}
|
||||
|
||||
@ -223,6 +227,33 @@ InstallerWindow::PublishPackages()
|
||||
return;
|
||||
|
||||
BEntry packageEntry;
|
||||
BList packages;
|
||||
while (dir.GetNextEntry(&packageEntry)==B_OK) {
|
||||
Package *package = Package::PackageFromEntry(packageEntry);
|
||||
if (package) {
|
||||
packages.AddItem(package);
|
||||
}
|
||||
}
|
||||
packages.SortItems(ComparePackages);
|
||||
|
||||
fPackagesView->AddPackages(packages);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
InstallerWindow::ComparePackages(const void *firstArg, const void *secondArg)
|
||||
{
|
||||
const Group *group1 = *static_cast<const Group * const *>(firstArg);
|
||||
const Group *group2 = *static_cast<const Group * const *>(secondArg);
|
||||
const Package *package1 = dynamic_cast<const Package *>(group1);
|
||||
const Package *package2 = dynamic_cast<const Package *>(group2);
|
||||
int sameGroup = strcmp(group1->GroupName(), group2->GroupName());
|
||||
if (sameGroup != 0)
|
||||
return sameGroup;
|
||||
if (!package2)
|
||||
return -1;
|
||||
if (!package1)
|
||||
return 1;
|
||||
return strcmp(package1->Name(), package2->Name());
|
||||
}
|
||||
|
||||
|
@ -23,13 +23,13 @@ public:
|
||||
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
private:
|
||||
void DisableInterface(bool disable);
|
||||
void LaunchDriveSetup();
|
||||
void PublishPackages();
|
||||
void ShowBottom();
|
||||
void StartScan();
|
||||
static int ComparePackages(const void *firstArg, const void *secondArg);
|
||||
BBox *fBackBox;
|
||||
BButton *fBeginButton, *fSetupButton;
|
||||
DrawButton *fDrawButton;
|
||||
|
@ -4,12 +4,14 @@
|
||||
*/
|
||||
|
||||
#include <Directory.h>
|
||||
#include <ScrollBar.h>
|
||||
#include <String.h>
|
||||
#include <View.h>
|
||||
#include "PackageViews.h"
|
||||
|
||||
Package::Package()
|
||||
: fName(NULL),
|
||||
fGroup(NULL),
|
||||
: Group(),
|
||||
fName(NULL),
|
||||
fDescription(NULL),
|
||||
fSize(0),
|
||||
fIcon(NULL)
|
||||
@ -21,7 +23,6 @@ Package::Package()
|
||||
Package::~Package()
|
||||
{
|
||||
free(fName);
|
||||
free(fGroup);
|
||||
free(fDescription);
|
||||
free(fIcon);
|
||||
}
|
||||
@ -34,22 +35,51 @@ 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)
|
||||
goto err;
|
||||
if (directory.ReadAttr("INSTALLER PACKAGE: GROUP", B_STRING_TYPE, 0, group, 255)<0)
|
||||
goto err;
|
||||
if (directory.ReadAttr("INSTALLER PACKAGE: DESCRIPTION", B_STRING_TYPE, 0, description, 255)<0)
|
||||
goto err;
|
||||
if (directory.ReadAttr("INSTALLER PACKAGE: ON_BY_DEFAULT", B_BOOL_TYPE, 0, &onByDefault, sizeof(onByDefault))<0)
|
||||
goto err;
|
||||
if (directory.ReadAttr("INSTALLER PACKAGE: ALWAYS_ON", B_BOOL_TYPE, 0, &alwaysOn, sizeof(alwaysOn))<0)
|
||||
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);
|
||||
return package;
|
||||
err:
|
||||
delete package;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Group::Group()
|
||||
: fGroup(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Group::~Group()
|
||||
{
|
||||
free(fGroup);
|
||||
}
|
||||
|
||||
|
||||
PackageCheckBox::PackageCheckBox(BRect rect, Package &item)
|
||||
: BCheckBox(rect, "pack_cb", item.Name(), NULL),
|
||||
: BCheckBox(rect.OffsetBySelf(7,0), "pack_cb", item.Name(), NULL),
|
||||
fPackage(item)
|
||||
{
|
||||
}
|
||||
@ -68,10 +98,10 @@ PackageCheckBox::Draw(BRect update)
|
||||
|
||||
|
||||
GroupView::GroupView(BRect rect, Group &group)
|
||||
: BStringView(rect, "group", group.Name()),
|
||||
: BStringView(rect, "group", group.GroupName()),
|
||||
fGroup(group)
|
||||
{
|
||||
|
||||
SetFont(be_bold_font);
|
||||
}
|
||||
|
||||
GroupView::~GroupView()
|
||||
@ -92,33 +122,53 @@ PackagesView::~PackagesView()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackagesView::AddPackage(Package &package)
|
||||
void
|
||||
PackagesView::Clean()
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
rect.top = rect.bottom;
|
||||
rect.bottom += 15;
|
||||
PackageCheckBox *checkBox = new PackageCheckBox(rect, package);
|
||||
AddChild(checkBox);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackagesView::AddGroup(Group &group)
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
rect.top = rect.bottom;
|
||||
rect.bottom += 15;
|
||||
GroupView *view = new GroupView(rect, group);
|
||||
AddChild(view);
|
||||
Invalidate();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackagesView::Clean()
|
||||
PackagesView::AddPackages(BList &packages)
|
||||
{
|
||||
int32 count = packages.CountItems();
|
||||
BRect rect = Bounds();
|
||||
BRect bounds = rect;
|
||||
rect.left = 1;
|
||||
rect.bottom = 15;
|
||||
BString lastGroup = "";
|
||||
for (int32 i=0; i<count; i++) {
|
||||
void *item = packages.ItemAt(i);
|
||||
Package *package = static_cast<Package *> (item);
|
||||
if (lastGroup != BString(package->GroupName())) {
|
||||
rect.OffsetBy(0, 1);
|
||||
lastGroup = package->GroupName();
|
||||
Group *group = new Group();
|
||||
group->SetGroupName(package->GroupName());
|
||||
GroupView *view = new GroupView(rect, *group);
|
||||
AddChild(view);
|
||||
rect.OffsetBy(0, 17);
|
||||
}
|
||||
PackageCheckBox *checkBox = new PackageCheckBox(rect, *package);
|
||||
checkBox->SetValue(package->OnByDefault() ? B_CONTROL_ON : B_CONTROL_OFF);
|
||||
checkBox->SetEnabled(!package->AlwaysOn());
|
||||
AddChild(checkBox);
|
||||
rect.OffsetBy(0, 20);
|
||||
}
|
||||
ResizeTo(bounds.Width(), rect.bottom);
|
||||
|
||||
BScrollBar *vertScroller = ScrollBar(B_VERTICAL);
|
||||
|
||||
if (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->SetSteps(15, bounds.Height());
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
@ -12,41 +12,44 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
class Package {
|
||||
public:
|
||||
Package();
|
||||
~Package();
|
||||
void SetName(const char *name) { free(fName); fName=strdup(name);};
|
||||
void SetGroup(const char *group) { free(fGroup); fName=strdup(group);};
|
||||
void SetDescription(const char *description) { free(fDescription); fName=strdup(description);};
|
||||
void SetSize(const int32 size) { fSize = size; };
|
||||
void SetIcon(const BBitmap * icon);
|
||||
const char * Name() { return fName; };
|
||||
const char * Group() { return fGroup; };
|
||||
const char * Description() { return fDescription; };
|
||||
const int32 Size() { return fSize; };
|
||||
const BBitmap * Icon() { return fIcon; };
|
||||
|
||||
static int Compare(const void *firstArg, const void *secondArg);
|
||||
static Package *PackageFromEntry(BEntry &dir);
|
||||
private:
|
||||
char *fName;
|
||||
char *fGroup;
|
||||
char *fDescription;
|
||||
int32 fSize;
|
||||
BBitmap *fIcon;
|
||||
};
|
||||
|
||||
class Group {
|
||||
public:
|
||||
Group();
|
||||
~Group();
|
||||
virtual ~Group();
|
||||
void SetGroupName(const char *group) { free(fGroup); fGroup=strdup(group);};
|
||||
const char * GroupName() const { return fGroup; };
|
||||
private:
|
||||
char *fGroup;
|
||||
};
|
||||
|
||||
|
||||
class Package : public Group {
|
||||
public:
|
||||
Package();
|
||||
virtual ~Package();
|
||||
void SetName(const char *name) { free(fName); fName=strdup(name);};
|
||||
const char * Name() { return fName; };
|
||||
void SetDescription(const char *description) { free(fDescription); fDescription=strdup(description);};
|
||||
void SetSize(const int32 size) { fSize = size; };
|
||||
void SetIcon(const BBitmap * icon);
|
||||
void SetOnByDefault(bool onByDefault) { fOnByDefault = onByDefault; };
|
||||
void SetAlwaysOn(bool alwaysOn) { fAlwaysOn = alwaysOn; };
|
||||
const char * Name() const { return fName; };
|
||||
const char * Description() const { return fDescription; };
|
||||
const int32 Size() const { return fSize; };
|
||||
const BBitmap * Icon() const { return fIcon; };
|
||||
bool OnByDefault() const { return fOnByDefault; };
|
||||
bool AlwaysOn() const { return fAlwaysOn; };
|
||||
|
||||
static Package *PackageFromEntry(BEntry &dir);
|
||||
private:
|
||||
char *fName;
|
||||
char *fDescription;
|
||||
int32 fSize;
|
||||
BBitmap *fIcon;
|
||||
bool fAlwaysOn, fOnByDefault;
|
||||
};
|
||||
|
||||
|
||||
class PackageCheckBox : public BCheckBox {
|
||||
public:
|
||||
PackageCheckBox(BRect rect, Package &item);
|
||||
@ -70,9 +73,8 @@ class PackagesView : public BView {
|
||||
public:
|
||||
PackagesView(BRect rect, const char* name);
|
||||
~PackagesView();
|
||||
void AddPackage(Package &package);
|
||||
void AddGroup(Group &group);
|
||||
void Clean();
|
||||
void AddPackages(BList &list);
|
||||
private:
|
||||
BList fViews;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user