summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/device/odevice.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opiecore/device/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/libopie2/opiecore/device/odevice.cpp b/libopie2/opiecore/device/odevice.cpp
index b58f9eb..26c6dca 100644
--- a/libopie2/opiecore/device/odevice.cpp
+++ b/libopie2/opiecore/device/odevice.cpp
@@ -1,95 +1,96 @@
/*
                This file is part of the Opie Project
              Copyright (C) The Opie Team <opie-devel@handhelds.org>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "odevice_ipaq.h"
#include "odevice_jornada.h"
#include "odevice_ramses.h"
#include "odevice_simpad.h"
#include "odevice_yopy.h"
#include "odevice_zaurus.h"
/* QT */
#include <qapplication.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qwindowsystem_qws.h>
/* OPIE */
#include <qpe/config.h>
#include <qpe/resource.h>
#include <qpe/sound.h>
#include <qpe/qcopenvelope_qws.h>
+#include <qpe/sound.h>
#include <opie2/okeyfilter.h>
/* STD */
#include <fcntl.h>
#include <math.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <unistd.h>
#ifndef QT_NO_SOUND
#include <linux/soundcard.h>
#endif
namespace Opie {
namespace Core {
static const char* PATH_PROC_CPUINFO = "/proc/cpuinfo";
/* STATIC and common implementation */
/* EXPORT */ ODistribution distributions[] = {
{ System_Familiar, "FamiliarLinux", "/etc/familiar-version" },
{ System_OpenZaurus, "OpenZaurus", "/etc/oz_version" },
{ System_OpenEmbedded, "OpenEmbedded", "/etc/oe-version" },
{ System_Unknown, "Linux", "/etc/issue" },
};
/* EXPORT */ bool isQWS(){
return qApp ? ( qApp->type() == QApplication::GuiServer ) : false;
}
/* EXPORT */ QCString makeChannel ( const char *str ){
if ( str && !::strchr ( str, '/' ))
return QCString ( "QPE/Application/" ) + str;
else
return str;
}
/* Now the default implementation of ODevice */
struct default_button default_buttons [] = {
{ Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
"devicebuttons/z_calendar",
"datebook", "nextView()",
@@ -126,96 +127,100 @@ ODevice *ODevice::inst()
{
QTextStream s( &f );
while ( !s.atEnd() )
{
QString line;
line = s.readLine();
if ( line.startsWith( "Hardware" ) )
{
qDebug( "ODevice() - found '%s'", (const char*) line );
cpu_info = line;
if ( line.contains( "sharp", false ) ) dev = new Internal::Zaurus();
else if ( line.contains( "ipaq", false ) ) dev = new Internal::iPAQ();
else if ( line.contains( "simpad", false ) ) dev = new Internal::SIMpad();
else if ( line.contains( "jornada", false ) ) dev = new Internal::Jornada();
else if ( line.contains( "ramses", false ) ) dev = new Internal::Ramses();
else qWarning( "ODevice() - unknown hardware - using default." );
break;
}
}
}
else
{
qWarning( "ODevice() - can't open '%s' - unknown hardware - using default.", PATH_PROC_CPUINFO );
}
if ( !dev ) dev = new ODevice();
dev->init(cpu_info);
}
return dev;
}
ODevice::ODevice()
{
d = new ODeviceData;
d->m_modelstr = "Unknown";
d->m_model = Model_Unknown;
d->m_vendorstr = "Unknown";
d->m_vendor = Vendor_Unknown;
d->m_systemstr = "Unknown";
d->m_system = System_Unknown;
d->m_sysverstr = "0.0";
d->m_rotation = Rot0;
d->m_direction = CW;
d->m_holdtime = 1000; // 1000ms
d->m_buttons = 0;
d->m_cpu_frequencies = new QStrList;
+
+ /* mixer */
+ d->m_sound = d->m_vol = d->m_mixer = -1;
+
// New distribution detection code first checks for legacy distributions,
// identified by /etc/familiar-version or /etc/oz_version.
// Then check for OpenEmbedded and lastly, read /etc/issue
for ( unsigned int i = 0; i < sizeof distributions; ++i )
{
if ( QFile::exists( distributions[i].sysvfile ) )
{
d->m_systemstr = distributions[i].sysstr;
d->m_system = distributions[i].system;
d->m_sysverstr = "<Unknown>";
QFile f( distributions[i].sysvfile );
if ( f.open( IO_ReadOnly ) )
{
QTextStream ts( &f );
d->m_sysverstr = ts.readLine();
}
break;
}
}
}
void ODevice::systemMessage( const QCString &msg, const QByteArray & )
{
if ( msg == "deviceButtonMappingChanged()" ) {
reloadButtonMapping();
}
}
void ODevice::init(const QString&)
{
}
/**
* This method initialises the button mapping
*/
void ODevice::initButtons()
{
if ( d->m_buttons )
return;
qDebug ( "init Buttons" );
d->m_buttons = new QValueList <ODeviceButton>;
for ( uint i = 0; i < ( sizeof( default_buttons ) / sizeof( default_button )); i++ ) {
default_button *db = default_buttons + i;
ODeviceButton b;
b. setKeycode ( db->code );
b. setUserText ( QObject::tr ( "Button", db->utext ));
@@ -660,69 +665,121 @@ void ODevice::reloadButtonMapping()
void ODevice::remapPressedAction ( int button, const OQCopMessage &action )
{
initButtons();
QString mb_chan;
if ( button >= (int) d->m_buttons->count())
return;
ODeviceButton &b = ( *d->m_buttons ) [button];
b. setPressedAction ( action );
mb_chan=b. pressedAction(). channel();
Config buttonFile ( "ButtonSettings" );
buttonFile. setGroup ( "Button" + QString::number ( button ));
buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan);
buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction(). message());
// buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction(). data()));
QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
}
void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
{
initButtons();
if ( button >= (int) d->m_buttons->count())
return;
ODeviceButton &b = ( *d->m_buttons ) [button];
b. setHeldAction ( action );
Config buttonFile ( "ButtonSettings" );
buttonFile. setGroup ( "Button" + QString::number ( button ));
buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction(). channel());
buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction(). message());
// buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction(). data()));
QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
}
void ODevice::virtual_hook(int, void* ){
}
+/**
+ * Sends a QCOP message to channel QPE/System
+ * with the message "aboutToSuspend()" if this
+ * is the windowing server
+ */
void ODevice::sendSuspendmsg()
{
if ( isQWS() )
return;
QCopEnvelope ( "QPE/System", "aboutToSuspend()" );
}
+/**
+ * \brief Prepend the QWSServer::KeyboardFilter to the list of installed KeyFilters
+ *
+ * Prepend a QWSServer::KeyboardFilter to the List of Keyboard
+ * Filters. This function is the only way to prepend a KeyFilter.
+ *
+ * @param aFilter The KeyFilter to be prepended to the list of filters
+ *
+ * @see Opie::Core::OKeyFilter
+ * @see Opie::Core::OKeyFilter::inst()
+ */
void ODevice::addPreHandler(QWSServer::KeyboardFilter*aFilter)
{
Opie::Core::OKeyFilter::inst()->addPreHandler(aFilter);
}
+/**
+ * \brief Remove the QWSServer::KeyboardFilter in the param from the list
+ *
+ * Remove the QWSServer::KeyboardFilter \par aFilter from the List
+ * of Keyfilters. Call this when you delete the KeyFilter!
+ *
+ * @param aFilter The filter to be removed from the Opie::Core::OKeyFilter
+ * @see Opie::Core::ODevice::addPreHandler
+ */
void ODevice::remPreHandler(QWSServer::KeyboardFilter*aFilter)
{
Opie::Core::OKeyFilter::inst()->remPreHandler(aFilter);
}
+void ODevice::playingStopped() {
+ const_cast<QObject*>(sender())->disconnect( this );
+ if ( d->m_sound >= 0 ) {
+ ::ioctl ( d->m_sound, MIXER_WRITE( d->m_mixer ), &d->m_vol );
+ ::close ( d->m_sound );
+ }
+}
+
+void ODevice::changeMixerForAlarm( int mixer, const char* file, Sound *snd ) {
+ if (( d->m_sound = ::open ( file, O_RDWR )) >= 0 ) {
+ if ( ::ioctl ( d->m_sound, MIXER_READ( mixer ), &d->m_vol ) >= 0 ) {
+ Config cfg ( "qpe" );
+ cfg. setGroup ( "Volume" );
+
+ int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
+ if ( volalarm < 0 )
+ volalarm = 0;
+ else if ( volalarm > 100 )
+ volalarm = 100;
+ volalarm |= ( volalarm << 8 );
+
+ if ( ::ioctl ( d->m_sound, MIXER_WRITE( mixer ), &volalarm ) >= 0 )
+ register_qpe_sound_finished(snd, this, SLOT(playingStopped()));
+ }
+ d->m_mixer = mixer;
+ }
+}
}
}