added some views for packages

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14230 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2005-09-23 16:01:21 +00:00
parent f1358045f7
commit 5b9ea6c314
7 changed files with 314 additions and 12 deletions

View File

@ -6,17 +6,22 @@
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Application.h>
#include <Box.h> #include <Box.h>
#include <Directory.h>
#include <Path.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <Roster.h> #include <Roster.h>
#include <ScrollView.h>
#include <string.h> #include <string.h>
#include "InstallerWindow.h" #include "InstallerWindow.h"
#include "PartitionMenuItem.h"
#define DRIVESETUP_SIG "application/x-vnd.Be-DRV$" #define DRIVESETUP_SIG "application/x-vnd.Be-DRV$"
const uint32 BEGIN_MESSAGE = 'iBGN'; const uint32 BEGIN_MESSAGE = 'iBGN';
const uint32 SHOW_BOTTOM_MESSAGE = 'iSBT'; const uint32 SHOW_BOTTOM_MESSAGE = 'iSBT';
const uint32 SETUP_MESSAGE = 'iSEP'; const uint32 SETUP_MESSAGE = 'iSEP';
const uint32 START_SCAN = 'iSSC';
const uint32 SRC_PARTITION = 'iSPT';
const uint32 DST_PARTITION = 'iDPT';
InstallerWindow::InstallerWindow(BRect frame_rect) InstallerWindow::InstallerWindow(BRect frame_rect)
: BWindow(frame_rect, "Installer", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE), : BWindow(frame_rect, "Installer", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
@ -51,6 +56,12 @@ InstallerWindow::InstallerWindow(BRect frame_rect)
fBackBox->AddChild(fSetupButton); fBackBox->AddChild(fSetupButton);
fSetupButton->Hide(); fSetupButton->Hide();
fPackagesView = new PackagesView(BRect(bounds.left+12, bounds.top+4, bounds.right-15-B_V_SCROLL_BAR_WIDTH, bounds.bottom-61), "packages_view");
fPackagesScrollView = new BScrollView("packagesScroll", fPackagesView, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW,
false, true);
fBackBox->AddChild(fPackagesScrollView);
fPackagesScrollView->Hide();
fDrawButton = new DrawButton(BRect(bounds.left+12, bounds.bottom-33, bounds.left+100, bounds.bottom-20), fDrawButton = new DrawButton(BRect(bounds.left+12, bounds.bottom-33, bounds.left+100, bounds.bottom-20),
"options_button", "Fewer options", "More options", new BMessage(SHOW_BOTTOM_MESSAGE)); "options_button", "Fewer options", "More options", new BMessage(SHOW_BOTTOM_MESSAGE));
fBackBox->AddChild(fDrawButton); fBackBox->AddChild(fDrawButton);
@ -58,7 +69,7 @@ InstallerWindow::InstallerWindow(BRect frame_rect)
fDestMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS); fDestMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS);
fSrcMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS); fSrcMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS);
BRect fieldRect(bounds.left+50, bounds.top+70, bounds.left+250, bounds.top+90); BRect fieldRect(bounds.left+50, bounds.top+70, bounds.right-13, bounds.top+90);
fSrcMenuField = new BMenuField(fieldRect, "srcMenuField", fSrcMenuField = new BMenuField(fieldRect, "srcMenuField",
"Install from: ", fSrcMenu); "Install from: ", fSrcMenu);
fSrcMenuField->SetDivider(70.0); fSrcMenuField->SetDivider(70.0);
@ -77,6 +88,8 @@ InstallerWindow::InstallerWindow(BRect frame_rect)
fDriveSetupLaunched = be_roster->IsRunning(DRIVESETUP_SIG); fDriveSetupLaunched = be_roster->IsRunning(DRIVESETUP_SIG);
be_roster->StartWatching(this); be_roster->StartWatching(this);
PostMessage(START_SCAN);
} }
InstallerWindow::~InstallerWindow() InstallerWindow::~InstallerWindow()
@ -89,11 +102,17 @@ void
InstallerWindow::MessageReceived(BMessage *msg) InstallerWindow::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
case START_SCAN:
StartScan();
break;
case BEGIN_MESSAGE: case BEGIN_MESSAGE:
break; break;
case SHOW_BOTTOM_MESSAGE: case SHOW_BOTTOM_MESSAGE:
ShowBottom(); ShowBottom();
break; break;
case SRC_PARTITION:
PublishPackages();
break;
case SETUP_MESSAGE: case SETUP_MESSAGE:
LaunchDriveSetup(); LaunchDriveSetup();
break; break;
@ -133,10 +152,14 @@ InstallerWindow::ShowBottom()
ResizeTo(332,306); ResizeTo(332,306);
if (fSetupButton->IsHidden()) if (fSetupButton->IsHidden())
fSetupButton->Show(); fSetupButton->Show();
if (fPackagesScrollView->IsHidden())
fPackagesScrollView->Show();
} else { } else {
ResizeTo(332,160);
if (!fSetupButton->IsHidden()) if (!fSetupButton->IsHidden())
fSetupButton->Hide(); fSetupButton->Hide();
if (!fPackagesScrollView->IsHidden())
fPackagesScrollView->Hide();
ResizeTo(332,160);
} }
} }
@ -153,7 +176,7 @@ void
InstallerWindow::DisableInterface(bool disable) InstallerWindow::DisableInterface(bool disable)
{ {
if (!disable) { if (!disable) {
ScanningInProgress(); StartScan();
} }
fDriveSetupLaunched = disable; fDriveSetupLaunched = disable;
fBeginButton->SetEnabled(!disable); fBeginButton->SetEnabled(!disable);
@ -162,20 +185,44 @@ InstallerWindow::DisableInterface(bool disable)
fDestMenuField->SetEnabled(!disable); fDestMenuField->SetEnabled(!disable);
if (disable) if (disable)
fStatusView->SetText("Running DriveSetup" B_UTF8_ELLIPSIS "\nClose DriveSetup to continue with the\ninstallation."); fStatusView->SetText("Running DriveSetup" B_UTF8_ELLIPSIS "\nClose DriveSetup to continue with the\ninstallation.");
} }
void void
InstallerWindow::ScanningComplete() InstallerWindow::StartScan()
{ {
fStatusView->SetText("Scanning for disks" B_UTF8_ELLIPSIS);
BMenuItem *item;
while ((item = fSrcMenu->RemoveItem((int32)0)))
delete item;
while ((item = fDestMenu->RemoveItem((int32)0)))
delete item;
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))
fSrcMenu->ItemAt(0)->SetMarked(true);
fStatusView->SetText("Choose the disk you want to install onto\nfrom the pop-up menu. Then click \"Begin\"."); fStatusView->SetText("Choose the disk you want to install onto\nfrom the pop-up menu. Then click \"Begin\".");
} }
void void
InstallerWindow::ScanningInProgress() InstallerWindow::PublishPackages()
{ {
fStatusView->SetText("Scanning for disks" B_UTF8_ELLIPSIS); fPackagesView->Clean();
} PartitionMenuItem *item = (PartitionMenuItem *)fSrcMenu->FindMarked();
if (!item)
return;
BPath directory(item->Path());
directory.Append("_packages_");
BDirectory dir(directory.Path());
if (dir.InitCheck()!=B_OK)
return;
BEntry packageEntry;
while (dir.GetNextEntry(&packageEntry)==B_OK) {
}
}

