Work in progress, now the Joystick pref should show the right text and error (that I can reproduce without joystick)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25865 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -17,6 +17,11 @@
|
||||
#define PORT_INVOKE 'PInV'
|
||||
#define JOY_INVOKE 'jInV'
|
||||
|
||||
#define DISABLEPORT 'pdis'
|
||||
#define PROBE 'prob'
|
||||
#define CALIBRATE 'cali'
|
||||
|
||||
#define SELECTED 'sele'
|
||||
|
||||
#endif /* _GLOBAL_H */
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
SubDir HAIKU_TOP src preferences joysticks ;
|
||||
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
AddSubDirSupportedPlatforms libbe_test ;
|
||||
|
||||
Preference Joysticks :
|
||||
CalibWin.cpp
|
||||
JoyWin.cpp
|
||||
Joysticks.cpp
|
||||
MessageWin.cpp
|
||||
PortItem.cpp
|
||||
: be device
|
||||
: Joysticks.rdef
|
||||
;
|
||||
|
||||
@@ -1,117 +1,264 @@
|
||||
/*
|
||||
* Copyright 2007 Haiku.
|
||||
* Copyright 2007-2008 Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||
* Ryan Leavengood, [email protected]
|
||||
* Oliver Ruiz Dorantes oliver.ruiz.dorantes_at_gmail.com
|
||||
* Ryan Leavengood [email protected]
|
||||
* Fredrik Modéen [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#include "JoyWin.h"
|
||||
#include "MessagedItem.h"
|
||||
#include "MessageWin.h"
|
||||
#include "CalibWin.h"
|
||||
#include "Global.h"
|
||||
#include "PortItem.h"
|
||||
//#include "FileReadWrite.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <CheckBox.h>
|
||||
#include <ListView.h>
|
||||
#include <ListItem.h>
|
||||
#include <ScrollView.h>
|
||||
#include <String.h>
|
||||
#include <StringView.h>
|
||||
#include <Application.h>
|
||||
#include <View.h>
|
||||
#include <Path.h>
|
||||
#include <Entry.h>
|
||||
#include <Directory.h>
|
||||
#include <Alert.h>
|
||||
#include <File.h>
|
||||
#include <SymLink.h>
|
||||
#include <Messenger.h>
|
||||
#include <Directory.h>
|
||||
#include <Joystick.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Joystick.h>
|
||||
|
||||
#define JOYSTICKPATH "/dev/joystick/"
|
||||
#define JOYSTICKFILEPATH "/boot/beos/etc/joysticks/"
|
||||
#define JOYSTICKFILESETTINGS "/boot/home/config/settings/joysticks/"
|
||||
#define SELECTGAMEPORTFIRST "Select a game port first"
|
||||
|
||||
JoyWin::JoyWin(BRect frame, const char *title, window_look look,
|
||||
window_feel feel, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE)
|
||||
: BWindow(frame, title, look, feel, flags, workspace)
|
||||
static int
|
||||
ShowMessage(char* string)
|
||||
{
|
||||
fProbeButton = new BButton(BRect(15.00, 260.00, 115.00, 285.00), "ProbeButton", "Probe", NULL);
|
||||
fCalibrateButton = new BButton(BRect(270.00, 260.00, 370.00, 285.00), "CalibrateButton", "Calibrate", NULL);
|
||||
BAlert *alert = new BAlert("Message", string, "OK");
|
||||
alert->SetShortcut(1, B_ESCAPE);
|
||||
return alert->Go();
|
||||
}
|
||||
|
||||
fGamePortL = new BListView(BRect(15.00, 30.00, 145.00, 250.00), "gamePort");
|
||||
JoyWin::JoyWin(BRect frame, const char *title)
|
||||
: BWindow(frame, title, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
B_NOT_ZOOMABLE), fSystemUsedSelect(false),
|
||||
fJoystick(new BJoystick)
|
||||
{
|
||||
fProbeButton = new BButton(BRect(15.00, 260.00, 115.00, 285.00),
|
||||
"ProbeButton", "Probe", new BMessage(PROBE));
|
||||
|
||||
fCalibrateButton = new BButton(BRect(270.00, 260.00, 370.00, 285.00),
|
||||
"CalibrateButton", "Calibrate", new BMessage(CALIBRATE));
|
||||
|
||||
fGamePortL = new BListView(BRect(15.00, 30.00, 145.00, 250.00),
|
||||
"gamePort");
|
||||
fGamePortL->SetSelectionMessage(new BMessage(PORT_SELECTED));
|
||||
fGamePortL->SetInvocationMessage(new BMessage(PORT_INVOKE));
|
||||
|
||||
fConControllerL = new BListView(BRect(175.00,30.00,370.00,250.00),"conController");
|
||||
fConControllerL = new BListView(BRect(175.00,30.00,370.00,250.00),
|
||||
"conController");
|
||||
fConControllerL->SetSelectionMessage(new BMessage(JOY_SELECTED));
|
||||
fConControllerL->SetInvocationMessage(new BMessage(JOY_INVOKE));
|
||||
|
||||
fGamePortS = new BStringView(BRect(15, 5, 160, 25), "gpString", "Game Port");
|
||||
fGamePortS = new BStringView(BRect(15, 5, 160, 25), "gpString",
|
||||
"Game Port");
|
||||
fGamePortS->SetFont(be_bold_font);
|
||||
fConControllerS = new BStringView(BRect(170, 5, 330, 25), "ccString", "Connected Controller");
|
||||
fConControllerS = new BStringView(BRect(170, 5, 330, 25), "ccString",
|
||||
"Connected Controller");
|
||||
|
||||
fConControllerS->SetFont(be_bold_font);
|
||||
|
||||
fCheckbox = new BCheckBox(BRect(131.00, 260.00, 227.00, 280.00), "Disabled", "Disabled", NULL);
|
||||
fBox = new BBox( Bounds(),"box", B_FOLLOW_ALL,
|
||||
fCheckbox = new BCheckBox(BRect(131.00, 260.00, 227.00, 280.00),
|
||||
"Disabled", "Disabled", new BMessage(DISABLEPORT));
|
||||
BBox *box = new BBox( Bounds(),"box", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE,
|
||||
B_PLAIN_BORDER);
|
||||
fBox->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
// Adding object
|
||||
fBox->AddChild(fCheckbox);
|
||||
|
||||
fBox->AddChild(fGamePortS);
|
||||
fBox->AddChild(fConControllerS);
|
||||
|
||||
box->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
// Add listViews with their scrolls
|
||||
fBox->AddChild(new BScrollView("PortScroll", fGamePortL,
|
||||
box->AddChild(new BScrollView("PortScroll", fGamePortL,
|
||||
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW, false, true));
|
||||
fBox->AddChild(new BScrollView("ConScroll", fConControllerL,
|
||||
B_FOLLOW_ALL, B_WILL_DRAW, false, true));
|
||||
|
||||
box->AddChild(new BScrollView("ConScroll", fConControllerL, B_FOLLOW_ALL,
|
||||
B_WILL_DRAW, false, true));
|
||||
|
||||
fBox->AddChild(fProbeButton);
|
||||
fBox->AddChild(fCalibrateButton);
|
||||
|
||||
AddChild(fBox);
|
||||
|
||||
// This resizable feature is not in R5 but.
|
||||
// making horizontal resizing allows
|
||||
// long joysticks names to be seen completelly
|
||||
// Adding object
|
||||
box->AddChild(fCheckbox);
|
||||
box->AddChild(fGamePortS);
|
||||
box->AddChild(fConControllerS);
|
||||
box->AddChild(fProbeButton);
|
||||
box->AddChild(fCalibrateButton);
|
||||
AddChild(box);
|
||||
|
||||
SetSizeLimits(400, 600, Bounds().Height(), Bounds().Height());
|
||||
|
||||
/* Add all the devices */
|
||||
AddDevices();
|
||||
|
||||
/* Add all the devices */
|
||||
int32 nr = fJoystick->CountDevices();
|
||||
for (int32 i = 0; i < nr;i++) {
|
||||
//BString str(path.Path());
|
||||
char buf[B_OS_NAME_LENGTH];
|
||||
fJoystick->GetDeviceName(i, buf, B_OS_NAME_LENGTH);
|
||||
fGamePortL->AddItem(new PortItem(buf));
|
||||
}
|
||||
fGamePortL->Select(0);
|
||||
|
||||
/* Add the joysticks specifications */
|
||||
AddJoysticks();
|
||||
_AddToList(fConControllerL, JOY_SELECTED, JOYSTICKFILEPATH);
|
||||
|
||||
_GetSettings();
|
||||
}
|
||||
|
||||
|
||||
void JoyWin::MessageReceived(BMessage *message)
|
||||
JoyWin::~JoyWin()
|
||||
{
|
||||
//delete fFileTempProbeJoystick;
|
||||
be_app_messenger.SendMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
JoyWin::MessageReceived(BMessage *message)
|
||||
{
|
||||
// message->PrintToStream();
|
||||
switch(message->what)
|
||||
{
|
||||
{
|
||||
case DISABLEPORT:
|
||||
break;
|
||||
{
|
||||
PortItem *item = _GetSelectedItem(fGamePortL);
|
||||
if (item != NULL) {
|
||||
//ToDo: item->SetEnabled(true);
|
||||
//don't work as you can't select a item that are disabled
|
||||
if(fCheckbox->Value()) {
|
||||
item->SetEnabled(false);
|
||||
_SelectDeselectJoystick(fConControllerL, false);
|
||||
} else {
|
||||
item->SetEnabled(true);
|
||||
_SelectDeselectJoystick(fConControllerL, true);
|
||||
_PerformProbe(item->Text());
|
||||
}
|
||||
} //else
|
||||
//printf("We have a null value\n");
|
||||
break;
|
||||
}
|
||||
|
||||
case PORT_SELECTED:
|
||||
break;
|
||||
|
||||
case PORT_INVOKE:
|
||||
// Do we have any port?
|
||||
|
||||
// And some joysticks ?
|
||||
|
||||
// Probe!
|
||||
PerformProbe();
|
||||
|
||||
break;
|
||||
{
|
||||
PortItem *item = _GetSelectedItem(fGamePortL);
|
||||
if (item != NULL) {
|
||||
fSystemUsedSelect = true;
|
||||
if (item->IsEnabled()) {
|
||||
//printf("SetEnabled = false\n");
|
||||
fCheckbox->SetValue(false);
|
||||
_SelectDeselectJoystick(fConControllerL, true);
|
||||
} else {
|
||||
//printf("SetEnabled = true\n");
|
||||
fCheckbox->SetValue(true);
|
||||
_SelectDeselectJoystick(fConControllerL, false);
|
||||
}
|
||||
|
||||
if (_CheckJoystickExist(item->Text()) == B_ERROR) {
|
||||
if (_ShowCantFindFileMessage(item->Text()) == B_OK) {
|
||||
_PerformProbe(item->Text());
|
||||
}
|
||||
} else {
|
||||
BString str(_FindFilePathForSymLink(JOYSTICKFILESETTINGS,
|
||||
item));
|
||||
if (str != NULL) {
|
||||
BString str(_FixPathToName(str.String()));
|
||||
int32 id = _FindStringItemInList(fConControllerL,
|
||||
new PortItem(str.String()));
|
||||
if (id > -1) {
|
||||
fConControllerL->Select(id);
|
||||
item->SetJoystickName(BString(str.String()));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fConControllerL->DeselectAll();
|
||||
ShowMessage(SELECTGAMEPORTFIRST);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case PROBE:
|
||||
case PORT_INVOKE:
|
||||
{
|
||||
PortItem *item = _GetSelectedItem(fGamePortL);
|
||||
if (item != NULL) {
|
||||
//printf("invoke.. inte null\n");
|
||||
_PerformProbe(item->Text());
|
||||
} else
|
||||
ShowMessage(SELECTGAMEPORTFIRST);
|
||||
break;
|
||||
}
|
||||
|
||||
case JOY_SELECTED:
|
||||
break;
|
||||
|
||||
{
|
||||
if (!fSystemUsedSelect) {
|
||||
PortItem *controllerName = _GetSelectedItem(fConControllerL);
|
||||
PortItem *portname = _GetSelectedItem(fGamePortL);
|
||||
if (portname != NULL && controllerName != NULL) {
|
||||
portname->SetJoystickName(BString(controllerName->Text()));
|
||||
|
||||
BString str = portname->GetOldJoystickName();
|
||||
if (str != NULL) {
|
||||
BString strOldFile(JOYSTICKFILESETTINGS);
|
||||
strOldFile.Append(portname->Text());
|
||||
BEntry entry(strOldFile.String());
|
||||
entry.Remove();
|
||||
}
|
||||
BString strLinkPlace(JOYSTICKFILESETTINGS);
|
||||
strLinkPlace.Append(portname->Text());
|
||||
|
||||
BString strLinkTo(JOYSTICKFILEPATH);
|
||||
strLinkTo.Append(controllerName->Text());
|
||||
|
||||
BDirectory *dir = new BDirectory();
|
||||
dir->CreateSymLink(strLinkPlace.String(),
|
||||
strLinkTo.String(), NULL);
|
||||
} else
|
||||
ShowMessage(SELECTGAMEPORTFIRST);
|
||||
}
|
||||
|
||||
fSystemUsedSelect = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case CALIBRATE:
|
||||
case JOY_INVOKE:
|
||||
|
||||
// Do we have a selected definition?
|
||||
|
||||
// And a suitale selected port?
|
||||
|
||||
// Calibrate it!
|
||||
Calibrate();
|
||||
|
||||
break;
|
||||
|
||||
{
|
||||
PortItem *controllerName = _GetSelectedItem(fConControllerL);
|
||||
PortItem *portname = _GetSelectedItem(fGamePortL);
|
||||
if (portname != NULL) {
|
||||
if (controllerName == NULL)
|
||||
_ShowNoDeviceConnectedMessage("known", portname->Text());
|
||||
else {
|
||||
_ShowNoDeviceConnectedMessage(controllerName->Text(), portname->Text());
|
||||
/*
|
||||
ToDo:
|
||||
Check for a device, and show calibrate window if so
|
||||
*/
|
||||
}
|
||||
} else
|
||||
ShowMessage(SELECTGAMEPORTFIRST);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
break;
|
||||
@@ -119,104 +266,360 @@ void JoyWin::MessageReceived(BMessage *message)
|
||||
}
|
||||
|
||||
|
||||
bool JoyWin::QuitRequested()
|
||||
bool
|
||||
JoyWin::QuitRequested()
|
||||
{
|
||||
// Apply changes and save configurations etc etc
|
||||
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
|
||||
_ApplyChanges();
|
||||
return BWindow::QuitRequested();
|
||||
}
|
||||
|
||||
|
||||
/* Initialization */
|
||||
//---------------------- Private ---------------------------------//
|
||||
status_t
|
||||
JoyWin::AddDevices()
|
||||
{
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
int devId = 0;
|
||||
MessagedItem* device;
|
||||
BMessage* message;
|
||||
BString str;
|
||||
|
||||
while (!fJoystick.GetDeviceName(devId, name, sizeof(name))) {
|
||||
message = new BMessage(PORT_SELECTED);
|
||||
message->AddString("devname", name);
|
||||
// NOTE: Adding the index in the list might be useful.
|
||||
|
||||
// TODO: Change it with leaf path
|
||||
str.SetTo(name);
|
||||
//str = str.Remove(0, str.FindLast('/') );
|
||||
|
||||
device = new MessagedItem(str.String(), message);
|
||||
fGamePortL->AddItem(device);
|
||||
|
||||
devId++;
|
||||
}
|
||||
|
||||
/* TODO: Add the Disabled devices */
|
||||
|
||||
/* We do not have any Joystick dev */
|
||||
if (devId == 0) {
|
||||
// keep track of it
|
||||
// Alert it
|
||||
JoyWin::_AddToList(BListView *list, uint32 command,
|
||||
const char* rootPath, BEntry *rootEntry = NULL)
|
||||
{
|
||||
BDirectory root;
|
||||
|
||||
if ( rootEntry != NULL )
|
||||
root.SetTo( rootEntry );
|
||||
else if ( rootPath != NULL )
|
||||
root.SetTo( rootPath );
|
||||
else
|
||||
return B_ERROR;
|
||||
|
||||
BEntry entry;
|
||||
while ((root.GetNextEntry(&entry)) > B_ERROR ) {
|
||||
if (entry.IsDirectory()) {
|
||||
_AddToList(list, command, rootPath, &entry);
|
||||
} else {
|
||||
BPath path;
|
||||
entry.GetPath(&path);
|
||||
BString str(path.Path());
|
||||
str.RemoveFirst(rootPath);
|
||||
list->AddItem(new PortItem(str.String()));
|
||||
}
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t JoyWin::AddJoysticks()
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Management */
|
||||
status_t JoyWin::Calibrate()
|
||||
status_t
|
||||
JoyWin::_Calibrate()
|
||||
{
|
||||
CalibWin* calibw;
|
||||
|
||||
calibw = new CalibWin(BRect(100, 100, 500, 400), "Calibrate",
|
||||
B_DOCUMENT_WINDOW_LOOK,
|
||||
B_NORMAL_WINDOW_FEEL,
|
||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
|
||||
|
||||
BRect rect(100, 100, 500, 400);
|
||||
calibw = new CalibWin(rect, "Calibrate", B_DOCUMENT_WINDOW_LOOK,
|
||||
B_NORMAL_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
|
||||
calibw->Show();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t JoyWin::PerformProbe()
|
||||
status_t
|
||||
JoyWin::_PerformProbe(const char* path)
|
||||
{
|
||||
MessageWin* mesgw;
|
||||
|
||||
// [...]
|
||||
status_t err = B_ERROR;
|
||||
err = _ShowProbeMesage(path);
|
||||
if (err != B_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
mesgw = new MessageWin(Frame(),"Probing",
|
||||
B_MODAL_WINDOW_LOOK,
|
||||
B_MODAL_APP_WINDOW_FEEL,
|
||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE );
|
||||
|
||||
MessageWin* mesgw = new MessageWin(Frame(),"Probing", B_MODAL_WINDOW_LOOK,
|
||||
B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
|
||||
|
||||
mesgw->Show();
|
||||
mesgw->SetText("Looking for: X in port Y ...");
|
||||
int32 number = fConControllerL->CountItems();
|
||||
PortItem *item;
|
||||
for (int i = 0; i < number; i++) {
|
||||
// Do a search in JOYSTICKFILEPATH with item->Text() find the string
|
||||
// that starts with "gadget" (tex gadget = "GamePad Pro") remove
|
||||
// spacing and the "=" ty to open this one, if failed move to next and
|
||||
// try to open.. list those that suxesfully work
|
||||
fConControllerL->Select(i);
|
||||
int32 selected = fConControllerL->CurrentSelection();
|
||||
item = dynamic_cast<PortItem*>(fConControllerL->ItemAt(selected));
|
||||
BString str("Looking for: ");
|
||||
str << item->Text() << " in port " << path;
|
||||
mesgw->SetText(str.String());
|
||||
_FindSettingString(item->Text(), JOYSTICKFILEPATH);
|
||||
//Need a check to find joysticks (don't know how right now so show a
|
||||
// don't find message)
|
||||
}
|
||||
mesgw->Hide();
|
||||
|
||||
//Need a if !found then show this message. else list joysticks.
|
||||
_ShowNoCompatibleJoystickMessage();
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Configuration */
|
||||
status_t JoyWin::ApplyChanges()
|
||||
status_t
|
||||
JoyWin::_ApplyChanges()
|
||||
{
|
||||
BString str = _BuildDisabledJoysticksFile();
|
||||
//ToDo; Save the string as the file "disabled_joysticks" under settings
|
||||
// (/boot/home/config/settings/disabled_joysticks)
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Configuration */
|
||||
status_t JoyWin::GetSettings()
|
||||
status_t
|
||||
JoyWin::_GetSettings()
|
||||
{
|
||||
// ToDo; Read the file "disabled_joysticks" and make the port with the
|
||||
// same name disabled (/boot/home/config/settings/disabled_joysticks)
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
JoyWin::_CheckJoystickExist(const char* path)
|
||||
{
|
||||
BString str(JOYSTICKFILESETTINGS);
|
||||
str << path;
|
||||
|
||||
BFile file;
|
||||
status_t status = file.SetTo(str.String(), B_READ_ONLY | B_FAIL_IF_EXISTS);
|
||||
|
||||
if (status == B_FILE_EXISTS || status == B_OK)
|
||||
return B_OK;
|
||||
else
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
JoyWin::_ShowProbeMesage(const char* device)
|
||||
{
|
||||
BString str("An attempt will be made to probe the port '");
|
||||
str << device << "' to try to figure out what kind of joystick (if any) ";
|
||||
str << "are attached.There is a small chance this process might cause ";
|
||||
str << "your machine to lock up and require a reboot. Make sure you have ";
|
||||
str << "savedchanges in all open applications before you Probe";
|
||||
|
||||
BAlert *alert = new BAlert("test1", str.String(), "Probe", "Cancel");
|
||||
alert->SetShortcut(1, B_ESCAPE);
|
||||
int32 bindex = alert->Go();
|
||||
|
||||
if (bindex == 0)
|
||||
return B_OK;
|
||||
else
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
//Used when a files/joysticks are no were to be found
|
||||
status_t
|
||||
JoyWin::_ShowCantFindFileMessage(const char* port)
|
||||
{
|
||||
BString str("The file '");
|
||||
str << _FixPathToName(port).String() << "' used by '" << port;
|
||||
str << "' cannot be found.\n Do you want to ";
|
||||
str << "try to auto-detect a joystick for this port?";
|
||||
|
||||
BAlert *alert = new BAlert("test1", str.String(), "Stop", "Probe");
|
||||
alert->SetShortcut(1, B_ENTER);
|
||||
int32 bindex = alert->Go();
|
||||
|
||||
if (bindex == 1)
|
||||
return B_OK;
|
||||
else
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
JoyWin::_ShowNoCompatibleJoystickMessage()
|
||||
{
|
||||
BString str("There where no compatible joysticks detected on this game");
|
||||
str << " port. Try another port, or ask the manufacture of your jostick";
|
||||
str << " for a driver designed for Haiku or BeOS.";
|
||||
|
||||
BAlert *alert = new BAlert("test1", str.String(), "Ok");
|
||||
alert->SetShortcut(0, B_ENTER);
|
||||
alert->Go();
|
||||
}
|
||||
|
||||
void
|
||||
JoyWin::_ShowNoDeviceConnectedMessage(const char* joy, const char* port)
|
||||
{
|
||||
BString str("There does not appear to be a ");
|
||||
str << joy << " device connected to the port '" << port << "'.";
|
||||
|
||||
BAlert *alert = new BAlert("test1", str.String(), "Stop");
|
||||
alert->SetShortcut(0, B_ENTER);
|
||||
alert->Go();
|
||||
}
|
||||
|
||||
|
||||
// Use this function to get a string of disabled ports
|
||||
BString
|
||||
JoyWin::_BuildDisabledJoysticksFile()
|
||||
{
|
||||
BString temp("# This is a list of disabled joystick devices.");
|
||||
temp << "# Do not include the /dev/joystick/ part of the device name.";
|
||||
|
||||
int32 number = fGamePortL->CountItems();
|
||||
PortItem *item;
|
||||
for (int i = 0; i < number; i++) {
|
||||
item = dynamic_cast<PortItem*>(fGamePortL->ItemAt(i));
|
||||
if (!item->IsEnabled())
|
||||
temp << "disable = \"" << item->Text() << "\"";
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
PortItem*
|
||||
JoyWin::_GetSelectedItem(BListView* list)
|
||||
{
|
||||
int32 id = list->CurrentSelection();
|
||||
if (id > -1) {
|
||||
//PortItem *item = dynamic_cast<PortItem*>(list->ItemAt(id));
|
||||
return dynamic_cast<PortItem*>(list->ItemAt(id));
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BString
|
||||
JoyWin::_FixPathToName(const char* port)
|
||||
{
|
||||
BString temp(port);
|
||||
temp = temp.Remove(0, temp.FindLast('/') + 1) ;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
JoyWin::_SelectDeselectJoystick(BListView* list, bool enable)
|
||||
{
|
||||
list->DeselectAll();
|
||||
int32 number = fGamePortL->CountItems();
|
||||
PortItem *item;
|
||||
for (int i = 0; i < number; i++) {
|
||||
item = dynamic_cast<PortItem*>(list->ItemAt(i));
|
||||
item->SetEnabled(enable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
JoyWin::_FindStringItemInList(BListView *view, PortItem *item)
|
||||
{
|
||||
PortItem *strItem;
|
||||
int32 number = view->CountItems();
|
||||
for (int32 i = 0; i < number; i++) {
|
||||
strItem = dynamic_cast<PortItem*>(view->ItemAt(i));
|
||||
if (!strcmp(strItem->Text(), item->Text())) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
delete strItem;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
BString
|
||||
JoyWin::_FindFilePathForSymLink(const char* symLinkPath, PortItem *item)
|
||||
{
|
||||
BPath path(symLinkPath);
|
||||
path.Append(item->Text());
|
||||
BEntry entry(path.Path());
|
||||
if (entry.IsSymLink()) {
|
||||
BSymLink symLink(&entry);
|
||||
BDirectory parent;
|
||||
entry.GetParent(&parent);
|
||||
symLink.MakeLinkedPath(&parent, &path);
|
||||
BString str(path.Path());
|
||||
return str;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
JoyWin::_FindStick(const char* name)
|
||||
{
|
||||
BJoystick *stick = new BJoystick();
|
||||
return stick->Open(name);
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
JoyWin::_FindSettingString(const char* name, const char* strPath)
|
||||
{
|
||||
//Make a BJoystick try open it
|
||||
BString str;
|
||||
|
||||
BPath path(strPath);
|
||||
path.Append(name);
|
||||
fFileTempProbeJoystick = new BFile(path.Path(), B_READ_ONLY);
|
||||
|
||||
//status_t err = find_directory(B_COMMON_ETC_DIRECTORY, &path);
|
||||
// if (err == B_OK) {
|
||||
//BString str(path.Path());
|
||||
//str << "/joysticks/" << name;
|
||||
//printf("path'%s'\n", str.String());
|
||||
//err = file->SetTo(strPath, B_READ_ONLY);
|
||||
status_t err = fFileTempProbeJoystick->InitCheck();
|
||||
if (err == B_OK) {
|
||||
//FileReadWrite frw(fFileTempProbeJoystick);
|
||||
//printf("Get going\n");
|
||||
//printf("Opening file = %s\n", path.Path());
|
||||
//while (frw.Next(str)) {
|
||||
//printf("In While loop\n");
|
||||
// printf("getline %s \n", str.String());
|
||||
//Test to open joystick with x number
|
||||
//}
|
||||
/*while (_GetLine(str)) {
|
||||
//printf("In While loop\n");
|
||||
printf("getline %s \n", str.String());
|
||||
//Test to open joystick with x number
|
||||
}*/
|
||||
return "";
|
||||
} else
|
||||
printf("BFile.SetTo error: %s, Path = %s\n", strerror(err), str.String());
|
||||
// } else
|
||||
// printf("find_directory error: %s\n", strerror(err));
|
||||
|
||||
// delete file;
|
||||
return "";
|
||||
}
|
||||
|
||||
/*
|
||||
//Function to get a line from a file
|
||||
bool
|
||||
JoyWin::_GetLine(BString& string)
|
||||
{
|
||||
// Fill up the buffer with the first chunk of code
|
||||
if (fPositionInBuffer == 0)
|
||||
fAmtRead = fFileTempProbeJoystick->Read(&fBuffer, sizeof(fBuffer));
|
||||
while (fAmtRead > 0) {
|
||||
while (fPositionInBuffer < fAmtRead) {
|
||||
// Return true if we hit a newline or the end of the file
|
||||
if (fBuffer[fPositionInBuffer] == '\n') {
|
||||
fPositionInBuffer++;
|
||||
//Convert begin
|
||||
int32 state = 0;
|
||||
int32 bufferLen = string.Length();
|
||||
int32 destBufferLen = bufferLen;
|
||||
char destination[destBufferLen];
|
||||
// if (fSourceEncoding)
|
||||
// convert_to_utf8(fSourceEncoding, string.String(), &bufferLen, destination, &destBufferLen, &state);
|
||||
string = destination;
|
||||
return true;
|
||||
}
|
||||
string += fBuffer[fPositionInBuffer];
|
||||
fPositionInBuffer++;
|
||||
}
|
||||
|
||||
// Once the buffer runs out, grab some more and start again
|
||||
fAmtRead = fFileTempProbeJoystick->Read(&fBuffer, sizeof(fBuffer));
|
||||
fPositionInBuffer = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -1,61 +1,81 @@
|
||||
/*
|
||||
* Copyright 2007 Haiku.
|
||||
* Copyright 2007-2008 Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||
* Ryan Leavengood, [email protected]
|
||||
* Oliver Ruiz Dorantes oliver.ruiz.dorantes_at_gmail.com
|
||||
* Ryan Leavengood [email protected]
|
||||
* Fredrik Modéen [email protected]
|
||||
*/
|
||||
|
||||
#ifndef _JOY_WIN_H
|
||||
#define _JOY_WIN_H
|
||||
|
||||
|
||||
#include <Window.h>
|
||||
#include <Joystick.h>
|
||||
|
||||
class BView;
|
||||
class BJoystick;
|
||||
class BCheckBox;
|
||||
class BStringView;
|
||||
class BListView;
|
||||
class PortItem;
|
||||
class BButton;
|
||||
class BBox;
|
||||
class BEntry;
|
||||
class BFile;
|
||||
|
||||
|
||||
class JoyWin : public BWindow
|
||||
{
|
||||
class JoyWin : public BWindow {
|
||||
public:
|
||||
JoyWin(BRect frame,const char *title,
|
||||
window_look look,
|
||||
window_feel feel,
|
||||
uint32 flags,
|
||||
uint32 workspace = B_CURRENT_WORKSPACE);
|
||||
|
||||
JoyWin(BRect frame,const char *title);
|
||||
virtual ~JoyWin();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
protected:
|
||||
BJoystick fJoystick;
|
||||
private:
|
||||
status_t _AddToList(BListView *list, uint32 command,
|
||||
const char* rootPath, BEntry *rootEntry = NULL);
|
||||
|
||||
status_t _Calibrate();
|
||||
status_t _PerformProbe(const char* path);
|
||||
status_t _ApplyChanges();
|
||||
status_t _GetSettings();
|
||||
status_t _CheckJoystickExist(const char* path);
|
||||
|
||||
/*Show Alert Boxes*/
|
||||
status_t _ShowProbeMesage(const char* str);
|
||||
status_t _ShowCantFindFileMessage(const char* port);
|
||||
void _ShowNoDeviceConnectedMessage(const char* joy,
|
||||
const char* port);
|
||||
void _ShowNoCompatibleJoystickMessage();
|
||||
|
||||
/*Util*/
|
||||
BString _FixPathToName(const char* port);
|
||||
BString _BuildDisabledJoysticksFile();
|
||||
PortItem* _GetSelectedItem(BListView* list);
|
||||
void _SelectDeselectJoystick(BListView* list, bool enable);
|
||||
int32 _FindStringItemInList(BListView *view,
|
||||
PortItem *item);
|
||||
BString _FindFilePathForSymLink(const char* symLinkPath,
|
||||
PortItem *item);
|
||||
status_t _FindStick(const char* name);
|
||||
const char* _FindSettingString(const char* name, const char* strPath);
|
||||
bool _GetLine(BString& string);
|
||||
|
||||
BBox* fBox;
|
||||
//this one are used when we select joystick when portare selected
|
||||
bool fSystemUsedSelect;
|
||||
|
||||
BJoystick* fJoystick;
|
||||
BCheckBox* fCheckbox;
|
||||
|
||||
BStringView* fGamePortS;
|
||||
BStringView* fConControllerS;
|
||||
|
||||
BListView* fGamePortL;
|
||||
BListView* fConControllerL;
|
||||
|
||||
BButton* fCalibrateButton;
|
||||
BButton* fProbeButton;
|
||||
|
||||
status_t AddDevices();
|
||||
status_t AddJoysticks();
|
||||
status_t Calibrate();
|
||||
status_t PerformProbe();
|
||||
status_t ApplyChanges();
|
||||
status_t GetSettings();
|
||||
|
||||
|
||||
BFile* fFileTempProbeJoystick;
|
||||
// int32 fSourceEncoding;
|
||||
char fBuffer[4096];
|
||||
off_t fPositionInBuffer;
|
||||
ssize_t fAmtRead;
|
||||
};
|
||||
|
||||
#endif /* _JOY_WIN_H */
|
||||
|
||||
|
||||
@@ -11,43 +11,46 @@
|
||||
#include "Joysticks.h"
|
||||
#include "JoyWin.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
#include <Button.h>
|
||||
#include <Box.h>
|
||||
#include <StringView.h>
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Joysticks application("application/x-vnd.Haiku-Joysticks");
|
||||
|
||||
// Start Application
|
||||
application.Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Joysticks::Joysticks(const char *signature) : BApplication(signature)
|
||||
{
|
||||
|
||||
Joysticks::Joysticks(const char *signature)
|
||||
: BApplication(signature)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Joysticks::~Joysticks()
|
||||
{
|
||||
|
||||
be_app_messenger.SendMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
|
||||
|
||||
void Joysticks::ReadyToRun()
|
||||
bool
|
||||
Joysticks::QuitRequested()
|
||||
{
|
||||
fJoywin = new JoyWin(BRect(100, 100, 500, 400), "Joysticks",
|
||||
B_DOCUMENT_WINDOW_LOOK,
|
||||
B_NORMAL_WINDOW_FEEL,
|
||||
B_NOT_ZOOMABLE);
|
||||
|
||||
return BApplication::QuitRequested();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Joysticks::ReadyToRun()
|
||||
{
|
||||
fJoywin = new JoyWin(BRect(100, 100, 500, 400), "Joysticks");
|
||||
if (fJoywin != NULL)
|
||||
fJoywin->Show();
|
||||
else
|
||||
|
||||
@@ -23,6 +23,7 @@ class Joysticks : public BApplication
|
||||
~Joysticks();
|
||||
|
||||
virtual void ReadyToRun();
|
||||
virtual bool QuitRequested();
|
||||
|
||||
protected:
|
||||
JoyWin* fJoywin;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2008 Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Fredrik Modéen [email protected]
|
||||
*/
|
||||
|
||||
#include "PortItem.h"
|
||||
|
||||
PortItem::PortItem(const char* label)
|
||||
:BStringItem(label)
|
||||
{}
|
||||
|
||||
|
||||
PortItem::~PortItem()
|
||||
{}
|
||||
|
||||
void
|
||||
PortItem::DrawItem(BView *owner, BRect frame, bool complete = false)
|
||||
{
|
||||
BStringItem::DrawItem(owner, frame, complete);
|
||||
}
|
||||
|
||||
BString
|
||||
PortItem::GetOldJoystickName()
|
||||
{
|
||||
return fOldSelectedJoystick;
|
||||
}
|
||||
|
||||
|
||||
BString
|
||||
PortItem::GetJoystickName()
|
||||
{
|
||||
return fSelectedJoystick;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PortItem::SetJoystickName(BString str)
|
||||
{
|
||||
fOldSelectedJoystick = fSelectedJoystick;
|
||||
fSelectedJoystick = str;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2008 Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Fredrik Modéen [email protected]
|
||||
*/
|
||||
#ifndef PORT_ITEM_H
|
||||
#define PORT_ITEM_H
|
||||
|
||||
#include <ListItem.h>
|
||||
#include <String.h>
|
||||
|
||||
class PortItem : public BStringItem {
|
||||
public:
|
||||
PortItem(const char* label);
|
||||
~PortItem();
|
||||
virtual void DrawItem(BView *owner, BRect frame, bool complete = false);
|
||||
BString GetOldJoystickName();
|
||||
BString GetJoystickName();
|
||||
void SetJoystickName(BString str);
|
||||
protected:
|
||||
BString fOldSelectedJoystick;
|
||||
BString fSelectedJoystick;
|
||||
};
|
||||
|
||||
|
||||
#endif /* MESSAGED_ITEM_H */
|
||||
|
||||
Reference in New Issue
Block a user