[haiku-commits] haiku: hrev45276 - in src: apps/drivesetup kits/app

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 12 Feb 2013 22:27:19 +0100 (CET)

hrev45276 adds 2 changesets to branch 'master'
old head: ab6114fe81eb08864858dbab96e5d55cadbe8e8b
new head: 32da57f74b8855c63e422aa74628d904f99f8ba7
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=32da57f+%5Eab6114f

----------------------------------------------------------------------------

d2239cb: BMessage::SetString() was broken.
  
  * We cannot use the macro for this, unfortunately.

32da57f: DriveSetup: solved a few issues of CreateParametersPanel.
  
  * I obviously wasn't really done last time: now the panel behaves as it 
should.

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

5 files changed, 155 insertions(+), 62 deletions(-)
src/apps/drivesetup/AbstractParametersPanel.cpp | 121 ++++++++++++--------
src/apps/drivesetup/AbstractParametersPanel.h   |   4 +
src/apps/drivesetup/CreateParametersPanel.cpp   |  62 +++++++---
src/apps/drivesetup/CreateParametersPanel.h     |   3 +
src/kits/app/Message.cpp                        |  27 ++++-

############################################################################

Commit:      d2239cb8b9f1e594173e41d4afe2b6949bb53609
URL:         http://cgit.haiku-os.org/haiku/commit/?id=d2239cb
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Thu Dec 13 21:43:26 2012 UTC

BMessage::SetString() was broken.

* We cannot use the macro for this, unfortunately.

----------------------------------------------------------------------------

diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp
index 36db077..3c0dbe6 100644
--- a/src/kits/app/Message.cpp
+++ b/src/kits/app/Message.cpp
@@ -2564,7 +2564,6 @@ DEFINE_SET_GET_FUNCTIONS(uint64, UInt64, B_UINT64_TYPE);
 DEFINE_SET_GET_FUNCTIONS(bool, Bool, B_BOOL_TYPE);
 DEFINE_SET_GET_FUNCTIONS(float, Float, B_FLOAT_TYPE);
 DEFINE_SET_GET_FUNCTIONS(double, Double, B_DOUBLE_TYPE);
-DEFINE_SET_GET_FUNCTIONS(const char *, String, B_STRING_TYPE);
 
 #undef DEFINE_SET_GET_FUNCTION
 
@@ -3136,6 +3135,25 @@ BMessage::HasFlat(const char *name, int32 index, const 
BFlattenable *object)
 }
 
 
