Tweaks to notify server of decorator changes, load/save settings
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3954 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
473f6f3088
commit
1344da2b98
@ -35,6 +35,7 @@
|
|||||||
#include "DecView.h"
|
#include "DecView.h"
|
||||||
#include <PortLink.h>
|
#include <PortLink.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
|
#include <ServerProtocol.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "RGBColor.h"
|
#include "RGBColor.h"
|
||||||
@ -118,7 +119,7 @@ void DecView::AllAttached(void)
|
|||||||
{
|
{
|
||||||
declist->SetTarget(this);
|
declist->SetTarget(this);
|
||||||
apply->SetTarget(this);
|
apply->SetTarget(this);
|
||||||
declist->Select(0);
|
LoadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecView::MessageReceived(BMessage *msg)
|
void DecView::MessageReceived(BMessage *msg)
|
||||||
@ -173,11 +174,17 @@ printf("MSG: Decorator NOT Chosen - couldn't load decorator\n");
|
|||||||
|
|
||||||
void DecView::SaveSettings(void)
|
void DecView::SaveSettings(void)
|
||||||
{
|
{
|
||||||
|
BStringItem *item=(BStringItem*)declist->ItemAt(declist->CurrentSelection());
|
||||||
|
if(!item)
|
||||||
|
return;
|
||||||
|
|
||||||
BString path(SETTINGS_DIR);
|
BString path(SETTINGS_DIR);
|
||||||
path+="DecoratorSettings";
|
path+="DecoratorSettings";
|
||||||
printf("%s\n",path.String());
|
printf("%s\n",path.String());
|
||||||
BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE);
|
BFile file(path.String(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE);
|
||||||
|
|
||||||
|
settings.MakeEmpty();
|
||||||
|
settings.AddString("decorator",item->Text());
|
||||||
settings.Flatten(&file);
|
settings.Flatten(&file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,45 +204,46 @@ void DecView::LoadSettings(void)
|
|||||||
{
|
{
|
||||||
if(settings.Unflatten(&file)==B_OK)
|
if(settings.Unflatten(&file)==B_OK)
|
||||||
{
|
{
|
||||||
// Get the color for the current attribute here
|
BString itemtext;
|
||||||
|
if(settings.FindString("decorator",&itemtext)==B_OK)
|
||||||
|
{
|
||||||
|
for(int32 i=0;i<declist->CountItems();i++)
|
||||||
|
{
|
||||||
|
BStringItem *item=(BStringItem*)declist->ItemAt(i);
|
||||||
|
if(item && itemtext.Compare(item->Text())==0)
|
||||||
|
{
|
||||||
|
declist->Select(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We got this far, so something must have gone wrong. Select the first item
|
||||||
|
declist->Select(0L);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("Error unflattening settings file %s\n",path.String());
|
printf("Error unflattening settings file %s\n",path.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get this far, we have encountered an error, so reset the settings
|
|
||||||
// to the defaults
|
|
||||||
SetDefaults();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DecView::SetDefaults(void)
|
|
||||||
{
|
|
||||||
settings.MakeEmpty();
|
|
||||||
|
|
||||||
// Add default settings here
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecView::NotifyServer(void)
|
void DecView::NotifyServer(void)
|
||||||
{
|
{
|
||||||
// Send a message to the app_server with the settings which we have.
|
// Send a message to the app_server to tell it which decorator we have selected.
|
||||||
// While it might be worthwhile to someday have a separate protocol for
|
|
||||||
// updating just one color, for now, we just need something to get things
|
|
||||||
// done. Extract all the colors from the settings BMessage, attach them
|
|
||||||
// to a PortLink message and fire it off to the server.
|
|
||||||
|
|
||||||
// Name taken from ServerProtocol.h
|
port_id serverport=find_port(SERVER_PORT_NAME);
|
||||||
port_id serverport=find_port("OBappserver");
|
|
||||||
|
|
||||||
if(serverport==B_NAME_NOT_FOUND)
|
if(serverport==B_NAME_NOT_FOUND)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PortLink *pl=new PortLink(serverport);
|
BStringItem *item=(BStringItem*)declist->ItemAt(declist->CurrentSelection());
|
||||||
|
if(!item)
|
||||||
// pl->SetOpCode(SET_UI_COLORS);
|
return;
|
||||||
|
|
||||||
// extract settings from settings object and attach to portlink object
|
PortLink *pl=new PortLink(serverport);
|
||||||
|
pl->SetOpCode(SET_DECORATOR);
|
||||||
// pl->Flush();
|
pl->Attach(item->Text(),strlen(item->Text())+1);
|
||||||
|
pl->Flush();
|
||||||
delete pl;
|
delete pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,6 @@ public:
|
|||||||
void MessageReceived(BMessage *msg);
|
void MessageReceived(BMessage *msg);
|
||||||
void SaveSettings(void);
|
void SaveSettings(void);
|
||||||
void LoadSettings(void);
|
void LoadSettings(void);
|
||||||
void SetDefaults(void);
|
|
||||||
void NotifyServer(void);
|
void NotifyServer(void);
|
||||||
void GetDecorators(void);
|
void GetDecorators(void);
|
||||||
void SetColors(const BMessage &message);
|
void SetColors(const BMessage &message);
|
||||||
|
Loading…
Reference in New Issue
Block a user