summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/device/odevice.cpp
Unidiff
Diffstat (limited to 'libopie2/opiecore/device/odevice.cpp') (more/less context) (show 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
@@ -24,48 +24,49 @@
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "odevice_ipaq.h" 30#include "odevice_ipaq.h"
31#include "odevice_jornada.h" 31#include "odevice_jornada.h"
32#include "odevice_ramses.h" 32#include "odevice_ramses.h"
33#include "odevice_simpad.h" 33#include "odevice_simpad.h"
34#include "odevice_yopy.h" 34#include "odevice_yopy.h"
35#include "odevice_zaurus.h" 35#include "odevice_zaurus.h"
36 36
37/* QT */ 37/* QT */
38#include <qapplication.h> 38#include <qapplication.h>
39#include <qfile.h> 39#include <qfile.h>
40#include <qtextstream.h> 40#include <qtextstream.h>
41#include <qwindowsystem_qws.h> 41#include <qwindowsystem_qws.h>
42 42
43/* OPIE */ 43/* OPIE */
44#include <qpe/config.h> 44#include <qpe/config.h>
45#include <qpe/resource.h> 45#include <qpe/resource.h>
46#include <qpe/sound.h> 46#include <qpe/sound.h>
47#include <qpe/qcopenvelope_qws.h> 47#include <qpe/qcopenvelope_qws.h>
48#include <qpe/sound.h>
48#include <opie2/okeyfilter.h> 49#include <opie2/okeyfilter.h>
49 50
50/* STD */ 51/* STD */
51#include <fcntl.h> 52#include <fcntl.h>
52#include <math.h> 53#include <math.h>
53#include <stdlib.h> 54#include <stdlib.h>
54#include <signal.h> 55#include <signal.h>
55#include <sys/ioctl.h> 56#include <sys/ioctl.h>
56#include <sys/time.h> 57#include <sys/time.h>
57#include <unistd.h> 58#include <unistd.h>
58#ifndef QT_NO_SOUND 59#ifndef QT_NO_SOUND
59#include <linux/soundcard.h> 60#include <linux/soundcard.h>
60#endif 61#endif
61 62
62namespace Opie { 63namespace Opie {
63namespace Core { 64namespace Core {
64 65
65static const char* PATH_PROC_CPUINFO = "/proc/cpuinfo"; 66static const char* PATH_PROC_CPUINFO = "/proc/cpuinfo";
66 67
67 68
68/* STATIC and common implementation */ 69/* STATIC and common implementation */
69/* EXPORT */ ODistribution distributions[] = { 70/* EXPORT */ ODistribution distributions[] = {
70 { System_Familiar, "FamiliarLinux", "/etc/familiar-version" }, 71 { System_Familiar, "FamiliarLinux", "/etc/familiar-version" },
71 { System_OpenZaurus, "OpenZaurus", "/etc/oz_version" }, 72 { System_OpenZaurus, "OpenZaurus", "/etc/oz_version" },
@@ -150,48 +151,52 @@ ODevice *ODevice::inst()
150 if ( !dev ) dev = new ODevice(); 151 if ( !dev ) dev = new ODevice();
151 dev->init(cpu_info); 152 dev->init(cpu_info);
152 } 153 }
153 return dev; 154 return dev;
154} 155}
155 156
156ODevice::ODevice() 157ODevice::ODevice()
157{ 158{
158 d = new ODeviceData; 159 d = new ODeviceData;
159 160
160 d->m_modelstr = "Unknown"; 161 d->m_modelstr = "Unknown";
161 d->m_model = Model_Unknown; 162 d->m_model = Model_Unknown;
162 d->m_vendorstr = "Unknown"; 163 d->m_vendorstr = "Unknown";
163 d->m_vendor = Vendor_Unknown; 164 d->m_vendor = Vendor_Unknown;
164 d->m_systemstr = "Unknown"; 165 d->m_systemstr = "Unknown";
165 d->m_system = System_Unknown; 166 d->m_system = System_Unknown;
166 d->m_sysverstr = "0.0"; 167 d->m_sysverstr = "0.0";
167 d->m_rotation = Rot0; 168 d->m_rotation = Rot0;
168 d->m_direction = CW; 169 d->m_direction = CW;
169 170
170 d->m_holdtime = 1000; // 1000ms 171 d->m_holdtime = 1000; // 1000ms
171 d->m_buttons = 0; 172 d->m_buttons = 0;
172 d->m_cpu_frequencies = new QStrList; 173 d->m_cpu_frequencies = new QStrList;
173 174
175
176 /* mixer */
177 d->m_sound = d->m_vol = d->m_mixer = -1;
178
174 // New distribution detection code first checks for legacy distributions, 179 // New distribution detection code first checks for legacy distributions,
175 // identified by /etc/familiar-version or /etc/oz_version. 180 // identified by /etc/familiar-version or /etc/oz_version.
176 // Then check for OpenEmbedded and lastly, read /etc/issue 181 // Then check for OpenEmbedded and lastly, read /etc/issue
177 182
178 for ( unsigned int i = 0; i < sizeof distributions; ++i ) 183 for ( unsigned int i = 0; i < sizeof distributions; ++i )
179 { 184 {
180 if ( QFile::exists( distributions[i].sysvfile ) ) 185 if ( QFile::exists( distributions[i].sysvfile ) )
181 { 186 {
182 d->m_systemstr = distributions[i].sysstr; 187 d->m_systemstr = distributions[i].sysstr;
183 d->m_system = distributions[i].system; 188 d->m_system = distributions[i].system;
184 d->m_sysverstr = "<Unknown>"; 189 d->m_sysverstr = "<Unknown>";
185 QFile f( distributions[i].sysvfile ); 190 QFile f( distributions[i].sysvfile );
186 if ( f.open( IO_ReadOnly ) ) 191 if ( f.open( IO_ReadOnly ) )
187 { 192 {
188 QTextStream ts( &f ); 193 QTextStream ts( &f );
189 d->m_sysverstr = ts.readLine(); 194 d->m_sysverstr = ts.readLine();
190 } 195 }
191 break; 196 break;
192 } 197 }
193 } 198 }
194} 199}
195 200
196void ODevice::systemMessage( const QCString &msg, const QByteArray & ) 201void ODevice::systemMessage( const QCString &msg, const QByteArray & )
197{ 202{
@@ -684,45 +689,97 @@ void ODevice::remapPressedAction ( int button, const OQCopMessage &action )
684 689
685void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) 690void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
686{ 691{
687 initButtons(); 692 initButtons();
688 693
689 if ( button >= (int) d->m_buttons->count()) 694 if ( button >= (int) d->m_buttons->count())
690 return; 695 return;
691 696
692 ODeviceButton &b = ( *d->m_buttons ) [button]; 697 ODeviceButton &b = ( *d->m_buttons ) [button];
693 b. setHeldAction ( action ); 698 b. setHeldAction ( action );
694 699
695 Config buttonFile ( "ButtonSettings" ); 700 Config buttonFile ( "ButtonSettings" );
696 buttonFile. setGroup ( "Button" + QString::number ( button )); 701 buttonFile. setGroup ( "Button" + QString::number ( button ));
697 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction(). channel()); 702 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction(). channel());
698 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction(). message()); 703 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction(). message());
699 704
700// buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction(). data())); 705// buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction(). data()));
701 706
702 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 707 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
703} 708}
704void ODevice::virtual_hook(int, void* ){ 709void ODevice::virtual_hook(int, void* ){
705 710
706} 711}
707 712
713/**
714 * Sends a QCOP message to channel QPE/System
715 * with the message "aboutToSuspend()" if this
716 * is the windowing server
717 */
708void ODevice::sendSuspendmsg() 718void ODevice::sendSuspendmsg()
709{ 719{
710 if ( isQWS() ) 720 if ( isQWS() )
711 return; 721 return;
712 722
713 QCopEnvelope ( "QPE/System", "aboutToSuspend()" ); 723 QCopEnvelope ( "QPE/System", "aboutToSuspend()" );
714} 724}
715 725
726/**
727 * \brief Prepend the QWSServer::KeyboardFilter to the list of installed KeyFilters
728 *
729 * Prepend a QWSServer::KeyboardFilter to the List of Keyboard
730 * Filters. This function is the only way to prepend a KeyFilter.
731 *
732 * @param aFilter The KeyFilter to be prepended to the list of filters
733 *
734 * @see Opie::Core::OKeyFilter
735 * @see Opie::Core::OKeyFilter::inst()
736 */
716void ODevice::addPreHandler(QWSServer::KeyboardFilter*aFilter) 737void ODevice::addPreHandler(QWSServer::KeyboardFilter*aFilter)
717{ 738{
718 Opie::Core::OKeyFilter::inst()->addPreHandler(aFilter); 739 Opie::Core::OKeyFilter::inst()->addPreHandler(aFilter);
719} 740}
720 741
742/**
743 * \brief Remove the QWSServer::KeyboardFilter in the param from the list
744 *
745 * Remove the QWSServer::KeyboardFilter \par aFilter from the List
746 * of Keyfilters. Call this when you delete the KeyFilter!
747 *
748 * @param aFilter The filter to be removed from the Opie::Core::OKeyFilter
749 * @see Opie::Core::ODevice::addPreHandler
750 */
721void ODevice::remPreHandler(QWSServer::KeyboardFilter*aFilter) 751void ODevice::remPreHandler(QWSServer::KeyboardFilter*aFilter)
722{ 752{
723 Opie::Core::OKeyFilter::inst()->remPreHandler(aFilter); 753 Opie::Core::OKeyFilter::inst()->remPreHandler(aFilter);
724} 754}
725 755
756void ODevice::playingStopped() {
757 const_cast<QObject*>(sender())->disconnect( this );
758 if ( d->m_sound >= 0 ) {
759 ::ioctl ( d->m_sound, MIXER_WRITE( d->m_mixer ), &d->m_vol );
760 ::close ( d->m_sound );
761 }
762}
763
764void ODevice::changeMixerForAlarm( int mixer, const char* file, Sound *snd ) {
765 if (( d->m_sound = ::open ( file, O_RDWR )) >= 0 ) {
766 if ( ::ioctl ( d->m_sound, MIXER_READ( mixer ), &d->m_vol ) >= 0 ) {
767 Config cfg ( "qpe" );
768 cfg. setGroup ( "Volume" );
769
770 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
771 if ( volalarm < 0 )
772 volalarm = 0;
773 else if ( volalarm > 100 )
774 volalarm = 100;
775 volalarm |= ( volalarm << 8 );
776
777 if ( ::ioctl ( d->m_sound, MIXER_WRITE( mixer ), &volalarm ) >= 0 )
778 register_qpe_sound_finished(snd, this, SLOT(playingStopped()));
779 }
780 d->m_mixer = mixer;
781 }
782}
726 783
727} 784}
728} 785}