Diffstat (limited to 'libopie2/opiecore/device/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/device/odevice.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/libopie2/opiecore/device/odevice.cpp b/libopie2/opiecore/device/odevice.cpp index 8b64c41..67cae1c 100644 --- a/libopie2/opiecore/device/odevice.cpp +++ b/libopie2/opiecore/device/odevice.cpp | |||
@@ -132,155 +132,155 @@ ODevice *ODevice::inst() | |||
132 | QString line; | 132 | QString line; |
133 | line = s.readLine(); | 133 | line = s.readLine(); |
134 | if ( line.startsWith( "Hardware" ) ) | 134 | if ( line.startsWith( "Hardware" ) ) |
135 | { | 135 | { |
136 | qDebug( "ODevice() - found '%s'", (const char*) line ); | 136 | qDebug( "ODevice() - found '%s'", (const char*) line ); |
137 | cpu_info = line; | 137 | cpu_info = line; |
138 | if ( line.contains( "sharp", false ) ) dev = new Internal::Zaurus(); | 138 | if ( line.contains( "sharp", false ) ) dev = new Internal::Zaurus(); |
139 | else if ( line.contains( "ipaq", false ) ) dev = new Internal::iPAQ(); | 139 | else if ( line.contains( "ipaq", false ) ) dev = new Internal::iPAQ(); |
140 | else if ( line.contains( "simpad", false ) ) dev = new Internal::SIMpad(); | 140 | else if ( line.contains( "simpad", false ) ) dev = new Internal::SIMpad(); |
141 | else if ( line.contains( "jornada", false ) ) dev = new Internal::Jornada(); | 141 | else if ( line.contains( "jornada", false ) ) dev = new Internal::Jornada(); |
142 | else if ( line.contains( "ramses", false ) ) dev = new Internal::Ramses(); | 142 | else if ( line.contains( "ramses", false ) ) dev = new Internal::Ramses(); |
143 | else if ( line.contains( "Tradesquare.NL", false ) ) dev = new Internal::Beagle(); | 143 | else if ( line.contains( "Tradesquare.NL", false ) ) dev = new Internal::Beagle(); |
144 | else qWarning( "ODevice() - unknown hardware - using default." ); | 144 | else qWarning( "ODevice() - unknown hardware - using default." ); |
145 | break; | 145 | break; |
146 | } | 146 | } |
147 | } | 147 | } |
148 | } | 148 | } |
149 | else | 149 | else |
150 | { | 150 | { |
151 | qWarning( "ODevice() - can't open '%s' - unknown hardware - using default.", PATH_PROC_CPUINFO ); | 151 | qWarning( "ODevice() - can't open '%s' - unknown hardware - using default.", PATH_PROC_CPUINFO ); |
152 | } | 152 | } |
153 | if ( !dev ) dev = new ODevice(); | 153 | if ( !dev ) dev = new ODevice(); |
154 | dev->init(cpu_info); | 154 | dev->init(cpu_info); |
155 | } | 155 | } |
156 | return dev; | 156 | return dev; |
157 | } | 157 | } |
158 | 158 | ||
159 | ODevice::ODevice() | 159 | ODevice::ODevice() |
160 | { | 160 | { |
161 | d = new ODeviceData; | 161 | d = new ODeviceData; |
162 | 162 | ||
163 | d->m_modelstr = "Unknown"; | 163 | d->m_modelstr = "Unknown"; |
164 | d->m_model = Model_Unknown; | 164 | d->m_model = Model_Unknown; |
165 | d->m_vendorstr = "Unknown"; | 165 | d->m_vendorstr = "Unknown"; |
166 | d->m_vendor = Vendor_Unknown; | 166 | d->m_vendor = Vendor_Unknown; |
167 | d->m_systemstr = "Unknown"; | 167 | d->m_systemstr = "Unknown"; |
168 | d->m_system = System_Unknown; | 168 | d->m_system = System_Unknown; |
169 | d->m_sysverstr = "0.0"; | 169 | d->m_sysverstr = "0.0"; |
170 | d->m_rotation = Rot0; | 170 | d->m_rotation = Rot0; |
171 | d->m_direction = CW; | 171 | d->m_direction = CW; |
172 | 172 | ||
173 | d->m_holdtime = 1000; // 1000ms | 173 | d->m_holdtime = 1000; // 1000ms |
174 | d->m_buttons = 0; | 174 | d->m_buttons = 0; |
175 | d->m_cpu_frequencies = new QStrList; | 175 | d->m_cpu_frequencies = new QStrList; |
176 | 176 | ||
177 | 177 | ||
178 | /* mixer */ | 178 | /* mixer */ |
179 | d->m_sound = d->m_vol = d->m_mixer = -1; | 179 | d->m_sound = d->m_vol = d->m_mixer = -1; |
180 | |||
181 | /* System QCopChannel created */ | ||
182 | d->m_initializedButtonQcop = false; | ||
180 | 183 | ||
181 | // New distribution detection code first checks for legacy distributions, | 184 | // New distribution detection code first checks for legacy distributions, |
182 | // identified by /etc/familiar-version or /etc/oz_version. | 185 | // identified by /etc/familiar-version or /etc/oz_version. |
183 | // Then check for OpenEmbedded and lastly, read /etc/issue | 186 | // Then check for OpenEmbedded and lastly, read /etc/issue |
184 | 187 | ||
185 | for ( unsigned int i = 0; i < sizeof distributions; ++i ) | 188 | for ( unsigned int i = 0; i < sizeof distributions; ++i ) |
186 | { | 189 | { |
187 | if ( QFile::exists( distributions[i].sysvfile ) ) | 190 | if ( QFile::exists( distributions[i].sysvfile ) ) |
188 | { | 191 | { |
189 | d->m_systemstr = distributions[i].sysstr; | 192 | d->m_systemstr = distributions[i].sysstr; |
190 | d->m_system = distributions[i].system; | 193 | d->m_system = distributions[i].system; |
191 | d->m_sysverstr = "<Unknown>"; | 194 | d->m_sysverstr = "<Unknown>"; |
192 | QFile f( distributions[i].sysvfile ); | 195 | QFile f( distributions[i].sysvfile ); |
193 | if ( f.open( IO_ReadOnly ) ) | 196 | if ( f.open( IO_ReadOnly ) ) |
194 | { | 197 | { |
195 | QTextStream ts( &f ); | 198 | QTextStream ts( &f ); |
196 | d->m_sysverstr = ts.readLine().replace( QRegExp( "\\\\." ), "" ); | 199 | d->m_sysverstr = ts.readLine().replace( QRegExp( "\\\\." ), "" ); |
197 | } | 200 | } |
198 | break; | 201 | break; |
199 | } | 202 | } |
200 | } | 203 | } |
201 | } | 204 | } |
202 | 205 | ||
203 | void ODevice::systemMessage( const QCString &msg, const QByteArray & ) | 206 | void ODevice::systemMessage( const QCString &msg, const QByteArray & ) |
204 | { | 207 | { |
205 | if ( msg == "deviceButtonMappingChanged()" ) { | 208 | if ( msg == "deviceButtonMappingChanged()" ) { |
206 | reloadButtonMapping(); | 209 | reloadButtonMapping(); |
207 | } | 210 | } |
208 | } | 211 | } |
209 | 212 | ||
210 | void ODevice::init(const QString&) | 213 | void ODevice::init(const QString&) |
211 | { | 214 | { |
212 | } | 215 | } |
213 | 216 | ||
214 | /** | 217 | /** |
215 | * This method initialises the button mapping | 218 | * This method initialises the button mapping |
216 | */ | 219 | */ |
217 | void ODevice::initButtons() | 220 | void ODevice::initButtons() |
218 | { | 221 | { |
219 | if ( d->m_buttons ) | 222 | if ( d->m_buttons ) |
220 | return; | 223 | return; |
221 | 224 | ||
222 | qDebug ( "init Buttons" ); | 225 | qDebug ( "init Buttons" ); |
223 | d->m_buttons = new QValueList <ODeviceButton>; | 226 | d->m_buttons = new QValueList <ODeviceButton>; |
224 | for ( uint i = 0; i < ( sizeof( default_buttons ) / sizeof( default_button )); i++ ) { | 227 | for ( uint i = 0; i < ( sizeof( default_buttons ) / sizeof( default_button )); i++ ) { |
225 | default_button *db = default_buttons + i; | 228 | default_button *db = default_buttons + i; |
226 | ODeviceButton b; | 229 | ODeviceButton b; |
227 | b. setKeycode ( db->code ); | 230 | b. setKeycode ( db->code ); |
228 | b. setUserText ( QObject::tr ( "Button", db->utext )); | 231 | b. setUserText ( QObject::tr ( "Button", db->utext )); |
229 | b. setPixmap ( Resource::loadPixmap ( db->pix )); | 232 | b. setPixmap ( Resource::loadPixmap ( db->pix )); |
230 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( db->fpressedservice ), db->fpressedaction )); | 233 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( db->fpressedservice ), db->fpressedaction )); |
231 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( db->fheldservice ), db->fheldaction )); | 234 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( db->fheldservice ), db->fheldaction )); |
232 | d->m_buttons->append ( b ); | 235 | d->m_buttons->append ( b ); |
233 | } | 236 | } |
234 | 237 | ||
235 | reloadButtonMapping(); | 238 | reloadButtonMapping(); |
236 | |||
237 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | ||
238 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); | ||
239 | } | 239 | } |
240 | 240 | ||
241 | ODevice::~ODevice() | 241 | ODevice::~ODevice() |
242 | { | 242 | { |
243 | // we leak m_devicebuttons and m_cpu_frequency | 243 | // we leak m_devicebuttons and m_cpu_frequency |
244 | // but it's a singleton and it is not so importantant | 244 | // but it's a singleton and it is not so importantant |
245 | // -zecke | 245 | // -zecke |
246 | delete d; | 246 | delete d; |
247 | } | 247 | } |
248 | 248 | ||
249 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) | 249 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) |
250 | { | 250 | { |
251 | return false; | 251 | return false; |
252 | } | 252 | } |
253 | 253 | ||
254 | //#include <linux/apm_bios.h> | 254 | //#include <linux/apm_bios.h> |
255 | 255 | ||
256 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) | 256 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) |
257 | 257 | ||
258 | /** | 258 | /** |
259 | * This method will try to suspend the device | 259 | * This method will try to suspend the device |
260 | * It only works if the user is the QWS Server and the apm application | 260 | * It only works if the user is the QWS Server and the apm application |
261 | * is installed. | 261 | * is installed. |
262 | * It tries to suspend and then waits some time cause some distributions | 262 | * It tries to suspend and then waits some time cause some distributions |
263 | * do have asynchronus apm implementations. | 263 | * do have asynchronus apm implementations. |
264 | * This method will either fail and return false or it'll suspend the | 264 | * This method will either fail and return false or it'll suspend the |
265 | * device and return once the device got woken up | 265 | * device and return once the device got woken up |
266 | * | 266 | * |
267 | * @return if the device got suspended | 267 | * @return if the device got suspended |
268 | */ | 268 | */ |
269 | bool ODevice::suspend() | 269 | bool ODevice::suspend() |
270 | { | 270 | { |
271 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend | 271 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend |
272 | return false; | 272 | return false; |
273 | 273 | ||
274 | if ( d->m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices | 274 | if ( d->m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices |
275 | return false; | 275 | return false; |
276 | 276 | ||
277 | bool res = false; | 277 | bool res = false; |
278 | ODevice::sendSuspendmsg(); | 278 | ODevice::sendSuspendmsg(); |
279 | 279 | ||
280 | struct timeval tvs, tvn; | 280 | struct timeval tvs, tvn; |
281 | ::gettimeofday ( &tvs, 0 ); | 281 | ::gettimeofday ( &tvs, 0 ); |
282 | 282 | ||
283 | ::sync(); // flush fs caches | 283 | ::sync(); // flush fs caches |
284 | res = ( ::system ( "apm --suspend" ) == 0 ); | 284 | res = ( ::system ( "apm --suspend" ) == 0 ); |
285 | 285 | ||
286 | // This is needed because the iPAQ apm implementation is asynchronous and we | 286 | // This is needed because the iPAQ apm implementation is asynchronous and we |
@@ -600,96 +600,103 @@ bool ODevice::setCurrentCpuFrequency(uint index) | |||
600 | int res = (::write(fd, writeCommand, count) != -1); | 600 | int res = (::write(fd, writeCommand, count) != -1); |
601 | ::close(fd); | 601 | ::close(fd); |
602 | return res; | 602 | return res; |
603 | } | 603 | } |
604 | 604 | ||
605 | return false; | 605 | return false; |
606 | } | 606 | } |
607 | 607 | ||
608 | 608 | ||
609 | /** | 609 | /** |
610 | * @return a list of hardware buttons | 610 | * @return a list of hardware buttons |
611 | */ | 611 | */ |
612 | const QValueList <ODeviceButton> &ODevice::buttons() | 612 | const QValueList <ODeviceButton> &ODevice::buttons() |
613 | { | 613 | { |
614 | initButtons(); | 614 | initButtons(); |
615 | 615 | ||
616 | return *d->m_buttons; | 616 | return *d->m_buttons; |
617 | } | 617 | } |
618 | 618 | ||
619 | /** | 619 | /** |
620 | * @return The amount of time that would count as a hold | 620 | * @return The amount of time that would count as a hold |
621 | */ | 621 | */ |
622 | uint ODevice::buttonHoldTime() const | 622 | uint ODevice::buttonHoldTime() const |
623 | { | 623 | { |
624 | return d->m_holdtime; | 624 | return d->m_holdtime; |
625 | } | 625 | } |
626 | 626 | ||
627 | /** | 627 | /** |
628 | * This method return a ODeviceButton for a key code | 628 | * This method return a ODeviceButton for a key code |
629 | * or 0 if no special hardware button is available for the device | 629 | * or 0 if no special hardware button is available for the device |
630 | * | 630 | * |
631 | * @return The devicebutton or 0l | 631 | * @return The devicebutton or 0l |
632 | * @see ODeviceButton | 632 | * @see ODeviceButton |
633 | */ | 633 | */ |
634 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) | 634 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) |
635 | { | 635 | { |
636 | initButtons(); | 636 | initButtons(); |
637 | 637 | ||
638 | for ( QValueListConstIterator<ODeviceButton> it = d->m_buttons->begin(); it != d->m_buttons->end(); ++it ) { | 638 | for ( QValueListConstIterator<ODeviceButton> it = d->m_buttons->begin(); it != d->m_buttons->end(); ++it ) { |
639 | if ( (*it). keycode() == code ) | 639 | if ( (*it). keycode() == code ) |
640 | return &(*it); | 640 | return &(*it); |
641 | } | 641 | } |
642 | return 0; | 642 | return 0; |
643 | } | 643 | } |
644 | 644 | ||
645 | void ODevice::reloadButtonMapping() | 645 | void ODevice::reloadButtonMapping() |
646 | { | 646 | { |
647 | initButtons(); | 647 | initButtons(); |
648 | |||
649 | if(!d->m_initializedButtonQcop) { | ||
650 | QCopChannel *chan = new QCopChannel("QPE/System", this, "ODevice button channel"); | ||
651 | connect(chan,SIGNAL(received(const QCString&,const QByteArray&)), | ||
652 | this,SLOT(systemMessage(const QCString&,const QByteArray&))); | ||
653 | d->m_initializedButtonQcop = true; | ||
654 | } | ||
648 | 655 | ||
649 | Config cfg ( "ButtonSettings" ); | 656 | Config cfg ( "ButtonSettings" ); |
650 | 657 | ||
651 | for ( uint i = 0; i < d->m_buttons->count(); i++ ) { | 658 | for ( uint i = 0; i < d->m_buttons->count(); i++ ) { |
652 | ODeviceButton &b = ( *d->m_buttons ) [i]; | 659 | ODeviceButton &b = ( *d->m_buttons ) [i]; |
653 | QString group = "Button" + QString::number ( i ); | 660 | QString group = "Button" + QString::number ( i ); |
654 | 661 | ||
655 | QCString pch, hch; | 662 | QCString pch, hch; |
656 | QCString pm, hm; | 663 | QCString pm, hm; |
657 | QByteArray pdata, hdata; | 664 | QByteArray pdata, hdata; |
658 | 665 | ||
659 | if ( cfg. hasGroup ( group )) { | 666 | if ( cfg. hasGroup ( group )) { |
660 | cfg. setGroup ( group ); | 667 | cfg. setGroup ( group ); |
661 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1(); | 668 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1(); |
662 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1(); | 669 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1(); |
663 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); | 670 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); |
664 | 671 | ||
665 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1(); | 672 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1(); |
666 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1(); | 673 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1(); |
667 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); | 674 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); |
668 | } | 675 | } |
669 | 676 | ||
670 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); | 677 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); |
671 | 678 | ||
672 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); | 679 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); |
673 | } | 680 | } |
674 | } | 681 | } |
675 | 682 | ||
676 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) | 683 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) |
677 | { | 684 | { |
678 | initButtons(); | 685 | initButtons(); |
679 | 686 | ||
680 | QString mb_chan; | 687 | QString mb_chan; |
681 | 688 | ||
682 | if ( button >= (int) d->m_buttons->count()) | 689 | if ( button >= (int) d->m_buttons->count()) |
683 | return; | 690 | return; |
684 | 691 | ||
685 | ODeviceButton &b = ( *d->m_buttons ) [button]; | 692 | ODeviceButton &b = ( *d->m_buttons ) [button]; |
686 | b. setPressedAction ( action ); | 693 | b. setPressedAction ( action ); |
687 | 694 | ||
688 | mb_chan=b. pressedAction(). channel(); | 695 | mb_chan=b. pressedAction(). channel(); |
689 | 696 | ||
690 | Config buttonFile ( "ButtonSettings" ); | 697 | Config buttonFile ( "ButtonSettings" ); |
691 | buttonFile. setGroup ( "Button" + QString::number ( button )); | 698 | buttonFile. setGroup ( "Button" + QString::number ( button )); |
692 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); | 699 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); |
693 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction(). message()); | 700 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction(). message()); |
694 | 701 | ||
695 | // buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction(). data())); | 702 | // buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction(). data())); |