Merge branch 'master' into sam460ex

This commit is contained in:
François Revol
2013-02-12 19:48:05 +01:00
19 changed files with 643 additions and 408 deletions
+18 -18
View File
@@ -135,7 +135,7 @@
\returns A status code. \returns A status code.
\retval B_OK Initialization was successful. \retval B_OK Initialization was successful.
\retval B_BAD_VALUE \c NULL \a ref. \retval B_BAD_VALUE \a ref was \c NULL.
\retval B_NAME_TOO_LONG The pathname was longer than \c B_PATH_NAME_LENGTH. \retval B_NAME_TOO_LONG The pathname was longer than \c B_PATH_NAME_LENGTH.
*/ */
@@ -148,7 +148,7 @@
\returns A status code. \returns A status code.
\retval B_OK Initialization was successful. \retval B_OK Initialization was successful.
\retval B_BAD_VALUE \c NULL \a ref. \retval B_BAD_VALUE \a ref was \c NULL.
\retval B_NAME_TOO_LONG The pathname was longer than \c B_PATH_NAME_LENGTH. \retval B_NAME_TOO_LONG The pathname was longer than \c B_PATH_NAME_LENGTH.
*/ */
@@ -173,7 +173,7 @@
\returns A status code. \returns A status code.
\retval B_OK Initialization was successful. \retval B_OK Initialization was successful.
\retval B_BAD_VALUE \c NULL \a ref. \retval B_BAD_VALUE \a ref was \c NULL.
\retval B_NAME_TOO_LONG The pathname was longer than \c B_PATH_NAME_LENGTH. \retval B_NAME_TOO_LONG The pathname was longer than \c B_PATH_NAME_LENGTH.
*/ */
@@ -196,7 +196,7 @@
\returns A status code. \returns A status code.
\retval B_OK Initialization was successful. \retval B_OK Initialization was successful.
\retval B_BAD_VALUE \c NULL \a ref. \retval B_BAD_VALUE \a ref was \c NULL.
\retval B_NAME_TOO_LONG The pathname was longer than \c B_PATH_NAME_LENGTH. \retval B_NAME_TOO_LONG The pathname was longer than \c B_PATH_NAME_LENGTH.
*/ */
@@ -204,7 +204,7 @@
/*! /*!
\fn void BPath::Unset() \fn void BPath::Unset()
\brief Returns the object to an uninitialized state. \brief Returns the object to an uninitialized state.
Frees any resources it allocated and marks the object as uninitialized. Frees any resources it allocated and marks the object as uninitialized.
*/ */
@@ -238,7 +238,7 @@
\returns A status code. \returns A status code.
\retval B_OK Initialization was successful. \retval B_OK Initialization was successful.
\retval B_BAD_VALUE \c NULL \a ref. \retval B_BAD_VALUE \a ref was \c NULL.
\retval B_NAME_TOO_LONG The pathname was longer than \c B_PATH_NAME_LENGTH. \retval B_NAME_TOO_LONG The pathname was longer than \c B_PATH_NAME_LENGTH.
*/ */
@@ -285,7 +285,7 @@
\returns A status code. \returns A status code.
\retval B_OK Everything went fine. \retval B_OK Everything went fine.
\retval B_BAD_VALUE \c NULL \a path. \retval B_BAD_VALUE \a path was \c NULL.
\retval B_ENTRY_NOT_FOUND The BPath object represents the root path and \retval B_ENTRY_NOT_FOUND The BPath object represents the root path and
thus has no parent. thus has no parent.
*/ */
@@ -389,7 +389,7 @@
/*! /*!
\name BFlattenable override methods \name BFlattenable method implementations
*/ */
@@ -398,7 +398,7 @@
/*! /*!
\fn bool BPath::IsFixedSize() const \fn bool BPath::IsFixedSize() const
\brief Overrides BFlattenable::IsFixedSize(). Always returns \c false. \brief Implements BFlattenable::IsFixedSize(). Always returns \c false.
\return \c false \return \c false
*/ */
@@ -406,7 +406,7 @@
/*! /*!
\fn type_code BPath::TypeCode() const \fn type_code BPath::TypeCode() const
\brief Overrides BFlattenable::TypeCode() Always returns \c B_REF_TYPE. \brief Implements BFlattenable::TypeCode(). Always returns \c B_REF_TYPE.
\return \c B_REF_TYPE \return \c B_REF_TYPE
*/ */
@@ -414,7 +414,7 @@
/*! /*!
\fn ssize_t BPath::FlattenedSize() const \fn ssize_t BPath::FlattenedSize() const
\brief Overrides BFlattenable::FlattenedSize() Gets the size of the \brief Implements BFlattenable::FlattenedSize(). Gets the size of the
flattened entry_ref struct that represents the path in bytes. flattened entry_ref struct that represents the path in bytes.
\return The size of the flattened entry_ref struct that represents the \return The size of the flattened entry_ref struct that represents the
@@ -424,7 +424,7 @@
/*! /*!
\fn status_t BPath::Flatten(void* buffer, ssize_t size) const \fn status_t BPath::Flatten(void* buffer, ssize_t size) const
\brief Overrides BFlattenable::Flatten(). Converts the path of the object \brief Implements BFlattenable::Flatten(). Converts the path of the object
to an entry_ref and writes it into <em>buffer</em>. to an entry_ref and writes it into <em>buffer</em>.
\param buffer The buffer that the data is to be stored in. \param buffer The buffer that the data is to be stored in.
@@ -432,13 +432,13 @@
\returns A status code. \returns A status code.
\retval B_OK Everything went fine. \retval B_OK Everything went fine.
\retval B_BAD_VALUE \c NULL buffer or the buffer is of insufficient size. \retval B_BAD_VALUE \a buffer was \c NULL or of insufficient size.
*/ */
/*! /*!
\fn bool BPath::AllowsTypeCode(type_code code) const \fn bool BPath::AllowsTypeCode(type_code code) const
\brief Overrides BFlattenable::AllowsTypeCode(). Checks if type code is \brief Implements BFlattenable::AllowsTypeCode(). Checks if type code is
equal to \c B_REF_TYPE. equal to \c B_REF_TYPE.
\param code The type code to test. \param code The type code to test.
@@ -450,7 +450,7 @@
/*! /*!
\fn status_t BPath::Unflatten(type_code code, const void* buffer, \fn status_t BPath::Unflatten(type_code code, const void* buffer,
ssize_t size) ssize_t size)
\brief Overrides BFlattenable::Unflatten(). Initializes the object with \brief Implements BFlattenable::Unflatten(). Initializes the object with
the flattened entry_ref data from the passed in buffer. the flattened entry_ref data from the passed in buffer.
The type code must be set to \c B_REF_TYPE. The type code must be set to \c B_REF_TYPE.
@@ -461,7 +461,7 @@
\returns A status code. \returns A status code.
\retval B_OK Everything went fine. \retval B_OK Everything went fine.
\retval B_BAD_VALUE \a buffer is \c NULL or doesn't contain an entry_ref. \retval B_BAD_VALUE \a buffer was \c NULL or didn't contain an entry_ref.
*/ */
@@ -475,8 +475,8 @@
status_t BPath::_SetPath(const char* path) status_t BPath::_SetPath(const char* path)
\brief Sets the supplied path. \brief Sets the supplied path.
The path is copied. If \a path is \c NULL path of the object is set to The path is copied, if \a path is \c NULL the path of the object is set to
\c NULL as well. The object's old path is deleted. \c NULL as well. The old path is deleted.
\param path the path to be set \param path the path to be set
+15 -19
View File
@@ -15,14 +15,14 @@
class BUrlProtocol { class BUrlProtocol {
public: public:
BUrlProtocol(const BUrl& url, BUrlProtocol(const BUrl& url,
BUrlProtocolListener* listener, BUrlProtocolListener* listener,
BUrlContext* context, BUrlContext* context,
BUrlResult* result, BUrlResult* result,
const char* threadName, const char* threadName,
const char* protocolName); const char* protocolName);
virtual ~BUrlProtocol(); virtual ~BUrlProtocol();
// URL protocol required members // URL protocol required members
// TODO: (stippi) I know it's sometimes appealing to have these // TODO: (stippi) I know it's sometimes appealing to have these
// "simplistic" methods that can do anything, but they remove // "simplistic" methods that can do anything, but they remove
@@ -39,7 +39,7 @@ public:
// is it here at all? Why not have non-virtual setters for specific // is it here at all? Why not have non-virtual setters for specific
// things, where the setter is properly named? // things, where the setter is properly named?
virtual status_t SetOption(uint32 name, void* value) = 0; virtual status_t SetOption(uint32 name, void* value) = 0;
// URL protocol thread management // URL protocol thread management
virtual thread_id Run(); virtual thread_id Run();
virtual status_t Pause(); virtual status_t Pause();
@@ -51,27 +51,25 @@ public:
status_t SetResult(BUrlResult* result); status_t SetResult(BUrlResult* result);
status_t SetContext(BUrlContext* context); status_t SetContext(BUrlContext* context);
status_t SetListener(BUrlProtocolListener* listener); status_t SetListener(BUrlProtocolListener* listener);
// URL protocol parameters access // URL protocol parameters access
const BUrl& Url() const; const BUrl& Url() const;
BUrlResult* Result() const; BUrlResult* Result() const;
BUrlContext* Context() const; BUrlContext* Context() const;
BUrlProtocolListener* Listener() const; BUrlProtocolListener* Listener() const;
const BString& Protocol() const; const BString& Protocol() const;
// TODO: Does not belong here.
BHttpHeaders& Headers() { return fRequestHeaders; }
// URL protocol informations // URL protocol informations
bool IsRunning() const; bool IsRunning() const;
status_t Status() const; status_t Status() const;
virtual const char* StatusString(status_t threadStatus) virtual const char* StatusString(status_t threadStatus)
const; const;
protected: protected:
static int32 _ThreadEntry(void* arg); static int32 _ThreadEntry(void* arg);
virtual status_t _ProtocolLoop(); virtual status_t _ProtocolLoop();
virtual void _EmitDebug(BUrlProtocolDebugMessage type, virtual void _EmitDebug(BUrlProtocolDebugMessage type,
const char* format, ...); const char* format, ...);
// URL result parameters access // URL result parameters access
@@ -79,15 +77,13 @@ protected:
BHttpHeaders& _ResultHeaders(); BHttpHeaders& _ResultHeaders();
void _SetResultStatusCode(int32 statusCode); void _SetResultStatusCode(int32 statusCode);
BString& _ResultStatusText(); BString& _ResultStatusText();
protected: protected:
BUrl fUrl; BUrl fUrl;
BHttpHeaders fRequestHeaders;
// TODO: Does not belong here.
BUrlResult* fResult; BUrlResult* fResult;
BUrlContext* fContext; BUrlContext* fContext;
BUrlProtocolListener* fListener; BUrlProtocolListener* fListener;
bool fQuit; bool fQuit;
bool fRunning; bool fRunning;
status_t fThreadStatus; status_t fThreadStatus;
@@ -110,7 +106,7 @@ enum {
B_PROT_WRITE_FAILED, B_PROT_WRITE_FAILED,
B_PROT_READ_FAILED, B_PROT_READ_FAILED,
B_PROT_NO_MEMORY, B_PROT_NO_MEMORY,
B_PROT_PROTOCOL_ERROR, B_PROT_PROTOCOL_ERROR,
// Thread status over this one are guaranteed to be // Thread status over this one are guaranteed to be
// errors // errors
B_PROT_THREAD_STATUS__END B_PROT_THREAD_STATUS__END
@@ -118,18 +114,18 @@ enum {
namespace BPrivate { namespace BPrivate {
class BUrlProtocolOption { class BUrlProtocolOption {
public: public:
BUrlProtocolOption(void* value) : fValuePtr(value) { } BUrlProtocolOption(void* value) : fValuePtr(value) { }
bool Bool() const { return *reinterpret_cast<bool*>(fValuePtr); } bool Bool() const { return *reinterpret_cast<bool*>(fValuePtr); }
int8 Int8() const { return *reinterpret_cast<int8*>(fValuePtr); } int8 Int8() const { return *reinterpret_cast<int8*>(fValuePtr); }
int16 Int16() const { return *reinterpret_cast<int16*>(fValuePtr); } int16 Int16() const { return *reinterpret_cast<int16*>(fValuePtr); }
int32 Int32() const { return *reinterpret_cast<int32*>(fValuePtr); } int32 Int32() const { return *reinterpret_cast<int32*>(fValuePtr); }
char* String() const { return reinterpret_cast<char*>(fValuePtr); } char* String() const { return reinterpret_cast<char*>(fValuePtr); }
void* Pointer() const { return fValuePtr; } void* Pointer() const { return fValuePtr; }
private: private:
void* fValuePtr; void* fValuePtr;
}; };
+29 -29
View File
@@ -30,7 +30,7 @@ public:
virtual ~BUrlProtocolHttp(); virtual ~BUrlProtocolHttp();
virtual status_t SetOption(uint32 option, void* value); virtual status_t SetOption(uint32 option, void* value);
static bool IsInformationalStatusCode(int16 code); static bool IsInformationalStatusCode(int16 code);
static bool IsSuccessStatusCode(int16 code); static bool IsSuccessStatusCode(int16 code);
static bool IsRedirectionStatusCode(int16 code); static bool IsRedirectionStatusCode(int16 code);
@@ -39,49 +39,49 @@ public:
static int16 StatusCodeClass(int16 code); static int16 StatusCodeClass(int16 code);
virtual const char* StatusString(status_t threadStatus) const; virtual const char* StatusString(status_t threadStatus) const;
private: private:
void _ResetOptions(); void _ResetOptions();
status_t _ProtocolLoop(); status_t _ProtocolLoop();
bool _ResolveHostName(); bool _ResolveHostName();
status_t _MakeRequest(); status_t _MakeRequest();
void _CreateRequest(); void _CreateRequest();
void _AddHeaders(); void _AddHeaders();
status_t _GetLine(BString& destString); status_t _GetLine(BString& destString);
void _ParseStatus(); void _ParseStatus();
void _ParseHeaders(); void _ParseHeaders();
void _CopyChunkInBuffer(char** buffer, void _CopyChunkInBuffer(char** buffer,
ssize_t* bytesReceived); ssize_t* bytesReceived);
void _AddOutputBufferLine(const char* line); void _AddOutputBufferLine(const char* line);
private: private:
BAbstractSocket* fSocket; BAbstractSocket* fSocket;
BNetworkAddress fRemoteAddr; BNetworkAddress fRemoteAddr;
bool fSSL; bool fSSL;
int8 fRequestMethod; int8 fRequestMethod;
int8 fHttpVersion; int8 fHttpVersion;
BString fOutputBuffer; BString fOutputBuffer;
BNetBuffer fInputBuffer; BNetBuffer fInputBuffer;
BHttpHeaders fHeaders; BHttpHeaders fHeaders;
BHttpAuthentication fAuthentication; BHttpAuthentication fAuthentication;
// Request status // Request status
BHttpHeaders fOutputHeaders; BHttpHeaders fOutputHeaders;
bool fStatusReceived; bool fStatusReceived;
bool fHeadersReceived; bool fHeadersReceived;
bool fContentReceived; bool fContentReceived;
bool fTrailingHeadersReceived; bool fTrailingHeadersReceived;
// Protocol options // Protocol options
uint8 fOptMaxRedirs; uint8 fOptMaxRedirs;
BString fOptReferer; BString fOptReferer;
@@ -128,21 +128,21 @@ enum {
enum { enum {
B_HTTPOPT_METHOD = 0, B_HTTPOPT_METHOD = 0,
// (int) Request method (see B_HTTP_GET, ...) // (int) Request method (see B_HTTP_GET, ...)
B_HTTPOPT_FOLLOWLOCATION, B_HTTPOPT_FOLLOWLOCATION,
// (bool) Follow Location: headers // (bool) Follow Location: headers
B_HTTPOPT_MAXREDIRS, B_HTTPOPT_MAXREDIRS,
// (int) Max relocation // (int) Max relocation
B_HTTPOPT_HEADERS, B_HTTPOPT_HEADERS,
// (BHttpHeaders*) Headers to be sent // (BHttpHeaders*) Headers to be sent
B_HTTPOPT_REFERER, B_HTTPOPT_REFERER,
// (string) Referer // (string) Referer
B_HTTPOPT_USERAGENT, B_HTTPOPT_USERAGENT,
// (string) User-Agent // (string) User-Agent
B_HTTPOPT_SETCOOKIES, B_HTTPOPT_SETCOOKIES,
// (bool) Send cookies from context // (bool) Send cookies from context
B_HTTPOPT_DISCARD_DATA, B_HTTPOPT_DISCARD_DATA,
// (bool) Discard incoming data (still notified) // (bool) Discard incoming data (still notified)
B_HTTPOPT_DISABLE_LISTENER, B_HTTPOPT_DISABLE_LISTENER,
// (bool) Don't send notification to the listener // (bool) Don't send notification to the listener
B_HTTPOPT_AUTOREFERER, B_HTTPOPT_AUTOREFERER,
// (bool) Automatically set the Referer header // (bool) Automatically set the Referer header
@@ -156,7 +156,7 @@ enum {
// (string) Authentication password // (string) Authentication password
B_HTTPOPT_AUTHMETHOD, B_HTTPOPT_AUTHMETHOD,
// (int) Allowed authentication methods (see BHttpAuthenticationMethod) // (int) Allowed authentication methods (see BHttpAuthenticationMethod)
B_HTTPOPT__OPT_NUM B_HTTPOPT__OPT_NUM
}; };
@@ -179,7 +179,7 @@ enum http_status_code {
B_HTTP_STATUS_CONTINUE = B_HTTP_STATUS__INFORMATIONAL_BASE, B_HTTP_STATUS_CONTINUE = B_HTTP_STATUS__INFORMATIONAL_BASE,
B_HTTP_STATUS_SWITCHING_PROTOCOLS, B_HTTP_STATUS_SWITCHING_PROTOCOLS,
B_HTTP_STATUS__INFORMATIONAL_END, B_HTTP_STATUS__INFORMATIONAL_END,
// Success status codes // Success status codes
B_HTTP_STATUS__SUCCESS_BASE = 200, B_HTTP_STATUS__SUCCESS_BASE = 200,
B_HTTP_STATUS_OK = B_HTTP_STATUS__SUCCESS_BASE, B_HTTP_STATUS_OK = B_HTTP_STATUS__SUCCESS_BASE,
@@ -190,7 +190,7 @@ enum http_status_code {
B_HTTP_STATUS_RESET_CONTENT, B_HTTP_STATUS_RESET_CONTENT,
B_HTTP_STATUS_PARTIAL_CONTENT, B_HTTP_STATUS_PARTIAL_CONTENT,
B_HTTP_STATUS__SUCCESS_END, B_HTTP_STATUS__SUCCESS_END,
// Redirection status codes // Redirection status codes
B_HTTP_STATUS__REDIRECTION_BASE = 300, B_HTTP_STATUS__REDIRECTION_BASE = 300,
B_HTTP_STATUS_MULTIPLE_CHOICE = B_HTTP_STATUS__REDIRECTION_BASE, B_HTTP_STATUS_MULTIPLE_CHOICE = B_HTTP_STATUS__REDIRECTION_BASE,
@@ -201,7 +201,7 @@ enum http_status_code {
B_HTTP_STATUS_USE_PROXY, B_HTTP_STATUS_USE_PROXY,
B_HTTP_STATUS_TEMPORARY_REDIRECT, B_HTTP_STATUS_TEMPORARY_REDIRECT,
B_HTTP_STATUS__REDIRECTION_END, B_HTTP_STATUS__REDIRECTION_END,
// Client error status codes // Client error status codes
B_HTTP_STATUS__CLIENT_ERROR_BASE = 400, B_HTTP_STATUS__CLIENT_ERROR_BASE = 400,
B_HTTP_STATUS_BAD_REQUEST = B_HTTP_STATUS__CLIENT_ERROR_BASE, B_HTTP_STATUS_BAD_REQUEST = B_HTTP_STATUS__CLIENT_ERROR_BASE,
@@ -223,7 +223,7 @@ enum http_status_code {
B_HTTP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE, B_HTTP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE,
B_HTTP_STATUS_EXPECTATION_FAILED, B_HTTP_STATUS_EXPECTATION_FAILED,
B_HTTP_STATUS__CLIENT_ERROR_END, B_HTTP_STATUS__CLIENT_ERROR_END,
// Server error status codes // Server error status codes
B_HTTP_STATUS__SERVER_ERROR_BASE = 500, B_HTTP_STATUS__SERVER_ERROR_BASE = 500,
B_HTTP_STATUS_INTERNAL_SERVER_ERROR = B_HTTP_STATUS__SERVER_ERROR_BASE, B_HTTP_STATUS_INTERNAL_SERVER_ERROR = B_HTTP_STATUS__SERVER_ERROR_BASE,
+13 -12
View File
@@ -22,36 +22,34 @@ enum {
class BUrlRequest { class BUrlRequest {
public: public:
BUrlRequest(const BUrl& url, BUrlRequest(const BUrl& url,
BUrlProtocolListener* listener); BUrlProtocolListener* listener = NULL,
BUrlRequest(const BUrl& url); BUrlContext* context = NULL);
BUrlRequest(const BUrlRequest& other); BUrlRequest(const BUrlRequest& other);
virtual ~BUrlRequest() { }; virtual ~BUrlRequest();
// Request parameters modification // Request parameters modification
status_t SetUrl(const BUrl& url); status_t SetUrl(const BUrl& url);
void SetContext(BUrlContext* context); void SetContext(BUrlContext* context);
void SetProtocolListener( void SetProtocolListener(
BUrlProtocolListener* listener); BUrlProtocolListener* listener);
bool SetProtocolOption(int32 option, bool SetProtocolOption(int32 option,
void* value); void* value);
// Request parameters access // Request parameters access
const BUrlProtocol* Protocol(); const BUrlProtocol* Protocol();
const BUrlResult& Result(); const BUrlResult& Result();
const BUrl& Url(); const BUrl& Url();
// Request control // Request control
status_t Identify(); virtual status_t Start();
virtual status_t Perform();
// TODO: Rename to Run() perhaps? "Perform" is used for FBC stuff.
virtual status_t Pause(); virtual status_t Pause();
virtual status_t Resume(); virtual status_t Resume();
virtual status_t Abort(); virtual status_t Abort();
// Request informations // Request informations
virtual bool InitCheck() const; virtual status_t InitCheck() const;
bool IsRunning() const; bool IsRunning() const;
status_t Status() const; status_t Status() const;
// Overloaded members // Overloaded members
BUrlRequest& operator=(const BUrlRequest& other); BUrlRequest& operator=(const BUrlRequest& other);
@@ -62,7 +60,10 @@ protected:
BUrlResult fResult; BUrlResult fResult;
BUrlContext* fContext; BUrlContext* fContext;
BUrl fUrl; BUrl fUrl;
bool fReady; status_t fInitStatus;
private:
status_t _SetupProtocol();
}; };
#endif // _B_URL_REQUEST_H_ #endif // _B_URL_REQUEST_H_
+11
View File
@@ -16,6 +16,7 @@
class AboutView; class AboutView;
class BBitmap;
class BPoint; class BPoint;
class BHandler; class BHandler;
@@ -26,6 +27,7 @@ class BAboutWindow : public BWindow {
virtual ~BAboutWindow(); virtual ~BAboutWindow();
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void Show();
BPoint AboutPosition(float width, float height); BPoint AboutPosition(float width, float height);
void AddDescription(const char* description); void AddDescription(const char* description);
@@ -37,6 +39,15 @@ class BAboutWindow : public BWindow {
void AddVersionHistory(const char** history); void AddVersionHistory(const char** history);
void AddExtraInfo(const char* extraInfo); void AddExtraInfo(const char* extraInfo);
BBitmap* Icon();
void SetIcon(BBitmap* icon);
const char* Name();
void SetName(const char* name);
const char* Version();
void SetVersion(const char* version);
private: private:
AboutView* fAboutView; AboutView* fAboutView;
BHandler* fCaller; BHandler* fCaller;
+8 -3
View File
@@ -133,7 +133,6 @@ TBarMenuTitle::DrawContent()
rgb_color menuColor = menu->LowColor(); rgb_color menuColor = menu->LowColor();
rgb_color dark = tint_color(menuColor, B_DARKEN_1_TINT); rgb_color dark = tint_color(menuColor, B_DARKEN_1_TINT);
rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT);
rgb_color black = {0, 0, 0, 255};
bool inExpandoMode = dynamic_cast<TExpandoMenuBar*>(menu) != NULL; bool inExpandoMode = dynamic_cast<TExpandoMenuBar*>(menu) != NULL;
@@ -161,7 +160,10 @@ TBarMenuTitle::DrawContent()
frame.InsetBy(1, 1); frame.InsetBy(1, 1);
menu->SetHighColor(menuColor); menu->SetHighColor(menuColor);
menu->FillRect(frame); menu->FillRect(frame);
menu->SetHighColor(black); if (IsSelected())
menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR));
else
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
frame.InsetBy(-1, -1); frame.InsetBy(-1, -1);
if (inExpandoMode) if (inExpandoMode)
frame.top -= 1; frame.top -= 1;
@@ -177,7 +179,10 @@ TBarMenuTitle::DrawContent()
menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()); menu->StrokeLine(frame.LeftTop(), frame.LeftBottom());
} }
menu->SetHighColor(black); if (IsSelected())
menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR));
else
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
} }
menu->SetDrawingMode(B_OP_ALPHA); menu->SetDrawingMode(B_OP_ALPHA);
+12
View File
@@ -283,6 +283,18 @@ PreferencesWindow::QuitRequested()
} }
void
PreferencesWindow::Show()
{
if (IsHidden()) {
// move to current workspace
SetWorkspaces(B_CURRENT_WORKSPACE);
}
BWindow::Show();
}
void void
PreferencesWindow::WindowActivated(bool active) PreferencesWindow::WindowActivated(bool active)
{ {
+1
View File
@@ -35,6 +35,7 @@ public:
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void Show();
virtual void WindowActivated(bool active); virtual void WindowActivated(bool active);
void UpdateRecentCounts(); void UpdateRecentCounts();
+5 -3
View File
@@ -395,9 +395,6 @@ TTeamMenuItem::DrawContent()
menu->MovePenTo(drawLoc); menu->MovePenTo(drawLoc);
} }
// set the pen to black so that either method will draw in the same color
// low color is set in inherited::DrawContent, override makes sure its
// what we want
if (fDrawLabel) { if (fDrawLabel) {
menu->SetDrawingMode(B_OP_OVER); menu->SetDrawingMode(B_OP_OVER);
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
@@ -513,6 +510,11 @@ TTeamMenuItem::DrawContentLabel()
else else
menu->SetLowColor(menu->LowColor()); menu->SetLowColor(menu->LowColor());
if (IsSelected())
menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR));
else
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
menu->DrawString(label); menu->DrawString(label);
free(truncLabel); free(truncLabel);
+5 -2
View File
@@ -272,8 +272,11 @@ TWindowMenuItem::DrawContent()
+ ((frame.Height() - fTitleAscent - fTitleDescent) / 2) + 1.0f; + ((frame.Height() - fTitleAscent - fTitleDescent) / 2) + 1.0f;
menu->MovePenTo(contLoc); menu->MovePenTo(contLoc);
// Set the pen color so that the label is always visible.
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); if (IsSelected())
menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR));
else
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
BMenuItem::DrawContent(); BMenuItem::DrawContent();
+1 -1
View File
@@ -77,7 +77,7 @@ PowerStatusView::PowerStatusView(BMessage* archive)
PowerStatusView::~PowerStatusView() PowerStatusView::~PowerStatusView()
{ {
if (fAboutWindow != NULL) if (fAboutWindow != NULL && fAboutWindow->Lock())
fAboutWindow->Quit(); fAboutWindow->Quit();
} }
+10 -7
View File
@@ -39,6 +39,7 @@
#include <Catalog.h> #include <Catalog.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <ControlLook.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <File.h> #include <File.h>
@@ -56,6 +57,7 @@
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
#include <SeparatorView.h> #include <SeparatorView.h>
#include <Size.h>
#include <SpaceLayoutItem.h> #include <SpaceLayoutItem.h>
#include <StatusBar.h> #include <StatusBar.h>
#include <StringView.h> #include <StringView.h>
@@ -424,6 +426,12 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
const float kElementSpacing = 5; const float kElementSpacing = 5;
// Find group // Find group
fFindCloseButton = new BButton("\xc3\x97", // multiplication sign
new BMessage(EDIT_HIDE_FIND_GROUP));
fFindCloseButton->SetExplicitMinSize(
BSize(be_control_look->DefaultItemSpacing() * 3, B_SIZE_UNSET));
fFindCloseButton->SetExplicitMaxSize(
BSize(be_control_look->DefaultItemSpacing() * 3, B_SIZE_UNSET));
fFindTextControl = new BTextControl("find", B_TRANSLATE("Find:"), "", fFindTextControl = new BTextControl("find", B_TRANSLATE("Find:"), "",
new BMessage(EDIT_FIND_NEXT)); new BMessage(EDIT_FIND_NEXT));
fFindTextControl->SetModificationMessage(new BMessage(FIND_TEXT_CHANGED)); fFindTextControl->SetModificationMessage(new BMessage(FIND_TEXT_CHANGED));
@@ -431,18 +439,15 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
new BMessage(EDIT_FIND_PREVIOUS)); new BMessage(EDIT_FIND_PREVIOUS));
fFindNextButton = new BButton(B_TRANSLATE("Next"), fFindNextButton = new BButton(B_TRANSLATE("Next"),
new BMessage(EDIT_FIND_NEXT)); new BMessage(EDIT_FIND_NEXT));
fFindCloseButton = new BButton(B_TRANSLATE("Close"),
new BMessage(EDIT_HIDE_FIND_GROUP));
fFindCaseSensitiveCheckBox = new BCheckBox(B_TRANSLATE("Match case")); fFindCaseSensitiveCheckBox = new BCheckBox(B_TRANSLATE("Match case"));
BGroupLayout* findGroup = BLayoutBuilder::Group<>(B_VERTICAL, 0.0) BGroupLayout* findGroup = BLayoutBuilder::Group<>(B_VERTICAL, 0.0)
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
.Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) .Add(BGroupLayoutBuilder(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
.Add(fFindCloseButton)
.Add(fFindTextControl) .Add(fFindTextControl)
.Add(fFindPreviousButton) .Add(fFindPreviousButton)
.Add(fFindNextButton) .Add(fFindNextButton)
.Add(fFindCaseSensitiveCheckBox) .Add(fFindCaseSensitiveCheckBox)
.Add(BSpaceLayoutItem::CreateGlue())
.Add(fFindCloseButton)
.SetInsets(kInsetSpacing, kInsetSpacing, .SetInsets(kInsetSpacing, kInsetSpacing,
kInsetSpacing, kInsetSpacing) kInsetSpacing, kInsetSpacing)
) )
@@ -2332,5 +2337,3 @@ BrowserWindow::_HandlePageSourceResult(const BMessage* message)
alert->Go(NULL); alert->Go(NULL);
} }
} }
+35 -1
View File
@@ -222,9 +222,12 @@ struct MimeAttribute
MimeAttribute(BMessage& msg, int32 index); MimeAttribute(BMessage& msg, int32 index);
MimeAttribute(TUserArgs& args); MimeAttribute(TUserArgs& args);
MimeAttribute(const MimeAttribute& src);
status_t InitCheck() { return fStatus; } status_t InitCheck() { return fStatus; }
MimeAttribute& operator=(const MimeAttribute& src);
void Dump(); void Dump();
void SyncWith(TUserArgs& args) throw(Error); void SyncWith(TUserArgs& args) throw(Error);
void StoreInto(BMessage* target); void StoreInto(BMessage* target);
@@ -288,12 +291,43 @@ MimeAttribute::MimeAttribute(BMessage& msg, int32 index)
MimeAttribute::MimeAttribute(TUserArgs& args) MimeAttribute::MimeAttribute(TUserArgs& args)
:
fStatus(B_NO_INIT),
fType('CSTR'),
fViewable(true),
fEditable(false),
fExtra(false),
fWidth(0),
fAlignment(0)
{ {
SyncWith(args); SyncWith(args);
fStatus = B_OK; fStatus = B_OK;
} }
MimeAttribute::MimeAttribute(const MimeAttribute& src)
{
*this = src;
}
MimeAttribute&
MimeAttribute::operator=(const MimeAttribute& src)
{
fStatus = src.fStatus;
fName = src.fName;
fPublicName = src.fPublicName;
fType = src.fType;
fViewable = src.fViewable;
fEditable = src.fEditable;
fExtra = src.fExtra;
fWidth = src.fWidth;
fAlignment = src.fAlignment;
return *this;
}
void void
MimeAttribute::SyncWith(TUserArgs& args) throw(Error) MimeAttribute::SyncWith(TUserArgs& args) throw(Error)
{ {
@@ -609,7 +643,7 @@ MimeType::_Init(char** argv) throw (Error)
throw Error("'%s' allowed only after the '%s' <name>", throw Error("'%s' allowed only after the '%s' <name>",
name, kAttribute); name, kAttribute);
if (!*++arg) if (!*++arg || **arg == '-')
throw Error("'%s', argument should be specified", name); throw Error("'%s', argument should be specified", name);
TUserArgsI A = fUserAttributes.back().find(key); TUserArgsI A = fUserAttributes.back().find(key);
+27 -27
View File
@@ -28,9 +28,9 @@ static const char* kProtocolThreadStrStatus[B_PROT_THREAD_STATUS__END+1]
BUrlProtocol::BUrlProtocol(const BUrl& url, BUrlProtocolListener* listener, BUrlProtocol::BUrlProtocol(const BUrl& url, BUrlProtocolListener* listener,
BUrlContext* context, BUrlResult* result, const char* threadName, BUrlContext* context, BUrlResult* result, const char* threadName,
const char* protocolName) const char* protocolName)
: :
fUrl(url), fUrl(url),
fResult(result), fResult(result),
fContext(context), fContext(context),
@@ -61,20 +61,20 @@ BUrlProtocol::Run()
"[urlProtocol=%p]!\n", this)); "[urlProtocol=%p]!\n", this));
return fThreadId; return fThreadId;
} }
fThreadId = spawn_thread(BUrlProtocol::_ThreadEntry, fThreadName, fThreadId = spawn_thread(BUrlProtocol::_ThreadEntry, fThreadName,
B_NORMAL_PRIORITY, this); B_NORMAL_PRIORITY, this);
if (fThreadId < B_OK) if (fThreadId < B_OK)
return fThreadId; return fThreadId;
status_t launchErr = resume_thread(fThreadId); status_t launchErr = resume_thread(fThreadId);
if (launchErr < B_OK) { if (launchErr < B_OK) {
PRINT(("BUrlProtocol::Run() : Failed to resume thread %ld\n", PRINT(("BUrlProtocol::Run() : Failed to resume thread %ld\n",
fThreadId)); fThreadId));
return launchErr; return launchErr;
} }
fRunning = true; fRunning = true;
return fThreadId; return fThreadId;
} }
@@ -101,11 +101,11 @@ BUrlProtocol::Stop()
{ {
if (!fRunning) if (!fRunning)
return B_ERROR; return B_ERROR;
status_t threadStatus = B_OK; status_t threadStatus = B_OK;
fQuit = true; fQuit = true;
wait_for_thread(fThreadId, &threadStatus); wait_for_thread(fThreadId, &threadStatus);
return threadStatus; return threadStatus;
} }
@@ -119,7 +119,7 @@ BUrlProtocol::SetUrl(const BUrl& url)
// We should avoid to change URL while the thread is running ... // We should avoid to change URL while the thread is running ...
if (IsRunning()) if (IsRunning())
return B_ERROR; return B_ERROR;
fUrl = url; fUrl = url;
return B_OK; return B_OK;
} }
@@ -130,7 +130,7 @@ BUrlProtocol::SetResult(BUrlResult* result)
{ {
if (IsRunning()) if (IsRunning())
return B_ERROR; return B_ERROR;
fResult = result; fResult = result;
return B_OK; return B_OK;
} }
@@ -138,10 +138,10 @@ BUrlProtocol::SetResult(BUrlResult* result)
status_t status_t
BUrlProtocol::SetContext(BUrlContext* context) BUrlProtocol::SetContext(BUrlContext* context)
{ {
if (IsRunning()) if (IsRunning())
return B_ERROR; return B_ERROR;
fContext = context; fContext = context;
return B_OK; return B_OK;
} }
@@ -152,7 +152,7 @@ BUrlProtocol::SetListener(BUrlProtocolListener* listener)
{ {
if (IsRunning()) if (IsRunning())
return B_ERROR; return B_ERROR;
fListener = listener; fListener = listener;
return B_OK; return B_OK;
} }
@@ -226,23 +226,23 @@ BUrlProtocol::StatusString(status_t threadStatus) const
// #pragma mark Thread management // #pragma mark Thread management
/*static*/ int32 /*static*/ int32
BUrlProtocol::_ThreadEntry(void* arg) BUrlProtocol::_ThreadEntry(void* arg)
{ {
BUrlProtocol* urlProtocol = reinterpret_cast<BUrlProtocol*>(arg); BUrlProtocol* urlProtocol = reinterpret_cast<BUrlProtocol*>(arg);
urlProtocol->fThreadStatus = B_PROT_RUNNING; urlProtocol->fThreadStatus = B_PROT_RUNNING;
status_t protocolLoopExitStatus = urlProtocol->_ProtocolLoop(); status_t protocolLoopExitStatus = urlProtocol->_ProtocolLoop();
urlProtocol->fRunning = false; urlProtocol->fRunning = false;
urlProtocol->fThreadStatus = protocolLoopExitStatus; urlProtocol->fThreadStatus = protocolLoopExitStatus;
if (urlProtocol->fListener != NULL) if (urlProtocol->fListener != NULL)
urlProtocol->fListener->RequestCompleted(urlProtocol, urlProtocol->fListener->RequestCompleted(urlProtocol,
protocolLoopExitStatus == B_PROT_SUCCESS); protocolLoopExitStatus == B_PROT_SUCCESS);
return B_OK; return B_OK;
} }
@@ -253,13 +253,13 @@ BUrlProtocol::_ProtocolLoop()
// Dummy _ProtocolLoop // Dummy _ProtocolLoop
while (!fQuit) while (!fQuit)
snooze(1000); snooze(1000);
return B_PROT_SUCCESS; return B_PROT_SUCCESS;
} }
void void
BUrlProtocol::_EmitDebug(BUrlProtocolDebugMessage type, BUrlProtocol::_EmitDebug(BUrlProtocolDebugMessage type,
const char* format, ...) const char* format, ...)
{ {
if (fListener == NULL) if (fListener == NULL)
@@ -267,7 +267,7 @@ BUrlProtocol::_EmitDebug(BUrlProtocolDebugMessage type,
va_list arguments; va_list arguments;
va_start(arguments, format); va_start(arguments, format);
char debugMsg[256]; char debugMsg[256];
vsnprintf(debugMsg, 256, format, arguments); vsnprintf(debugMsg, 256, format, arguments);
fListener->DebugMessage(this, type, debugMsg); fListener->DebugMessage(this, type, debugMsg);
@@ -275,7 +275,7 @@ BUrlProtocol::_EmitDebug(BUrlProtocolDebugMessage type,
} }
BMallocIO& BMallocIO&
BUrlProtocol::_ResultRawData() BUrlProtocol::_ResultRawData()
{ {
return fResult->fRawData; return fResult->fRawData;
+177 -201
View File
@@ -31,10 +31,10 @@ static const char* kHttpProtocolThreadStrStatus[
}; };
BUrlProtocolHttp::BUrlProtocolHttp(BUrl& url, bool ssl, BUrlProtocolHttp::BUrlProtocolHttp(BUrl& url, bool ssl,
const char *protocolName, BUrlProtocolListener* listener, const char* protocolName, BUrlProtocolListener* listener,
BUrlContext* context, BUrlResult* result) BUrlContext* context, BUrlResult* result)
: :
BUrlProtocol(url, listener, context, result, "BUrlProtocol.HTTP", protocolName), BUrlProtocol(url, listener, context, result, "BUrlProtocol.HTTP", protocolName),
fSSL(ssl), fSSL(ssl),
fRequestMethod(B_HTTP_GET), fRequestMethod(B_HTTP_GET),
@@ -45,7 +45,6 @@ BUrlProtocolHttp::BUrlProtocolHttp(BUrl& url, bool ssl,
fSocket = new BSecureSocket(); fSocket = new BSecureSocket();
else else
fSocket = new BSocket(); fSocket = new BSocket();
} }
@@ -59,67 +58,67 @@ status_t
BUrlProtocolHttp::SetOption(uint32 name, void* value) BUrlProtocolHttp::SetOption(uint32 name, void* value)
{ {
BUrlProtocolOption option(value); BUrlProtocolOption option(value);
switch (name) { switch (name) {
case B_HTTPOPT_METHOD: case B_HTTPOPT_METHOD:
fRequestMethod = option.Int8(); fRequestMethod = option.Int8();
break; break;
case B_HTTPOPT_FOLLOWLOCATION: case B_HTTPOPT_FOLLOWLOCATION:
fOptFollowLocation = option.Bool(); fOptFollowLocation = option.Bool();
break; break;
case B_HTTPOPT_MAXREDIRS: case B_HTTPOPT_MAXREDIRS:
fOptMaxRedirs = option.Int8(); fOptMaxRedirs = option.Int8();
break; break;
case B_HTTPOPT_REFERER: case B_HTTPOPT_REFERER:
fOptReferer = option.String(); fOptReferer = option.String();
break; break;
case B_HTTPOPT_USERAGENT: case B_HTTPOPT_USERAGENT:
fOptUserAgent = option.String(); fOptUserAgent = option.String();
break; break;
case B_HTTPOPT_HEADERS: case B_HTTPOPT_HEADERS:
fOptHeaders = reinterpret_cast<BHttpHeaders*>(option.Pointer()); fOptHeaders = reinterpret_cast<BHttpHeaders*>(option.Pointer());
break; break;
case B_HTTPOPT_DISCARD_DATA: case B_HTTPOPT_DISCARD_DATA:
fOptDiscardData = option.Bool(); fOptDiscardData = option.Bool();
break; break;
case B_HTTPOPT_DISABLE_LISTENER: case B_HTTPOPT_DISABLE_LISTENER:
fOptDisableListener = option.Bool(); fOptDisableListener = option.Bool();
break; break;
case B_HTTPOPT_AUTOREFERER: case B_HTTPOPT_AUTOREFERER:
fOptAutoReferer = option.Bool(); fOptAutoReferer = option.Bool();
break; break;
case B_HTTPOPT_POSTFIELDS: case B_HTTPOPT_POSTFIELDS:
fOptPostFields = reinterpret_cast<BHttpForm*>(option.Pointer()); fOptPostFields = reinterpret_cast<BHttpForm*>(option.Pointer());
if (fOptPostFields != NULL) if (fOptPostFields != NULL)
fRequestMethod = B_HTTP_POST; fRequestMethod = B_HTTP_POST;
break; break;
case B_HTTPOPT_INPUTDATA: case B_HTTPOPT_INPUTDATA:
fOptInputData = reinterpret_cast<BDataIO*>(option.Pointer()); fOptInputData = reinterpret_cast<BDataIO*>(option.Pointer());
break; break;
case B_HTTPOPT_AUTHUSERNAME: case B_HTTPOPT_AUTHUSERNAME:
fOptUsername = option.String(); fOptUsername = option.String();
break; break;
case B_HTTPOPT_AUTHPASSWORD: case B_HTTPOPT_AUTHPASSWORD:
fOptPassword = option.String(); fOptPassword = option.String();
break; break;
default: default:
return B_ERROR; return B_ERROR;
} }
return B_OK; return B_OK;
} }
@@ -177,7 +176,7 @@ BUrlProtocolHttp::StatusCodeClass(int16 code)
return B_HTTP_STATUS_CLASS_CLIENT_ERROR; return B_HTTP_STATUS_CLASS_CLIENT_ERROR;
else if (BUrlProtocolHttp::IsServerErrorStatusCode(code)) else if (BUrlProtocolHttp::IsServerErrorStatusCode(code))
return B_HTTP_STATUS_CLASS_SERVER_ERROR; return B_HTTP_STATUS_CLASS_SERVER_ERROR;
return B_HTTP_STATUS_CLASS_INVALID; return B_HTTP_STATUS_CLASS_INVALID;
} }
@@ -190,11 +189,11 @@ BUrlProtocolHttp::StatusString(status_t threadStatus) const
else if (threadStatus >= B_PROT_HTTP_THREAD_STATUS__END) else if (threadStatus >= B_PROT_HTTP_THREAD_STATUS__END)
return BUrlProtocol::StatusString(-1); return BUrlProtocol::StatusString(-1);
else else
return kHttpProtocolThreadStrStatus[threadStatus return kHttpProtocolThreadStrStatus[threadStatus
- B_PROT_THREAD_STATUS__END]; - B_PROT_THREAD_STATUS__END];
} }
void void
BUrlProtocolHttp::_ResetOptions() BUrlProtocolHttp::_ResetOptions()
{ {
@@ -204,7 +203,7 @@ BUrlProtocolHttp::_ResetOptions()
fOptUserAgent = "Services Kit (Haiku)"; fOptUserAgent = "Services Kit (Haiku)";
fOptUsername = ""; fOptUsername = "";
fOptPassword = ""; fOptPassword = "";
fOptAuthMethods = B_HTTP_AUTHENTICATION_BASIC | B_HTTP_AUTHENTICATION_DIGEST fOptAuthMethods = B_HTTP_AUTHENTICATION_BASIC | B_HTTP_AUTHENTICATION_DIGEST
| B_HTTP_AUTHENTICATION_IE_DIGEST; | B_HTTP_AUTHENTICATION_IE_DIGEST;
fOptHeaders = NULL; fOptHeaders = NULL;
fOptPostFields = NULL; fOptPostFields = NULL;
@@ -217,16 +216,16 @@ BUrlProtocolHttp::_ResetOptions()
#include <stdio.h> #include <stdio.h>
status_t status_t
BUrlProtocolHttp::_ProtocolLoop() BUrlProtocolHttp::_ProtocolLoop()
{ {
printf("UHP[%p]::{Loop} %s\n", this, fUrl.UrlString().String()); printf("UHP[%p]::{Loop} %s\n", this, fUrl.UrlString().String());
// Initialize the request redirection loop // Initialize the request redirection loop
int8 maxRedirs = fOptMaxRedirs; int8 maxRedirs = fOptMaxRedirs;
bool newRequest; bool newRequest;
do { do {
newRequest = false; newRequest = false;
// Result reset // Result reset
fOutputBuffer.Truncate(0, true); fOutputBuffer.Truncate(0, true);
fOutputHeaders.Clear(); fOutputHeaders.Clear();
@@ -234,61 +233,61 @@ BUrlProtocolHttp::_ProtocolLoop()
_ResultHeaders().Clear(); _ResultHeaders().Clear();
_ResultRawData().Seek(SEEK_SET, 0); _ResultRawData().Seek(SEEK_SET, 0);
_ResultRawData().SetSize(0); _ResultRawData().SetSize(0);
if (!_ResolveHostName()) { if (!_ResolveHostName()) {
_EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR, _EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR,
"Unable to resolve hostname, aborting."); "Unable to resolve hostname, aborting.");
return B_PROT_CANT_RESOLVE_HOSTNAME; return B_PROT_CANT_RESOLVE_HOSTNAME;
} }
_CreateRequest(); _CreateRequest();
_AddHeaders(); _AddHeaders();
_AddOutputBufferLine(""); _AddOutputBufferLine("");
status_t requestStatus = _MakeRequest(); status_t requestStatus = _MakeRequest();
if (requestStatus != B_PROT_SUCCESS) if (requestStatus != B_PROT_SUCCESS)
return requestStatus; return requestStatus;
// Prepare the referer for the next request if needed // Prepare the referer for the next request if needed
if (fOptAutoReferer) if (fOptAutoReferer)
fOptReferer = fUrl.UrlString(); fOptReferer = fUrl.UrlString();
switch (StatusCodeClass(fResult->StatusCode())) { switch (StatusCodeClass(fResult->StatusCode())) {
case B_HTTP_STATUS_CLASS_INFORMATIONAL: case B_HTTP_STATUS_CLASS_INFORMATIONAL:
// Header 100:continue should have been // Header 100:continue should have been
// handled in the _MakeRequest read loop // handled in the _MakeRequest read loop
break; break;
case B_HTTP_STATUS_CLASS_SUCCESS: case B_HTTP_STATUS_CLASS_SUCCESS:
break; break;
case B_HTTP_STATUS_CLASS_REDIRECTION: case B_HTTP_STATUS_CLASS_REDIRECTION:
// Redirection has been explicitly disabled // Redirection has been explicitly disabled
if (!fOptFollowLocation) if (!fOptFollowLocation)
break; break;
// TODO: Some browsers seems to translate POST requests to // TODO: Some browsers seems to translate POST requests to
// GET when following a 302 redirection // GET when following a 302 redirection
if (fResult->StatusCode() == B_HTTP_STATUS_MOVED_PERMANENTLY) { if (fResult->StatusCode() == B_HTTP_STATUS_MOVED_PERMANENTLY) {
BString locationUrl = fHeaders["Location"]; BString locationUrl = fHeaders["Location"];
// Absolute path // Absolute path
if (locationUrl[0] == '/') if (locationUrl[0] == '/')
fUrl.SetPath(locationUrl); fUrl.SetPath(locationUrl);
// URI // URI
else else
fUrl.SetUrlString(locationUrl); fUrl.SetUrlString(locationUrl);
if (--maxRedirs > 0) { if (--maxRedirs > 0) {
newRequest = true; newRequest = true;
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, _EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT,
"Following: %s\n", "Following: %s\n",
fUrl.UrlString().String()); fUrl.UrlString().String());
} }
} }
break; break;
case B_HTTP_STATUS_CLASS_CLIENT_ERROR: case B_HTTP_STATUS_CLASS_CLIENT_ERROR:
switch (fResult->StatusCode()) { switch (fResult->StatusCode()) {
case B_HTTP_STATUS_UNAUTHORIZED: case B_HTTP_STATUS_UNAUTHORIZED:
@@ -296,7 +295,7 @@ BUrlProtocolHttp::_ProtocolLoop()
newRequest = false; newRequest = false;
break; break;
} }
newRequest = false; newRequest = false;
if (fOptUsername.Length() > 0 if (fOptUsername.Length() > 0
&& fAuthentication.Initialize(fHeaders["WWW-Authenticate"]) && fAuthentication.Initialize(fHeaders["WWW-Authenticate"])
@@ -308,21 +307,20 @@ BUrlProtocolHttp::_ProtocolLoop()
break; break;
} }
break; break;
case B_HTTP_STATUS_CLASS_SERVER_ERROR: case B_HTTP_STATUS_CLASS_SERVER_ERROR:
break; break;
default: default:
case B_HTTP_STATUS_CLASS_INVALID: case B_HTTP_STATUS_CLASS_INVALID:
break; break;
} }
} while (newRequest); } while (newRequest);
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, _EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT,
"%ld headers and %ld bytes of data remaining", "%ld headers and %ld bytes of data remaining",
fHeaders.CountHeaders(), fHeaders.CountHeaders(), fInputBuffer.Size());
fInputBuffer.Size());
if (fResult->StatusCode() == 404) if (fResult->StatusCode() == 404)
return B_PROT_HTTP_NOT_FOUND; return B_PROT_HTTP_NOT_FOUND;
@@ -335,27 +333,23 @@ BUrlProtocolHttp::_ResolveHostName()
{ {
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Resolving %s", _EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Resolving %s",
fUrl.UrlString().String()); fUrl.UrlString().String());
if (fUrl.HasPort()) if (fUrl.HasPort())
fRemoteAddr = BNetworkAddress(fUrl.Host(), fUrl.Port()); fRemoteAddr = BNetworkAddress(fUrl.Host(), fUrl.Port());
else { else {
if (fSSL) fRemoteAddr = BNetworkAddress(fUrl.Host(), fSSL ? 443 : 80);
fRemoteAddr = BNetworkAddress(fUrl.Host(), 443);
else
fRemoteAddr = BNetworkAddress(fUrl.Host(), 80);
} }
if (fRemoteAddr.InitCheck() != B_OK) if (fRemoteAddr.InitCheck() != B_OK)
return false; return false;
//! ProtocolHook:HostnameResolved //! ProtocolHook:HostnameResolved
if (fListener != NULL) if (fListener != NULL)
fListener->HostnameResolved(this, fListener->HostnameResolved(this, fRemoteAddr.ToString().String());
const_cast<const char*>(fRemoteAddr.ToString().String()));
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Hostname resolved to: %s",
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Hostname resolved to: %s", fRemoteAddr.ToString().String());
fRemoteAddr.ToString().String());
return true; return true;
} }
@@ -363,58 +357,58 @@ BUrlProtocolHttp::_ResolveHostName()
status_t status_t
BUrlProtocolHttp::_MakeRequest() BUrlProtocolHttp::_MakeRequest()
{ {
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Connection to %s.", _EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Connection to %s.",
fUrl.Authority().String()); fUrl.Authority().String());
status_t connectError = fSocket->Connect(fRemoteAddr); status_t connectError = fSocket->Connect(fRemoteAddr);
if (connectError != B_OK) { if (connectError != B_OK) {
_EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR, "Socket connection error."); _EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR, "Socket connection error.");
return B_PROT_CONNECTION_FAILED; return B_PROT_CONNECTION_FAILED;
} }
//! ProtocolHook:ConnectionOpened //! ProtocolHook:ConnectionOpened
if (fListener != NULL) if (fListener != NULL)
fListener->ConnectionOpened(this); fListener->ConnectionOpened(this);
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Connection opened."); _EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Connection opened.");
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Sending request (size=%d)", _EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Sending request (size=%d)",
fOutputBuffer.Length()); fOutputBuffer.Length());
fSocket->Write(fOutputBuffer.String(), fOutputBuffer.Length()); fSocket->Write(fOutputBuffer.String(), fOutputBuffer.Length());
fOutputBuffer.Truncate(0); fOutputBuffer.Truncate(0);
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Request sent."); _EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Request sent.");
if (fRequestMethod == B_HTTP_POST && fOptPostFields != NULL) { if (fRequestMethod == B_HTTP_POST && fOptPostFields != NULL) {
if (fOptPostFields->GetFormType() != B_HTTP_FORM_MULTIPART) { if (fOptPostFields->GetFormType() != B_HTTP_FORM_MULTIPART) {
fOutputBuffer = fOptPostFields->RawData(); fOutputBuffer = fOptPostFields->RawData();
_EmitDebug(B_URL_PROTOCOL_DEBUG_TRANSFER_OUT, _EmitDebug(B_URL_PROTOCOL_DEBUG_TRANSFER_OUT,
fOutputBuffer.String()); fOutputBuffer.String());
fSocket->Write(fOutputBuffer.String(), fOutputBuffer.Length()); fSocket->Write(fOutputBuffer.String(), fOutputBuffer.Length());
} else { } else {
for (BHttpForm::Iterator it = fOptPostFields->GetIterator(); for (BHttpForm::Iterator it = fOptPostFields->GetIterator();
const BHttpFormData* currentField = it.Next(); const BHttpFormData* currentField = it.Next();
) { ) {
_EmitDebug(B_URL_PROTOCOL_DEBUG_TRANSFER_OUT, _EmitDebug(B_URL_PROTOCOL_DEBUG_TRANSFER_OUT,
it.MultipartHeader().String()); it.MultipartHeader().String());
fSocket->Write(it.MultipartHeader().String(), fSocket->Write(it.MultipartHeader().String(),
it.MultipartHeader().Length()); it.MultipartHeader().Length());
switch (currentField->Type()) { switch (currentField->Type()) {
case B_HTTPFORM_UNKNOWN: case B_HTTPFORM_UNKNOWN:
ASSERT(0); ASSERT(0);
break; break;
case B_HTTPFORM_STRING: case B_HTTPFORM_STRING:
fSocket->Write(currentField->String().String(), fSocket->Write(currentField->String().String(),
currentField->String().Length()); currentField->String().Length());
break; break;
case B_HTTPFORM_FILE: case B_HTTPFORM_FILE:
{ {
BFile upFile(currentField->File().Path(), BFile upFile(currentField->File().Path(),
B_READ_ONLY); B_READ_ONLY);
char readBuffer[1024]; char readBuffer[1024];
ssize_t readSize; ssize_t readSize;
readSize = upFile.Read(readBuffer, 1024); readSize = upFile.Read(readBuffer, 1024);
while (readSize > 0) { while (readSize > 0) {
@@ -423,45 +417,45 @@ BUrlProtocolHttp::_MakeRequest()
} }
} }
break; break;
case B_HTTPFORM_BUFFER: case B_HTTPFORM_BUFFER:
fSocket->Write(currentField->Buffer(), fSocket->Write(currentField->Buffer(),
currentField->BufferSize()); currentField->BufferSize());
break; break;
} }
fSocket->Write("\r\n", 2); fSocket->Write("\r\n", 2);
} }
fSocket->Write(fOptPostFields->GetMultipartFooter().String(), fSocket->Write(fOptPostFields->GetMultipartFooter().String(),
fOptPostFields->GetMultipartFooter().Length()); fOptPostFields->GetMultipartFooter().Length());
} }
} else if ((fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT) } else if ((fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT)
&& fOptInputData != NULL) { && fOptInputData != NULL) {
char outputTempBuffer[1024]; char outputTempBuffer[1024];
ssize_t read = 0; ssize_t read = 0;
while (read != -1) { while (read != -1) {
read = fOptInputData->Read(outputTempBuffer, 1024); read = fOptInputData->Read(outputTempBuffer, 1024);
if (read > 0) { if (read > 0) {
char hexSize[16]; char hexSize[16];
size_t hexLength = sprintf(hexSize, "%ld", read); size_t hexLength = sprintf(hexSize, "%ld", read);
fSocket->Write(hexSize, hexLength); fSocket->Write(hexSize, hexLength);
fSocket->Write("\r\n", 2); fSocket->Write("\r\n", 2);
fSocket->Write(outputTempBuffer, read); fSocket->Write(outputTempBuffer, read);
fSocket->Write("\r\n", 2); fSocket->Write("\r\n", 2);
} }
} }
fSocket->Write("0\r\n\r\n", 5); fSocket->Write("0\r\n\r\n", 5);
} }
fOutputBuffer.Truncate(0, true); fOutputBuffer.Truncate(0, true);
fStatusReceived = false; fStatusReceived = false;
fHeadersReceived = false; fHeadersReceived = false;
// Receive loop // Receive loop
bool receiveEnd = false; bool receiveEnd = false;
bool parseEnd = false; bool parseEnd = false;
@@ -473,38 +467,38 @@ BUrlProtocolHttp::_MakeRequest()
ssize_t bytesTotal = 0; ssize_t bytesTotal = 0;
char* inputTempBuffer = NULL; char* inputTempBuffer = NULL;
fQuit = false; fQuit = false;
while (!fQuit && !(receiveEnd && parseEnd)) { while (!fQuit && !(receiveEnd && parseEnd)) {
if (!receiveEnd) { if (!receiveEnd) {
fSocket->WaitForReadable(); fSocket->WaitForReadable();
BNetBuffer chunk(receiveBufferSize); BNetBuffer chunk(receiveBufferSize);
bytesRead = fSocket->Read(chunk.Data(), receiveBufferSize); bytesRead = fSocket->Read(chunk.Data(), receiveBufferSize);
if (bytesRead < 0) { if (bytesRead < 0) {
readError = true; readError = true;
fQuit = true; fQuit = true;
continue; continue;
} else if (bytesRead == 0) } else if (bytesRead == 0)
receiveEnd = true; receiveEnd = true;
fInputBuffer.AppendData(chunk.Data(), bytesRead); fInputBuffer.AppendData(chunk.Data(), bytesRead);
} }
else else
bytesRead = 0; bytesRead = 0;
if (!fStatusReceived) { if (!fStatusReceived) {
_ParseStatus(); _ParseStatus();
//! ProtocolHook:ResponseStarted //! ProtocolHook:ResponseStarted
if (fStatusReceived && fListener != NULL) if (fStatusReceived && fListener != NULL)
fListener->ResponseStarted(this); fListener->ResponseStarted(this);
} else if (!fHeadersReceived) { } else if (!fHeadersReceived) {
_ParseHeaders(); _ParseHeaders();
if (fHeadersReceived) { if (fHeadersReceived) {
receiveBufferSize = kHttpProtocolReceiveBufferSize; receiveBufferSize = kHttpProtocolReceiveBufferSize;
_ResultHeaders() = fHeaders; _ResultHeaders() = fHeaders;
//! ProtocolHook:HeadersReceived //! ProtocolHook:HeadersReceived
if (fListener != NULL) if (fListener != NULL)
fListener->HeadersReceived(this); fListener->HeadersReceived(this);
@@ -516,10 +510,10 @@ BUrlProtocolHttp::_MakeRequest()
} }
} }
} }
if (BString(fHeaders["Transfer-Encoding"]) == "chunked") if (BString(fHeaders["Transfer-Encoding"]) == "chunked")
readByChunks = true; readByChunks = true;
int32 index = fHeaders.HasHeader("Content-Length"); int32 index = fHeaders.HasHeader("Content-Length");
if (index != B_ERROR) if (index != B_ERROR)
bytesTotal = atoi(fHeaders.HeaderAt(index).Value()); bytesTotal = atoi(fHeaders.HeaderAt(index).Value());
@@ -531,7 +525,7 @@ BUrlProtocolHttp::_MakeRequest()
// chunk in buffer before handling it // chunk in buffer before handling it
if (readByChunks) { if (readByChunks) {
_CopyChunkInBuffer(&inputTempBuffer, &bytesRead); _CopyChunkInBuffer(&inputTempBuffer, &bytesRead);
// A chunk of 0 bytes indicates the end of the chunked transfer // A chunk of 0 bytes indicates the end of the chunked transfer
if (bytesRead == 0) { if (bytesRead == 0) {
receiveEnd = true; receiveEnd = true;
@@ -539,50 +533,50 @@ BUrlProtocolHttp::_MakeRequest()
} }
else { else {
bytesRead = fInputBuffer.Size(); bytesRead = fInputBuffer.Size();
if (bytesRead > 0) { if (bytesRead > 0) {
inputTempBuffer = new char[bytesRead]; inputTempBuffer = new char[bytesRead];
fInputBuffer.RemoveData(inputTempBuffer, bytesRead); fInputBuffer.RemoveData(inputTempBuffer, bytesRead);
} }
} }
if (bytesRead > 0) { if (bytesRead > 0) {
bytesReceived += bytesRead; bytesReceived += bytesRead;
_EmitDebug(B_URL_PROTOCOL_DEBUG_TRANSFER_IN, "%d bytes", _EmitDebug(B_URL_PROTOCOL_DEBUG_TRANSFER_IN, "%d bytes",
bytesRead); bytesRead);
if (fListener != NULL) { if (fListener != NULL) {
fListener->DataReceived(this, inputTempBuffer, bytesRead); fListener->DataReceived(this, inputTempBuffer, bytesRead);
fListener->DownloadProgress(this, bytesReceived, fListener->DownloadProgress(this, bytesReceived,
bytesTotal); bytesTotal);
} }
ssize_t dataWrite = _ResultRawData().Write(inputTempBuffer, ssize_t dataWrite = _ResultRawData().Write(inputTempBuffer,
bytesRead); bytesRead);
if (dataWrite != bytesRead) { if (dataWrite != bytesRead) {
_EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR, _EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR,
"Unable to write %dbytes of data (%d).", bytesRead, "Unable to write %dbytes of data (%d).", bytesRead,
dataWrite); dataWrite);
return B_PROT_NO_MEMORY; return B_PROT_NO_MEMORY;
} }
if (bytesTotal > 0 && bytesReceived >= bytesTotal) if (bytesTotal > 0 && bytesReceived >= bytesTotal)
receiveEnd = true; receiveEnd = true;
delete[] inputTempBuffer; delete[] inputTempBuffer;
} }
} }
parseEnd = (fInputBuffer.Size() == 0); parseEnd = (fInputBuffer.Size() == 0);
} }
fSocket->Disconnect(); fSocket->Disconnect();
if (readError) if (readError)
return B_PROT_READ_FAILED; return B_PROT_READ_FAILED;
return fQuit?B_PROT_ABORTED:B_PROT_SUCCESS; return fQuit ? B_PROT_ABORTED : B_PROT_SUCCESS;
} }
@@ -591,23 +585,23 @@ BUrlProtocolHttp::_GetLine(BString& destString)
{ {
// Find a complete line in inputBuffer // Find a complete line in inputBuffer
uint32 characterIndex = 0; uint32 characterIndex = 0;
while ((characterIndex < fInputBuffer.Size()) while ((characterIndex < fInputBuffer.Size())
&& ((fInputBuffer.Data())[characterIndex] != '\n')) && ((fInputBuffer.Data())[characterIndex] != '\n'))
characterIndex++; characterIndex++;
if (characterIndex == fInputBuffer.Size()) if (characterIndex == fInputBuffer.Size())
return B_ERROR; return B_ERROR;
char* temporaryBuffer = new(std::nothrow) char[characterIndex + 1]; char* temporaryBuffer = new(std::nothrow) char[characterIndex + 1];
fInputBuffer.RemoveData(temporaryBuffer, characterIndex + 1); fInputBuffer.RemoveData(temporaryBuffer, characterIndex + 1);
// Strip end-of-line character(s) // Strip end-of-line character(s)
if (temporaryBuffer[characterIndex-1] == '\r') if (temporaryBuffer[characterIndex-1] == '\r')
destString.SetTo(temporaryBuffer, characterIndex - 1); destString.SetTo(temporaryBuffer, characterIndex - 1);
else else
destString.SetTo(temporaryBuffer, characterIndex); destString.SetTo(temporaryBuffer, characterIndex);
delete[] temporaryBuffer; delete[] temporaryBuffer;
return B_OK; return B_OK;
} }
@@ -624,19 +618,19 @@ BUrlProtocolHttp::_ParseStatus()
BString statusLine; BString statusLine;
if (_GetLine(statusLine) == B_ERROR) if (_GetLine(statusLine) == B_ERROR)
return; return;
if (statusLine.CountChars() < 12) if (statusLine.CountChars() < 12)
return; return;
fStatusReceived = true; fStatusReceived = true;
BString statusCodeStr; BString statusCodeStr;
BString statusText; BString statusText;
statusLine.CopyInto(statusCodeStr, 9, 3); statusLine.CopyInto(statusCodeStr, 9, 3);
_SetResultStatusCode(atoi(statusCodeStr.String())); _SetResultStatusCode(atoi(statusCodeStr.String()));
statusLine.CopyInto(_ResultStatusText(), 13, statusLine.Length() - 13); statusLine.CopyInto(_ResultStatusText(), 13, statusLine.Length() - 13);
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Status line received: Code %d (%s)", _EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Status line received: Code %d (%s)",
atoi(statusCodeStr.String()), _ResultStatusText().String()); atoi(statusCodeStr.String()), _ResultStatusText().String());
} }
@@ -648,14 +642,14 @@ BUrlProtocolHttp::_ParseHeaders()
BString currentHeader; BString currentHeader;
if (_GetLine(currentHeader) == B_ERROR) if (_GetLine(currentHeader) == B_ERROR)
return; return;
// Empty line // Empty line
if (currentHeader.Length() == 0) { if (currentHeader.Length() == 0) {
fHeadersReceived = true; fHeadersReceived = true;
return; return;
} }
_EmitDebug(B_URL_PROTOCOL_DEBUG_HEADER_IN, "%s", currentHeader.String()); _EmitDebug(B_URL_PROTOCOL_DEBUG_HEADER_IN, "%s", currentHeader.String());
fHeaders.AddHeader(currentHeader.String()); fHeaders.AddHeader(currentHeader.String());
} }
@@ -665,7 +659,7 @@ BUrlProtocolHttp::_CopyChunkInBuffer(char** buffer, ssize_t* bytesReceived)
{ {
static ssize_t chunkSize = -1; static ssize_t chunkSize = -1;
BString chunkHeader; BString chunkHeader;
if (chunkSize >= 0) { if (chunkSize >= 0) {
if ((ssize_t)fInputBuffer.Size() >= chunkSize + 2) { if ((ssize_t)fInputBuffer.Size() >= chunkSize + 2) {
// 2 more bytes to handle the closing CR+LF // 2 more bytes to handle the closing CR+LF
@@ -684,22 +678,22 @@ BUrlProtocolHttp::_CopyChunkInBuffer(char** buffer, ssize_t* bytesReceived)
*bytesReceived = -1; *bytesReceived = -1;
return; return;
} }
// Format of a chunk header: // Format of a chunk header:
// <chunk size in hex>[; optional data] // <chunk size in hex>[; optional data]
int32 semiColonIndex = chunkHeader.FindFirst(";", 0); int32 semiColonIndex = chunkHeader.FindFirst(";", 0);
// Cut-off optional data if present // Cut-off optional data if present
if (semiColonIndex != -1) if (semiColonIndex != -1)
chunkHeader.Remove(semiColonIndex, chunkHeader.Remove(semiColonIndex,
chunkHeader.Length() - semiColonIndex); chunkHeader.Length() - semiColonIndex);
chunkSize = strtol(chunkHeader.String(), NULL, 16); chunkSize = strtol(chunkHeader.String(), NULL, 16);
PRINT(("BHP[%p] Chunk %s=%ld\n", this, chunkHeader.String(), chunkSize)); PRINT(("BHP[%p] Chunk %s=%ld\n", this, chunkHeader.String(), chunkSize));
if (chunkSize == 0) { if (chunkSize == 0) {
fContentReceived = true; fContentReceived = true;
} }
*bytesReceived = -1; *bytesReceived = -1;
*buffer = NULL; *buffer = NULL;
} }
@@ -710,46 +704,46 @@ void
BUrlProtocolHttp::_CreateRequest() BUrlProtocolHttp::_CreateRequest()
{ {
BString request; BString request;
switch (fRequestMethod) { switch (fRequestMethod) {
case B_HTTP_POST: case B_HTTP_POST:
request << "POST"; request << "POST";
break; break;
case B_HTTP_PUT: case B_HTTP_PUT:
request << "PUT"; request << "PUT";
break; break;
default: default:
case B_HTTP_GET: case B_HTTP_GET:
request << "GET"; request << "GET";
break; break;
} }
if (Url().HasPath()) if (Url().HasPath())
request << ' ' << Url().Path(); request << ' ' << Url().Path();
else else
request << " /"; request << " /";
if (Url().HasRequest()) if (Url().HasRequest())
request << '?' << Url().Request(); request << '?' << Url().Request();
if (Url().HasFragment()) if (Url().HasFragment())
request << '#' << Url().Fragment(); request << '#' << Url().Fragment();
request << ' '; request << ' ';
switch (fHttpVersion) { switch (fHttpVersion) {
case B_HTTP_11: case B_HTTP_11:
request << "HTTP/1.1"; request << "HTTP/1.1";
break; break;
default: default:
case B_HTTP_10: case B_HTTP_10:
request << "HTTP/1.0"; request << "HTTP/1.0";
break; break;
} }
_AddOutputBufferLine(request.String()); _AddOutputBufferLine(request.String());
} }
@@ -760,93 +754,77 @@ BUrlProtocolHttp::_AddHeaders()
// HTTP 1.1 additional headers // HTTP 1.1 additional headers
if (fHttpVersion == B_HTTP_11) { if (fHttpVersion == B_HTTP_11) {
fOutputHeaders.AddHeader("Host", Url().Host()); fOutputHeaders.AddHeader("Host", Url().Host());
fOutputHeaders.AddHeader("Accept", "*/*"); fOutputHeaders.AddHeader("Accept", "*/*");
fOutputHeaders.AddHeader("Accept-Encoding", "chunked"); fOutputHeaders.AddHeader("Accept-Encoding", "chunked");
// Allow the remote server to send dynamic content by chunks // Allow the remote server to send dynamic content by chunks
// rather than waiting for the full content to be generated and // rather than waiting for the full content to be generated and
// sending us data. // sending us data.
fOutputHeaders.AddHeader("Connection", "close"); fOutputHeaders.AddHeader("Connection", "close");
// Let the remote server close the connection after response since // Let the remote server close the connection after response since
// we don't handle multiple request on a single connection // we don't handle multiple request on a single connection
} }
// Classic HTTP headers // Classic HTTP headers
if (fOptUserAgent.CountChars() > 0) if (fOptUserAgent.CountChars() > 0)
fOutputHeaders.AddHeader("User-Agent", fOptUserAgent.String()); fOutputHeaders.AddHeader("User-Agent", fOptUserAgent.String());
if (fOptReferer.CountChars() > 0) if (fOptReferer.CountChars() > 0)
fOutputHeaders.AddHeader("Referer", fOptReferer.String()); fOutputHeaders.AddHeader("Referer", fOptReferer.String());
// Authentication // Authentication
if (fAuthentication.Method() != B_HTTP_AUTHENTICATION_NONE) { if (fAuthentication.Method() != B_HTTP_AUTHENTICATION_NONE) {
BString request; BString request;
switch (fRequestMethod) { switch (fRequestMethod) {
case B_HTTP_POST: case B_HTTP_POST:
request = "POST"; request = "POST";
break; break;
case B_HTTP_PUT: case B_HTTP_PUT:
request = "PUT"; request = "PUT";
break; break;
default: default:
case B_HTTP_GET: case B_HTTP_GET:
request = "GET"; request = "GET";
break; break;
} }
fOutputHeaders.AddHeader("Authorization", fOutputHeaders.AddHeader("Authorization",
fAuthentication.Authorization(fUrl, request)); fAuthentication.Authorization(fUrl, request));
} }
// Required headers for POST data // Required headers for POST data
if (fOptPostFields != NULL && fRequestMethod == B_HTTP_POST) { if (fOptPostFields != NULL && fRequestMethod == B_HTTP_POST) {
BString contentType; BString contentType;
switch (fOptPostFields->GetFormType()) { switch (fOptPostFields->GetFormType()) {
case B_HTTP_FORM_MULTIPART: case B_HTTP_FORM_MULTIPART:
contentType << "multipart/form-data; boundary=" contentType << "multipart/form-data; boundary="
<< fOptPostFields->GetMultipartBoundary() << ""; << fOptPostFields->GetMultipartBoundary() << "";
break; break;
case B_HTTP_FORM_URL_ENCODED: case B_HTTP_FORM_URL_ENCODED:
contentType << "application/x-www-form-urlencoded"; contentType << "application/x-www-form-urlencoded";
break; break;
} }
fOutputHeaders.AddHeader("Content-Type", contentType); fOutputHeaders.AddHeader("Content-Type", contentType);
fOutputHeaders.AddHeader("Content-Length", fOutputHeaders.AddHeader("Content-Length",
fOptPostFields->ContentLength()); fOptPostFields->ContentLength());
} else if (fOptInputData != NULL } else if (fOptInputData != NULL
&& (fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT)) && (fRequestMethod == B_HTTP_POST || fRequestMethod == B_HTTP_PUT))
fOutputHeaders.AddHeader("Transfer-Encoding", "chunked"); fOutputHeaders.AddHeader("Transfer-Encoding", "chunked");
// Request headers
for (int32 headerIndex = 0;
headerIndex < fRequestHeaders.CountHeaders();
headerIndex++) {
BHttpHeader& optHeader = fRequestHeaders[headerIndex];
int32 replaceIndex = fOutputHeaders.HasHeader(optHeader.Name());
// Add or replace the current option header to the
// output header list
if (replaceIndex == -1)
fOutputHeaders.AddHeader(optHeader.Name(), optHeader.Value());
else
fOutputHeaders[replaceIndex].SetValue(optHeader.Value());
}
// Optional headers specified by the user // Optional headers specified by the user
if (fOptHeaders != NULL) { if (fOptHeaders != NULL) {
for (int32 headerIndex = 0; for (int32 headerIndex = 0; headerIndex < fOptHeaders->CountHeaders();
headerIndex < fOptHeaders->CountHeaders(); headerIndex++) {
headerIndex++) {
BHttpHeader& optHeader = (*fOptHeaders)[headerIndex]; BHttpHeader& optHeader = (*fOptHeaders)[headerIndex];
int32 replaceIndex = fOutputHeaders.HasHeader(optHeader.Name()); int32 replaceIndex = fOutputHeaders.HasHeader(optHeader.Name());
// Add or replace the current option header to the // Add or replace the current option header to the
// output header list // output header list
if (replaceIndex == -1) if (replaceIndex == -1)
fOutputHeaders.AddHeader(optHeader.Name(), optHeader.Value()); fOutputHeaders.AddHeader(optHeader.Name(), optHeader.Value());
@@ -854,22 +832,20 @@ BUrlProtocolHttp::_AddHeaders()
fOutputHeaders[replaceIndex].SetValue(optHeader.Value()); fOutputHeaders[replaceIndex].SetValue(optHeader.Value());
} }
} }
// Context cookies // Context cookies
if (fOptSetCookies && (fContext != NULL)) { if (fOptSetCookies && (fContext != NULL)) {
BNetworkCookie* cookie; BNetworkCookie* cookie;
for (BNetworkCookieJar::UrlIterator for (BNetworkCookieJar::UrlIterator it
it(fContext->GetCookieJar().GetUrlIterator(fUrl)); = fContext->GetCookieJar().GetUrlIterator(fUrl);
(cookie = it.Next()) != NULL; (cookie = it.Next()) != NULL;)
) fOutputHeaders.AddHeader("Cookie", cookie->RawCookie(false));
fOutputHeaders.AddHeader("Cookie", cookie->RawCookie(false));
} }
// Write output headers to output stream // Write output headers to output stream
for (int32 headerIndex = 0; for (int32 headerIndex = 0; headerIndex < fOutputHeaders.CountHeaders();
headerIndex < fOutputHeaders.CountHeaders(); headerIndex++)
headerIndex++)
_AddOutputBufferLine(fOutputHeaders.HeaderAt(headerIndex).Header()); _AddOutputBufferLine(fOutputHeaders.HeaderAt(headerIndex).Header());
} }
+56 -67
View File
@@ -13,27 +13,15 @@
#include <Debug.h> #include <Debug.h>
BUrlRequest::BUrlRequest(const BUrl& url, BUrlProtocolListener* listener) BUrlRequest::BUrlRequest(const BUrl& url, BUrlProtocolListener* listener,
: BUrlContext* context)
:
fListener(listener), fListener(listener),
fUrlProtocol(NULL), fUrlProtocol(NULL),
fResult(url), fResult(url),
fContext(), fContext(context),
fUrl(), fUrl(),
fReady(false) fInitStatus(B_ERROR)
{
SetUrl(url);
}
BUrlRequest::BUrlRequest(const BUrl& url)
:
fListener(NULL),
fUrlProtocol(NULL),
fResult(url),
fContext(),
fUrl(),
fReady(false)
{ {
SetUrl(url); SetUrl(url);
} }
@@ -46,12 +34,18 @@ BUrlRequest::BUrlRequest(const BUrlRequest& other)
fResult(other.fUrl), fResult(other.fUrl),
fContext(), fContext(),
fUrl(), fUrl(),
fReady(false) fInitStatus(B_ERROR)
{ {
*this = other; *this = other;
} }
BUrlRequest::~BUrlRequest()
{
if (fUrlProtocol != NULL)
delete fUrlProtocol;
}
// #pragma mark Request parameters modification // #pragma mark Request parameters modification
@@ -60,16 +54,14 @@ BUrlRequest::SetUrl(const BUrl& url)
{ {
fUrl = url; fUrl = url;
fResult.SetUrl(url); fResult.SetUrl(url);
if (fUrlProtocol != NULL && url.Protocol() == fUrl.Protocol()) if (fUrlProtocol != NULL && url.Protocol() == fUrl.Protocol()) {
fUrlProtocol->SetUrl(url); fUrlProtocol->SetUrl(url);
else { return B_OK;
status_t err = Identify();
if (err != B_OK)
return err;
} }
return B_OK; fInitStatus = _SetupProtocol();
return fInitStatus;
} }
@@ -84,7 +76,7 @@ void
BUrlRequest::SetProtocolListener(BUrlProtocolListener* listener) BUrlRequest::SetProtocolListener(BUrlProtocolListener* listener)
{ {
fListener = listener; fListener = listener;
if (fUrlProtocol != NULL) if (fUrlProtocol != NULL)
fUrlProtocol->SetListener(listener); fUrlProtocol->SetListener(listener);
} }
@@ -95,7 +87,7 @@ BUrlRequest::SetProtocolOption(int32 option, void* value)
{ {
if (fUrlProtocol == NULL) if (fUrlProtocol == NULL)
return false; return false;
fUrlProtocol->SetOption(option, value); fUrlProtocol->SetOption(option, value);
return true; return true;
} }
@@ -129,44 +121,18 @@ BUrlRequest::Url()
status_t status_t
BUrlRequest::Identify() BUrlRequest::Start()
{
// TODO: instanciate the correct BUrlProtocol w/ the services roster
delete fUrlProtocol;
fUrlProtocol = NULL;
if (fUrl.Protocol() == "http") {
fUrlProtocol = new(std::nothrow) BUrlProtocolHttp(fUrl, false, "HTTP",
fListener, fContext,
&fResult);
fReady = true;
return B_OK;
} else if (fUrl.Protocol() == "https") {
fUrlProtocol = new(std::nothrow) BUrlProtocolHttp(fUrl, true, "HTTPS",
fListener, fContext,
&fResult);
fReady = true;
return B_OK;
}
fReady = false;
return B_NO_HANDLER_FOR_PROTOCOL;
}
status_t
BUrlRequest::Perform()
{ {
if (fUrlProtocol == NULL) { if (fUrlProtocol == NULL) {
PRINT(("BUrlRequest::Perform() : Oops, no BUrlProtocol defined!\n")); PRINT(("BUrlRequest::Perform() : Oops, no BUrlProtocol defined!\n"));
return B_ERROR; return B_ERROR;
} }
thread_id protocolThread = fUrlProtocol->Run(); thread_id protocolThread = fUrlProtocol->Run();
if (protocolThread < B_OK) if (protocolThread < B_OK)
return protocolThread; return protocolThread;
return B_OK; return B_OK;
} }
@@ -176,7 +142,7 @@ BUrlRequest::Pause()
{ {
if (fUrlProtocol == NULL) if (fUrlProtocol == NULL)
return B_ERROR; return B_ERROR;
return fUrlProtocol->Pause(); return fUrlProtocol->Pause();
} }
@@ -186,7 +152,7 @@ BUrlRequest::Resume()
{ {
if (fUrlProtocol == NULL) if (fUrlProtocol == NULL)
return B_ERROR; return B_ERROR;
return fUrlProtocol->Resume(); return fUrlProtocol->Resume();
} }
@@ -196,11 +162,11 @@ BUrlRequest::Abort()
{ {
if (fUrlProtocol == NULL) if (fUrlProtocol == NULL)
return B_ERROR; return B_ERROR;
status_t returnCode = fUrlProtocol->Stop(); status_t returnCode = fUrlProtocol->Stop();
delete fUrlProtocol; delete fUrlProtocol;
fUrlProtocol = NULL; fUrlProtocol = NULL;
return returnCode; return returnCode;
} }
@@ -208,10 +174,10 @@ BUrlRequest::Abort()
// #pragma mark Request informations // #pragma mark Request informations
bool status_t
BUrlRequest::InitCheck() const BUrlRequest::InitCheck() const
{ {
return fReady; return fInitStatus;
} }
@@ -220,7 +186,7 @@ BUrlRequest::IsRunning() const
{ {
if (fUrlProtocol == NULL) if (fUrlProtocol == NULL)
return false; return false;
return fUrlProtocol->IsRunning(); return fUrlProtocol->IsRunning();
} }
@@ -230,7 +196,7 @@ BUrlRequest::Status() const
{ {
if (fUrlProtocol == NULL) if (fUrlProtocol == NULL)
return B_ERROR; return B_ERROR;
return fUrlProtocol->Status(); return fUrlProtocol->Status();
} }
@@ -248,6 +214,29 @@ BUrlRequest::operator=(const BUrlRequest& other)
fContext = other.fContext; fContext = other.fContext;
fResult = BUrlResult(other.fUrl); fResult = BUrlResult(other.fUrl);
SetUrl(other.fUrl); SetUrl(other.fUrl);
return *this; return *this;
} }
status_t
BUrlRequest::_SetupProtocol()
{
// TODO: instanciate the correct BUrlProtocol w/ the services roster
delete fUrlProtocol;
fUrlProtocol = NULL;
if (fUrl.Protocol() == "http")
fUrlProtocol = new(std::nothrow) BUrlProtocolHttp(fUrl, false, "HTTP",
fListener, fContext, &fResult);
else if (fUrl.Protocol() == "https")
fUrlProtocol = new(std::nothrow) BUrlProtocolHttp(fUrl, true, "HTTPS",
fListener, fContext, &fResult);
else
return B_NO_HANDLER_FOR_PROTOCOL;
if (fUrlProtocol == NULL)
return B_NO_MEMORY;
return B_OK;
}
@@ -14,7 +14,7 @@
BUrlSynchronousRequest::BUrlSynchronousRequest(BUrl& url) BUrlSynchronousRequest::BUrlSynchronousRequest(BUrl& url)
: :
BUrlRequest(url, this), BUrlRequest(url, this),
fRequestComplete(false) fRequestComplete(false)
{ {
@@ -26,8 +26,8 @@ BUrlSynchronousRequest::Perform()
{ {
SetProtocolListener(this); SetProtocolListener(this);
fRequestComplete = false; fRequestComplete = false;
return BUrlRequest::Perform(); return Start();
} }
@@ -36,7 +36,7 @@ BUrlSynchronousRequest::WaitUntilCompletion()
{ {
while (!fRequestComplete) while (!fRequestComplete)
snooze(10000); snooze(10000);
return B_OK; return B_OK;
} }
@@ -70,7 +70,7 @@ BUrlSynchronousRequest::HeadersReceived(BUrlProtocol*)
void void
BUrlSynchronousRequest::DataReceived(BUrlProtocol*, const char*, BUrlSynchronousRequest::DataReceived(BUrlProtocol*, const char*,
ssize_t size) ssize_t size)
{ {
PRINT(("SynchronousRequest::DataReceived(%zd)\n", size)); PRINT(("SynchronousRequest::DataReceived(%zd)\n", size));
@@ -78,7 +78,7 @@ BUrlSynchronousRequest::DataReceived(BUrlProtocol*, const char*,
void void
BUrlSynchronousRequest::DownloadProgress(BUrlProtocol*, BUrlSynchronousRequest::DownloadProgress(BUrlProtocol*,
ssize_t bytesReceived, ssize_t bytesTotal) ssize_t bytesReceived, ssize_t bytesTotal)
{ {
PRINT(("SynchronousRequest::DownloadProgress(%zd, %zd)\n", bytesReceived, PRINT(("SynchronousRequest::DownloadProgress(%zd, %zd)\n", bytesReceived,
@@ -98,7 +98,7 @@ BUrlSynchronousRequest::UploadProgress(BUrlProtocol*, ssize_t bytesSent,
void void
BUrlSynchronousRequest::RequestCompleted(BUrlProtocol* caller, bool success) BUrlSynchronousRequest::RequestCompleted(BUrlProtocol* caller, bool success)
{ {
PRINT(("SynchronousRequest::RequestCompleted(%s) : %s\n", (success?"true":"false"), PRINT(("SynchronousRequest::RequestCompleted(%s) : %s\n", (success?"true":"false"),
caller->StatusString(caller->Status()))); caller->StatusString(caller->Status())));
fRequestComplete = true; fRequestComplete = true;
} }
+206 -10
View File
@@ -20,7 +20,10 @@
#include <Font.h> #include <Font.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <GroupView.h> #include <GroupView.h>
#include <InterfaceDefs.h>
#include <LayoutBuilder.h> #include <LayoutBuilder.h>
#include <Message.h>
#include <MessageFilter.h>
#include <Point.h> #include <Point.h>
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
@@ -42,6 +45,46 @@ using BPrivate::gSystemCatalog;
#define B_TRANSLATION_CONTEXT "AboutWindow" #define B_TRANSLATION_CONTEXT "AboutWindow"
class EscapeFilter : public BMessageFilter {
public:
EscapeFilter(BWindow* target)
:
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
fTarget(target)
{
}
virtual ~EscapeFilter()
{
}
virtual filter_result
Filter(BMessage* message, BHandler** target)
{
filter_result result = B_DISPATCH_MESSAGE;
switch (message->what) {
case B_KEY_DOWN:
case B_UNMAPPED_KEY_DOWN: {
uint32 key;
if (message->FindInt32("raw_char",
(int32*)&key) >= B_OK) {
if (key == B_ESCAPE) {
result = B_SKIP_MESSAGE;
fTarget->PostMessage(
B_QUIT_REQUESTED);
}
}
break;
}
default:
break;
}
return result;
}
private:
BWindow* fTarget;
};
class StripeView : public BView { class StripeView : public BView {
public: public:
StripeView(BBitmap* icon); StripeView(BBitmap* icon);
@@ -49,6 +92,9 @@ class StripeView : public BView {
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
BBitmap* Icon() const { return fIcon; };
void SetIcon(BBitmap* icon);
private: private:
BBitmap* fIcon; BBitmap* fIcon;
}; };
@@ -62,14 +108,24 @@ class AboutView : public BGroupView {
BTextView* InfoView() const { return fInfoView; }; BTextView* InfoView() const { return fInfoView; };
BBitmap* Icon();
status_t SetIcon(BBitmap* icon);
const char* Name();
status_t SetName(const char* name);
const char* Version();
status_t SetVersion(const char* version);
protected: protected:
const char* AppVersion(const char* signature); const char* _GetVersionFromSignature(const char* signature);
BBitmap* AppIcon(const char* signature); BBitmap* _GetIconFromSignature(const char* signature);
private: private:
BStringView* fNameView; BStringView* fNameView;
BStringView* fVersionView; BStringView* fVersionView;
BTextView* fInfoView; BTextView* fInfoView;
StripeView* fStripeView;
}; };
@@ -81,13 +137,14 @@ StripeView::StripeView(BBitmap* icon)
BView("StripeView", B_WILL_DRAW), BView("StripeView", B_WILL_DRAW),
fIcon(icon) fIcon(icon)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
float width = 0.0f; float width = 0.0f;
if (icon != NULL) if (icon != NULL)
width += icon->Bounds().Width() + 32.0f; width += icon->Bounds().Width() + 32.0f;
SetExplicitMinSize(BSize(width, B_SIZE_UNSET)); SetExplicitMinSize(BSize(width, B_SIZE_UNSET));
SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED)); SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED));
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
} }
@@ -116,7 +173,24 @@ StripeView::Draw(BRect updateRect)
} }
// #pragma mark - void
StripeView::SetIcon(BBitmap* icon)
{
if (fIcon != NULL)
delete fIcon;
fIcon = icon;
float width = 0.0f;
if (icon != NULL)
width += icon->Bounds().Width() + 32.0f;
SetExplicitMinSize(BSize(width, B_SIZE_UNSET));
SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED));
};
// #pragma mark - AboutView
AboutView::AboutView(const char* appName, const char* signature) AboutView::AboutView(const char* appName, const char* signature)
@@ -131,7 +205,8 @@ AboutView::AboutView(const char* appName, const char* signature)
fNameView->SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE fNameView->SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE
| B_FONT_FLAGS); | B_FONT_FLAGS);
fVersionView = new BStringView("version", AppVersion(signature)); fVersionView = new BStringView("version",
_GetVersionFromSignature(signature));
fInfoView = new BTextView("info", B_WILL_DRAW); fInfoView = new BTextView("info", B_WILL_DRAW);
fInfoView->SetExplicitMinSize(BSize(210.0, 160.0)); fInfoView->SetExplicitMinSize(BSize(210.0, 160.0));
@@ -145,10 +220,12 @@ AboutView::AboutView(const char* appName, const char* signature)
"infoViewScroller", fInfoView, B_WILL_DRAW | B_FRAME_EVENTS, "infoViewScroller", fInfoView, B_WILL_DRAW | B_FRAME_EVENTS,
false, true, B_PLAIN_BORDER); false, true, B_PLAIN_BORDER);
fStripeView = new StripeView(_GetIconFromSignature(signature));
GroupLayout()->SetSpacing(0); GroupLayout()->SetSpacing(0);
BLayoutBuilder::Group<>(this) BLayoutBuilder::Group<>(this)
.AddGroup(B_HORIZONTAL, 0) .AddGroup(B_HORIZONTAL, 0)
.Add(new StripeView(AppIcon(signature))) .Add(fStripeView)
.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING) .AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
.SetInsets(0, B_USE_DEFAULT_SPACING, .SetInsets(0, B_USE_DEFAULT_SPACING,
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
@@ -166,8 +243,11 @@ AboutView::~AboutView()
} }
// #pragma mark - AboutView protected methods
const char* const char*
AboutView::AppVersion(const char* signature) AboutView::_GetVersionFromSignature(const char* signature)
{ {
if (signature == NULL) if (signature == NULL)
return NULL; return NULL;
@@ -228,7 +308,7 @@ AboutView::AppVersion(const char* signature)
BBitmap* BBitmap*
AboutView::AppIcon(const char* signature) AboutView::_GetIconFromSignature(const char* signature)
{ {
if (signature == NULL) if (signature == NULL)
return NULL; return NULL;
@@ -251,7 +331,64 @@ AboutView::AppIcon(const char* signature)
} }
// #pragma mark - // #pragma mark - AboutView public methods
const char*
AboutView::Name()
{
return fNameView->Text();
}
status_t
AboutView::SetName(const char* name)
{
fNameView->SetText(name);
return B_OK;
}
const char*
AboutView::Version()
{
return fVersionView->Text();
}
status_t
AboutView::SetVersion(const char* version)
{
fVersionView->SetText(version);
return B_OK;
}
BBitmap*
AboutView::Icon()
{
if (fStripeView == NULL)
return NULL;
return fStripeView->Icon();
}
status_t
AboutView::SetIcon(BBitmap* icon)
{
if (fStripeView == NULL)
return B_NO_INIT;
fStripeView->SetIcon(icon);
return B_OK;
}
// #pragma mark - BAboutWindow
BAboutWindow::BAboutWindow(const char* appName, const char* signature) BAboutWindow::BAboutWindow(const char* appName, const char* signature)
@@ -272,6 +409,8 @@ BAboutWindow::BAboutWindow(const char* appName, const char* signature)
AddChild(fAboutView); AddChild(fAboutView);
MoveTo(AboutPosition(Frame().Width(), Frame().Height())); MoveTo(AboutPosition(Frame().Width(), Frame().Height()));
AddCommonFilter(new EscapeFilter(this));
} }
@@ -283,6 +422,9 @@ BAboutWindow::~BAboutWindow()
} }
// #pragma mark - BAboutWindow virtual methods
bool bool
BAboutWindow::QuitRequested() BAboutWindow::QuitRequested()
{ {
@@ -292,7 +434,19 @@ BAboutWindow::QuitRequested()
} }
// #pragma mark - void
BAboutWindow::Show()
{
if (IsHidden()) {
// move to current workspace
SetWorkspaces(B_CURRENT_WORKSPACE);
}
BWindow::Show();
}
// #pragma mark - BAboutWindow public methods
BPoint BPoint
@@ -463,3 +617,45 @@ BAboutWindow::AddExtraInfo(const char* extraInfo)
fAboutView->InfoView()->Insert(extra.String()); fAboutView->InfoView()->Insert(extra.String());
} }
const char*
BAboutWindow::Name()
{
return fAboutView->Name();
}
void
BAboutWindow::SetName(const char* name)
{
fAboutView->SetName(name);
}
const char*
BAboutWindow::Version()
{
return fAboutView->Version();
}
void
BAboutWindow::SetVersion(const char* version)
{
fAboutView->SetVersion(version);
}
BBitmap*
BAboutWindow::Icon()
{
return fAboutView->Icon();
}
void
BAboutWindow::SetIcon(BBitmap* icon)
{
fAboutView->SetIcon(icon);
}
+7 -1
View File
@@ -70,11 +70,11 @@ const uint32 kRevertButtonPressed = 'Rebp';
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "TrackerSettingsWindow" #define B_TRANSLATION_CONTEXT "TrackerSettingsWindow"
TrackerSettingsWindow::TrackerSettingsWindow() TrackerSettingsWindow::TrackerSettingsWindow()
: :
BWindow(BRect(80, 80, 450, 350), B_TRANSLATE("Tracker preferences"), BWindow(BRect(80, 80, 450, 350), B_TRANSLATE("Tracker preferences"),
B_TITLED_WINDOW, B_NOT_MINIMIZABLE | B_NOT_RESIZABLE B_TITLED_WINDOW, B_NOT_MINIMIZABLE | B_NOT_RESIZABLE
| B_NO_WORKSPACE_ACTIVATION | B_NOT_ANCHORED_ON_ACTIVATE
| B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS) | B_AUTO_UPDATE_SIZE_LIMITS)
{ {
@@ -184,6 +184,12 @@ TrackerSettingsWindow::Show()
Unlock(); Unlock();
} }
if (IsHidden()) {
// move to current workspace
SetWorkspaces(B_CURRENT_WORKSPACE);
}
_inherited::Show(); _inherited::Show();
} }