+const char*
+BMessage::GetString(const char *name, const char *defaultValue) const
+{
+       return GetString(name, 0, defaultValue);
+}
+
+
+const char*
+BMessage::GetString(const char *name, int32 index,
+       const char *defaultValue) const
+{
+       const char* value;
+       if (FindString(name, index, &value) == B_OK)
+               return value;
+
+       return defaultValue;
+}
+
+
 status_t
 BMessage::SetString(const char *name, const BString& value)
 {
@@ -3144,6 +3162,13 @@ BMessage::SetString(const char *name, const BString& 
value)
 
 
 status_t
+BMessage::SetString(const char *name, const char* value)
+{
+       return SetData(name, B_STRING_TYPE, value, strlen(value) + 1);
+}
+
+
+status_t
 BMessage::SetData(const char* name, type_code type, const void* data,
        ssize_t numBytes)
 {

############################################################################

Revision:    hrev45276
Commit:      32da57f74b8855c63e422aa74628d904f99f8ba7
URL:         http://cgit.haiku-os.org/haiku/commit/?id=32da57f
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Tue Feb 12 21:24:16 2013 UTC

DriveSetup: solved a few issues of CreateParametersPanel.

* I obviously wasn't really done last time: now the panel behaves as it should.

----------------------------------------------------------------------------

diff --git a/src/apps/drivesetup/AbstractParametersPanel.cpp 
b/src/apps/drivesetup/AbstractParametersPanel.cpp
index 1c38f64..b161494 100644
--- a/src/apps/drivesetup/AbstractParametersPanel.cpp
+++ b/src/apps/drivesetup/AbstractParametersPanel.cpp
@@ -136,54 +136,8 @@ AbstractParametersPanel::MessageReceived(BMessage* message)
 status_t
 AbstractParametersPanel::Go(BString& parameters)
 {
-       // Without an editor, we cannot change anything, anyway
-       if (fEditor == NULL) {
-               parameters = "";
-               if (fReturnStatus == B_CANCELED)
-                       fReturnStatus = B_OK;
-
-               if (!Lock())
-                       return B_ERROR;
-       } else {
-               // run the window thread, to get an initial layout of the 
controls
-               Hide();
-               Show();
-               if (!Lock())
-                       return B_CANCELED;
-
-               // center the panel above the parent window
-               CenterIn(fWindow->Frame());
-
-               Show();
-               Unlock();
-
-               // block this thread now, but keep the window repainting
-               while (true) {
-                       status_t status = acquire_sem_etc(fExitSemaphore, 1,
-                               B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT, 50000);
-                       if (status != B_TIMED_OUT && status != B_INTERRUPTED)
-                               break;
-                       fWindow->UpdateIfNeeded();
-               }
-
-               if (!Lock())
-                       return B_CANCELED;
-
-               if (fReturnStatus == B_OK) {
-                       if (fEditor->ValidateParameters()) {
-                               status_t err = 
fEditor->GetParameters(parameters);
-                               if (err != B_OK)
-                                       fReturnStatus = err;
-                       }
-               }
-       }
-
-       status_t status = fReturnStatus;
-
-       Quit();
-               // NOTE: this object is toast now!
-
-       return status;
+       BMessage storage;
+       return Go(parameters, storage);
 }
 
 
@@ -240,6 +194,77 @@ AbstractParametersPanel::Init(B_PARAMETER_EDITOR_TYPE type,
 }
 
 
+status_t
+AbstractParametersPanel::Go(BString& parameters, BMessage& storage)
+{
+       // Without an editor, we cannot change anything, anyway
+       if (fEditor == NULL && NeedsEditor()) {
+               parameters = "";
+               if (fReturnStatus == B_CANCELED)
+                       fReturnStatus = B_OK;
+
+               if (!Lock())
+                       return B_ERROR;
+       } else {
+               // run the window thread, to get an initial layout of the 
controls
+               Hide();
+               Show();
+               if (!Lock())
+                       return B_CANCELED;
+
+               // center the panel above the parent window
+               CenterIn(fWindow->Frame());
+
+               Show();
+               Unlock();
+
+               // block this thread now, but keep the window repainting
+               while (true) {
+                       status_t status = acquire_sem_etc(fExitSemaphore, 1,
+                               B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT, 50000);
+                       if (status != B_TIMED_OUT && status != B_INTERRUPTED)
+                               break;
+                       fWindow->UpdateIfNeeded();
+               }
+
+               if (!Lock())
+                       return B_CANCELED;
+
+               if (fReturnStatus == B_OK) {
+                       if (fEditor != NULL && fEditor->ValidateParameters()) {
+                               status_t status = 
fEditor->GetParameters(parameters);
+                               if (status != B_OK)
+                                       fReturnStatus = status;
+                       }
+                       if (fReturnStatus == B_OK)
+                               fReturnStatus = ParametersReceived(parameters, 
storage);
+               }
+       }
+
+       status_t status = fReturnStatus;
+
+       Quit();
+               // NOTE: this object is toast now!
+
+       return status;
+}
+
+
+bool
+AbstractParametersPanel::NeedsEditor() const
+{
+       return true;
+}
+
+
+status_t
+AbstractParametersPanel::ParametersReceived(const BString& parameters,
+       BMessage& storage)
+{
+       return B_OK;
+}
+
+
 void
 AbstractParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
        BView* editorView)
diff --git a/src/apps/drivesetup/AbstractParametersPanel.h 
b/src/apps/drivesetup/AbstractParametersPanel.h
index 123e957..9e24a33 100644
--- a/src/apps/drivesetup/AbstractParametersPanel.h
+++ b/src/apps/drivesetup/AbstractParametersPanel.h
@@ -37,7 +37,11 @@ protected:
                        void                            
Init(B_PARAMETER_EDITOR_TYPE type,
                                                                        const 
BString& diskSystem,
                                                                        
BPartition* partition);
+                       status_t                        Go(BString& parameters, 
BMessage& storage);
 
+       virtual bool                            NeedsEditor() const;
+       virtual status_t                        ParametersReceived(const 
BString& parameters,
+                                                                       
BMessage& storage);
        virtual void                            
AddControls(BLayoutBuilder::Group<>& builder,
                                                                        BView* 
editorView);
 
diff --git a/src/apps/drivesetup/CreateParametersPanel.cpp 
b/src/apps/drivesetup/CreateParametersPanel.cpp
index 44baa33..145809c 100644
--- a/src/apps/drivesetup/CreateParametersPanel.cpp
+++ b/src/apps/drivesetup/CreateParametersPanel.cpp
@@ -60,25 +60,25 @@ status_t
 CreateParametersPanel::Go(off_t& offset, off_t& size, BString& name,
        BString& type, BString& parameters)
 {
-       // The object will be deleted in Go(), so we need to get the values 
before
+       // The object will be deleted in Go(), so we need to get the values via
+       // a BMessage
+
+       BMessage storage;
+       status_t status = AbstractParametersPanel::Go(parameters, storage);
+       if (status != B_OK)
+               return status;
 
        // Return the value back as bytes.
-       size = fSizeSlider->Size();
-       offset = fSizeSlider->Offset();
+       size = storage.GetInt64("size", 0);
+       offset = storage.GetInt64("offset", 0);
 
        // get name
-       name.SetTo(fNameTextControl->Text());
+       name.SetTo(storage.GetString("name", NULL));
 
        // get type
-       if (BMenuItem* item = fTypeMenuField->Menu()->FindMarked()) {
-               const char* _type;
-               BMessage* message = item->Message();
-               if (!message || message->FindString("type", &_type) < B_OK)
-                       _type = kPartitionTypeBFS;
-               type << _type;
-       }
+       type.SetTo(storage.GetString("type", NULL));
 
-       return AbstractParametersPanel::Go(parameters);
+       return B_OK;
 }
 
 
@@ -114,6 +114,41 @@ CreateParametersPanel::MessageReceived(BMessage* message)
 }
 
 
