summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-29 01:27:31 (UTC)
committer ulf69 <ulf69>2004-10-29 01:27:31 (UTC)
commitf8dd437160acec2959c462dd43d87f2a0920c0b9 (patch) (unidiff)
treeddd271930f54adc1b7220d534f682f616efeb20a
parent1b8d173d880e8f681bca88220bdd806a95d3c2a0 (diff)
downloadkdepimpi-f8dd437160acec2959c462dd43d87f2a0920c0b9.zip
kdepimpi-f8dd437160acec2959c462dd43d87f2a0920c0b9.tar.gz
kdepimpi-f8dd437160acec2959c462dd43d87f2a0920c0b9.tar.bz2
enabling/disabling syncing of launcher
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp10
-rw-r--r--pwmanager/pwmanager/pwmdoc.h20
2 files changed, 24 insertions, 6 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index fd17ce5..9043acc 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -1487,2015 +1487,2013 @@ PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash,
1487 return e_hashNotImpl; 1487 return e_hashNotImpl;
1488 string calcHash(reinterpret_cast<const char *>(buf), 1488 string calcHash(reinterpret_cast<const char *>(buf),
1489 static_cast<string::size_type>(hashLen)); 1489 static_cast<string::size_type>(hashLen));
1490 delete [] buf; 1490 delete [] buf;
1491 if (calcHash != *dataHash) 1491 if (calcHash != *dataHash)
1492 return e_fileCorrupt; 1492 return e_fileCorrupt;
1493 break; 1493 break;
1494 } 1494 }
1495 default: 1495 default:
1496 return e_hashNotImpl; 1496 return e_hashNotImpl;
1497 } 1497 }
1498 return e_success; 1498 return e_success;
1499} 1499}
1500 1500
1501bool PwMDoc::lockAt(unsigned int category, unsigned int index, 1501bool PwMDoc::lockAt(unsigned int category, unsigned int index,
1502 bool lock) 1502 bool lock)
1503{ 1503{
1504 if (index >= numEntries(category)) { 1504 if (index >= numEntries(category)) {
1505 BUG(); 1505 BUG();
1506 return false; 1506 return false;
1507 } 1507 }
1508 if (lock == dti.dta[category].d[index].lockStat) 1508 if (lock == dti.dta[category].d[index].lockStat)
1509 return true; 1509 return true;
1510 1510
1511 if (!lock && currentPw != "") { 1511 if (!lock && currentPw != "") {
1512 // "unlocking" and "password is already set" 1512 // "unlocking" and "password is already set"
1513 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { 1513 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1514 // unlocking without pw not allowed 1514 // unlocking without pw not allowed
1515 QString pw; 1515 QString pw;
1516 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1516 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1517 if (pw != "") { 1517 if (pw != "") {
1518 if (pw != currentPw) { 1518 if (pw != currentPw) {
1519 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1519 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1520 return false; 1520 return false;
1521 } else { 1521 } else {
1522 timer()->start(DocTimer::id_mpwTimer); 1522 timer()->start(DocTimer::id_mpwTimer);
1523 } 1523 }
1524 } else { 1524 } else {
1525 return false; 1525 return false;
1526 } 1526 }
1527 } else { 1527 } else {
1528 timer()->start(DocTimer::id_mpwTimer); 1528 timer()->start(DocTimer::id_mpwTimer);
1529 } 1529 }
1530 } 1530 }
1531 1531
1532 dti.dta[category].d[index].lockStat = lock; 1532 dti.dta[category].d[index].lockStat = lock;
1533 dti.dta[category].d[index].rev++; // increment revision counter. 1533 dti.dta[category].d[index].rev++; // increment revision counter.
1534 1534
1535 emitDataChanged(this); 1535 emitDataChanged(this);
1536 if (!lock) 1536 if (!lock)
1537 timer()->start(DocTimer::id_autoLockTimer); 1537 timer()->start(DocTimer::id_autoLockTimer);
1538 1538
1539 return true; 1539 return true;
1540 1540
1541} 1541}
1542 1542
1543bool PwMDoc::lockAt(const QString &category,unsigned int index, 1543bool PwMDoc::lockAt(const QString &category,unsigned int index,
1544 bool lock) 1544 bool lock)
1545{ 1545{
1546 unsigned int cat = 0; 1546 unsigned int cat = 0;
1547 1547
1548 if (!findCategory(category, &cat)) { 1548 if (!findCategory(category, &cat)) {
1549 BUG(); 1549 BUG();
1550 return false; 1550 return false;
1551 } 1551 }
1552 1552
1553 return lockAt(cat, index, lock); 1553 return lockAt(cat, index, lock);
1554} 1554}
1555 1555
1556bool PwMDoc::lockAll(bool lock) 1556bool PwMDoc::lockAll(bool lock)
1557{ 1557{
1558 if (!lock && isDeepLocked()) { 1558 if (!lock && isDeepLocked()) {
1559 PwMerror ret; 1559 PwMerror ret;
1560 ret = deepLock(false); 1560 ret = deepLock(false);
1561 if (ret != e_success) 1561 if (ret != e_success)
1562 return false; 1562 return false;
1563 return true; 1563 return true;
1564 } 1564 }
1565 if (isDocEmpty()) { 1565 if (isDocEmpty()) {
1566 return true; 1566 return true;
1567 } 1567 }
1568 if (!lock && currentPw != "") { 1568 if (!lock && currentPw != "") {
1569 // unlocking and password is already set 1569 // unlocking and password is already set
1570 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { 1570 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1571 // unlocking without pw not allowed 1571 // unlocking without pw not allowed
1572 QString pw; 1572 QString pw;
1573 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1573 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1574 if (pw != "") { 1574 if (pw != "") {
1575 if (pw != currentPw) { 1575 if (pw != currentPw) {
1576 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1576 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1577 return false; 1577 return false;
1578 } else { 1578 } else {
1579 timer()->start(DocTimer::id_mpwTimer); 1579 timer()->start(DocTimer::id_mpwTimer);
1580 } 1580 }
1581 } else { 1581 } else {
1582 return false; 1582 return false;
1583 } 1583 }
1584 } else { 1584 } else {
1585 timer()->start(DocTimer::id_mpwTimer); 1585 timer()->start(DocTimer::id_mpwTimer);
1586 } 1586 }
1587 } 1587 }
1588 1588
1589 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1589 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1590 catEnd = dti.dta.end(), 1590 catEnd = dti.dta.end(),
1591 catI = catBegin; 1591 catI = catBegin;
1592 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1592 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1593 while (catI != catEnd) { 1593 while (catI != catEnd) {
1594 entrBegin = catI->d.begin(); 1594 entrBegin = catI->d.begin();
1595 entrEnd = catI->d.end(); 1595 entrEnd = catI->d.end();
1596 entrI = entrBegin; 1596 entrI = entrBegin;
1597 while (entrI != entrEnd) { 1597 while (entrI != entrEnd) {
1598 entrI->lockStat = lock; 1598 entrI->lockStat = lock;
1599 entrI->rev++; // increment revision counter. 1599 entrI->rev++; // increment revision counter.
1600 ++entrI; 1600 ++entrI;
1601 } 1601 }
1602 ++catI; 1602 ++catI;
1603 } 1603 }
1604 1604
1605 emitDataChanged(this); 1605 emitDataChanged(this);
1606 if (lock) 1606 if (lock)
1607 timer()->stop(DocTimer::id_autoLockTimer); 1607 timer()->stop(DocTimer::id_autoLockTimer);
1608 else 1608 else
1609 timer()->start(DocTimer::id_autoLockTimer); 1609 timer()->start(DocTimer::id_autoLockTimer);
1610 1610
1611 return true; 1611 return true;
1612} 1612}
1613 1613
1614bool PwMDoc::isLocked(const QString &category, unsigned int index) 1614bool PwMDoc::isLocked(const QString &category, unsigned int index)
1615{ 1615{
1616 unsigned int cat = 0; 1616 unsigned int cat = 0;
1617 1617
1618 if (!findCategory(category, &cat)) { 1618 if (!findCategory(category, &cat)) {
1619 BUG(); 1619 BUG();
1620 return false; 1620 return false;
1621 } 1621 }
1622 1622
1623 return isLocked(cat, index); 1623 return isLocked(cat, index);
1624} 1624}
1625 1625
1626bool PwMDoc::unlockAll_tempoary(bool revert) 1626bool PwMDoc::unlockAll_tempoary(bool revert)
1627{ 1627{
1628 static vector< vector<bool> > *oldLockStates = 0; 1628 static vector< vector<bool> > *oldLockStates = 0;
1629 static bool wasDeepLocked; 1629 static bool wasDeepLocked;
1630 1630
1631 if (revert) {// revert the unlocking 1631 if (revert) {// revert the unlocking
1632 if (oldLockStates) { 1632 if (oldLockStates) {
1633 /* we actually _have_ unlocked something, because 1633 /* we actually _have_ unlocked something, because
1634 * we have allocated space for the oldLockStates. 1634 * we have allocated space for the oldLockStates.
1635 * So, go on and revert them! 1635 * So, go on and revert them!
1636 */ 1636 */
1637 if (wasDeepLocked) { 1637 if (wasDeepLocked) {
1638 PwMerror ret = deepLock(true); 1638 PwMerror ret = deepLock(true);
1639 if (ret == e_success) { 1639 if (ret == e_success) {
1640 /* deep-lock succeed. We are save. 1640 /* deep-lock succeed. We are save.
1641 * (but if it failed, just go on 1641 * (but if it failed, just go on
1642 * lock them normally) 1642 * lock them normally)
1643 */ 1643 */
1644 delete_and_null(oldLockStates); 1644 delete_and_null(oldLockStates);
1645 timer()->start(DocTimer::id_autoLockTimer); 1645 timer()->start(DocTimer::id_autoLockTimer);
1646 printDebug("tempoary unlocking of dta " 1646 printDebug("tempoary unlocking of dta "
1647 "reverted by deep-locking."); 1647 "reverted by deep-locking.");
1648 return true; 1648 return true;
1649 } 1649 }
1650 printDebug("deep-lock failed while reverting! " 1650 printDebug("deep-lock failed while reverting! "
1651 "Falling back to normal-lock."); 1651 "Falling back to normal-lock.");
1652 } 1652 }
1653 if (unlikely(!wasDeepLocked && 1653 if (unlikely(!wasDeepLocked &&
1654 numCategories() != oldLockStates->size())) { 1654 numCategories() != oldLockStates->size())) {
1655 /* DOH! We have modified "dta" while 1655 /* DOH! We have modified "dta" while
1656 * it was unlocked tempoary. DON'T DO THIS! 1656 * it was unlocked tempoary. DON'T DO THIS!
1657 */ 1657 */
1658 BUG(); 1658 BUG();
1659 delete_and_null(oldLockStates); 1659 delete_and_null(oldLockStates);
1660 timer()->start(DocTimer::id_autoLockTimer); 1660 timer()->start(DocTimer::id_autoLockTimer);
1661 return false; 1661 return false;
1662 } 1662 }
1663 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1663 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1664 catEnd = dti.dta.end(), 1664 catEnd = dti.dta.end(),
1665 catI = catBegin; 1665 catI = catBegin;
1666 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1666 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1667 vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); 1667 vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin();
1668 vector<bool>::iterator oldEntrStatBegin, 1668 vector<bool>::iterator oldEntrStatBegin,
1669 oldEntrStatEnd, 1669 oldEntrStatEnd,
1670 oldEntrStatI; 1670 oldEntrStatI;
1671 while (catI != catEnd) { 1671 while (catI != catEnd) {
1672 entrBegin = catI->d.begin(); 1672 entrBegin = catI->d.begin();
1673 entrEnd = catI->d.end(); 1673 entrEnd = catI->d.end();
1674 entrI = entrBegin; 1674 entrI = entrBegin;
1675 if (likely(!wasDeepLocked)) { 1675 if (likely(!wasDeepLocked)) {
1676 oldEntrStatBegin = oldCatStatI->begin(); 1676 oldEntrStatBegin = oldCatStatI->begin();
1677 oldEntrStatEnd = oldCatStatI->end(); 1677 oldEntrStatEnd = oldCatStatI->end();
1678 oldEntrStatI = oldEntrStatBegin; 1678 oldEntrStatI = oldEntrStatBegin;
1679 if (unlikely(catI->d.size() != oldCatStatI->size())) { 1679 if (unlikely(catI->d.size() != oldCatStatI->size())) {
1680 /* DOH! We have modified "dta" while 1680 /* DOH! We have modified "dta" while
1681 * it was unlocked tempoary. DON'T DO THIS! 1681 * it was unlocked tempoary. DON'T DO THIS!
1682 */ 1682 */
1683 BUG(); 1683 BUG();
1684 delete_and_null(oldLockStates); 1684 delete_and_null(oldLockStates);
1685 timer()->start(DocTimer::id_autoLockTimer); 1685 timer()->start(DocTimer::id_autoLockTimer);
1686 return false; 1686 return false;
1687 } 1687 }
1688 } 1688 }
1689 while (entrI != entrEnd) { 1689 while (entrI != entrEnd) {
1690 if (wasDeepLocked) { 1690 if (wasDeepLocked) {
1691 /* this is an error-fallback if 1691 /* this is an error-fallback if
1692 * deeplock didn't succeed 1692 * deeplock didn't succeed
1693 */ 1693 */
1694 entrI->lockStat = true; 1694 entrI->lockStat = true;
1695 } else { 1695 } else {
1696 entrI->lockStat = *oldEntrStatI; 1696 entrI->lockStat = *oldEntrStatI;
1697 } 1697 }
1698 ++entrI; 1698 ++entrI;
1699 if (likely(!wasDeepLocked)) 1699 if (likely(!wasDeepLocked))
1700 ++oldEntrStatI; 1700 ++oldEntrStatI;
1701 } 1701 }
1702 ++catI; 1702 ++catI;
1703 if (likely(!wasDeepLocked)) 1703 if (likely(!wasDeepLocked))
1704 ++oldCatStatI; 1704 ++oldCatStatI;
1705 } 1705 }
1706 delete_and_null(oldLockStates); 1706 delete_and_null(oldLockStates);
1707 if (unlikely(wasDeepLocked)) { 1707 if (unlikely(wasDeepLocked)) {
1708 /* error fallback... */ 1708 /* error fallback... */
1709 unsetDocStatFlag(DOC_STAT_DEEPLOCKED); 1709 unsetDocStatFlag(DOC_STAT_DEEPLOCKED);
1710 emitDataChanged(this); 1710 emitDataChanged(this);
1711 printDebug("WARNING: unlockAll_tempoary(true) " 1711 printDebug("WARNING: unlockAll_tempoary(true) "
1712 "deeplock fallback!"); 1712 "deeplock fallback!");
1713 } 1713 }
1714 printDebug("tempoary unlocking of dta reverted."); 1714 printDebug("tempoary unlocking of dta reverted.");
1715 } else { 1715 } else {
1716 printDebug("unlockAll_tempoary(true): nothing to do."); 1716 printDebug("unlockAll_tempoary(true): nothing to do.");
1717 } 1717 }
1718 timer()->start(DocTimer::id_autoLockTimer); 1718 timer()->start(DocTimer::id_autoLockTimer);
1719 } else {// unlock all data tempoary 1719 } else {// unlock all data tempoary
1720 if (unlikely(oldLockStates != 0)) { 1720 if (unlikely(oldLockStates != 0)) {
1721 /* DOH! We have already unlocked the data tempoarly. 1721 /* DOH! We have already unlocked the data tempoarly.
1722 * No need to do it twice. ;) 1722 * No need to do it twice. ;)
1723 */ 1723 */
1724 BUG(); 1724 BUG();
1725 return false; 1725 return false;
1726 } 1726 }
1727 wasDeepLocked = false; 1727 wasDeepLocked = false;
1728 bool mustUnlock = false; 1728 bool mustUnlock = false;
1729 if (isDeepLocked()) { 1729 if (isDeepLocked()) {
1730 PwMerror ret; 1730 PwMerror ret;
1731 while (1) { 1731 while (1) {
1732 ret = deepLock(false); 1732 ret = deepLock(false);
1733 if (ret == e_success) { 1733 if (ret == e_success) {
1734 break; 1734 break;
1735 } else if (ret == e_wrongPw) { 1735 } else if (ret == e_wrongPw) {
1736 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1736 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1737 } else { 1737 } else {
1738 printDebug("deep-unlocking failed while " 1738 printDebug("deep-unlocking failed while "
1739 "tempoary unlocking!"); 1739 "tempoary unlocking!");
1740 return false; 1740 return false;
1741 } 1741 }
1742 } 1742 }
1743 wasDeepLocked = true; 1743 wasDeepLocked = true;
1744 mustUnlock = true; 1744 mustUnlock = true;
1745 } else { 1745 } else {
1746 // first check if it's needed to unlock some entries 1746 // first check if it's needed to unlock some entries
1747 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1747 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1748 catEnd = dti.dta.end(), 1748 catEnd = dti.dta.end(),
1749 catI = catBegin; 1749 catI = catBegin;
1750 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1750 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1751 while (catI != catEnd) { 1751 while (catI != catEnd) {
1752 entrBegin = catI->d.begin(); 1752 entrBegin = catI->d.begin();
1753 entrEnd = catI->d.end(); 1753 entrEnd = catI->d.end();
1754 entrI = entrBegin; 1754 entrI = entrBegin;
1755 while (entrI != entrEnd) { 1755 while (entrI != entrEnd) {
1756 if (entrI->lockStat == true) { 1756 if (entrI->lockStat == true) {
1757 mustUnlock = true; 1757 mustUnlock = true;
1758 break; 1758 break;
1759 } 1759 }
1760 ++entrI; 1760 ++entrI;
1761 } 1761 }
1762 if (mustUnlock) 1762 if (mustUnlock)
1763 break; 1763 break;
1764 ++catI; 1764 ++catI;
1765 } 1765 }
1766 } 1766 }
1767 if (!mustUnlock) { 1767 if (!mustUnlock) {
1768 // nothing to do. 1768 // nothing to do.
1769 timer()->stop(DocTimer::id_autoLockTimer); 1769 timer()->stop(DocTimer::id_autoLockTimer);
1770 printDebug("unlockAll_tempoary(): nothing to do."); 1770 printDebug("unlockAll_tempoary(): nothing to do.");
1771 return true; 1771 return true;
1772 } else if (!wasDeepLocked) { 1772 } else if (!wasDeepLocked) {
1773 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && 1773 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) &&
1774 currentPw != "") { 1774 currentPw != "") {
1775 /* we can't unlock without mpw, so 1775 /* we can't unlock without mpw, so
1776 * we need to ask for it. 1776 * we need to ask for it.
1777 */ 1777 */
1778 QString pw; 1778 QString pw;
1779 while (1) { 1779 while (1) {
1780 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1780 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1781 if (pw == "") { 1781 if (pw == "") {
1782 return false; 1782 return false;
1783 } else if (pw == currentPw) { 1783 } else if (pw == currentPw) {
1784 break; 1784 break;
1785 } 1785 }
1786 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1786 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1787 } 1787 }
1788 } 1788 }
1789 } 1789 }
1790 timer()->stop(DocTimer::id_autoLockTimer); 1790 timer()->stop(DocTimer::id_autoLockTimer);
1791 oldLockStates = new vector< vector<bool> >; 1791 oldLockStates = new vector< vector<bool> >;
1792 vector<bool> tmp_vec; 1792 vector<bool> tmp_vec;
1793 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1793 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1794 catEnd = dti.dta.end(), 1794 catEnd = dti.dta.end(),
1795 catI = catBegin; 1795 catI = catBegin;
1796 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1796 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1797 while (catI != catEnd) { 1797 while (catI != catEnd) {
1798 entrBegin = catI->d.begin(); 1798 entrBegin = catI->d.begin();
1799 entrEnd = catI->d.end(); 1799 entrEnd = catI->d.end();
1800 entrI = entrBegin; 1800 entrI = entrBegin;
1801 while (entrI != entrEnd) { 1801 while (entrI != entrEnd) {
1802 if (!wasDeepLocked) { 1802 if (!wasDeepLocked) {
1803 tmp_vec.push_back(entrI->lockStat); 1803 tmp_vec.push_back(entrI->lockStat);
1804 } 1804 }
1805 entrI->lockStat = false; 1805 entrI->lockStat = false;
1806 ++entrI; 1806 ++entrI;
1807 } 1807 }
1808 if (!wasDeepLocked) { 1808 if (!wasDeepLocked) {
1809 oldLockStates->push_back(tmp_vec); 1809 oldLockStates->push_back(tmp_vec);
1810 tmp_vec.clear(); 1810 tmp_vec.clear();
1811 } 1811 }
1812 ++catI; 1812 ++catI;
1813 } 1813 }
1814 printDebug("tempoary unlocked dta."); 1814 printDebug("tempoary unlocked dta.");
1815 } 1815 }
1816 1816
1817 return true; 1817 return true;
1818} 1818}
1819 1819
1820PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) 1820PwMerror PwMDoc::deepLock(bool lock, bool saveToFile)
1821{ 1821{
1822 PwMerror ret; 1822 PwMerror ret;
1823 /* NOTE: saveDoc() depends on this function to return 1823 /* NOTE: saveDoc() depends on this function to return
1824 * e_success if saveToFile == false 1824 * e_success if saveToFile == false
1825 */ 1825 */
1826 1826
1827 if (lock) { 1827 if (lock) {
1828 if (isDeepLocked()) 1828 if (isDeepLocked())
1829 return e_lock; 1829 return e_lock;
1830 if (saveToFile) { 1830 if (saveToFile) {
1831 if (isDocEmpty()) 1831 if (isDocEmpty())
1832 return e_docIsEmpty; 1832 return e_docIsEmpty;
1833 ret = saveDoc(conf()->confGlobCompression()); 1833 ret = saveDoc(conf()->confGlobCompression());
1834 if (ret == e_filename) { 1834 if (ret == e_filename) {
1835 /* the doc wasn't saved to a file 1835 /* the doc wasn't saved to a file
1836 * by the user, yet. 1836 * by the user, yet.
1837 */ 1837 */
1838 cantDeeplock_notSavedMsgBox(); 1838 cantDeeplock_notSavedMsgBox();
1839 return e_docNotSaved; 1839 return e_docNotSaved;
1840 } else if (ret != e_success) { 1840 } else if (ret != e_success) {
1841 return e_lock; 1841 return e_lock;
1842 } 1842 }
1843 } 1843 }
1844 timer()->stop(DocTimer::id_autoLockTimer); 1844 timer()->stop(DocTimer::id_autoLockTimer);
1845 clearDoc(); 1845 clearDoc();
1846 PwMDataItem d; 1846 PwMDataItem d;
1847 d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); 1847 d.desc = IS_DEEPLOCKED_SHORTMSG.latin1();
1848 d.comment = IS_DEEPLOCKED_MSG.latin1(); 1848 d.comment = IS_DEEPLOCKED_MSG.latin1();
1849 d.listViewPos = 0; 1849 d.listViewPos = 0;
1850 addEntry(DEFAULT_CATEGORY, &d, true); 1850 addEntry(DEFAULT_CATEGORY, &d, true);
1851 lockAt(DEFAULT_CATEGORY, 0, true); 1851 lockAt(DEFAULT_CATEGORY, 0, true);
1852 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 1852 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
1853 setDocStatFlag(DOC_STAT_DEEPLOCKED); 1853 setDocStatFlag(DOC_STAT_DEEPLOCKED);
1854 } else { 1854 } else {
1855 if (!isDeepLocked()) 1855 if (!isDeepLocked())
1856 return e_lock; 1856 return e_lock;
1857 ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) 1857 ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen())
1858 ? 0 : 1); 1858 ? 0 : 1);
1859 if (ret == e_wrongPw) { 1859 if (ret == e_wrongPw) {
1860 return e_wrongPw; 1860 return e_wrongPw;
1861 } else if (ret != e_success) { 1861 } else if (ret != e_success) {
1862 printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") 1862 printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ")
1863 + tostr(static_cast<int>(ret))); 1863 + tostr(static_cast<int>(ret)));
1864 return e_lock; 1864 return e_lock;
1865 } 1865 }
1866 unsetDocStatFlag(DOC_STAT_DEEPLOCKED); 1866 unsetDocStatFlag(DOC_STAT_DEEPLOCKED);
1867 timer()->start(DocTimer::id_autoLockTimer); 1867 timer()->start(DocTimer::id_autoLockTimer);
1868 } 1868 }
1869 1869
1870 emitDataChanged(this); 1870 emitDataChanged(this);
1871 return e_success; 1871 return e_success;
1872} 1872}
1873 1873
1874void PwMDoc::_deepUnlock() 1874void PwMDoc::_deepUnlock()
1875{ 1875{
1876 deepLock(false); 1876 deepLock(false);
1877} 1877}
1878 1878
1879void PwMDoc::clearDoc() 1879void PwMDoc::clearDoc()
1880{ 1880{
1881 dti.clear(); 1881 dti.clear();
1882 PwMCategoryItem d; 1882 PwMCategoryItem d;
1883 d.name = DEFAULT_CATEGORY.latin1(); 1883 d.name = DEFAULT_CATEGORY.latin1();
1884 dti.dta.push_back(d); 1884 dti.dta.push_back(d);
1885 currentPw = ""; 1885 currentPw = "";
1886 unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 1886 unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
1887} 1887}
1888 1888
1889void PwMDoc::changeCurrentPw() 1889void PwMDoc::changeCurrentPw()
1890{ 1890{
1891 if (currentPw == "") 1891 if (currentPw == "")
1892 return; // doc hasn't been saved. No mpw available. 1892 return; // doc hasn't been saved. No mpw available.
1893 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); 1893 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD);
1894 QString pw = requestMpwChange(&currentPw, &useChipcard); 1894 QString pw = requestMpwChange(&currentPw, &useChipcard);
1895 if (pw == "") 1895 if (pw == "")
1896 return; 1896 return;
1897 if (useChipcard) 1897 if (useChipcard)
1898 setDocStatFlag(DOC_STAT_USE_CHIPCARD); 1898 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
1899 else 1899 else
1900 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); 1900 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
1901 setCurrentPw(pw); 1901 setCurrentPw(pw);
1902} 1902}
1903 1903
1904void PwMDoc::setListViewPos(const QString &category, unsigned int index, 1904void PwMDoc::setListViewPos(const QString &category, unsigned int index,
1905 int pos) 1905 int pos)
1906{ 1906{
1907 unsigned int cat = 0; 1907 unsigned int cat = 0;
1908 1908
1909 if (!findCategory(category, &cat)) { 1909 if (!findCategory(category, &cat)) {
1910 BUG(); 1910 BUG();
1911 return; 1911 return;
1912 } 1912 }
1913 setListViewPos(cat, index, pos); 1913 setListViewPos(cat, index, pos);
1914} 1914}
1915 1915
1916void PwMDoc::setListViewPos(unsigned int category, unsigned int index, 1916void PwMDoc::setListViewPos(unsigned int category, unsigned int index,
1917 int pos) 1917 int pos)
1918{ 1918{
1919 dti.dta[category].d[index].listViewPos = pos; 1919 dti.dta[category].d[index].listViewPos = pos;
1920 1920
1921/* FIXME workaround: don't flag dirty, because this function sometimes 1921/* FIXME workaround: don't flag dirty, because this function sometimes
1922 * get's called when it shouldn't. It's because PwMView assumes 1922 * get's called when it shouldn't. It's because PwMView assumes
1923 * the user resorted the UI on behalf of signal layoutChanged(). 1923 * the user resorted the UI on behalf of signal layoutChanged().
1924 * This is somewhat broken and incorrect, but I've no other 1924 * This is somewhat broken and incorrect, but I've no other
1925 * solution for now. 1925 * solution for now.
1926 */ 1926 */
1927 //setDocStatFlag(DOC_STAT_DISK_DIRTY); 1927 //setDocStatFlag(DOC_STAT_DISK_DIRTY);
1928} 1928}
1929 1929
1930int PwMDoc::getListViewPos(const QString &category, unsigned int index) 1930int PwMDoc::getListViewPos(const QString &category, unsigned int index)
1931{ 1931{
1932 unsigned int cat = 0; 1932 unsigned int cat = 0;
1933 1933
1934 if (!findCategory(category, &cat)) { 1934 if (!findCategory(category, &cat)) {
1935 BUG(); 1935 BUG();
1936 return -1; 1936 return -1;
1937 } 1937 }
1938 1938
1939 return dti.dta[cat].d[index].listViewPos; 1939 return dti.dta[cat].d[index].listViewPos;
1940} 1940}
1941 1941
1942void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, 1942void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
1943 vector<unsigned int> *foundPositions, bool breakAfterFound, 1943 vector<unsigned int> *foundPositions, bool breakAfterFound,
1944 bool caseSensitive, bool exactWordMatch, bool sortByLvp) 1944 bool caseSensitive, bool exactWordMatch, bool sortByLvp)
1945{ 1945{
1946 PWM_ASSERT(foundPositions); 1946 PWM_ASSERT(foundPositions);
1947 PWM_ASSERT(searchIn); 1947 PWM_ASSERT(searchIn);
1948 foundPositions->clear(); 1948 foundPositions->clear();
1949 1949
1950 unsigned int i, entries = numEntries(category); 1950 unsigned int i, entries = numEntries(category);
1951 for (i = 0; i < entries; ++i) { 1951 for (i = 0; i < entries; ++i) {
1952 if (searchIn & SEARCH_IN_DESC) { 1952 if (searchIn & SEARCH_IN_DESC) {
1953 if (!compareString(find.desc, dti.dta[category].d[i].desc, 1953 if (!compareString(find.desc, dti.dta[category].d[i].desc,
1954 caseSensitive, exactWordMatch)) { 1954 caseSensitive, exactWordMatch)) {
1955 continue; 1955 continue;
1956 } 1956 }
1957 } 1957 }
1958 if (searchIn & SEARCH_IN_NAME) { 1958 if (searchIn & SEARCH_IN_NAME) {
1959 if (!compareString(find.name, dti.dta[category].d[i].name, 1959 if (!compareString(find.name, dti.dta[category].d[i].name,
1960 caseSensitive, exactWordMatch)) { 1960 caseSensitive, exactWordMatch)) {
1961 continue; 1961 continue;
1962 } 1962 }
1963 } 1963 }
1964 if (searchIn & SEARCH_IN_PW) { 1964 if (searchIn & SEARCH_IN_PW) {
1965 bool wasLocked = isLocked(category, i); 1965 bool wasLocked = isLocked(category, i);
1966 getDataChangedLock(); 1966 getDataChangedLock();
1967 lockAt(category, i, false); 1967 lockAt(category, i, false);
1968 if (!compareString(find.pw, dti.dta[category].d[i].pw, 1968 if (!compareString(find.pw, dti.dta[category].d[i].pw,
1969 caseSensitive, exactWordMatch)) { 1969 caseSensitive, exactWordMatch)) {
1970 lockAt(category, i, wasLocked); 1970 lockAt(category, i, wasLocked);
1971 putDataChangedLock(); 1971 putDataChangedLock();
1972 continue; 1972 continue;
1973 } 1973 }
1974 lockAt(category, i, wasLocked); 1974 lockAt(category, i, wasLocked);
1975 putDataChangedLock(); 1975 putDataChangedLock();
1976 } 1976 }
1977 if (searchIn & SEARCH_IN_COMMENT) { 1977 if (searchIn & SEARCH_IN_COMMENT) {
1978 if (!compareString(find.comment, dti.dta[category].d[i].comment, 1978 if (!compareString(find.comment, dti.dta[category].d[i].comment,
1979 caseSensitive, exactWordMatch)) { 1979 caseSensitive, exactWordMatch)) {
1980 continue; 1980 continue;
1981 } 1981 }
1982 } 1982 }
1983 if (searchIn & SEARCH_IN_URL) { 1983 if (searchIn & SEARCH_IN_URL) {
1984 if (!compareString(find.url, dti.dta[category].d[i].url, 1984 if (!compareString(find.url, dti.dta[category].d[i].url,
1985 caseSensitive, exactWordMatch)) { 1985 caseSensitive, exactWordMatch)) {
1986 continue; 1986 continue;
1987 } 1987 }
1988 } 1988 }
1989 if (searchIn & SEARCH_IN_LAUNCHER) { 1989 if (searchIn & SEARCH_IN_LAUNCHER) {
1990 if (!compareString(find.launcher, dti.dta[category].d[i].launcher, 1990 if (!compareString(find.launcher, dti.dta[category].d[i].launcher,
1991 caseSensitive, exactWordMatch)) { 1991 caseSensitive, exactWordMatch)) {
1992 continue; 1992 continue;
1993 } 1993 }
1994 } 1994 }
1995 1995
1996 // all selected "searchIn" matched. 1996 // all selected "searchIn" matched.
1997 foundPositions->push_back(i); 1997 foundPositions->push_back(i);
1998 if (breakAfterFound) 1998 if (breakAfterFound)
1999 break; 1999 break;
2000 } 2000 }
2001 2001
2002 if (sortByLvp && foundPositions->size() > 1) { 2002 if (sortByLvp && foundPositions->size() > 1) {
2003 vector< pair<unsigned int /* foundPosition (real doc pos) */, 2003 vector< pair<unsigned int /* foundPosition (real doc pos) */,
2004 unsigned int /* lvp-pos */> > tmp_vec; 2004 unsigned int /* lvp-pos */> > tmp_vec;
2005 2005
2006 unsigned int i, items = foundPositions->size(); 2006 unsigned int i, items = foundPositions->size();
2007 pair<unsigned int, unsigned int> tmp_pair; 2007 pair<unsigned int, unsigned int> tmp_pair;
2008 for (i = 0; i < items; ++i) { 2008 for (i = 0; i < items; ++i) {
2009 tmp_pair.first = (*foundPositions)[i]; 2009 tmp_pair.first = (*foundPositions)[i];
2010 tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; 2010 tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos;
2011 tmp_vec.push_back(tmp_pair); 2011 tmp_vec.push_back(tmp_pair);
2012 } 2012 }
2013 sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); 2013 sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater());
2014 foundPositions->clear(); 2014 foundPositions->clear();
2015 for (i = 0; i < items; ++i) { 2015 for (i = 0; i < items; ++i) {
2016 foundPositions->push_back(tmp_vec[i].first); 2016 foundPositions->push_back(tmp_vec[i].first);
2017 } 2017 }
2018 } 2018 }
2019} 2019}
2020 2020
2021void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, 2021void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
2022 vector<unsigned int> *foundPositions, bool breakAfterFound, 2022 vector<unsigned int> *foundPositions, bool breakAfterFound,
2023 bool caseSensitive, bool exactWordMatch, bool sortByLvp) 2023 bool caseSensitive, bool exactWordMatch, bool sortByLvp)
2024{ 2024{
2025 PWM_ASSERT(foundPositions); 2025 PWM_ASSERT(foundPositions);
2026 unsigned int cat = 0; 2026 unsigned int cat = 0;
2027 2027
2028 if (!findCategory(category, &cat)) { 2028 if (!findCategory(category, &cat)) {
2029 foundPositions->clear(); 2029 foundPositions->clear();
2030 return; 2030 return;
2031 } 2031 }
2032 2032
2033 findEntry(cat, find, searchIn, foundPositions, breakAfterFound, 2033 findEntry(cat, find, searchIn, foundPositions, breakAfterFound,
2034 caseSensitive, exactWordMatch, sortByLvp); 2034 caseSensitive, exactWordMatch, sortByLvp);
2035} 2035}
2036 2036
2037bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, 2037bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive,
2038 bool exactWordMatch) 2038 bool exactWordMatch)
2039{ 2039{
2040 QString _s1(s1.c_str()); 2040 QString _s1(s1.c_str());
2041 QString _s2(s2.c_str()); 2041 QString _s2(s2.c_str());
2042 if (!caseSensitive) { 2042 if (!caseSensitive) {
2043 _s1 = _s1.lower(); 2043 _s1 = _s1.lower();
2044 _s2 = _s2.lower(); 2044 _s2 = _s2.lower();
2045 } 2045 }
2046 if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) 2046 if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1))
2047 return true; 2047 return true;
2048 return false; 2048 return false;
2049} 2049}
2050 2050
2051bool PwMDoc::findCategory(const QString &name, unsigned int *index) 2051bool PwMDoc::findCategory(const QString &name, unsigned int *index)
2052{ 2052{
2053 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2053 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2054 end = dti.dta.end(); 2054 end = dti.dta.end();
2055 while (i != end) { 2055 while (i != end) {
2056 if ((*i).name == name.latin1()) { 2056 if ((*i).name == name.latin1()) {
2057 if (index) { 2057 if (index) {
2058 *index = i - dti.dta.begin(); 2058 *index = i - dti.dta.begin();
2059 } 2059 }
2060 return true; 2060 return true;
2061 } 2061 }
2062 ++i; 2062 ++i;
2063 } 2063 }
2064 return false; 2064 return false;
2065} 2065}
2066 2066
2067bool PwMDoc::renameCategory(const QString &category, const QString &newName) 2067bool PwMDoc::renameCategory(const QString &category, const QString &newName)
2068{ 2068{
2069 unsigned int cat = 0; 2069 unsigned int cat = 0;
2070 2070
2071 if (!findCategory(category, &cat)) 2071 if (!findCategory(category, &cat))
2072 return false; 2072 return false;
2073 2073
2074 return renameCategory(cat, newName); 2074 return renameCategory(cat, newName);
2075} 2075}
2076 2076
2077bool PwMDoc::renameCategory(unsigned int category, const QString &newName, 2077bool PwMDoc::renameCategory(unsigned int category, const QString &newName,
2078 bool dontFlagDirty) 2078 bool dontFlagDirty)
2079{ 2079{
2080 if (category > numCategories() - 1) 2080 if (category > numCategories() - 1)
2081 return false; 2081 return false;
2082 2082
2083 dti.dta[category].name = newName.latin1(); 2083 dti.dta[category].name = newName.latin1();
2084 if (!dontFlagDirty) 2084 if (!dontFlagDirty)
2085 flagDirty(); 2085 flagDirty();
2086 2086
2087 return true; 2087 return true;
2088} 2088}
2089 2089
2090bool PwMDoc::delCategory(const QString &category) 2090bool PwMDoc::delCategory(const QString &category)
2091{ 2091{
2092 unsigned int cat = 0; 2092 unsigned int cat = 0;
2093 2093
2094 if (!findCategory(category, &cat)) 2094 if (!findCategory(category, &cat))
2095 return false; 2095 return false;
2096 2096
2097 return delCategory(cat); 2097 return delCategory(cat);
2098} 2098}
2099 2099
2100bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) 2100bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty)
2101{ 2101{
2102 if (category > numCategories() - 1) 2102 if (category > numCategories() - 1)
2103 return false; 2103 return false;
2104 2104
2105 // We don't delete it, if it is the last existing 2105 // We don't delete it, if it is the last existing
2106 // category! Instead we rename it to "Default". 2106 // category! Instead we rename it to "Default".
2107 if (numCategories() > 1) { 2107 if (numCategories() > 1) {
2108 dti.dta.erase(dti.dta.begin() + category); 2108 dti.dta.erase(dti.dta.begin() + category);
2109 } else { 2109 } else {
2110 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); 2110 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty);
2111 return true; 2111 return true;
2112 } 2112 }
2113 if (!dontFlagDirty) 2113 if (!dontFlagDirty)
2114 flagDirty(); 2114 flagDirty();
2115 2115
2116 return true; 2116 return true;
2117} 2117}
2118 2118
2119void PwMDoc::delAllEmptyCat(bool dontFlagDirty) 2119void PwMDoc::delAllEmptyCat(bool dontFlagDirty)
2120{ 2120{
2121 vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), 2121 vector<PwMCategoryItem>::iterator begin = dti.dta.begin(),
2122 end = dti.dta.end(), 2122 end = dti.dta.end(),
2123 i = begin; 2123 i = begin;
2124 while (i != end) { 2124 while (i != end) {
2125 if (i->d.empty()) { 2125 if (i->d.empty()) {
2126 delCategory(begin - i, dontFlagDirty); 2126 delCategory(begin - i, dontFlagDirty);
2127 } 2127 }
2128 ++i; 2128 ++i;
2129 } 2129 }
2130} 2130}
2131 2131
2132void PwMDoc::getCategoryList(vector<string> *list) 2132void PwMDoc::getCategoryList(vector<string> *list)
2133{ 2133{
2134 PWM_ASSERT(list); 2134 PWM_ASSERT(list);
2135 list->clear(); 2135 list->clear();
2136 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2136 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2137 end = dti.dta.end(); 2137 end = dti.dta.end();
2138 while (i != end) { 2138 while (i != end) {
2139 list->push_back(i->name); 2139 list->push_back(i->name);
2140 ++i; 2140 ++i;
2141 } 2141 }
2142} 2142}
2143 2143
2144void PwMDoc::getCategoryList(QStringList *list) 2144void PwMDoc::getCategoryList(QStringList *list)
2145{ 2145{
2146 PWM_ASSERT(list); 2146 PWM_ASSERT(list);
2147 list->clear(); 2147 list->clear();
2148 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2148 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2149 end = dti.dta.end(); 2149 end = dti.dta.end();
2150 while (i != end) { 2150 while (i != end) {
2151#ifndef PWM_EMBEDDED 2151#ifndef PWM_EMBEDDED
2152 list->push_back(i->name.c_str()); 2152 list->push_back(i->name.c_str());
2153#else 2153#else
2154 list->append(i->name.c_str()); 2154 list->append(i->name.c_str());
2155#endif 2155#endif
2156 ++i; 2156 ++i;
2157 } 2157 }
2158} 2158}
2159 2159
2160void PwMDoc::getEntryList(const QString &category, QStringList *list) 2160void PwMDoc::getEntryList(const QString &category, QStringList *list)
2161{ 2161{
2162 PWM_ASSERT(list); 2162 PWM_ASSERT(list);
2163 unsigned int cat = 0; 2163 unsigned int cat = 0;
2164 if (!findCategory(category, &cat)) { 2164 if (!findCategory(category, &cat)) {
2165 list->clear(); 2165 list->clear();
2166 return; 2166 return;
2167 } 2167 }
2168 getEntryList(cat, list); 2168 getEntryList(cat, list);
2169} 2169}
2170 2170
2171void PwMDoc::getEntryList(const QString &category, vector<string> *list) 2171void PwMDoc::getEntryList(const QString &category, vector<string> *list)
2172{ 2172{
2173 PWM_ASSERT(list); 2173 PWM_ASSERT(list);
2174 unsigned int cat = 0; 2174 unsigned int cat = 0;
2175 if (!findCategory(category, &cat)) { 2175 if (!findCategory(category, &cat)) {
2176 list->clear(); 2176 list->clear();
2177 return; 2177 return;
2178 } 2178 }
2179 getEntryList(cat, list); 2179 getEntryList(cat, list);
2180} 2180}
2181 2181
2182void PwMDoc::getEntryList(unsigned int category, vector<string> *list) 2182void PwMDoc::getEntryList(unsigned int category, vector<string> *list)
2183{ 2183{
2184 PWM_ASSERT(list); 2184 PWM_ASSERT(list);
2185 list->clear(); 2185 list->clear();
2186 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), 2186 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
2187 end = dti.dta[category].d.end(), 2187 end = dti.dta[category].d.end(),
2188 i = begin; 2188 i = begin;
2189 while (i != end) { 2189 while (i != end) {
2190 list->push_back(i->desc); 2190 list->push_back(i->desc);
2191 ++i; 2191 ++i;
2192 } 2192 }
2193} 2193}
2194 2194
2195void PwMDoc::getEntryList(unsigned int category, QStringList *list) 2195void PwMDoc::getEntryList(unsigned int category, QStringList *list)
2196{ 2196{
2197 PWM_ASSERT(list); 2197 PWM_ASSERT(list);
2198 list->clear(); 2198 list->clear();
2199 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), 2199 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
2200 end = dti.dta[category].d.end(), 2200 end = dti.dta[category].d.end(),
2201 i = begin; 2201 i = begin;
2202 while (i != end) { 2202 while (i != end) {
2203#ifndef PWM_EMBEDDED 2203#ifndef PWM_EMBEDDED
2204 list->push_back(i->desc.c_str()); 2204 list->push_back(i->desc.c_str());
2205#else 2205#else
2206 list->append(i->desc.c_str()); 2206 list->append(i->desc.c_str());
2207#endif 2207#endif
2208 ++i; 2208 ++i;
2209 } 2209 }
2210} 2210}
2211 2211
2212bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) 2212bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex)
2213{ 2213{
2214 unsigned int cat = 0; 2214 unsigned int cat = 0;
2215 2215
2216 if (!findCategory(category, &cat)) 2216 if (!findCategory(category, &cat))
2217 return false; 2217 return false;
2218 2218
2219 return execLauncher(cat, entryIndex); 2219 return execLauncher(cat, entryIndex);
2220} 2220}
2221 2221
2222bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) 2222bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex)
2223{ 2223{
2224#ifndef _WIN32_ 2224#ifndef _WIN32_
2225 if (geteuid() == 0) { 2225 if (geteuid() == 0) {
2226 rootAlertMsgBox(); 2226 rootAlertMsgBox();
2227 return false; 2227 return false;
2228 } 2228 }
2229#endif 2229#endif
2230 QString command(dti.dta[category].d[entryIndex].launcher.c_str()); 2230 QString command(dti.dta[category].d[entryIndex].launcher.c_str());
2231 bool wasLocked = isLocked(category, entryIndex); 2231 bool wasLocked = isLocked(category, entryIndex);
2232 2232
2233 if (command.find("$p") != -1) { 2233 if (command.find("$p") != -1) {
2234 /* the user requested the password to be included 2234 /* the user requested the password to be included
2235 * into the command. We have to ask for the password, 2235 * into the command. We have to ask for the password,
2236 * if it's locked. We do that by unlocking the entry 2236 * if it's locked. We do that by unlocking the entry
2237 */ 2237 */
2238 if (!lockAt(category, entryIndex, false)) 2238 if (!lockAt(category, entryIndex, false))
2239 return false; 2239 return false;
2240 } 2240 }
2241#ifndef PWM_EMBEDDED 2241#ifndef PWM_EMBEDDED
2242 command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); 2242 command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str());
2243 command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); 2243 command.replace("$n", dti.dta[category].d[entryIndex].name.c_str());
2244 command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); 2244 command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str());
2245 command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); 2245 command.replace("$u", dti.dta[category].d[entryIndex].url.c_str());
2246 command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); 2246 command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str());
2247#else 2247#else
2248 command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); 2248 command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str());
2249 command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); 2249 command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str());
2250 command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); 2250 command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str());
2251 command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); 2251 command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str());
2252 command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); 2252 command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str());
2253#endif 2253#endif
2254 command.append(" &"); 2254 command.append(" &");
2255 2255
2256 QString customXterm(conf()->confGlobXtermCommand()); 2256 QString customXterm(conf()->confGlobXtermCommand());
2257 if (!customXterm.isEmpty()) 2257 if (!customXterm.isEmpty())
2258 command = customXterm + " " + command; 2258 command = customXterm + " " + command;
2259 2259
2260 system(command.latin1()); 2260 system(command.latin1());
2261 2261
2262 lockAt(category, entryIndex, wasLocked); 2262 lockAt(category, entryIndex, wasLocked);
2263 return true; 2263 return true;
2264} 2264}
2265 2265
2266bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) 2266bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex)
2267{ 2267{
2268 unsigned int cat = 0; 2268 unsigned int cat = 0;
2269 2269
2270 if (!findCategory(category, &cat)) 2270 if (!findCategory(category, &cat))
2271 return false; 2271 return false;
2272 2272
2273 return goToURL(cat, entryIndex); 2273 return goToURL(cat, entryIndex);
2274} 2274}
2275 2275
2276bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) 2276bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex)
2277{ 2277{
2278#ifndef _WIN32_ 2278#ifndef _WIN32_
2279 if (geteuid() == 0) { 2279 if (geteuid() == 0) {
2280 rootAlertMsgBox(); 2280 rootAlertMsgBox();
2281 return false; 2281 return false;
2282 } 2282 }
2283#endif 2283#endif
2284 QString url(dti.dta[category].d[entryIndex].url.c_str()); 2284 QString url(dti.dta[category].d[entryIndex].url.c_str());
2285 if (url.isEmpty()) 2285 if (url.isEmpty())
2286 return false; 2286 return false;
2287 2287
2288 QString customBrowser(conf()->confGlobBrowserCommand()); 2288 QString customBrowser(conf()->confGlobBrowserCommand());
2289 if (!customBrowser.isEmpty()) { 2289 if (!customBrowser.isEmpty()) {
2290 browserProc.clearArguments(); 2290 browserProc.clearArguments();
2291 browserProc << customBrowser << url; 2291 browserProc << customBrowser << url;
2292 if (browserProc.start(KProcess::DontCare)) 2292 if (browserProc.start(KProcess::DontCare))
2293 return true; 2293 return true;
2294 } 2294 }
2295 2295
2296 browserProc.clearArguments(); 2296 browserProc.clearArguments();
2297 browserProc << "konqueror" << url; 2297 browserProc << "konqueror" << url;
2298 if (browserProc.start(KProcess::DontCare)) 2298 if (browserProc.start(KProcess::DontCare))
2299 return true; 2299 return true;
2300 2300
2301 browserProc.clearArguments(); 2301 browserProc.clearArguments();
2302 browserProc << "mozilla" << url; 2302 browserProc << "mozilla" << url;
2303 if (browserProc.start(KProcess::DontCare)) 2303 if (browserProc.start(KProcess::DontCare))
2304 return true; 2304 return true;
2305 2305
2306 browserProc.clearArguments(); 2306 browserProc.clearArguments();
2307 browserProc << "opera" << url; 2307 browserProc << "opera" << url;
2308 if (browserProc.start(KProcess::DontCare)) 2308 if (browserProc.start(KProcess::DontCare))
2309 return true; 2309 return true;
2310 return false; 2310 return false;
2311} 2311}
2312 2312
2313PwMerror PwMDoc::exportToText(const QString *file) 2313PwMerror PwMDoc::exportToText(const QString *file)
2314{ 2314{
2315 PWM_ASSERT(file); 2315 PWM_ASSERT(file);
2316 if (QFile::exists(*file)) { 2316 if (QFile::exists(*file)) {
2317 if (!QFile::remove(*file)) 2317 if (!QFile::remove(*file))
2318 return e_accessFile; 2318 return e_accessFile;
2319 } 2319 }
2320 QFile f(*file); 2320 QFile f(*file);
2321 if (!f.open(IO_ReadWrite)) 2321 if (!f.open(IO_ReadWrite))
2322 return e_openFile; 2322 return e_openFile;
2323 2323
2324 if (!unlockAll_tempoary()) { 2324 if (!unlockAll_tempoary()) {
2325 f.close(); 2325 f.close();
2326 return e_lock; 2326 return e_lock;
2327 } 2327 }
2328 2328
2329 // write header 2329 // write header
2330 string header = i18n("Password table generated by\nPwM v").latin1(); 2330 string header = i18n("Password table generated by\nPwM v").latin1();
2331 header += PACKAGE_VER; 2331 header += PACKAGE_VER;
2332 header += i18n("\non ").latin1(); 2332 header += i18n("\non ").latin1();
2333 QDate currDate = QDate::currentDate(); 2333 QDate currDate = QDate::currentDate();
2334 QTime currTime = QTime::currentTime(); 2334 QTime currTime = QTime::currentTime();
2335 2335
2336#ifndef PWM_EMBEDDED 2336#ifndef PWM_EMBEDDED
2337 header += currDate.toString("ddd MMMM d ").latin1(); 2337 header += currDate.toString("ddd MMMM d ").latin1();
2338 header += currTime.toString("hh:mm:ss ").latin1(); 2338 header += currTime.toString("hh:mm:ss ").latin1();
2339#else 2339#else
2340 QString dfs = KGlobal::locale()->dateFormatShort(); 2340 QString dfs = KGlobal::locale()->dateFormatShort();
2341 bool ampm = KGlobal::locale()->use12Clock(); 2341 bool ampm = KGlobal::locale()->use12Clock();
2342 KGlobal::locale()->setDateFormatShort("%A %B %d"); 2342 KGlobal::locale()->setDateFormatShort("%A %B %d");
2343 KGlobal::locale()->setHore24Format(true); 2343 KGlobal::locale()->setHore24Format(true);
2344 2344
2345 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1(); 2345 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1();
2346 header += KGlobal::locale()->formatTime(currTime, true).latin1(); 2346 header += KGlobal::locale()->formatTime(currTime, true).latin1();
2347 KGlobal::locale()->setDateFormatShort(dfs); 2347 KGlobal::locale()->setDateFormatShort(dfs);
2348 KGlobal::locale()->setHore24Format(!ampm); 2348 KGlobal::locale()->setHore24Format(!ampm);
2349 2349
2350#endif 2350#endif
2351 header += tostr(currDate.year()); 2351 header += tostr(currDate.year());
2352 header += "\n==============================\n\n"; 2352 header += "\n==============================\n\n";
2353 2353
2354 2354
2355#ifndef PWM_EMBEDDED 2355#ifndef PWM_EMBEDDED
2356 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { 2356 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) {
2357 unlockAll_tempoary(true); 2357 unlockAll_tempoary(true);
2358 f.close(); 2358 f.close();
2359 return e_writeFile; 2359 return e_writeFile;
2360 } 2360 }
2361#else 2361#else
2362 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { 2362 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) {
2363 unlockAll_tempoary(true); 2363 unlockAll_tempoary(true);
2364 f.close(); 2364 f.close();
2365 return e_writeFile; 2365 return e_writeFile;
2366 } 2366 }
2367#endif 2367#endif
2368 unsigned int i, numCat = numCategories(); 2368 unsigned int i, numCat = numCategories();
2369 unsigned int j, numEnt; 2369 unsigned int j, numEnt;
2370 string exp; 2370 string exp;
2371 for (i = 0; i < numCat; ++i) { 2371 for (i = 0; i < numCat; ++i) {
2372 numEnt = numEntries(i); 2372 numEnt = numEntries(i);
2373 2373
2374 exp = "\n== Category: "; 2374 exp = "\n== Category: ";
2375 exp += dti.dta[i].name; 2375 exp += dti.dta[i].name;
2376 exp += " ==\n"; 2376 exp += " ==\n";
2377#ifndef PWM_EMBEDDED 2377#ifndef PWM_EMBEDDED
2378 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { 2378 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2379 unlockAll_tempoary(true); 2379 unlockAll_tempoary(true);
2380 f.close(); 2380 f.close();
2381 return e_writeFile; 2381 return e_writeFile;
2382 } 2382 }
2383#else 2383#else
2384 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { 2384 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2385 unlockAll_tempoary(true); 2385 unlockAll_tempoary(true);
2386 f.close(); 2386 f.close();
2387 return e_writeFile; 2387 return e_writeFile;
2388 } 2388 }
2389#endif 2389#endif
2390 for (j = 0; j < numEnt; ++j) { 2390 for (j = 0; j < numEnt; ++j) {
2391 exp = "\n-- "; 2391 exp = "\n-- ";
2392 exp += dti.dta[i].d[j].desc; 2392 exp += dti.dta[i].d[j].desc;
2393 exp += " --\n"; 2393 exp += " --\n";
2394 2394
2395 exp += i18n("Username: ").latin1(); 2395 exp += i18n("Username: ").latin1();
2396 exp += dti.dta[i].d[j].name; 2396 exp += dti.dta[i].d[j].name;
2397 exp += "\n"; 2397 exp += "\n";
2398 2398
2399 exp += i18n("Password: ").latin1(); 2399 exp += i18n("Password: ").latin1();
2400 exp += dti.dta[i].d[j].pw; 2400 exp += dti.dta[i].d[j].pw;
2401 exp += "\n"; 2401 exp += "\n";
2402 2402
2403 exp += i18n("Comment: ").latin1(); 2403 exp += i18n("Comment: ").latin1();
2404 exp += dti.dta[i].d[j].comment; 2404 exp += dti.dta[i].d[j].comment;
2405 exp += "\n"; 2405 exp += "\n";
2406 2406
2407 exp += i18n("URL: ").latin1(); 2407 exp += i18n("URL: ").latin1();
2408 exp += dti.dta[i].d[j].url; 2408 exp += dti.dta[i].d[j].url;
2409 exp += "\n"; 2409 exp += "\n";
2410 2410
2411 exp += i18n("Launcher: ").latin1(); 2411 exp += i18n("Launcher: ").latin1();
2412 exp += dti.dta[i].d[j].launcher; 2412 exp += dti.dta[i].d[j].launcher;
2413 exp += "\n"; 2413 exp += "\n";
2414 2414
2415#ifndef PWM_EMBEDDED 2415#ifndef PWM_EMBEDDED
2416 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { 2416 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2417 unlockAll_tempoary(true); 2417 unlockAll_tempoary(true);
2418 f.close(); 2418 f.close();
2419 return e_writeFile; 2419 return e_writeFile;
2420 } 2420 }
2421#else 2421#else
2422 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { 2422 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2423 unlockAll_tempoary(true); 2423 unlockAll_tempoary(true);
2424 f.close(); 2424 f.close();
2425 return e_writeFile; 2425 return e_writeFile;
2426 } 2426 }
2427#endif 2427#endif
2428 } 2428 }
2429 } 2429 }
2430 unlockAll_tempoary(true); 2430 unlockAll_tempoary(true);
2431 f.close(); 2431 f.close();
2432 2432
2433 return e_success; 2433 return e_success;
2434} 2434}
2435 2435
2436PwMerror PwMDoc::importFromText(const QString *file, int format) 2436PwMerror PwMDoc::importFromText(const QString *file, int format)
2437{ 2437{
2438 PWM_ASSERT(file); 2438 PWM_ASSERT(file);
2439 if (format == 0) 2439 if (format == 0)
2440 return importText_PwM(file); 2440 return importText_PwM(file);
2441 else if (format == -1) { 2441 else if (format == -1) {
2442 // probe for all formats 2442 // probe for all formats
2443 if (importText_PwM(file) == e_success) 2443 if (importText_PwM(file) == e_success)
2444 return e_success; 2444 return e_success;
2445 dti.clear(); 2445 dti.clear();
2446 emitDataChanged(this); 2446 emitDataChanged(this);
2447 // add next format here... 2447 // add next format here...
2448 return e_fileFormat; 2448 return e_fileFormat;
2449 } 2449 }
2450 return e_invalidArg; 2450 return e_invalidArg;
2451} 2451}
2452 2452
2453PwMerror PwMDoc::importText_PwM(const QString *file) 2453PwMerror PwMDoc::importText_PwM(const QString *file)
2454{ 2454{
2455#ifndef PWM_EMBEDDED 2455#ifndef PWM_EMBEDDED
2456 PWM_ASSERT(file); 2456 PWM_ASSERT(file);
2457 FILE *f; 2457 FILE *f;
2458 int tmp; 2458 int tmp;
2459 ssize_t ret; 2459 ssize_t ret;
2460 string curCat; 2460 string curCat;
2461 unsigned int entriesRead = 0; 2461 unsigned int entriesRead = 0;
2462 PwMDataItem currItem; 2462 PwMDataItem currItem;
2463 f = fopen(file->latin1(), "r"); 2463 f = fopen(file->latin1(), "r");
2464 if (!f) 2464 if (!f)
2465 return e_openFile; 2465 return e_openFile;
2466 size_t ch_tmp_size = 1024; 2466 size_t ch_tmp_size = 1024;
2467 char *ch_tmp = (char*)malloc(ch_tmp_size); 2467 char *ch_tmp = (char*)malloc(ch_tmp_size);
2468 if (!ch_tmp) { 2468 if (!ch_tmp) {
2469 fclose(f); 2469 fclose(f);
2470 return e_outOfMem; 2470 return e_outOfMem;
2471 } 2471 }
2472 2472
2473 // - check header 2473 // - check header
2474 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. 2474 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line.
2475 goto formatError; 2475 goto formatError;
2476 // check version-string and return version in "ch_tmp". 2476 // check version-string and return version in "ch_tmp".
2477 if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2477 if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2478 // header not recognized as PwM generated header 2478 // header not recognized as PwM generated header
2479 goto formatError; 2479 goto formatError;
2480 } 2480 }
2481 // set filepointer behind version-string-line previously checked 2481 // set filepointer behind version-string-line previously checked
2482 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2482 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2483 goto formatError; 2483 goto formatError;
2484 // skip next line containing the build-date 2484 // skip next line containing the build-date
2485 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2485 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2486 goto formatError; 2486 goto formatError;
2487 // read header termination line 2487 // read header termination line
2488 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2488 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2489 goto formatError; 2489 goto formatError;
2490 if (strcmp(ch_tmp, "==============================\n")) 2490 if (strcmp(ch_tmp, "==============================\n"))
2491 goto formatError; 2491 goto formatError;
2492 2492
2493 // - read entries 2493 // - read entries
2494 do { 2494 do {
2495 // find beginning of next category 2495 // find beginning of next category
2496 do { 2496 do {
2497 tmp = fgetc(f); 2497 tmp = fgetc(f);
2498 } while (tmp == '\n' && tmp != EOF); 2498 } while (tmp == '\n' && tmp != EOF);
2499 if (tmp == EOF) 2499 if (tmp == EOF)
2500 break; 2500 break;
2501 2501
2502 // decrement filepos by one 2502 // decrement filepos by one
2503 fseek(f, -1, SEEK_CUR); 2503 fseek(f, -1, SEEK_CUR);
2504 // read cat-name 2504 // read cat-name
2505 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2505 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2506 goto formatError; 2506 goto formatError;
2507 // check cat-name format 2507 // check cat-name format
2508 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2508 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2509 goto formatError; 2509 goto formatError;
2510 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2510 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2511 goto formatError; 2511 goto formatError;
2512 // copy cat-name 2512 // copy cat-name
2513 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2513 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2514 2514
2515 do { 2515 do {
2516 // find beginning of next entry 2516 // find beginning of next entry
2517 do { 2517 do {
2518 tmp = fgetc(f); 2518 tmp = fgetc(f);
2519 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2519 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2520 if (tmp == EOF) 2520 if (tmp == EOF)
2521 break; 2521 break;
2522 if (tmp == '=') { 2522 if (tmp == '=') {
2523 fseek(f, -1, SEEK_CUR); 2523 fseek(f, -1, SEEK_CUR);
2524 break; 2524 break;
2525 } 2525 }
2526 // decrement filepos by one 2526 // decrement filepos by one
2527 fseek(f, -1, SEEK_CUR); 2527 fseek(f, -1, SEEK_CUR);
2528 // read desc-line 2528 // read desc-line
2529 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2529 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2530 goto formatError; 2530 goto formatError;
2531 // check desc-line format 2531 // check desc-line format
2532 if (memcmp(ch_tmp, "-- ", 3) != 0) 2532 if (memcmp(ch_tmp, "-- ", 3) != 0)
2533 goto formatError; 2533 goto formatError;
2534 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2534 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2535 goto formatError; 2535 goto formatError;
2536 // add desc-line 2536 // add desc-line
2537 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2537 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2538 2538
2539 // read username-line 2539 // read username-line
2540 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2540 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2541 goto formatError; 2541 goto formatError;
2542 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2542 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2543 goto formatError; 2543 goto formatError;
2544 2544
2545 // read pw-line 2545 // read pw-line
2546 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2546 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2547 goto formatError; 2547 goto formatError;
2548 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2548 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2549 goto formatError; 2549 goto formatError;
2550 2550
2551 // read comment-line 2551 // read comment-line
2552 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2552 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2553 goto formatError; 2553 goto formatError;
2554 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2554 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2555 goto formatError; 2555 goto formatError;
2556 2556
2557 // read URL-line 2557 // read URL-line
2558 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2558 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2559 goto formatError; 2559 goto formatError;
2560 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2560 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2561 goto formatError; 2561 goto formatError;
2562 2562
2563 // read launcher-line 2563 // read launcher-line
2564 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2564 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2565 goto formatError; 2565 goto formatError;
2566 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2566 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2567 goto formatError; 2567 goto formatError;
2568 2568
2569 currItem.lockStat = true; 2569 currItem.lockStat = true;
2570 currItem.listViewPos = -1; 2570 currItem.listViewPos = -1;
2571 addEntry(curCat.c_str(), &currItem, true); 2571 addEntry(curCat.c_str(), &currItem, true);
2572 ++entriesRead; 2572 ++entriesRead;
2573 } while (1); 2573 } while (1);
2574 } while (1); 2574 } while (1);
2575 if (!entriesRead) 2575 if (!entriesRead)
2576 goto formatError; 2576 goto formatError;
2577 2577
2578 free(ch_tmp); 2578 free(ch_tmp);
2579 fclose(f); 2579 fclose(f);
2580 flagDirty(); 2580 flagDirty();
2581 return e_success; 2581 return e_success;
2582 2582
2583 formatError: 2583 formatError:
2584 free(ch_tmp); 2584 free(ch_tmp);
2585 fclose(f); 2585 fclose(f);
2586 return e_fileFormat; 2586 return e_fileFormat;
2587#else 2587#else
2588 PWM_ASSERT(file); 2588 PWM_ASSERT(file);
2589 QFile f(file->latin1()); 2589 QFile f(file->latin1());
2590 int tmp; 2590 int tmp;
2591 ssize_t ret; 2591 ssize_t ret;
2592 string curCat; 2592 string curCat;
2593 unsigned int entriesRead = 0; 2593 unsigned int entriesRead = 0;
2594 PwMDataItem currItem; 2594 PwMDataItem currItem;
2595 bool res = f.open(IO_ReadOnly); 2595 bool res = f.open(IO_ReadOnly);
2596 if (res == false) 2596 if (res == false)
2597 return e_openFile; 2597 return e_openFile;
2598 2598
2599 unsigned int ch_tmp_size = 1024; 2599 unsigned int ch_tmp_size = 1024;
2600 char *ch_tmp = (char*)malloc(ch_tmp_size); 2600 char *ch_tmp = (char*)malloc(ch_tmp_size);
2601 if (!ch_tmp) { 2601 if (!ch_tmp) {
2602 f.close(); 2602 f.close();
2603 return e_outOfMem; 2603 return e_outOfMem;
2604 } 2604 }
2605 2605
2606 // - check header 2606 // - check header
2607 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. 2607 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line.
2608 goto formatError; 2608 goto formatError;
2609 2609
2610 //US read fileversion first, then check if ok. 2610 //US read fileversion first, then check if ok.
2611 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2611 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2612 goto formatError; 2612 goto formatError;
2613 2613
2614 // check version-string and return version in "ch_tmp". 2614 // check version-string and return version in "ch_tmp".
2615 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2615 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2616 //US // header not recognized as PwM generated header 2616 //US // header not recognized as PwM generated header
2617 //US goto formatError; 2617 //US goto formatError;
2618 //US} 2618 //US}
2619 //US set filepointer behind version-string-line previously checked 2619 //US set filepointer behind version-string-line previously checked
2620 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2620 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2621 //US goto formatError; 2621 //US goto formatError;
2622 // skip next line containing the build-date 2622 // skip next line containing the build-date
2623 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2623 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2624 goto formatError; 2624 goto formatError;
2625 // read header termination line 2625 // read header termination line
2626 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2626 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2627 goto formatError; 2627 goto formatError;
2628 if (strcmp(ch_tmp, "==============================\n")) 2628 if (strcmp(ch_tmp, "==============================\n"))
2629 goto formatError; 2629 goto formatError;
2630 2630
2631 // - read entries 2631 // - read entries
2632 do { 2632 do {
2633 // find beginning of next category 2633 // find beginning of next category
2634 do { 2634 do {
2635 tmp = f.getch(); 2635 tmp = f.getch();
2636 } while (tmp == '\n' && tmp != EOF); 2636 } while (tmp == '\n' && tmp != EOF);
2637 if (tmp == EOF) 2637 if (tmp == EOF)
2638 break; 2638 break;
2639 2639
2640 // decrement filepos by one 2640 // decrement filepos by one
2641 f.at(f.at()-1); 2641 f.at(f.at()-1);
2642 // read cat-name 2642 // read cat-name
2643 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2643 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2644 goto formatError; 2644 goto formatError;
2645 // check cat-name format 2645 // check cat-name format
2646 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2646 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2647 goto formatError; 2647 goto formatError;
2648 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2648 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2649 goto formatError; 2649 goto formatError;
2650 // copy cat-name 2650 // copy cat-name
2651 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2651 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2652 2652
2653 do { 2653 do {
2654 // find beginning of next entry 2654 // find beginning of next entry
2655 do { 2655 do {
2656 tmp = f.getch(); 2656 tmp = f.getch();
2657 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2657 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2658 if (tmp == EOF) 2658 if (tmp == EOF)
2659 break; 2659 break;
2660 if (tmp == '=') { 2660 if (tmp == '=') {
2661 f.at(f.at()-1); 2661 f.at(f.at()-1);
2662 break; 2662 break;
2663 } 2663 }
2664 // decrement filepos by one 2664 // decrement filepos by one
2665 f.at(f.at()-1); 2665 f.at(f.at()-1);
2666 // read desc-line 2666 // read desc-line
2667 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2667 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2668 goto formatError; 2668 goto formatError;
2669 // check desc-line format 2669 // check desc-line format
2670 if (memcmp(ch_tmp, "-- ", 3) != 0) 2670 if (memcmp(ch_tmp, "-- ", 3) != 0)
2671 goto formatError; 2671 goto formatError;
2672 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2672 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2673 goto formatError; 2673 goto formatError;
2674 // add desc-line 2674 // add desc-line
2675 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2675 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2676 2676
2677 // read username-line 2677 // read username-line
2678 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2678 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2679 goto formatError; 2679 goto formatError;
2680 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2680 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2681 goto formatError; 2681 goto formatError;
2682 2682
2683 // read pw-line 2683 // read pw-line
2684 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2684 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2685 goto formatError; 2685 goto formatError;
2686 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2686 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2687 goto formatError; 2687 goto formatError;
2688 2688
2689 // read comment-line 2689 // read comment-line
2690 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2690 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2691 goto formatError; 2691 goto formatError;
2692 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2692 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2693 goto formatError; 2693 goto formatError;
2694 2694
2695 // read URL-line 2695 // read URL-line
2696 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2696 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2697 goto formatError; 2697 goto formatError;
2698 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2698 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2699 goto formatError; 2699 goto formatError;
2700 2700
2701 // read launcher-line 2701 // read launcher-line
2702 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2702 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2703 goto formatError; 2703 goto formatError;
2704 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2704 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2705 goto formatError; 2705 goto formatError;
2706 2706
2707 currItem.lockStat = true; 2707 currItem.lockStat = true;
2708 currItem.listViewPos = -1; 2708 currItem.listViewPos = -1;
2709 addEntry(curCat.c_str(), &currItem, true); 2709 addEntry(curCat.c_str(), &currItem, true);
2710 ++entriesRead; 2710 ++entriesRead;
2711 } while (1); 2711 } while (1);
2712 } while (1); 2712 } while (1);
2713 if (!entriesRead) 2713 if (!entriesRead)
2714 goto formatError; 2714 goto formatError;
2715 2715
2716 free(ch_tmp); 2716 free(ch_tmp);
2717 f.close(); 2717 f.close();
2718 flagDirty(); 2718 flagDirty();
2719 return e_success; 2719 return e_success;
2720 2720
2721 formatError: 2721 formatError:
2722 free(ch_tmp); 2722 free(ch_tmp);
2723 f.close(); 2723 f.close();
2724 return e_fileFormat; 2724 return e_fileFormat;
2725 2725
2726#endif 2726#endif
2727 2727
2728} 2728}
2729 2729
2730bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) 2730bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out)
2731{ 2731{
2732 PWM_ASSERT(in && out); 2732 PWM_ASSERT(in && out);
2733 ssize_t i = 0, len = in_size - 1; 2733 ssize_t i = 0, len = in_size - 1;
2734 while (i < len) { 2734 while (i < len) {
2735 if (in[i] == ':') 2735 if (in[i] == ':')
2736 break; 2736 break;
2737 ++i; 2737 ++i;
2738 } 2738 }
2739 i += 2; 2739 i += 2;
2740 *out = ""; 2740 *out = "";
2741 out->append(in + i, in_size - i - 1); 2741 out->append(in + i, in_size - i - 1);
2742 return true; 2742 return true;
2743} 2743}
2744 2744
2745PwMerror PwMDoc::exportToGpasman(const QString *file) 2745PwMerror PwMDoc::exportToGpasman(const QString *file)
2746{ 2746{
2747 PWM_ASSERT(file); 2747 PWM_ASSERT(file);
2748 GpasmanFile gp; 2748 GpasmanFile gp;
2749 int ret; 2749 int ret;
2750 2750
2751 if (!unlockAll_tempoary()) 2751 if (!unlockAll_tempoary())
2752 return e_lock; 2752 return e_lock;
2753 2753
2754 QString gpmPassword; 2754 QString gpmPassword;
2755 while (1) { 2755 while (1) {
2756 gpmPassword = requestNewMpw(0); 2756 gpmPassword = requestNewMpw(0);
2757 if (gpmPassword == "") { 2757 if (gpmPassword == "") {
2758 unlockAll_tempoary(true); 2758 unlockAll_tempoary(true);
2759 return e_noPw; 2759 return e_noPw;
2760 } 2760 }
2761 if (gpmPassword.length() < 4) { 2761 if (gpmPassword.length() < 4) {
2762 gpmPwLenErrMsgBox(); 2762 gpmPwLenErrMsgBox();
2763 } else { 2763 } else {
2764 break; 2764 break;
2765 } 2765 }
2766 } 2766 }
2767 2767
2768 ret = gp.save_init(file->latin1(), gpmPassword.latin1()); 2768 ret = gp.save_init(file->latin1(), gpmPassword.latin1());
2769 if (ret != 1) { 2769 if (ret != 1) {
2770 unlockAll_tempoary(true); 2770 unlockAll_tempoary(true);
2771 return e_accessFile; 2771 return e_accessFile;
2772 } 2772 }
2773 2773
2774 char *entry[4]; 2774 char *entry[4];
2775 unsigned int numCat = numCategories(), i; 2775 unsigned int numCat = numCategories(), i;
2776 unsigned int numEntr, j; 2776 unsigned int numEntr, j;
2777 int descLen, nameLen, pwLen, commentLen; 2777 int descLen, nameLen, pwLen, commentLen;
2778 for (i = 0; i < numCat; ++i) { 2778 for (i = 0; i < numCat; ++i) {
2779 numEntr = numEntries(i); 2779 numEntr = numEntries(i);
2780 for (j = 0; j < numEntr; ++j) { 2780 for (j = 0; j < numEntr; ++j) {
2781 descLen = dti.dta[i].d[j].desc.length(); 2781 descLen = dti.dta[i].d[j].desc.length();
2782 nameLen = dti.dta[i].d[j].name.length(); 2782 nameLen = dti.dta[i].d[j].name.length();
2783 pwLen = dti.dta[i].d[j].pw.length(); 2783 pwLen = dti.dta[i].d[j].pw.length();
2784 commentLen = dti.dta[i].d[j].comment.length(); 2784 commentLen = dti.dta[i].d[j].comment.length();
2785 entry[0] = new char[descLen + 1]; 2785 entry[0] = new char[descLen + 1];
2786 entry[1] = new char[nameLen + 1]; 2786 entry[1] = new char[nameLen + 1];
2787 entry[2] = new char[pwLen + 1]; 2787 entry[2] = new char[pwLen + 1];
2788 entry[3] = new char[commentLen + 1]; 2788 entry[3] = new char[commentLen + 1];
2789 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); 2789 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str());
2790 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); 2790 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str());
2791 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); 2791 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str());
2792 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); 2792 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str());
2793 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; 2793 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0';
2794 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; 2794 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0';
2795 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; 2795 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0';
2796 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; 2796 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0';
2797 2797
2798 ret = gp.save_entry(entry); 2798 ret = gp.save_entry(entry);
2799 if (ret == -1){ 2799 if (ret == -1){
2800 delete [] entry[0]; 2800 delete [] entry[0];
2801 delete [] entry[1]; 2801 delete [] entry[1];
2802 delete [] entry[2]; 2802 delete [] entry[2];
2803 delete [] entry[3]; 2803 delete [] entry[3];
2804 gp.save_finalize(); 2804 gp.save_finalize();
2805 unlockAll_tempoary(true); 2805 unlockAll_tempoary(true);
2806 return e_writeFile; 2806 return e_writeFile;
2807 } 2807 }
2808 2808
2809 delete [] entry[0]; 2809 delete [] entry[0];
2810 delete [] entry[1]; 2810 delete [] entry[1];
2811 delete [] entry[2]; 2811 delete [] entry[2];
2812 delete [] entry[3]; 2812 delete [] entry[3];
2813 } 2813 }
2814 } 2814 }
2815 unlockAll_tempoary(true); 2815 unlockAll_tempoary(true);
2816 if (gp.save_finalize() == -1) 2816 if (gp.save_finalize() == -1)
2817 return e_writeFile; 2817 return e_writeFile;
2818 2818
2819 return e_success; 2819 return e_success;
2820} 2820}
2821 2821
2822PwMerror PwMDoc::importFromGpasman(const QString *file) 2822PwMerror PwMDoc::importFromGpasman(const QString *file)
2823{ 2823{
2824 PWM_ASSERT(file); 2824 PWM_ASSERT(file);
2825 QString pw = requestMpw(false); 2825 QString pw = requestMpw(false);
2826 if (pw == "") 2826 if (pw == "")
2827 return e_noPw; 2827 return e_noPw;
2828 GpasmanFile gp; 2828 GpasmanFile gp;
2829 int ret, i; 2829 int ret, i;
2830 PwMerror ret2; 2830 PwMerror ret2;
2831 char *entry[4]; 2831 char *entry[4];
2832 PwMDataItem tmpData; 2832 PwMDataItem tmpData;
2833 ret = gp.load_init(file->latin1(), pw.latin1()); 2833 ret = gp.load_init(file->latin1(), pw.latin1());
2834 if (ret != 1) 2834 if (ret != 1)
2835 return e_accessFile; 2835 return e_accessFile;
2836 2836
2837 do { 2837 do {
2838 ret = gp.load_entry(entry); 2838 ret = gp.load_entry(entry);
2839 if(ret != 1) 2839 if(ret != 1)
2840 break; 2840 break;
2841 tmpData.desc = entry[0]; 2841 tmpData.desc = entry[0];
2842 tmpData.name = entry[1]; 2842 tmpData.name = entry[1];
2843 tmpData.pw = entry[2]; 2843 tmpData.pw = entry[2];
2844 tmpData.comment = entry[3]; 2844 tmpData.comment = entry[3];
2845 tmpData.lockStat = true; 2845 tmpData.lockStat = true;
2846 tmpData.listViewPos = -1; 2846 tmpData.listViewPos = -1;
2847 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); 2847 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2848 for (i = 0; i < 4; ++i) 2848 for (i = 0; i < 4; ++i)
2849 free(entry[i]); 2849 free(entry[i]);
2850 if (ret2 == e_maxAllowedEntr) { 2850 if (ret2 == e_maxAllowedEntr) {
2851 gp.load_finalize(); 2851 gp.load_finalize();
2852 return e_maxAllowedEntr; 2852 return e_maxAllowedEntr;
2853 } 2853 }
2854 } while (1); 2854 } while (1);
2855 gp.load_finalize(); 2855 gp.load_finalize();
2856 if (isDocEmpty()) 2856 if (isDocEmpty())
2857 return e_wrongPw; // we assume this. 2857 return e_wrongPw; // we assume this.
2858 2858
2859 flagDirty(); 2859 flagDirty();
2860 return e_success; 2860 return e_success;
2861} 2861}
2862 2862
2863 2863
2864//US: we use the stl sort algorythm to sort all elements in the order 2864//US: we use the stl sort algorythm to sort all elements in the order
2865//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 2865//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
2866struct PwMDataItemListViewPosSort 2866struct PwMDataItemListViewPosSort
2867{ 2867{
2868 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) 2868 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
2869 { 2869 {
2870 //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); 2870 //qDebug("pwMDoc::PwMDataItemListViewPosSort()");
2871 if ((rpEnd)->listViewPos < 0) 2871 if ((rpEnd)->listViewPos < 0)
2872 return false; 2872 return false;
2873 else 2873 else
2874 return (rpStart)->listViewPos < (rpEnd)->listViewPos; 2874 return (rpStart)->listViewPos < (rpEnd)->listViewPos;
2875 } 2875 }
2876}; 2876};
2877 2877
2878void PwMDoc::ensureLvp() 2878void PwMDoc::ensureLvp()
2879{ 2879{
2880 if (isDocEmpty()) 2880 if (isDocEmpty())
2881 return; 2881 return;
2882 2882
2883 //US ENH BUG: when using syncronizing, this way of sorting 2883 //US ENH BUG: when using syncronizing, this way of sorting
2884 //is not sufficient, because there might be empty spaces 2884 //is not sufficient, because there might be empty spaces
2885 // at the beginning. But the old algorythm only can add elements 2885 // at the beginning. But the old algorythm only can add elements
2886 //to the end.The result are crashes because of list overflows 2886 //to the end.The result are crashes because of list overflows
2887 //we need something to fill all gaps. 2887 //we need something to fill all gaps.
2888 vector<PwMDataItem*> sorted; 2888 vector<PwMDataItem*> sorted;
2889 vector< PwMDataItem*>::iterator sortedBegin, 2889 vector< PwMDataItem*>::iterator sortedBegin,
2890 sortedEnd, 2890 sortedEnd,
2891 sortedI; 2891 sortedI;
2892 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 2892 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
2893 catEnd = dti.dta.end(), 2893 catEnd = dti.dta.end(),
2894 catI = catBegin; 2894 catI = catBegin;
2895 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 2895 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2896 int lvpTop, tmpLvp; 2896 int lvpTop, tmpLvp;
2897 2897
2898 //qDebug("collect:"); 2898 //qDebug("collect:");
2899 2899
2900 while (catI != catEnd) { 2900 while (catI != catEnd) {
2901 lvpTop = -1; 2901 lvpTop = -1;
2902 sorted.clear(); 2902 sorted.clear();
2903 2903
2904 entrBegin = catI->d.begin(); 2904 entrBegin = catI->d.begin();
2905 entrEnd = catI->d.end(); 2905 entrEnd = catI->d.end();
2906 entrI = entrBegin; 2906 entrI = entrBegin;
2907 2907
2908 //US: we use the stl sort algorythm to sort all elements in the order 2908 //US: we use the stl sort algorythm to sort all elements in the order
2909 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 2909 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1
2910 while (entrI != entrEnd) { 2910 while (entrI != entrEnd) {
2911 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 2911 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2912 sorted.push_back((PwMDataItem*)&(*entrI)); 2912 sorted.push_back((PwMDataItem*)&(*entrI));
2913 ++entrI; 2913 ++entrI;
2914 } 2914 }
2915 2915
2916 sortedBegin = sorted.begin(); 2916 sortedBegin = sorted.begin();
2917 sortedEnd = sorted.end(); 2917 sortedEnd = sorted.end();
2918 2918
2919 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); 2919 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort());
2920 2920
2921 // qDebug("resort:"); 2921 // qDebug("resort:");
2922 //now we have all sorted in a collection 2922 //now we have all sorted in a collection
2923 //Now start with the sorted and reset listviewpos. 2923 //Now start with the sorted and reset listviewpos.
2924 sortedBegin = sorted.begin(); 2924 sortedBegin = sorted.begin();
2925 sortedEnd = sorted.end(); 2925 sortedEnd = sorted.end();
2926 sortedI = sortedBegin; 2926 sortedI = sortedBegin;
2927 2927
2928 while (sortedI != sortedEnd) { 2928 while (sortedI != sortedEnd) {
2929 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); 2929 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1);
2930 (*sortedI)->listViewPos = ++lvpTop; 2930 (*sortedI)->listViewPos = ++lvpTop;
2931 ++sortedI; 2931 ++sortedI;
2932 } 2932 }
2933 2933
2934 /*/debug 2934 /*/debug
2935 entrBegin = catI->d.begin(); 2935 entrBegin = catI->d.begin();
2936 entrEnd = catI->d.end(); 2936 entrEnd = catI->d.end();
2937 entrI = entrBegin; 2937 entrI = entrBegin;
2938 2938
2939 while (entrI != entrEnd) { 2939 while (entrI != entrEnd) {
2940 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 2940 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2941 ++entrI; 2941 ++entrI;
2942 } 2942 }
2943 */ 2943 */
2944 2944
2945 ++catI; 2945 ++catI;
2946 } 2946 }
2947} 2947}
2948 2948
2949QString PwMDoc::getTitle() 2949QString PwMDoc::getTitle()
2950{ 2950{
2951 /* NOTE: We have to ensure, that the returned title 2951 /* NOTE: We have to ensure, that the returned title
2952 * is unique and not reused somewhere else while 2952 * is unique and not reused somewhere else while
2953 * this document is valid (open). 2953 * this document is valid (open).
2954 */ 2954 */
2955 QString title(getFilename()); 2955 QString title(getFilename());
2956 2956
2957 //US ENH: The whole filename on PDAs is too long. So use only the last characters 2957 //US ENH: The whole filename on PDAs is too long. So use only the last characters
2958 if (QApplication::desktop()->width() < 640) 2958 if (QApplication::desktop()->width() < 640)
2959 { 2959 {
2960 if (title.length() > 30) 2960 if (title.length() > 30)
2961 title = "..." + title.right(30); 2961 title = "..." + title.right(30);
2962 2962
2963 } 2963 }
2964 2964
2965 2965
2966 if (title.isEmpty()) { 2966 if (title.isEmpty()) {
2967 if (unnamedNum == 0) { 2967 if (unnamedNum == 0) {
2968 unnamedNum = PwMDocList::getNewUnnamedNumber(); 2968 unnamedNum = PwMDocList::getNewUnnamedNumber();
2969 PWM_ASSERT(unnamedNum != 0); 2969 PWM_ASSERT(unnamedNum != 0);
2970 } 2970 }
2971 title = DEFAULT_TITLE; 2971 title = DEFAULT_TITLE;
2972 title += " "; 2972 title += " ";
2973 title += tostr(unnamedNum).c_str(); 2973 title += tostr(unnamedNum).c_str();
2974 } 2974 }
2975 return title; 2975 return title;
2976} 2976}
2977 2977
2978bool PwMDoc::tryDelete() 2978bool PwMDoc::tryDelete()
2979{ 2979{
2980 2980
2981 if (deleted) 2981 if (deleted)
2982 return true; 2982 return true;
2983 int ret; 2983 int ret;
2984 if (isDirty()) { 2984 if (isDirty()) {
2985 ret = dirtyAskSave(getTitle()); 2985 ret = dirtyAskSave(getTitle());
2986 if (ret == 0) { // save to disk 2986 if (ret == 0) { // save to disk
2987 if (!saveDocUi(this)) 2987 if (!saveDocUi(this))
2988 goto out_ignore; 2988 goto out_ignore;
2989 } else if (ret == 1) { // don't save and delete 2989 } else if (ret == 1) { // don't save and delete
2990 goto out_accept; 2990 goto out_accept;
2991 } else { // cancel operation 2991 } else { // cancel operation
2992 goto out_ignore; 2992 goto out_ignore;
2993 } 2993 }
2994 } 2994 }
2995out_accept: 2995out_accept:
2996 deleted = true; 2996 deleted = true;
2997 delete this; 2997 delete this;
2998 return true; 2998 return true;
2999out_ignore: 2999out_ignore:
3000 return false; 3000 return false;
3001} 3001}
3002 3002
3003 3003
3004 3004
3005#ifdef PWM_EMBEDDED 3005#ifdef PWM_EMBEDDED
3006//US ENH: this is the magic function that syncronizes the this doc with the remote doc 3006//US ENH: this is the magic function that syncronizes the this doc with the remote doc
3007//US it could have been defined as static, but I did not want to. 3007//US it could have been defined as static, but I did not want to.
3008PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 3008PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
3009{ 3009{
3010 int addedPasswordsLocal = 0; 3010 int addedPasswordsLocal = 0;
3011 int addedPasswordsRemote = 0; 3011 int addedPasswordsRemote = 0;
3012 int deletedPasswordsRemote = 0; 3012 int deletedPasswordsRemote = 0;
3013 int deletedPasswordsLocal = 0; 3013 int deletedPasswordsLocal = 0;
3014 int changedLocal = 0; 3014 int changedLocal = 0;
3015 int changedRemote = 0; 3015 int changedRemote = 0;
3016 3016
3017 PwMSyncItem* syncItemLocal; 3017 PwMSyncItem* syncItemLocal;
3018 PwMSyncItem* syncItemRemote; 3018 PwMSyncItem* syncItemRemote;
3019 3019
3020 QString mCurrentSyncName = manager->getCurrentSyncName(); 3020 QString mCurrentSyncName = manager->getCurrentSyncName();
3021 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3021 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3022 3022
3023 bool mSyncLauncher = true;
3024
3023 bool fullDateRange = false; 3025 bool fullDateRange = false;
3024 int take; 3026 int take;
3025 // local->resetTempSyncStat(); 3027 // local->resetTempSyncStat();
3026 QDateTime mLastSync = QDateTime::currentDateTime(); 3028 QDateTime mLastSync = QDateTime::currentDateTime();
3027 QDateTime modifiedSync = mLastSync; 3029 QDateTime modifiedSync = mLastSync;
3028 3030
3029 unsigned int index; 3031 unsigned int index;
3030 //Step 1. Find syncinfo in Local file and create if not existent. 3032 //Step 1. Find syncinfo in Local file and create if not existent.
3031 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3033 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3032 if (found == false) 3034 if (found == false)
3033 { 3035 {
3034 PwMSyncItem newSyncItemLocal; 3036 PwMSyncItem newSyncItemLocal;
3035 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); 3037 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1();
3036 newSyncItemLocal.lastSyncDate = mLastSync; 3038 newSyncItemLocal.lastSyncDate = mLastSync;
3037 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 3039 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
3038 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3040 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3039 if (found == false) { 3041 if (found == false) {
3040 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 3042 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
3041 return e_syncError; 3043 return e_syncError;
3042 } 3044 }
3043 } 3045 }
3044 3046
3045 syncItemLocal = syncLocal->getSyncDataEntry(index); 3047 syncItemLocal = syncLocal->getSyncDataEntry(index);
3046 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); 3048 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
3047 3049
3048 //Step 2. Find syncinfo in remote file and create if not existent. 3050 //Step 2. Find syncinfo in remote file and create if not existent.
3049 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3051 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3050 if (found == false) 3052 if (found == false)
3051 { 3053 {
3052 qDebug("FULLDATE 1"); 3054 qDebug("FULLDATE 1");
3053 fullDateRange = true; 3055 fullDateRange = true;
3054 PwMSyncItem newSyncItemRemote; 3056 PwMSyncItem newSyncItemRemote;
3055 newSyncItemRemote.syncName = mCurrentSyncName.latin1(); 3057 newSyncItemRemote.syncName = mCurrentSyncName.latin1();
3056 newSyncItemRemote.lastSyncDate = mLastSync; 3058 newSyncItemRemote.lastSyncDate = mLastSync;
3057 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 3059 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
3058 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3060 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3059 if (found == false) { 3061 if (found == false) {
3060 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 3062 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
3061 return e_syncError; 3063 return e_syncError;
3062 } 3064 }
3063 } 3065 }
3064 3066
3065 syncItemRemote = syncRemote->getSyncDataEntry(index); 3067 syncItemRemote = syncRemote->getSyncDataEntry(index);
3066 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); 3068 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
3067 //and remove the found entry here. We will reenter it later again. 3069 //and remove the found entry here. We will reenter it later again.
3068 //US syncRemote->delSyncDataEntry(index, true); 3070 //US syncRemote->delSyncDataEntry(index, true);
3069 3071
3070 3072
3071 if ( syncItemLocal->lastSyncDate == mLastSync ) { 3073 if ( syncItemLocal->lastSyncDate == mLastSync ) {
3072 qDebug("FULLDATE 2"); 3074 qDebug("FULLDATE 2");
3073 fullDateRange = true; 3075 fullDateRange = true;
3074 } 3076 }
3075 3077
3076 if ( ! fullDateRange ) { 3078 if ( ! fullDateRange ) {
3077 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 3079 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
3078 3080
3079 fullDateRange = true; 3081 fullDateRange = true;
3080 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 3082 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
3081 } 3083 }
3082 } 3084 }
3083 // fullDateRange = true; // debug only! 3085 // fullDateRange = true; // debug only!
3084 if ( fullDateRange ) 3086 if ( fullDateRange )
3085 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 3087 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
3086 else 3088 else
3087 mLastSync = syncItemLocal->lastSyncDate; 3089 mLastSync = syncItemLocal->lastSyncDate;
3088 3090
3089 3091
3090 qDebug("*************************** "); 3092 qDebug("*************************** ");
3091 qDebug("mLastSync %s ",mLastSync.toString().latin1() ); 3093 qDebug("mLastSync %s ",mLastSync.toString().latin1() );
3092 QStringList er = syncRemote->getIDEntryList(); 3094 QStringList er = syncRemote->getIDEntryList();
3093 PwMDataItem* inRemote ;//= er.first(); 3095 PwMDataItem* inRemote ;//= er.first();
3094 PwMDataItem* inLocal; 3096 PwMDataItem* inLocal;
3095 unsigned int catLocal, indexLocal; 3097 unsigned int catLocal, indexLocal;
3096 unsigned int catRemote, indexRemote; 3098 unsigned int catRemote, indexRemote;
3097 3099
3098 QString uid; 3100 QString uid;
3099 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 3101 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
3100 3102
3101 int modulo = (er.count()/10)+1; 3103 int modulo = (er.count()/10)+1;
3102 unsigned int incCounter = 0; 3104 unsigned int incCounter = 0;
3103 while ( incCounter < er.count()) { 3105 while ( incCounter < er.count()) {
3104 if (manager->isProgressBarCanceled()) 3106 if (manager->isProgressBarCanceled())
3105 return e_syncError; 3107 return e_syncError;
3106 if ( incCounter % modulo == 0 ) 3108 if ( incCounter % modulo == 0 )
3107 manager->showProgressBar(incCounter); 3109 manager->showProgressBar(incCounter);
3108 3110
3109 uid = er[ incCounter ]; 3111 uid = er[ incCounter ];
3110 qDebug("sync uid %s from remote file", uid.latin1()); 3112 qDebug("sync uid %s from remote file", uid.latin1());
3111 3113
3112 qApp->processEvents(); 3114 qApp->processEvents();
3113 3115
3114 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3116 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3115 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3117 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3116 PWM_ASSERT(inRemote); 3118 PWM_ASSERT(inRemote);
3117 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3119 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3118 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3120 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3119 qDebug("take %d %s ", take, inLocal->desc.c_str()); 3121 qDebug("take %d %s ", take, inLocal->desc.c_str());
3120 if ( take == 3 ) 3122 if ( take == 3 )
3121 return e_syncError; 3123 return e_syncError;
3122 if ( take == 1 ) {// take local 3124 if ( take == 1 ) {// take local
3123 int oldlistpos = inRemote->listViewPos; 3125 inRemote->syncItem(*inLocal, mSyncLauncher);
3124 (*inRemote) = (*inLocal);
3125 inRemote->listViewPos = oldlistpos;
3126 ++changedRemote; 3126 ++changedRemote;
3127 } else { // take == 2 take remote 3127 } else { // take == 2 take remote
3128 int oldlistpos = inLocal->listViewPos; 3128 inLocal->syncItem(*inRemote, mSyncLauncher);
3129 (*inLocal) = (*inRemote);
3130 inLocal->listViewPos = oldlistpos;
3131 ++changedLocal; 3129 ++changedLocal;
3132 } 3130 }
3133 } 3131 }
3134 } else { // no conflict 3132 } else { // no conflict
3135 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3133 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3136 inRemote->meta.update = modifiedSync; 3134 inRemote->meta.update = modifiedSync;
3137 3135
3138 //first check if we have a matching category in the local file 3136 //first check if we have a matching category in the local file
3139 const string* remotecat = syncRemote->getCategory(catRemote); 3137 const string* remotecat = syncRemote->getCategory(catRemote);
3140 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3138 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3141 3139
3142 ++addedPasswordsLocal; 3140 ++addedPasswordsLocal;
3143 } else { 3141 } else {
3144 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3142 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3145 syncRemote->delEntry(catRemote, indexRemote, true); 3143 syncRemote->delEntry(catRemote, indexRemote, true);
3146 ++deletedPasswordsRemote; 3144 ++deletedPasswordsRemote;
3147 } 3145 }
3148 } 3146 }
3149 3147
3150 ++incCounter; 3148 ++incCounter;
3151 } 3149 }
3152 3150
3153 3151
3154 er.clear(); 3152 er.clear();
3155 QStringList el = syncLocal->getIDEntryList(); 3153 QStringList el = syncLocal->getIDEntryList();
3156 modulo = (el.count()/10)+1; 3154 modulo = (el.count()/10)+1;
3157 3155
3158 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3156 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3159 incCounter = 0; 3157 incCounter = 0;
3160 while ( incCounter < el.count()) { 3158 while ( incCounter < el.count()) {
3161 qApp->processEvents(); 3159 qApp->processEvents();
3162 if (manager->isProgressBarCanceled()) 3160 if (manager->isProgressBarCanceled())
3163 return e_syncError; 3161 return e_syncError;
3164 if ( incCounter % modulo == 0 ) 3162 if ( incCounter % modulo == 0 )
3165 manager->showProgressBar(incCounter); 3163 manager->showProgressBar(incCounter);
3166 uid = el[ incCounter ]; 3164 uid = el[ incCounter ];
3167 qDebug("sync uid %s from local file", uid.latin1()); 3165 qDebug("sync uid %s from local file", uid.latin1());
3168 3166
3169 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3167 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3170 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3168 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3171 PWM_ASSERT(inLocal); 3169 PWM_ASSERT(inLocal);
3172 3170
3173 if ( inRemote == 0 ) { 3171 if ( inRemote == 0 ) {
3174 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3172 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3175 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3173 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3176 syncLocal->delEntry(catLocal, indexLocal, true); 3174 syncLocal->delEntry(catLocal, indexLocal, true);
3177 ++deletedPasswordsLocal; 3175 ++deletedPasswordsLocal;
3178 } else { 3176 } else {
3179 if ( ! manager->mWriteBackExistingOnly ) { 3177 if ( ! manager->mWriteBackExistingOnly ) {
3180 ++addedPasswordsRemote; 3178 ++addedPasswordsRemote;
3181 inLocal->meta.update = modifiedSync; 3179 inLocal->meta.update = modifiedSync;
3182 3180
3183 //first check if we have a matching category in the remote file 3181 //first check if we have a matching category in the remote file
3184 const string* localcat = syncLocal->getCategory(catLocal); 3182 const string* localcat = syncLocal->getCategory(catLocal);
3185 3183
3186 PwMDataItem newEntry; 3184 PwMDataItem newEntry;
3187 newEntry = *inLocal; 3185 newEntry = *inLocal;
3188 inRemote = &newEntry; 3186 inRemote = &newEntry;
3189 3187
3190 //USsyncRemote->insertAddressee( inRemote, false ); 3188 //USsyncRemote->insertAddressee( inRemote, false );
3191 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 3189 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
3192 3190
3193 } 3191 }
3194 } 3192 }
3195 3193
3196 } 3194 }
3197 ++incCounter; 3195 ++incCounter;
3198 } 3196 }
3199 el.clear(); 3197 el.clear();
3200 manager->hideProgressBar(); 3198 manager->hideProgressBar();
3201 3199
3202 // Now write the info back into the sync data space of the files 3200 // Now write the info back into the sync data space of the files
3203 3201
3204 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 3202 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
3205 // get rid of micro seconds 3203 // get rid of micro seconds
3206 QTime t = mLastSync.time(); 3204 QTime t = mLastSync.time();
3207 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3205 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3208 3206
3209 3207
3210 syncItemLocal->lastSyncDate = mLastSync; 3208 syncItemLocal->lastSyncDate = mLastSync;
3211 syncItemRemote->lastSyncDate = mLastSync; 3209 syncItemRemote->lastSyncDate = mLastSync;
3212 3210
3213 QString mes; 3211 QString mes;
3214 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); 3212 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote );
3215 if ( manager->mShowSyncSummary ) { 3213 if ( manager->mShowSyncSummary ) {
3216 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3214 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3217 } 3215 }
3218 qDebug( mes ); 3216 qDebug( mes );
3219 return e_success; 3217 return e_success;
3220} 3218}
3221 3219
3222 3220
3223int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3221int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3224{ 3222{
3225 // 0 equal 3223 // 0 equal
3226 // 1 take local 3224 // 1 take local
3227 // 2 take remote 3225 // 2 take remote
3228 // 3 cancel 3226 // 3 cancel
3229 QDateTime localMod = local->meta.update; 3227 QDateTime localMod = local->meta.update;
3230 QDateTime remoteMod = remote->meta.update; 3228 QDateTime remoteMod = remote->meta.update;
3231 3229
3232 if ( localMod == remoteMod ) 3230 if ( localMod == remoteMod )
3233 return 0; 3231 return 0;
3234 3232
3235 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3233 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3236 3234
3237 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3235 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3238 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3236 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3239 //full = true; //debug only 3237 //full = true; //debug only
3240 if ( full ) { 3238 if ( full ) {
3241 bool equ = ( (*local) == (*remote) ); 3239 bool equ = ( (*local) == (*remote) );
3242 if ( equ ) { 3240 if ( equ ) {
3243 //qDebug("equal "); 3241 //qDebug("equal ");
3244 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3242 if ( mode < SYNC_PREF_FORCE_LOCAL )
3245 return 0; 3243 return 0;
3246 3244
3247 }//else //debug only 3245 }//else //debug only
3248 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); 3246 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
3249 } 3247 }
3250 3248
3251 int result; 3249 int result;
3252 bool localIsNew; 3250 bool localIsNew;
3253 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 3251 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
3254 3252
3255 if ( full && mode < SYNC_PREF_NEWEST ) 3253 if ( full && mode < SYNC_PREF_NEWEST )
3256 mode = SYNC_PREF_ASK; 3254 mode = SYNC_PREF_ASK;
3257 3255
3258 switch( mode ) { 3256 switch( mode ) {
3259 case SYNC_PREF_LOCAL: 3257 case SYNC_PREF_LOCAL:
3260 if ( lastSync > remoteMod ) 3258 if ( lastSync > remoteMod )
3261 return 1; 3259 return 1;
3262 if ( lastSync > localMod ) 3260 if ( lastSync > localMod )
3263 return 2; 3261 return 2;
3264 return 1; 3262 return 1;
3265 break; 3263 break;
3266 case SYNC_PREF_REMOTE: 3264 case SYNC_PREF_REMOTE:
3267 if ( lastSync > remoteMod ) 3265 if ( lastSync > remoteMod )
3268 return 1; 3266 return 1;
3269 if ( lastSync > localMod ) 3267 if ( lastSync > localMod )
3270 return 2; 3268 return 2;
3271 return 2; 3269 return 2;
3272 break; 3270 break;
3273 case SYNC_PREF_NEWEST: 3271 case SYNC_PREF_NEWEST:
3274 if ( localMod > remoteMod ) 3272 if ( localMod > remoteMod )
3275 return 1; 3273 return 1;
3276 else 3274 else
3277 return 2; 3275 return 2;
3278 break; 3276 break;
3279 case SYNC_PREF_ASK: 3277 case SYNC_PREF_ASK:
3280 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3278 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3281 if ( lastSync > remoteMod ) 3279 if ( lastSync > remoteMod )
3282 return 1; 3280 return 1;
3283 if ( lastSync > localMod ) 3281 if ( lastSync > localMod )
3284 return 2; 3282 return 2;
3285 localIsNew = localMod >= remoteMod; 3283 localIsNew = localMod >= remoteMod;
3286 //qDebug("conflict! ************************************** "); 3284 //qDebug("conflict! ************************************** ");
3287 { 3285 {
3288 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3286 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3289 result = acd.executeD(localIsNew); 3287 result = acd.executeD(localIsNew);
3290 return result; 3288 return result;
3291 } 3289 }
3292 break; 3290 break;
3293 case SYNC_PREF_FORCE_LOCAL: 3291 case SYNC_PREF_FORCE_LOCAL:
3294 return 1; 3292 return 1;
3295 break; 3293 break;
3296 case SYNC_PREF_FORCE_REMOTE: 3294 case SYNC_PREF_FORCE_REMOTE:
3297 return 2; 3295 return 2;
3298 break; 3296 break;
3299 3297
3300 default: 3298 default:
3301 // SYNC_PREF_TAKE_BOTH not implemented 3299 // SYNC_PREF_TAKE_BOTH not implemented
3302 break; 3300 break;
3303 } 3301 }
3304 return 0; 3302 return 0;
3305} 3303}
3306 3304
3307void PwMDoc::removeSyncInfo( QString syncProfile) 3305void PwMDoc::removeSyncInfo( QString syncProfile)
3308{ 3306{
3309 qDebug("PwMDoc::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1()); 3307 qDebug("PwMDoc::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1());
3310} 3308}
3311 3309
3312 3310
3313//this are the overwritten callbackmethods from the syncinterface 3311//this are the overwritten callbackmethods from the syncinterface
3314bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3312bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3315{ 3313{
3316 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3314 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3317 3315
3318 //1) unlock local file first if necessary (ask for password) 3316 //1) unlock local file first if necessary (ask for password)
3319 if (this->isDeepLocked()) { 3317 if (this->isDeepLocked()) {
3320 PwMerror ret = this->deepLock(false); 3318 PwMerror ret = this->deepLock(false);
3321 if (ret != e_success) 3319 if (ret != e_success)
3322 return false; 3320 return false;
3323 } 3321 }
3324 3322
3325 //2) construct and open a new doc on the stack(automatic cleanup of remote file). 3323 //2) construct and open a new doc on the stack(automatic cleanup of remote file).
3326 PwMDoc syncTarget(this, "synctarget"); 3324 PwMDoc syncTarget(this, "synctarget");
3327 PwMDoc* pSyncTarget = &syncTarget; 3325 PwMDoc* pSyncTarget = &syncTarget;
3328 3326
3329 3327
3330 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); 3328 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3331 3329
3332 if (err == e_alreadyOpen) { 3330 if (err == e_alreadyOpen) {
3333 PwMDocList::listItem li; 3331 PwMDocList::listItem li;
3334 if (getOpenDocList()->find(filename.latin1(), &li)) 3332 if (getOpenDocList()->find(filename.latin1(), &li))
3335 pSyncTarget = li.doc; 3333 pSyncTarget = li.doc;
3336 else { 3334 else {
3337 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3335 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3338 return false; 3336 return false;
3339 } 3337 }
3340 } 3338 }
3341 else if (err != e_success) { 3339 else if (err != e_success) {
3342 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3340 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3343 return false; 3341 return false;
3344 } 3342 }
3345 3343
3346 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3344 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3347 3345
3348 3346
3349 //3) unlock remote file first if necessary (ask for password) 3347 //3) unlock remote file first if necessary (ask for password)
3350 if (pSyncTarget->isDeepLocked()) { 3348 if (pSyncTarget->isDeepLocked()) {
3351 PwMerror ret = pSyncTarget->deepLock(false); 3349 PwMerror ret = pSyncTarget->deepLock(false);
3352 if (ret != e_success) 3350 if (ret != e_success)
3353 return false; 3351 return false;
3354 } 3352 }
3355 3353
3356 3354
3357 err = syncronize(manager, this, pSyncTarget, mode ); 3355 err = syncronize(manager, this, pSyncTarget, mode );
3358 3356
3359 if (err == e_success) { 3357 if (err == e_success) {
3360 if ( manager->mWriteBackFile ){ 3358 if ( manager->mWriteBackFile ){
3361 qDebug("Saving remote PWManager file"); 3359 qDebug("Saving remote PWManager file");
3362 err = pSyncTarget->saveDoc(conf()->confGlobCompression()); 3360 err = pSyncTarget->saveDoc(conf()->confGlobCompression());
3363 if (err != e_success) { 3361 if (err != e_success) {
3364 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); 3362 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
3365 return false; 3363 return false;
3366 } 3364 }
3367 } 3365 }
3368 3366
3369 flagDirty(); 3367 flagDirty();
3370 return true; 3368 return true;
3371 } 3369 }
3372 else { 3370 else {
3373 return false; 3371 return false;
3374 } 3372 }
3375} 3373}
3376 3374
3377#endif 3375#endif
3378 3376
3379 3377
3380bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) 3378bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
3381{ 3379{
3382 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), 3380 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
3383 end = dti.syncDta.end(); 3381 end = dti.syncDta.end();
3384 3382
3385 while (i != end) { 3383 while (i != end) {
3386 if ((*i).syncName == syncname.latin1()) { 3384 if ((*i).syncName == syncname.latin1()) {
3387 if (index) { 3385 if (index) {
3388 *index = i - dti.syncDta.begin(); 3386 *index = i - dti.syncDta.begin();
3389 } 3387 }
3390 return true; 3388 return true;
3391 } 3389 }
3392 ++i; 3390 ++i;
3393 } 3391 }
3394 return false; 3392 return false;
3395}; 3393};
3396 3394
3397/** add new syncdataentry */ 3395/** add new syncdataentry */
3398PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) 3396PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
3399{ 3397{
3400 PWM_ASSERT(d); 3398 PWM_ASSERT(d);
3401 3399
3402 if (isDeepLocked()) { 3400 if (isDeepLocked()) {
3403 PwMerror ret; 3401 PwMerror ret;
3404 ret = deepLock(false); 3402 ret = deepLock(false);
3405 if (ret != e_success) 3403 if (ret != e_success)
3406 return e_lock; 3404 return e_lock;
3407 } 3405 }
3408 unsigned int index; 3406 unsigned int index;
3409 3407
3410 const QString tmp = d->syncName.c_str(); 3408 const QString tmp = d->syncName.c_str();
3411 bool exists = findSyncData(d->syncName.c_str(), &index); 3409 bool exists = findSyncData(d->syncName.c_str(), &index);
3412 3410
3413 if (exists == true) { 3411 if (exists == true) {
3414 // DOH! We found this entry. 3412 // DOH! We found this entry.
3415 return e_entryExists; 3413 return e_entryExists;
3416 } 3414 }
3417 3415
3418 dti.syncDta.push_back(*d); 3416 dti.syncDta.push_back(*d);
3419 3417
3420 if (!dontFlagDirty) 3418 if (!dontFlagDirty)
3421 flagDirty(); 3419 flagDirty();
3422 return e_success; 3420 return e_success;
3423} 3421}
3424 3422
3425 3423
3426 3424
3427/** delete syncdata entry */ 3425/** delete syncdata entry */
3428bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) 3426bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty)
3429{ 3427{
3430 if (isDeepLocked()) 3428 if (isDeepLocked())
3431 return false; 3429 return false;
3432 if (index > dti.syncDta.size() - 1) 3430 if (index > dti.syncDta.size() - 1)
3433 return false; 3431 return false;
3434 3432
3435 // delete entry 3433 // delete entry
3436 dti.syncDta.erase(dti.syncDta.begin() + index); 3434 dti.syncDta.erase(dti.syncDta.begin() + index);
3437 3435
3438 if (!dontFlagDirty) 3436 if (!dontFlagDirty)
3439 flagDirty(); 3437 flagDirty();
3440 return true; 3438 return true;
3441} 3439}
3442 3440
3443 3441
3444PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) 3442PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index)
3445{ 3443{
3446 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3444 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3447 catend = dti.dta.end(); 3445 catend = dti.dta.end();
3448 3446
3449 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3447 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3450 3448
3451 while (catcounter != catend) { 3449 while (catcounter != catend) {
3452 entrBegin = catcounter->d.begin(); 3450 entrBegin = catcounter->d.begin();
3453 entrEnd = catcounter->d.end(); 3451 entrEnd = catcounter->d.end();
3454 entrI = entrBegin; 3452 entrI = entrBegin;
3455 while (entrI != entrEnd) { 3453 while (entrI != entrEnd) {
3456 if ((*entrI).meta.uniqueid == uid.latin1()) { 3454 if ((*entrI).meta.uniqueid == uid.latin1()) {
3457 if (category) 3455 if (category)
3458 *category = catcounter - dti.dta.begin(); 3456 *category = catcounter - dti.dta.begin();
3459 if (index) 3457 if (index)
3460 *index = entrI - entrBegin; 3458 *index = entrI - entrBegin;
3461 3459
3462 return &(*entrI); 3460 return &(*entrI);
3463 } 3461 }
3464 ++entrI; 3462 ++entrI;
3465 } 3463 }
3466 ++catcounter; 3464 ++catcounter;
3467 } 3465 }
3468 3466
3469 return 0; 3467 return 0;
3470} 3468}
3471 3469
3472QStringList PwMDoc::getIDEntryList() 3470QStringList PwMDoc::getIDEntryList()
3473{ 3471{
3474 QStringList results; 3472 QStringList results;
3475 3473
3476 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3474 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3477 catend = dti.dta.end(); 3475 catend = dti.dta.end();
3478 3476
3479 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3477 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3480 3478
3481 while (catcounter != catend) { 3479 while (catcounter != catend) {
3482 entrBegin = catcounter->d.begin(); 3480 entrBegin = catcounter->d.begin();
3483 entrEnd = catcounter->d.end(); 3481 entrEnd = catcounter->d.end();
3484 entrI = entrBegin; 3482 entrI = entrBegin;
3485 while (entrI != entrEnd) { 3483 while (entrI != entrEnd) {
3486 results.append( (*entrI).meta.uniqueid.c_str() ); 3484 results.append( (*entrI).meta.uniqueid.c_str() );
3487 ++entrI; 3485 ++entrI;
3488 } 3486 }
3489 ++catcounter; 3487 ++catcounter;
3490 } 3488 }
3491 3489
3492 return results; 3490 return results;
3493} 3491}
3494 3492
3495 3493
3496 3494
3497 3495
3498 3496
3499#ifndef PWM_EMBEDDED 3497#ifndef PWM_EMBEDDED
3500#include "pwmdoc.moc" 3498#include "pwmdoc.moc"
3501#endif 3499#endif
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index e419c24..09923ab 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -1,789 +1,809 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.1 of pwmanager 14 * This file is originaly based on version 1.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __PWMDOC_H 20#ifndef __PWMDOC_H
21#define __PWMDOC_H 21#define __PWMDOC_H
22#ifdef _WIN32_ 22#ifdef _WIN32_
23#define ssize_t unsigned int 23#define ssize_t unsigned int
24#endif 24#endif
25 #define PWM_FILE_VER (static_cast<char>(0x05)) 25 #define PWM_FILE_VER (static_cast<char>(0x05))
26 26
27 #define PWM_HASH_SHA1 (static_cast<char>(0x01)) 27 #define PWM_HASH_SHA1 (static_cast<char>(0x01))
28 #define PWM_HASH_SHA256 (static_cast<char>(0x02)) 28 #define PWM_HASH_SHA256 (static_cast<char>(0x02))
29 #define PWM_HASH_SHA384 (static_cast<char>(0x03)) 29 #define PWM_HASH_SHA384 (static_cast<char>(0x03))
30 #define PWM_HASH_SHA512 (static_cast<char>(0x04)) 30 #define PWM_HASH_SHA512 (static_cast<char>(0x04))
31 #define PWM_HASH_MD5 (static_cast<char>(0x05)) 31 #define PWM_HASH_MD5 (static_cast<char>(0x05))
32 #define PWM_HASH_RMD160 (static_cast<char>(0x06)) 32 #define PWM_HASH_RMD160 (static_cast<char>(0x06))
33 #define PWM_HASH_TIGER (static_cast<char>(0x07)) 33 #define PWM_HASH_TIGER (static_cast<char>(0x07))
34 34
35 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) 35 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01))
36 #define PWM_CRYPT_AES128(static_cast<char>(0x02)) 36 #define PWM_CRYPT_AES128(static_cast<char>(0x02))
37 #define PWM_CRYPT_AES192(static_cast<char>(0x03)) 37 #define PWM_CRYPT_AES192(static_cast<char>(0x03))
38 #define PWM_CRYPT_AES256(static_cast<char>(0x04)) 38 #define PWM_CRYPT_AES256(static_cast<char>(0x04))
39 #define PWM_CRYPT_3DES (static_cast<char>(0x05)) 39 #define PWM_CRYPT_3DES (static_cast<char>(0x05))
40 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) 40 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06))
41 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) 41 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07))
42 42
43 #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) 43 #define PWM_COMPRESS_NONE(static_cast<char>(0x00))
44 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) 44 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01))
45 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) 45 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02))
46 46
47 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) 47 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0)))
48 #define FILE_ID_HEADER "PWM_PASSWORD_FILE" 48 #define FILE_ID_HEADER "PWM_PASSWORD_FILE"
49 49
50 50
51#include "pwmexception.h" 51#include "pwmexception.h"
52#include "pwmdocui.h" 52#include "pwmdocui.h"
53 53
54#include <qobject.h> 54#include <qobject.h>
55#include <qtimer.h> 55#include <qtimer.h>
56#include <qdatetime.h> 56#include <qdatetime.h>
57 57
58#include <kprocess.h> 58#include <kprocess.h>
59 59
60#ifndef PWM_EMBEDDED 60#ifndef PWM_EMBEDDED
61#include "configuration.h" 61#include "configuration.h"
62#else 62#else
63#include <kapplication.h> 63#include <kapplication.h>
64#include <ksyncmanager.h> 64#include <ksyncmanager.h>
65#endif 65#endif
66 66
67#include <string> 67#include <string>
68#include <vector> 68#include <vector>
69#include <utility> 69#include <utility>
70 70
71using std::vector; 71using std::vector;
72using std::string; 72using std::string;
73using std::pair; 73using std::pair;
74 74
75/* used in findEntry() function */ 75/* used in findEntry() function */
76 #define SEARCH_IN_DESC (1) 76 #define SEARCH_IN_DESC (1)
77 #define SEARCH_IN_NAME (1 << 1) 77 #define SEARCH_IN_NAME (1 << 1)
78 #define SEARCH_IN_PW (1 << 2) 78 #define SEARCH_IN_PW (1 << 2)
79 #define SEARCH_IN_COMMENT(1 << 3) 79 #define SEARCH_IN_COMMENT(1 << 3)
80 #define SEARCH_IN_URL (1 << 4) 80 #define SEARCH_IN_URL (1 << 4)
81 #define SEARCH_IN_LAUNCHER(1 << 5) 81 #define SEARCH_IN_LAUNCHER(1 << 5)
82 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ 82 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \
83 SEARCH_IN_PW | SEARCH_IN_COMMENT| \ 83 SEARCH_IN_PW | SEARCH_IN_COMMENT| \
84 SEARCH_IN_URL| SEARCH_IN_LAUNCHER) 84 SEARCH_IN_URL| SEARCH_IN_LAUNCHER)
85 85
86/** document deeplocked. Data is out for lunch to disk */ 86/** document deeplocked. Data is out for lunch to disk */
87 #define DOC_STAT_DEEPLOCKED (1) 87 #define DOC_STAT_DEEPLOCKED (1)
88/** encrypted document on disk is dirty. data has to go to disk. */ 88/** encrypted document on disk is dirty. data has to go to disk. */
89 #define DOC_STAT_DISK_DIRTY (1 << 1) 89 #define DOC_STAT_DISK_DIRTY (1 << 1)
90/** we are using a chipcard to encrypt the data */ 90/** we are using a chipcard to encrypt the data */
91 #define DOC_STAT_USE_CHIPCARD (1 << 2) 91 #define DOC_STAT_USE_CHIPCARD (1 << 2)
92/** use "currentPw" to unlock. (This flag is set/unset by a timer) */ 92/** use "currentPw" to unlock. (This flag is set/unset by a timer) */
93 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) 93 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3)
94 94
95class PwMDoc; 95class PwMDoc;
96class PwMView; 96class PwMView;
97class QFile; 97class QFile;
98 98
99/* meta data for a PwMDataItem */ 99/* meta data for a PwMDataItem */
100struct PwMMetaData 100struct PwMMetaData
101{ 101{
102 PwMMetaData() 102 PwMMetaData()
103 : updateInt (0) 103 : updateInt (0)
104 { } 104 { }
105 /** creation date of the PwMDataItem to which 105 /** creation date of the PwMDataItem to which
106 * this meta data belongs. 106 * this meta data belongs.
107 */ 107 */
108 QDateTimecreate; 108 QDateTimecreate;
109 /** becomes valid on this date */ 109 /** becomes valid on this date */
110 QDateTimevalid; 110 QDateTimevalid;
111 /** expire date */ 111 /** expire date */
112 QDateTimeexpire; 112 QDateTimeexpire;
113 /** update date (last updated at this date) */ 113 /** update date (last updated at this date) */
114 QDateTimeupdate; 114 QDateTimeupdate;
115 /** update interval (in minutes). Time since the 115 /** update interval (in minutes). Time since the
116 * last update to remind the user to update the item. 116 * last update to remind the user to update the item.
117 * 0 disables. 117 * 0 disables.
118 */ 118 */
119 unsigned long updateInt; 119 unsigned long updateInt;
120 120
121 //US ENH: enhancements of the filestructure 121 //US ENH: enhancements of the filestructure
122 /* each entry gets a unique id assigned */ 122 /* each entry gets a unique id assigned */
123 string uniqueid; 123 string uniqueid;
124 124
125 125
126 void clear() 126 void clear()
127 { 127 {
128 create = QDateTime(); 128 create = QDateTime();
129 expire = QDateTime(); 129 expire = QDateTime();
130 update = QDateTime(); 130 update = QDateTime();
131 updateInt = 0; 131 updateInt = 0;
132 uniqueid = KApplication::randomString(8).latin1(); 132 uniqueid = KApplication::randomString(8).latin1();
133 } 133 }
134 134
135 inline bool isValid() const 135 inline bool isValid() const
136 { 136 {
137 if (valid.isNull()) 137 if (valid.isNull())
138 return true; 138 return true;
139 return (valid < QDateTime::currentDateTime()); 139 return (valid < QDateTime::currentDateTime());
140 } 140 }
141 inline bool isExpired() const 141 inline bool isExpired() const
142 { 142 {
143 if (expire.isNull()) 143 if (expire.isNull())
144 return false; 144 return false;
145 return (expire < QDateTime::currentDateTime()); 145 return (expire < QDateTime::currentDateTime());
146 } 146 }
147 inline bool isUpdateIntOver() const 147 inline bool isUpdateIntOver() const
148 { 148 {
149 if (updateInt == 0 || 149 if (updateInt == 0 ||
150 update.isNull()) 150 update.isNull())
151 return false; 151 return false;
152 QDateTime d(update); 152 QDateTime d(update);
153 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); 153 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime());
154 } 154 }
155}; 155};
156 156
157struct PwMDataItem 157struct PwMDataItem
158{ 158{
159 PwMDataItem() 159 PwMDataItem()
160 : lockStat (true) 160 : lockStat (true)
161 , listViewPos (-1) 161 , listViewPos (-1)
162 , binary (false) 162 , binary (false)
163 , rev (0) 163 , rev (0)
164 { } 164 { }
165 165
166 /** password description */ 166 /** password description */
167 stringdesc; 167 stringdesc;
168 /** user-name */ 168 /** user-name */
169 stringname; 169 stringname;
170 /** the password itself */ 170 /** the password itself */
171 stringpw; 171 stringpw;
172 /** some comment */ 172 /** some comment */
173 stringcomment; 173 stringcomment;
174 /** an URL string */ 174 /** an URL string */
175 stringurl; 175 stringurl;
176 /** launcher. Can be executed as a system() command */ 176 /** launcher. Can be executed as a system() command */
177 stringlauncher; 177 stringlauncher;
178 /** locking status. If locked (true), pw is not emitted through getEntry() */ 178 /** locking status. If locked (true), pw is not emitted through getEntry() */
179 boollockStat; 179 boollockStat;
180 /** position of this item in main "list-view" 180 /** position of this item in main "list-view"
181 * If -1, the position is not yet specified and should be appended to the list 181 * If -1, the position is not yet specified and should be appended to the list
182 */ 182 */
183 intlistViewPos; 183 intlistViewPos;
184 /** does this entry contain binary data? */ 184 /** does this entry contain binary data? */
185 bool binary; 185 bool binary;
186 /** meta data for this data item. */ 186 /** meta data for this data item. */
187 PwMMetaData meta; 187 PwMMetaData meta;
188 /** data revision counter. This counter can be used 188 /** data revision counter. This counter can be used
189 * to easily, efficiently determine if this data item 189 * to easily, efficiently determine if this data item
190 * has changed since some time. 190 * has changed since some time.
191 * This counter is incremented on every update. 191 * This counter is incremented on every update.
192 */ 192 */
193 unsigned int rev; 193 unsigned int rev;
194 194
195 void clear(bool clearMeta = true) 195 void clear(bool clearMeta = true)
196 { 196 {
197 /* NOTE: Don't use .clear() here to be 197 /* NOTE: Don't use .clear() here to be
198 * backward compatible with gcc-2 (Debian Woody) 198 * backward compatible with gcc-2 (Debian Woody)
199 */ 199 */
200 desc = ""; 200 desc = "";
201 name = ""; 201 name = "";
202 pw = ""; 202 pw = "";
203 comment = ""; 203 comment = "";
204 url = ""; 204 url = "";
205 launcher = ""; 205 launcher = "";
206 lockStat = true; 206 lockStat = true;
207 listViewPos = -1; 207 listViewPos = -1;
208 binary = false; 208 binary = false;
209 if (clearMeta) 209 if (clearMeta)
210 meta.clear(); 210 meta.clear();
211 } 211 }
212 //US ENH: we need this operator to compare two items if we have no unique ids 212 //US ENH: we need this operator to compare two items if we have no unique ids
213 //available. Generaly this happens before the first sync 213 //available. Generaly this happens before the first sync
214 214
215 bool PwMDataItem::operator==( const PwMDataItem &a ) const 215 bool PwMDataItem::operator==( const PwMDataItem &a ) const
216 { 216 {
217 //qDebug("oper==%s", a.desc.c_str()); 217 //qDebug("oper==%s", a.desc.c_str());
218 if ( desc != a.desc ) return false; 218 if ( desc != a.desc ) return false;
219 if ( name != a.name ) return false; 219 if ( name != a.name ) return false;
220 if ( pw != a.pw ) return false; 220 if ( pw != a.pw ) return false;
221 if ( comment != a.comment ) return false; 221 if ( comment != a.comment ) return false;
222 if ( url != a.url ) return false; 222 if ( url != a.url ) return false;
223 if ( launcher != a.launcher ) return false; 223 if ( launcher != a.launcher ) return false;
224 //all other field will not be checked. 224 //all other field will not be checked.
225 return true; 225 return true;
226 } 226 }
227
228 //US ENH: this sync method actually copies all values from the parameter like the =operator
229 //does with two exceptions: listViewPos will not be changed, and the launcher only if required.
230 bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true )
231 {
232 desc = a.desc;
233 name = a.name;
234 pw = a.pw;
235 comment = a.comment;
236 url = a.url;
237 if (syncLauncher == true)
238 launcher = a.launcher;
239 meta = a.meta;
240 binary = a.binary;
241 lockStat = a.lockStat;
242 rev = a.rev;
243
244 return true;
245 }
246
227}; 247};
228 248
229struct PwMCategoryItem 249struct PwMCategoryItem
230{ 250{
231 /** all PwMDataItems (all passwords) within this category */ 251 /** all PwMDataItems (all passwords) within this category */
232 vector<PwMDataItem>d; 252 vector<PwMDataItem>d;
233 /** category name/description */ 253 /** category name/description */
234 string name; 254 string name;
235 255
236 void clear() 256 void clear()
237 { 257 {
238 d.clear(); 258 d.clear();
239 name = ""; 259 name = "";
240 } 260 }
241}; 261};
242 262
243struct PwMSyncItem 263struct PwMSyncItem
244{ 264{
245 string syncName; 265 string syncName;
246 QDateTime lastSyncDate; 266 QDateTime lastSyncDate;
247 267
248 void clear() 268 void clear()
249 { 269 {
250 lastSyncDate = QDateTime(); 270 lastSyncDate = QDateTime();
251 syncName = ""; 271 syncName = "";
252 } 272 }
253}; 273};
254 274
255struct PwMItem 275struct PwMItem
256{ 276{
257 vector<PwMCategoryItem> dta; 277 vector<PwMCategoryItem> dta;
258 vector<PwMSyncItem> syncDta; 278 vector<PwMSyncItem> syncDta;
259 279
260 void clear() 280 void clear()
261 { 281 {
262 dta.clear(); 282 dta.clear();
263 syncDta.clear(); 283 syncDta.clear();
264 } 284 }
265}; 285};
266 286
267 287
268/** "Function Object" for sort()ing PwMDataItem::listViewPos */ 288/** "Function Object" for sort()ing PwMDataItem::listViewPos */
269class dta_lvp_greater 289class dta_lvp_greater
270{ 290{
271public: 291public:
272 bool operator() (const pair<unsigned int, unsigned int> &d1, 292 bool operator() (const pair<unsigned int, unsigned int> &d1,
273 const pair<unsigned int, unsigned int> &d2) 293 const pair<unsigned int, unsigned int> &d2)
274 { 294 {
275 return d1.second > d2.second; 295 return d1.second > d2.second;
276 } 296 }
277}; 297};
278 298
279/** list of PwMDoc documents and it's IDs */ 299/** list of PwMDoc documents and it's IDs */
280class PwMDocList 300class PwMDocList
281{ 301{
282public: 302public:
283 struct listItem 303 struct listItem
284 { 304 {
285 /** document filename (known as ID, here) */ 305 /** document filename (known as ID, here) */
286 string docId; 306 string docId;
287 /** pointer to the document class */ 307 /** pointer to the document class */
288 PwMDoc *doc; 308 PwMDoc *doc;
289 }; 309 };
290 310
291 PwMDocList() {} 311 PwMDocList() {}
292 312
293 /** add a new item to the list */ 313 /** add a new item to the list */
294 void add(PwMDoc *doc, const string &id); 314 void add(PwMDoc *doc, const string &id);
295 /** changes the contents of an existing item */ 315 /** changes the contents of an existing item */
296 void edit(PwMDoc *doc, const string &newId); 316 void edit(PwMDoc *doc, const string &newId);
297 /** remove the given item */ 317 /** remove the given item */
298 void del(PwMDoc *doc); 318 void del(PwMDoc *doc);
299 /** get the item at index */ 319 /** get the item at index */
300 listItem getAt(int index) 320 listItem getAt(int index)
301 { return docList[index]; } 321 { return docList[index]; }
302 /** find an entry with this id */ 322 /** find an entry with this id */
303 bool find(const string &id, listItem *ret = 0); 323 bool find(const string &id, listItem *ret = 0);
304 /** returns a copy of the list */ 324 /** returns a copy of the list */
305 const vector<listItem>* getList() const 325 const vector<listItem>* getList() const
306 { return &docList; } 326 { return &docList; }
307 327
308 328
309 /** returns a new unique number to extend the name of 329 /** returns a new unique number to extend the name of
310 * an unnamed document. 330 * an unnamed document.
311 */ 331 */
312 static unsigned int getNewUnnamedNumber() 332 static unsigned int getNewUnnamedNumber()
313 { return unnamedDocCnt++; } 333 { return unnamedDocCnt++; }
314 334
315protected: 335protected:
316 /* Hm, I think we shouldn't really use a "list" here, should we? 336 /* Hm, I think we shouldn't really use a "list" here, should we?
317 * So I decided to actually use a vector. 337 * So I decided to actually use a vector.
318 */ 338 */
319 vector<listItem> docList; 339 vector<listItem> docList;
320 /** This value is used to get a new number for yet unnamed 340 /** This value is used to get a new number for yet unnamed
321 * documents. It is incremented on every request. So it's 341 * documents. It is incremented on every request. So it's
322 * theoretically possible to overflow it, but... :) 342 * theoretically possible to overflow it, but... :)
323 */ 343 */
324 static unsigned int unnamedDocCnt; 344 static unsigned int unnamedDocCnt;
325}; 345};
326 346
327/** implements timers for the document */ 347/** implements timers for the document */
328class DocTimer : public QObject 348class DocTimer : public QObject
329{ 349{
330 Q_OBJECT 350 Q_OBJECT
331public: 351public:
332 enum TimerIDs 352 enum TimerIDs
333 { 353 {
334 id_mpwTimer, 354 id_mpwTimer,
335 id_autoLockTimer, 355 id_autoLockTimer,
336 id_metaCheckTimer 356 id_metaCheckTimer
337 }; 357 };
338 358
339public: 359public:
340 DocTimer(PwMDoc *_doc); 360 DocTimer(PwMDoc *_doc);
341 ~DocTimer(); 361 ~DocTimer();
342 362
343 /** start the timer */ 363 /** start the timer */
344 void start(TimerIDs timer); 364 void start(TimerIDs timer);
345 /** stop the timer */ 365 /** stop the timer */
346 void stop(TimerIDs timer); 366 void stop(TimerIDs timer);
347 /** get the lock for a timer. 367 /** get the lock for a timer.
348 * This lock is a recursive lock. When a lock is 368 * This lock is a recursive lock. When a lock is
349 * held, the timer will be stopped and timeout is 369 * held, the timer will be stopped and timeout is
350 * guaranteed to not happen 370 * guaranteed to not happen
351 */ 371 */
352 void getLock(TimerIDs timer); 372 void getLock(TimerIDs timer);
353 /** put a recursive timer lock */ 373 /** put a recursive timer lock */
354 void putLock(TimerIDs timer); 374 void putLock(TimerIDs timer);
355 375
356protected slots: 376protected slots:
357 /** timeout slot for the mpw timer */ 377 /** timeout slot for the mpw timer */
358 void mpwTimeout(); 378 void mpwTimeout();
359 /** timeout slot for the autoLock timer */ 379 /** timeout slot for the autoLock timer */
360 void autoLockTimeout(); 380 void autoLockTimeout();
361 /** timeout slot for the metaCheck timer */ 381 /** timeout slot for the metaCheck timer */
362 void metaCheckTimeout(); 382 void metaCheckTimeout();
363 383
364protected: 384protected:
365 /** pointer to the document associated with this timer. */ 385 /** pointer to the document associated with this timer. */
366 PwMDoc *doc; 386 PwMDoc *doc;
367 /** timer object for mpw timer */ 387 /** timer object for mpw timer */
368 QTimer *mpwTimer; 388 QTimer *mpwTimer;
369 /** timer object for the autoLock timer */ 389 /** timer object for the autoLock timer */
370 QTimer *autoLockTimer; 390 QTimer *autoLockTimer;
371 /** timer object for the metaCheck timer */ 391 /** timer object for the metaCheck timer */
372 QTimer *metaCheckTimer; 392 QTimer *metaCheckTimer;
373 /** lock counter for the mpw timer */ 393 /** lock counter for the mpw timer */
374 unsigned int mpwLock; 394 unsigned int mpwLock;
375 /** lock counter for the autoLock timer */ 395 /** lock counter for the autoLock timer */
376 unsigned int autoLockLock; 396 unsigned int autoLockLock;
377 /** lock counter for the metaCheck timer */ 397 /** lock counter for the metaCheck timer */
378 unsigned int metaCheckLock; 398 unsigned int metaCheckLock;
379}; 399};
380 400
381/** Document class for PwM */ 401/** Document class for PwM */
382//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. 402//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required.
383// But PwMDoc is handling the sync by itself. 403// But PwMDoc is handling the sync by itself.
384class PwMDoc : public PwMDocUi, public KSyncInterface 404class PwMDoc : public PwMDocUi, public KSyncInterface
385 405
386{ 406{
387 Q_OBJECT 407 Q_OBJECT
388 friend class DocTimer; 408 friend class DocTimer;
389 409
390public: 410public:
391 /** construtor */ 411 /** construtor */
392 PwMDoc(QObject* parent = 0, const char *name = 0); 412 PwMDoc(QObject* parent = 0, const char *name = 0);
393 /** destructor */ 413 /** destructor */
394 ~PwMDoc(); 414 ~PwMDoc();
395 415
396 /** returns a pointer to a list of all open documents */ 416 /** returns a pointer to a list of all open documents */
397 static PwMDocList* getOpenDocList() 417 static PwMDocList* getOpenDocList()
398 { return &openDocList; } 418 { return &openDocList; }
399 419
400 /** flag document dirty. dta changed */ 420 /** flag document dirty. dta changed */
401 void flagDirty() 421 void flagDirty()
402 { 422 {
403 setDocStatFlag(DOC_STAT_DISK_DIRTY); 423 setDocStatFlag(DOC_STAT_DISK_DIRTY);
404 emitDataChanged(this); 424 emitDataChanged(this);
405 } 425 }
406 /** modified? */ 426 /** modified? */
407 bool isDirty() 427 bool isDirty()
408 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } 428 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); }
409 /** save document to disk */ 429 /** save document to disk */
410 PwMerror saveDoc(char compress, const QString *file = 0); 430 PwMerror saveDoc(char compress, const QString *file = 0);
411 /** read document from file. 431 /** read document from file.
412 * "openLocked is must be set to either of these values: 432 * "openLocked is must be set to either of these values:
413 * 0 == open with all entries unlocked 433 * 0 == open with all entries unlocked
414 * 1 == open with all entries locked 434 * 1 == open with all entries locked
415 * 2 == open deep-locked 435 * 2 == open deep-locked
416 */ 436 */
417 PwMerror openDoc(const QString *file, int openLocked); 437 PwMerror openDoc(const QString *file, int openLocked);
418 /** export document to ascii-textfile */ 438 /** export document to ascii-textfile */
419 PwMerror exportToText(const QString *file); 439 PwMerror exportToText(const QString *file);
420 /** export document to gpasman / kpasman file */ 440 /** export document to gpasman / kpasman file */
421 PwMerror exportToGpasman(const QString *file); 441 PwMerror exportToGpasman(const QString *file);
422 /** import document from ascii-textfile */ 442 /** import document from ascii-textfile */
423 PwMerror importFromText(const QString *file, int format = -1); 443 PwMerror importFromText(const QString *file, int format = -1);
424 /** import document from gpasman / kpasman file */ 444 /** import document from gpasman / kpasman file */
425 PwMerror importFromGpasman(const QString *file); 445 PwMerror importFromGpasman(const QString *file);
426 /** add new entry */ 446 /** add new entry */
427 PwMerror addEntry(const QString &category, PwMDataItem *d, 447 PwMerror addEntry(const QString &category, PwMDataItem *d,
428 bool dontFlagDirty = false, bool updateMeta = true); 448 bool dontFlagDirty = false, bool updateMeta = true);
429 /** add new category. This function doesn't flag the document dirty! */ 449 /** add new category. This function doesn't flag the document dirty! */
430 PwMerror addCategory(const QString &category, unsigned int *categoryIndex, 450 PwMerror addCategory(const QString &category, unsigned int *categoryIndex,
431 bool checkIfExist = true); 451 bool checkIfExist = true);
432 /** rename an existing category */ 452 /** rename an existing category */
433 bool renameCategory(const QString &category, const QString &newName); 453 bool renameCategory(const QString &category, const QString &newName);
434 /** rename an existing category */ 454 /** rename an existing category */
435 bool renameCategory(unsigned int category, const QString &newName, 455 bool renameCategory(unsigned int category, const QString &newName,
436 bool dontFlagDirty = false); 456 bool dontFlagDirty = false);
437 /** delete an existing category */ 457 /** delete an existing category */
438 bool delCategory(const QString &category); 458 bool delCategory(const QString &category);
439 /** delete an existing category */ 459 /** delete an existing category */
440 bool delCategory(unsigned int category, bool dontFlagDirty = false); 460 bool delCategory(unsigned int category, bool dontFlagDirty = false);
441 /** returns a list of all category-names */ 461 /** returns a list of all category-names */
442 void getCategoryList(vector<string> *list); 462 void getCategoryList(vector<string> *list);
443 /** returns a list of all category-names */ 463 /** returns a list of all category-names */
444 void getCategoryList(QStringList *list); 464 void getCategoryList(QStringList *list);
445 /** returns a list of all entry-descs in the given category */ 465 /** returns a list of all entry-descs in the given category */
446 void getEntryList(const QString &category, QStringList *list); 466 void getEntryList(const QString &category, QStringList *list);
447 /** returns a list of all entry-descs in the given category */ 467 /** returns a list of all entry-descs in the given category */
448 void getEntryList(const QString &category, vector<string> *list); 468 void getEntryList(const QString &category, vector<string> *list);
449 /** returns a list of all entry-descs in the given category */ 469 /** returns a list of all entry-descs in the given category */
450 void getEntryList(unsigned int category, vector<string> *list); 470 void getEntryList(unsigned int category, vector<string> *list);
451 /** returns a list of all entry-descs in the given category */ 471 /** returns a list of all entry-descs in the given category */
452 void getEntryList(unsigned int category, QStringList *list); 472 void getEntryList(unsigned int category, QStringList *list);
453 /** delete entry */ 473 /** delete entry */
454 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); 474 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false);
455 /** delete entry */ 475 /** delete entry */
456 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); 476 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false);
457 /** edit entry */ 477 /** edit entry */
458 bool editEntry(const QString &oldCategory, const QString &newCategory, 478 bool editEntry(const QString &oldCategory, const QString &newCategory,
459 unsigned int index, PwMDataItem *d, bool updateMeta = true); 479 unsigned int index, PwMDataItem *d, bool updateMeta = true);
460 /** edit entry */ 480 /** edit entry */
461 bool editEntry(unsigned int oldCategory, const QString &newCategory, 481 bool editEntry(unsigned int oldCategory, const QString &newCategory,
462 unsigned int index, PwMDataItem *d, bool updateMeta = true); 482 unsigned int index, PwMDataItem *d, bool updateMeta = true);
463 /** finds the category with the "name" and return it's index */ 483 /** finds the category with the "name" and return it's index */
464 bool findCategory(const QString &name, unsigned int *index); 484 bool findCategory(const QString &name, unsigned int *index);
465 /** search for an entry "find" and check while searching only for 485 /** search for an entry "find" and check while searching only for
466 * the data-fields specified by "searchIn". To set the "searchIn" 486 * the data-fields specified by "searchIn". To set the "searchIn"
467 * value, we may use one or more of the SEARCH_IN_* defines at 487 * value, we may use one or more of the SEARCH_IN_* defines at
468 * the top of this header-file. It returns the positions of all 488 * the top of this header-file. It returns the positions of all
469 * matched entries in "foundPositions". If "breakAfterFound" is true, 489 * matched entries in "foundPositions". If "breakAfterFound" is true,
470 * the function terminates after the first occurence of the entry 490 * the function terminates after the first occurence of the entry
471 * and doesn't go on searching. So foundPositions->size() is never 491 * and doesn't go on searching. So foundPositions->size() is never
472 * > 1 if breakAfterFound is true. 492 * > 1 if breakAfterFound is true.
473 */ 493 */
474 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, 494 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
475 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 495 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
476 bool caseSensitive = true, bool exactWordMatch = true, 496 bool caseSensitive = true, bool exactWordMatch = true,
477 bool sortByLvp = false); 497 bool sortByLvp = false);
478 /** see the above funtion. This function allows to set the category by name. */ 498 /** see the above funtion. This function allows to set the category by name. */
479 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, 499 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
480 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 500 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
481 bool caseSensitive = true, bool exactWordMatch = true, 501 bool caseSensitive = true, bool exactWordMatch = true,
482 bool sortByLvp = false); 502 bool sortByLvp = false);
483 /** returns number of entries */ 503 /** returns number of entries */
484 unsigned int numEntries(const QString &category); 504 unsigned int numEntries(const QString &category);
485 unsigned int numEntries(unsigned int category) 505 unsigned int numEntries(unsigned int category)
486 { return dti.dta[category].d.size(); } 506 { return dti.dta[category].d.size(); }
487 /** returns number of categories */ 507 /** returns number of categories */
488 unsigned int numCategories() 508 unsigned int numCategories()
489 { return dti.dta.size(); } 509 { return dti.dta.size(); }
490 /** returns the name of the category at "index" */ 510 /** returns the name of the category at "index" */
491 const string* getCategory(unsigned int index) 511 const string* getCategory(unsigned int index)
492 { return (&(dti.dta[index].name)); } 512 { return (&(dti.dta[index].name)); }
493 513
494 /** returns the data of item at "index". 514 /** returns the data of item at "index".
495 * It unlocks the entry if it's locked and unlockIfLocked is true. 515 * It unlocks the entry if it's locked and unlockIfLocked is true.
496 * If the entry is locked, but unlockIfLocked is false, it'll not return 516 * If the entry is locked, but unlockIfLocked is false, it'll not return
497 * the pw. 517 * the pw.
498 */ 518 */
499 bool getEntry(const QString &category, unsigned int index, 519 bool getEntry(const QString &category, unsigned int index,
500 PwMDataItem *d, bool unlockIfLocked = false); 520 PwMDataItem *d, bool unlockIfLocked = false);
501 bool getEntry(unsigned int category, unsigned int index, 521 bool getEntry(unsigned int category, unsigned int index,
502 PwMDataItem *d, bool unlockIfLocked = false); 522 PwMDataItem *d, bool unlockIfLocked = false);
503 /** returns the comment-string by looking at the category 523 /** returns the comment-string by looking at the category
504 * and the listViewPos 524 * and the listViewPos
505 */ 525 */
506 PwMerror getCommentByLvp(const QString &category, int listViewPos, 526 PwMerror getCommentByLvp(const QString &category, int listViewPos,
507 string *foundComment); 527 string *foundComment);
508 /** checks if a password is already available. (currentPw) */ 528 /** checks if a password is already available. (currentPw) */
509 bool isPwAvailable() 529 bool isPwAvailable()
510 { return (currentPw != ""); } 530 { return (currentPw != ""); }
511 /** un/lock entry at "index". If needed, ask for password. */ 531 /** un/lock entry at "index". If needed, ask for password. */
512 bool lockAt(const QString &category, unsigned int index, 532 bool lockAt(const QString &category, unsigned int index,
513 bool lock = true); 533 bool lock = true);
514 bool lockAt(unsigned int category, unsigned int index, 534 bool lockAt(unsigned int category, unsigned int index,
515 bool lock = true); 535 bool lock = true);
516 /** returns the lock-status at "index" */ 536 /** returns the lock-status at "index" */
517 bool isLocked(const QString &category, unsigned int index); 537 bool isLocked(const QString &category, unsigned int index);
518 bool isLocked(unsigned int category, unsigned int index) 538 bool isLocked(unsigned int category, unsigned int index)
519 { return dti.dta[category].d[index].lockStat; } 539 { return dti.dta[category].d[index].lockStat; }
520 /** returns the deeplock status */ 540 /** returns the deeplock status */
521 bool isDeepLocked() 541 bool isDeepLocked()
522 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } 542 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); }
523 /** (un)lock all entries */ 543 /** (un)lock all entries */
524 bool lockAll(bool lock); 544 bool lockAll(bool lock);
525 /** unlocks all entries tempoarly. 545 /** unlocks all entries tempoarly.
526 * 1st NOTE: Be very careful with this function! :) 546 * 1st NOTE: Be very careful with this function! :)
527 * 2nd NOTE: After you have called unlockAll_Tempoary(); , 547 * 2nd NOTE: After you have called unlockAll_Tempoary(); ,
528 * please DON'T forget to call unlockAll_Tempoary(true); 548 * please DON'T forget to call unlockAll_Tempoary(true);
529 * _before_ the user (or someone else) is able to change 549 * _before_ the user (or someone else) is able to change
530 * the document! 550 * the document!
531 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary 551 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary
532 * unlocked! This will cause corruption. 552 * unlocked! This will cause corruption.
533 */ 553 */
534 bool unlockAll_tempoary(bool revert = false); 554 bool unlockAll_tempoary(bool revert = false);
535 /** deep-(un)locks the document. 555 /** deep-(un)locks the document.
536 * deep-locking writes all data to the file, deletes all data 556 * deep-locking writes all data to the file, deletes all data
537 * in memory, but doesn't close the document. 557 * in memory, but doesn't close the document.
538 * deep-locking is only available, if the user previously saved 558 * deep-locking is only available, if the user previously saved
539 * the doc to a file (with a password). 559 * the doc to a file (with a password).
540 * If "saveToFile" is false, it does NOT write the data to the file! 560 * If "saveToFile" is false, it does NOT write the data to the file!
541 */ 561 */
542 PwMerror deepLock(bool lock = true, bool saveToFile = true); 562 PwMerror deepLock(bool lock = true, bool saveToFile = true);
543 /** is unlockable without pw? */ 563 /** is unlockable without pw? */
544 bool unlockWoPw() 564 bool unlockWoPw()
545 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } 565 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); }
546 /** get the "currentPassword" */ 566 /** get the "currentPassword" */
547 const QString& getCurrentPw() 567 const QString& getCurrentPw()
548 { return currentPw; } 568 { return currentPw; }
549 /** open a window and request the user to change the mpw */ 569 /** open a window and request the user to change the mpw */
550 void changeCurrentPw(); 570 void changeCurrentPw();
551 /** set the "listViewPos" variable of "dta" */ 571 /** set the "listViewPos" variable of "dta" */
552 void setListViewPos(const QString &category, unsigned int index, 572 void setListViewPos(const QString &category, unsigned int index,
553 int pos); 573 int pos);
554 /** set the "listViewPos" variable of "dta" */ 574 /** set the "listViewPos" variable of "dta" */
555 void setListViewPos(unsigned int category, unsigned int index, 575 void setListViewPos(unsigned int category, unsigned int index,
556 int pos); 576 int pos);
557 /** get the "listViewPos" variable of "dta" */ 577 /** get the "listViewPos" variable of "dta" */
558 int getListViewPos(const QString &category, unsigned int index); 578 int getListViewPos(const QString &category, unsigned int index);
559 /** set the maximum number of entries allowed */ 579 /** set the maximum number of entries allowed */
560 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) 580 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES)
561 { maxEntries = num; } 581 { maxEntries = num; }
562 /** get the maximum number of entries allowed */ 582 /** get the maximum number of entries allowed */
563 unsigned int getMaxNumEntries() 583 unsigned int getMaxNumEntries()
564 { return maxEntries; } 584 { return maxEntries; }
565 /** ensure all listViewPos of all dta items are set. (are ! -1). 585 /** ensure all listViewPos of all dta items are set. (are ! -1).
566 * If there are some undefined entries, add them to the end of 586 * If there are some undefined entries, add them to the end of
567 * the listViewPos(itions). */ 587 * the listViewPos(itions). */
568 void ensureLvp(); 588 void ensureLvp();
569 /** execute the "launcher" of this entry */ 589 /** execute the "launcher" of this entry */
570 bool execLauncher(const QString &category, unsigned int entryIndex); 590 bool execLauncher(const QString &category, unsigned int entryIndex);
571 /** see above */ 591 /** see above */
572 bool execLauncher(unsigned int category, unsigned int entryIndex); 592 bool execLauncher(unsigned int category, unsigned int entryIndex);
573 /** open a browser with the URL-section of the given entry */ 593 /** open a browser with the URL-section of the given entry */
574 bool goToURL(const QString &category, unsigned int entryIndex); 594 bool goToURL(const QString &category, unsigned int entryIndex);
575 /** see above */ 595 /** see above */
576 bool goToURL(unsigned int category, unsigned int entryIndex); 596 bool goToURL(unsigned int category, unsigned int entryIndex);
577 /** returns true if there is no entry present in the document. 597 /** returns true if there is no entry present in the document.
578 * Note: The "default" Category is present everytime, so 598 * Note: The "default" Category is present everytime, so
579 * it's checked for it's entries. 599 * it's checked for it's entries.
580 */ 600 */
581 bool isDocEmpty() 601 bool isDocEmpty()
582 { 602 {
583 if (numCategories() > 1) 603 if (numCategories() > 1)
584 return false; 604 return false;
585 if (numEntries(0)) 605 if (numEntries(0))
586 return false; 606 return false;
587 return true; 607 return true;
588 } 608 }
589 /** returns the filename of this doc */ 609 /** returns the filename of this doc */
590 const QString& getFilename() 610 const QString& getFilename()
591 { return filename; } 611 { return filename; }
592 /** returns the title of the doc */ 612 /** returns the title of the doc */
593 QString getTitle(); 613 QString getTitle();
594 /** sets the list-view-pointer hold in the doc */ 614 /** sets the list-view-pointer hold in the doc */
595 void setListViewPointer(PwMView *_listView) 615 void setListViewPointer(PwMView *_listView)
596 { listView = _listView; } 616 { listView = _listView; }
597 /** returns the list-view-pointer */ 617 /** returns the list-view-pointer */
598 PwMView * getListViewPointer() 618 PwMView * getListViewPointer()
599 { return listView; } 619 { return listView; }
600 /** try to delete the doc. The user may be asked to save 620 /** try to delete the doc. The user may be asked to save
601 * the data. The user may cancel the whole operation. 621 * the data. The user may cancel the whole operation.
602 * false is returned, then. 622 * false is returned, then.
603 */ 623 */
604 bool tryDelete(); 624 bool tryDelete();
605 /** is the doc deleted? (with tryDelete() ) */ 625 /** is the doc deleted? (with tryDelete() ) */
606 bool isDeleted() 626 bool isDeleted()
607 { return deleted; } 627 { return deleted; }
608 /** returns the document timer object */ 628 /** returns the document timer object */
609 DocTimer * timer() 629 DocTimer * timer()
610 { return _timer; } 630 { return _timer; }
611 /** get a lock on the dataChanged signal. 631 /** get a lock on the dataChanged signal.
612 * If someone is holding a lock, the signal is not emitted. 632 * If someone is holding a lock, the signal is not emitted.
613 */ 633 */
614 void getDataChangedLock() 634 void getDataChangedLock()
615 { ++dataChangedLock; } 635 { ++dataChangedLock; }
616 /** put the dataChanged lock */ 636 /** put the dataChanged lock */
617 void putDataChangedLock() 637 void putDataChangedLock()
618 { --dataChangedLock; } 638 { --dataChangedLock; }
619 /** returns the revision count of the item at cat/index */ 639 /** returns the revision count of the item at cat/index */
620 unsigned int getEntryRevCnt(unsigned int category, unsigned int index) 640 unsigned int getEntryRevCnt(unsigned int category, unsigned int index)
621 { return dti.dta[category].d[index].rev; } 641 { return dti.dta[category].d[index].rev; }
622 /** returns a const pointer to the entries meta */ 642 /** returns a const pointer to the entries meta */
623 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) 643 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index)
624 { return &(dti.dta[category].d[index].meta); } 644 { return &(dti.dta[category].d[index].meta); }
625 /** is the entry at "category" "index" a binary entry? */ 645 /** is the entry at "category" "index" a binary entry? */
626 bool isBinEntry(unsigned int category, unsigned int index) 646 bool isBinEntry(unsigned int category, unsigned int index)
627 { return dti.dta[category].d[index].binary; } 647 { return dti.dta[category].d[index].binary; }
628 648
629public slots: 649public slots:
630 /** wrapper for PwMTray */ 650 /** wrapper for PwMTray */
631 void _deepUnlock(); 651 void _deepUnlock();
632 652
633signals: 653signals:
634 /** the data of the document has changed and must be updated 654 /** the data of the document has changed and must be updated
635 * in all views. 655 * in all views.
636 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! 656 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal!
637 */ 657 */
638 void dataChanged(PwMDoc *document); 658 void dataChanged(PwMDoc *document);
639 /** the document class is going to close. This signal may be 659 /** the document class is going to close. This signal may be
640 * used to nofify all views, that the user closed the document, 660 * used to nofify all views, that the user closed the document,
641 * so the views can go down, too. 661 * so the views can go down, too.
642 */ 662 */
643 void docClosed(PwMDoc *document); 663 void docClosed(PwMDoc *document);
644 /** somebody just opened the document */ 664 /** somebody just opened the document */
645 void docOpened(PwMDoc *document); 665 void docOpened(PwMDoc *document);
646 /** this document object just got created */ 666 /** this document object just got created */
647 void docCreated(PwMDoc *document); 667 void docCreated(PwMDoc *document);
648 668
649public: 669public:
650 /** emit the dataChanged signal after checking for a lock */ 670 /** emit the dataChanged signal after checking for a lock */
651 void emitDataChanged(PwMDoc *document) 671 void emitDataChanged(PwMDoc *document)
652 { 672 {
653 if (!dataChangedLock) 673 if (!dataChangedLock)
654 emit dataChanged(document); 674 emit dataChanged(document);
655 } 675 }
656 676
657protected: 677protected:
658 /** current file for this doc */ 678 /** current file for this doc */
659 QString filename; 679 QString filename;
660//US ENH: we need a place where we keep the syncentries. So I invented 680//US ENH: we need a place where we keep the syncentries. So I invented
661// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem 681// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem
662 /** holds all data */ 682 /** holds all data */
663 PwMItem dti; 683 PwMItem dti;
664 /** maximum number of entries */ 684 /** maximum number of entries */
665 unsigned int maxEntries; 685 unsigned int maxEntries;
666 /** currently used password to encrypt data */ 686 /** currently used password to encrypt data */
667 QString currentPw; 687 QString currentPw;
668 /** current global document status flags */ 688 /** current global document status flags */
669 unsigned int curDocStat; 689 unsigned int curDocStat;
670 /** browser process for goToURL() */ 690 /** browser process for goToURL() */
671 KProcess browserProc; 691 KProcess browserProc;
672 /** pointer to the list-view, using this document. 692 /** pointer to the list-view, using this document.
673 * As there can only be one list-view per doc, we 693 * As there can only be one list-view per doc, we
674 * don't need a list here. 694 * don't need a list here.
675 */ 695 */
676 PwMView *listView; 696 PwMView *listView;
677 /** unnamedNum is used to store the "unnamed counter" 697 /** unnamedNum is used to store the "unnamed counter"
678 * for this document, while it's unnamed. If it's 0, 698 * for this document, while it's unnamed. If it's 0,
679 * we have to get a new unique one. 699 * we have to get a new unique one.
680 */ 700 */
681 unsigned int unnamedNum; 701 unsigned int unnamedNum;
682 /** is this doc going to be deleted (executing in destructor context) */ 702 /** is this doc going to be deleted (executing in destructor context) */
683 bool deleted; 703 bool deleted;
684 /** document timer */ 704 /** document timer */
685 DocTimer *_timer; 705 DocTimer *_timer;
686 /** lock counter for the "dataChanged" signal */ 706 /** lock counter for the "dataChanged" signal */
687 unsigned int dataChangedLock; 707 unsigned int dataChangedLock;
688 708
689 /** list of all open documents */ 709 /** list of all open documents */
690 static PwMDocList openDocList; 710 static PwMDocList openDocList;
691 711
692protected: 712protected:
693 /** serialize "dta" and return it in "d". */ 713 /** serialize "dta" and return it in "d". */
694 bool serializeDta(string *d); 714 bool serializeDta(string *d);
695 /** de-serialize "d" and overwrite "dta" */ 715 /** de-serialize "d" and overwrite "dta" */
696 bool deSerializeDta(const string *d, bool entriesLocked); 716 bool deSerializeDta(const string *d, bool entriesLocked);
697 /** write header to file */ 717 /** write header to file */
698 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 718 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
699 QString *pw, QFile *f); 719 QString *pw, QFile *f);
700 /** write data-hash to file */ 720 /** write data-hash to file */
701 PwMerror writeDataHash(char dataHash, string *d, QFile *f); 721 PwMerror writeDataHash(char dataHash, string *d, QFile *f);
702 /** check header. Read header info and verify key-hash and filever. 722 /** check header. Read header info and verify key-hash and filever.
703 * returns length of header in "headerLength" */ 723 * returns length of header in "headerLength" */
704 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, 724 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress,
705 unsigned int *headerLength, char *dataHashType, 725 unsigned int *headerLength, char *dataHashType,
706 string *dataHash, QFile *f); 726 string *dataHash, QFile *f);
707 /** check the data-hash */ 727 /** check the data-hash */
708 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); 728 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream);
709 /** encrypt data "d" and write to "filename" */ 729 /** encrypt data "d" and write to "filename" */
710 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); 730 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo);
711 /** read data from file beginning at "pos", decrypt and return it */ 731 /** read data from file beginning at "pos", decrypt and return it */
712 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); 732 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f);
713 /** compress the data */ 733 /** compress the data */
714 bool compressDta(string *d, char algo); 734 bool compressDta(string *d, char algo);
715 /** uncompress the data */ 735 /** uncompress the data */
716 bool decompressDta(string *d, char algo); 736 bool decompressDta(string *d, char algo);
717 /** internal import function for a text-file generated by PwM. 737 /** internal import function for a text-file generated by PwM.
718 * If this is not a valid PwM-exported file, it returns e_fileFormat */ 738 * If this is not a valid PwM-exported file, it returns e_fileFormat */
719 PwMerror importText_PwM(const QString *file); 739 PwMerror importText_PwM(const QString *file);
720 /** PwM-text-import helper function to extract the name/pw/comment out 740 /** PwM-text-import helper function to extract the name/pw/comment out
721 * of one entry-line */ 741 * of one entry-line */
722 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); 742 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out);
723 /** compare two strings */ 743 /** compare two strings */
724 bool compareString(const string &s1, const string &s2, bool caseSensitive, 744 bool compareString(const string &s1, const string &s2, bool caseSensitive,
725 bool exactWordMatch); 745 bool exactWordMatch);
726 /** clears all document-data */ 746 /** clears all document-data */
727 void clearDoc(); 747 void clearDoc();
728 /** delete all empty categories */ 748 /** delete all empty categories */
729 void delAllEmptyCat(bool dontFlagDirty); 749 void delAllEmptyCat(bool dontFlagDirty);
730 /** set a document status flag */ 750 /** set a document status flag */
731 void setDocStatFlag(unsigned int statFlag) 751 void setDocStatFlag(unsigned int statFlag)
732 { curDocStat |= statFlag; } 752 { curDocStat |= statFlag; }
733 /** unset a document status flag */ 753 /** unset a document status flag */
734 void unsetDocStatFlag(unsigned int statFlag) 754 void unsetDocStatFlag(unsigned int statFlag)
735 { curDocStat &= ~statFlag; } 755 { curDocStat &= ~statFlag; }
736 /** get a document status flag */ 756 /** get a document status flag */
737 bool getDocStatFlag(unsigned int statFlag) const 757 bool getDocStatFlag(unsigned int statFlag) const
738 { return (curDocStat & statFlag); } 758 { return (curDocStat & statFlag); }
739 /** set the "currentPassword" */ 759 /** set the "currentPassword" */
740 void setCurrentPw(const QString &pw) 760 void setCurrentPw(const QString &pw)
741 { 761 {
742 currentPw = pw; 762 currentPw = pw;
743 setDocStatFlag(DOC_STAT_DISK_DIRTY); 763 setDocStatFlag(DOC_STAT_DISK_DIRTY);
744 } 764 }
745 /** make a backup-copy of the given file */ 765 /** make a backup-copy of the given file */
746 bool backupFile(const QString &filePath); 766 bool backupFile(const QString &filePath);
747 /** copy a file from src to dst */ 767 /** copy a file from src to dst */
748 bool copyFile(const QString &src, const QString &dst); 768 bool copyFile(const QString &src, const QString &dst);
749 769
750 770
751 public: 771 public:
752#ifdef PWM_EMBEDDED 772#ifdef PWM_EMBEDDED
753 //US ENH: this is the magic function that syncronizes the local doc with the remote doc. 773 //US ENH: this is the magic function that syncronizes the local doc with the remote doc.
754 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); 774 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode );
755 775
756 //takePwMDataItem returns the following values 776 //takePwMDataItem returns the following values
757 // 0 equal 777 // 0 equal
758 // 1 take local 778 // 1 take local
759 // 2 take remote 779 // 2 take remote
760 // 3 cancel 780 // 3 cancel
761 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); 781 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full );
762 782
763 //the following methods are the overwritten callbackmethods from the syncinterface 783 //the following methods are the overwritten callbackmethods from the syncinterface
764 virtual bool sync(KSyncManager* manager, QString filename, int mode); 784 virtual bool sync(KSyncManager* manager, QString filename, int mode);
765 virtual void removeSyncInfo( QString syncProfile); 785 virtual void removeSyncInfo( QString syncProfile);
766 786
767#endif 787#endif
768 private: 788 private:
769 //US ENH: helpermethods to access the sync data for a certain syncname. 789 //US ENH: helpermethods to access the sync data for a certain syncname.
770 // It returns the syncdatas index 790 // It returns the syncdatas index
771 bool findSyncData(const QString &syncname, unsigned int *index); 791 bool findSyncData(const QString &syncname, unsigned int *index);
772 792
773 /** add new syncdataentry */ 793 /** add new syncdataentry */
774 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); 794 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false);
775 795
776 /** returns a pointer to the syncdata */ 796 /** returns a pointer to the syncdata */
777 PwMSyncItem* getSyncDataEntry(unsigned int index) 797 PwMSyncItem* getSyncDataEntry(unsigned int index)
778 { return &(dti.syncDta[index]); } 798 { return &(dti.syncDta[index]); }
779 799
780 /** delete entry */ 800 /** delete entry */
781 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); 801 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false);
782 802
783 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); 803 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index);
784 804
785 QStringList getIDEntryList(); 805 QStringList getIDEntryList();
786 806
787}; 807};
788 808
789#endif 809#endif