18314c36bSRene Gollent/*
28314c36bSRene Gollent * Copyright 2011, Rene Gollent, rene@gollent.com.
38314c36bSRene Gollent * Distributed under the terms of the MIT License.
48314c36bSRene Gollent */
58314c36bSRene Gollent
68314c36bSRene Gollent
7f4b1ddb5SIngo Weinhold#include "GuiSettingsUtils.h"
88314c36bSRene Gollent
91483288fSRene Gollent#include <Message.h>
108314c36bSRene Gollent#include <SplitView.h>
118314c36bSRene Gollent
1229ca41d5SRene Gollent#include "table/AbstractTable.h"
1329ca41d5SRene Gollent
148314c36bSRene Gollent
158314c36bSRene Gollent/*static*/ status_t
16f4b1ddb5SIngo WeinholdGuiSettingsUtils::ArchiveSplitView(BMessage& settings, BSplitView* view)
178314c36bSRene Gollent{
181483288fSRene Gollent	settings.MakeEmpty();
198314c36bSRene Gollent	for (int32 i = 0; i < view->CountItems(); i++) {
201483288fSRene Gollent		if (settings.AddFloat("weight", view->ItemWeight(i)) != B_OK)
218314c36bSRene Gollent			return B_NO_MEMORY;
228314c36bSRene Gollent
232b9c68afSRene Gollent		if (settings.AddBool("collapsed", view->IsItemCollapsed(i)) != B_OK)
248314c36bSRene Gollent			return B_NO_MEMORY;
258314c36bSRene Gollent	}
268314c36bSRene Gollent
278314c36bSRene Gollent	return B_OK;
288314c36bSRene Gollent}
298314c36bSRene Gollent
308314c36bSRene Gollent
318314c36bSRene Gollent/*static*/ void
32f4b1ddb5SIngo WeinholdGuiSettingsUtils::UnarchiveSplitView(const BMessage& settings,
331483288fSRene Gollent	BSplitView* view)
348314c36bSRene Gollent{
358314c36bSRene Gollent	for (int32 i = 0; i < view->CountItems(); i++) {
361483288fSRene Gollent		float weight;
371483288fSRene Gollent		if (settings.FindFloat("weight", i, &weight) == B_OK)
381483288fSRene Gollent			view->SetItemWeight(i, weight, i == view->CountItems() - 1);
391483288fSRene Gollent
401483288fSRene Gollent		bool collapsed;
411483288fSRene Gollent		if (settings.FindBool("collapsed", i, &collapsed) == B_OK)
421483288fSRene Gollent			view->SetItemCollapsed(i, collapsed);
438314c36bSRene Gollent	}
448314c36bSRene Gollent}
4529ca41d5SRene Gollent
4629ca41d5SRene Gollent
4729ca41d5SRene Gollent/*static*/ status_t
48f4b1ddb5SIngo WeinholdGuiSettingsUtils::ArchiveTableSettings(BMessage& settings,
491483288fSRene Gollent	AbstractTable* table)
5029ca41d5SRene Gollent{
511483288fSRene Gollent	settings.MakeEmpty();
521483288fSRene Gollent	table->SaveState(&settings);
5329ca41d5SRene Gollent
5429ca41d5SRene Gollent	return B_OK;
5529ca41d5SRene Gollent}
5629ca41d5SRene Gollent
5729ca41d5SRene Gollent
5829ca41d5SRene Gollent/*static*/ void
59f4b1ddb5SIngo WeinholdGuiSettingsUtils::UnarchiveTableSettings(const BMessage& settings,
6029ca41d5SRene Gollent	AbstractTable* table)
6129ca41d5SRene Gollent{
621483288fSRene Gollent	BMessage settingsCopy(settings);
631483288fSRene Gollent	table->LoadState(&settingsCopy);
6429ca41d5SRene Gollent}
6529ca41d5SRene Gollent
66