* 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:
parent
509798f986
commit
47c1e3d9a9
@ -52,6 +52,9 @@ All rights reserved.
|
||||
#include "BackgroundImage.h"
|
||||
#include "BackgroundsView.h"
|
||||
|
||||
#include <new>
|
||||
|
||||
|
||||
const char *kBackgroundImageInfo = "be:bgndimginfo";
|
||||
const char *kBackgroundImageInfoOffset = "be:bgndimginfooffset";
|
||||
const char *kBackgroundImageInfoEraseText = "be:bgndimginfoerasetext";
|
||||
@ -64,6 +67,7 @@ const char *kBackgroundImageSetPeriod = "be:bgndimgsetperiod";
|
||||
const char *kBackgroundImageRandomChange = "be:bgndimgrandomchange";
|
||||
const char *kBackgroundImageCacheMode = "be:bgndimgcachemode";
|
||||
|
||||
|
||||
BackgroundImage *
|
||||
BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
|
||||
BackgroundsView* view)
|
||||
@ -428,13 +432,22 @@ BackgroundImage::SetBackgroundImage(BNode *node)
|
||||
|
||||
PRINT_OBJECT(container);
|
||||
|
||||
char buffer[container.FlattenedSize()];
|
||||
if ((err = container.Flatten(buffer, container.FlattenedSize())) != B_OK)
|
||||
size_t flattenedSize = container.FlattenedSize();
|
||||
char* buffer = new (std::nothrow) char[flattenedSize];
|
||||
if (buffer == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
if ((err = container.Flatten(buffer, flattenedSize)) != B_OK)
|
||||
return err;
|
||||
|
||||
ssize_t size = node->WriteAttr(kBackgroundImageInfo, 0, 0, buffer,
|
||||
container.FlattenedSize());
|
||||
if (size <= 0)
|
||||
ssize_t size = node->WriteAttr(kBackgroundImageInfo, B_MESSAGE_TYPE,
|
||||
0, buffer, flattenedSize);
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
if (size < B_OK)
|
||||
return size;
|
||||
if ((size_t)size != flattenedSize)
|
||||
return B_ERROR;
|
||||
|
||||
return B_OK;
|
||||
|
@ -355,6 +355,7 @@ BackgroundsView::MessageReceived(BMessage *msg)
|
||||
case APPLY_SETTINGS:
|
||||
{
|
||||
Save();
|
||||
|
||||
//NotifyServer();
|
||||
thread_id notify_thread;
|
||||
notify_thread = spawn_thread(BackgroundsView::NotifyThread, "notifyServer",
|
||||
@ -584,7 +585,12 @@ BackgroundsView::Save()
|
||||
}
|
||||
|
||||
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
|
||||
BackgroundsView::LoadSettings(void)
|
||||
BackgroundsView::LoadSettings()
|
||||
{
|
||||
fSettings.MakeEmpty();
|
||||
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
|
||||
path.Append(SETTINGS_FILE);
|
||||
BFile file(path.Path(),B_READ_ONLY);
|
||||
if (file.InitCheck() == B_OK && fSettings.Unflatten(&file) == B_OK) {
|
||||
PRINT_OBJECT(fSettings);
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||
return;
|
||||
|
||||
BPoint point;
|
||||
if (fSettings.FindPoint("pos", &point) == B_OK)
|
||||
Window()->MoveTo(point);
|
||||
path.Append(SETTINGS_FILE);
|
||||
BFile file(path.Path(), B_READ_ONLY);
|
||||
if (file.InitCheck() != B_OK)
|
||||
return;
|
||||
|
||||
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"));
|
||||
} else {
|
||||
printf("Error unflattening settings file %s\n", path.Path());
|
||||
}
|
||||
if (fSettings.Unflatten(&file) != B_OK) {
|
||||
printf("Error unflattening settings file %s\n", path.Path());
|
||||
return;
|
||||
}
|
||||
|
||||
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()) {
|
||||
BNodeInfo nodeInfo(&node);
|
||||
char fileType[256];
|
||||
char fileType[B_MIME_TYPE_LENGTH];
|
||||
if (nodeInfo.GetType(fileType) != B_OK)
|
||||
continue;
|
||||
|
||||
@ -937,6 +948,7 @@ BackgroundsView::RefsReceived(BMessage *msg)
|
||||
item->SetTarget(this);
|
||||
fLastWorkspaceIndex = -index-1 + 6;
|
||||
}
|
||||
|
||||
item->SetMarked(true);
|
||||
BMessenger messenger(this);
|
||||
messenger.SendMessage(FOLDER_SELECTED);
|
||||
|
Loading…
Reference in New Issue
Block a user