From 2e3a7b96c0bc598de278d27a6612e2c8f655ff61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 16 Jan 2008 18:35:58 +0000 Subject: [PATCH] * finished the initialization paremeter panel and used it in MainWindow::_Initialize()... setting the name and block size should work, though I have not tested this yet due to lack of available partitions. TODO: Use driver settings API from libroot to build the parameter string and move the GUI of the InitParamsPanel into the BFS add-on, implement BPartition::GetInitializationParameterEditor() accordingly. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23561 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/drivesetup/DiskView.cpp | 2 +- src/preferences/drivesetup/DiskView.h | 2 +- .../drivesetup/InitParamsPanel.cpp | 111 +++++++++++++++--- src/preferences/drivesetup/InitParamsPanel.h | 7 ++ src/preferences/drivesetup/Jamfile | 1 + src/preferences/drivesetup/MainWindow.cpp | 19 +-- src/preferences/drivesetup/MainWindow.h | 6 +- src/preferences/drivesetup/PartitionList.cpp | 3 +- src/preferences/drivesetup/PartitionList.h | 6 +- 9 files changed, 130 insertions(+), 27 deletions(-) diff --git a/src/preferences/drivesetup/DiskView.cpp b/src/preferences/drivesetup/DiskView.cpp index 3ac5126312..0cd8853a71 100644 --- a/src/preferences/drivesetup/DiskView.cpp +++ b/src/preferences/drivesetup/DiskView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2007 Haiku Inc. All rights reserved. + * Copyright 2007-2008 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: diff --git a/src/preferences/drivesetup/DiskView.h b/src/preferences/drivesetup/DiskView.h index 0d949b73d9..2ac4d36d7b 100644 --- a/src/preferences/drivesetup/DiskView.h +++ b/src/preferences/drivesetup/DiskView.h @@ -1,5 +1,5 @@ /* - * Copyright 2007 Haiku Inc. All rights reserved. + * Copyright 2007-2008 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. */ #ifndef DISK_VIEW_H diff --git a/src/preferences/drivesetup/InitParamsPanel.cpp b/src/preferences/drivesetup/InitParamsPanel.cpp index 3ce4630c86..7aa5064039 100644 --- a/src/preferences/drivesetup/InitParamsPanel.cpp +++ b/src/preferences/drivesetup/InitParamsPanel.cpp @@ -1,12 +1,26 @@ +/* + * Copyright 2008 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Stephan Aßmus + */ #include "InitParamsPanel.h" #include +#include +#include +#include +#include #include #include +#include +#include #include #include - +#include +#include class InitParamsPanel::EscapeFilter : public BMessageFilter { @@ -49,24 +63,81 @@ private: enum { MSG_OK = 'okok', - MSG_CANCEL = 'cncl' + MSG_CANCEL = 'cncl', + MSG_BLOCK_SIZE = 'blsz' }; -InitParamsPanel::InitParamsPanel(BWindow *window) - : Panel(BRect(300.0, 200.0, 600.0, 400.0), 0, B_MODAL_WINDOW_LOOK, - B_MODAL_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS), +InitParamsPanel::InitParamsPanel(BWindow* window) + : BWindow(BRect(300.0, 200.0, 600.0, 300.0), 0, B_MODAL_WINDOW_LOOK, + B_MODAL_SUBSET_WINDOW_FEEL, + B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) , fEscapeFilter(new EscapeFilter(this)) - , fExitSemaphore(create_sem(0, "InitParamsPanel exit") + , fExitSemaphore(create_sem(0, "InitParamsPanel exit")) , fWindow(window) , fReturnValue(GO_CANCELED) { AddCommonFilter(fEscapeFilter); - ... + fNameTC = new BTextControl("Name", NULL, NULL); - AddChild(topView); + BPopUpMenu* blocksizeMenu = new BPopUpMenu("Blocksize"); + BMessage* message = new BMessage(MSG_BLOCK_SIZE); + message->AddString("size", "1024"); + blocksizeMenu->AddItem(new BMenuItem("1024 (Mostly small files)", message)); + message = new BMessage(MSG_BLOCK_SIZE); + message->AddString("size", "2048"); + blocksizeMenu->AddItem(new BMenuItem("2048 (Recommended)", message)); + message = new BMessage(MSG_BLOCK_SIZE); + message->AddString("size", "4096"); + blocksizeMenu->AddItem(new BMenuItem("4096", message)); + message = new BMessage(MSG_BLOCK_SIZE); + message->AddString("size", "8192"); + blocksizeMenu->AddItem(new BMenuItem("8192 (Mostly large files)", message)); + + fBlockSizeMF = new BMenuField("Blocksize", blocksizeMenu, NULL); + + BButton* okButton = new BButton("Initialize", new BMessage(MSG_OK)); + BButton* cancelButton = new BButton("Cancel", new BMessage(MSG_CANCEL)); + + BView* rootView = BGroupLayoutBuilder(B_VERTICAL, 5) + + .Add(BSpaceLayoutItem::CreateVerticalStrut(10)) + + // test views + .Add(BGridLayoutBuilder(10, 10) + // row 1 + .Add(BSpaceLayoutItem::CreateHorizontalStrut(5), 0, 0) + + .Add(fNameTC->CreateLabelLayoutItem(), 1, 0) + .Add(fNameTC->CreateTextViewLayoutItem(), 2, 0) + + .Add(BSpaceLayoutItem::CreateHorizontalStrut(10), 3, 0) + + // row 2 + .Add(BSpaceLayoutItem::CreateHorizontalStrut(10), 0, 1) + + .Add(fBlockSizeMF->CreateLabelLayoutItem(), 1, 1) + .Add(fBlockSizeMF->CreateMenuBarLayoutItem(), 2, 1) + + .Add(BSpaceLayoutItem::CreateHorizontalStrut(5), 3, 1) + ) + + // controls + .AddGroup(B_HORIZONTAL, 10) + .Add(BSpaceLayoutItem::CreateHorizontalStrut(5)) + .AddGlue() + .Add(cancelButton) + .Add(okButton) + .Add(BSpaceLayoutItem::CreateHorizontalStrut(5)) + .End() + + .Add(BSpaceLayoutItem::CreateVerticalStrut(5)) + ; + + SetLayout(new BGroupLayout(B_HORIZONTAL)); + AddChild(rootView); SetDefaultButton(okButton); AddToSubset(fWindow); @@ -93,7 +164,7 @@ InitParamsPanel::QuitRequested() void InitParamsPanel::MessageReceived(BMessage* message) { - switch (msg->what) { + switch (message->what) { case MSG_CANCEL: Cancel(); break; @@ -102,7 +173,7 @@ InitParamsPanel::MessageReceived(BMessage* message) fReturnValue = GO_SUCCESS; release_sem(fExitSemaphore); break; - } + default: BWindow::MessageReceived(message); } @@ -110,13 +181,13 @@ InitParamsPanel::MessageReceived(BMessage* message) int32 -InitParamsPanel::Answer(BString& name, BString& parameters) +InitParamsPanel::Go(BString& name, BString& parameters) { // run the window thread, to get an initial layout of the controls Hide(); Show(); if (!Lock()) - return false; + return GO_CANCELED; // center the panel above the parent window BRect frame = Frame(); @@ -133,12 +204,22 @@ InitParamsPanel::Answer(BString& name, BString& parameters) // block this thread now acquire_sem(fExitSemaphore); - if (fMode == GO_SUCCESS) { + if (!Lock()) + return GO_CANCELED; + + if (fReturnValue == GO_SUCCESS) { name = fNameTC->Text(); - parameters ... + parameters = ""; + if (BMenuItem* item = fBlockSizeMF->Menu()->FindMarked()) { + const char* size; + BMessage* message = item->Message(); + if (!message || message->FindString("size", &size) < B_OK) + size = "2048"; + // TODO: use libroot driver settings API + parameters << "block_size " << size << ";\n"; + } } - Lock(); Quit(); return fReturnValue; } diff --git a/src/preferences/drivesetup/InitParamsPanel.h b/src/preferences/drivesetup/InitParamsPanel.h index e039a09516..64e0954611 100644 --- a/src/preferences/drivesetup/InitParamsPanel.h +++ b/src/preferences/drivesetup/InitParamsPanel.h @@ -1,3 +1,10 @@ +/* + * Copyright 2008 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Stephan Aßmus + */ #ifndef INIT_PARAMS_PANEL_H #define INIT_PARAMS_PANEL_H diff --git a/src/preferences/drivesetup/Jamfile b/src/preferences/drivesetup/Jamfile index a562b83b47..b7cdd6b37e 100644 --- a/src/preferences/drivesetup/Jamfile +++ b/src/preferences/drivesetup/Jamfile @@ -7,6 +7,7 @@ UsePrivateHeaders interface shared storage ; Preference DriveSetup : DiskView.cpp DriveSetup.cpp + InitParamsPanel.cpp MainWindow.cpp PartitionList.cpp Support.cpp diff --git a/src/preferences/drivesetup/MainWindow.cpp b/src/preferences/drivesetup/MainWindow.cpp index 3d60f6a81e..de1787108a 100644 --- a/src/preferences/drivesetup/MainWindow.cpp +++ b/src/preferences/drivesetup/MainWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 Haiku Inc. All rights reserved. + * Copyright 2002-2008 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: @@ -9,6 +9,7 @@ */ #include "MainWindow.h" #include "DiskView.h" +#include "InitParamsPanel.h" #include "PartitionList.h" #include "Support.h" @@ -578,10 +579,13 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition, } -// TODO: check and allow BFS only, since our parameter string -// construction only handles BFS at the moment -// if (BString("") != diskSystem) { -// } + // allow BFS only, since our parameter string + // construction only handles BFS at the moment + if (diskSystemName != "Be File System") { + _DisplayPartitionError("Don't know how to construct parameters " + "for this file system."); + return; + } status_t ret = disk->PrepareModifications(); if (ret != B_OK) { @@ -593,9 +597,10 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition, // TODO: use partition initialization editor // (partition->GetInitializationParameterEditor()) - BString name = "BFS Init Test"; + BString name = "Haiku"; BString parameters; - parameters << "block_size " << 2048 << "\n"; + InitParamsPanel* panel = new InitParamsPanel(this); + panel->Go(name, parameters); bool supportsName = diskSystem.SupportsContentName(); BString validatedName(name); diff --git a/src/preferences/drivesetup/MainWindow.h b/src/preferences/drivesetup/MainWindow.h index 2e34f4f956..da4ebc32d5 100644 --- a/src/preferences/drivesetup/MainWindow.h +++ b/src/preferences/drivesetup/MainWindow.h @@ -1,6 +1,10 @@ /* - * Copyright 2002-2007 Haiku Inc. All rights reserved. + * Copyright 2002-2008 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. + * + * Authors: + * Ithamar R. Adema + * Stephan Aßmus */ #ifndef MAIN_WINDOW_H #define MAIN_WINDOW_H diff --git a/src/preferences/drivesetup/PartitionList.cpp b/src/preferences/drivesetup/PartitionList.cpp index d6506c7d5c..bb98f89c72 100644 --- a/src/preferences/drivesetup/PartitionList.cpp +++ b/src/preferences/drivesetup/PartitionList.cpp @@ -1,9 +1,10 @@ /* - * Copyright 2006-2007 Haiku Inc. All rights reserved. + * Copyright 2006-2008 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: * Ithamar R. Adema + * Stephan Aßmus */ #include "PartitionList.h" #include "Support.h" diff --git a/src/preferences/drivesetup/PartitionList.h b/src/preferences/drivesetup/PartitionList.h index 44481b7281..c0b57afe2d 100644 --- a/src/preferences/drivesetup/PartitionList.h +++ b/src/preferences/drivesetup/PartitionList.h @@ -1,6 +1,10 @@ /* - * Copyright 2006-2007 Haiku Inc. All rights reserved. + * Copyright 2006-2008 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. + * + * Authors: + * Ithamar R. Adema + * Stephan Aßmus */ #ifndef PARTITIONLIST_H #define PARTITIONLIST_H