summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/modplug/sndfile.cpp5
-rw-r--r--core/multimedia/opieplayer/vorbis/tremor/block.c6
-rw-r--r--core/multimedia/opieplayer/vorbis/tremor/info.c2
-rw-r--r--noncore/apps/opie-write/qrichtext.cpp69
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp3
-rw-r--r--noncore/settings/packagemanager/oipkgconfigdlg.cpp6
6 files changed, 62 insertions, 29 deletions
diff --git a/core/multimedia/opieplayer/modplug/sndfile.cpp b/core/multimedia/opieplayer/modplug/sndfile.cpp
index 1d0d610..799555c 100644
--- a/core/multimedia/opieplayer/modplug/sndfile.cpp
+++ b/core/multimedia/opieplayer/modplug/sndfile.cpp
@@ -1550,326 +1550,329 @@ void CSoundFile::AdjustSampleLoop(MODINSTRUMENT *pIns)
1550 { 1550 {
1551 pSample[len+4] = pSample[len+3] = pSample[len+2] = pSample[len+1] = pSample[len] = pSample[len-1]; 1551 pSample[len+4] = pSample[len+3] = pSample[len+2] = pSample[len+1] = pSample[len] = pSample[len-1];
1552 } 1552 }
1553 if ((pIns->uFlags & (CHN_LOOP|CHN_PINGPONGLOOP|CHN_STEREO)) == CHN_LOOP) 1553 if ((pIns->uFlags & (CHN_LOOP|CHN_PINGPONGLOOP|CHN_STEREO)) == CHN_LOOP)
1554 { 1554 {
1555 // Fix bad loops 1555 // Fix bad loops
1556 if ((pIns->nLoopEnd+3 >= pIns->nLength) || (m_nType & MOD_TYPE_S3M)) 1556 if ((pIns->nLoopEnd+3 >= pIns->nLength) || (m_nType & MOD_TYPE_S3M))
1557 { 1557 {
1558 pSample[pIns->nLoopEnd] = pSample[pIns->nLoopStart]; 1558 pSample[pIns->nLoopEnd] = pSample[pIns->nLoopStart];
1559 pSample[pIns->nLoopEnd+1] = pSample[pIns->nLoopStart+1]; 1559 pSample[pIns->nLoopEnd+1] = pSample[pIns->nLoopStart+1];
1560 pSample[pIns->nLoopEnd+2] = pSample[pIns->nLoopStart+2]; 1560 pSample[pIns->nLoopEnd+2] = pSample[pIns->nLoopStart+2];
1561 pSample[pIns->nLoopEnd+3] = pSample[pIns->nLoopStart+3]; 1561 pSample[pIns->nLoopEnd+3] = pSample[pIns->nLoopStart+3];
1562 pSample[pIns->nLoopEnd+4] = pSample[pIns->nLoopStart+4]; 1562 pSample[pIns->nLoopEnd+4] = pSample[pIns->nLoopStart+4];
1563 } 1563 }
1564 } 1564 }
1565 } else 1565 } else
1566 { 1566 {
1567 signed char *pSample = pIns->pSample; 1567 signed char *pSample = pIns->pSample;
1568#ifndef FASTSOUNDLIB 1568#ifndef FASTSOUNDLIB
1569 // Crappy samples (except chiptunes) ? 1569 // Crappy samples (except chiptunes) ?
1570 if ((pIns->nLength > 0x100) && (m_nType & (MOD_TYPE_MOD|MOD_TYPE_S3M)) 1570 if ((pIns->nLength > 0x100) && (m_nType & (MOD_TYPE_MOD|MOD_TYPE_S3M))
1571 && (!(pIns->uFlags & CHN_STEREO))) 1571 && (!(pIns->uFlags & CHN_STEREO)))
1572 { 1572 {
1573 int smpend = pSample[pIns->nLength-1], smpfix = 0, kscan; 1573 int smpend = pSample[pIns->nLength-1], smpfix = 0, kscan;
1574 for (kscan=pIns->nLength-1; kscan>0; kscan--) 1574 for (kscan=pIns->nLength-1; kscan>0; kscan--)
1575 { 1575 {
1576 smpfix = pSample[kscan-1]; 1576 smpfix = pSample[kscan-1];
1577 if (smpfix != smpend) break; 1577 if (smpfix != smpend) break;
1578 } 1578 }
1579 int delta = smpfix - smpend; 1579 int delta = smpfix - smpend;
1580 if (((!(pIns->uFlags & CHN_LOOP)) || (kscan > (int)pIns->nLoopEnd)) 1580 if (((!(pIns->uFlags & CHN_LOOP)) || (kscan > (int)pIns->nLoopEnd))
1581 && ((delta < -8) || (delta > 8))) 1581 && ((delta < -8) || (delta > 8)))
1582 { 1582 {
1583 while (kscan<(int)pIns->nLength) 1583 while (kscan<(int)pIns->nLength)
1584 { 1584 {
1585 if (!(kscan & 7)) 1585 if (!(kscan & 7))
1586 { 1586 {
1587 if (smpfix > 0) smpfix--; 1587 if (smpfix > 0) smpfix--;
1588 if (smpfix < 0) smpfix++; 1588 if (smpfix < 0) smpfix++;
1589 } 1589 }
1590 pSample[kscan] = (signed char)smpfix; 1590 pSample[kscan] = (signed char)smpfix;
1591 kscan++; 1591 kscan++;
1592 } 1592 }
1593 } 1593 }
1594 } 1594 }
1595#endif 1595#endif
1596 // Adjust end of sample 1596 // Adjust end of sample
1597 if (pIns->uFlags & CHN_STEREO) 1597 if (pIns->uFlags & CHN_STEREO)
1598 { 1598 {
1599 pSample[len*2+6] = pSample[len*2+4] = pSample[len*2+2] = pSample[len*2] = pSample[len*2-2]; 1599 pSample[len*2+6] = pSample[len*2+4] = pSample[len*2+2] = pSample[len*2] = pSample[len*2-2];
1600 pSample[len*2+7] = pSample[len*2+5] = pSample[len*2+3] = pSample[len*2+1] = pSample[len*2-1]; 1600 pSample[len*2+7] = pSample[len*2+5] = pSample[len*2+3] = pSample[len*2+1] = pSample[len*2-1];
1601 } else 1601 } else
1602 { 1602 {
1603 pSample[len+4] = pSample[len+3] = pSample[len+2] = pSample[len+1] = pSample[len] = pSample[len-1]; 1603 pSample[len+4] = pSample[len+3] = pSample[len+2] = pSample[len+1] = pSample[len] = pSample[len-1];
1604 } 1604 }
1605 if ((pIns->uFlags & (CHN_LOOP|CHN_PINGPONGLOOP|CHN_STEREO)) == CHN_LOOP) 1605 if ((pIns->uFlags & (CHN_LOOP|CHN_PINGPONGLOOP|CHN_STEREO)) == CHN_LOOP)
1606 { 1606 {
1607 if ((pIns->nLoopEnd+3 >= pIns->nLength) || (m_nType & (MOD_TYPE_MOD|MOD_TYPE_S3M))) 1607 if ((pIns->nLoopEnd+3 >= pIns->nLength) || (m_nType & (MOD_TYPE_MOD|MOD_TYPE_S3M)))
1608 { 1608 {
1609 pSample[pIns->nLoopEnd] = pSample[pIns->nLoopStart]; 1609 pSample[pIns->nLoopEnd] = pSample[pIns->nLoopStart];
1610 pSample[pIns->nLoopEnd+1] = pSample[pIns->nLoopStart+1]; 1610 pSample[pIns->nLoopEnd+1] = pSample[pIns->nLoopStart+1];
1611 pSample[pIns->nLoopEnd+2] = pSample[pIns->nLoopStart+2]; 1611 pSample[pIns->nLoopEnd+2] = pSample[pIns->nLoopStart+2];
1612 pSample[pIns->nLoopEnd+3] = pSample[pIns->nLoopStart+3]; 1612 pSample[pIns->nLoopEnd+3] = pSample[pIns->nLoopStart+3];
1613 pSample[pIns->nLoopEnd+4] = pSample[pIns->nLoopStart+4]; 1613 pSample[pIns->nLoopEnd+4] = pSample[pIns->nLoopStart+4];
1614 } 1614 }
1615 } 1615 }
1616 } 1616 }
1617} 1617}
1618 1618
1619 1619
1620///////////////////////////////////////////////////////////// 1620/////////////////////////////////////////////////////////////
1621// Transpose <-> Frequency conversions 1621// Transpose <-> Frequency conversions
1622 1622
1623// returns 8363*2^((transp*128+ftune)/(12*128)) 1623// returns 8363*2^((transp*128+ftune)/(12*128))
1624DWORD CSoundFile::TransposeToFrequency(int transp, int ftune) 1624DWORD CSoundFile::TransposeToFrequency(int transp, int ftune)
1625//----------------------------------------------------------- 1625//-----------------------------------------------------------
1626{ 1626{
1627 //---GCCFIX: Removed assembly. 1627 //---GCCFIX: Removed assembly.
1628 return (DWORD)(8363*pow(2, (transp*128+ftune)/(1536))); 1628 return (DWORD)(8363*pow(2, (transp*128+ftune)/(1536)));
1629 1629
1630#ifdef WIN32 1630#ifdef WIN32
1631 const float _fbase = 8363; 1631 const float _fbase = 8363;
1632 const float _factor = 1.0f/(12.0f*128.0f); 1632 const float _factor = 1.0f/(12.0f*128.0f);
1633 int result; 1633 int result;
1634 DWORD freq; 1634 DWORD freq;
1635 1635
1636 transp = (transp << 7) + ftune; 1636 transp = (transp << 7) + ftune;
1637 _asm { 1637 _asm {
1638 fild transp 1638 fild transp
1639 fld _factor 1639 fld _factor
1640 fmulp st(1), st(0) 1640 fmulp st(1), st(0)
1641 fist result 1641 fist result
1642 fisub result 1642 fisub result
1643 f2xm1 1643 f2xm1
1644 fild result 1644 fild result
1645 fld _fbase 1645 fld _fbase
1646 fscale 1646 fscale
1647 fstp st(1) 1647 fstp st(1)
1648 fmul st(1), st(0) 1648 fmul st(1), st(0)
1649 faddp st(1), st(0) 1649 faddp st(1), st(0)
1650 fistp freq 1650 fistp freq
1651 } 1651 }
1652 UINT derr = freq % 11025; 1652 UINT derr = freq % 11025;
1653 if (derr <= 8) freq -= derr; 1653 if (derr <= 8) freq -= derr;
1654 if (derr >= 11015) freq += 11025-derr; 1654 if (derr >= 11015) freq += 11025-derr;
1655 derr = freq % 1000; 1655 derr = freq % 1000;
1656 if (derr <= 5) freq -= derr; 1656 if (derr <= 5) freq -= derr;
1657 if (derr >= 995) freq += 1000-derr; 1657 if (derr >= 995) freq += 1000-derr;
1658 return freq; 1658 return freq;
1659#endif 1659#endif
1660} 1660}
1661 1661
1662 1662
1663// returns 12*128*log2(freq/8363) 1663// returns 12*128*log2(freq/8363)
1664int CSoundFile::FrequencyToTranspose(DWORD freq) 1664int CSoundFile::FrequencyToTranspose(DWORD freq)
1665//---------------------------------------------- 1665//----------------------------------------------
1666{ 1666{
1667 //---GCCFIX: Removed assembly. 1667 //---GCCFIX: Removed assembly.
1668 return int(1536*(log(freq/8363)/log(2))); 1668 return int(1536*(log(freq/8363)/log(2)));
1669 1669
1670#ifdef WIN32 1670#ifdef WIN32
1671 const float _f1_8363 = 1.0f / 8363.0f; 1671 const float _f1_8363 = 1.0f / 8363.0f;
1672 const float _factor = 128 * 12; 1672 const float _factor = 128 * 12;
1673 LONG result; 1673 LONG result;
1674 1674
1675 if (!freq) return 0; 1675 if (!freq) return 0;
1676 _asm { 1676 _asm {
1677 fld _factor 1677 fld _factor
1678 fild freq 1678 fild freq
1679 fld _f1_8363 1679 fld _f1_8363
1680 fmulp st(1), st(0) 1680 fmulp st(1), st(0)
1681 fyl2x 1681 fyl2x
1682 fistp result 1682 fistp result
1683 } 1683 }
1684 return result; 1684 return result;
1685#endif 1685#endif
1686} 1686}
1687 1687
1688 1688
1689void CSoundFile::FrequencyToTranspose(MODINSTRUMENT *psmp) 1689void CSoundFile::FrequencyToTranspose(MODINSTRUMENT *psmp)
1690//-------------------------------------------------------- 1690//--------------------------------------------------------
1691{ 1691{
1692 int f2t = FrequencyToTranspose(psmp->nC4Speed); 1692 int f2t = FrequencyToTranspose(psmp->nC4Speed);
1693 int transp = f2t >> 7; 1693 int transp = f2t >> 7;
1694 int ftune = f2t & 0x7F; 1694 int ftune = f2t & 0x7F;
1695 if (ftune > 80) 1695 if (ftune > 80)
1696 { 1696 {
1697 transp++; 1697 transp++;
1698 ftune -= 128; 1698 ftune -= 128;
1699 } 1699 }
1700 if (transp > 127) transp = 127; 1700 if (transp > 127) transp = 127;
1701 if (transp < -127) transp = -127; 1701 if (transp < -127) transp = -127;
1702 psmp->RelativeTone = transp; 1702 psmp->RelativeTone = transp;
1703 psmp->nFineTune = ftune; 1703 psmp->nFineTune = ftune;
1704} 1704}
1705 1705
1706 1706
1707void CSoundFile::CheckCPUUsage(UINT nCPU) 1707void CSoundFile::CheckCPUUsage(UINT nCPU)
1708//--------------------------------------- 1708//---------------------------------------
1709{ 1709{
1710 if (nCPU > 100) nCPU = 100; 1710 if (nCPU > 100) nCPU = 100;
1711 gnCPUUsage = nCPU; 1711 gnCPUUsage = nCPU;
1712 if (nCPU < 90) 1712 if (nCPU < 90)
1713 { 1713 {
1714 m_dwSongFlags &= ~SONG_CPUVERYHIGH; 1714 m_dwSongFlags &= ~SONG_CPUVERYHIGH;
1715 } else 1715 } else
1716 if ((m_dwSongFlags & SONG_CPUVERYHIGH) && (nCPU >= 94)) 1716 if ((m_dwSongFlags & SONG_CPUVERYHIGH) && (nCPU >= 94))
1717 { 1717 {
1718 UINT i=MAX_CHANNELS; 1718 UINT i=MAX_CHANNELS;
1719 while (i >= 8) 1719 while (i >= 8)
1720 { 1720 {
1721 i--; 1721 i--;
1722 if (Chn[i].nLength) 1722 if (Chn[i].nLength)
1723 { 1723 {
1724 Chn[i].nLength = Chn[i].nPos = 0; 1724 Chn[i].nLength = Chn[i].nPos = 0;
1725 nCPU -= 2; 1725 nCPU -= 2;
1726 if (nCPU < 94) break; 1726 if (nCPU < 94) break;
1727 } 1727 }
1728 } 1728 }
1729 } else 1729 } else
1730 if (nCPU > 90) 1730 if (nCPU > 90)
1731 { 1731 {
1732 m_dwSongFlags |= SONG_CPUVERYHIGH; 1732 m_dwSongFlags |= SONG_CPUVERYHIGH;
1733 } 1733 }
1734} 1734}
1735 1735
1736 1736
1737BOOL CSoundFile::SetPatternName(UINT nPat, LPCSTR lpszName) 1737BOOL CSoundFile::SetPatternName(UINT nPat, LPCSTR lpszName)
1738//--------------------------------------------------------- 1738//---------------------------------------------------------
1739{ 1739{
1740 char szName[MAX_PATTERNNAME] = ""; // changed from CHAR 1740 char szName[MAX_PATTERNNAME] = ""; // changed from CHAR
1741 if (nPat >= MAX_PATTERNS) return FALSE; 1741 if (nPat >= MAX_PATTERNS) return FALSE;
1742 if (lpszName) lstrcpyn(szName, lpszName, MAX_PATTERNNAME); 1742 if (lpszName)
1743 lstrcpyn(szName, lpszName, MAX_PATTERNNAME);
1744 else
1745 return FALSE;
1743 szName[MAX_PATTERNNAME-1] = 0; 1746 szName[MAX_PATTERNNAME-1] = 0;
1744 if (!m_lpszPatternNames) m_nPatternNames = 0; 1747 if (!m_lpszPatternNames) m_nPatternNames = 0;
1745 if (nPat >= m_nPatternNames) 1748 if (nPat >= m_nPatternNames)
1746 { 1749 {
1747 if (!lpszName[0]) return TRUE; 1750 if (!lpszName[0]) return TRUE;
1748 UINT len = (nPat+1)*MAX_PATTERNNAME; 1751 UINT len = (nPat+1)*MAX_PATTERNNAME;
1749 char *p = new char[len]; // changed from CHAR 1752 char *p = new char[len]; // changed from CHAR
1750 if (!p) return FALSE; 1753 if (!p) return FALSE;
1751 memset(p, 0, len); 1754 memset(p, 0, len);
1752 if (m_lpszPatternNames) 1755 if (m_lpszPatternNames)
1753 { 1756 {
1754 memcpy(p, m_lpszPatternNames, m_nPatternNames * MAX_PATTERNNAME); 1757 memcpy(p, m_lpszPatternNames, m_nPatternNames * MAX_PATTERNNAME);
1755 delete m_lpszPatternNames; 1758 delete m_lpszPatternNames;
1756 m_lpszPatternNames = NULL; 1759 m_lpszPatternNames = NULL;
1757 } 1760 }
1758 m_lpszPatternNames = p; 1761 m_lpszPatternNames = p;
1759 m_nPatternNames = nPat + 1; 1762 m_nPatternNames = nPat + 1;
1760 } 1763 }
1761 memcpy(m_lpszPatternNames + nPat * MAX_PATTERNNAME, szName, MAX_PATTERNNAME); 1764 memcpy(m_lpszPatternNames + nPat * MAX_PATTERNNAME, szName, MAX_PATTERNNAME);
1762 return TRUE; 1765 return TRUE;
1763} 1766}
1764 1767
1765 1768
1766BOOL CSoundFile::GetPatternName(UINT nPat, LPSTR lpszName, UINT cbSize) const 1769BOOL CSoundFile::GetPatternName(UINT nPat, LPSTR lpszName, UINT cbSize) const
1767//--------------------------------------------------------------------------- 1770//---------------------------------------------------------------------------
1768{ 1771{
1769 if ((!lpszName) || (!cbSize)) return FALSE; 1772 if ((!lpszName) || (!cbSize)) return FALSE;
1770 lpszName[0] = 0; 1773 lpszName[0] = 0;
1771 if (cbSize > MAX_PATTERNNAME) cbSize = MAX_PATTERNNAME; 1774 if (cbSize > MAX_PATTERNNAME) cbSize = MAX_PATTERNNAME;
1772 if ((m_lpszPatternNames) && (nPat < m_nPatternNames)) 1775 if ((m_lpszPatternNames) && (nPat < m_nPatternNames))
1773 { 1776 {
1774 memcpy(lpszName, m_lpszPatternNames + nPat * MAX_PATTERNNAME, cbSize); 1777 memcpy(lpszName, m_lpszPatternNames + nPat * MAX_PATTERNNAME, cbSize);
1775 lpszName[cbSize-1] = 0; 1778 lpszName[cbSize-1] = 0;
1776 return TRUE; 1779 return TRUE;
1777 } 1780 }
1778 return FALSE; 1781 return FALSE;
1779} 1782}
1780 1783
1781 1784
1782#ifndef FASTSOUNDLIB 1785#ifndef FASTSOUNDLIB
1783 1786
1784UINT CSoundFile::DetectUnusedSamples(BOOL *pbIns) 1787UINT CSoundFile::DetectUnusedSamples(BOOL *pbIns)
1785//----------------------------------------------- 1788//-----------------------------------------------
1786{ 1789{
1787 UINT nExt = 0; 1790 UINT nExt = 0;
1788 1791
1789 if (!pbIns) return 0; 1792 if (!pbIns) return 0;
1790 if (m_nInstruments) 1793 if (m_nInstruments)
1791 { 1794 {
1792 memset(pbIns, 0, MAX_SAMPLES * sizeof(BOOL)); 1795 memset(pbIns, 0, MAX_SAMPLES * sizeof(BOOL));
1793 for (UINT ipat=0; ipat<MAX_PATTERNS; ipat++) 1796 for (UINT ipat=0; ipat<MAX_PATTERNS; ipat++)
1794 { 1797 {
1795 MODCOMMAND *p = Patterns[ipat]; 1798 MODCOMMAND *p = Patterns[ipat];
1796 if (p) 1799 if (p)
1797 { 1800 {
1798 UINT jmax = PatternSize[ipat] * m_nChannels; 1801 UINT jmax = PatternSize[ipat] * m_nChannels;
1799 for (UINT j=0; j<jmax; j++, p++) 1802 for (UINT j=0; j<jmax; j++, p++)
1800 { 1803 {
1801 if ((p->note) && (p->note <= 120)) 1804 if ((p->note) && (p->note <= 120))
1802 { 1805 {
1803 if ((p->instr) && (p->instr < MAX_INSTRUMENTS)) 1806 if ((p->instr) && (p->instr < MAX_INSTRUMENTS))
1804 { 1807 {
1805 INSTRUMENTHEADER *penv = Headers[p->instr]; 1808 INSTRUMENTHEADER *penv = Headers[p->instr];
1806 if (penv) 1809 if (penv)
1807 { 1810 {
1808 UINT n = penv->Keyboard[p->note-1]; 1811 UINT n = penv->Keyboard[p->note-1];
1809 if (n < MAX_SAMPLES) pbIns[n] = TRUE; 1812 if (n < MAX_SAMPLES) pbIns[n] = TRUE;
1810 } 1813 }
1811 } else 1814 } else
1812 { 1815 {
1813 for (UINT k=1; k<=m_nInstruments; k++) 1816 for (UINT k=1; k<=m_nInstruments; k++)
1814 { 1817 {
1815 INSTRUMENTHEADER *penv = Headers[k]; 1818 INSTRUMENTHEADER *penv = Headers[k];
1816 if (penv) 1819 if (penv)
1817 { 1820 {
1818 UINT n = penv->Keyboard[p->note-1]; 1821 UINT n = penv->Keyboard[p->note-1];
1819 if (n < MAX_SAMPLES) pbIns[n] = TRUE; 1822 if (n < MAX_SAMPLES) pbIns[n] = TRUE;
1820 } 1823 }
1821 } 1824 }
1822 } 1825 }
1823 } 1826 }
1824 } 1827 }
1825 } 1828 }
1826 } 1829 }
1827 for (UINT ichk=1; ichk<=m_nSamples; ichk++) 1830 for (UINT ichk=1; ichk<=m_nSamples; ichk++)
1828 { 1831 {
1829 if ((!pbIns[ichk]) && (Ins[ichk].pSample)) nExt++; 1832 if ((!pbIns[ichk]) && (Ins[ichk].pSample)) nExt++;
1830 } 1833 }
1831 } 1834 }
1832 return nExt; 1835 return nExt;
1833} 1836}
1834 1837
1835 1838
1836BOOL CSoundFile::RemoveSelectedSamples(BOOL *pbIns) 1839BOOL CSoundFile::RemoveSelectedSamples(BOOL *pbIns)
1837//------------------------------------------------- 1840//-------------------------------------------------
1838{ 1841{
1839 if (!pbIns) return FALSE; 1842 if (!pbIns) return FALSE;
1840 for (UINT j=1; j<MAX_SAMPLES; j++) 1843 for (UINT j=1; j<MAX_SAMPLES; j++)
1841 { 1844 {
1842 if ((!pbIns[j]) && (Ins[j].pSample)) 1845 if ((!pbIns[j]) && (Ins[j].pSample))
1843 { 1846 {
1844 DestroySample(j); 1847 DestroySample(j);
1845 if ((j == m_nSamples) && (j > 1)) m_nSamples--; 1848 if ((j == m_nSamples) && (j > 1)) m_nSamples--;
1846 } 1849 }
1847 } 1850 }
1848 return TRUE; 1851 return TRUE;
1849} 1852}
1850 1853
1851 1854
1852BOOL CSoundFile::DestroySample(UINT nSample) 1855BOOL CSoundFile::DestroySample(UINT nSample)
1853//------------------------------------------ 1856//------------------------------------------
1854{ 1857{
1855 if ((!nSample) || (nSample >= MAX_SAMPLES)) return FALSE; 1858 if ((!nSample) || (nSample >= MAX_SAMPLES)) return FALSE;
1856 if (!Ins[nSample].pSample) return TRUE; 1859 if (!Ins[nSample].pSample) return TRUE;
1857 MODINSTRUMENT *pins = &Ins[nSample]; 1860 MODINSTRUMENT *pins = &Ins[nSample];
1858 signed char *pSample = pins->pSample; 1861 signed char *pSample = pins->pSample;
1859 pins->pSample = NULL; 1862 pins->pSample = NULL;
1860 pins->nLength = 0; 1863 pins->nLength = 0;
1861 pins->uFlags &= ~(CHN_16BIT); 1864 pins->uFlags &= ~(CHN_16BIT);
1862 for (UINT i=0; i<MAX_CHANNELS; i++) 1865 for (UINT i=0; i<MAX_CHANNELS; i++)
1863 { 1866 {
1864 if (Chn[i].pSample == pSample) 1867 if (Chn[i].pSample == pSample)
1865 { 1868 {
1866 Chn[i].nPos = Chn[i].nLength = 0; 1869 Chn[i].nPos = Chn[i].nLength = 0;
1867 Chn[i].pSample = Chn[i].pCurrentSample = NULL; 1870 Chn[i].pSample = Chn[i].pCurrentSample = NULL;
1868 } 1871 }
1869 } 1872 }
1870 FreeSample(pSample); 1873 FreeSample(pSample);
1871 return TRUE; 1874 return TRUE;
1872} 1875}
1873 1876
1874#endif // FASTSOUNDLIB 1877#endif // FASTSOUNDLIB
1875 1878
diff --git a/core/multimedia/opieplayer/vorbis/tremor/block.c b/core/multimedia/opieplayer/vorbis/tremor/block.c
index 8949253..7b5531b 100644
--- a/core/multimedia/opieplayer/vorbis/tremor/block.c
+++ b/core/multimedia/opieplayer/vorbis/tremor/block.c
@@ -37,386 +37,388 @@ static int ilog(unsigned int v){
37} 37}
38 38
39/* pcm accumulator examples (not exhaustive): 39/* pcm accumulator examples (not exhaustive):
40 40
41 <-------------- lW ----------------> 41 <-------------- lW ---------------->
42 <--------------- W ----------------> 42 <--------------- W ---------------->
43: .....|..... _______________ | 43: .....|..... _______________ |
44: .''' | '''_--- | |\ | 44: .''' | '''_--- | |\ |
45:.....''' |_____--- '''......| | \_______| 45:.....''' |_____--- '''......| | \_______|
46:.................|__________________|_______|__|______| 46:.................|__________________|_______|__|______|
47 |<------ Sl ------>| > Sr < |endW 47 |<------ Sl ------>| > Sr < |endW
48 |beginSl |endSl | |endSr 48 |beginSl |endSl | |endSr
49 |beginW |endlW |beginSr 49 |beginW |endlW |beginSr
50 50
51 51
52 |< lW >| 52 |< lW >|
53 <--------------- W ----------------> 53 <--------------- W ---------------->
54 | | .. ______________ | 54 | | .. ______________ |
55 | | ' `/ | ---_ | 55 | | ' `/ | ---_ |
56 |___.'___/`. | ---_____| 56 |___.'___/`. | ---_____|
57 |_______|__|_______|_________________| 57 |_______|__|_______|_________________|
58 | >|Sl|< |<------ Sr ----->|endW 58 | >|Sl|< |<------ Sr ----->|endW
59 | | |endSl |beginSr |endSr 59 | | |endSl |beginSr |endSr
60 |beginW | |endlW 60 |beginW | |endlW
61 mult[0] |beginSl mult[n] 61 mult[0] |beginSl mult[n]
62 62
63 <-------------- lW -----------------> 63 <-------------- lW ----------------->
64 |<--W-->| 64 |<--W-->|
65: .............. ___ | | 65: .............. ___ | |
66: .''' |`/ \ | | 66: .''' |`/ \ | |
67:.....''' |/`....\|...| 67:.....''' |/`....\|...|
68:.........................|___|___|___| 68:.........................|___|___|___|
69 |Sl |Sr |endW 69 |Sl |Sr |endW
70 | | |endSr 70 | | |endSr
71 | |beginSr 71 | |beginSr
72 | |endSl 72 | |endSl
73 |beginSl 73 |beginSl
74 |beginW 74 |beginW
75*/ 75*/
76 76
77/* block abstraction setup *********************************************/ 77/* block abstraction setup *********************************************/
78 78
79#ifndef WORD_ALIGN 79#ifndef WORD_ALIGN
80#define WORD_ALIGN 8 80#define WORD_ALIGN 8
81#endif 81#endif
82 82
83int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){ 83int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
84 memset(vb,0,sizeof(*vb)); 84 memset(vb,0,sizeof(*vb));
85 vb->vd=v; 85 vb->vd=v;
86 vb->localalloc=0; 86 vb->localalloc=0;
87 vb->localstore=NULL; 87 vb->localstore=NULL;
88 88
89 return(0); 89 return(0);
90} 90}
91 91
92void *_vorbis_block_alloc(vorbis_block *vb,long bytes){ 92void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
93 bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1); 93 bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
94 if(bytes+vb->localtop>vb->localalloc){ 94 if(bytes+vb->localtop>vb->localalloc){
95 /* can't just _ogg_realloc... there are outstanding pointers */ 95 /* can't just _ogg_realloc... there are outstanding pointers */
96 if(vb->localstore){ 96 if(vb->localstore){
97 struct alloc_chain *link=(struct alloc_chain *)_ogg_malloc(sizeof(*link)); 97 struct alloc_chain *link=(struct alloc_chain *)_ogg_malloc(sizeof(*link));
98 vb->totaluse+=vb->localtop; 98 vb->totaluse+=vb->localtop;
99 link->next=vb->reap; 99 link->next=vb->reap;
100 link->ptr=vb->localstore; 100 link->ptr=vb->localstore;
101 vb->reap=link; 101 vb->reap=link;
102 } 102 }
103 /* highly conservative */ 103 /* highly conservative */
104 vb->localalloc=bytes; 104 vb->localalloc=bytes;
105 vb->localstore=_ogg_malloc(vb->localalloc); 105 vb->localstore=_ogg_malloc(vb->localalloc);
106 vb->localtop=0; 106 vb->localtop=0;
107 } 107 }
108 { 108 {
109 void *ret=(void *)(((char *)vb->localstore)+vb->localtop); 109 void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
110 vb->localtop+=bytes; 110 vb->localtop+=bytes;
111 return ret; 111 return ret;
112 } 112 }
113} 113}
114 114
115/* reap the chain, pull the ripcord */ 115/* reap the chain, pull the ripcord */
116void _vorbis_block_ripcord(vorbis_block *vb){ 116void _vorbis_block_ripcord(vorbis_block *vb){
117 /* reap the chain */ 117 /* reap the chain */
118 struct alloc_chain *reap=vb->reap; 118 struct alloc_chain *reap=vb->reap;
119 while(reap){ 119 while(reap){
120 struct alloc_chain *next=reap->next; 120 struct alloc_chain *next=reap->next;
121 _ogg_free(reap->ptr); 121 _ogg_free(reap->ptr);
122 memset(reap,0,sizeof(*reap)); 122 memset(reap,0,sizeof(*reap));
123 _ogg_free(reap); 123 _ogg_free(reap);
124 reap=next; 124 reap=next;
125 } 125 }
126 /* consolidate storage */ 126 /* consolidate storage */
127 if(vb->totaluse){ 127 if(vb->totaluse){
128 vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc); 128 vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
129 vb->localalloc+=vb->totaluse; 129 vb->localalloc+=vb->totaluse;
130 vb->totaluse=0; 130 vb->totaluse=0;
131 } 131 }
132 132
133 /* pull the ripcord */ 133 /* pull the ripcord */
134 vb->localtop=0; 134 vb->localtop=0;
135 vb->reap=NULL; 135 vb->reap=NULL;
136} 136}
137 137
138int vorbis_block_clear(vorbis_block *vb){ 138int vorbis_block_clear(vorbis_block *vb){
139 _vorbis_block_ripcord(vb); 139 _vorbis_block_ripcord(vb);
140 if(vb->localstore)_ogg_free(vb->localstore); 140 if(vb->localstore)_ogg_free(vb->localstore);
141 141
142 memset(vb,0,sizeof(*vb)); 142 memset(vb,0,sizeof(*vb));
143 return(0); 143 return(0);
144} 144}
145 145
146static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ 146static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){
147 int i; 147 int i;
148 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 148 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
149 private_state *b=NULL; 149 private_state *b=NULL;
150 150
151 memset(v,0,sizeof(*v)); 151 memset(v,0,sizeof(*v));
152 b=(private_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b))); 152 b=(private_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b)));
153 153
154 v->vi=vi; 154 v->vi=vi;
155 b->modebits=ilog(ci->modes); 155 b->modebits=ilog(ci->modes);
156 156
157 /* Vorbis I uses only window type 0 */ 157 /* Vorbis I uses only window type 0 */
158 b->window[0]=_vorbis_window(0,ci->blocksizes[0]/2); 158 b->window[0]=_vorbis_window(0,ci->blocksizes[0]/2);
159 b->window[1]=_vorbis_window(0,ci->blocksizes[1]/2); 159 b->window[1]=_vorbis_window(0,ci->blocksizes[1]/2);
160 160
161 /* finish the codebooks */ 161 /* finish the codebooks */
162 if(!ci->fullbooks){ 162 if(!ci->fullbooks){
163 ci->fullbooks=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->fullbooks)); 163 ci->fullbooks=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->fullbooks));
164 for(i=0;i<ci->books;i++){ 164 for(i=0;i<ci->books;i++){
165 vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]); 165 vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
166 /* decode codebooks are now standalone after init */ 166 /* decode codebooks are now standalone after init */
167 vorbis_staticbook_destroy(ci->book_param[i]); 167 vorbis_staticbook_destroy(ci->book_param[i]);
168 ci->book_param[i]=NULL; 168 ci->book_param[i]=NULL;
169 } 169 }
170 } 170 }
171 171
172 v->pcm_storage=ci->blocksizes[1]; 172 v->pcm_storage=ci->blocksizes[1];
173 v->pcm=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcm)); 173 v->pcm=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcm));
174 v->pcmret=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcmret)); 174 v->pcmret=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
175 for(i=0;i<vi->channels;i++) 175 for(i=0;i<vi->channels;i++)
176 v->pcm[i]=(ogg_int32_t *)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i])); 176 v->pcm[i]=(ogg_int32_t *)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
177 177
178 /* all 1 (large block) or 0 (small block) */ 178 /* all 1 (large block) or 0 (small block) */
179 /* explicitly set for the sake of clarity */ 179 /* explicitly set for the sake of clarity */
180 v->lW=0; /* previous window size */ 180 v->lW=0; /* previous window size */
181 v->W=0; /* current window size */ 181 v->W=0; /* current window size */
182 182
183 /* initialize all the mapping/backend lookups */ 183 /* initialize all the mapping/backend lookups */
184 b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode)); 184 b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode));
185 for(i=0;i<ci->modes;i++){ 185 for(i=0;i<ci->modes;i++){
186 int mapnum=ci->mode_param[i]->mapping; 186 int mapnum=ci->mode_param[i]->mapping;
187 int maptype=ci->map_type[mapnum]; 187 int maptype=ci->map_type[mapnum];
188 b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i], 188 b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i],
189 ci->map_param[mapnum]); 189 ci->map_param[mapnum]);
190 } 190 }
191 return(0); 191 return(0);
192} 192}
193 193
194int vorbis_synthesis_restart(vorbis_dsp_state *v){ 194int vorbis_synthesis_restart(vorbis_dsp_state *v){
195 vorbis_info *vi=v->vi; 195 vorbis_info *vi=v->vi;
196 codec_setup_info *ci; 196 codec_setup_info *ci;
197 197
198 if(!v->backend_state)return -1; 198 if(!v->backend_state)return -1;
199 if(!vi)return -1; 199 if(!vi)return -1;
200 ci=vi->codec_setup; 200 ci=vi->codec_setup;
201 if(!ci)return -1; 201 if(!ci)return -1;
202 202
203 v->centerW=ci->blocksizes[1]/2; 203 v->centerW=ci->blocksizes[1]/2;
204 v->pcm_current=v->centerW; 204 v->pcm_current=v->centerW;
205 205
206 v->pcm_returned=-1; 206 v->pcm_returned=-1;
207 v->granulepos=-1; 207 v->granulepos=-1;
208 v->sequence=-1; 208 v->sequence=-1;
209 ((private_state *)(v->backend_state))->sample_count=-1; 209 ((private_state *)(v->backend_state))->sample_count=-1;
210 210
211 return(0); 211 return(0);
212} 212}
213 213
214int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){ 214int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
215 _vds_init(v,vi); 215 _vds_init(v,vi);
216 vorbis_synthesis_restart(v); 216 vorbis_synthesis_restart(v);
217 217
218 return(0); 218 return(0);
219} 219}
220 220
221void vorbis_dsp_clear(vorbis_dsp_state *v){ 221void vorbis_dsp_clear(vorbis_dsp_state *v){
222 int i; 222 int i;
223 if(v){ 223 if(v){
224 vorbis_info *vi=v->vi; 224 vorbis_info *vi=v->vi;
225 codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL); 225 codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL);
226 private_state *b=(private_state *)v->backend_state; 226 private_state *b=(private_state *)v->backend_state;
227 227
228 if(v->pcm){ 228 if(v->pcm){
229 for(i=0;i<vi->channels;i++) 229 if (vi) {
230 if(v->pcm[i])_ogg_free(v->pcm[i]); 230 for(i=0;i<vi->channels;i++)
231 if(v->pcm[i])_ogg_free(v->pcm[i]);
232 }
231 _ogg_free(v->pcm); 233 _ogg_free(v->pcm);
232 if(v->pcmret)_ogg_free(v->pcmret); 234 if(v->pcmret)_ogg_free(v->pcmret);
233 } 235 }
234 236
235 /* free mode lookups; these are actually vorbis_look_mapping structs */ 237 /* free mode lookups; these are actually vorbis_look_mapping structs */
236 if(ci){ 238 if(ci){
237 for(i=0;i<ci->modes;i++){ 239 for(i=0;i<ci->modes;i++){
238 int mapnum=ci->mode_param[i]->mapping; 240 int mapnum=ci->mode_param[i]->mapping;
239 int maptype=ci->map_type[mapnum]; 241 int maptype=ci->map_type[mapnum];
240 if(b && b->mode)_mapping_P[maptype]->free_look(b->mode[i]); 242 if(b && b->mode)_mapping_P[maptype]->free_look(b->mode[i]);
241 } 243 }
242 } 244 }
243 245
244 if(b){ 246 if(b){
245 if(b->mode)_ogg_free(b->mode); 247 if(b->mode)_ogg_free(b->mode);
246 _ogg_free(b); 248 _ogg_free(b);
247 } 249 }
248 250
249 memset(v,0,sizeof(*v)); 251 memset(v,0,sizeof(*v));
250 } 252 }
251} 253}
252 254
253/* Unlike in analysis, the window is only partially applied for each 255/* Unlike in analysis, the window is only partially applied for each
254 block. The time domain envelope is not yet handled at the point of 256 block. The time domain envelope is not yet handled at the point of
255 calling (as it relies on the previous block). */ 257 calling (as it relies on the previous block). */
256 258
257int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ 259int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
258 vorbis_info *vi=v->vi; 260 vorbis_info *vi=v->vi;
259 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 261 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
260 private_state *b=v->backend_state; 262 private_state *b=v->backend_state;
261 int i,j; 263 int i,j;
262 264
263 if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL); 265 if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
264 266
265 v->lW=v->W; 267 v->lW=v->W;
266 v->W=vb->W; 268 v->W=vb->W;
267 v->nW=-1; 269 v->nW=-1;
268 270
269 if((v->sequence==-1)|| 271 if((v->sequence==-1)||
270 (v->sequence+1 != vb->sequence)){ 272 (v->sequence+1 != vb->sequence)){
271 v->granulepos=-1; /* out of sequence; lose count */ 273 v->granulepos=-1; /* out of sequence; lose count */
272 b->sample_count=-1; 274 b->sample_count=-1;
273 } 275 }
274 276
275 v->sequence=vb->sequence; 277 v->sequence=vb->sequence;
276 278
277 if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly 279 if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
278 was called on block */ 280 was called on block */
279 int n=ci->blocksizes[v->W]/2; 281 int n=ci->blocksizes[v->W]/2;
280 int n0=ci->blocksizes[0]/2; 282 int n0=ci->blocksizes[0]/2;
281 int n1=ci->blocksizes[1]/2; 283 int n1=ci->blocksizes[1]/2;
282 284
283 int thisCenter; 285 int thisCenter;
284 int prevCenter; 286 int prevCenter;
285 287
286 if(v->centerW){ 288 if(v->centerW){
287 thisCenter=n1; 289 thisCenter=n1;
288 prevCenter=0; 290 prevCenter=0;
289 }else{ 291 }else{
290 thisCenter=0; 292 thisCenter=0;
291 prevCenter=n1; 293 prevCenter=n1;
292 } 294 }
293 295
294 /* v->pcm is now used like a two-stage double buffer. We don't want 296 /* v->pcm is now used like a two-stage double buffer. We don't want
295 to have to constantly shift *or* adjust memory usage. Don't 297 to have to constantly shift *or* adjust memory usage. Don't
296 accept a new block until the old is shifted out */ 298 accept a new block until the old is shifted out */
297 299
298 /* overlap/add PCM */ 300 /* overlap/add PCM */
299 301
300 for(j=0;j<vi->channels;j++){ 302 for(j=0;j<vi->channels;j++){
301 /* the overlap/add section */ 303 /* the overlap/add section */
302 if(v->lW){ 304 if(v->lW){
303 if(v->W){ 305 if(v->W){
304 /* large/large */ 306 /* large/large */
305 ogg_int32_t *pcm=v->pcm[j]+prevCenter; 307 ogg_int32_t *pcm=v->pcm[j]+prevCenter;
306 ogg_int32_t *p=vb->pcm[j]; 308 ogg_int32_t *p=vb->pcm[j];
307 for(i=0;i<n1;i++) 309 for(i=0;i<n1;i++)
308 pcm[i]+=p[i]; 310 pcm[i]+=p[i];
309 }else{ 311 }else{
310 /* large/small */ 312 /* large/small */
311 ogg_int32_t *pcm=v->pcm[j]+prevCenter+n1/2-n0/2; 313 ogg_int32_t *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
312 ogg_int32_t *p=vb->pcm[j]; 314 ogg_int32_t *p=vb->pcm[j];
313 for(i=0;i<n0;i++) 315 for(i=0;i<n0;i++)
314 pcm[i]+=p[i]; 316 pcm[i]+=p[i];
315 } 317 }
316 }else{ 318 }else{
317 if(v->W){ 319 if(v->W){
318 /* small/large */ 320 /* small/large */
319 ogg_int32_t *pcm=v->pcm[j]+prevCenter; 321 ogg_int32_t *pcm=v->pcm[j]+prevCenter;
320 ogg_int32_t *p=vb->pcm[j]+n1/2-n0/2; 322 ogg_int32_t *p=vb->pcm[j]+n1/2-n0/2;
321 for(i=0;i<n0;i++) 323 for(i=0;i<n0;i++)
322 pcm[i]+=p[i]; 324 pcm[i]+=p[i];
323 for(;i<n1/2+n0/2;i++) 325 for(;i<n1/2+n0/2;i++)
324 pcm[i]=p[i]; 326 pcm[i]=p[i];
325 }else{ 327 }else{
326 /* small/small */ 328 /* small/small */
327 ogg_int32_t *pcm=v->pcm[j]+prevCenter; 329 ogg_int32_t *pcm=v->pcm[j]+prevCenter;
328 ogg_int32_t *p=vb->pcm[j]; 330 ogg_int32_t *p=vb->pcm[j];
329 for(i=0;i<n0;i++) 331 for(i=0;i<n0;i++)
330 pcm[i]+=p[i]; 332 pcm[i]+=p[i];
331 } 333 }
332 } 334 }
333 335
334 /* the copy section */ 336 /* the copy section */
335 { 337 {
336 ogg_int32_t *pcm=v->pcm[j]+thisCenter; 338 ogg_int32_t *pcm=v->pcm[j]+thisCenter;
337 ogg_int32_t *p=vb->pcm[j]+n; 339 ogg_int32_t *p=vb->pcm[j]+n;
338 for(i=0;i<n;i++) 340 for(i=0;i<n;i++)
339 pcm[i]=p[i]; 341 pcm[i]=p[i];
340 } 342 }
341 } 343 }
342 344
343 if(v->centerW) 345 if(v->centerW)
344 v->centerW=0; 346 v->centerW=0;
345 else 347 else
346 v->centerW=n1; 348 v->centerW=n1;
347 349
348 /* deal with initial packet state; we do this using the explicit 350 /* deal with initial packet state; we do this using the explicit
349 pcm_returned==-1 flag otherwise we're sensitive to first block 351 pcm_returned==-1 flag otherwise we're sensitive to first block
350 being short or long */ 352 being short or long */
351 353
352 if(v->pcm_returned==-1){ 354 if(v->pcm_returned==-1){
353 v->pcm_returned=thisCenter; 355 v->pcm_returned=thisCenter;
354 v->pcm_current=thisCenter; 356 v->pcm_current=thisCenter;
355 }else{ 357 }else{
356 v->pcm_returned=prevCenter; 358 v->pcm_returned=prevCenter;
357 v->pcm_current=prevCenter+ 359 v->pcm_current=prevCenter+
358 ci->blocksizes[v->lW]/4+ 360 ci->blocksizes[v->lW]/4+
359 ci->blocksizes[v->W]/4; 361 ci->blocksizes[v->W]/4;
360 } 362 }
361 363
362 } 364 }
363 365
364 /* track the frame number... This is for convenience, but also 366 /* track the frame number... This is for convenience, but also
365 making sure our last packet doesn't end with added padding. If 367 making sure our last packet doesn't end with added padding. If
366 the last packet is partial, the number of samples we'll have to 368 the last packet is partial, the number of samples we'll have to
367 return will be past the vb->granulepos. 369 return will be past the vb->granulepos.
368 370
369 This is not foolproof! It will be confused if we begin 371 This is not foolproof! It will be confused if we begin
370 decoding at the last page after a seek or hole. In that case, 372 decoding at the last page after a seek or hole. In that case,
371 we don't have a starting point to judge where the last frame 373 we don't have a starting point to judge where the last frame
372 is. For this reason, vorbisfile will always try to make sure 374 is. For this reason, vorbisfile will always try to make sure
373 it reads the last two marked pages in proper sequence */ 375 it reads the last two marked pages in proper sequence */
374 376
375 if(b->sample_count==-1){ 377 if(b->sample_count==-1){
376 b->sample_count=0; 378 b->sample_count=0;
377 }else{ 379 }else{
378 b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4; 380 b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
379 } 381 }
380 382
381 if(v->granulepos==-1){ 383 if(v->granulepos==-1){
382 if(vb->granulepos!=-1){ /* only set if we have a position to set to */ 384 if(vb->granulepos!=-1){ /* only set if we have a position to set to */
383 385
384 v->granulepos=vb->granulepos; 386 v->granulepos=vb->granulepos;
385 387
386 /* is this a short page? */ 388 /* is this a short page? */
387 if(b->sample_count>v->granulepos){ 389 if(b->sample_count>v->granulepos){
388 /* corner case; if this is both the first and last audio page, 390 /* corner case; if this is both the first and last audio page,
389 then spec says the end is cut, not beginning */ 391 then spec says the end is cut, not beginning */
390 if(vb->eofflag){ 392 if(vb->eofflag){
391 /* trim the end */ 393 /* trim the end */
392 /* no preceeding granulepos; assume we started at zero (we'd 394 /* no preceeding granulepos; assume we started at zero (we'd
393 have to in a short single-page stream) */ 395 have to in a short single-page stream) */
394 /* granulepos could be -1 due to a seek, but that would result 396 /* granulepos could be -1 due to a seek, but that would result
395 in a long coun`t, not short count */ 397 in a long coun`t, not short count */
396 398
397 v->pcm_current-=(b->sample_count-v->granulepos); 399 v->pcm_current-=(b->sample_count-v->granulepos);
398 }else{ 400 }else{
399 /* trim the beginning */ 401 /* trim the beginning */
400 v->pcm_returned+=(b->sample_count-v->granulepos); 402 v->pcm_returned+=(b->sample_count-v->granulepos);
401 if(v->pcm_returned>v->pcm_current) 403 if(v->pcm_returned>v->pcm_current)
402 v->pcm_returned=v->pcm_current; 404 v->pcm_returned=v->pcm_current;
403 } 405 }
404 406
405 } 407 }
406 408
407 } 409 }
408 }else{ 410 }else{
409 v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4; 411 v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
410 if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){ 412 if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
411 413
412 if(v->granulepos>vb->granulepos){ 414 if(v->granulepos>vb->granulepos){
413 long extra=v->granulepos-vb->granulepos; 415 long extra=v->granulepos-vb->granulepos;
414 416
415 if(extra) 417 if(extra)
416 if(vb->eofflag){ 418 if(vb->eofflag){
417 /* partial last frame. Strip the extra samples off */ 419 /* partial last frame. Strip the extra samples off */
418 v->pcm_current-=extra; 420 v->pcm_current-=extra;
419 } /* else {Shouldn't happen *unless* the bitstream is out of 421 } /* else {Shouldn't happen *unless* the bitstream is out of
420 spec. Either way, believe the bitstream } */ 422 spec. Either way, believe the bitstream } */
421 } /* else {Shouldn't happen *unless* the bitstream is out of 423 } /* else {Shouldn't happen *unless* the bitstream is out of
422 spec. Either way, believe the bitstream } */ 424 spec. Either way, believe the bitstream } */
diff --git a/core/multimedia/opieplayer/vorbis/tremor/info.c b/core/multimedia/opieplayer/vorbis/tremor/info.c
index 941695e..3499ae4 100644
--- a/core/multimedia/opieplayer/vorbis/tremor/info.c
+++ b/core/multimedia/opieplayer/vorbis/tremor/info.c
@@ -1,293 +1,293 @@
1/******************************************************************** 1/********************************************************************
2 * * 2 * *
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * 3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
4 * * 4 * *
5 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
6 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
7 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * * 8 * *
9 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * 9 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 *
10 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * 10 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
11 * * 11 * *
12 ******************************************************************** 12 ********************************************************************
13 13
14 function: maintain the info structure, info <-> header packets 14 function: maintain the info structure, info <-> header packets
15 15
16 ********************************************************************/ 16 ********************************************************************/
17 17
18/* general handling of the header and the vorbis_info structure (and 18/* general handling of the header and the vorbis_info structure (and
19 substructures) */ 19 substructures) */
20 20
21#include <stdlib.h> 21#include <stdlib.h>
22#include <string.h> 22#include <string.h>
23#include <ctype.h> 23#include <ctype.h>
24#include "ogg.h" 24#include "ogg.h"
25#include "ivorbiscodec.h" 25#include "ivorbiscodec.h"
26#include "codec_internal.h" 26#include "codec_internal.h"
27#include "codebook.h" 27#include "codebook.h"
28#include "registry.h" 28#include "registry.h"
29#include "window.h" 29#include "window.h"
30#include "misc.h" 30#include "misc.h"
31#include "os.h" 31#include "os.h"
32 32
33/* helpers */ 33/* helpers */
34static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){ 34static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
35 while(bytes--){ 35 while(bytes--){
36 *buf++=oggpack_read(o,8); 36 *buf++=oggpack_read(o,8);
37 } 37 }
38} 38}
39 39
40void vorbis_comment_init(vorbis_comment *vc){ 40void vorbis_comment_init(vorbis_comment *vc){
41 memset(vc,0,sizeof(*vc)); 41 memset(vc,0,sizeof(*vc));
42} 42}
43 43
44/* This is more or less the same as strncasecmp - but that doesn't exist 44/* This is more or less the same as strncasecmp - but that doesn't exist
45 * everywhere, and this is a fairly trivial function, so we include it */ 45 * everywhere, and this is a fairly trivial function, so we include it */
46static int tagcompare(const char *s1, const char *s2, int n){ 46static int tagcompare(const char *s1, const char *s2, int n){
47 int c=0; 47 int c=0;
48 while(c < n){ 48 while(c < n){
49 if(toupper(s1[c]) != toupper(s2[c])) 49 if(toupper(s1[c]) != toupper(s2[c]))
50 return !0; 50 return !0;
51 c++; 51 c++;
52 } 52 }
53 return 0; 53 return 0;
54} 54}
55 55
56char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){ 56char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
57 long i; 57 long i;
58 int found = 0; 58 int found = 0;
59 int taglen = strlen(tag)+1; /* +1 for the = we append */ 59 int taglen = strlen(tag)+1; /* +1 for the = we append */
60 char *fulltag = (char *)alloca(taglen+ 1); 60 char *fulltag = (char *)alloca(taglen+ 1);
61 61
62 strcpy(fulltag, tag); 62 strcpy(fulltag, tag);
63 strcat(fulltag, "="); 63 strcat(fulltag, "=");
64 64
65 for(i=0;i<vc->comments;i++){ 65 for(i=0;i<vc->comments;i++){
66 if(!tagcompare(vc->user_comments[i], fulltag, taglen)){ 66 if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
67 if(count == found) 67 if(count == found)
68 /* We return a pointer to the data, not a copy */ 68 /* We return a pointer to the data, not a copy */
69 return vc->user_comments[i] + taglen; 69 return vc->user_comments[i] + taglen;
70 else 70 else
71 found++; 71 found++;
72 } 72 }
73 } 73 }
74 return NULL; /* didn't find anything */ 74 return NULL; /* didn't find anything */
75} 75}
76 76
77int vorbis_comment_query_count(vorbis_comment *vc, char *tag){ 77int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
78 int i,count=0; 78 int i,count=0;
79 int taglen = strlen(tag)+1; /* +1 for the = we append */ 79 int taglen = strlen(tag)+1; /* +1 for the = we append */
80 char *fulltag = (char *)alloca(taglen+1); 80 char *fulltag = (char *)alloca(taglen+1);
81 strcpy(fulltag,tag); 81 strcpy(fulltag,tag);
82 strcat(fulltag, "="); 82 strcat(fulltag, "=");
83 83
84 for(i=0;i<vc->comments;i++){ 84 for(i=0;i<vc->comments;i++){
85 if(!tagcompare(vc->user_comments[i], fulltag, taglen)) 85 if(!tagcompare(vc->user_comments[i], fulltag, taglen))
86 count++; 86 count++;
87 } 87 }
88 88
89 return count; 89 return count;
90} 90}
91 91
92void vorbis_comment_clear(vorbis_comment *vc){ 92void vorbis_comment_clear(vorbis_comment *vc){
93 if(vc){ 93 if(vc){
94 long i; 94 long i;
95 for(i=0;i<vc->comments;i++) 95 for(i=0;i<vc->comments;i++)
96 if(vc->user_comments[i])_ogg_free(vc->user_comments[i]); 96 if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
97 if(vc->user_comments)_ogg_free(vc->user_comments); 97 if(vc->user_comments)_ogg_free(vc->user_comments);
98 if(vc->comment_lengths)_ogg_free(vc->comment_lengths); 98 if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
99 if(vc->vendor)_ogg_free(vc->vendor); 99 if(vc->vendor)_ogg_free(vc->vendor);
100 memset(vc,0,sizeof(*vc));
100 } 101 }
101 memset(vc,0,sizeof(*vc));
102} 102}
103 103
104/* blocksize 0 is guaranteed to be short, 1 is guarantted to be long. 104/* blocksize 0 is guaranteed to be short, 1 is guarantted to be long.
105 They may be equal, but short will never ge greater than long */ 105 They may be equal, but short will never ge greater than long */
106int vorbis_info_blocksize(vorbis_info *vi,int zo){ 106int vorbis_info_blocksize(vorbis_info *vi,int zo){
107 codec_setup_info *ci = (codec_setup_info *)vi->codec_setup; 107 codec_setup_info *ci = (codec_setup_info *)vi->codec_setup;
108 return ci ? ci->blocksizes[zo] : -1; 108 return ci ? ci->blocksizes[zo] : -1;
109} 109}
110 110
111/* used by synthesis, which has a full, alloced vi */ 111/* used by synthesis, which has a full, alloced vi */
112void vorbis_info_init(vorbis_info *vi){ 112void vorbis_info_init(vorbis_info *vi){
113 memset(vi,0,sizeof(*vi)); 113 memset(vi,0,sizeof(*vi));
114 vi->codec_setup=(codec_setup_info *)_ogg_calloc(1,sizeof(codec_setup_info)); 114 vi->codec_setup=(codec_setup_info *)_ogg_calloc(1,sizeof(codec_setup_info));
115} 115}
116 116
117void vorbis_info_clear(vorbis_info *vi){ 117void vorbis_info_clear(vorbis_info *vi){
118 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 118 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
119 int i; 119 int i;
120 120
121 if(ci){ 121 if(ci){
122 122
123 for(i=0;i<ci->modes;i++) 123 for(i=0;i<ci->modes;i++)
124 if(ci->mode_param[i])_ogg_free(ci->mode_param[i]); 124 if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
125 125
126 for(i=0;i<ci->maps;i++) /* unpack does the range checking */ 126 for(i=0;i<ci->maps;i++) /* unpack does the range checking */
127 _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]); 127 _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
128 128
129 for(i=0;i<ci->floors;i++) /* unpack does the range checking */ 129 for(i=0;i<ci->floors;i++) /* unpack does the range checking */
130 _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]); 130 _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
131 131
132 for(i=0;i<ci->residues;i++) /* unpack does the range checking */ 132 for(i=0;i<ci->residues;i++) /* unpack does the range checking */
133 _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]); 133 _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
134 134
135 for(i=0;i<ci->books;i++){ 135 for(i=0;i<ci->books;i++){
136 if(ci->book_param[i]){ 136 if(ci->book_param[i]){
137 /* knows if the book was not alloced */ 137 /* knows if the book was not alloced */
138 vorbis_staticbook_destroy(ci->book_param[i]); 138 vorbis_staticbook_destroy(ci->book_param[i]);
139 } 139 }
140 if(ci->fullbooks) 140 if(ci->fullbooks)
141 vorbis_book_clear(ci->fullbooks+i); 141 vorbis_book_clear(ci->fullbooks+i);
142 } 142 }
143 if(ci->fullbooks) 143 if(ci->fullbooks)
144 _ogg_free(ci->fullbooks); 144 _ogg_free(ci->fullbooks);
145 145
146 _ogg_free(ci); 146 _ogg_free(ci);
147 } 147 }
148 148
149 memset(vi,0,sizeof(*vi)); 149 memset(vi,0,sizeof(*vi));
150} 150}
151 151
152/* Header packing/unpacking ********************************************/ 152/* Header packing/unpacking ********************************************/
153 153
154static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){ 154static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
155 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 155 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
156 if(!ci)return(OV_EFAULT); 156 if(!ci)return(OV_EFAULT);
157 157
158 vi->version=oggpack_read(opb,32); 158 vi->version=oggpack_read(opb,32);
159 if(vi->version!=0)return(OV_EVERSION); 159 if(vi->version!=0)return(OV_EVERSION);
160 160
161 vi->channels=oggpack_read(opb,8); 161 vi->channels=oggpack_read(opb,8);
162 vi->rate=oggpack_read(opb,32); 162 vi->rate=oggpack_read(opb,32);
163 163
164 vi->bitrate_upper=oggpack_read(opb,32); 164 vi->bitrate_upper=oggpack_read(opb,32);
165 vi->bitrate_nominal=oggpack_read(opb,32); 165 vi->bitrate_nominal=oggpack_read(opb,32);
166 vi->bitrate_lower=oggpack_read(opb,32); 166 vi->bitrate_lower=oggpack_read(opb,32);
167 167
168 ci->blocksizes[0]=1<<oggpack_read(opb,4); 168 ci->blocksizes[0]=1<<oggpack_read(opb,4);
169 ci->blocksizes[1]=1<<oggpack_read(opb,4); 169 ci->blocksizes[1]=1<<oggpack_read(opb,4);
170 170
171 if(vi->rate<1)goto err_out; 171 if(vi->rate<1)goto err_out;
172 if(vi->channels<1)goto err_out; 172 if(vi->channels<1)goto err_out;
173 if(ci->blocksizes[0]<64)goto err_out; 173 if(ci->blocksizes[0]<64)goto err_out;
174 if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out; 174 if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
175 if(ci->blocksizes[1]>8192)goto err_out; 175 if(ci->blocksizes[1]>8192)goto err_out;
176 176
177 if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */ 177 if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
178 178
179 return(0); 179 return(0);
180 err_out: 180 err_out:
181 vorbis_info_clear(vi); 181 vorbis_info_clear(vi);
182 return(OV_EBADHEADER); 182 return(OV_EBADHEADER);
183} 183}
184 184
185static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){ 185static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
186 int i; 186 int i;
187 int vendorlen=oggpack_read(opb,32); 187 int vendorlen=oggpack_read(opb,32);
188 if(vendorlen<0)goto err_out; 188 if(vendorlen<0)goto err_out;
189 vc->vendor=(char *)_ogg_calloc(vendorlen+1,1); 189 vc->vendor=(char *)_ogg_calloc(vendorlen+1,1);
190 _v_readstring(opb,vc->vendor,vendorlen); 190 _v_readstring(opb,vc->vendor,vendorlen);
191 vc->comments=oggpack_read(opb,32); 191 vc->comments=oggpack_read(opb,32);
192 if(vc->comments<0)goto err_out; 192 if(vc->comments<0)goto err_out;
193 vc->user_comments=(char **)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments)); 193 vc->user_comments=(char **)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
194 vc->comment_lengths=(int *)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths)); 194 vc->comment_lengths=(int *)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
195 195
196 for(i=0;i<vc->comments;i++){ 196 for(i=0;i<vc->comments;i++){
197 int len=oggpack_read(opb,32); 197 int len=oggpack_read(opb,32);
198 if(len<0)goto err_out; 198 if(len<0)goto err_out;
199 vc->comment_lengths[i]=len; 199 vc->comment_lengths[i]=len;
200 vc->user_comments[i]=(char *)_ogg_calloc(len+1,1); 200 vc->user_comments[i]=(char *)_ogg_calloc(len+1,1);
201 _v_readstring(opb,vc->user_comments[i],len); 201 _v_readstring(opb,vc->user_comments[i],len);
202 } 202 }
203 if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */ 203 if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
204 204
205 return(0); 205 return(0);
206 err_out: 206 err_out:
207 vorbis_comment_clear(vc); 207 vorbis_comment_clear(vc);
208 return(OV_EBADHEADER); 208 return(OV_EBADHEADER);
209} 209}
210 210
211/* all of the real encoding details are here. The modes, books, 211/* all of the real encoding details are here. The modes, books,
212 everything */ 212 everything */
213static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){ 213static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
214 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 214 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
215 int i; 215 int i;
216 if(!ci)return(OV_EFAULT); 216 if(!ci)return(OV_EFAULT);
217 217
218 /* codebooks */ 218 /* codebooks */
219 ci->books=oggpack_read(opb,8)+1; 219 ci->books=oggpack_read(opb,8)+1;
220 /*ci->book_param=_ogg_calloc(ci->books,sizeof(*ci->book_param));*/ 220 /*ci->book_param=_ogg_calloc(ci->books,sizeof(*ci->book_param));*/
221 for(i=0;i<ci->books;i++){ 221 for(i=0;i<ci->books;i++){
222 ci->book_param[i]=(static_codebook *)_ogg_calloc(1,sizeof(*ci->book_param[i])); 222 ci->book_param[i]=(static_codebook *)_ogg_calloc(1,sizeof(*ci->book_param[i]));
223 if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out; 223 if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
224 } 224 }
225 225
226 /* time backend settings */ 226 /* time backend settings */
227 ci->times=oggpack_read(opb,6)+1; 227 ci->times=oggpack_read(opb,6)+1;
228 /*ci->time_type=_ogg_malloc(ci->times*sizeof(*ci->time_type));*/ 228 /*ci->time_type=_ogg_malloc(ci->times*sizeof(*ci->time_type));*/
229 /*ci->time_param=_ogg_calloc(ci->times,sizeof(void *));*/ 229 /*ci->time_param=_ogg_calloc(ci->times,sizeof(void *));*/
230 for(i=0;i<ci->times;i++){ 230 for(i=0;i<ci->times;i++){
231 ci->time_type[i]=oggpack_read(opb,16); 231 ci->time_type[i]=oggpack_read(opb,16);
232 if(ci->time_type[i]<0 || ci->time_type[i]>=VI_TIMEB)goto err_out; 232 if(ci->time_type[i]<0 || ci->time_type[i]>=VI_TIMEB)goto err_out;
233 /* ci->time_param[i]=_time_P[ci->time_type[i]]->unpack(vi,opb); 233 /* ci->time_param[i]=_time_P[ci->time_type[i]]->unpack(vi,opb);
234 Vorbis I has no time backend */ 234 Vorbis I has no time backend */
235 /*if(!ci->time_param[i])goto err_out;*/ 235 /*if(!ci->time_param[i])goto err_out;*/
236 } 236 }
237 237
238 /* floor backend settings */ 238 /* floor backend settings */
239 ci->floors=oggpack_read(opb,6)+1; 239 ci->floors=oggpack_read(opb,6)+1;
240 /*ci->floor_type=_ogg_malloc(ci->floors*sizeof(*ci->floor_type));*/ 240 /*ci->floor_type=_ogg_malloc(ci->floors*sizeof(*ci->floor_type));*/
241 /*ci->floor_param=_ogg_calloc(ci->floors,sizeof(void *));*/ 241 /*ci->floor_param=_ogg_calloc(ci->floors,sizeof(void *));*/
242 for(i=0;i<ci->floors;i++){ 242 for(i=0;i<ci->floors;i++){
243 ci->floor_type[i]=oggpack_read(opb,16); 243 ci->floor_type[i]=oggpack_read(opb,16);
244 if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out; 244 if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
245 ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb); 245 ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
246 if(!ci->floor_param[i])goto err_out; 246 if(!ci->floor_param[i])goto err_out;
247 } 247 }
248 248
249 /* residue backend settings */ 249 /* residue backend settings */
250 ci->residues=oggpack_read(opb,6)+1; 250 ci->residues=oggpack_read(opb,6)+1;
251 /*ci->residue_type=_ogg_malloc(ci->residues*sizeof(*ci->residue_type));*/ 251 /*ci->residue_type=_ogg_malloc(ci->residues*sizeof(*ci->residue_type));*/
252 /*ci->residue_param=_ogg_calloc(ci->residues,sizeof(void *));*/ 252 /*ci->residue_param=_ogg_calloc(ci->residues,sizeof(void *));*/
253 for(i=0;i<ci->residues;i++){ 253 for(i=0;i<ci->residues;i++){
254 ci->residue_type[i]=oggpack_read(opb,16); 254 ci->residue_type[i]=oggpack_read(opb,16);
255 if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out; 255 if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
256 ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb); 256 ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
257 if(!ci->residue_param[i])goto err_out; 257 if(!ci->residue_param[i])goto err_out;
258 } 258 }
259 259
260 /* map backend settings */ 260 /* map backend settings */
261 ci->maps=oggpack_read(opb,6)+1; 261 ci->maps=oggpack_read(opb,6)+1;
262 /*ci->map_type=_ogg_malloc(ci->maps*sizeof(*ci->map_type));*/ 262 /*ci->map_type=_ogg_malloc(ci->maps*sizeof(*ci->map_type));*/
263 /*ci->map_param=_ogg_calloc(ci->maps,sizeof(void *));*/ 263 /*ci->map_param=_ogg_calloc(ci->maps,sizeof(void *));*/
264 for(i=0;i<ci->maps;i++){ 264 for(i=0;i<ci->maps;i++){
265 ci->map_type[i]=oggpack_read(opb,16); 265 ci->map_type[i]=oggpack_read(opb,16);
266 if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out; 266 if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
267 ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb); 267 ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
268 if(!ci->map_param[i])goto err_out; 268 if(!ci->map_param[i])goto err_out;
269 } 269 }
270 270
271 /* mode settings */ 271 /* mode settings */
272 ci->modes=oggpack_read(opb,6)+1; 272 ci->modes=oggpack_read(opb,6)+1;
273 /*vi->mode_param=_ogg_calloc(vi->modes,sizeof(void *));*/ 273 /*vi->mode_param=_ogg_calloc(vi->modes,sizeof(void *));*/
274 for(i=0;i<ci->modes;i++){ 274 for(i=0;i<ci->modes;i++){
275 ci->mode_param[i]=(vorbis_info_mode *)_ogg_calloc(1,sizeof(*ci->mode_param[i])); 275 ci->mode_param[i]=(vorbis_info_mode *)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
276 ci->mode_param[i]->blockflag=oggpack_read(opb,1); 276 ci->mode_param[i]->blockflag=oggpack_read(opb,1);
277 ci->mode_param[i]->windowtype=oggpack_read(opb,16); 277 ci->mode_param[i]->windowtype=oggpack_read(opb,16);
278 ci->mode_param[i]->transformtype=oggpack_read(opb,16); 278 ci->mode_param[i]->transformtype=oggpack_read(opb,16);
279 ci->mode_param[i]->mapping=oggpack_read(opb,8); 279 ci->mode_param[i]->mapping=oggpack_read(opb,8);
280 280
281 if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out; 281 if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
282 if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out; 282 if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
283 if(ci->mode_param[i]->mapping>=ci->maps)goto err_out; 283 if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
284 } 284 }
285 285
286 if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */ 286 if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
287 287
288 return(0); 288 return(0);
289 err_out: 289 err_out:
290 vorbis_info_clear(vi); 290 vorbis_info_clear(vi);
291 return(OV_EBADHEADER); 291 return(OV_EBADHEADER);
292} 292}
293 293
diff --git a/noncore/apps/opie-write/qrichtext.cpp b/noncore/apps/opie-write/qrichtext.cpp
index f040f1e..768da44 100644
--- a/noncore/apps/opie-write/qrichtext.cpp
+++ b/noncore/apps/opie-write/qrichtext.cpp
@@ -1,427 +1,436 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Implementation of the internal Qt classes dealing with rich text 4** Implementation of the internal Qt classes dealing with rich text
5** 5**
6** Created : 990101 6** Created : 990101
7** 7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the kernel module of the Qt GUI Toolkit. 10** This file is part of the kernel module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "qrichtext_p.h" 38#include "qrichtext_p.h"
39 39
40/* OPIE */ 40/* OPIE */
41#include <opie2/odebug.h> 41#include <opie2/odebug.h>
42using namespace Opie::Core; 42using namespace Opie::Core;
43 43
44/* QT */ 44/* QT */
45#include "qdragobject.h" 45#include "qdragobject.h"
46#include "qpaintdevicemetrics.h" 46#include "qpaintdevicemetrics.h"
47#include "qdrawutil.h" 47#include "qdrawutil.h"
48#include "qcleanuphandler.h" 48#include "qcleanuphandler.h"
49 49
50/* STD */ 50/* STD */
51#include <stdlib.h> 51#include <stdlib.h>
52 52
53using namespace Qt3; 53using namespace Qt3;
54 54
55static QTextCursor* richTextExportStart = 0; 55static QTextCursor* richTextExportStart = 0;
56static QTextCursor* richTextExportEnd = 0; 56static QTextCursor* richTextExportEnd = 0;
57 57
58static QTextFormatCollection *qFormatCollection = 0; 58static QTextFormatCollection *qFormatCollection = 0;
59 59
60const int border_tolerance = 2; 60const int border_tolerance = 2;
61 61
62#ifdef Q_WS_WIN 62#ifdef Q_WS_WIN
63#include "qt_windows.h" 63#include "qt_windows.h"
64#endif 64#endif
65 65
66#define QChar_linesep QChar(0x2028U) 66#define QChar_linesep QChar(0x2028U)
67 67
68static inline bool is_printer( QPainter *p ) 68static inline bool is_printer( QPainter *p )
69{ 69{
70 if ( !p || !p->device() ) 70 if ( !p || !p->device() )
71 return FALSE; 71 return FALSE;
72 return p->device()->devType() == QInternal::Printer; 72 return p->device()->devType() == QInternal::Printer;
73} 73}
74 74
75static inline int scale( int value, QPainter *painter ) 75static inline int scale( int value, QPainter *painter )
76{ 76{
77 if ( is_printer( painter ) ) { 77 if ( is_printer( painter ) ) {
78 QPaintDeviceMetrics metrics( painter->device() ); 78 QPaintDeviceMetrics metrics( painter->device() );
79#if defined(Q_WS_X11) 79#if defined(Q_WS_X11)
80 value = value * metrics.logicalDpiY() / QPaintDevice::x11AppDpiY(); 80 value = value * metrics.logicalDpiY() / QPaintDevice::x11AppDpiY();
81#elif defined (Q_WS_WIN) 81#elif defined (Q_WS_WIN)
82 HDC hdc = GetDC( 0 ); 82 HDC hdc = GetDC( 0 );
83 int gdc = GetDeviceCaps( hdc, LOGPIXELSY ); 83 int gdc = GetDeviceCaps( hdc, LOGPIXELSY );
84 if ( gdc ) 84 if ( gdc )
85 value = value * metrics.logicalDpiY() / gdc; 85 value = value * metrics.logicalDpiY() / gdc;
86 ReleaseDC( 0, hdc ); 86 ReleaseDC( 0, hdc );
87#elif defined (Q_WS_MAC) 87#elif defined (Q_WS_MAC)
88 value = value * metrics.logicalDpiY() / 75; // ##### FIXME 88 value = value * metrics.logicalDpiY() / 75; // ##### FIXME
89#elif defined (Q_WS_QWS) 89#elif defined (Q_WS_QWS)
90 value = value * metrics.logicalDpiY() / 75; 90 value = value * metrics.logicalDpiY() / 75;
91#endif 91#endif
92 } 92 }
93 return value; 93 return value;
94} 94}
95 95
96// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 96// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
97 97
98void QTextCommandHistory::addCommand( QTextCommand *cmd ) 98void QTextCommandHistory::addCommand( QTextCommand *cmd )
99{ 99{
100 if ( current < (int)history.count() - 1 ) { 100 if ( current < (int)history.count() - 1 ) {
101 QPtrList<QTextCommand> commands; 101 QPtrList<QTextCommand> commands;
102 commands.setAutoDelete( FALSE ); 102 commands.setAutoDelete( FALSE );
103 103
104 for( int i = 0; i <= current; ++i ) { 104 for( int i = 0; i <= current; ++i ) {
105 commands.insert( i, history.at( 0 ) ); 105 commands.insert( i, history.at( 0 ) );
106 history.take( 0 ); 106 history.take( 0 );
107 } 107 }
108 108
109 commands.append( cmd ); 109 commands.append( cmd );
110 history.clear(); 110 history.clear();
111 history = commands; 111 history = commands;
112 history.setAutoDelete( TRUE ); 112 history.setAutoDelete( TRUE );
113 } else { 113 } else {
114 history.append( cmd ); 114 history.append( cmd );
115 } 115 }
116 116
117 if ( (int)history.count() > steps ) 117 if ( (int)history.count() > steps )
118 history.removeFirst(); 118 history.removeFirst();
119 else 119 else
120 ++current; 120 ++current;
121} 121}
122 122
123QTextCursor *QTextCommandHistory::undo( QTextCursor *c ) 123QTextCursor *QTextCommandHistory::undo( QTextCursor *c )
124{ 124{
125 if ( current > -1 ) { 125 if ( current > -1 ) {
126 QTextCursor *c2 = history.at( current )->unexecute( c ); 126 QTextCursor *c2 = history.at( current )->unexecute( c );
127 --current; 127 --current;
128 return c2; 128 return c2;
129 } 129 }
130 return 0; 130 return 0;
131} 131}
132 132
133QTextCursor *QTextCommandHistory::redo( QTextCursor *c ) 133QTextCursor *QTextCommandHistory::redo( QTextCursor *c )
134{ 134{
135 if ( current > -1 ) { 135 if ( current > -1 ) {
136 if ( current < (int)history.count() - 1 ) { 136 if ( current < (int)history.count() - 1 ) {
137 ++current; 137 ++current;
138 return history.at( current )->execute( c ); 138 return history.at( current )->execute( c );
139 } 139 }
140 } else { 140 } else {
141 if ( history.count() > 0 ) { 141 if ( history.count() > 0 ) {
142 ++current; 142 ++current;
143 return history.at( current )->execute( c ); 143 return history.at( current )->execute( c );
144 } 144 }
145 } 145 }
146 return 0; 146 return 0;
147} 147}
148 148
149bool QTextCommandHistory::isUndoAvailable() 149bool QTextCommandHistory::isUndoAvailable()
150{ 150{
151 return current > -1; 151 return current > -1;
152} 152}
153 153
154bool QTextCommandHistory::isRedoAvailable() 154bool QTextCommandHistory::isRedoAvailable()
155{ 155{
156 return current > -1 && current < (int)history.count() - 1 || current == -1 && history.count() > 0; 156 return current > -1 && current < (int)history.count() - 1 || current == -1 && history.count() > 0;
157} 157}
158 158
159// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 159// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
160 160
161QTextDeleteCommand::QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, 161QTextDeleteCommand::QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str,
162 const QByteArray& oldStyleInfo ) 162 const QByteArray& oldStyleInfo )
163 : QTextCommand( d ), id( i ), index( idx ), parag( 0 ), text( str ), styleInformation( oldStyleInfo ) 163 : QTextCommand( d ), id( i ), index( idx ), parag( 0 ), text( str ), styleInformation( oldStyleInfo )
164{ 164{
165 for ( int j = 0; j < (int)text.size(); ++j ) { 165 for ( int j = 0; j < (int)text.size(); ++j ) {
166 if ( text[ j ].format() ) 166 if ( text[ j ].format() )
167 text[ j ].format()->addRef(); 167 text[ j ].format()->addRef();
168 } 168 }
169} 169}
170 170
171QTextDeleteCommand::QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str ) 171QTextDeleteCommand::QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str )
172 : QTextCommand( 0 ), id( -1 ), index( idx ), parag( p ), text( str ) 172 : QTextCommand( 0 ), id( -1 ), index( idx ), parag( p ), text( str )
173{ 173{
174 for ( int i = 0; i < (int)text.size(); ++i ) { 174 for ( int i = 0; i < (int)text.size(); ++i ) {
175 if ( text[ i ].format() ) 175 if ( text[ i ].format() )
176 text[ i ].format()->addRef(); 176 text[ i ].format()->addRef();
177 } 177 }
178} 178}
179 179
180QTextDeleteCommand::~QTextDeleteCommand() 180QTextDeleteCommand::~QTextDeleteCommand()
181{ 181{
182 for ( int i = 0; i < (int)text.size(); ++i ) { 182 for ( int i = 0; i < (int)text.size(); ++i ) {
183 if ( text[ i ].format() ) 183 if ( text[ i ].format() )
184 text[ i ].format()->removeRef(); 184 text[ i ].format()->removeRef();
185 } 185 }
186 text.resize( 0 ); 186 text.resize( 0 );
187} 187}
188 188
189QTextCursor *QTextDeleteCommand::execute( QTextCursor *c ) 189QTextCursor *QTextDeleteCommand::execute( QTextCursor *c )
190{ 190{
191 QTextParagraph *s = doc ? doc->paragAt( id ) : parag; 191 QTextParagraph *s = doc ? doc->paragAt( id ) : parag;
192 if ( !s ) { 192 if ( !s && doc ) {
193 owarn << "can't locate parag at " << id << ", last parag: " << doc->lastParagraph()->paragId() << "" << oendl; 193 owarn << "can't locate parag at " << id << ", last parag: " << doc->lastParagraph()->paragId() << "" << oendl;
194 return 0; 194 return 0;
195 } else if ( !doc ) {
196 owarn << "No valid doc" << oendl;
197 return 0;
195 } 198 }
196 199
197 cursor.setParagraph( s ); 200 cursor.setParagraph( s );
198 cursor.setIndex( index ); 201 cursor.setIndex( index );
199 int len = text.size(); 202 int len = text.size();
200 if ( c ) 203 if ( c )
201 *c = cursor; 204 *c = cursor;
202 if ( doc ) { 205 if ( doc ) {
203 doc->setSelectionStart( QTextDocument::Temp, cursor ); 206 doc->setSelectionStart( QTextDocument::Temp, cursor );
204 for ( int i = 0; i < len; ++i ) 207 for ( int i = 0; i < len; ++i )
205 cursor.gotoNextLetter(); 208 cursor.gotoNextLetter();
206 doc->setSelectionEnd( QTextDocument::Temp, cursor ); 209 doc->setSelectionEnd( QTextDocument::Temp, cursor );
207 doc->removeSelectedText( QTextDocument::Temp, &cursor ); 210 doc->removeSelectedText( QTextDocument::Temp, &cursor );
208 if ( c ) 211 if ( c )
209 *c = cursor; 212 *c = cursor;
210 } else { 213 } else {
211 s->remove( index, len ); 214 s->remove( index, len );
212 } 215 }
213 216
214 return c; 217 return c;
215} 218}
216 219
217QTextCursor *QTextDeleteCommand::unexecute( QTextCursor *c ) 220QTextCursor *QTextDeleteCommand::unexecute( QTextCursor *c )
218{ 221{
219 QTextParagraph *s = doc ? doc->paragAt( id ) : parag; 222 QTextParagraph *s = doc ? doc->paragAt( id ) : parag;
220 if ( !s ) { 223 if ( !s && doc ) {
221 owarn << "can't locate parag at " << id << ", last parag: " << doc->lastParagraph()->paragId() << "" << oendl; 224 owarn << "can't locate parag at " << id << ", last parag: " << doc->lastParagraph()->paragId() << "" << oendl;
222 return 0; 225 return 0;
226 } else if ( !doc ) {
227 owarn << "No valid doc" << oendl;
228 return 0;
223 } 229 }
224 230
225 cursor.setParagraph( s ); 231 cursor.setParagraph( s );
226 cursor.setIndex( index ); 232 cursor.setIndex( index );
227 QString str = QTextString::toString( text ); 233 QString str = QTextString::toString( text );
228 cursor.insert( str, TRUE, &text ); 234 cursor.insert( str, TRUE, &text );
229 cursor.setParagraph( s ); 235 cursor.setParagraph( s );
230 cursor.setIndex( index ); 236 cursor.setIndex( index );
231 if ( c ) { 237 if ( c ) {
232 c->setParagraph( s ); 238 c->setParagraph( s );
233 c->setIndex( index ); 239 c->setIndex( index );
234 for ( int i = 0; i < (int)text.size(); ++i ) 240 for ( int i = 0; i < (int)text.size(); ++i )
235 c->gotoNextLetter(); 241 c->gotoNextLetter();
242 } else {
243 owarn << "No valid cursor" << oendl;
244 return 0;
236 } 245 }
237 246
238 if ( !styleInformation.isEmpty() ) { 247 if ( !styleInformation.isEmpty() ) {
239 QDataStream styleStream( styleInformation, IO_ReadOnly ); 248 QDataStream styleStream( styleInformation, IO_ReadOnly );
240 int num; 249 int num;
241 styleStream >> num; 250 styleStream >> num;
242 QTextParagraph *p = s; 251 QTextParagraph *p = s;
243 while ( num-- && p ) { 252 while ( num-- && p ) {
244 p->readStyleInformation( styleStream ); 253 p->readStyleInformation( styleStream );
245 p = p->next(); 254 p = p->next();
246 } 255 }
247 } 256 }
248 s = cursor.paragraph(); 257 s = cursor.paragraph();
249 while ( s ) { 258 while ( s ) {
250 s->format(); 259 s->format();
251 s->setChanged( TRUE ); 260 s->setChanged( TRUE );
252 if ( s == c->paragraph() ) 261 if ( s == c->paragraph() )
253 break; 262 break;
254 s = s->next(); 263 s = s->next();
255 } 264 }
256 265
257 return &cursor; 266 return &cursor;
258} 267}
259 268
260QTextFormatCommand::QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx, 269QTextFormatCommand::QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx,
261 const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl ) 270 const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl )
262 : QTextCommand( d ), startId( sid ), startIndex( sidx ), endId( eid ), endIndex( eidx ), format( f ), oldFormats( old ), flags( fl ) 271 : QTextCommand( d ), startId( sid ), startIndex( sidx ), endId( eid ), endIndex( eidx ), format( f ), oldFormats( old ), flags( fl )
263{ 272{
264 format = d->formatCollection()->format( f ); 273 format = d->formatCollection()->format( f );
265 for ( int j = 0; j < (int)oldFormats.size(); ++j ) { 274 for ( int j = 0; j < (int)oldFormats.size(); ++j ) {
266 if ( oldFormats[ j ].format() ) 275 if ( oldFormats[ j ].format() )
267 oldFormats[ j ].format()->addRef(); 276 oldFormats[ j ].format()->addRef();
268 } 277 }
269} 278}
270 279
271QTextFormatCommand::~QTextFormatCommand() 280QTextFormatCommand::~QTextFormatCommand()
272{ 281{
273 format->removeRef(); 282 format->removeRef();
274 for ( int j = 0; j < (int)oldFormats.size(); ++j ) { 283 for ( int j = 0; j < (int)oldFormats.size(); ++j ) {
275 if ( oldFormats[ j ].format() ) 284 if ( oldFormats[ j ].format() )
276 oldFormats[ j ].format()->removeRef(); 285 oldFormats[ j ].format()->removeRef();
277 } 286 }
278} 287}
279 288
280QTextCursor *QTextFormatCommand::execute( QTextCursor *c ) 289QTextCursor *QTextFormatCommand::execute( QTextCursor *c )
281{ 290{
282 QTextParagraph *sp = doc->paragAt( startId ); 291 QTextParagraph *sp = doc->paragAt( startId );
283 QTextParagraph *ep = doc->paragAt( endId ); 292 QTextParagraph *ep = doc->paragAt( endId );
284 if ( !sp || !ep ) 293 if ( !sp || !ep )
285 return c; 294 return c;
286 295
287 QTextCursor start( doc ); 296 QTextCursor start( doc );
288 start.setParagraph( sp ); 297 start.setParagraph( sp );
289 start.setIndex( startIndex ); 298 start.setIndex( startIndex );
290 QTextCursor end( doc ); 299 QTextCursor end( doc );
291 end.setParagraph( ep ); 300 end.setParagraph( ep );
292 end.setIndex( endIndex ); 301 end.setIndex( endIndex );
293 302
294 doc->setSelectionStart( QTextDocument::Temp, start ); 303 doc->setSelectionStart( QTextDocument::Temp, start );
295 doc->setSelectionEnd( QTextDocument::Temp, end ); 304 doc->setSelectionEnd( QTextDocument::Temp, end );
296 doc->setFormat( QTextDocument::Temp, format, flags ); 305 doc->setFormat( QTextDocument::Temp, format, flags );
297 doc->removeSelection( QTextDocument::Temp ); 306 doc->removeSelection( QTextDocument::Temp );
298 if ( endIndex == ep->length() ) 307 if ( endIndex == ep->length() )
299 end.gotoLeft(); 308 end.gotoLeft();
300 *c = end; 309 *c = end;
301 return c; 310 return c;
302} 311}
303 312
304QTextCursor *QTextFormatCommand::unexecute( QTextCursor *c ) 313QTextCursor *QTextFormatCommand::unexecute( QTextCursor *c )
305{ 314{
306 QTextParagraph *sp = doc->paragAt( startId ); 315 QTextParagraph *sp = doc->paragAt( startId );
307 QTextParagraph *ep = doc->paragAt( endId ); 316 QTextParagraph *ep = doc->paragAt( endId );
308 if ( !sp || !ep ) 317 if ( !sp || !ep )
309 return 0; 318 return 0;
310 319
311 int idx = startIndex; 320 int idx = startIndex;
312 int fIndex = 0; 321 int fIndex = 0;
313 for ( ;; ) { 322 for ( ;; ) {
314 if ( oldFormats.at( fIndex ).c == '\n' ) { 323 if ( oldFormats.at( fIndex ).c == '\n' ) {
315 if ( idx > 0 ) { 324 if ( idx > 0 ) {
316 if ( idx < sp->length() && fIndex > 0 ) 325 if ( idx < sp->length() && fIndex > 0 )
317 sp->setFormat( idx, 1, oldFormats.at( fIndex - 1 ).format() ); 326 sp->setFormat( idx, 1, oldFormats.at( fIndex - 1 ).format() );
318 if ( sp == ep ) 327 if ( sp == ep )
319 break; 328 break;
320 sp = sp->next(); 329 sp = sp->next();
321 idx = 0; 330 idx = 0;
322 } 331 }
323 fIndex++; 332 fIndex++;
324 } 333 }
325 if ( oldFormats.at( fIndex ).format() ) 334 if ( oldFormats.at( fIndex ).format() )
326 sp->setFormat( idx, 1, oldFormats.at( fIndex ).format() ); 335 sp->setFormat( idx, 1, oldFormats.at( fIndex ).format() );
327 idx++; 336 idx++;
328 fIndex++; 337 fIndex++;
329 if ( fIndex >= (int)oldFormats.size() ) 338 if ( fIndex >= (int)oldFormats.size() )
330 break; 339 break;
331 if ( idx >= sp->length() ) { 340 if ( idx >= sp->length() ) {
332 if ( sp == ep ) 341 if ( sp == ep )
333 break; 342 break;
334 sp = sp->next(); 343 sp = sp->next();
335 idx = 0; 344 idx = 0;
336 } 345 }
337 } 346 }
338 347
339 QTextCursor end( doc ); 348 QTextCursor end( doc );
340 end.setParagraph( ep ); 349 end.setParagraph( ep );
341 end.setIndex( endIndex ); 350 end.setIndex( endIndex );
342 if ( endIndex == ep->length() ) 351 if ( endIndex == ep->length() )
343 end.gotoLeft(); 352 end.gotoLeft();
344 *c = end; 353 *c = end;
345 return c; 354 return c;
346} 355}
347 356
348QTextStyleCommand::QTextStyleCommand( QTextDocument *d, int fParag, int lParag, const QByteArray& beforeChange ) 357QTextStyleCommand::QTextStyleCommand( QTextDocument *d, int fParag, int lParag, const QByteArray& beforeChange )
349 : QTextCommand( d ), firstParag( fParag ), lastParag( lParag ), before( beforeChange ) 358 : QTextCommand( d ), firstParag( fParag ), lastParag( lParag ), before( beforeChange )
350{ 359{
351 after = readStyleInformation( d, fParag, lParag ); 360 after = readStyleInformation( d, fParag, lParag );
352} 361}
353 362
354 363
355QByteArray QTextStyleCommand::readStyleInformation( QTextDocument* doc, int fParag, int lParag ) 364QByteArray QTextStyleCommand::readStyleInformation( QTextDocument* doc, int fParag, int lParag )
356{ 365{
357 QByteArray style; 366 QByteArray style;
358 QTextParagraph *p = doc->paragAt( fParag ); 367 QTextParagraph *p = doc->paragAt( fParag );
359 if ( !p ) 368 if ( !p )
360 return style; 369 return style;
361 QDataStream styleStream( style, IO_WriteOnly ); 370 QDataStream styleStream( style, IO_WriteOnly );
362 int num = lParag - fParag + 1; 371 int num = lParag - fParag + 1;
363 styleStream << num; 372 styleStream << num;
364 while ( num -- && p ) { 373 while ( num -- && p ) {
365 p->writeStyleInformation( styleStream ); 374 p->writeStyleInformation( styleStream );
366 p = p->next(); 375 p = p->next();
367 } 376 }
368 return style; 377 return style;
369} 378}
370 379
371void QTextStyleCommand::writeStyleInformation( QTextDocument* doc, int fParag, const QByteArray& style ) 380void QTextStyleCommand::writeStyleInformation( QTextDocument* doc, int fParag, const QByteArray& style )
372{ 381{
373 QTextParagraph *p = doc->paragAt( fParag ); 382 QTextParagraph *p = doc->paragAt( fParag );
374 if ( !p ) 383 if ( !p )
375 return; 384 return;
376 QDataStream styleStream( style, IO_ReadOnly ); 385 QDataStream styleStream( style, IO_ReadOnly );
377 int num; 386 int num;
378 styleStream >> num; 387 styleStream >> num;
379 while ( num-- && p ) { 388 while ( num-- && p ) {
380 p->readStyleInformation( styleStream ); 389 p->readStyleInformation( styleStream );
381 p = p->next(); 390 p = p->next();
382 } 391 }
383} 392}
384 393
385QTextCursor *QTextStyleCommand::execute( QTextCursor *c ) 394QTextCursor *QTextStyleCommand::execute( QTextCursor *c )
386{ 395{
387 writeStyleInformation( doc, firstParag, after ); 396 writeStyleInformation( doc, firstParag, after );
388 return c; 397 return c;
389} 398}
390 399
391QTextCursor *QTextStyleCommand::unexecute( QTextCursor *c ) 400QTextCursor *QTextStyleCommand::unexecute( QTextCursor *c )
392{ 401{
393 writeStyleInformation( doc, firstParag, before ); 402 writeStyleInformation( doc, firstParag, before );
394 return c; 403 return c;
395} 404}
396 405
397// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 406// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
398 407
399QTextCursor::QTextCursor( QTextDocument *d ) 408QTextCursor::QTextCursor( QTextDocument *d )
400 : idx( 0 ), tmpIndex( -1 ), ox( 0 ), oy( 0 ), 409 : idx( 0 ), tmpIndex( -1 ), ox( 0 ), oy( 0 ),
401 valid( TRUE ) 410 valid( TRUE )
402{ 411{
403 para = d ? d->firstParagraph() : 0; 412 para = d ? d->firstParagraph() : 0;
404} 413}
405 414
406QTextCursor::QTextCursor( const QTextCursor &c ) 415QTextCursor::QTextCursor( const QTextCursor &c )
407{ 416{
408 ox = c.ox; 417 ox = c.ox;
409 oy = c.oy; 418 oy = c.oy;
410 idx = c.idx; 419 idx = c.idx;
411 para = c.para; 420 para = c.para;
412 tmpIndex = c.tmpIndex; 421 tmpIndex = c.tmpIndex;
413 indices = c.indices; 422 indices = c.indices;
414 paras = c.paras; 423 paras = c.paras;
415 xOffsets = c.xOffsets; 424 xOffsets = c.xOffsets;
416 yOffsets = c.yOffsets; 425 yOffsets = c.yOffsets;
417 valid = c.valid; 426 valid = c.valid;
418} 427}
419 428
420QTextCursor &QTextCursor::operator=( const QTextCursor &c ) 429QTextCursor &QTextCursor::operator=( const QTextCursor &c )
421{ 430{
422 ox = c.ox; 431 ox = c.ox;
423 oy = c.oy; 432 oy = c.oy;
424 idx = c.idx; 433 idx = c.idx;
425 para = c.para; 434 para = c.para;
426 tmpIndex = c.tmpIndex; 435 tmpIndex = c.tmpIndex;
427 indices = c.indices; 436 indices = c.indices;
@@ -1203,402 +1212,413 @@ void QTextDocument::init()
1203 backBrush = 0; 1212 backBrush = 0;
1204 buf_pixmap = 0; 1213 buf_pixmap = 0;
1205 nextDoubleBuffered = FALSE; 1214 nextDoubleBuffered = FALSE;
1206 1215
1207 if ( par ) 1216 if ( par )
1208 withoutDoubleBuffer = par->withoutDoubleBuffer; 1217 withoutDoubleBuffer = par->withoutDoubleBuffer;
1209 else 1218 else
1210 withoutDoubleBuffer = FALSE; 1219 withoutDoubleBuffer = FALSE;
1211 1220
1212 lParag = fParag = createParagraph( this, 0, 0 ); 1221 lParag = fParag = createParagraph( this, 0, 0 );
1213 1222
1214 cx = 0; 1223 cx = 0;
1215 cy = 2; 1224 cy = 2;
1216 if ( par ) 1225 if ( par )
1217 cx = cy = 0; 1226 cx = cy = 0;
1218 cw = 600; 1227 cw = 600;
1219 vw = 0; 1228 vw = 0;
1220 flow_ = new QTextFlow; 1229 flow_ = new QTextFlow;
1221 flow_->setWidth( cw ); 1230 flow_->setWidth( cw );
1222 1231
1223 leftmargin = rightmargin = 4; 1232 leftmargin = rightmargin = 4;
1224 scaleFontsFactor = 1; 1233 scaleFontsFactor = 1;
1225 1234
1226 1235
1227 selectionColors[ Standard ] = QApplication::palette().color( QPalette::Active, QColorGroup::Highlight ); 1236 selectionColors[ Standard ] = QApplication::palette().color( QPalette::Active, QColorGroup::Highlight );
1228 selectionText[ Standard ] = TRUE; 1237 selectionText[ Standard ] = TRUE;
1229 commandHistory = new QTextCommandHistory( 100 ); 1238 commandHistory = new QTextCommandHistory( 100 );
1230 tStopWidth = formatCollection()->defaultFormat()->width( 'x' ) * 8; 1239 tStopWidth = formatCollection()->defaultFormat()->width( 'x' ) * 8;
1231} 1240}
1232 1241
1233QTextDocument::~QTextDocument() 1242QTextDocument::~QTextDocument()
1234{ 1243{
1235 if ( par ) 1244 if ( par )
1236 par->removeChild( this ); 1245 par->removeChild( this );
1237 clear(); 1246 clear();
1238 delete commandHistory; 1247 delete commandHistory;
1239 delete flow_; 1248 delete flow_;
1240 if ( !par ) 1249 if ( !par )
1241 delete pFormatter; 1250 delete pFormatter;
1242 delete fCollection; 1251 delete fCollection;
1243 delete pProcessor; 1252 delete pProcessor;
1244 delete buf_pixmap; 1253 delete buf_pixmap;
1245 delete indenter; 1254 delete indenter;
1246 delete backBrush; 1255 delete backBrush;
1247 if ( tArray ) 1256 if ( tArray )
1248 delete [] tArray; 1257 delete [] tArray;
1249} 1258}
1250 1259
1251void QTextDocument::clear( bool createEmptyParag ) 1260void QTextDocument::clear( bool createEmptyParag )
1252{ 1261{
1253 if ( flow_ ) 1262 if ( flow_ )
1254 flow_->clear(); 1263 flow_->clear();
1255 while ( fParag ) { 1264 while ( fParag ) {
1256 QTextParagraph *p = fParag->next(); 1265 QTextParagraph *p = fParag->next();
1257 delete fParag; 1266 delete fParag;
1258 fParag = p; 1267 fParag = p;
1259 } 1268 }
1260 fParag = lParag = 0; 1269 fParag = lParag = 0;
1261 if ( createEmptyParag ) 1270 if ( createEmptyParag )
1262 fParag = lParag = createParagraph( this ); 1271 fParag = lParag = createParagraph( this );
1263 selections.clear(); 1272 selections.clear();
1264 oText = QString::null; 1273 oText = QString::null;
1265 oTextValid = TRUE; 1274 oTextValid = TRUE;
1266} 1275}
1267 1276
1268int QTextDocument::widthUsed() const 1277int QTextDocument::widthUsed() const
1269{ 1278{
1270 return wused + border_tolerance; 1279 return wused + border_tolerance;
1271} 1280}
1272 1281
1273int QTextDocument::height() const 1282int QTextDocument::height() const
1274{ 1283{
1275 int h = 0; 1284 int h = 0;
1276 if ( lParag ) 1285 if ( lParag )
1277 h = lParag->rect().top() + lParag->rect().height() + 1; 1286 h = lParag->rect().top() + lParag->rect().height() + 1;
1278 int fh = flow_->boundingRect().bottom(); 1287 int fh = flow_->boundingRect().bottom();
1279 return QMAX( h, fh ); 1288 return QMAX( h, fh );
1280} 1289}
1281 1290
1282 1291
1283 1292
1284QTextParagraph *QTextDocument::createParagraph( QTextDocument *d, QTextParagraph *pr, QTextParagraph *nx, bool updateIds ) 1293QTextParagraph *QTextDocument::createParagraph( QTextDocument *d, QTextParagraph *pr, QTextParagraph *nx, bool updateIds )
1285{ 1294{
1286 return new QTextParagraph( d, pr, nx, updateIds ); 1295 return new QTextParagraph( d, pr, nx, updateIds );
1287} 1296}
1288 1297
1289bool QTextDocument::setMinimumWidth( int needed, int used, QTextParagraph *p ) 1298bool QTextDocument::setMinimumWidth( int needed, int used, QTextParagraph *p )
1290{ 1299{
1291 if ( needed == -1 ) { 1300 if ( needed == -1 ) {
1292 minw = 0; 1301 minw = 0;
1293 wused = 0; 1302 wused = 0;
1294 p = 0; 1303 p = 0;
1295 } 1304 }
1296 if ( p == minwParag ) { 1305 if ( p == minwParag ) {
1297 minw = needed; 1306 minw = needed;
1298 emit minimumWidthChanged( minw ); 1307 emit minimumWidthChanged( minw );
1299 } else if ( needed > minw ) { 1308 } else if ( needed > minw ) {
1300 minw = needed; 1309 minw = needed;
1301 minwParag = p; 1310 minwParag = p;
1302 emit minimumWidthChanged( minw ); 1311 emit minimumWidthChanged( minw );
1303 } 1312 }
1304 wused = QMAX( wused, used ); 1313 wused = QMAX( wused, used );
1305 wused = QMAX( wused, minw ); 1314 wused = QMAX( wused, minw );
1306 cw = QMAX( minw, cw ); 1315 cw = QMAX( minw, cw );
1307 return TRUE; 1316 return TRUE;
1308} 1317}
1309 1318
1310void QTextDocument::setPlainText( const QString &text ) 1319void QTextDocument::setPlainText( const QString &text )
1311{ 1320{
1312 clear(); 1321 clear();
1313 preferRichText = FALSE; 1322 preferRichText = FALSE;
1314 oTextValid = TRUE; 1323 oTextValid = TRUE;
1315 oText = text; 1324 oText = text;
1316 1325
1317 int lastNl = 0; 1326 int lastNl = 0;
1318 int nl = text.find( '\n' ); 1327 int nl = text.find( '\n' );
1319 if ( nl == -1 ) { 1328 if ( nl == -1 ) {
1320 lParag = createParagraph( this, lParag, 0 ); 1329 lParag = createParagraph( this, lParag, 0 );
1321 if ( !fParag ) 1330 if ( !fParag )
1322 fParag = lParag; 1331 fParag = lParag;
1323 QString s = text; 1332 QString s = text;
1324 if ( !s.isEmpty() ) { 1333 if ( !s.isEmpty() ) {
1325 if ( s[ (int)s.length() - 1 ] == '\r' ) 1334 if ( s[ (int)s.length() - 1 ] == '\r' )
1326 s.remove( s.length() - 1, 1 ); 1335 s.remove( s.length() - 1, 1 );
1327 lParag->append( s ); 1336 lParag->append( s );
1328 } 1337 }
1329 } else { 1338 } else {
1330 for (;;) { 1339 for (;;) {
1331 lParag = createParagraph( this, lParag, 0 ); 1340 lParag = createParagraph( this, lParag, 0 );
1332 if ( !fParag ) 1341 if ( !fParag )
1333 fParag = lParag; 1342 fParag = lParag;
1334 QString s = text.mid( lastNl, nl - lastNl ); 1343 QString s = text.mid( lastNl, nl - lastNl );
1335 if ( !s.isEmpty() ) { 1344 if ( !s.isEmpty() ) {
1336 if ( s[ (int)s.length() - 1 ] == '\r' ) 1345 if ( s[ (int)s.length() - 1 ] == '\r' )
1337 s.remove( s.length() - 1, 1 ); 1346 s.remove( s.length() - 1, 1 );
1338 lParag->append( s ); 1347 lParag->append( s );
1339 } 1348 }
1340 if ( nl == 0xffffff ) 1349 if ( nl == 0xffffff )
1341 break; 1350 break;
1342 lastNl = nl + 1; 1351 lastNl = nl + 1;
1343 nl = text.find( '\n', nl + 1 ); 1352 nl = text.find( '\n', nl + 1 );
1344 if ( nl == -1 ) 1353 if ( nl == -1 )
1345 nl = 0xffffff; 1354 nl = 0xffffff;
1346 } 1355 }
1347 } 1356 }
1348 if ( !lParag ) 1357 if ( !lParag )
1349 lParag = fParag = createParagraph( this, 0, 0 ); 1358 lParag = fParag = createParagraph( this, 0, 0 );
1350} 1359}
1351 1360
1352struct Q_EXPORT QTextDocumentTag { 1361struct Q_EXPORT QTextDocumentTag {
1353 QTextDocumentTag(){} 1362 QTextDocumentTag(){}
1354 QTextDocumentTag( const QString&n, const QStyleSheetItem* s, const QTextFormat& f ) 1363 QTextDocumentTag( const QString&n, const QStyleSheetItem* s, const QTextFormat& f )
1355 :name(n),style(s), format(f), alignment(Qt3::AlignAuto), direction(QChar::DirON),liststyle(QStyleSheetItem::ListDisc) { 1364 :name(n),style(s), format(f), alignment(Qt3::AlignAuto), direction(QChar::DirON),liststyle(QStyleSheetItem::ListDisc) {
1356 wsm = QStyleSheetItem::WhiteSpaceNormal; 1365 wsm = QStyleSheetItem::WhiteSpaceNormal;
1357 } 1366 }
1358 QString name; 1367 QString name;
1359 const QStyleSheetItem* style; 1368 const QStyleSheetItem* style;
1360 QString anchorHref; 1369 QString anchorHref;
1361 QStyleSheetItem::WhiteSpaceMode wsm; 1370 QStyleSheetItem::WhiteSpaceMode wsm;
1362 QTextFormat format; 1371 QTextFormat format;
1363 int alignment : 16; 1372 int alignment : 16;
1364 int direction : 5; 1373 int direction : 5;
1365 QStyleSheetItem::ListStyle liststyle; 1374 QStyleSheetItem::ListStyle liststyle;
1366 1375
1367 QTextDocumentTag( const QTextDocumentTag& t ) { 1376 QTextDocumentTag( const QTextDocumentTag& t ) {
1368 name = t.name; 1377 name = t.name;
1369 style = t.style; 1378 style = t.style;
1370 anchorHref = t.anchorHref; 1379 anchorHref = t.anchorHref;
1371 wsm = t.wsm; 1380 wsm = t.wsm;
1372 format = t.format; 1381 format = t.format;
1373 alignment = t.alignment; 1382 alignment = t.alignment;
1374 direction = t.direction; 1383 direction = t.direction;
1375 liststyle = t.liststyle; 1384 liststyle = t.liststyle;
1376 } 1385 }
1377 QTextDocumentTag& operator=(const QTextDocumentTag& t) { 1386 QTextDocumentTag& operator=(const QTextDocumentTag& t) {
1378 name = t.name; 1387 name = t.name;
1379 style = t.style; 1388 style = t.style;
1380 anchorHref = t.anchorHref; 1389 anchorHref = t.anchorHref;
1381 wsm = t.wsm; 1390 wsm = t.wsm;
1382 format = t.format; 1391 format = t.format;
1383 alignment = t.alignment; 1392 alignment = t.alignment;
1384 direction = t.direction; 1393 direction = t.direction;
1385 liststyle = t.liststyle; 1394 liststyle = t.liststyle;
1386 return *this; 1395 return *this;
1387 } 1396 }
1388 1397
1389#if defined(Q_FULL_TEMPLATE_INSTANTIATION) 1398#if defined(Q_FULL_TEMPLATE_INSTANTIATION)
1390 bool operator==( const QTextDocumentTag& ) const { return FALSE; } 1399 bool operator==( const QTextDocumentTag& ) const { return FALSE; }
1391#endif 1400#endif
1392}; 1401};
1393 1402
1394 1403
1395#define NEWPAR do{ if ( !hasNewPar) { \ 1404#define NEWPAR do { \
1396 if ( !textEditMode && curpar && curpar->length()>1 && curpar->at( curpar->length()-2)->c == QChar_linesep ) \ 1405 if ( !hasNewPar) { \
1397 curpar->remove( curpar->length()-2, 1 ); \ 1406 if ( !curpar ) { \
1398 curpar = createParagraph( this, curpar, curpar->next() ); styles.append( vec ); vec = 0;} \ 1407 owarn << "no current paragraph" << oendl; \
1399 hasNewPar = TRUE; \ 1408 return; \
1400 curpar->rtext = TRUE; \ 1409 } \
1401 curpar->align = curtag.alignment; \ 1410 if ( !textEditMode && curpar && curpar->length()>1 && curpar->at( curpar->length()-2)->c == QChar_linesep ) \
1402 curpar->lstyle = curtag.liststyle; \ 1411 curpar->remove( curpar->length()-2, 1 ); \
1403 curpar->litem = ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ); \ 1412 curpar = createParagraph( this, curpar, curpar->next() ); styles.append( vec ); \
1404 curpar->str->setDirection( (QChar::Direction)curtag.direction ); \ 1413 if ( !curpar ) { \
1405 space = TRUE; \ 1414 owarn << "failed in creating a new paragraph" << oendl; \
1406 delete vec; vec = new QPtrVector<QStyleSheetItem>( (uint)tags.count() + 1); \ 1415 return; \
1407 int i = 0; \ 1416 } \
1408 for ( QValueStack<QTextDocumentTag>::Iterator it = tags.begin(); it != tags.end(); ++it ) \ 1417 vec = 0; \
1409 vec->insert( i++, (*it).style ); \ 1418 } \
1410 vec->insert( i, curtag.style ); \ 1419 hasNewPar = TRUE; \
1411 }while(FALSE) 1420 curpar->rtext = TRUE; \
1412 1421 curpar->align = curtag.alignment; \
1422 curpar->lstyle = curtag.liststyle; \
1423 curpar->litem = ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ); \
1424 curpar->str->setDirection( (QChar::Direction)curtag.direction ); \
1425 space = TRUE; \
1426 delete vec; \
1427 vec = new QPtrVector<QStyleSheetItem>( (uint)tags.count() + 1); \
1428 int i = 0; \
1429 for ( QValueStack<QTextDocumentTag>::Iterator it = tags.begin(); it != tags.end(); ++it ) \
1430 vec->insert( i++, (*it).style ); \
1431 vec->insert( i, curtag.style ); \
1432 } while ( FALSE )
1413 1433
1414void QTextDocument::setRichText( const QString &text, const QString &context ) 1434void QTextDocument::setRichText( const QString &text, const QString &context )
1415{ 1435{
1416 if ( !context.isEmpty() ) 1436 if ( !context.isEmpty() )
1417 setContext( context ); 1437 setContext( context );
1418 clear(); 1438 clear();
1419 fParag = lParag = createParagraph( this ); 1439 fParag = lParag = createParagraph( this );
1420 oTextValid = TRUE; 1440 oTextValid = TRUE;
1421 oText = text; 1441 oText = text;
1422 setRichTextInternal( text ); 1442 setRichTextInternal( text );
1423 fParag->rtext = TRUE; 1443 fParag->rtext = TRUE;
1424} 1444}
1425 1445
1426void QTextDocument::setRichTextInternal( const QString &text, QTextCursor* cursor ) 1446void QTextDocument::setRichTextInternal( const QString &text, QTextCursor* cursor )
1427{ 1447{
1428 QTextParagraph* curpar = lParag; 1448 QTextParagraph* curpar = lParag;
1429 int pos = 0; 1449 int pos = 0;
1430 QValueStack<QTextDocumentTag> tags; 1450 QValueStack<QTextDocumentTag> tags;
1431 QTextDocumentTag initag( "", sheet_->item(""), *formatCollection()->defaultFormat() ); 1451 QTextDocumentTag initag( "", sheet_->item(""), *formatCollection()->defaultFormat() );
1432 QTextDocumentTag curtag = initag; 1452 QTextDocumentTag curtag = initag;
1433 bool space = TRUE; 1453 bool space = TRUE;
1434 bool canMergeLi = FALSE; 1454 bool canMergeLi = FALSE;
1435 1455
1436 bool textEditMode = FALSE; 1456 bool textEditMode = FALSE;
1437 1457
1438 const QChar* doc = text.unicode(); 1458 const QChar* doc = text.unicode();
1439 int length = text.length(); 1459 int length = text.length();
1440 bool hasNewPar = curpar->length() <= 1; 1460 bool hasNewPar = curpar->length() <= 1;
1441 QString anchorName; 1461 QString anchorName;
1442 1462
1443 // style sheet handling for margin and line spacing calculation below 1463 // style sheet handling for margin and line spacing calculation below
1444 QTextParagraph* stylesPar = curpar; 1464 QTextParagraph* stylesPar = curpar;
1445 QPtrVector<QStyleSheetItem>* vec = 0; 1465 QPtrVector<QStyleSheetItem>* vec = 0;
1446 QPtrList< QPtrVector<QStyleSheetItem> > styles; 1466 QPtrList< QPtrVector<QStyleSheetItem> > styles;
1447 styles.setAutoDelete( TRUE ); 1467 styles.setAutoDelete( TRUE );
1448 1468
1449 if ( cursor ) { 1469 if ( cursor ) {
1450 cursor->splitAndInsertEmptyParagraph(); 1470 cursor->splitAndInsertEmptyParagraph();
1451 QTextCursor tmp = *cursor; 1471 QTextCursor tmp = *cursor;
1452 tmp.gotoPreviousLetter(); 1472 tmp.gotoPreviousLetter();
1453 stylesPar = curpar = tmp.paragraph(); 1473 stylesPar = curpar = tmp.paragraph();
1454 hasNewPar = TRUE; 1474 hasNewPar = TRUE;
1455 textEditMode = TRUE; 1475 textEditMode = TRUE;
1456 } else { 1476 } else {
1457 NEWPAR; 1477 NEWPAR;
1458 } 1478 }
1459 1479
1460 // set rtext spacing to FALSE for the initial paragraph. 1480 // set rtext spacing to FALSE for the initial paragraph.
1461 curpar->rtext = FALSE; 1481 curpar->rtext = FALSE;
1462 1482
1463 QString wellKnownTags = "br hr wsp table qt body meta title"; 1483 QString wellKnownTags = "br hr wsp table qt body meta title";
1464 1484
1465 while ( pos < length ) { 1485 while ( pos < length ) {
1466 if ( hasPrefix(doc, length, pos, '<' ) ){ 1486 if ( hasPrefix(doc, length, pos, '<' ) ){
1467 if ( !hasPrefix( doc, length, pos+1, QChar('/') ) ) { 1487 if ( !hasPrefix( doc, length, pos+1, QChar('/') ) ) {
1468 // open tag 1488 // open tag
1469 QMap<QString, QString> attr; 1489 QMap<QString, QString> attr;
1470 bool emptyTag = FALSE; 1490 bool emptyTag = FALSE;
1471 QString tagname = parseOpenTag(doc, length, pos, attr, emptyTag); 1491 QString tagname = parseOpenTag(doc, length, pos, attr, emptyTag);
1472 if ( tagname.isEmpty() ) 1492 if ( tagname.isEmpty() )
1473 continue; // nothing we could do with this, probably parse error 1493 continue; // nothing we could do with this, probably parse error
1474 1494
1475 const QStyleSheetItem* nstyle = sheet_->item(tagname); 1495 const QStyleSheetItem* nstyle = sheet_->item(tagname);
1476 1496
1477 if ( nstyle ) { 1497 if ( nstyle ) {
1478 // we might have to close some 'forgotten' tags 1498 // we might have to close some 'forgotten' tags
1479 while ( !nstyle->allowedInContext( curtag.style ) ) { 1499 while ( !nstyle->allowedInContext( curtag.style ) ) {
1480 QString msg; 1500 QString msg;
1481 msg.sprintf( "QText Warning: Document not valid ( '%s' not allowed in '%s' #%d)", 1501 msg.sprintf( "QText Warning: Document not valid ( '%s' not allowed in '%s' #%d)",
1482 tagname.ascii(), curtag.style->name().ascii(), pos); 1502 tagname.ascii(), curtag.style->name().ascii(), pos);
1483 sheet_->error( msg ); 1503 sheet_->error( msg );
1484 if ( tags.isEmpty() ) 1504 if ( tags.isEmpty() )
1485 break; 1505 break;
1486 curtag = tags.pop(); 1506 curtag = tags.pop();
1487 } 1507 }
1488 1508
1489 /* special handling for p and li for HTML 1509 /* special handling for p and li for HTML
1490 compatibility. We do not want to embed blocks in 1510 compatibility. We do not want to embed blocks in
1491 p, and we do not want new blocks inside non-empty 1511 p, and we do not want new blocks inside non-empty
1492 lis. Plus we want to merge empty lis sometimes. */ 1512 lis. Plus we want to merge empty lis sometimes. */
1493 if( nstyle->displayMode() == QStyleSheetItem::DisplayListItem ) { 1513 if( nstyle->displayMode() == QStyleSheetItem::DisplayListItem ) {
1494 canMergeLi = TRUE; 1514 canMergeLi = TRUE;
1495 } else if ( nstyle->displayMode() == QStyleSheetItem::DisplayBlock ) { 1515 } else if ( nstyle->displayMode() == QStyleSheetItem::DisplayBlock ) {
1496 while ( curtag.style->name() == "p" ) { 1516 while ( curtag.style->name() == "p" ) {
1497 if ( tags.isEmpty() ) 1517 if ( tags.isEmpty() )
1498 break; 1518 break;
1499 curtag = tags.pop(); 1519 curtag = tags.pop();
1500 } 1520 }
1501 1521
1502 if ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ) { 1522 if ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ) {
1503 // we are in a li and a new block comes along 1523 // we are in a li and a new block comes along
1504 if ( nstyle->name() == "ul" || nstyle->name() == "ol" ) 1524 if ( nstyle->name() == "ul" || nstyle->name() == "ol" )
1505 hasNewPar = FALSE; // we want an empty li (like most browsers) 1525 hasNewPar = FALSE; // we want an empty li (like most browsers)
1506 if ( !hasNewPar ) { 1526 if ( !hasNewPar ) {
1507 /* do not add new blocks inside 1527 /* do not add new blocks inside
1508 non-empty lis */ 1528 non-empty lis */
1509 while ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ) { 1529 while ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ) {
1510 if ( tags.isEmpty() ) 1530 if ( tags.isEmpty() )
1511 break; 1531 break;
1512 curtag = tags.pop(); 1532 curtag = tags.pop();
1513 } 1533 }
1514 } else if ( canMergeLi ) { 1534 } else if ( canMergeLi ) {
1515 /* we have an empty li and a block 1535 /* we have an empty li and a block
1516 comes along, merge them */ 1536 comes along, merge them */
1517 nstyle = curtag.style; 1537 nstyle = curtag.style;
1518 } 1538 }
1519 canMergeLi = FALSE; 1539 canMergeLi = FALSE;
1520 } 1540 }
1521 } 1541 }
1522 } 1542 }
1523 1543
1524 QTextCustomItem* custom = 0; 1544 QTextCustomItem* custom = 0;
1525 1545
1526 // some well-known tags, some have a nstyle, some not 1546 // some well-known tags, some have a nstyle, some not
1527 if ( wellKnownTags.find( tagname ) != -1 ) { 1547 if ( wellKnownTags.find( tagname ) != -1 ) {
1528 if ( tagname == "br" ) { 1548 if ( tagname == "br" ) {
1529 emptyTag = space = TRUE; 1549 emptyTag = space = TRUE;
1530 int index = QMAX( curpar->length(),1) - 1; 1550 int index = QMAX( curpar->length(),1) - 1;
1531 QTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor ); 1551 QTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor );
1532 curpar->append( QChar_linesep ); 1552 curpar->append( QChar_linesep );
1533 curpar->setFormat( index, 1, &format ); 1553 curpar->setFormat( index, 1, &format );
1534 } else if ( tagname == "hr" ) { 1554 } else if ( tagname == "hr" ) {
1535 emptyTag = space = TRUE; 1555 emptyTag = space = TRUE;
1536 custom = sheet_->tag( tagname, attr, contxt, *factory_ , emptyTag, this ); 1556 custom = sheet_->tag( tagname, attr, contxt, *factory_ , emptyTag, this );
1537 NEWPAR; 1557 NEWPAR;
1538 } else if ( tagname == "table" ) { 1558 } else if ( tagname == "table" ) {
1539 emptyTag = space = TRUE; 1559 emptyTag = space = TRUE;
1540 QTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor ); 1560 QTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor );
1541 curpar->setAlignment( curtag.alignment ); 1561 curpar->setAlignment( curtag.alignment );
1542 custom = parseTable( attr, format, doc, length, pos, curpar ); 1562 custom = parseTable( attr, format, doc, length, pos, curpar );
1543 } else if ( tagname == "qt" || tagname == "body" ) { 1563 } else if ( tagname == "qt" || tagname == "body" ) {
1544 if ( attr.contains( "bgcolor" ) ) { 1564 if ( attr.contains( "bgcolor" ) ) {
1545 QBrush *b = new QBrush( QColor( attr["bgcolor"] ) ); 1565 QBrush *b = new QBrush( QColor( attr["bgcolor"] ) );
1546 setPaper( b ); 1566 setPaper( b );
1547 } 1567 }
1548 if ( attr.contains( "background" ) ) { 1568 if ( attr.contains( "background" ) ) {
1549 QImage img; 1569 QImage img;
1550 QString bg = attr["background"]; 1570 QString bg = attr["background"];
1551 const QMimeSource* m = factory_->data( bg, contxt ); 1571 const QMimeSource* m = factory_->data( bg, contxt );
1552 if ( !m ) { 1572 if ( !m ) {
1553 owarn << "QRichText: no mimesource for " << bg.latin1() << "" << oendl; 1573 owarn << "QRichText: no mimesource for " << bg.latin1() << "" << oendl;
1554 } else { 1574 } else {
1555 if ( !QImageDrag::decode( m, img ) ) { 1575 if ( !QImageDrag::decode( m, img ) ) {
1556 owarn << "QTextImage: cannot decode " << bg.latin1() << "" << oendl; 1576 owarn << "QTextImage: cannot decode " << bg.latin1() << "" << oendl;
1557 } 1577 }
1558 } 1578 }
1559 if ( !img.isNull() ) { 1579 if ( !img.isNull() ) {
1560 QPixmap pm; 1580 QPixmap pm;
1561 pm.convertFromImage( img ); 1581 pm.convertFromImage( img );
1562 QBrush *b = new QBrush( QColor(), pm ); 1582 QBrush *b = new QBrush( QColor(), pm );
1563 setPaper( b ); 1583 setPaper( b );
1564 } 1584 }
1565 } 1585 }
1566 if ( attr.contains( "text" ) ) { 1586 if ( attr.contains( "text" ) ) {
1567 QColor c( attr["text"] ); 1587 QColor c( attr["text"] );
1568 if ( formatCollection()->defaultFormat()->color() != c ) { 1588 if ( formatCollection()->defaultFormat()->color() != c ) {
1569 QDict<QTextFormat> formats = formatCollection()->dict(); 1589 QDict<QTextFormat> formats = formatCollection()->dict();
1570 QDictIterator<QTextFormat> it( formats ); 1590 QDictIterator<QTextFormat> it( formats );
1571 while ( it.current() ) { 1591 while ( it.current() ) {
1572 if ( it.current() == formatCollection()->defaultFormat() ) { 1592 if ( it.current() == formatCollection()->defaultFormat() ) {
1573 ++it; 1593 ++it;
1574 continue; 1594 continue;
1575 } 1595 }
1576 it.current()->setColor( c ); 1596 it.current()->setColor( c );
1577 ++it; 1597 ++it;
1578 } 1598 }
1579 formatCollection()->defaultFormat()->setColor( c ); 1599 formatCollection()->defaultFormat()->setColor( c );
1580 curtag.format.setColor( c ); 1600 curtag.format.setColor( c );
1581 } 1601 }
1582 } 1602 }
1583 if ( attr.contains( "link" ) ) 1603 if ( attr.contains( "link" ) )
1584 linkColor = QColor( attr["link"] ); 1604 linkColor = QColor( attr["link"] );
1585 if ( attr.contains( "title" ) ) 1605 if ( attr.contains( "title" ) )
1586 attribs.replace( "title", attr["title"] ); 1606 attribs.replace( "title", attr["title"] );
1587 1607
1588 if ( textEditMode ) { 1608 if ( textEditMode ) {
1589 if ( attr.contains("style" ) ) { 1609 if ( attr.contains("style" ) ) {
1590 QString a = attr["style"]; 1610 QString a = attr["style"];
1591 for ( int s = 0; s < a.contains(';')+1; s++ ) { 1611 for ( int s = 0; s < a.contains(';')+1; s++ ) {
1592 QString style = QTextDocument::section( a, ";", s, s ); 1612 QString style = QTextDocument::section( a, ";", s, s );
1593 if ( style.startsWith("font-size:" ) && QTextDocument::endsWith(style, "pt") ) { 1613 if ( style.startsWith("font-size:" ) && QTextDocument::endsWith(style, "pt") ) {
1594 scaleFontsFactor = double( formatCollection()->defaultFormat()->fn.pointSize() ) / 1614 scaleFontsFactor = double( formatCollection()->defaultFormat()->fn.pointSize() ) /
1595 style.mid( 10, style.length() - 12 ).toInt(); 1615 style.mid( 10, style.length() - 12 ).toInt();
1596 } 1616 }
1597 } 1617 }
1598 } 1618 }
1599 nstyle = 0; // ignore body in textEditMode 1619 nstyle = 0; // ignore body in textEditMode
1600 } 1620 }
1601 // end qt- and body-tag handling 1621 // end qt- and body-tag handling
1602 } else if ( tagname == "meta" ) { 1622 } else if ( tagname == "meta" ) {
1603 if ( attr["name"] == "qrichtext" && attr["content"] == "1" ) 1623 if ( attr["name"] == "qrichtext" && attr["content"] == "1" )
1604 textEditMode = TRUE; 1624 textEditMode = TRUE;
@@ -1706,386 +1726,389 @@ void QTextDocument::setRichTextInternal( const QString &text, QTextCursor* curso
1706 xMargin() functions we restrict ourselves to 1726 xMargin() functions we restrict ourselves to
1707 <ol>. Once we calculate the margins in the 1727 <ol>. Once we calculate the margins in the
1708 parser rathern than later, the unelegance of 1728 parser rathern than later, the unelegance of
1709 this approach goes awy 1729 this approach goes awy
1710 */ 1730 */
1711 if ( nstyle->name() == "ul" ) 1731 if ( nstyle->name() == "ul" )
1712 curtag.style = sheet_->item( "ol" ); 1732 curtag.style = sheet_->item( "ol" );
1713 1733
1714 if ( attr.contains( "align" ) ) { 1734 if ( attr.contains( "align" ) ) {
1715 QString align = attr["align"]; 1735 QString align = attr["align"];
1716 if ( align == "center" ) 1736 if ( align == "center" )
1717 curtag.alignment = Qt::AlignCenter; 1737 curtag.alignment = Qt::AlignCenter;
1718 else if ( align == "right" ) 1738 else if ( align == "right" )
1719 curtag.alignment = Qt::AlignRight; 1739 curtag.alignment = Qt::AlignRight;
1720 else if ( align == "justify" ) 1740 else if ( align == "justify" )
1721 curtag.alignment = Qt3::AlignJustify; 1741 curtag.alignment = Qt3::AlignJustify;
1722 } 1742 }
1723 if ( attr.contains( "dir" ) ) { 1743 if ( attr.contains( "dir" ) ) {
1724 QString dir = attr["dir"]; 1744 QString dir = attr["dir"];
1725 if ( dir == "rtl" ) 1745 if ( dir == "rtl" )
1726 curtag.direction = QChar::DirR; 1746 curtag.direction = QChar::DirR;
1727 else if ( dir == "ltr" ) 1747 else if ( dir == "ltr" )
1728 curtag.direction = QChar::DirL; 1748 curtag.direction = QChar::DirL;
1729 } 1749 }
1730 1750
1731 NEWPAR; 1751 NEWPAR;
1732 1752
1733 if ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ) { 1753 if ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ) {
1734 if ( attr.contains( "value " ) ) 1754 if ( attr.contains( "value " ) )
1735 curpar->setListValue( attr["value"].toInt() ); 1755 curpar->setListValue( attr["value"].toInt() );
1736 } 1756 }
1737 1757
1738 if ( attr.contains( "style" ) ) { 1758 if ( attr.contains( "style" ) ) {
1739 QString a = attr["style"]; 1759 QString a = attr["style"];
1740 bool ok = TRUE; 1760 bool ok = TRUE;
1741 for ( int s = 0; ok && s < a.contains(';')+1; s++ ) { 1761 for ( int s = 0; ok && s < a.contains(';')+1; s++ ) {
1742 QString style = QTextDocument::section( a, ";", s, s ); 1762 QString style = QTextDocument::section( a, ";", s, s );
1743 if ( style.startsWith("margin-top:" ) && QTextDocument::endsWith(style, "px") ) 1763 if ( style.startsWith("margin-top:" ) && QTextDocument::endsWith(style, "px") )
1744 curpar->utm = 1+style.mid(11, style.length() - 13).toInt(&ok); 1764 curpar->utm = 1+style.mid(11, style.length() - 13).toInt(&ok);
1745 else if ( style.startsWith("margin-bottom:" ) && QTextDocument::endsWith(style, "px") ) 1765 else if ( style.startsWith("margin-bottom:" ) && QTextDocument::endsWith(style, "px") )
1746 curpar->ubm = 1+style.mid(14, style.length() - 16).toInt(&ok); 1766 curpar->ubm = 1+style.mid(14, style.length() - 16).toInt(&ok);
1747 else if ( style.startsWith("margin-left:" ) && QTextDocument::endsWith(style, "px") ) 1767 else if ( style.startsWith("margin-left:" ) && QTextDocument::endsWith(style, "px") )
1748 curpar->ulm = 1+style.mid(12, style.length() - 14).toInt(&ok); 1768 curpar->ulm = 1+style.mid(12, style.length() - 14).toInt(&ok);
1749 else if ( style.startsWith("margin-right:" ) && QTextDocument::endsWith(style, "px") ) 1769 else if ( style.startsWith("margin-right:" ) && QTextDocument::endsWith(style, "px") )
1750 curpar->urm = 1+style.mid(13, style.length() - 15).toInt(&ok); 1770 curpar->urm = 1+style.mid(13, style.length() - 15).toInt(&ok);
1751 else if ( style.startsWith("text-indent:" ) && QTextDocument::endsWith(style, "px") ) 1771 else if ( style.startsWith("text-indent:" ) && QTextDocument::endsWith(style, "px") )
1752 curpar->uflm = 1+style.mid(12, style.length() - 14).toInt(&ok); 1772 curpar->uflm = 1+style.mid(12, style.length() - 14).toInt(&ok);
1753 } 1773 }
1754 if ( !ok ) // be pressmistic 1774 if ( !ok ) // be pressmistic
1755 curpar->utm = curpar->ubm = curpar->urm = curpar->ulm = 0; 1775 curpar->utm = curpar->ubm = curpar->urm = curpar->ulm = 0;
1756 } 1776 }
1757 } 1777 }
1758 } 1778 }
1759 } else { 1779 } else {
1760 QString tagname = parseCloseTag( doc, length, pos ); 1780 QString tagname = parseCloseTag( doc, length, pos );
1761 if ( tagname.isEmpty() ) 1781 if ( tagname.isEmpty() )
1762 continue; // nothing we could do with this, probably parse error 1782 continue; // nothing we could do with this, probably parse error
1763 if ( !sheet_->item( tagname ) ) // ignore unknown tags 1783 if ( !sheet_->item( tagname ) ) // ignore unknown tags
1764 continue; 1784 continue;
1765 1785
1766 // we close a block item. Since the text may continue, we need to have a new paragraph 1786 // we close a block item. Since the text may continue, we need to have a new paragraph
1767 bool needNewPar = curtag.style->displayMode() == QStyleSheetItem::DisplayBlock 1787 bool needNewPar = curtag.style->displayMode() == QStyleSheetItem::DisplayBlock
1768 || curtag.style->displayMode() == QStyleSheetItem::DisplayListItem; 1788 || curtag.style->displayMode() == QStyleSheetItem::DisplayListItem;
1769 1789
1770 1790
1771 // html slopiness: handle unbalanched tag closing 1791 // html slopiness: handle unbalanched tag closing
1772 while ( curtag.name != tagname ) { 1792 while ( curtag.name != tagname ) {
1773 QString msg; 1793 QString msg;
1774 msg.sprintf( "QText Warning: Document not valid ( '%s' not closed before '%s' #%d)", 1794 msg.sprintf( "QText Warning: Document not valid ( '%s' not closed before '%s' #%d)",
1775 curtag.name.ascii(), tagname.ascii(), pos); 1795 curtag.name.ascii(), tagname.ascii(), pos);
1776 sheet_->error( msg ); 1796 sheet_->error( msg );
1777 if ( tags.isEmpty() ) 1797 if ( tags.isEmpty() )
1778 break; 1798 break;
1779 curtag = tags.pop(); 1799 curtag = tags.pop();
1780 } 1800 }
1781 1801
1782 1802
1783 // close the tag 1803 // close the tag
1784 if ( !tags.isEmpty() ) 1804 if ( !tags.isEmpty() )
1785 curtag = tags.pop(); 1805 curtag = tags.pop();
1786 else 1806 else
1787 curtag = initag; 1807 curtag = initag;
1788 1808
1789 if ( needNewPar ) { 1809 if ( needNewPar ) {
1790 if ( textEditMode && tagname == "p" ) // preserve empty paragraphs 1810 if ( textEditMode && tagname == "p" ) // preserve empty paragraphs
1791 hasNewPar = FALSE; 1811 hasNewPar = FALSE;
1792 NEWPAR; 1812 NEWPAR;
1793 } 1813 }
1794 } 1814 }
1795 } else { 1815 } else {
1796 // normal contents 1816 // normal contents
1797 QString s; 1817 QString s;
1798 QChar c; 1818 QChar c;
1799 while ( pos < length && !hasPrefix(doc, length, pos, QChar('<') ) ){ 1819 while ( pos < length && !hasPrefix(doc, length, pos, QChar('<') ) ){
1800 if ( textEditMode ) { 1820 if ( textEditMode ) {
1801 // text edit mode: we handle all white space but ignore newlines 1821 // text edit mode: we handle all white space but ignore newlines
1802 c = parseChar( doc, length, pos, QStyleSheetItem::WhiteSpacePre ); 1822 c = parseChar( doc, length, pos, QStyleSheetItem::WhiteSpacePre );
1803 if ( c == QChar_linesep ) 1823 if ( c == QChar_linesep )
1804 break; 1824 break;
1805 } else { 1825 } else {
1806 int l = pos; 1826 int l = pos;
1807 c = parseChar( doc, length, pos, curtag.wsm ); 1827 c = parseChar( doc, length, pos, curtag.wsm );
1808 1828
1809 // in white space pre mode: treat any space as non breakable 1829 // in white space pre mode: treat any space as non breakable
1810 if ( c == ' ' && curtag.wsm == QStyleSheetItem::WhiteSpacePre ) 1830 if ( c == ' ' && curtag.wsm == QStyleSheetItem::WhiteSpacePre )
1811 c = QChar::nbsp; 1831 c = QChar::nbsp;
1812 1832
1813 if ( c == ' ' || c == QChar_linesep ) { 1833 if ( c == ' ' || c == QChar_linesep ) {
1814 /* avoid overlong paragraphs by forcing a new 1834 /* avoid overlong paragraphs by forcing a new
1815 paragraph after 4096 characters. This case can 1835 paragraph after 4096 characters. This case can
1816 occur when loading undiscovered plain text 1836 occur when loading undiscovered plain text
1817 documents in rich text mode. Instead of hanging 1837 documents in rich text mode. Instead of hanging
1818 forever, we do the trick. 1838 forever, we do the trick.
1819 */ 1839 */
1820 if ( curtag.wsm == QStyleSheetItem::WhiteSpaceNormal && s.length() > 4096 ) do { 1840 if ( curtag.wsm == QStyleSheetItem::WhiteSpaceNormal && s.length() > 4096 ) do {
1821 if ( doc[l] == '\n' ) { 1841 if ( doc[l] == '\n' ) {
1822 hasNewPar = FALSE; // for a new paragraph ... 1842 hasNewPar = FALSE; // for a new paragraph ...
1823 NEWPAR; 1843 NEWPAR;
1824 hasNewPar = FALSE; // ... and make it non-reusable 1844 hasNewPar = FALSE; // ... and make it non-reusable
1825 c = '\n'; // make sure we break below 1845 c = '\n'; // make sure we break below
1826 break; 1846 break;
1827 } 1847 }
1828 } while ( ++l < pos ); 1848 } while ( ++l < pos );
1829 } 1849 }
1830 } 1850 }
1831 1851
1832 if ( c == '\n' ) 1852 if ( c == '\n' )
1833 break; // break on newlines, pre delievers a QChar_linesep 1853 break; // break on newlines, pre delievers a QChar_linesep
1834 1854
1835 bool c_isSpace = c.isSpace() && c.unicode() != 0x00a0U && !textEditMode; 1855 bool c_isSpace = c.isSpace() && c.unicode() != 0x00a0U && !textEditMode;
1836 1856
1837 if ( curtag.wsm == QStyleSheetItem::WhiteSpaceNormal && c_isSpace && space ) 1857 if ( curtag.wsm == QStyleSheetItem::WhiteSpaceNormal && c_isSpace && space )
1838 continue; 1858 continue;
1839 if ( c == '\r' ) 1859 if ( c == '\r' )
1840 continue; 1860 continue;
1841 space = c_isSpace; 1861 space = c_isSpace;
1842 s += c; 1862 s += c;
1843 } 1863 }
1844 if ( !s.isEmpty() && curtag.style->displayMode() != QStyleSheetItem::DisplayNone ) { 1864 if ( !s.isEmpty() && curtag.style->displayMode() != QStyleSheetItem::DisplayNone ) {
1845 hasNewPar = FALSE; 1865 hasNewPar = FALSE;
1846 int index = QMAX( curpar->length(),1) - 1; 1866 int index = QMAX( curpar->length(),1) - 1;
1847 curpar->append( s ); 1867 curpar->append( s );
1848 QTextFormat* f = formatCollection()->format( &curtag.format ); 1868 QTextFormat* f = formatCollection()->format( &curtag.format );
1849 curpar->setFormat( index, s.length(), f, FALSE ); // do not use collection because we have done that already 1869 curpar->setFormat( index, s.length(), f, FALSE ); // do not use collection because we have done that already
1850 f->ref += s.length() -1; // that what friends are for... 1870 f->ref += s.length() -1; // that what friends are for...
1851 if ( !curtag.anchorHref.isEmpty() ) { 1871 if ( !curtag.anchorHref.isEmpty() ) {
1852 for ( int i = 0; i < int(s.length()); i++ ) 1872 for ( int i = 0; i < int(s.length()); i++ )
1853 curpar->at(index + i)->setAnchor( QString::null, curtag.anchorHref ); 1873 curpar->at(index + i)->setAnchor( QString::null, curtag.anchorHref );
1854 } 1874 }
1855 if ( !anchorName.isEmpty() ) { 1875 if ( !anchorName.isEmpty() ) {
1856 curpar->at(index)->setAnchor( anchorName, curpar->at(index)->anchorHref() ); 1876 curpar->at(index)->setAnchor( anchorName, curpar->at(index)->anchorHref() );
1857 anchorName = QString::null; 1877 anchorName = QString::null;
1858 } 1878 }
1859 } 1879 }
1860 } 1880 }
1861 } 1881 }
1862 if ( hasNewPar && curpar != fParag && !cursor ) { 1882 if ( hasNewPar && curpar != fParag && !cursor ) {
1863 // cleanup unused last paragraphs 1883 // cleanup unused last paragraphs
1864 curpar = curpar->p; 1884 curpar = curpar->p;
1865 delete curpar->n; 1885 delete curpar->n;
1866 } 1886 }
1867 if ( !anchorName.isEmpty() ) { 1887 if ( !anchorName.isEmpty() ) {
1868 curpar->at(curpar->length() - 1)->setAnchor( anchorName, curpar->at( curpar->length() - 1 )->anchorHref() ); 1888 curpar->at(curpar->length() - 1)->setAnchor( anchorName, curpar->at( curpar->length() - 1 )->anchorHref() );
1869 anchorName = QString::null; 1889 anchorName = QString::null;
1870 } 1890 }
1871 1891
1872 1892
1873 setRichTextMarginsInternal( styles, stylesPar ); 1893 setRichTextMarginsInternal( styles, stylesPar );
1874 1894
1875 if ( cursor ) { 1895 if ( cursor ) {
1876 cursor->gotoPreviousLetter(); 1896 cursor->gotoPreviousLetter();
1877 cursor->remove(); 1897 cursor->remove();
1878 } 1898 }
1879 1899
1880} 1900}
1881 1901
1882void QTextDocument::setRichTextMarginsInternal( QPtrList< QPtrVector<QStyleSheetItem> >& styles, QTextParagraph* stylesPar ) 1902void QTextDocument::setRichTextMarginsInternal( QPtrList< QPtrVector<QStyleSheetItem> >& styles, QTextParagraph* stylesPar )
1883{ 1903{
1884 // margin and line spacing calculation 1904 // margin and line spacing calculation
1885 QPtrVector<QStyleSheetItem>* prevStyle = 0; 1905 QPtrVector<QStyleSheetItem>* prevStyle = 0;
1886 QPtrVector<QStyleSheetItem>* curStyle = styles.first(); 1906 QPtrVector<QStyleSheetItem>* curStyle = styles.first();
1887 QPtrVector<QStyleSheetItem>* nextStyle = styles.next(); 1907 QPtrVector<QStyleSheetItem>* nextStyle = styles.next();
1888 while ( stylesPar ) { 1908 while ( stylesPar ) {
1889 if ( !curStyle ) { 1909 if ( !curStyle ) {
1890 stylesPar = stylesPar->next(); 1910 stylesPar = stylesPar->next();
1891 prevStyle = curStyle; 1911 prevStyle = curStyle;
1892 curStyle = nextStyle; 1912 curStyle = nextStyle;
1893 nextStyle = styles.next(); 1913 nextStyle = styles.next();
1894 continue; 1914 continue;
1895 } 1915 }
1896 1916
1897 int i, mar; 1917 int i, mar;
1898 QStyleSheetItem* mainStyle = curStyle->size() ? (*curStyle)[curStyle->size()-1] : 0; 1918 QStyleSheetItem* mainStyle = (*curStyle)[curStyle->size()-1];
1899 if ( mainStyle && mainStyle->displayMode() == QStyleSheetItem::DisplayListItem ) 1919 if ( !mainStyle )
1920 return;
1921
1922 if ( mainStyle->displayMode() == QStyleSheetItem::DisplayListItem )
1900 stylesPar->setListItem( TRUE ); 1923 stylesPar->setListItem( TRUE );
1901 int numLists = 0; 1924 int numLists = 0;
1902 for ( i = 0; i < (int)curStyle->size(); ++i ) { 1925 for ( i = 0; i < (int)curStyle->size(); ++i ) {
1903 if ( (*curStyle)[ i ]->displayMode() == QStyleSheetItem::DisplayBlock 1926 if ( (*curStyle)[ i ]->displayMode() == QStyleSheetItem::DisplayBlock
1904 && int((*curStyle)[ i ]->listStyle()) != QStyleSheetItem::Undefined ) 1927 && int((*curStyle)[ i ]->listStyle()) != QStyleSheetItem::Undefined )
1905 numLists++; 1928 numLists++;
1906 } 1929 }
1907 stylesPar->ldepth = numLists; 1930 stylesPar->ldepth = numLists;
1908 if ( stylesPar->next() && nextStyle ) { 1931 if ( stylesPar->next() && nextStyle ) {
1909 // also set the depth of the next paragraph, required for the margin calculation 1932 // also set the depth of the next paragraph, required for the margin calculation
1910 numLists = 0; 1933 numLists = 0;
1911 for ( i = 0; i < (int)nextStyle->size(); ++i ) { 1934 for ( i = 0; i < (int)nextStyle->size(); ++i ) {
1912 if ( (*nextStyle)[ i ]->displayMode() == QStyleSheetItem::DisplayBlock 1935 if ( (*nextStyle)[ i ]->displayMode() == QStyleSheetItem::DisplayBlock
1913 && int((*nextStyle)[ i ]->listStyle()) != QStyleSheetItem::Undefined ) 1936 && int((*nextStyle)[ i ]->listStyle()) != QStyleSheetItem::Undefined )
1914 numLists++; 1937 numLists++;
1915 } 1938 }
1916 stylesPar->next()->ldepth = numLists; 1939 stylesPar->next()->ldepth = numLists;
1917 } 1940 }
1918 1941
1919 // do the top margin 1942 // do the top margin
1920 QStyleSheetItem* item = mainStyle; 1943 QStyleSheetItem* item = mainStyle;
1921 int m; 1944 int m;
1922 if (stylesPar->utm > 0 ) { 1945 if (stylesPar->utm > 0 ) {
1923 m = stylesPar->utm-1; 1946 m = stylesPar->utm-1;
1924 stylesPar->utm = 0; 1947 stylesPar->utm = 0;
1925 } else { 1948 } else {
1926 m = QMAX(0, item->margin( QStyleSheetItem::MarginTop ) ); 1949 m = QMAX(0, item->margin( QStyleSheetItem::MarginTop ) );
1927 if ( item->displayMode() == QStyleSheetItem::DisplayListItem 1950 if ( item->displayMode() == QStyleSheetItem::DisplayListItem
1928 && stylesPar->ldepth ) 1951 && stylesPar->ldepth )
1929 m /= stylesPar->ldepth; 1952 m /= stylesPar->ldepth;
1930 } 1953 }
1931 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) { 1954 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
1932 item = (*curStyle)[ i ]; 1955 item = (*curStyle)[ i ];
1933 if ( prevStyle && i < (int) prevStyle->size() && 1956 if ( prevStyle && i < (int) prevStyle->size() &&
1934 ( item->displayMode() == QStyleSheetItem::DisplayBlock && 1957 ( item->displayMode() == QStyleSheetItem::DisplayBlock &&
1935 (*prevStyle)[ i ] == item ) ) 1958 (*prevStyle)[ i ] == item ) )
1936 break; 1959 break;
1937 // emulate CSS2' standard 0 vertical margin for multiple ul or ol tags 1960 // emulate CSS2' standard 0 vertical margin for multiple ul or ol tags
1938 if ( int(item->listStyle()) != QStyleSheetItem::Undefined && 1961 if ( int(item->listStyle()) != QStyleSheetItem::Undefined &&
1939 ( ( i> 0 && (*curStyle)[ i-1 ] == item ) || (*curStyle)[i+1] == item ) ) 1962 ( ( i> 0 && (*curStyle)[ i-1 ] == item ) || (*curStyle)[i+1] == item ) )
1940 continue; 1963 continue;
1941 mar = QMAX( 0, item->margin( QStyleSheetItem::MarginTop ) ); 1964 mar = QMAX( 0, item->margin( QStyleSheetItem::MarginTop ) );
1942 m = QMAX( m, mar ); 1965 m = QMAX( m, mar );
1943 } 1966 }
1944 stylesPar->utm = m - stylesPar->topMargin(); 1967 stylesPar->utm = m - stylesPar->topMargin();
1945 1968
1946 // do the bottom margin 1969 // do the bottom margin
1947 item = mainStyle; 1970 item = mainStyle;
1948 if (stylesPar->ubm > 0 ) { 1971 if (stylesPar->ubm > 0 ) {
1949 m = stylesPar->ubm-1; 1972 m = stylesPar->ubm-1;
1950 stylesPar->ubm = 0; 1973 stylesPar->ubm = 0;
1951 } else { 1974 } else {
1952 m = QMAX(0, item->margin( QStyleSheetItem::MarginBottom ) ); 1975 m = QMAX(0, item->margin( QStyleSheetItem::MarginBottom ) );
1953 if ( item->displayMode() == QStyleSheetItem::DisplayListItem 1976 if ( item->displayMode() == QStyleSheetItem::DisplayListItem
1954 && stylesPar->ldepth ) 1977 && stylesPar->ldepth )
1955 m /= stylesPar->ldepth; 1978 m /= stylesPar->ldepth;
1956 } 1979 }
1957 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) { 1980 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
1958 item = (*curStyle)[ i ]; 1981 item = (*curStyle)[ i ];
1959 if ( nextStyle && i < (int) nextStyle->size() && 1982 if ( nextStyle && i < (int) nextStyle->size() &&
1960 ( item->displayMode() == QStyleSheetItem::DisplayBlock && 1983 ( item->displayMode() == QStyleSheetItem::DisplayBlock &&
1961 (*nextStyle)[ i ] == item ) ) 1984 (*nextStyle)[ i ] == item ) )
1962 break; 1985 break;
1963 // emulate CSS2' standard 0 vertical margin for multiple ul or ol tags 1986 // emulate CSS2' standard 0 vertical margin for multiple ul or ol tags
1964 if ( int(item->listStyle()) != QStyleSheetItem::Undefined && 1987 if ( int(item->listStyle()) != QStyleSheetItem::Undefined &&
1965 ( ( i> 0 && (*curStyle)[ i-1 ] == item ) || (*curStyle)[i+1] == item ) ) 1988 ( ( i> 0 && (*curStyle)[ i-1 ] == item ) || (*curStyle)[i+1] == item ) )
1966 continue; 1989 continue;
1967 mar = QMAX(0, item->margin( QStyleSheetItem::MarginBottom ) ); 1990 mar = QMAX(0, item->margin( QStyleSheetItem::MarginBottom ) );
1968 m = QMAX( m, mar ); 1991 m = QMAX( m, mar );
1969 } 1992 }
1970 stylesPar->ubm = m - stylesPar->bottomMargin(); 1993 stylesPar->ubm = m - stylesPar->bottomMargin();
1971 1994
1972 // do the left margin, simplyfied 1995 // do the left margin, simplyfied
1973 item = mainStyle; 1996 item = mainStyle;
1974 if (stylesPar->ulm > 0 ) { 1997 if (stylesPar->ulm > 0 ) {
1975 m = stylesPar->ulm-1; 1998 m = stylesPar->ulm-1;
1976 stylesPar->ulm = 0; 1999 stylesPar->ulm = 0;
1977 } else { 2000 } else {
1978 m = QMAX( 0, item->margin( QStyleSheetItem::MarginLeft ) ); 2001 m = QMAX( 0, item->margin( QStyleSheetItem::MarginLeft ) );
1979 } 2002 }
1980 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) { 2003 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
1981 item = (*curStyle)[ i ]; 2004 item = (*curStyle)[ i ];
1982 m += QMAX( 0, item->margin( QStyleSheetItem::MarginLeft ) ); 2005 m += QMAX( 0, item->margin( QStyleSheetItem::MarginLeft ) );
1983 } 2006 }
1984 stylesPar->ulm = m - stylesPar->leftMargin(); 2007 stylesPar->ulm = m - stylesPar->leftMargin();
1985 2008
1986 // do the right margin, simplyfied 2009 // do the right margin, simplyfied
1987 item = mainStyle; 2010 item = mainStyle;
1988 if (stylesPar->urm > 0 ) { 2011 if (stylesPar->urm > 0 ) {
1989 m = stylesPar->urm-1; 2012 m = stylesPar->urm-1;
1990 stylesPar->urm = 0; 2013 stylesPar->urm = 0;
1991 } else { 2014 } else {
1992 m = QMAX( 0, item->margin( QStyleSheetItem::MarginRight ) ); 2015 m = QMAX( 0, item->margin( QStyleSheetItem::MarginRight ) );
1993 } 2016 }
1994 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) { 2017 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
1995 item = (*curStyle)[ i ]; 2018 item = (*curStyle)[ i ];
1996 m += QMAX( 0, item->margin( QStyleSheetItem::MarginRight ) ); 2019 m += QMAX( 0, item->margin( QStyleSheetItem::MarginRight ) );
1997 } 2020 }
1998 stylesPar->urm = m - stylesPar->rightMargin(); 2021 stylesPar->urm = m - stylesPar->rightMargin();
1999 2022
2000 // do the first line margin, which really should be called text-indent 2023 // do the first line margin, which really should be called text-indent
2001 item = mainStyle; 2024 item = mainStyle;
2002 if (stylesPar->uflm > 0 ) { 2025 if (stylesPar->uflm > 0 ) {
2003 m = stylesPar->uflm-1; 2026 m = stylesPar->uflm-1;
2004 stylesPar->uflm = 0; 2027 stylesPar->uflm = 0;
2005 } else { 2028 } else {
2006 m = QMAX( 0, item->margin( QStyleSheetItem::MarginFirstLine ) ); 2029 m = QMAX( 0, item->margin( QStyleSheetItem::MarginFirstLine ) );
2007 } 2030 }
2008 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) { 2031 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
2009 item = (*curStyle)[ i ]; 2032 item = (*curStyle)[ i ];
2010 mar = QMAX( 0, item->margin( QStyleSheetItem::MarginFirstLine ) ); 2033 mar = QMAX( 0, item->margin( QStyleSheetItem::MarginFirstLine ) );
2011 m = QMAX( m, mar ); 2034 m = QMAX( m, mar );
2012 } 2035 }
2013 stylesPar->uflm =m - stylesPar->firstLineMargin(); 2036 stylesPar->uflm =m - stylesPar->firstLineMargin();
2014 2037
2015 // do the bogus line "spacing", which really is just an extra margin 2038 // do the bogus line "spacing", which really is just an extra margin
2016 item = mainStyle; 2039 item = mainStyle;
2017 for ( i = (int)curStyle->size() - 1 ; i >= 0; --i ) { 2040 for ( i = (int)curStyle->size() - 1 ; i >= 0; --i ) {
2018 item = (*curStyle)[ i ]; 2041 item = (*curStyle)[ i ];
2019 if ( item->lineSpacing() != QStyleSheetItem::Undefined ) { 2042 if ( item->lineSpacing() != QStyleSheetItem::Undefined ) {
2020 stylesPar->ulinespacing = item->lineSpacing(); 2043 stylesPar->ulinespacing = item->lineSpacing();
2021 if ( formatCollection() && 2044 if ( formatCollection() &&
2022 stylesPar->ulinespacing < formatCollection()->defaultFormat()->height() ) 2045 stylesPar->ulinespacing < formatCollection()->defaultFormat()->height() )
2023 stylesPar->ulinespacing += formatCollection()->defaultFormat()->height(); 2046 stylesPar->ulinespacing += formatCollection()->defaultFormat()->height();
2024 break; 2047 break;
2025 } 2048 }
2026 } 2049 }
2027 2050
2028 stylesPar = stylesPar->next(); 2051 stylesPar = stylesPar->next();
2029 prevStyle = curStyle; 2052 prevStyle = curStyle;
2030 curStyle = nextStyle; 2053 curStyle = nextStyle;
2031 nextStyle = styles.next(); 2054 nextStyle = styles.next();
2032 } 2055 }
2033} 2056}
2034 2057
2035void QTextDocument::setText( const QString &text, const QString &context ) 2058void QTextDocument::setText( const QString &text, const QString &context )
2036{ 2059{
2037 focusIndicator.parag = 0; 2060 focusIndicator.parag = 0;
2038 selections.clear(); 2061 selections.clear();
2039 if ( txtFormat == Qt::AutoText && QStyleSheet::mightBeRichText( text ) || 2062 if ( txtFormat == Qt::AutoText && QStyleSheet::mightBeRichText( text ) ||
2040 txtFormat == Qt::RichText ) 2063 txtFormat == Qt::RichText )
2041 setRichText( text, context ); 2064 setRichText( text, context );
2042 else 2065 else
2043 setPlainText( text ); 2066 setPlainText( text );
2044} 2067}
2045 2068
2046QString QTextDocument::plainText() const 2069QString QTextDocument::plainText() const
2047{ 2070{
2048 QString buffer; 2071 QString buffer;
2049 QString s; 2072 QString s;
2050 QTextParagraph *p = fParag; 2073 QTextParagraph *p = fParag;
2051 while ( p ) { 2074 while ( p ) {
2052 if ( !p->mightHaveCustomItems ) { 2075 if ( !p->mightHaveCustomItems ) {
2053 s = p->string()->toString(); 2076 s = p->string()->toString();
2054 } else { 2077 } else {
2055 for ( int i = 0; i < p->length() - 1; ++i ) { 2078 for ( int i = 0; i < p->length() - 1; ++i ) {
2056 if ( p->at( i )->isCustom() ) { 2079 if ( p->at( i )->isCustom() ) {
2057 if ( p->at( i )->customItem()->isNested() ) { 2080 if ( p->at( i )->customItem()->isNested() ) {
2058 s += "\n"; 2081 s += "\n";
2059 QTextTable *t = (QTextTable*)p->at( i )->customItem(); 2082 QTextTable *t = (QTextTable*)p->at( i )->customItem();
2060 QPtrList<QTextTableCell> cells = t->tableCells(); 2083 QPtrList<QTextTableCell> cells = t->tableCells();
2061 for ( QTextTableCell *c = cells.first(); c; c = cells.next() ) 2084 for ( QTextTableCell *c = cells.first(); c; c = cells.next() )
2062 s += c->richText()->plainText() + "\n"; 2085 s += c->richText()->plainText() + "\n";
2063 s += "\n"; 2086 s += "\n";
2064 } 2087 }
2065 } else { 2088 } else {
2066 s += p->at( i )->c; 2089 s += p->at( i )->c;
2067 } 2090 }
2068 } 2091 }
2069 } 2092 }
2070 s.remove( s.length() - 1, 1 ); 2093 s.remove( s.length() - 1, 1 );
2071 if ( p->next() ) 2094 if ( p->next() )
2072 s += "\n"; 2095 s += "\n";
2073 buffer += s; 2096 buffer += s;
2074 p = p->next(); 2097 p = p->next();
2075 } 2098 }
2076 return buffer; 2099 return buffer;
2077} 2100}
2078 2101
2079static QString align_to_string( int a ) 2102static QString align_to_string( int a )
2080{ 2103{
2081 if ( a & Qt::AlignRight ) 2104 if ( a & Qt::AlignRight )
2082 return " align=\"right\""; 2105 return " align=\"right\"";
2083 if ( a & Qt::AlignHCenter ) 2106 if ( a & Qt::AlignHCenter )
2084 return " align=\"center\""; 2107 return " align=\"center\"";
2085 if ( a & Qt3::AlignJustify ) 2108 if ( a & Qt3::AlignJustify )
2086 return " align=\"justify\""; 2109 return " align=\"justify\"";
2087 return QString::null; 2110 return QString::null;
2088} 2111}
2089 2112
2090static QString direction_to_string( int d ) 2113static QString direction_to_string( int d )
2091{ 2114{
@@ -5152,385 +5175,385 @@ int QTextFormatter::formatVertically( QTextDocument* doc, QTextParagraph* parag
5152// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5175// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5153 5176
5154QTextFormatterBreakInWords::QTextFormatterBreakInWords() 5177QTextFormatterBreakInWords::QTextFormatterBreakInWords()
5155{ 5178{
5156} 5179}
5157 5180
5158#define SPACE(s) doc?(s>0?s:0):s 5181#define SPACE(s) doc?(s>0?s:0):s
5159 5182
5160int QTextFormatterBreakInWords::format( QTextDocument *doc,QTextParagraph *parag, 5183int QTextFormatterBreakInWords::format( QTextDocument *doc,QTextParagraph *parag,
5161 int start, const QMap<int, QTextLineStart*> & ) 5184 int start, const QMap<int, QTextLineStart*> & )
5162{ 5185{
5163 QTextStringChar *c = 0; 5186 QTextStringChar *c = 0;
5164 QTextStringChar *firstChar = 0; 5187 QTextStringChar *firstChar = 0;
5165 int left = doc ? parag->leftMargin() + doc->leftMargin() : 0; 5188 int left = doc ? parag->leftMargin() + doc->leftMargin() : 0;
5166 int x = left + ( doc ? parag->firstLineMargin() : 0 ); 5189 int x = left + ( doc ? parag->firstLineMargin() : 0 );
5167 int dw = parag->documentVisibleWidth() - ( doc ? doc->rightMargin() : 0 ); 5190 int dw = parag->documentVisibleWidth() - ( doc ? doc->rightMargin() : 0 );
5168 int y = parag->prev() ? QMAX(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0; 5191 int y = parag->prev() ? QMAX(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0;
5169 int h = y; 5192 int h = y;
5170 int len = parag->length(); 5193 int len = parag->length();
5171 if ( doc ) 5194 if ( doc )
5172 x = doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), x, 4 ); 5195 x = doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), x, 4 );
5173 int rm = parag->rightMargin(); 5196 int rm = parag->rightMargin();
5174 int w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 ); 5197 int w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
5175 bool fullWidth = TRUE; 5198 bool fullWidth = TRUE;
5176 int minw = 0; 5199 int minw = 0;
5177 int wused = 0; 5200 int wused = 0;
5178 bool wrapEnabled = isWrapEnabled( parag ); 5201 bool wrapEnabled = isWrapEnabled( parag );
5179 5202
5180 start = 0; //######### what is the point with start?! (Matthias) 5203 start = 0; //######### what is the point with start?! (Matthias)
5181 if ( start == 0 ) 5204 if ( start == 0 )
5182 c = &parag->string()->at( 0 ); 5205 c = &parag->string()->at( 0 );
5183 5206
5184 int i = start; 5207 int i = start;
5185 QTextLineStart *lineStart = new QTextLineStart( y, y, 0 ); 5208 QTextLineStart *lineStart = new QTextLineStart( y, y, 0 );
5186 insertLineStart( parag, 0, lineStart ); 5209 insertLineStart( parag, 0, lineStart );
5187 5210
5188 QPainter *painter = QTextFormat::painter(); 5211 QPainter *painter = QTextFormat::painter();
5189 5212
5190 int col = 0; 5213 int col = 0;
5191 int ww = 0; 5214 int ww = 0;
5192 QChar lastChr; 5215 QChar lastChr;
5193 for ( ; i < len; ++i, ++col ) { 5216 for ( ; i < len; ++i, ++col ) {
5194 if ( c ) 5217 if ( c )
5195 lastChr = c->c; 5218 lastChr = c->c;
5196 c = &parag->string()->at( i ); 5219 c = &parag->string()->at( i );
5197 c->rightToLeft = FALSE; 5220 c->rightToLeft = FALSE;
5198 // ### the lines below should not be needed 5221 // ### the lines below should not be needed
5199 if ( painter ) 5222 if ( painter )
5200 c->format()->setPainter( painter ); 5223 c->format()->setPainter( painter );
5201 if ( i > 0 ) { 5224 if ( i > 0 ) {
5202 c->lineStart = 0; 5225 c->lineStart = 0;
5203 } else { 5226 } else {
5204 c->lineStart = 1; 5227 c->lineStart = 1;
5205 firstChar = c; 5228 firstChar = c;
5206 } 5229 }
5207 if ( c->c.unicode() >= 32 || c->isCustom() ) { 5230 if ( c->c.unicode() >= 32 || c->isCustom() ) {
5208 ww = parag->string()->width( i ); 5231 ww = parag->string()->width( i );
5209 } else if ( c->c == '\t' ) { 5232 } else if ( c->c == '\t' ) {
5210 int nx = parag->nextTab( i, x - left ) + left; 5233 int nx = parag->nextTab( i, x - left ) + left;
5211 if ( nx < x ) 5234 if ( nx < x )
5212 ww = w - x; 5235 ww = w - x;
5213 else 5236 else
5214 ww = nx - x; 5237 ww = nx - x;
5215 } else { 5238 } else {
5216 ww = c->format()->width( ' ' ); 5239 ww = c->format()->width( ' ' );
5217 } 5240 }
5218 5241
5219 if ( c->isCustom() && c->customItem()->ownLine() ) { 5242 if ( c->isCustom() && c->customItem()->ownLine() ) {
5220 x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left; 5243 x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
5221 w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 ); 5244 w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
5222 c->customItem()->resize( w - x ); 5245 c->customItem()->resize( w - x );
5223 w = dw; 5246 w = dw;
5224 y += h; 5247 y += h;
5225 h = c->height(); 5248 h = c->height();
5226 lineStart = new QTextLineStart( y, h, h ); 5249 lineStart = new QTextLineStart( y, h, h );
5227 insertLineStart( parag, i, lineStart ); 5250 insertLineStart( parag, i, lineStart );
5228 c->lineStart = 1; 5251 c->lineStart = 1;
5229 firstChar = c; 5252 firstChar = c;
5230 x = 0xffffff; 5253 x = 0xffffff;
5231 continue; 5254 continue;
5232 } 5255 }
5233 5256
5234 if ( wrapEnabled && 5257 if ( wrapEnabled &&
5235 ( wrapAtColumn() == -1 && x + ww > w || 5258 ( wrapAtColumn() == -1 && x + ww > w ||
5236 wrapAtColumn() != -1 && col >= wrapAtColumn() ) ) { 5259 wrapAtColumn() != -1 && col >= wrapAtColumn() ) ) {
5237 x = doc ? parag->document()->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left; 5260 x = doc ? parag->document()->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
5238 w = dw; 5261 w = dw;
5239 y += h; 5262 y += h;
5240 h = c->height(); 5263 h = c->height();
5241 lineStart = formatLine( parag, parag->string(), lineStart, firstChar, SPACE(c-1) ); 5264 lineStart = formatLine( parag, parag->string(), lineStart, firstChar, SPACE(c-1) );
5242 lineStart->y = y; 5265 lineStart->y = y;
5243 insertLineStart( parag, i, lineStart ); 5266 insertLineStart( parag, i, lineStart );
5244 lineStart->baseLine = c->ascent(); 5267 lineStart->baseLine = c->ascent();
5245 lineStart->h = c->height(); 5268 lineStart->h = c->height();
5246 c->lineStart = 1; 5269 c->lineStart = 1;
5247 firstChar = c; 5270 firstChar = c;
5248 col = 0; 5271 col = 0;
5249 if ( wrapAtColumn() != -1 ) 5272 if ( wrapAtColumn() != -1 )
5250 minw = QMAX( minw, w ); 5273 minw = QMAX( minw, w );
5251 } else if ( lineStart ) { 5274 } else if ( lineStart ) {
5252 lineStart->baseLine = QMAX( lineStart->baseLine, c->ascent() ); 5275 lineStart->baseLine = QMAX( lineStart->baseLine, c->ascent() );
5253 h = QMAX( h, c->height() ); 5276 h = QMAX( h, c->height() );
5254 lineStart->h = h; 5277 lineStart->h = h;
5255 } 5278 }
5256 5279
5257 c->x = x; 5280 c->x = x;
5258 x += ww; 5281 x += ww;
5259 wused = QMAX( wused, x ); 5282 wused = QMAX( wused, x );
5260 } 5283 }
5261 5284
5262 int m = parag->bottomMargin(); 5285 int m = parag->bottomMargin();
5263 if ( !parag->next() ) 5286 if ( !parag->next() )
5264 m = 0; 5287 m = 0;
5265 else 5288 else
5266 m = QMAX(m, parag->next()->topMargin() ) / 2; 5289 m = QMAX(m, parag->next()->topMargin() ) / 2;
5267 parag->setFullWidth( fullWidth ); 5290 parag->setFullWidth( fullWidth );
5268 y += h + m; 5291 y += h + m;
5269 if ( doc ) 5292 if ( doc )
5270 minw += doc->rightMargin(); 5293 minw += doc->rightMargin();
5271 if ( !wrapEnabled ) 5294 if ( !wrapEnabled )
5272 minw = QMAX(minw, wused); 5295 minw = QMAX(minw, wused);
5273 5296
5274 thisminw = minw; 5297 thisminw = minw;
5275 thiswused = wused; 5298 thiswused = wused;
5276 return y; 5299 return y;
5277} 5300}
5278 5301
5279// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5302// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5280 5303
5281QTextFormatterBreakWords::QTextFormatterBreakWords() 5304QTextFormatterBreakWords::QTextFormatterBreakWords()
5282{ 5305{
5283} 5306}
5284 5307
5285#define DO_FLOW( lineStart ) do{ if ( doc && doc->isPageBreakEnabled() ) { \ 5308#define DO_FLOW( lineStart ) do{ if ( doc && doc->isPageBreakEnabled() ) { \
5286 int yflow = lineStart->y + parag->rect().y();\ 5309 int yflow = lineStart->y + parag->rect().y();\
5287 int shift = doc->flow()->adjustFlow( yflow, dw, lineStart->h ); \ 5310 int shift = doc->flow()->adjustFlow( yflow, dw, lineStart->h ); \
5288 lineStart->y += shift;\ 5311 lineStart->y += shift;\
5289 y += shift;\ 5312 y += shift;\
5290 }}while(FALSE) 5313 }}while(FALSE)
5291 5314
5292int QTextFormatterBreakWords::format( QTextDocument *doc, QTextParagraph *parag, 5315int QTextFormatterBreakWords::format( QTextDocument *doc, QTextParagraph *parag,
5293 int start, const QMap<int, QTextLineStart*> & ) 5316 int start, const QMap<int, QTextLineStart*> & )
5294{ 5317{
5295 QTextStringChar *c = 0; 5318 QTextStringChar *c = 0;
5296 QTextStringChar *firstChar = 0; 5319 QTextStringChar *firstChar = 0;
5297 QTextString *string = parag->string(); 5320 QTextString *string = parag->string();
5298 int left = doc ? parag->leftMargin() + doc->leftMargin() : 0; 5321 int left = doc ? parag->leftMargin() + doc->leftMargin() : 0;
5299 int x = left + ( doc ? parag->firstLineMargin() : 0 ); 5322 int x = left + ( doc ? parag->firstLineMargin() : 0 );
5300 int y = parag->prev() ? QMAX(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0; 5323 int y = parag->prev() ? QMAX(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0;
5301 int h = y; 5324 int h = y;
5302 int len = parag->length(); 5325 int len = parag->length();
5303 if ( doc ) 5326 if ( doc )
5304 x = doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), x, 0 ); 5327 x = doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), x, 0 );
5305 int dw = parag->documentVisibleWidth() - ( doc ? ( left != x ? 0 : doc->rightMargin() ) : 0 ); 5328 int dw = parag->documentVisibleWidth() - ( doc ? ( left != x ? 0 : doc->rightMargin() ) : 0 );
5306 5329
5307 int curLeft = x; 5330 int curLeft = x;
5308 int rm = parag->rightMargin(); 5331 int rm = parag->rightMargin();
5309 int rdiff = doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 0 ) : 0; 5332 int rdiff = doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 0 ) : 0;
5310 int w = dw - rdiff; 5333 int w = dw - rdiff;
5311 bool fullWidth = TRUE; 5334 bool fullWidth = TRUE;
5312 int marg = left + rdiff; 5335 int marg = left + rdiff;
5313 int minw = 0; 5336 int minw = 0;
5314 int wused = 0; 5337 int wused = 0;
5315 int tminw = marg; 5338 int tminw = marg;
5316 int linespacing = doc ? parag->lineSpacing() : 0; 5339 int linespacing = doc ? parag->lineSpacing() : 0;
5317 bool wrapEnabled = isWrapEnabled( parag ); 5340 bool wrapEnabled = isWrapEnabled( parag );
5318 5341
5319 start = 0; 5342 start = 0;
5320 if ( start == 0 ) 5343 if ( start == 0 )
5321 c = &parag->string()->at( 0 ); 5344 c = &parag->string()->at( 0 );
5322 5345
5323 int i = start; 5346 int i = start;
5324 QTextLineStart *lineStart = new QTextLineStart( y, y, 0 ); 5347 QTextLineStart *lineStart = new QTextLineStart( y, y, 0 );
5325 insertLineStart( parag, 0, lineStart ); 5348 insertLineStart( parag, 0, lineStart );
5326 int lastBreak = -1; 5349 int lastBreak = -1;
5327 int tmpBaseLine = 0, tmph = 0; 5350 int tmpBaseLine = 0, tmph = 0;
5328 bool lastWasNonInlineCustom = FALSE; 5351 bool lastWasNonInlineCustom = FALSE;
5329 5352
5330 int align = parag->alignment(); 5353 int align = parag->alignment();
5331 if ( align == Qt3::AlignAuto && doc && doc->alignment() != Qt3::AlignAuto ) 5354 if ( align == Qt3::AlignAuto && doc && doc->alignment() != Qt3::AlignAuto )
5332 align = doc->alignment(); 5355 align = doc->alignment();
5333 5356
5334 align &= Qt3::AlignHorizontal_Mask; 5357 align &= Qt3::AlignHorizontal_Mask;
5335 5358
5336 QPainter *painter = QTextFormat::painter(); 5359 QPainter *painter = QTextFormat::painter();
5337 int col = 0; 5360 int col = 0;
5338 int ww = 0; 5361 int ww = 0;
5339 QChar lastChr; 5362 QChar lastChr;
5340 for ( ; i < len; ++i, ++col ) { 5363 for ( ; i < len; ++i, ++col ) {
5341 if ( c ) 5364 if ( c )
5342 lastChr = c->c; 5365 lastChr = c->c;
5343 // ### next line should not be needed 5366 // ### next line should not be needed
5344 if ( painter ) 5367 if ( c && painter )
5345 c->format()->setPainter( painter ); 5368 c->format()->setPainter( painter );
5346 c = &string->at( i ); 5369 c = &string->at( i );
5347 c->rightToLeft = FALSE; 5370 c->rightToLeft = FALSE;
5348 if ( i > 0 && (x > curLeft || ww == 0) || lastWasNonInlineCustom ) { 5371 if ( i > 0 && (x > curLeft || ww == 0) || lastWasNonInlineCustom ) {
5349 c->lineStart = 0; 5372 c->lineStart = 0;
5350 } else { 5373 } else {
5351 c->lineStart = 1; 5374 c->lineStart = 1;
5352 firstChar = c; 5375 firstChar = c;
5353 } 5376 }
5354 5377
5355 if ( c->isCustom() && c->customItem()->placement() != QTextCustomItem::PlaceInline ) 5378 if ( c->isCustom() && c->customItem()->placement() != QTextCustomItem::PlaceInline )
5356 lastWasNonInlineCustom = TRUE; 5379 lastWasNonInlineCustom = TRUE;
5357 else 5380 else
5358 lastWasNonInlineCustom = FALSE; 5381 lastWasNonInlineCustom = FALSE;
5359 5382
5360 if ( c->c.unicode() >= 32 || c->isCustom() ) { 5383 if ( c->c.unicode() >= 32 || c->isCustom() ) {
5361 ww = string->width( i ); 5384 ww = string->width( i );
5362 } else if ( c->c == '\t' ) { 5385 } else if ( c->c == '\t' ) {
5363 int nx = parag->nextTab( i, x - left ) + left; 5386 int nx = parag->nextTab( i, x - left ) + left;
5364 if ( nx < x ) 5387 if ( nx < x )
5365 ww = w - x; 5388 ww = w - x;
5366 else 5389 else
5367 ww = nx - x; 5390 ww = nx - x;
5368 } else { 5391 } else {
5369 ww = c->format()->width( ' ' ); 5392 ww = c->format()->width( ' ' );
5370 } 5393 }
5371 5394
5372 // last character ("invisible" space) has no width 5395 // last character ("invisible" space) has no width
5373 if ( i == len - 1 ) 5396 if ( i == len - 1 )
5374 ww = 0; 5397 ww = 0;
5375 5398
5376 QTextCustomItem* ci = c->customItem(); 5399 QTextCustomItem* ci = c->customItem();
5377 if ( c->isCustom() && ci->ownLine() ) { 5400 if ( c->isCustom() && ci->ownLine() ) {
5378 x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left; 5401 x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
5379 w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 ); 5402 w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
5380 QTextLineStart *lineStart2 = formatLine( parag, string, lineStart, firstChar, c-1, align, SPACE(w - x) ); 5403 QTextLineStart *lineStart2 = formatLine( parag, string, lineStart, firstChar, c-1, align, SPACE(w - x) );
5381 ci->resize( w - x); 5404 ci->resize( w - x);
5382 if ( ci->width < w - x ) { 5405 if ( ci->width < w - x ) {
5383 if ( align & Qt::AlignHCenter ) 5406 if ( align & Qt::AlignHCenter )
5384 x = ( w - ci->width ) / 2; 5407 x = ( w - ci->width ) / 2;
5385 else if ( align & Qt::AlignRight ) { 5408 else if ( align & Qt::AlignRight ) {
5386 x = w - ci->width; 5409 x = w - ci->width;
5387 } 5410 }
5388 } 5411 }
5389 c->x = x; 5412 c->x = x;
5390 curLeft = x; 5413 curLeft = x;
5391 if ( i == 0 || !isBreakable( string, i - 1 ) || string->at( i - 1 ).lineStart == 0 ) { 5414 if ( i == 0 || !isBreakable( string, i - 1 ) || string->at( i - 1 ).lineStart == 0 ) {
5392 y += QMAX( h, QMAX( tmph, linespacing ) ); 5415 y += QMAX( h, QMAX( tmph, linespacing ) );
5393 tmph = c->height(); 5416 tmph = c->height();
5394 h = tmph; 5417 h = tmph;
5395 lineStart = lineStart2; 5418 lineStart = lineStart2;
5396 lineStart->y = y; 5419 lineStart->y = y;
5397 insertLineStart( parag, i, lineStart ); 5420 insertLineStart( parag, i, lineStart );
5398 c->lineStart = 1; 5421 c->lineStart = 1;
5399 firstChar = c; 5422 firstChar = c;
5400 } else { 5423 } else {
5401 tmph = c->height(); 5424 tmph = c->height();
5402 h = tmph; 5425 h = tmph;
5403 delete lineStart2; 5426 delete lineStart2;
5404 } 5427 }
5405 lineStart->h = h; 5428 lineStart->h = h;
5406 lineStart->baseLine = h; 5429 lineStart->baseLine = h;
5407 tmpBaseLine = lineStart->baseLine; 5430 tmpBaseLine = lineStart->baseLine;
5408 lastBreak = -2; 5431 lastBreak = -2;
5409 x = 0xffffff; 5432 x = 0xffffff;
5410 minw = QMAX( minw, tminw ); 5433 minw = QMAX( minw, tminw );
5411 5434
5412 int tw = ci->minimumWidth() + ( doc ? doc->leftMargin() : 0 ); 5435 int tw = ci->minimumWidth() + ( doc ? doc->leftMargin() : 0 );
5413 if ( tw < QWIDGETSIZE_MAX ) 5436 if ( tw < QWIDGETSIZE_MAX )
5414 tminw = tw; 5437 tminw = tw;
5415 else 5438 else
5416 tminw = marg; 5439 tminw = marg;
5417 wused = QMAX( wused, ci->width ); 5440 wused = QMAX( wused, ci->width );
5418 continue; 5441 continue;
5419 } else if ( c->isCustom() && ci->placement() != QTextCustomItem::PlaceInline ) { 5442 } else if ( c->isCustom() && ci->placement() != QTextCustomItem::PlaceInline ) {
5420 int tw = ci->minimumWidth(); 5443 int tw = ci->minimumWidth();
5421 if ( tw < QWIDGETSIZE_MAX ) 5444 if ( tw < QWIDGETSIZE_MAX )
5422 minw = QMAX( minw, tw ); 5445 minw = QMAX( minw, tw );
5423 } 5446 }
5424 5447
5425 bool lastWasOwnLineCustomItem = lastBreak == -2; 5448 bool lastWasOwnLineCustomItem = lastBreak == -2;
5426 bool hadBreakableChar = lastBreak != -1; 5449 bool hadBreakableChar = lastBreak != -1;
5427 bool lastWasHardBreak = lastChr == QChar_linesep; 5450 bool lastWasHardBreak = lastChr == QChar_linesep;
5428 5451
5429 // we break if 5452 // we break if
5430 // 1. the last character was a hard break (QChar_linesep) or 5453 // 1. the last character was a hard break (QChar_linesep) or
5431 // 2. the last charater was a own-line custom item (eg. table or ruler) or 5454 // 2. the last charater was a own-line custom item (eg. table or ruler) or
5432 // 3. wrapping was enabled, it was not a space and following 5455 // 3. wrapping was enabled, it was not a space and following
5433 // condition is true: We either had a breakable character 5456 // condition is true: We either had a breakable character
5434 // previously or we ar allowed to break in words and - either 5457 // previously or we ar allowed to break in words and - either
5435 // we break at w pixels and the current char would exceed that 5458 // we break at w pixels and the current char would exceed that
5436 // or - we break at a column and the current character would 5459 // or - we break at a column and the current character would
5437 // exceed that. 5460 // exceed that.
5438 if ( lastWasHardBreak || lastWasOwnLineCustomItem || 5461 if ( lastWasHardBreak || lastWasOwnLineCustomItem ||
5439 ( wrapEnabled && 5462 ( wrapEnabled &&
5440 ( (!c->c.isSpace() && (hadBreakableChar || allowBreakInWords()) && 5463 ( (!c->c.isSpace() && (hadBreakableChar || allowBreakInWords()) &&
5441 ( (wrapAtColumn() == -1 && x + ww > w) || 5464 ( (wrapAtColumn() == -1 && x + ww > w) ||
5442 (wrapAtColumn() != -1 && col >= wrapAtColumn()) ) ) ) 5465 (wrapAtColumn() != -1 && col >= wrapAtColumn()) ) ) )
5443 ) 5466 )
5444 ) { 5467 ) {
5445 if ( wrapAtColumn() != -1 ) 5468 if ( wrapAtColumn() != -1 )
5446 minw = QMAX( minw, x + ww ); 5469 minw = QMAX( minw, x + ww );
5447 // if a break was forced (no breakable char, hard break or own line custom item), break immediately.... 5470 // if a break was forced (no breakable char, hard break or own line custom item), break immediately....
5448 if ( !hadBreakableChar || lastWasHardBreak || lastWasOwnLineCustomItem ) { 5471 if ( !hadBreakableChar || lastWasHardBreak || lastWasOwnLineCustomItem ) {
5449 if ( lineStart ) { 5472 if ( lineStart ) {
5450 lineStart->baseLine = QMAX( lineStart->baseLine, tmpBaseLine ); 5473 lineStart->baseLine = QMAX( lineStart->baseLine, tmpBaseLine );
5451 h = QMAX( h, tmph ); 5474 h = QMAX( h, tmph );
5452 lineStart->h = h; 5475 lineStart->h = h;
5453 DO_FLOW( lineStart ); 5476 DO_FLOW( lineStart );
5454 } 5477 }
5455 lineStart = formatLine( parag, string, lineStart, firstChar, c-1, align, SPACE(w - x) ); 5478 lineStart = formatLine( parag, string, lineStart, firstChar, c-1, align, SPACE(w - x) );
5456 x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left; 5479 x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
5457 w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 ); 5480 w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
5458 if ( !doc && c->c == '\t' ) { // qt_format_text tab handling 5481 if ( !doc && c->c == '\t' ) { // qt_format_text tab handling
5459 int nx = parag->nextTab( i, x - left ) + left; 5482 int nx = parag->nextTab( i, x - left ) + left;
5460 if ( nx < x ) 5483 if ( nx < x )
5461 ww = w - x; 5484 ww = w - x;
5462 else 5485 else
5463 ww = nx - x; 5486 ww = nx - x;
5464 } 5487 }
5465 curLeft = x; 5488 curLeft = x;
5466 y += QMAX( h, linespacing ); 5489 y += QMAX( h, linespacing );
5467 tmph = c->height(); 5490 tmph = c->height();
5468 h = 0; 5491 h = 0;
5469 lineStart->y = y; 5492 lineStart->y = y;
5470 insertLineStart( parag, i, lineStart ); 5493 insertLineStart( parag, i, lineStart );
5471 lineStart->baseLine = c->ascent(); 5494 lineStart->baseLine = c->ascent();
5472 lineStart->h = c->height(); 5495 lineStart->h = c->height();
5473 c->lineStart = 1; 5496 c->lineStart = 1;
5474 firstChar = c; 5497 firstChar = c;
5475 tmpBaseLine = lineStart->baseLine; 5498 tmpBaseLine = lineStart->baseLine;
5476 lastBreak = -1; 5499 lastBreak = -1;
5477 col = 0; 5500 col = 0;
5478 } else { // ... otherwise if we had a breakable char, break there 5501 } else { // ... otherwise if we had a breakable char, break there
5479 DO_FLOW( lineStart ); 5502 DO_FLOW( lineStart );
5480 i = lastBreak; 5503 i = lastBreak;
5481 lineStart = formatLine( parag, string, lineStart, firstChar, parag->at( lastBreak ),align, SPACE(w - string->at( i ).x) ); 5504 lineStart = formatLine( parag, string, lineStart, firstChar, parag->at( lastBreak ),align, SPACE(w - string->at( i ).x) );
5482 x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left; 5505 x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
5483 w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 ); 5506 w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
5484 if ( !doc && c->c == '\t' ) { // qt_format_text tab handling 5507 if ( !doc && c->c == '\t' ) { // qt_format_text tab handling
5485 int nx = parag->nextTab( i, x - left ) + left; 5508 int nx = parag->nextTab( i, x - left ) + left;
5486 if ( nx < x ) 5509 if ( nx < x )
5487 ww = w - x; 5510 ww = w - x;
5488 else 5511 else
5489 ww = nx - x; 5512 ww = nx - x;
5490 } 5513 }
5491 curLeft = x; 5514 curLeft = x;
5492 y += QMAX( h, linespacing ); 5515 y += QMAX( h, linespacing );
5493 tmph = c->height(); 5516 tmph = c->height();
5494 h = tmph; 5517 h = tmph;
5495 lineStart->y = y; 5518 lineStart->y = y;
5496 insertLineStart( parag, i + 1, lineStart ); 5519 insertLineStart( parag, i + 1, lineStart );
5497 lineStart->baseLine = c->ascent(); 5520 lineStart->baseLine = c->ascent();
5498 lineStart->h = c->height(); 5521 lineStart->h = c->height();
5499 c->lineStart = 1; 5522 c->lineStart = 1;
5500 firstChar = c; 5523 firstChar = c;
5501 tmpBaseLine = lineStart->baseLine; 5524 tmpBaseLine = lineStart->baseLine;
5502 lastBreak = -1; 5525 lastBreak = -1;
5503 col = 0; 5526 col = 0;
5504 tminw = marg; 5527 tminw = marg;
5505 continue; 5528 continue;
5506 } 5529 }
5507 } else if ( lineStart && isBreakable( string, i ) ) { 5530 } else if ( lineStart && isBreakable( string, i ) ) {
5508 if ( len <= 2 || i < len - 1 ) { 5531 if ( len <= 2 || i < len - 1 ) {
5509 tmpBaseLine = QMAX( tmpBaseLine, c->ascent() ); 5532 tmpBaseLine = QMAX( tmpBaseLine, c->ascent() );
5510 tmph = QMAX( tmph, c->height() ); 5533 tmph = QMAX( tmph, c->height() );
5511 } 5534 }
5512 minw = QMAX( minw, tminw ); 5535 minw = QMAX( minw, tminw );
5513 tminw = marg + ww; 5536 tminw = marg + ww;
5514 lineStart->baseLine = QMAX( lineStart->baseLine, tmpBaseLine ); 5537 lineStart->baseLine = QMAX( lineStart->baseLine, tmpBaseLine );
5515 h = QMAX( h, tmph ); 5538 h = QMAX( h, tmph );
5516 lineStart->h = h; 5539 lineStart->h = h;
5517 if ( i < len - 2 || c->c != ' ' ) 5540 if ( i < len - 2 || c->c != ' ' )
5518 lastBreak = i; 5541 lastBreak = i;
5519 } else { 5542 } else {
5520 tminw += ww; 5543 tminw += ww;
5521 int belowBaseLine = QMAX( tmph - tmpBaseLine, c->height()- c->ascent() ); 5544 int belowBaseLine = QMAX( tmph - tmpBaseLine, c->height()- c->ascent() );
5522 tmpBaseLine = QMAX( tmpBaseLine, c->ascent() ); 5545 tmpBaseLine = QMAX( tmpBaseLine, c->ascent() );
5523 tmph = tmpBaseLine + belowBaseLine; 5546 tmph = tmpBaseLine + belowBaseLine;
5524 } 5547 }
5525 5548
5526 c->x = x; 5549 c->x = x;
5527 x += ww; 5550 x += ww;
5528 wused = QMAX( wused, x ); 5551 wused = QMAX( wused, x );
5529 } 5552 }
5530 5553
5531 // ### hack. The last char in the paragraph is always invisible, 5554 // ### hack. The last char in the paragraph is always invisible,
5532 // ### and somehow sometimes has a wrong format. It changes 5555 // ### and somehow sometimes has a wrong format. It changes
5533 // ### between // layouting and printing. This corrects some 5556 // ### between // layouting and printing. This corrects some
5534 // ### layouting errors in BiDi mode due to this. 5557 // ### layouting errors in BiDi mode due to this.
5535 if ( len > 1 && !c->isAnchor() ) { 5558 if ( len > 1 && !c->isAnchor() ) {
5536 c->format()->removeRef(); 5559 c->format()->removeRef();
diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp
index 9069c09..3fd877f 100644
--- a/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp
@@ -106,224 +106,227 @@ OTSDPAttribute::OTSDPAttribute( sdp_data_t * attrib ) {
106 case SDP_TEXT_STR_UNSPEC : 106 case SDP_TEXT_STR_UNSPEC :
107 case SDP_TEXT_STR8 : 107 case SDP_TEXT_STR8 :
108 case SDP_TEXT_STR16 : 108 case SDP_TEXT_STR16 :
109 case SDP_TEXT_STR32 : 109 case SDP_TEXT_STR32 :
110 setString( QString(attrib->val.str) ); 110 setString( QString(attrib->val.str) );
111 break; 111 break;
112 case SDP_URL_STR_UNSPEC : 112 case SDP_URL_STR_UNSPEC :
113 case SDP_URL_STR8 : 113 case SDP_URL_STR8 :
114 case SDP_URL_STR16 : 114 case SDP_URL_STR16 :
115 case SDP_URL_STR32 : 115 case SDP_URL_STR32 :
116 setURL( QString(attrib->val.str) ); 116 setURL( QString(attrib->val.str) );
117 break; 117 break;
118 case SDP_BOOL: 118 case SDP_BOOL:
119 setBool( attrib->val.int8 != 0); 119 setBool( attrib->val.int8 != 0);
120 break; 120 break;
121 case SDP_SEQ_UNSPEC : 121 case SDP_SEQ_UNSPEC :
122 case SDP_SEQ8 : 122 case SDP_SEQ8 :
123 case SDP_SEQ16 : 123 case SDP_SEQ16 :
124 case SDP_SEQ32 : 124 case SDP_SEQ32 :
125 case SDP_ALT_UNSPEC : 125 case SDP_ALT_UNSPEC :
126 case SDP_ALT8 : 126 case SDP_ALT8 :
127 case SDP_ALT16 : 127 case SDP_ALT16 :
128 case SDP_ALT32 : 128 case SDP_ALT32 :
129 { AttributeVector subAttribs; 129 { AttributeVector subAttribs;
130 OTSDPAttribute * Attr; 130 OTSDPAttribute * Attr;
131 sdp_data_t* subAttrib = attrib->val.dataseq; 131 sdp_data_t* subAttrib = attrib->val.dataseq;
132 132
133 for (; subAttrib; subAttrib = subAttrib->next) { 133 for (; subAttrib; subAttrib = subAttrib->next) {
134 134
135 Attr = new OTSDPAttribute(subAttrib); 135 Attr = new OTSDPAttribute(subAttrib);
136 subAttribs.resize( subAttribs.size() + 1 ); 136 subAttribs.resize( subAttribs.size() + 1 );
137 subAttribs.insert( subAttribs.size() - 1, Attr ); 137 subAttribs.insert( subAttribs.size() - 1, Attr );
138 } 138 }
139 139
140 if( attrib->dtd == SDP_ALT_UNSPEC || 140 if( attrib->dtd == SDP_ALT_UNSPEC ||
141 attrib->dtd == SDP_ALT8 || 141 attrib->dtd == SDP_ALT8 ||
142 attrib->dtd == SDP_ALT16 || 142 attrib->dtd == SDP_ALT16 ||
143 attrib->dtd == SDP_ALT32 ) { 143 attrib->dtd == SDP_ALT32 ) {
144 setAlternative(subAttribs); 144 setAlternative(subAttribs);
145 } else { 145 } else {
146 setSequence(subAttribs); 146 setSequence(subAttribs);
147 } 147 }
148 break; 148 break;
149 } 149 }
150 } // end case 150 } // end case
151} 151}
152 152
153QString OTSDPAttribute::toString( void ) { 153QString OTSDPAttribute::toString( void ) {
154 QString S; 154 QString S;
155 switch( type ) { 155 switch( type ) {
156 case INVALID : 156 case INVALID :
157 S = "invalid"; 157 S = "invalid";
158 break; 158 break;
159 case NIL : 159 case NIL :
160 S = "NIL"; 160 S = "NIL";
161 break; 161 break;
162 case UINT : 162 case UINT :
163 S = Value.uintVal->toString(); 163 S = Value.uintVal->toString();
164 break; 164 break;
165 case INT : 165 case INT :
166 S = Value.intVal->toString(); 166 S = Value.intVal->toString();
167 break; 167 break;
168 case UUID : 168 case UUID :
169 S = Value.uuidVal->toString(); 169 S = Value.uuidVal->toString();
170 break; 170 break;
171 case BOOLEAN : 171 case BOOLEAN :
172 S = (Value.boolVal) ? "true" : "false"; 172 S = (Value.boolVal) ? "true" : "false";
173 break; 173 break;
174 case STRING : 174 case STRING :
175 S = *(Value.stringVal); 175 S = *(Value.stringVal);
176 break; 176 break;
177 case URL : 177 case URL :
178 S = *(Value.stringVal); 178 S = *(Value.stringVal);
179 break; 179 break;
180 case SEQUENCE : 180 case SEQUENCE :
181 S.sprintf( "Sequence(%d)", Value.sequenceVal->count() ); 181 S.sprintf( "Sequence(%d)", Value.sequenceVal->count() );
182 break; 182 break;
183 case ALTERNATIVE : 183 case ALTERNATIVE :
184 S.sprintf( "Alternative(%d)", Value.sequenceVal->count() ); 184 S.sprintf( "Alternative(%d)", Value.sequenceVal->count() );
185 break; 185 break;
186 case UNKNOWN : 186 case UNKNOWN :
187 S = "unknown"; 187 S = "unknown";
188 break; 188 break;
189 } 189 }
190 return S; 190 return S;
191} 191}
192 192
193void OTSDPAttribute::setNil() { 193void OTSDPAttribute::setNil() {
194 type = NIL; 194 type = NIL;
195} 195}
196 196
197void OTSDPAttribute::setInt(const OTSDPAttribute::int128_t & val) { 197void OTSDPAttribute::setInt(const OTSDPAttribute::int128_t & val) {
198 type = INT; 198 type = INT;
199 Value.intVal = new int128_t( val ); 199 Value.intVal = new int128_t( val );
200} 200}
201 201
202void OTSDPAttribute::setUInt(const uint128_t & val) { 202void OTSDPAttribute::setUInt(const uint128_t & val) {
203 type = UINT; 203 type = UINT;
204 Value.uintVal = new uint128_t(val); 204 Value.uintVal = new uint128_t(val);
205} 205}
206 206
207void OTSDPAttribute::setUUID(const OTUUID & val) { 207void OTSDPAttribute::setUUID(const OTUUID & val) {
208 type = UUID; 208 type = UUID;
209 Value.uuidVal = new OTUUID( val ); 209 Value.uuidVal = new OTUUID( val );
210} 210}
211 211
212void OTSDPAttribute::setBool(bool val) { 212void OTSDPAttribute::setBool(bool val) {
213 type = BOOLEAN; 213 type = BOOLEAN;
214 Value.boolVal = val; 214 Value.boolVal = val;
215} 215}
216 216
217void OTSDPAttribute::setString( const QString & val) { 217void OTSDPAttribute::setString( const QString & val) {
218 type = STRING; 218 type = STRING;
219 Value.stringVal = new QString( val ); 219 Value.stringVal = new QString( val );
220} 220}
221 221
222void OTSDPAttribute::setURL( const QString & val) { 222void OTSDPAttribute::setURL( const QString & val) {
223 type = URL; 223 type = URL;
224 Value.stringVal = new QString(val); 224 Value.stringVal = new QString(val);
225} 225}
226 226
227void OTSDPAttribute::setSequence(const AttributeVector& val) { 227void OTSDPAttribute::setSequence(const AttributeVector& val) {
228 type = SEQUENCE; 228 type = SEQUENCE;
229 Value.sequenceVal = new AttributeVector(); 229 Value.sequenceVal = new AttributeVector();
230 Value.sequenceVal->setAutoDelete( TRUE ); 230 Value.sequenceVal->setAutoDelete( TRUE );
231 *Value.sequenceVal = val; 231 *Value.sequenceVal = val;
232} 232}
233 233
234void OTSDPAttribute::setAlternative(const AttributeVector& val) { 234void OTSDPAttribute::setAlternative(const AttributeVector& val) {
235 type = ALTERNATIVE; 235 type = ALTERNATIVE;
236 Value.sequenceVal = new AttributeVector(); 236 Value.sequenceVal = new AttributeVector();
237 Value.sequenceVal->setAutoDelete( TRUE ); 237 Value.sequenceVal->setAutoDelete( TRUE );
238 *Value.sequenceVal = val; 238 *Value.sequenceVal = val;
239} 239}
240 240
241QString OTSDPAttribute::getString() { 241QString OTSDPAttribute::getString() {
242 assert(type == STRING); 242 assert(type == STRING);
243 return *Value.stringVal; 243 return *Value.stringVal;
244} 244}
245 245
246QString OTSDPAttribute::getURL() { 246QString OTSDPAttribute::getURL() {
247 assert(type == URL); 247 assert(type == URL);
248 return *Value.stringVal; 248 return *Value.stringVal;
249} 249}
250 250
251const OTSDPAttribute::int128_t & OTSDPAttribute::getInt() { 251const OTSDPAttribute::int128_t & OTSDPAttribute::getInt() {
252 assert(type == INT); 252 assert(type == INT);
253 return *Value.intVal; 253 return *Value.intVal;
254} 254}
255 255
256 256
257const OTSDPAttribute::uint128_t & OTSDPAttribute::getUInt() { 257const OTSDPAttribute::uint128_t & OTSDPAttribute::getUInt() {
258 assert(type == UINT); 258 assert(type == UINT);
259 return *Value.uintVal; 259 return *Value.uintVal;
260} 260}
261 261
262const OTUUID & OTSDPAttribute::getUUID() { 262const OTUUID & OTSDPAttribute::getUUID() {
263 assert(type == UUID); 263 assert(type == UUID);
264 return *Value.uuidVal; 264 return *Value.uuidVal;
265} 265}
266 266
267bool OTSDPAttribute::getBool() { 267bool OTSDPAttribute::getBool() {
268 assert(type == BOOLEAN); 268 assert(type == BOOLEAN);
269 return Value.boolVal; 269 return Value.boolVal;
270} 270}
271 271
272AttributeVector * OTSDPAttribute::getSequence() { 272AttributeVector * OTSDPAttribute::getSequence() {
273 assert(type == SEQUENCE); 273 assert(type == SEQUENCE);
274 return Value.sequenceVal; 274 return Value.sequenceVal;
275} 275}
276 276
277AttributeVector * OTSDPAttribute::getAlternative() { 277AttributeVector * OTSDPAttribute::getAlternative() {
278 assert(type == ALTERNATIVE); 278 assert(type == ALTERNATIVE);
279 return Value.sequenceVal; 279 return Value.sequenceVal;
280} 280}
281 281
282UUIDVector OTSDPAttribute::getAllUUIDs() { 282UUIDVector OTSDPAttribute::getAllUUIDs() {
283 283
284 UUIDVector uuids; 284 UUIDVector uuids;
285 285
286 if (getType() == UUID) { 286 if (getType() == UUID) {
287 uuids.resize( uuids.size()+1 ); 287 uuids.resize( uuids.size()+1 );
288 uuids[uuids.size()-1] = getUUID(); 288 uuids[uuids.size()-1] = getUUID();
289 } else { 289 } else {
290 AttributeVector * subAttributes = 0 ; 290 AttributeVector * subAttributes = 0 ;
291 291
292 if (getType() == SEQUENCE) { 292 if (getType() == SEQUENCE) {
293 subAttributes = getSequence(); 293 subAttributes = getSequence();
294 } else if (getType() == ALTERNATIVE) { 294 } else if (getType() == ALTERNATIVE) {
295 subAttributes = getAlternative(); 295 subAttributes = getAlternative();
296 } 296 }
297 297
298 if (!subAttributes)
299 return 0;
300
298 int os; 301 int os;
299 for( unsigned int i = 0; i < subAttributes->count(); i++ ) { 302 for( unsigned int i = 0; i < subAttributes->count(); i++ ) {
300 UUIDVector subUUIDs = (*subAttributes)[i]->getAllUUIDs(); 303 UUIDVector subUUIDs = (*subAttributes)[i]->getAllUUIDs();
301 304
302 os = uuids.size(); 305 os = uuids.size();
303 uuids.resize( uuids.size()+subUUIDs.count() ); 306 uuids.resize( uuids.size()+subUUIDs.count() );
304 307
305 for( unsigned int k = 0; k < subUUIDs.count(); k++ ) { 308 for( unsigned int k = 0; k < subUUIDs.count(); k++ ) {
306 uuids[os + k] = subUUIDs[k]; 309 uuids[os + k] = subUUIDs[k];
307 } 310 }
308 } 311 }
309 } 312 }
310 return uuids; 313 return uuids;
311} 314}
312 315
313static char * Attr2String[] = { 316static char * Attr2String[] = {
314 "Invalid", 317 "Invalid",
315 "Nil", 318 "Nil",
316 "UInt", 319 "UInt",
317 "int", 320 "int",
318 "UUID", 321 "UUID",
319 "Boolean", 322 "Boolean",
320 "String", 323 "String",
321 "Sequence", 324 "Sequence",
322 "Alternative", 325 "Alternative",
323 "URL", 326 "URL",
324 "Unknown" 327 "Unknown"
325}; 328};
326 329
327const char * OTSDPAttribute::getTypeString() { 330const char * OTSDPAttribute::getTypeString() {
328 return Attr2String[type]; 331 return Attr2String[type];
329} 332}
diff --git a/noncore/settings/packagemanager/oipkgconfigdlg.cpp b/noncore/settings/packagemanager/oipkgconfigdlg.cpp
index d014378..78a18f7 100644
--- a/noncore/settings/packagemanager/oipkgconfigdlg.cpp
+++ b/noncore/settings/packagemanager/oipkgconfigdlg.cpp
@@ -247,399 +247,401 @@ void OIpkgConfigDlg::initDestinationWidget()
247 247
248 m_destDeleteBtn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), 248 m_destDeleteBtn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ),
249 tr( "Delete" ), container ); 249 tr( "Delete" ), container );
250 m_destDeleteBtn->setMinimumHeight( AppLnk::smallIconSize()+4 ); 250 m_destDeleteBtn->setMinimumHeight( AppLnk::smallIconSize()+4 );
251 m_destDeleteBtn->setEnabled( false ); 251 m_destDeleteBtn->setEnabled( false );
252 QWhatsThis::add( m_destDeleteBtn, tr( "Tap here to delete the entry selected above." ) ); 252 QWhatsThis::add( m_destDeleteBtn, tr( "Tap here to delete the entry selected above." ) );
253 connect( m_destDeleteBtn, SIGNAL(clicked()), this, SLOT(slotDestDelete()) ); 253 connect( m_destDeleteBtn, SIGNAL(clicked()), this, SLOT(slotDestDelete()) );
254 layout->addWidget( m_destDeleteBtn, 1, 2 ); 254 layout->addWidget( m_destDeleteBtn, 1, 2 );
255} 255}
256 256
257void OIpkgConfigDlg::initProxyWidget() 257void OIpkgConfigDlg::initProxyWidget()
258{ 258{
259 m_proxyWidget = new QWidget( this ); 259 m_proxyWidget = new QWidget( this );
260 260
261 // Initialize UI 261 // Initialize UI
262 QVBoxLayout *vb = new QVBoxLayout( m_proxyWidget ); 262 QVBoxLayout *vb = new QVBoxLayout( m_proxyWidget );
263 QScrollView *sv = new QScrollView( m_proxyWidget ); 263 QScrollView *sv = new QScrollView( m_proxyWidget );
264 vb->addWidget( sv, 0, 0 ); 264 vb->addWidget( sv, 0, 0 );
265 sv->setResizePolicy( QScrollView::AutoOneFit ); 265 sv->setResizePolicy( QScrollView::AutoOneFit );
266 sv->setFrameStyle( QFrame::NoFrame ); 266 sv->setFrameStyle( QFrame::NoFrame );
267 QWidget *container = new QWidget( sv->viewport() ); 267 QWidget *container = new QWidget( sv->viewport() );
268 sv->addChild( container ); 268 sv->addChild( container );
269 QGridLayout *layout = new QGridLayout( container, 4, 2, 2, 4 ); 269 QGridLayout *layout = new QGridLayout( container, 4, 2, 2, 4 );
270 270
271 // HTTP proxy server configuration 271 // HTTP proxy server configuration
272 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "HTTP Proxy" ), container ); 272 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "HTTP Proxy" ), container );
273 grpbox->layout()->setSpacing( 2 ); 273 grpbox->layout()->setSpacing( 2 );
274 grpbox->layout()->setMargin( 4 ); 274 grpbox->layout()->setMargin( 4 );
275 layout->addMultiCellWidget( grpbox, 0, 0, 0, 1 ); 275 layout->addMultiCellWidget( grpbox, 0, 0, 0, 1 );
276 QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() ); 276 QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() );
277 m_proxyHttpServer = new QLineEdit( grpbox ); 277 m_proxyHttpServer = new QLineEdit( grpbox );
278 QWhatsThis::add( m_proxyHttpServer, tr( "Enter the URL address of the HTTP proxy server here." ) ); 278 QWhatsThis::add( m_proxyHttpServer, tr( "Enter the URL address of the HTTP proxy server here." ) );
279 grplayout->addWidget( m_proxyHttpServer ); 279 grplayout->addWidget( m_proxyHttpServer );
280 m_proxyHttpActive = new QCheckBox( tr( "Enabled" ), grpbox ); 280 m_proxyHttpActive = new QCheckBox( tr( "Enabled" ), grpbox );
281 QWhatsThis::add( m_proxyHttpActive, tr( "Tap here to enable or disable the HTTP proxy server." ) ); 281 QWhatsThis::add( m_proxyHttpActive, tr( "Tap here to enable or disable the HTTP proxy server." ) );
282 grplayout->addWidget( m_proxyHttpActive ); 282 grplayout->addWidget( m_proxyHttpActive );
283 283
284 // FTP proxy server configuration 284 // FTP proxy server configuration
285 grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container ); 285 grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container );
286 grpbox->layout()->setSpacing( 2 ); 286 grpbox->layout()->setSpacing( 2 );
287 grpbox->layout()->setMargin( 4 ); 287 grpbox->layout()->setMargin( 4 );
288 layout->addMultiCellWidget( grpbox, 1, 1, 0, 1 ); 288 layout->addMultiCellWidget( grpbox, 1, 1, 0, 1 );
289 grplayout = new QVBoxLayout( grpbox->layout() ); 289 grplayout = new QVBoxLayout( grpbox->layout() );
290 m_proxyFtpServer = new QLineEdit( grpbox ); 290 m_proxyFtpServer = new QLineEdit( grpbox );
291 QWhatsThis::add( m_proxyFtpServer, tr( "Enter the URL address of the FTP proxy server here." ) ); 291 QWhatsThis::add( m_proxyFtpServer, tr( "Enter the URL address of the FTP proxy server here." ) );
292 grplayout->addWidget( m_proxyFtpServer ); 292 grplayout->addWidget( m_proxyFtpServer );
293 m_proxyFtpActive = new QCheckBox( tr( "Enabled" ), grpbox ); 293 m_proxyFtpActive = new QCheckBox( tr( "Enabled" ), grpbox );
294 QWhatsThis::add( m_proxyFtpActive, tr( "Tap here to enable or disable the FTP proxy server." ) ); 294 QWhatsThis::add( m_proxyFtpActive, tr( "Tap here to enable or disable the FTP proxy server." ) );
295 grplayout->addWidget( m_proxyFtpActive ); 295 grplayout->addWidget( m_proxyFtpActive );
296 296
297 // Proxy server username and password configuration 297 // Proxy server username and password configuration
298 QLabel *label = new QLabel( tr( "Username:" ), container ); 298 QLabel *label = new QLabel( tr( "Username:" ), container );
299 QWhatsThis::add( label, tr( "Enter the username for the proxy servers here." ) ); 299 QWhatsThis::add( label, tr( "Enter the username for the proxy servers here." ) );
300 layout->addWidget( label, 2, 0 ); 300 layout->addWidget( label, 2, 0 );
301 m_proxyUsername = new QLineEdit( container ); 301 m_proxyUsername = new QLineEdit( container );
302 QWhatsThis::add( m_proxyUsername, tr( "Enter the username for the proxy servers here." ) ); 302 QWhatsThis::add( m_proxyUsername, tr( "Enter the username for the proxy servers here." ) );
303 layout->addWidget( m_proxyUsername, 2, 1 ); 303 layout->addWidget( m_proxyUsername, 2, 1 );
304 304
305 label = new QLabel( tr( "Password:" ), container ); 305 label = new QLabel( tr( "Password:" ), container );
306 QWhatsThis::add( label, tr( "Enter the password for the proxy servers here." ) ); 306 QWhatsThis::add( label, tr( "Enter the password for the proxy servers here." ) );
307 layout->addWidget( label, 3, 0 ); 307 layout->addWidget( label, 3, 0 );
308 m_proxyPassword = new QLineEdit( container ); 308 m_proxyPassword = new QLineEdit( container );
309 QWhatsThis::add( m_proxyPassword, tr( "Enter the password for the proxy servers here." ) ); 309 QWhatsThis::add( m_proxyPassword, tr( "Enter the password for the proxy servers here." ) );
310 layout->addWidget( m_proxyPassword, 3, 1 ); 310 layout->addWidget( m_proxyPassword, 3, 1 );
311} 311}
312 312
313void OIpkgConfigDlg::initOptionsWidget() 313void OIpkgConfigDlg::initOptionsWidget()
314{ 314{
315 m_optionsWidget = new QWidget( this ); 315 m_optionsWidget = new QWidget( this );
316 316
317 // Initialize UI 317 // Initialize UI
318 QVBoxLayout *vb = new QVBoxLayout( m_optionsWidget ); 318 QVBoxLayout *vb = new QVBoxLayout( m_optionsWidget );
319 QScrollView *sv = new QScrollView( m_optionsWidget ); 319 QScrollView *sv = new QScrollView( m_optionsWidget );
320 vb->addWidget( sv, 0, 0 ); 320 vb->addWidget( sv, 0, 0 );
321 sv->setResizePolicy( QScrollView::AutoOneFit ); 321 sv->setResizePolicy( QScrollView::AutoOneFit );
322 sv->setFrameStyle( QFrame::NoFrame ); 322 sv->setFrameStyle( QFrame::NoFrame );
323 QWidget *container = new QWidget( sv->viewport() ); 323 QWidget *container = new QWidget( sv->viewport() );
324 sv->addChild( container ); 324 sv->addChild( container );
325 QGridLayout *layout = new QGridLayout( container, 8, 2, 2, 4 ); 325 QGridLayout *layout = new QGridLayout( container, 8, 2, 2, 4 );
326 326
327 m_optForceDepends = new QCheckBox( tr( "Force Depends" ), container ); 327 m_optForceDepends = new QCheckBox( tr( "Force Depends" ), container );
328 QWhatsThis::add( m_optForceDepends, tr( "Tap here to enable or disable the '-force-depends' option for Ipkg." ) ); 328 QWhatsThis::add( m_optForceDepends, tr( "Tap here to enable or disable the '-force-depends' option for Ipkg." ) );
329 layout->addMultiCellWidget( m_optForceDepends, 0, 0, 0, 1 ); 329 layout->addMultiCellWidget( m_optForceDepends, 0, 0, 0, 1 );
330 330
331 m_optForceReinstall = new QCheckBox( tr( "Force Reinstall" ), container ); 331 m_optForceReinstall = new QCheckBox( tr( "Force Reinstall" ), container );
332 QWhatsThis::add( m_optForceReinstall, tr( "Tap here to enable or disable the '-force-reinstall' option for Ipkg." ) ); 332 QWhatsThis::add( m_optForceReinstall, tr( "Tap here to enable or disable the '-force-reinstall' option for Ipkg." ) );
333 layout->addMultiCellWidget( m_optForceReinstall, 1, 1, 0, 1 ); 333 layout->addMultiCellWidget( m_optForceReinstall, 1, 1, 0, 1 );
334 334
335 m_optForceRemove = new QCheckBox( tr( "Force Remove" ), container ); 335 m_optForceRemove = new QCheckBox( tr( "Force Remove" ), container );
336 QWhatsThis::add( m_optForceRemove, tr( "Tap here to enable or disable the '-force-removal-of-dependent-packages' option for Ipkg." ) ); 336 QWhatsThis::add( m_optForceRemove, tr( "Tap here to enable or disable the '-force-removal-of-dependent-packages' option for Ipkg." ) );
337 layout->addMultiCellWidget( m_optForceRemove, 2, 2, 0, 1 ); 337 layout->addMultiCellWidget( m_optForceRemove, 2, 2, 0, 1 );
338 338
339 m_optForceOverwrite = new QCheckBox( tr( "Force Overwrite" ), container ); 339 m_optForceOverwrite = new QCheckBox( tr( "Force Overwrite" ), container );
340 QWhatsThis::add( m_optForceOverwrite, tr( "Tap here to enable or disable the '-force-overwrite' option for Ipkg." ) ); 340 QWhatsThis::add( m_optForceOverwrite, tr( "Tap here to enable or disable the '-force-overwrite' option for Ipkg." ) );
341 layout->addMultiCellWidget( m_optForceOverwrite, 3, 3, 0, 1 ); 341 layout->addMultiCellWidget( m_optForceOverwrite, 3, 3, 0, 1 );
342 342
343 m_optForceRecursive = new QCheckBox( tr( "Force Recursive" ), container ); 343 m_optForceRecursive = new QCheckBox( tr( "Force Recursive" ), container );
344 QWhatsThis::add( m_optForceRecursive, tr( "Tap here to enable or disable the '-recursive' option for Ipkg." ) ); 344 QWhatsThis::add( m_optForceRecursive, tr( "Tap here to enable or disable the '-recursive' option for Ipkg." ) );
345 layout->addMultiCellWidget( m_optForceRecursive, 4, 4, 0, 1 ); 345 layout->addMultiCellWidget( m_optForceRecursive, 4, 4, 0, 1 );
346 346
347 m_optVerboseWget = new QCheckBox( tr( "Verbose fetch" ), container ); 347 m_optVerboseWget = new QCheckBox( tr( "Verbose fetch" ), container );
348 QWhatsThis::add( m_optVerboseWget, tr( "Tap here to enable or disable the '-verbose_wget' option for Ipkg." ) ); 348 QWhatsThis::add( m_optVerboseWget, tr( "Tap here to enable or disable the '-verbose_wget' option for Ipkg." ) );
349 layout->addMultiCellWidget( m_optVerboseWget, 5, 5, 0, 1 ); 349 layout->addMultiCellWidget( m_optVerboseWget, 5, 5, 0, 1 );
350 350
351 QLabel *l = new QLabel( tr( "Information level:" ), container ); 351 QLabel *l = new QLabel( tr( "Information level:" ), container );
352 QWhatsThis::add( l, tr( "Select information level for Ipkg." ) ); 352 QWhatsThis::add( l, tr( "Select information level for Ipkg." ) );
353 layout->addMultiCellWidget( l, 6, 6, 0, 1 ); 353 layout->addMultiCellWidget( l, 6, 6, 0, 1 );
354 354
355 m_optVerboseIpkg = new QComboBox( container ); 355 m_optVerboseIpkg = new QComboBox( container );
356 QWhatsThis::add( m_optVerboseIpkg, tr( "Select information level for Ipkg." ) ); 356 QWhatsThis::add( m_optVerboseIpkg, tr( "Select information level for Ipkg." ) );
357 m_optVerboseIpkg->insertItem( tr( "Errors only" ) ); 357 m_optVerboseIpkg->insertItem( tr( "Errors only" ) );
358 m_optVerboseIpkg->insertItem( tr( "Normal messages" ) ); 358 m_optVerboseIpkg->insertItem( tr( "Normal messages" ) );
359 m_optVerboseIpkg->insertItem( tr( "Informative messages" ) ); 359 m_optVerboseIpkg->insertItem( tr( "Informative messages" ) );
360 m_optVerboseIpkg->insertItem( tr( "Troubleshooting output" ) ); 360 m_optVerboseIpkg->insertItem( tr( "Troubleshooting output" ) );
361 layout->addMultiCellWidget( m_optVerboseIpkg, 7, 7, 0, 1 ); 361 layout->addMultiCellWidget( m_optVerboseIpkg, 7, 7, 0, 1 );
362 362
363 l = new QLabel( tr( "Package source lists directory:" ), container ); 363 l = new QLabel( tr( "Package source lists directory:" ), container );
364 QWhatsThis::add( l, tr( "Enter the directory where package source feed information is stored." ) ); 364 QWhatsThis::add( l, tr( "Enter the directory where package source feed information is stored." ) );
365 layout->addMultiCellWidget( l, 8, 8, 0, 1 ); 365 layout->addMultiCellWidget( l, 8, 8, 0, 1 );
366 366
367 m_optSourceLists = new QLineEdit( container ); 367 m_optSourceLists = new QLineEdit( container );
368 QWhatsThis::add( m_optSourceLists, tr( "Enter the directory where package source feed information is stored." ) ); 368 QWhatsThis::add( m_optSourceLists, tr( "Enter the directory where package source feed information is stored." ) );
369 layout->addWidget( m_optSourceLists, 9, 0 ); 369 layout->addWidget( m_optSourceLists, 9, 0 );
370 370
371 QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "folder", Opie::Core::OResource::SmallIcon ), 371 QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "folder", Opie::Core::OResource::SmallIcon ),
372 QString::null, container ); 372 QString::null, container );
373 btn->setMinimumHeight( AppLnk::smallIconSize()+4 ); 373 btn->setMinimumHeight( AppLnk::smallIconSize()+4 );
374 btn->setMaximumWidth( btn->height() ); 374 btn->setMaximumWidth( btn->height() );
375 QWhatsThis::add( btn, tr( "Tap here to select the directory where package source feed information is stored." ) ); 375 QWhatsThis::add( btn, tr( "Tap here to select the directory where package source feed information is stored." ) );
376 connect( btn, SIGNAL(clicked()), this, SLOT(slotOptSelectSourceListsPath()) ); 376 connect( btn, SIGNAL(clicked()), this, SLOT(slotOptSelectSourceListsPath()) );
377 layout->addWidget( btn, 9, 1 ); 377 layout->addWidget( btn, 9, 1 );
378 378
379 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); 379 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
380} 380}
381 381
382void OIpkgConfigDlg::initData() 382void OIpkgConfigDlg::initData()
383{ 383{
384 // Read ipkg configuration (server/destination/proxy) information 384 // Read ipkg configuration (server/destination/proxy) information
385 if ( m_ipkg && !m_installOptions ) 385 if ( m_ipkg && !m_installOptions )
386 { 386 {
387 m_configs = m_ipkg->configItems(); 387 m_configs = m_ipkg->configItems();
388 if ( m_configs ) 388 if ( m_configs )
389 { 389 {
390 for ( OConfItemListIterator configIt( *m_configs ); configIt.current(); ++configIt ) 390 for ( OConfItemListIterator configIt( *m_configs ); configIt.current(); ++configIt )
391 { 391 {
392 OConfItem *config = configIt.current(); 392 OConfItem *config = configIt.current();
393 393
394 // Add configuration item to the appropriate dialog controls 394 // Add configuration item to the appropriate dialog controls
395 if ( config ) 395 if ( config )
396 { 396 {
397 switch ( config->type() ) 397 switch ( config->type() )
398 { 398 {
399 case OConfItem::Source : m_serverList->insertItem( config->name() ); break; 399 case OConfItem::Source : m_serverList->insertItem( config->name() ); break;
400 case OConfItem::Destination : m_destList->insertItem( config->name() ); break; 400 case OConfItem::Destination : m_destList->insertItem( config->name() ); break;
401 case OConfItem::Option : 401 case OConfItem::Option :
402 { 402 {
403 if ( config->name() == "http_proxy" ) 403 if ( config->name() == "http_proxy" )
404 { 404 {
405 m_proxyHttpServer->setText( config->value() ); 405 m_proxyHttpServer->setText( config->value() );
406 m_proxyHttpActive->setChecked( config->active() ); 406 m_proxyHttpActive->setChecked( config->active() );
407 } 407 }
408 else if ( config->name() == "ftp_proxy" ) 408 else if ( config->name() == "ftp_proxy" )
409 { 409 {
410 m_proxyFtpServer->setText( config->value() ); 410 m_proxyFtpServer->setText( config->value() );
411 m_proxyFtpActive->setChecked( config->active() ); 411 m_proxyFtpActive->setChecked( config->active() );
412 } 412 }
413 else if ( config->name() == "proxy_username" ) 413 else if ( config->name() == "proxy_username" )
414 { 414 {
415 m_proxyUsername->setText( config->value() ); 415 m_proxyUsername->setText( config->value() );
416 } 416 }
417 else if ( config->name() == "proxy_password" ) 417 else if ( config->name() == "proxy_password" )
418 { 418 {
419 m_proxyPassword->setText( config->value() ); 419 m_proxyPassword->setText( config->value() );
420 } 420 }
421 } 421 }
422 break; 422 break;
423 case OConfItem::Other : 423 case OConfItem::Other :
424 { 424 {
425 if ( config->name() == "lists_dir" ) 425 if ( config->name() == "lists_dir" )
426 m_optSourceLists->setText( config->value() ); 426 m_optSourceLists->setText( config->value() );
427 else // TODO - use proper libipkg define 427 else // TODO - use proper libipkg define
428 m_optSourceLists->setText( "/usr/lib/ipkg/lists" ); 428 m_optSourceLists->setText( "/usr/lib/ipkg/lists" );
429 } 429 }
430 break; 430 break;
431 default : break; 431 default : break;
432 }; 432 };
433 } 433 }
434 } 434 }
435 } 435 }
436 } 436 }
437 437
438 // Get Ipkg execution options 438 // Get Ipkg execution options
439 int options = m_ipkg->ipkgExecOptions(); 439 int options = 0;
440 if ( m_ipkg )
441 options = m_ipkg->ipkgExecOptions();
440 if ( options & FORCE_DEPENDS ) 442 if ( options & FORCE_DEPENDS )
441 m_optForceDepends->setChecked( true ); 443 m_optForceDepends->setChecked( true );
442 if ( options & FORCE_REINSTALL ) 444 if ( options & FORCE_REINSTALL )
443 m_optForceReinstall->setChecked( true ); 445 m_optForceReinstall->setChecked( true );
444 if ( options & FORCE_REMOVE ) 446 if ( options & FORCE_REMOVE )
445 m_optForceRemove->setChecked( true ); 447 m_optForceRemove->setChecked( true );
446 if ( options & FORCE_OVERWRITE ) 448 if ( options & FORCE_OVERWRITE )
447 m_optForceOverwrite->setChecked( true ); 449 m_optForceOverwrite->setChecked( true );
448 if ( options & FORCE_RECURSIVE ) 450 if ( options & FORCE_RECURSIVE )
449 m_optForceRecursive->setChecked( true ); 451 m_optForceRecursive->setChecked( true );
450 if ( options & FORCE_VERBOSE_WGET ) 452 if ( options & FORCE_VERBOSE_WGET )
451 m_optVerboseWget->setChecked( true ); 453 m_optVerboseWget->setChecked( true );
452 454
453 m_optVerboseIpkg->setCurrentItem( m_ipkg->ipkgExecVerbosity() ); 455 m_optVerboseIpkg->setCurrentItem( ( m_ipkg ? m_ipkg->ipkgExecVerbosity() : 0 ) );
454} 456}
455 457
456void OIpkgConfigDlg::slotServerSelected( int index ) 458void OIpkgConfigDlg::slotServerSelected( int index )
457{ 459{
458 m_serverCurrent = index; 460 m_serverCurrent = index;
459 461
460 // Enable Edit and Delete buttons 462 // Enable Edit and Delete buttons
461 m_serverEditBtn->setEnabled( true ); 463 m_serverEditBtn->setEnabled( true );
462 m_serverDeleteBtn->setEnabled( true ); 464 m_serverDeleteBtn->setEnabled( true );
463} 465}
464 466
465void OIpkgConfigDlg::slotServerNew() 467void OIpkgConfigDlg::slotServerNew()
466{ 468{
467 OConfItem *server = new OConfItem( OConfItem::Source ); 469 OConfItem *server = new OConfItem( OConfItem::Source );
468 470
469 OIpkgServerDlg dlg( server, this ); 471 OIpkgServerDlg dlg( server, this );
470 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) 472 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted )
471 { 473 {
472 // Add to configuration option list 474 // Add to configuration option list
473 m_configs->append( server ); 475 m_configs->append( server );
474 m_configs->sort(); 476 m_configs->sort();
475 477
476 // Add to server list 478 // Add to server list
477 m_serverList->insertItem( server->name() ); 479 m_serverList->insertItem( server->name() );
478 m_serverList->setCurrentItem( m_serverList->count() ); 480 m_serverList->setCurrentItem( m_serverList->count() );
479 } 481 }
480 else 482 else
481 delete server; 483 delete server;
482} 484}
483 485
484void OIpkgConfigDlg::slotServerEdit() 486void OIpkgConfigDlg::slotServerEdit()
485{ 487{
486 // Find selected server in list 488 // Find selected server in list
487 OConfItem *server = m_ipkg->findConfItem( OConfItem::Source, m_serverList->currentText() ); 489 OConfItem *server = m_ipkg->findConfItem( OConfItem::Source, m_serverList->currentText() );
488 490
489 // Edit server 491 // Edit server
490 if ( server ) 492 if ( server )
491 { 493 {
492 QString origName = server->name(); 494 QString origName = server->name();
493 OIpkgServerDlg dlg( server, this ); 495 OIpkgServerDlg dlg( server, this );
494 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) 496 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted )
495 { 497 {
496 // Check to see if name has changed, if so update the server list 498 // Check to see if name has changed, if so update the server list
497 if ( server->name() != origName ) 499 if ( server->name() != origName )
498 m_serverList->changeItem( server->name(), m_serverCurrent ); 500 m_serverList->changeItem( server->name(), m_serverCurrent );
499 } 501 }
500 } 502 }
501} 503}
502 504
503void OIpkgConfigDlg::slotServerDelete() 505void OIpkgConfigDlg::slotServerDelete()
504{ 506{
505 // Find selected server in list 507 // Find selected server in list
506 OConfItem *server = m_ipkg->findConfItem( OConfItem::Source, m_serverList->currentText() ); 508 OConfItem *server = m_ipkg->findConfItem( OConfItem::Source, m_serverList->currentText() );
507 509
508 // Delete server 510 // Delete server
509 if ( server ) 511 if ( server )
510 { 512 {
511 m_configs->removeRef( server ); 513 m_configs->removeRef( server );
512 m_serverList->removeItem( m_serverCurrent ); 514 m_serverList->removeItem( m_serverCurrent );
513 } 515 }
514} 516}
515 517
516void OIpkgConfigDlg::slotDestSelected( int index ) 518void OIpkgConfigDlg::slotDestSelected( int index )
517{ 519{
518 m_destCurrent = index; 520 m_destCurrent = index;
519 521
520 // Enable Edit and Delete buttons 522 // Enable Edit and Delete buttons
521 m_destEditBtn->setEnabled( true ); 523 m_destEditBtn->setEnabled( true );
522 m_destDeleteBtn->setEnabled( true ); 524 m_destDeleteBtn->setEnabled( true );
523} 525}
524 526
525void OIpkgConfigDlg::slotDestNew() 527void OIpkgConfigDlg::slotDestNew()
526{ 528{
527 OConfItem *dest = new OConfItem( OConfItem::Destination ); 529 OConfItem *dest = new OConfItem( OConfItem::Destination );
528 530
529 OIpkgDestDlg dlg( dest, this ); 531 OIpkgDestDlg dlg( dest, this );
530 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) 532 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted )
531 { 533 {
532 // Add to configuration option list 534 // Add to configuration option list
533 m_configs->append( dest ); 535 m_configs->append( dest );
534 m_configs->sort(); 536 m_configs->sort();
535 537
536 // Add to destination list 538 // Add to destination list
537 m_destList->insertItem( dest->name() ); 539 m_destList->insertItem( dest->name() );
538 m_destList->setCurrentItem( m_destList->count() ); 540 m_destList->setCurrentItem( m_destList->count() );
539 } 541 }
540 else 542 else
541 delete dest; 543 delete dest;
542} 544}
543 545
544void OIpkgConfigDlg::slotDestEdit() 546void OIpkgConfigDlg::slotDestEdit()
545{ 547{
546 // Find selected destination in list 548 // Find selected destination in list
547 OConfItem *dest = m_ipkg->findConfItem( OConfItem::Destination, m_destList->currentText() ); 549 OConfItem *dest = m_ipkg->findConfItem( OConfItem::Destination, m_destList->currentText() );
548 550
549 // Edit destination 551 // Edit destination
550 if ( dest ) 552 if ( dest )
551 { 553 {
552 QString origName = dest->name(); 554 QString origName = dest->name();
553 OIpkgDestDlg dlg( dest, this ); 555 OIpkgDestDlg dlg( dest, this );
554 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) 556 if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted )
555 { 557 {
556 // Check to see if name has changed, if so update the dest list 558 // Check to see if name has changed, if so update the dest list
557 if ( dest->name() != origName ) 559 if ( dest->name() != origName )
558 m_destList->changeItem( dest->name(), m_destCurrent ); 560 m_destList->changeItem( dest->name(), m_destCurrent );
559 } 561 }
560 } 562 }
561} 563}
562 564
563void OIpkgConfigDlg::slotDestDelete() 565void OIpkgConfigDlg::slotDestDelete()
564{ 566{
565 // Find selected destination in list 567 // Find selected destination in list
566 OConfItem *destination = m_ipkg->findConfItem( OConfItem::Destination, m_destList->currentText() ); 568 OConfItem *destination = m_ipkg->findConfItem( OConfItem::Destination, m_destList->currentText() );
567 569
568 // Delete destination 570 // Delete destination
569 if ( destination ) 571 if ( destination )
570 { 572 {
571 m_configs->removeRef( destination ); 573 m_configs->removeRef( destination );
572 m_destList->removeItem( m_destCurrent ); 574 m_destList->removeItem( m_destCurrent );
573 } 575 }
574} 576}
575 577
576void OIpkgConfigDlg::slotOptSelectSourceListsPath() 578void OIpkgConfigDlg::slotOptSelectSourceListsPath()
577{ 579{
578 QString path = Opie::Ui::OFileDialog::getDirectory( 0, m_optSourceLists->text() ); 580 QString path = Opie::Ui::OFileDialog::getDirectory( 0, m_optSourceLists->text() );
579 if ( path.at( path.length() - 1 ) == '/' ) 581 if ( path.at( path.length() - 1 ) == '/' )
580 path.truncate( path.length() - 1 ); 582 path.truncate( path.length() - 1 );
581 if ( !path.isNull() ) 583 if ( !path.isNull() )
582 m_optSourceLists->setText( path ); 584 m_optSourceLists->setText( path );
583} 585}
584 586
585OIpkgServerDlg::OIpkgServerDlg( OConfItem *server, QWidget *parent ) 587OIpkgServerDlg::OIpkgServerDlg( OConfItem *server, QWidget *parent )
586 : QDialog( parent, QString::null, true, WStyle_ContextHelp ) 588 : QDialog( parent, QString::null, true, WStyle_ContextHelp )
587 , m_server( server ) 589 , m_server( server )
588{ 590{
589 setCaption( tr( "Edit Server" ) ); 591 setCaption( tr( "Edit Server" ) );
590 592
591 // Initialize UI 593 // Initialize UI
592 QVBoxLayout *layout = new QVBoxLayout( this, 2, 4 ); 594 QVBoxLayout *layout = new QVBoxLayout( this, 2, 4 );
593 595
594 m_active = new QCheckBox( tr( "Active" ), this ); 596 m_active = new QCheckBox( tr( "Active" ), this );
595 QWhatsThis::add( m_active, tr( "Tap here to indicate whether this entry is active or not." ) ); 597 QWhatsThis::add( m_active, tr( "Tap here to indicate whether this entry is active or not." ) );
596 layout->addWidget( m_active ); 598 layout->addWidget( m_active );
597 599
598 layout->addStretch(); 600 layout->addStretch();
599 601
600 QLabel *label = new QLabel( tr( "Name:" ), this ); 602 QLabel *label = new QLabel( tr( "Name:" ), this );
601 QWhatsThis::add( label, tr( "Enter the name of this entry here." ) ); 603 QWhatsThis::add( label, tr( "Enter the name of this entry here." ) );
602 layout->addWidget( label ); 604 layout->addWidget( label );
603 m_name = new QLineEdit( this ); 605 m_name = new QLineEdit( this );
604 QWhatsThis::add( m_name, tr( "Enter the name of this entry here." ) ); 606 QWhatsThis::add( m_name, tr( "Enter the name of this entry here." ) );
605 layout->addWidget( m_name ); 607 layout->addWidget( m_name );
606 608
607 layout->addStretch(); 609 layout->addStretch();
608 610
609 label = new QLabel( tr( "Address:" ), this ); 611 label = new QLabel( tr( "Address:" ), this );
610 QWhatsThis::add( label, tr( "Enter the URL address of this entry here." ) ); 612 QWhatsThis::add( label, tr( "Enter the URL address of this entry here." ) );
611 layout->addWidget( label ); 613 layout->addWidget( label );
612 m_location = new QLineEdit( this ); 614 m_location = new QLineEdit( this );
613 QWhatsThis::add( m_location, tr( "Enter the URL address of this entry here." ) ); 615 QWhatsThis::add( m_location, tr( "Enter the URL address of this entry here." ) );
614 layout->addWidget( m_location ); 616 layout->addWidget( m_location );
615 617
616 layout->addStretch(); 618 layout->addStretch();
617 619
618 m_compressed = new QCheckBox( tr( "Compressed server feed" ), this ); 620 m_compressed = new QCheckBox( tr( "Compressed server feed" ), this );
619 QWhatsThis::add( m_compressed, tr( "Tap here to indicate whether the server support compressed archives or not." ) ); 621 QWhatsThis::add( m_compressed, tr( "Tap here to indicate whether the server support compressed archives or not." ) );
620 layout->addWidget( m_compressed ); 622 layout->addWidget( m_compressed );
621 623
622 // Populate initial information 624 // Populate initial information
623 if ( m_server ) 625 if ( m_server )
624 { 626 {
625 m_name->setText( m_server->name() ); 627 m_name->setText( m_server->name() );
626 m_location->setText( m_server->value() ); 628 m_location->setText( m_server->value() );
627 m_compressed->setChecked( m_server->features().contains( "Compressed" ) ); 629 m_compressed->setChecked( m_server->features().contains( "Compressed" ) );
628 m_active->setChecked( m_server->active() ); 630 m_active->setChecked( m_server->active() );
629 } 631 }
630} 632}
631 633
632void OIpkgServerDlg::accept() 634void OIpkgServerDlg::accept()
633{ 635{
634 // Save information entered 636 // Save information entered
635 QString name = m_name->text(); 637 QString name = m_name->text();
636 name.replace( QRegExp( " " ), "_" ); 638 name.replace( QRegExp( " " ), "_" );
637 m_server->setName( name ); 639 m_server->setName( name );
638 m_server->setValue( m_location->text() ); 640 m_server->setValue( m_location->text() );
639 m_compressed->isChecked() ? m_server->setFeatures( "Compressed" ) 641 m_compressed->isChecked() ? m_server->setFeatures( "Compressed" )
640 : m_server->setFeatures( QString::null ); 642 : m_server->setFeatures( QString::null );
641 m_server->setActive( m_active->isChecked() ); 643 m_server->setActive( m_active->isChecked() );
642 644
643 QDialog::accept(); 645 QDialog::accept();
644} 646}
645 647