Fix reading of compressed strings. This fixes #7266. Some clean up.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40895 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -42,7 +42,7 @@ AutoConfigWindow::AutoConfigWindow(BRect rect, ConfigWindow *parent)
|
|||||||
B_FOLLOW_ALL_SIDES, B_NAVIGABLE);
|
B_FOLLOW_ALL_SIDES, B_NAVIGABLE);
|
||||||
fRootView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
fRootView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
AddChild(fRootView);
|
AddChild(fRootView);
|
||||||
|
|
||||||
int32 buttonHeight = 25;
|
int32 buttonHeight = 25;
|
||||||
int32 buttonWidth = 50;
|
int32 buttonWidth = 50;
|
||||||
BRect buttonRect = Bounds();
|
BRect buttonRect = Bounds();
|
||||||
@@ -51,27 +51,26 @@ AutoConfigWindow::AutoConfigWindow(BRect rect, ConfigWindow *parent)
|
|||||||
buttonRect.left = buttonRect.right - 2 * buttonWidth - 5;
|
buttonRect.left = buttonRect.right - 2 * buttonWidth - 5;
|
||||||
buttonRect.right = buttonRect.left + buttonWidth;
|
buttonRect.right = buttonRect.left + buttonWidth;
|
||||||
fBackButton = new BButton(buttonRect, "back", B_TRANSLATE("Back"),
|
fBackButton = new BButton(buttonRect, "back", B_TRANSLATE("Back"),
|
||||||
new BMessage(kBackMsg));
|
new BMessage(kBackMsg));
|
||||||
fBackButton->SetEnabled(false);
|
fBackButton->SetEnabled(false);
|
||||||
fRootView->AddChild(fBackButton);
|
fRootView->AddChild(fBackButton);
|
||||||
|
|
||||||
buttonRect.left+= 5 + buttonWidth;
|
buttonRect.left+= 5 + buttonWidth;
|
||||||
buttonRect.right = buttonRect.left + buttonWidth;
|
buttonRect.right = buttonRect.left + buttonWidth;
|
||||||
fNextButton = new BButton(buttonRect, "ok", B_TRANSLATE("OK"), new BMessage(kOkMsg));
|
fNextButton = new BButton(buttonRect, "ok", B_TRANSLATE("OK"), new BMessage(kOkMsg));
|
||||||
fNextButton->MakeDefault(true);
|
fNextButton->MakeDefault(true);
|
||||||
fRootView->AddChild(fNextButton);
|
fRootView->AddChild(fNextButton);
|
||||||
|
|
||||||
fBoxRect = Bounds();
|
fBoxRect = Bounds();
|
||||||
fBoxRect.InsetBy(5,5);
|
fBoxRect.InsetBy(5,5);
|
||||||
fBoxRect.bottom-= buttonHeight + 5;
|
fBoxRect.bottom-= buttonHeight + 5;
|
||||||
|
|
||||||
fMainView = new AutoConfigView(fBoxRect, fAutoConfig);
|
fMainView = new AutoConfigView(fBoxRect, fAutoConfig);
|
||||||
fMainView->SetLabel(B_TRANSLATE("Account settings"));
|
fMainView->SetLabel(B_TRANSLATE("Account settings"));
|
||||||
fRootView->AddChild(fMainView);
|
fRootView->AddChild(fMainView);
|
||||||
|
|
||||||
// Add a shortcut to close the window using Command-W
|
// Add a shortcut to close the window using Command-W
|
||||||
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
|
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -245,7 +245,8 @@ class AboutTextView : public BTextView
|
|||||||
SetFontAndColor(0,23,&font,B_FONT_SIZE);
|
SetFontAndColor(0,23,&font,B_FONT_SIZE);
|
||||||
|
|
||||||
// center the view vertically
|
// center the view vertically
|
||||||
rect = TextRect(); rect.OffsetTo(0,(Bounds().Height() - TextHeight(0,42)) / 2);
|
rect = TextRect();
|
||||||
|
rect.OffsetTo(0,(Bounds().Height() - TextHeight(0,42)) / 2);
|
||||||
SetTextRect(rect);
|
SetTextRect(rect);
|
||||||
|
|
||||||
// set the link regions
|
// set the link regions
|
||||||
@@ -270,11 +271,14 @@ class AboutTextView : public BTextView
|
|||||||
BTextView::Draw(updateRect);
|
BTextView::Draw(updateRect);
|
||||||
|
|
||||||
BRect rect(fMail.Frame());
|
BRect rect(fMail.Frame());
|
||||||
StrokeLine(BPoint(rect.left,rect.bottom-2),BPoint(rect.right,rect.bottom-2));
|
StrokeLine(BPoint(rect.left,rect.bottom-2),
|
||||||
|
BPoint(rect.right,rect.bottom-2));
|
||||||
rect = fBugsite.Frame();
|
rect = fBugsite.Frame();
|
||||||
StrokeLine(BPoint(rect.left,rect.bottom-2),BPoint(rect.right,rect.bottom-2));
|
StrokeLine(BPoint(rect.left,rect.bottom-2),
|
||||||
|
BPoint(rect.right,rect.bottom-2));
|
||||||
rect = fWebsite.Frame();
|
rect = fWebsite.Frame();
|
||||||
StrokeLine(BPoint(rect.left,rect.bottom-2),BPoint(rect.right,rect.bottom-2));
|
StrokeLine(BPoint(rect.left,rect.bottom-2),
|
||||||
|
BPoint(rect.right,rect.bottom-2));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void MouseDown(BPoint point)
|
virtual void MouseDown(BPoint point)
|
||||||
@@ -308,7 +312,6 @@ ConfigWindow::ConfigWindow()
|
|||||||
fSaveSettings(false)
|
fSaveSettings(false)
|
||||||
{
|
{
|
||||||
// create controls
|
// create controls
|
||||||
|
|
||||||
BRect rect(Bounds());
|
BRect rect(Bounds());
|
||||||
BView *top = new BView(rect, NULL, B_FOLLOW_ALL, 0);
|
BView *top = new BView(rect, NULL, B_FOLLOW_ALL, 0);
|
||||||
top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|||||||
@@ -94,29 +94,11 @@ BRawNetBuffer::ReadUint32(uint32& value)
|
|||||||
status_t
|
status_t
|
||||||
BRawNetBuffer::ReadString(BString& string)
|
BRawNetBuffer::ReadString(BString& string)
|
||||||
{
|
{
|
||||||
if (fReadPosition >= fBuffer.BufferLength())
|
string = "";
|
||||||
|
size_t readed = _ReadStringAt(string, fReadPosition);
|
||||||
|
if (readed < 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
fReadPosition += readed;
|
||||||
char* buffer = (char*)fBuffer.Buffer();
|
|
||||||
buffer = &buffer[fReadPosition];
|
|
||||||
|
|
||||||
// if the string is compressed we have to follow the links to the
|
|
||||||
// sub strings
|
|
||||||
while (fReadPosition < fBuffer.BufferLength() && *buffer != 0) {
|
|
||||||
if (uint8(*buffer) == 192) {
|
|
||||||
// found a pointer mark
|
|
||||||
buffer++;
|
|
||||||
// pointer takes 2 byte
|
|
||||||
fReadPosition = fReadPosition + 1;
|
|
||||||
off_t pos = uint8(*buffer);
|
|
||||||
_ReadSubString(string, pos);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
string.Append(buffer, 1);
|
|
||||||
buffer++;
|
|
||||||
fReadPosition++;
|
|
||||||
}
|
|
||||||
fReadPosition++;
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,13 +122,32 @@ BRawNetBuffer::_Init(const void* buf, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
size_t
|
||||||
BRawNetBuffer::_ReadSubString(BString& string, off_t pos)
|
BRawNetBuffer::_ReadStringAt(BString& string, off_t pos)
|
||||||
{
|
{
|
||||||
// sub strings have no links to other substrings so we can read it in one
|
if (pos >= fBuffer.BufferLength())
|
||||||
// piece
|
return -1;
|
||||||
|
|
||||||
|
size_t readed = 0;
|
||||||
char* buffer = (char*)fBuffer.Buffer();
|
char* buffer = (char*)fBuffer.Buffer();
|
||||||
string.Append(&buffer[pos]);
|
buffer = &buffer[pos];
|
||||||
|
// if the string is compressed we have to follow the links to the
|
||||||
|
// sub strings
|
||||||
|
while (pos < fBuffer.BufferLength() && *buffer != 0) {
|
||||||
|
if (uint8(*buffer) == 192) {
|
||||||
|
// found a pointer mark
|
||||||
|
buffer++;
|
||||||
|
readed++;
|
||||||
|
off_t subPos = uint8(*buffer);
|
||||||
|
_ReadStringAt(string, subPos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
string.Append(buffer, 1);
|
||||||
|
buffer++;
|
||||||
|
readed++;
|
||||||
|
}
|
||||||
|
readed++;
|
||||||
|
return readed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void _Init(const void* buf, size_t size);
|
void _Init(const void* buf, size_t size);
|
||||||
void _ReadSubString(BString& string, off_t pos);
|
size_t _ReadStringAt(BString& string, off_t pos);
|
||||||
|
|
||||||
off_t fWritePosition;
|
off_t fWritePosition;
|
||||||
off_t fReadPosition;
|
off_t fReadPosition;
|
||||||
BMallocIO fBuffer;
|
BMallocIO fBuffer;
|
||||||
|
|||||||
@@ -1,46 +1,23 @@
|
|||||||
/* main - the application and startup code
|
/*
|
||||||
**
|
* Copyright 2011, Haiku, Inc. All rights reserved.
|
||||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
* Copyright 2011, Clemens Zeidler <[email protected]>
|
||||||
*/
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
|
||||||
#include "ConfigWindow.h"
|
#include "ConfigWindow.h"
|
||||||
|
|
||||||
#include <Application.h>
|
|
||||||
#include <Catalog.h>
|
|
||||||
#include <Locale.h>
|
|
||||||
|
|
||||||
|
|
||||||
class BCatalog;
|
|
||||||
|
|
||||||
class MailConfigApp : public BApplication {
|
|
||||||
public:
|
|
||||||
MailConfigApp();
|
|
||||||
~MailConfigApp();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
MailConfigApp::MailConfigApp()
|
|
||||||
: BApplication("application/x-vnd.Haiku-Mail")
|
|
||||||
{
|
|
||||||
(new ConfigWindow())->Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MailConfigApp::~MailConfigApp()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc,char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
(new MailConfigApp())->Run();
|
BApplication app("application/x-vnd.Haiku-Mail");
|
||||||
delete be_app;
|
|
||||||
|
|
||||||
|
BWindow* window = new ConfigWindow;
|
||||||
|
window->Show();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user