View File

@ -10,9 +10,11 @@
#include <Button.h> #include <Button.h>
#include <Menu.h> #include <Menu.h>
#include <MenuField.h> #include <MenuField.h>
#include <ScrollView.h>
#include <TextView.h> #include <TextView.h>
#include <Window.h> #include <Window.h>
#include "DrawButton.h" #include "DrawButton.h"
#include "PackageViews.h"
class InstallerWindow : public BWindow { class InstallerWindow : public BWindow {
public: public:
@ -25,9 +27,9 @@ public:
private: private:
void DisableInterface(bool disable); void DisableInterface(bool disable);
void LaunchDriveSetup(); void LaunchDriveSetup();
void PublishPackages();
void ShowBottom(); void ShowBottom();
void ScanningComplete(); void StartScan();
void ScanningInProgress();
BBox *fBackBox; BBox *fBackBox;
BButton *fBeginButton, *fSetupButton; BButton *fBeginButton, *fSetupButton;
DrawButton *fDrawButton; DrawButton *fDrawButton;
@ -35,6 +37,8 @@ private:
BTextView *fStatusView; BTextView *fStatusView;
BMenu* fSrcMenu, *fDestMenu; BMenu* fSrcMenu, *fDestMenu;
BMenuField* fSrcMenuField, *fDestMenuField; BMenuField* fSrcMenuField, *fDestMenuField;
PackagesView *fPackagesView;
BScrollView *fPackagesScrollView;
}; };
#endif /* _InstallerWindow_h */ #endif /* _InstallerWindow_h */

