* Now writes the background info message as B_MESSAGE_TYPE attribute (instead of 0).

* Better error reporting when writing the attributes.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15744 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-12-30 15:36:14 +00:00
parent 509798f986
commit 47c1e3d9a9
2 changed files with 68 additions and 43 deletions

View File

@ -52,6 +52,9 @@ All rights reserved.
#include "BackgroundImage.h" #include "BackgroundImage.h"
#include "BackgroundsView.h" #include "BackgroundsView.h"
#include <new>
const char *kBackgroundImageInfo = "be:bgndimginfo"; const char *kBackgroundImageInfo = "be:bgndimginfo";
const char *kBackgroundImageInfoOffset = "be:bgndimginfooffset"; const char *kBackgroundImageInfoOffset = "be:bgndimginfooffset";
const char *kBackgroundImageInfoEraseText = "be:bgndimginfoerasetext"; const char *kBackgroundImageInfoEraseText = "be:bgndimginfoerasetext";
@ -64,6 +67,7 @@ const char *kBackgroundImageSetPeriod = "be:bgndimgsetperiod";
const char *kBackgroundImageRandomChange = "be:bgndimgrandomchange"; const char *kBackgroundImageRandomChange = "be:bgndimgrandomchange";
const char *kBackgroundImageCacheMode = "be:bgndimgcachemode"; const char *kBackgroundImageCacheMode = "be:bgndimgcachemode";
BackgroundImage * BackgroundImage *
BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop, BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
BackgroundsView* view) BackgroundsView* view)
@ -428,13 +432,22 @@ BackgroundImage::SetBackgroundImage(BNode *node)
PRINT_OBJECT(container); PRINT_OBJECT(container);
char buffer[container.FlattenedSize()]; size_t flattenedSize = container.FlattenedSize();
if ((err = container.Flatten(buffer, container.FlattenedSize())) != B_OK) char* buffer = new (std::nothrow) char[flattenedSize];
if (buffer == NULL)
return B_NO_MEMORY;
if ((err = container.Flatten(buffer, flattenedSize)) != B_OK)
return err; return err;
ssize_t size = node->WriteAttr(kBackgroundImageInfo, 0, 0, buffer, ssize_t size = node->WriteAttr(kBackgroundImageInfo, B_MESSAGE_TYPE,
container.FlattenedSize()); 0, buffer, flattenedSize);
if (size <= 0)
delete[] buffer;
if (size < B_OK)
return size;
if ((size_t)size != flattenedSize)
return B_ERROR; return B_ERROR;
return B_OK; return B_OK;

View File

@ -355,6 +355,7 @@ BackgroundsView::MessageReceived(BMessage *msg)
case APPLY_SETTINGS: case APPLY_SETTINGS:
{ {
Save(); Save();
//NotifyServer(); //NotifyServer();
thread_id notify_thread; thread_id notify_thread;
notify_thread = spawn_thread(BackgroundsView::NotifyThread, "notifyServer", notify_thread = spawn_thread(BackgroundsView::NotifyThread, "notifyServer",
@ -584,7 +585,12 @@ BackgroundsView::Save()
} }
BNode node(&fCurrentRef); BNode node(&fCurrentRef);
fCurrent->SetBackgroundImage(&node);
status_t status = fCurrent->SetBackgroundImage(&node);
if (status != B_OK) {
// TODO: this should be a BAlert!
printf("setting background image failed: %s\n", strerror(status));
}
} }
@ -714,49 +720,54 @@ BackgroundsView::SaveSettings(void)
void void
BackgroundsView::LoadSettings(void) BackgroundsView::LoadSettings()
{ {
fSettings.MakeEmpty(); fSettings.MakeEmpty();
BPath path; BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
path.Append(SETTINGS_FILE); return;
BFile file(path.Path(),B_READ_ONLY);
if (file.InitCheck() == B_OK && fSettings.Unflatten(&file) == B_OK) {
PRINT_OBJECT(fSettings);
BPoint point; path.Append(SETTINGS_FILE);
if (fSettings.FindPoint("pos", &point) == B_OK) BFile file(path.Path(), B_READ_ONLY);
Window()->MoveTo(point); if (file.InitCheck() != B_OK)
return;
BString string; if (fSettings.Unflatten(&file) != B_OK) {
if (fSettings.FindString("paneldir", &string) == B_OK) printf("Error unflattening settings file %s\n", path.Path());
fPanel->SetPanelDirectory(string.String()); return;
if (fSettings.FindString("folderpaneldir", &string) == B_OK)
fFolderPanel->SetPanelDirectory(string.String());
int32 index = 0;
while (fSettings.FindString("recentfolder", index, &string) == B_OK) {
if (index == 0)
fWorkspaceMenu->AddSeparatorItem();
BPath path(string.String());
int32 i = AddPath(path);
BString s;
s << "Folder: " << path.Leaf();
BMenuItem *item = new BMenuItem(s.String(),
new BMessage(FOLDER_SELECTED));
fWorkspaceMenu->AddItem(item, -i-1+6);
index++;
}
fWorkspaceMenu->SetTargetForItems(this);
PRINT(("Settings Loaded\n"));
} else {
printf("Error unflattening settings file %s\n", path.Path());
}
} }
PRINT_OBJECT(fSettings);
BPoint point;
if (fSettings.FindPoint("pos", &point) == B_OK)
Window()->MoveTo(point);
BString string;
if (fSettings.FindString("paneldir", &string) == B_OK)
fPanel->SetPanelDirectory(string.String());
if (fSettings.FindString("folderpaneldir", &string) == B_OK)
fFolderPanel->SetPanelDirectory(string.String());
int32 index = 0;
while (fSettings.FindString("recentfolder", index, &string) == B_OK) {
if (index == 0)
fWorkspaceMenu->AddSeparatorItem();
BPath path(string.String());
int32 i = AddPath(path);
BString s;
s << "Folder: " << path.Leaf();
BMenuItem *item = new BMenuItem(s.String(),
new BMessage(FOLDER_SELECTED));
fWorkspaceMenu->AddItem(item, -i-1+6);
index++;
}
fWorkspaceMenu->SetTargetForItems(this);
PRINT(("Settings Loaded\n"));
} }
@ -896,7 +907,7 @@ BackgroundsView::RefsReceived(BMessage *msg)
if (node.IsFile()) { if (node.IsFile()) {
BNodeInfo nodeInfo(&node); BNodeInfo nodeInfo(&node);
char fileType[256]; char fileType[B_MIME_TYPE_LENGTH];
if (nodeInfo.GetType(fileType) != B_OK) if (nodeInfo.GetType(fileType) != B_OK)
continue; continue;
@ -937,6 +948,7 @@ BackgroundsView::RefsReceived(BMessage *msg)
item->SetTarget(this); item->SetTarget(this);
fLastWorkspaceIndex = -index-1 + 6; fLastWorkspaceIndex = -index-1 + 6;
} }
item->SetMarked(true); item->SetMarked(true);
BMessenger messenger(this); BMessenger messenger(this);
messenger.SendMessage(FOLDER_SELECTED); messenger.SendMessage(FOLDER_SELECTED);