Fixed a couple problems like off-by-one errors, wrong error checks. Implemented Save() method, not tested
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16289 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -118,6 +118,7 @@ _rep_data_::_rep_data_()
|
|||||||
fDragger(NULL),
|
fDragger(NULL),
|
||||||
fRelation(BDragger::TARGET_UNKNOWN),
|
fRelation(BDragger::TARGET_UNKNOWN),
|
||||||
fId(0),
|
fId(0),
|
||||||
|
fImage(-1),
|
||||||
fError(B_ERROR),
|
fError(B_ERROR),
|
||||||
fZombieView(NULL)
|
fZombieView(NULL)
|
||||||
{
|
{
|
||||||
@@ -193,12 +194,13 @@ _rep_data_::index_of(BList const *list, BView const *view, bool allowZombie)
|
|||||||
{
|
{
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
_rep_data_ *item;
|
_rep_data_ *item;
|
||||||
while ((item = (_rep_data_*)list->ItemAt(i++)) != NULL) {
|
while ((item = (_rep_data_*)list->ItemAt(i)) != NULL) {
|
||||||
if (item->fView == view)
|
if (item->fView == view)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
if (allowZombie && item->fZombieView == view)
|
if (allowZombie && item->fZombieView == view)
|
||||||
return i;
|
return i;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@@ -211,9 +213,10 @@ _rep_data_::index_of(BList const *list, unsigned long id)
|
|||||||
{
|
{
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
_rep_data_ *item;
|
_rep_data_ *item;
|
||||||
while ((item = (_rep_data_*)list->ItemAt(i++)) != NULL) {
|
while ((item = (_rep_data_*)list->ItemAt(i)) != NULL) {
|
||||||
if (item->fId == id)
|
if (item->fId == id)
|
||||||
return i;
|
return i;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@@ -276,9 +279,8 @@ _TContainerViewFilter_::ObjectDropFilter(BMessage *msg, BHandler **_handler)
|
|||||||
point = mouseView->ConvertFromScreen(point - offset);
|
point = mouseView->ConvertFromScreen(point - offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
BHandler *handler;
|
|
||||||
BLooper *looper;
|
BLooper *looper;
|
||||||
handler = msg->ReturnAddress().Target(&looper);
|
BHandler *handler = msg->ReturnAddress().Target(&looper);
|
||||||
|
|
||||||
BDragger *dragger;
|
BDragger *dragger;
|
||||||
|
|
||||||
@@ -401,14 +403,32 @@ BShelf::Instantiate(BMessage *data)
|
|||||||
void
|
void
|
||||||
BShelf::MessageReceived(BMessage *msg)
|
BShelf::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
|
//TODO: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BShelf::Save()
|
BShelf::Save()
|
||||||
{
|
{
|
||||||
//TODO
|
status_t status = B_ERROR;
|
||||||
return B_ERROR;
|
if (fEntry != NULL) {
|
||||||
|
BFile *file = new BFile(fEntry, B_READ_WRITE);
|
||||||
|
status = file->InitCheck();
|
||||||
|
if (status < B_OK) {
|
||||||
|
delete file;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
fStream = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fStream != NULL) {
|
||||||
|
BMessage message;
|
||||||
|
status = _Archive(&message);
|
||||||
|
if (status == B_OK)
|
||||||
|
status = message.Flatten(fStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -689,12 +709,14 @@ BShelf::ReplicantDeleted(int32 index, const BMessage *archive,
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_ReservedShelf1__6BShelfFv(BShelf *const, int32, const BMessage*,
|
_ReservedShelf1__6BShelfFv(BShelf *const, int32, const BMessage*,
|
||||||
const BView*)
|
const BView*)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BShelf::_ReservedShelf2() {}
|
void BShelf::_ReservedShelf2() {}
|
||||||
void BShelf::_ReservedShelf3() {}
|
void BShelf::_ReservedShelf3() {}
|
||||||
void BShelf::_ReservedShelf4() {}
|
void BShelf::_ReservedShelf4() {}
|
||||||
@@ -786,8 +808,7 @@ BShelf::_InitData(BEntry *entry, BDataIO *stream, BView *view,
|
|||||||
status_t
|
status_t
|
||||||
BShelf::_DeleteReplicant(_rep_data_* item)
|
BShelf::_DeleteReplicant(_rep_data_* item)
|
||||||
{
|
{
|
||||||
bool loadedImage;
|
bool loadedImage = item->fMessage->FindBool("");
|
||||||
item->fMessage->FindBool("", &loadedImage);
|
|
||||||
|
|
||||||
BView *view = item->fView;
|
BView *view = item->fView;
|
||||||
if (view == NULL)
|
if (view == NULL)
|
||||||
@@ -799,6 +820,11 @@ BShelf::_DeleteReplicant(_rep_data_* item)
|
|||||||
if (item->fDragger)
|
if (item->fDragger)
|
||||||
item->fDragger->RemoveSelf();
|
item->fDragger->RemoveSelf();
|
||||||
|
|
||||||
|
int32 index = _rep_data_::index_of(&fReplicants, item->fMessage);
|
||||||
|
|
||||||
|
// TODO: Test if it's ok here
|
||||||
|
ReplicantDeleted(index, item->fMessage, view);
|
||||||
|
|
||||||
fReplicants.RemoveItem(item);
|
fReplicants.RemoveItem(item);
|
||||||
|
|
||||||
if (loadedImage && item->fImage >= 0)
|
if (loadedImage && item->fImage >= 0)
|
||||||
@@ -833,27 +859,28 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if we can accept this message
|
// Check if we can accept this message
|
||||||
if (!CanAcceptReplicantMessage(data))
|
if (!CanAcceptReplicantMessage(data)) {
|
||||||
|
printf("Replicant was rejected by BShelf: CanAcceptReplicant() returned false");
|
||||||
return send_reply(data, B_ERROR, uniqueID);
|
return send_reply(data, B_ERROR, uniqueID);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we can create multiple instances
|
// Check if we can create multiple instances
|
||||||
if (data->FindBool("be:load_each_time")) {
|
if (data->FindBool("be:load_each_time")) {
|
||||||
const char *_class = NULL;
|
const char *_class = NULL;
|
||||||
const char *add_on = NULL;
|
const char *add_on = NULL;
|
||||||
|
|
||||||
if (data->FindString("class", &_class)) {
|
if (data->FindString("class", &_class) == B_OK
|
||||||
if (data->FindString("add_on", &add_on)) {
|
&& data->FindString("add_on", &add_on) == B_OK) {
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
_rep_data_ *item;
|
_rep_data_ *item;
|
||||||
const char *rep_class = NULL;
|
const char *rep_class = NULL;
|
||||||
const char *rep_add_on = NULL;
|
const char *rep_add_on = NULL;
|
||||||
|
|
||||||
while ((item = (_rep_data_*)fReplicants.ItemAt(i++)) !=NULL) {
|
while ((item = (_rep_data_*)fReplicants.ItemAt(i++)) != NULL) {
|
||||||
item->fMessage->FindString("class", &rep_class);
|
if (item->fMessage->FindString("class", &rep_class) == B_OK
|
||||||
item->fMessage->FindString("add_on", &rep_add_on);
|
&& item->fMessage->FindString("add_on", &rep_add_on) == B_OK
|
||||||
|
&& !strcmp(_class, rep_class) && add_on && rep_add_on
|
||||||
if (!strcmp(_class, rep_class) && add_on && rep_add_on
|
&& !strcmp(add_on, rep_add_on)) {
|
||||||
&& strcmp(_class, rep_class) == 0) {
|
|
||||||
printf("Replicant was rejected. Unique replicant already exists. class=%s, signature=%s",
|
printf("Replicant was rejected. Unique replicant already exists. class=%s, signature=%s",
|
||||||
rep_class, rep_add_on);
|
rep_class, rep_add_on);
|
||||||
return send_reply(data, B_ERROR, uniqueID);
|
return send_reply(data, B_ERROR, uniqueID);
|
||||||
@@ -861,7 +888,6 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
BDragger* dragger = NULL;
|
BDragger* dragger = NULL;
|
||||||
BView* replicant = NULL;
|
BView* replicant = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user