- Timestamp:
- Sep 20, 2006, 12:29:16 AM (18 years ago)
- Location:
- psi/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
psi/trunk/src/common.cpp
r50 r54 45 45 #include<qlibrary.h> 46 46 #include<qstylesheet.h> 47 48 #include<qthread.h> 49 #include<qmutex.h> 50 #include<qsemaphore.h> 51 #include<qvaluelist.h> 47 52 48 53 … … 1564 1569 } 1565 1570 1571 class BeepThread : public QThread 1572 { 1573 public: 1574 BeepThread() : sem(1), terminate(false) {} 1575 ~BeepThread() { while (sem.available() != sem.total()) sem--; } 1576 void run() { 1577 lock.lock(); 1578 while (!terminate) { 1579 while (!terminate && queue.count()) { 1580 Beep beep = queue.front(); 1581 queue.pop_front(); 1582 lock.unlock(); 1583 #if defined(Q_WS_WIN) 1584 if (beep.freq && beep.dur) 1585 Beep(beep.freq, beep.dur); 1586 else 1587 #elif defined(Q_WS_PM) 1588 if (beep.freq && beep.dur) 1589 DosBeep(beep.freq, beep.dur); 1590 else 1591 #endif 1592 QApplication::beep(); 1593 lock.lock(); 1594 } 1595 lock.unlock(); 1596 sem++; 1597 lock.lock(); 1598 } 1599 lock.unlock(); 1600 } 1601 void add(ulong freq, ulong dur) { 1602 lock.lock(); 1603 queue.push_back(Beep(freq, dur)); 1604 lock.unlock(); 1605 if (!sem.available()) 1606 sem--; 1607 } 1608 void stop() { 1609 lock.lock(); 1610 terminate = true; 1611 lock.unlock(); 1612 if (!sem.available()) 1613 sem--; 1614 wait(); 1615 } 1616 private: 1617 struct Beep { 1618 Beep() : freq(0), dur(0) {} 1619 Beep(ulong f, ulong d) : freq(f), dur(d) {} 1620 const ulong freq; 1621 const ulong dur; 1622 }; 1623 QMutex lock; 1624 QSemaphore sem; 1625 QValueList<Beep> queue; 1626 bool terminate; 1627 }; 1628 1629 static BeepThread *beepThread = 0; 1630 1631 static void cleanupBeepThread() 1632 { 1633 if (beepThread) { 1634 beepThread->stop(); 1635 delete beepThread; 1636 beepThread = 0; 1637 } 1638 } 1566 1639 1567 1640 void soundPlay(const QString &str) 1568 1641 { 1569 if(str == "!beep") { 1570 QApplication::beep(); 1571 return; 1642 if(str.startsWith("!beep")) { 1643 QStringList list = QStringList::split(':',str); 1644 if (list[0].length() == 5 /* strlen("!beep") */) { 1645 ulong freq = 0, dur = 0; 1646 if (list.count() == 3) { 1647 freq = list[1].toULong(); 1648 dur = list[2].toULong(); 1649 if (freq < 0x25 || freq > 0x7FFF || 1650 dur == 0 || dur > 3000 /* 3s is the reasonable maximum */) 1651 freq = dur = 0; 1652 } 1653 if (beepThread == 0) { 1654 beepThread = new BeepThread(); 1655 if (beepThread) { 1656 qAddPostRoutine(cleanupBeepThread); 1657 beepThread->start(); 1658 } 1659 } 1660 if (beepThread) 1661 beepThread->add(freq, dur); 1662 return; 1663 } 1572 1664 } 1573 1665 -
psi/trunk/src/options/opt_sound-ui.ui
r2 r54 103 103 </property> 104 104 <property name="toolTip" stdset="0"> 105 <string>Enter a filename or !beepfor a system beep</string>105 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 106 106 </property> 107 107 </widget> … … 119 119 </property> 120 120 <property name="toolTip" stdset="0"> 121 <string>Enter a filename or !beepfor a system beep</string>121 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 122 122 </property> 123 123 </widget> … … 135 135 </property> 136 136 <property name="toolTip" stdset="0"> 137 <string>Enter a filename or !beepfor a system beep</string>137 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 138 138 </property> 139 139 </widget> … … 159 159 </property> 160 160 <property name="toolTip" stdset="0"> 161 <string>Enter a filename or !beepfor a system beep</string>161 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 162 162 </property> 163 163 </widget> … … 207 207 </property> 208 208 <property name="toolTip" stdset="0"> 209 <string>Enter a filename or !beepfor a system beep</string>209 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 210 210 </property> 211 211 </widget> … … 239 239 </property> 240 240 <property name="toolTip" stdset="0"> 241 <string>Enter a filename or !beepfor a system beep</string>241 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 242 242 </property> 243 243 </widget> … … 319 319 </property> 320 320 <property name="toolTip" stdset="0"> 321 <string>Enter a filename or !beepfor a system beep</string>321 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 322 322 </property> 323 323 </widget> … … 343 343 </property> 344 344 <property name="toolTip" stdset="0"> 345 <string>Enter a filename or !beepfor a system beep</string>345 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 346 346 </property> 347 347 </widget> … … 351 351 </property> 352 352 <property name="toolTip" stdset="0"> 353 <string>Enter a filename or !beepfor a system beep</string>353 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 354 354 </property> 355 355 </widget> … … 367 367 </property> 368 368 <property name="toolTip" stdset="0"> 369 <string>Enter a filename or !beepfor a system beep</string>369 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 370 370 </property> 371 371 </widget> -
psi/trunk/src/options/opt_sound_events.ui
r2 r54 68 68 </property> 69 69 <property name="toolTip" stdset="0"> 70 <string>Enter a filename or !beepfor a system beep</string>70 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 71 71 </property> 72 72 </widget> … … 84 84 </property> 85 85 <property name="toolTip" stdset="0"> 86 <string>Enter a filename or !beepfor a system beep</string>86 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 87 87 </property> 88 88 </widget> … … 140 140 </property> 141 141 <property name="toolTip" stdset="0"> 142 <string>Enter a filename or !beepfor a system beep</string>142 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 143 143 </property> 144 144 </widget> … … 164 164 </property> 165 165 <property name="toolTip" stdset="0"> 166 <string>Enter a filename or !beepfor a system beep</string>166 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 167 167 </property> 168 168 </widget> … … 212 212 </property> 213 213 <property name="toolTip" stdset="0"> 214 <string>Enter a filename or !beepfor a system beep</string>214 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 215 215 </property> 216 216 </widget> … … 244 244 </property> 245 245 <property name="toolTip" stdset="0"> 246 <string>Enter a filename or !beepfor a system beep</string>246 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 247 247 </property> 248 248 </widget> … … 252 252 </property> 253 253 <property name="toolTip" stdset="0"> 254 <string>Enter a filename or !beepfor a system beep</string>254 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 255 255 </property> 256 256 </widget> … … 268 268 </property> 269 269 <property name="toolTip" stdset="0"> 270 <string>Enter a filename or !beepfor a system beep</string>270 <string>Enter a filename or <tt>!beep[:freq:duration]</tt> for a system beep</string> 271 271 </property> 272 272 </widget>
Note:
See TracChangeset
for help on using the changeset viewer.