* Changed the default settings to close after being done with expanding.

* Some cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29508 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-03-14 08:50:08 +00:00
parent 2c4e929f54
commit 152a0ade57
+89 -69
View File
@@ -53,13 +53,24 @@
// 4 bytes : window position topleft x (default : 0x4842) // 4 bytes : window position topleft x (default : 0x4842)
// 4 bytes : window position topleft y (default : 0x4842) // 4 bytes : window position topleft y (default : 0x4842)
template<typename T> bool
read_data(BFile& file, T& value)
{
return file.Read(&value, sizeof(T)) == (ssize_t)sizeof(T);
}
// #pragma mark -
ExpanderSettings::ExpanderSettings() ExpanderSettings::ExpanderSettings()
: :
fMessage(kMsgExpanderSettings), fMessage(kMsgExpanderSettings),
fUpdated(false) fUpdated(false)
{ {
fMessage.AddBool("automatically_expand_files", false); fMessage.AddBool("automatically_expand_files", false);
fMessage.AddBool("close_when_done", false); fMessage.AddBool("close_when_done", true);
fMessage.AddInt8("destination_folder", 0x63); fMessage.AddInt8("destination_folder", 0x63);
entry_ref ref; entry_ref ref;
fMessage.AddRef("destination_folder_use", &ref); fMessage.AddRef("destination_folder_use", &ref);
@@ -71,49 +82,52 @@ ExpanderSettings::ExpanderSettings()
if (Open(&file, B_READ_ONLY) != B_OK) if (Open(&file, B_READ_ONLY) != B_OK)
return; return;
// ToDo: load/save settings as flattened BMessage - but not yet, // TODO: load/save settings as flattened BMessage - but not yet,
// since that will break compatibility with R5's Expander // since that will break compatibility with R5's Expander
bool unknown; bool unknown;
bool automatically_expand_files; bool automaticallyExpandFiles;
bool close_when_done; bool closeWhenDone;
int8 destination_folder; int8 destinationFolder;
bool open_destination_folder; bool openDestinationFolder;
bool show_contents_listing; bool showContentsListing;
BPoint position; BPoint position;
int32 name_size; char name[B_FILE_NAME_LENGTH] = {'\0'};
if ( int32 nameSize;
(file.Read(&unknown, sizeof(unknown)) == sizeof(unknown)) if (read_data(file, unknown)
&& (file.Read(&automatically_expand_files, sizeof(automatically_expand_files)) == sizeof(automatically_expand_files)) && read_data(file, automaticallyExpandFiles)
&& (file.Read(&close_when_done, sizeof(close_when_done)) == sizeof(close_when_done)) && read_data(file, closeWhenDone)
&& (file.Read(&destination_folder, sizeof(destination_folder)) == sizeof(destination_folder)) && read_data(file, destinationFolder)
&& (file.Read(&unknown, sizeof(unknown)) == sizeof(unknown)) && read_data(file, unknown)
&& (file.Read(&ref.device, sizeof(ref.device)) == sizeof(ref.device)) && read_data(file, ref.device)
&& (file.Read(&ref.directory, sizeof(ref.directory)) == sizeof(ref.directory)) && read_data(file, ref.directory)
&& (file.Read(&name_size, sizeof(name_size)) == sizeof(name_size)) && read_data(file, nameSize)
&& ((name_size <= 0) || (ref.name = (char*)malloc(name_size + 1))) && (nameSize <= 0 || file.Read(name, nameSize) == nameSize)
&& (file.Read(ref.name, name_size) == name_size) && read_data(file, openDestinationFolder)
&& (file.Read(&open_destination_folder, sizeof(open_destination_folder)) == sizeof(open_destination_folder)) && read_data(file, showContentsListing)
&& (file.Read(&show_contents_listing, sizeof(show_contents_listing)) == sizeof(show_contents_listing)) && read_data(file, position)) {
&& (file.Read(&position, sizeof(position)) == sizeof(position)) if (nameSize > 0 && nameSize < B_FILE_NAME_LENGTH) {
) { name[nameSize] = '\0';
ref.set_name(name);
}
// check if the window position is on screen at all // check if the window position is on screen at all
BScreen screen; BScreen screen;
if (screen.Frame().Contains(position)) if (screen.Frame().Contains(position))
fMessage.ReplacePoint("window_position", position); fMessage.ReplacePoint("window_position", position);
fMessage.ReplaceBool("automatically_expand_files", automatically_expand_files); fMessage.ReplaceBool("automatically_expand_files",
fMessage.ReplaceBool("close_when_done", close_when_done); automaticallyExpandFiles);
if (destination_folder == 0x66 || destination_folder == 0x63 || destination_folder == 0x65) fMessage.ReplaceBool("close_when_done", closeWhenDone);
fMessage.ReplaceInt8("destination_folder", destination_folder); if (destinationFolder == 0x66
if (name_size > 0) || destinationFolder == 0x63
ref.name[name_size] = '\0'; || destinationFolder == 0x65)
fMessage.ReplaceInt8("destination_folder", destinationFolder);
BEntry entry(&ref); BEntry entry(&ref);
if (entry.Exists()) if (entry.Exists())
fMessage.ReplaceRef("destination_folder_use", &ref); fMessage.ReplaceRef("destination_folder_use", &ref);
fMessage.ReplaceBool("open_destination_folder", open_destination_folder); fMessage.ReplaceBool("open_destination_folder", openDestinationFolder);
fMessage.ReplaceBool("show_contents_listing", show_contents_listing); fMessage.ReplaceBool("show_contents_listing", showContentsListing);
} }
} }
@@ -128,41 +142,42 @@ ExpanderSettings::~ExpanderSettings()
if (Open(&file, B_CREATE_FILE | B_WRITE_ONLY) != B_OK) if (Open(&file, B_CREATE_FILE | B_WRITE_ONLY) != B_OK)
return; return;
bool automatically_expand_files; bool automaticallyExpandFiles;
bool close_when_done; bool closeWhenDone;
int8 destination_folder; int8 destinationFolder;
entry_ref ref; entry_ref ref;
bool open_destination_folder; bool openDestinationFolder;
bool show_contents_listing; bool showContentsListing;
BPoint position; BPoint position;
bool unknown = 1; bool unknown = 1;
if ((fMessage.FindPoint("window_position", &position) == B_OK) if (fMessage.FindPoint("window_position", &position) == B_OK
&& (fMessage.FindBool("automatically_expand_files", &automatically_expand_files) == B_OK) && fMessage.FindBool("automatically_expand_files",
&& (fMessage.FindBool("close_when_done", &close_when_done) == B_OK) &automaticallyExpandFiles) == B_OK
&& (fMessage.FindInt8("destination_folder", &destination_folder) == B_OK) && fMessage.FindBool("close_when_done", &closeWhenDone) == B_OK
&& (fMessage.FindRef("destination_folder_use", &ref) == B_OK) && fMessage.FindInt8("destination_folder", &destinationFolder) == B_OK
&& (fMessage.FindBool("open_destination_folder", &open_destination_folder) == B_OK) && fMessage.FindRef("destination_folder_use", &ref) == B_OK
&& (fMessage.FindBool("show_contents_listing", &show_contents_listing) == B_OK)) { && fMessage.FindBool("open_destination_folder",
&openDestinationFolder) == B_OK
&& fMessage.FindBool("show_contents_listing",
&showContentsListing) == B_OK) {
file.Write(&unknown, sizeof(unknown)); file.Write(&unknown, sizeof(unknown));
file.Write(&automatically_expand_files, sizeof(automatically_expand_files)); file.Write(&automaticallyExpandFiles, sizeof(automaticallyExpandFiles));
file.Write(&close_when_done, sizeof(close_when_done)); file.Write(&closeWhenDone, sizeof(closeWhenDone));
file.Write(&destination_folder, sizeof(destination_folder)); file.Write(&destinationFolder, sizeof(destinationFolder));
unknown = 0; unknown = 0;
file.Write(&unknown, sizeof(unknown)); file.Write(&unknown, sizeof(unknown));
file.Write(&ref.device, sizeof(ref.device)); file.Write(&ref.device, sizeof(ref.device));
file.Write(&ref.directory, sizeof(ref.directory)); file.Write(&ref.directory, sizeof(ref.directory));
int32 name_size = 0; int32 nameSize = 0;
if (ref.name) if (ref.name)
name_size = strlen(ref.name); nameSize = strlen(ref.name);
file.Write(&name_size, sizeof(name_size)); file.Write(&nameSize, sizeof(nameSize));
file.Write(ref.name, name_size); file.Write(ref.name, nameSize);
file.Write(&open_destination_folder, sizeof(open_destination_folder)); file.Write(&openDestinationFolder, sizeof(openDestinationFolder));
file.Write(&show_contents_listing, sizeof(show_contents_listing)); file.Write(&showContentsListing, sizeof(showContentsListing));
file.Write(&position, sizeof(position)); file.Write(&position, sizeof(position));
} }
} }
@@ -182,34 +197,39 @@ ExpanderSettings::Open(BFile *file, int32 mode)
void void
ExpanderSettings::UpdateFrom(BMessage *message) ExpanderSettings::UpdateFrom(BMessage *message)
{ {
bool automatically_expand_files; bool automaticallyExpandFiles;
bool close_when_done; bool closeWhenDone;
int8 destination_folder; int8 destinationFolder;
entry_ref ref; entry_ref ref;
bool open_destination_folder; bool openDestinationFolder;
bool show_contents_listing; bool showContentsListing;
BPoint position; BPoint position;
if (message->FindPoint("window_position", &position) == B_OK) if (message->FindPoint("window_position", &position) == B_OK)
fMessage.ReplacePoint("window_position", position); fMessage.ReplacePoint("window_position", position);
if (message->FindBool("automatically_expand_files", &automatically_expand_files) == B_OK) if (message->FindBool("automatically_expand_files",
fMessage.ReplaceBool("automatically_expand_files", automatically_expand_files); &automaticallyExpandFiles) == B_OK) {
fMessage.ReplaceBool("automatically_expand_files",
automaticallyExpandFiles);
}
if (message->FindBool("close_when_done", &close_when_done) == B_OK) if (message->FindBool("close_when_done", &closeWhenDone) == B_OK)
fMessage.ReplaceBool("close_when_done", close_when_done); fMessage.ReplaceBool("close_when_done", closeWhenDone);
if (message->FindInt8("destination_folder", &destination_folder) == B_OK) if (message->FindInt8("destination_folder", &destinationFolder) == B_OK)
fMessage.ReplaceInt8("destination_folder", destination_folder); fMessage.ReplaceInt8("destination_folder", destinationFolder);
if (message->FindRef("destination_folder_use", &ref) == B_OK) if (message->FindRef("destination_folder_use", &ref) == B_OK)
fMessage.ReplaceRef("destination_folder_use", &ref); fMessage.ReplaceRef("destination_folder_use", &ref);
if (message->FindBool("open_destination_folder", &open_destination_folder) == B_OK) if (message->FindBool("open_destination_folder",
fMessage.ReplaceBool("open_destination_folder", open_destination_folder); &openDestinationFolder) == B_OK)
fMessage.ReplaceBool("open_destination_folder", openDestinationFolder);
if (message->FindBool("show_contents_listing", &show_contents_listing) == B_OK) if (message->FindBool("show_contents_listing",
fMessage.ReplaceBool("show_contents_listing", show_contents_listing); &showContentsListing) == B_OK)
fMessage.ReplaceBool("show_contents_listing", showContentsListing);
fUpdated = true; fUpdated = true;
} }