+bool
+CreateParametersPanel::NeedsEditor() const
+{
+       return false;
+}
+
+
+status_t
+CreateParametersPanel::ParametersReceived(const BString& parameters,
+       BMessage& storage)
+{
+       // Return the value back as bytes.
+       status_t status = storage.SetInt64("size", fSizeSlider->Size());
+       if (status == B_OK)
+               status = storage.SetInt64("offset", fSizeSlider->Offset());
+
+       // get name
+       if (status == B_OK)
+               status = storage.SetString("name", fNameTextControl->Text());
+
+       // get type
+       if (BMenuItem* item = fTypeMenuField->Menu()->FindMarked()) {
+               const char* type;
+               BMessage* message = item->Message();
+               if (!message || message->FindString("type", &type) != B_OK)
+                       type = kPartitionTypeBFS;
+
+               if (status == B_OK)
+                       status = storage.SetString("type", type);
+       }
+
+       return status;
+}
+
+
 void
 CreateParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
        BView* editorView)
@@ -136,7 +171,8 @@ CreateParametersPanel::AddControls(BLayoutBuilder::Group<>& 
builder,
                }
        }
 
-       builder.Add(editorView);
+       if (editorView != NULL)
+               builder.Add(editorView);
 }
 
 
diff --git a/src/apps/drivesetup/CreateParametersPanel.h 
b/src/apps/drivesetup/CreateParametersPanel.h
index 1ecd800..3ae1ca7 100644
--- a/src/apps/drivesetup/CreateParametersPanel.h
+++ b/src/apps/drivesetup/CreateParametersPanel.h
@@ -33,6 +33,9 @@ public:
        virtual void                            MessageReceived(BMessage* 
message);
 
 protected:
+       virtual bool                            NeedsEditor() const;
+       virtual status_t                        ParametersReceived(const 
BString& parameters,
+                                                                       
BMessage& storage);
        virtual void                            
AddControls(BLayoutBuilder::Group<>& builder,
                                                                        BView* 
editorView);
 


Other related posts:

  • » [haiku-commits] haiku: hrev45276 - in src: apps/drivesetup kits/app - axeld