Files
haiku-beta6/src/preferences/keymap/KeymapApplication.cpp
T

160 lines
3.1 KiB
C++
Raw Normal View History

2004-07-14 16:10:25 +00:00
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2004, Haiku
//
// This software is part of the Haiku distribution and is covered
// by the Haiku license.
//
//
// File: KeymapApplication.cpp
// Author: Sandor Vroemisse, Jérôme Duval
// Description: Keymap Preferences
// Created : July 12, 2004
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#include <InputServerDevice.h>
#include <File.h>
#include <Application.h>
#include <Directory.h>
#include <Entry.h>
#include <Path.h>
2002-07-09 12:24:59 +00:00
#if DEBUG
#include <interface/Input.h>
#include <stdio.h>
2002-07-09 12:24:59 +00:00
#endif //DEBUG
#include "KeymapWindow.h"
#include "KeymapApplication.h"
#include <stdlib.h>
KeymapApplication::KeymapApplication()
: BApplication( APP_SIGNATURE )
{
// create the window
BRect frame = WINDOW_DIMENSIONS;
frame.OffsetTo( WINDOW_LEFT_TOP_POSITION );
fWindow = new KeymapWindow( frame );
fWindow->Show();
}
void KeymapApplication::MessageReceived( BMessage * message )
{
BApplication::MessageReceived( message );
}
2004-07-14 16:10:25 +00:00
/*bool
KeymapApplication::UseKeymap( BEntry *keymap )
2002-07-09 12:24:59 +00:00
{ // Copies keymap to ~/config/settings/key_map
BFile *inFile;
BFile *outFile;
// Open input file
if( !keymap->Exists() )
return false;
inFile = new BFile( keymap, B_READ_ONLY );
if( !inFile->IsReadable() ) {
delete inFile;
return false;
}
// Is keymap a valid keymap file?
if( !IsValidKeymap( inFile ) ) {
delete inFile;
return false;
}
// Open output file
// TODO: find a nice constant for the path and use that instead
outFile = new BFile( "/boot/home/config/settings/Key_map", B_WRITE_ONLY|B_ERASE_FILE|B_CREATE_FILE );
if( !outFile->IsWritable() ) {
delete inFile;
delete outFile;
return false;
}
// Copy file
if( Copy( inFile, outFile ) != B_OK ) {
delete inFile;
delete outFile;
return false;
}
delete inFile;
delete outFile;
// Tell Input Server there is a new keymap
if( NotifyInputServer() != B_OK )
return false;
return true;
}
2004-07-14 16:10:25 +00:00
bool
KeymapApplication::IsValidKeymap( BFile *inFile )
2002-07-09 12:24:59 +00:00
{
// TODO: implement this thing
return true;
}
2004-07-14 16:10:25 +00:00
int
KeymapApplication::Copy( BFile *original, BFile *copy )
2002-07-09 12:24:59 +00:00
{
char *buffer[ COPY_BUFFER_SIZE ];
int offset = 0;
int errorCode = B_NO_ERROR;
ssize_t nrBytesRead;
ssize_t nrBytesWritten;
while( true ) {
nrBytesRead = original->ReadAt( offset, buffer, COPY_BUFFER_SIZE );
if( nrBytesRead == 0 )
{
errorCode = B_OK;
break;
}
nrBytesWritten = copy->WriteAt( offset, buffer, nrBytesRead );
if( nrBytesWritten != nrBytesRead )
{
errorCode = B_ERROR;
break;
}
if( nrBytesRead < COPY_BUFFER_SIZE )
{
errorCode = B_OK;
break;
}
offset += nrBytesRead;
}
return errorCode;
2004-07-14 16:10:25 +00:00
}*/
2002-07-09 12:24:59 +00:00
2004-07-14 16:10:25 +00:00
int
KeymapApplication::NotifyInputServer()
2002-07-09 12:24:59 +00:00
{
// This took me days to find out. Go figure.
// Be didn't need to restart the thing - they prolly used
// a proprietary interface to notify it. Coordinate with
// the input_server guys.
system("kill -KILL input_server");
return B_NO_ERROR;
}
2004-07-03 17:51:51 +00:00
2004-07-14 16:10:25 +00:00
int
main ()
2004-07-03 17:51:51 +00:00
{
new KeymapApplication;
be_app->Run();
delete be_app;
2004-07-14 16:10:25 +00:00
return B_OK;
2004-07-03 17:51:51 +00:00
}