View File

@ -7,6 +7,8 @@ App Installer :
DrawButton.cpp DrawButton.cpp
InstallerApp.cpp InstallerApp.cpp
InstallerWindow.cpp InstallerWindow.cpp
: libbe.so libtracker.so PackageViews.cpp
PartitionMenuItem.cpp
: be tracker
: Installer.rdef ; : Installer.rdef ;

View File

@ -0,0 +1,124 @@
/*
* Copyright 2005, Jérôme DUVAL. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <Directory.h>
#include <View.h>
#include "PackageViews.h"
Package::Package()
: fName(NULL),
fGroup(NULL),
fDescription(NULL),
fSize(0),
fIcon(NULL)
{
}
Package::~Package()
{
free(fName);
free(fGroup);
free(fDescription);
free(fIcon);
}
Package *
Package::PackageFromEntry(BEntry &entry)
{
BDirectory directory(&entry);
if (directory.InitCheck()!=B_OK)
return NULL;
Package *package = new Package();
return package;
}
Group::Group()
{
}
Group::~Group()
{
}
PackageCheckBox::PackageCheckBox(BRect rect, Package &item)
: BCheckBox(rect, "pack_cb", item.Name(), NULL),
fPackage(item)
{
}
PackageCheckBox::~PackageCheckBox()
{
}
void
PackageCheckBox::Draw(BRect update)
{
BCheckBox::Draw(update);
}
GroupView::GroupView(BRect rect, Group &group)
: BStringView(rect, "group", group.Name()),
fGroup(group)
{
}
GroupView::~GroupView()
{
}
PackagesView::PackagesView(BRect rect, const char* name)
: BView(rect, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_FRAME_EVENTS)
{
}
PackagesView::~PackagesView()
{
}
void
PackagesView::AddPackage(Package &package)
{
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()
{
}

View File

@ -0,0 +1,80 @@
/*
* Copyright 2005, Jérôme DUVAL. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef __PACKAGEVIEWS_H__
#define __PACKAGEVIEWS_H__
#include <CheckBox.h>
#include <List.h>
#include <StringView.h>
#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();
void SetName(const char *name) { free(fName); fName=strdup(name);};
const char * Name() { return fName; };
private:
char *fName;
};
class PackageCheckBox : public BCheckBox {
public:
PackageCheckBox(BRect rect, Package &item);
~PackageCheckBox();
void Draw(BRect update);
private:
Package &fPackage;
};
class GroupView : public BStringView {
public:
GroupView(BRect rect, Group &group);
~GroupView();
private:
Group &fGroup;
};
class PackagesView : public BView {
public:
PackagesView(BRect rect, const char* name);
~PackagesView();
void AddPackage(Package &package);
void AddGroup(Group &group);
void Clean();
private:
BList fViews;
};
#endif /* __PACKAGEVIEWS_H__ */

View File

@ -0,0 +1,23 @@
/*
* Copyright 2005, Jérôme DUVAL. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <View.h>
#include <stdlib.h>
#include <string.h>
#include "PartitionMenuItem.h"
PartitionMenuItem::PartitionMenuItem(const char *label, BMessage *msg, const char* path)
: BMenuItem(label, msg)
{
fPath = strdup(path);
}
PartitionMenuItem::~PartitionMenuItem()
{
free(fPath);
}

View File

@ -0,0 +1,22 @@
/*
* Copyright 2005, Jérôme DUVAL. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef __PARTITIONMENUITEM_H_
#define __PARTITIONMENUITEM_H_
#include <MenuItem.h>
class PartitionMenuItem : public BMenuItem {
public:
PartitionMenuItem(const char *label, BMessage *msg, const char* path);
~PartitionMenuItem();
const char* Path() { return fPath; };
private:
char *fPath;
};
#endif /* __PARTITIONMENUITEM_H_ */