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:
parent
8b254785bb
commit
6467e4b16d
@ -42,7 +42,7 @@ AutoConfigWindow::AutoConfigWindow(BRect rect, ConfigWindow *parent)
|
||||
B_FOLLOW_ALL_SIDES, B_NAVIGABLE);
|
||||
fRootView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
AddChild(fRootView);
|
||||
|
||||
|
||||
int32 buttonHeight = 25;
|
||||
int32 buttonWidth = 50;
|
||||
BRect buttonRect = Bounds();
|
||||
@ -51,27 +51,26 @@ AutoConfigWindow::AutoConfigWindow(BRect rect, ConfigWindow *parent)
|
||||
buttonRect.left = buttonRect.right - 2 * buttonWidth - 5;
|
||||
buttonRect.right = buttonRect.left + buttonWidth;
|
||||
fBackButton = new BButton(buttonRect, "back", B_TRANSLATE("Back"),
|
||||
new BMessage(kBackMsg));
|
||||
new BMessage(kBackMsg));
|
||||
fBackButton->SetEnabled(false);
|
||||
fRootView->AddChild(fBackButton);
|
||||
|
||||
|
||||
buttonRect.left+= 5 + buttonWidth;
|
||||
buttonRect.right = buttonRect.left + buttonWidth;
|
||||
fNextButton = new BButton(buttonRect, "ok", B_TRANSLATE("OK"), new BMessage(kOkMsg));
|
||||
fNextButton->MakeDefault(true);
|
||||
fRootView->AddChild(fNextButton);
|
||||
|
||||
|
||||
fBoxRect = Bounds();
|
||||
fBoxRect.InsetBy(5,5);
|
||||
fBoxRect.bottom-= buttonHeight + 5;
|
||||
|
||||
|
||||
fMainView = new AutoConfigView(fBoxRect, fAutoConfig);
|
||||
fMainView->SetLabel(B_TRANSLATE("Account settings"));
|
||||
fRootView->AddChild(fMainView);
|
||||
|
||||
|
||||
// Add a shortcut to close the window using Command-W
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
// set the link regions
|
||||
@ -270,11 +271,14 @@ class AboutTextView : public BTextView
|
||||
BTextView::Draw(updateRect);
|
||||
|
||||
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();
|
||||
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();
|
||||
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)
|
||||
@ -308,7 +312,6 @@ ConfigWindow::ConfigWindow()
|
||||
fSaveSettings(false)
|
||||
{
|
||||
// create controls
|
||||
|
||||
BRect rect(Bounds());
|
||||
BView *top = new BView(rect, NULL, B_FOLLOW_ALL, 0);
|
||||
top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
@ -94,29 +94,11 @@ BRawNetBuffer::ReadUint32(uint32& value)
|
||||
status_t
|
||||
BRawNetBuffer::ReadString(BString& string)
|
||||
{
|
||||
if (fReadPosition >= fBuffer.BufferLength())
|
||||
string = "";
|
||||
size_t readed = _ReadStringAt(string, fReadPosition);
|
||||
if (readed < 0)
|
||||
return B_ERROR;
|
||||
|
||||
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++;
|
||||
fReadPosition += readed;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -140,13 +122,32 @@ BRawNetBuffer::_Init(const void* buf, size_t size)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BRawNetBuffer::_ReadSubString(BString& string, off_t pos)
|
||||
size_t
|
||||
BRawNetBuffer::_ReadStringAt(BString& string, off_t pos)
|
||||
{
|
||||
// sub strings have no links to other substrings so we can read it in one
|
||||
// piece
|
||||
if (pos >= fBuffer.BufferLength())
|
||||
return -1;
|
||||
|
||||
size_t readed = 0;
|
||||
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:
|
||||
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 fReadPosition;
|
||||
BMallocIO fBuffer;
|
||||
|
@ -1,46 +1,23 @@
|
||||
/* main - the application and startup code
|
||||
**
|
||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <Application.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
|
||||
main(int argc,char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
(new MailConfigApp())->Run();
|
||||
delete be_app;
|
||||
BApplication app("application/x-vnd.Haiku-Mail");
|
||||
|
||||
BWindow* window = new ConfigWindow;
|
||||
window->Show();
|
||||
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user