summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index 824b841..0864293 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -1420,1025 +1420,1025 @@ void ZSafe::readAllEntries()
1420 QString::null, 1420 QString::null,
1421 mimeTypes, 1421 mimeTypes,
1422 this, 1422 this,
1423 tr ("Import text file")); 1423 tr ("Import text file"));
1424#else 1424#else
1425 QString fn = ScQtFileEdit::getOpenFileName(this, 1425 QString fn = ScQtFileEdit::getOpenFileName(this,
1426 tr ("Import text file"), 1426 tr ("Import text file"),
1427 QDir::homeDirPath() + "/Documents/application/zsafe", 1427 QDir::homeDirPath() + "/Documents/application/zsafe",
1428 "*.txt"); 1428 "*.txt");
1429#endif 1429#endif
1430#else 1430#else
1431 QString fn = QFileDialog::getOpenFileName( 1431 QString fn = QFileDialog::getOpenFileName(
1432 QDir::homeDirPath() + "/Documents/application/zsafe", 1432 QDir::homeDirPath() + "/Documents/application/zsafe",
1433 "ZSafe (*.txt)", 1433 "ZSafe (*.txt)",
1434 this, 1434 this,
1435 "ZSafe File Dialog" 1435 "ZSafe File Dialog"
1436 "Choose a text file" ); 1436 "Choose a text file" );
1437#endif 1437#endif
1438 1438
1439 if (fn && fn.length() > 0 ) 1439 if (fn && fn.length() > 0 )
1440 { 1440 {
1441 QFile f( fn ); 1441 QFile f( fn );
1442 if ( !f.open( IO_ReadOnly ) ) 1442 if ( !f.open( IO_ReadOnly ) )
1443 { 1443 {
1444#ifndef NO_OPIE 1444#ifndef NO_OPIE
1445 owarn << "Could not read file " << fn << oendl; 1445 owarn << "Could not read file " << fn << oendl;
1446#else 1446#else
1447 qWarning( QString("Could not read file %1").arg(fn), 2000 ); 1447 qWarning( QString("Could not read file %1").arg(fn), 2000 );
1448#endif 1448#endif
1449 QMessageBox::critical( 0, "ZSafe", 1449 QMessageBox::critical( 0, "ZSafe",
1450 QString("Could not import text file.") ); 1450 QString("Could not import text file.") );
1451 return; 1451 return;
1452 } 1452 }
1453 1453
1454 modified = true; 1454 modified = true;
1455 1455
1456 // clear the password list 1456 // clear the password list
1457 selectedItem = NULL; 1457 selectedItem = NULL;
1458 QListViewItem *i; 1458 QListViewItem *i;
1459 // step through all categories 1459 // step through all categories
1460 for (i = ListView->firstChild(); 1460 for (i = ListView->firstChild();
1461 i != NULL; 1461 i != NULL;
1462 i = i->nextSibling()) 1462 i = i->nextSibling())
1463 { 1463 {
1464 // step through all subitems 1464 // step through all subitems
1465 QListViewItem *si; 1465 QListViewItem *si;
1466 for (si = i->firstChild(); 1466 for (si = i->firstChild();
1467 si != NULL; ) 1467 si != NULL; )
1468 // si = si->nextSibling()) 1468 // si = si->nextSibling())
1469 { 1469 {
1470 QListViewItem *_si = si; 1470 QListViewItem *_si = si;
1471 si = si->nextSibling(); 1471 si = si->nextSibling();
1472 i->takeItem(_si); // remove from view list 1472 i->takeItem(_si); // remove from view list
1473 if (_si) delete _si; 1473 if (_si) delete _si;
1474 } 1474 }
1475 } 1475 }
1476 1476
1477#ifndef NO_OPIE 1477#ifndef NO_OPIE
1478 owarn << "ReadAllEntries(): " << oendl; 1478 owarn << "ReadAllEntries(): " << oendl;
1479#else 1479#else
1480 qWarning ("ReadAllEntries(): "); 1480 qWarning ("ReadAllEntries(): ");
1481#endif 1481#endif
1482 1482
1483 QTextStream t(&f); 1483 QTextStream t(&f);
1484 while ( !t.eof() ) 1484 while ( !t.eof() )
1485 { 1485 {
1486 QString s = t.readLine(); 1486 QString s = t.readLine();
1487 s.replace (QRegExp("\";\""), "\"|\""); 1487 s.replace (QRegExp("\";\""), "\"|\"");
1488 // char buffer[1024]; 1488 // char buffer[1024];
1489#ifndef WIN32 1489#ifndef WIN32
1490 char buffer[s.length()+1]; 1490 char buffer[s.length()+1];
1491#else 1491#else
1492 char buffer[4048]; 1492 char buffer[4048];
1493#endif 1493#endif
1494 1494
1495 1495
1496 /* modify QString -> QCString::utf8 */ 1496 /* modify QString -> QCString::utf8 */
1497 1497
1498 strcpy (buffer, s.utf8()); 1498 strcpy (buffer, s.utf8());
1499 1499
1500 QString name; 1500 QString name;
1501 QString user; 1501 QString user;
1502 QString password; 1502 QString password;
1503 QString comment; 1503 QString comment;
1504 QString field5=""; 1504 QString field5="";
1505 QString field6=""; 1505 QString field6="";
1506 1506
1507 // separete the entries 1507 // separete the entries
1508 char *i = strtok (buffer, "|"); 1508 char *i = strtok (buffer, "|");
1509 QString category(QString::fromUtf8(&i[1])); 1509 QString category(QString::fromUtf8(&i[1]));
1510 category.truncate(category.length() -1); 1510 category.truncate(category.length() -1);
1511 1511
1512 int idx=0; 1512 int idx=0;
1513 while ((i = strtok (NULL, "|")) != NULL) 1513 while ((i = strtok (NULL, "|")) != NULL)
1514 { 1514 {
1515 switch (idx) 1515 switch (idx)
1516 { 1516 {
1517 case 0: 1517 case 0:
1518 name = QString::fromUtf8(&i[1]); 1518 name = QString::fromUtf8(&i[1]);
1519 name.truncate(name.length() -1); 1519 name.truncate(name.length() -1);
1520 // name 1520 // name
1521 break; 1521 break;
1522 case 1: 1522 case 1:
1523 // user 1523 // user
1524 user = QString::fromUtf8(&i[1]); 1524 user = QString::fromUtf8(&i[1]);
1525 user.truncate(user.length() -1); 1525 user.truncate(user.length() -1);
1526 break; 1526 break;
1527 case 2: 1527 case 2:
1528 // password 1528 // password
1529 password = QString::fromUtf8(&i[1]); 1529 password = QString::fromUtf8(&i[1]);
1530 password.truncate(password.length() -1); 1530 password.truncate(password.length() -1);
1531 break; 1531 break;
1532 case 3: 1532 case 3:
1533 // comment 1533 // comment
1534 comment = QString::fromUtf8(&i[1]); 1534 comment = QString::fromUtf8(&i[1]);
1535 comment.truncate(comment.length() -1); 1535 comment.truncate(comment.length() -1);
1536 break; 1536 break;
1537 case 4: 1537 case 4:
1538 // field5 1538 // field5
1539 field5 = QString::fromUtf8(&i[1]); 1539 field5 = QString::fromUtf8(&i[1]);
1540 field5.truncate(field5.length() -1); 1540 field5.truncate(field5.length() -1);
1541 break; 1541 break;
1542 case 5: 1542 case 5:
1543 // field6 1543 // field6
1544 field6 = QString::fromUtf8(&i[1]); 1544 field6 = QString::fromUtf8(&i[1]);
1545 field6.truncate(field6.length() -1); 1545 field6.truncate(field6.length() -1);
1546 break; 1546 break;
1547 } 1547 }
1548 idx++; 1548 idx++;
1549 } 1549 }
1550 1550
1551 Category *cat= categories.find (category); 1551 Category *cat= categories.find (category);
1552 if (cat) 1552 if (cat)
1553 { 1553 {
1554 // use the existend item 1554 // use the existend item
1555 QListViewItem *catItem = cat->getListItem(); 1555 QListViewItem *catItem = cat->getListItem();
1556 if (catItem) 1556 if (catItem)
1557 { 1557 {
1558 QListViewItem * item = new ShadedListItem( 0, catItem ); 1558 QListViewItem * item = new ShadedListItem( 0, catItem );
1559 item->setText( 0, tr( name ) ); 1559 item->setText( 0, tr( name ) );
1560 item->setText( 1, tr( user ) ); 1560 item->setText( 1, tr( user ) );
1561 item->setText( 2, tr( password ) ); 1561 item->setText( 2, tr( password ) );
1562 item->setText( 3, tr( comment ) ); 1562 item->setText( 3, tr( comment ) );
1563 item->setText( 4, tr( field5 ) ); 1563 item->setText( 4, tr( field5 ) );
1564 item->setText( 5, tr( field6 ) ); 1564 item->setText( 5, tr( field6 ) );
1565 catItem->setOpen( TRUE ); 1565 catItem->setOpen( TRUE );
1566 } 1566 }
1567 } 1567 }
1568 else 1568 else
1569 { 1569 {
1570 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1570 QListViewItem *catI = new ShadedListItem( 1, ListView );
1571 // create and insert a new item 1571 // create and insert a new item
1572 QListViewItem * item = new ShadedListItem( 0, catI ); 1572 QListViewItem * item = new ShadedListItem( 0, catI );
1573 item->setText( 0, tr( name ) ); 1573 item->setText( 0, tr( name ) );
1574 item->setText( 1, tr( user ) ); 1574 item->setText( 1, tr( user ) );
1575 item->setText( 2, tr( password ) ); 1575 item->setText( 2, tr( password ) );
1576 item->setText( 3, tr( comment ) ); 1576 item->setText( 3, tr( comment ) );
1577 item->setText( 4, tr( field5 ) ); 1577 item->setText( 4, tr( field5 ) );
1578 item->setText( 5, tr( field6 ) ); 1578 item->setText( 5, tr( field6 ) );
1579 1579
1580 catI->setOpen( TRUE ); 1580 catI->setOpen( TRUE );
1581 1581
1582 Category *c1 = new Category(); 1582 Category *c1 = new Category();
1583 c1->setCategoryName(category); 1583 c1->setCategoryName(category);
1584 1584
1585 QString icon; 1585 QString icon;
1586 QString fullIconPath; 1586 QString fullIconPath;
1587 QPixmap *pix; 1587 QPixmap *pix;
1588// #ifndef WIN32 1588// #ifndef WIN32
1589 icon = conf->readEntry(APP_KEY+category); 1589 icon = conf->readEntry(APP_KEY+category);
1590// #endif 1590// #endif
1591 bool isIconAv = false; 1591 bool isIconAv = false;
1592 if (!icon.isEmpty() && !icon.isNull()) 1592 if (!icon.isEmpty() && !icon.isNull())
1593 { 1593 {
1594 // build the full path 1594 // build the full path
1595 fullIconPath = iconPath + icon; 1595 fullIconPath = iconPath + icon;
1596 pix = new QPixmap (fullIconPath); 1596 pix = new QPixmap (fullIconPath);
1597 if (!pix->isNull()) 1597 if (!pix->isNull())
1598 { 1598 {
1599 QImage img = pix->convertToImage(); 1599 QImage img = pix->convertToImage();
1600 pix->convertFromImage(img.smoothScale(14,14)); 1600 pix->convertFromImage(img.smoothScale(14,14));
1601 c1->setIconName (icon); 1601 c1->setIconName (icon);
1602 c1->setIcon (*pix); 1602 c1->setIcon (*pix);
1603 isIconAv = true; 1603 isIconAv = true;
1604 } 1604 }
1605 } 1605 }
1606 if (!isIconAv) 1606 if (!isIconAv)
1607 { 1607 {
1608 c1->setIcon (*getPredefinedIcon(category)); 1608 c1->setIcon (*getPredefinedIcon(category));
1609 } 1609 }
1610 c1->setListItem (catI); 1610 c1->setListItem (catI);
1611 c1->initListItem(); 1611 c1->initListItem();
1612 categories.insert (c1->getCategoryName(), c1); 1612 categories.insert (c1->getCategoryName(), c1);
1613 } 1613 }
1614 1614
1615 } 1615 }
1616 f.close(); 1616 f.close();
1617 1617
1618 } 1618 }
1619 else 1619 else
1620 { 1620 {
1621 } 1621 }
1622 1622
1623} 1623}
1624 1624
1625#ifdef UNUSED 1625#ifdef UNUSED
1626void ZSafe::writeAllEntries() 1626void ZSafe::writeAllEntries()
1627{ 1627{
1628 if (filename.isEmpty()) 1628 if (filename.isEmpty())
1629 { 1629 {
1630 QMessageBox::critical( 0, tr("ZSafe"), 1630 QMessageBox::critical( 0, tr("ZSafe"),
1631 tr("<P>No document defined. You have to create a new document</P>")); 1631 tr("<P>No document defined. You have to create a new document</P>"));
1632 return; 1632 return;
1633 } 1633 }
1634 1634
1635 // open the file for writing 1635 // open the file for writing
1636 QString fn = filename + ".txt"; 1636 QString fn = filename + ".txt";
1637 QFile f( fn ); 1637 QFile f( fn );
1638 if ( !f.open( IO_WriteOnly ) ) { 1638 if ( !f.open( IO_WriteOnly ) ) {
1639#ifndef NO_OPIE 1639#ifndef NO_OPIE
1640 owarn << "Could not write to file " << fn << oendl; 1640 owarn << "Could not write to file " << fn << oendl;
1641#else 1641#else
1642 qWarning( QString("Could not write to file %1").arg(fn), 2000 ); 1642 qWarning( QString("Could not write to file %1").arg(fn), 2000 );
1643#endif 1643#endif
1644 QMessageBox::critical( 0, tr("ZSafe"), 1644 QMessageBox::critical( 0, tr("ZSafe"),
1645 tr("Could not export to text file.") ); 1645 tr("Could not export to text file.") );
1646 return; 1646 return;
1647 } 1647 }
1648 QTextStream t( &f ); 1648 QTextStream t( &f );
1649 1649
1650 QListViewItem *i; 1650 QListViewItem *i;
1651 // step through all categories 1651 // step through all categories
1652 for (i = ListView->firstChild(); 1652 for (i = ListView->firstChild();
1653 i != NULL; 1653 i != NULL;
1654 i = i->nextSibling()) 1654 i = i->nextSibling())
1655 { 1655 {
1656 // step through all subitems 1656 // step through all subitems
1657 QListViewItem *si; 1657 QListViewItem *si;
1658 for (si = i->firstChild(); 1658 for (si = i->firstChild();
1659 si != NULL; 1659 si != NULL;
1660 si = si->nextSibling()) 1660 si = si->nextSibling())
1661 { 1661 {
1662 QString oneEntry; 1662 QString oneEntry;
1663 oneEntry += "\""; 1663 oneEntry += "\"";
1664 oneEntry += i->text(0); 1664 oneEntry += i->text(0);
1665 oneEntry += "\";"; 1665 oneEntry += "\";";
1666 oneEntry += "\""; 1666 oneEntry += "\"";
1667 oneEntry += si->text(0); 1667 oneEntry += si->text(0);
1668 oneEntry += "\";"; 1668 oneEntry += "\";";
1669 oneEntry += "\""; 1669 oneEntry += "\"";
1670 oneEntry += si->text(1); 1670 oneEntry += si->text(1);
1671 oneEntry += "\";"; 1671 oneEntry += "\";";
1672 oneEntry += "\""; 1672 oneEntry += "\"";
1673 oneEntry += si->text(2); 1673 oneEntry += si->text(2);
1674 oneEntry += "\";"; 1674 oneEntry += "\";";
1675 oneEntry += "\""; 1675 oneEntry += "\"";
1676 // oneEntry += si->text(3); 1676 // oneEntry += si->text(3);
1677 QString comment = si->text(3); 1677 QString comment = si->text(3);
1678 comment.replace (QRegExp("\n"), "<br>"); 1678 comment.replace (QRegExp("\n"), "<br>");
1679 oneEntry += comment; 1679 oneEntry += comment;
1680 oneEntry += "\""; 1680 oneEntry += "\"";
1681 // owarn << oneEntry << oendl; 1681 // owarn << oneEntry << oendl;
1682 t << oneEntry << endl; 1682 t << oneEntry << endl;
1683 1683
1684 // owarn << si->text(0) << oendl; 1684 // owarn << si->text(0) << oendl;
1685 } 1685 }
1686 } 1686 }
1687 f.close(); 1687 f.close();
1688} 1688}
1689 1689
1690void ZSafe::readAllEntries() 1690void ZSafe::readAllEntries()
1691{ 1691{
1692 QString fn = filename + ".txt"; 1692 QString fn = filename + ".txt";
1693 QFile f( fn ); 1693 QFile f( fn );
1694 if ( !f.open( IO_ReadOnly ) ) 1694 if ( !f.open( IO_ReadOnly ) )
1695 { 1695 {
1696#ifndef NO_OPIE 1696#ifndef NO_OPIE
1697 owarn << "Could not read file " << fn << oendl; 1697 owarn << "Could not read file " << fn << oendl;
1698#else 1698#else
1699 qWarning( QString("Could not read file %1").arg(fn), 2000 ); 1699 qWarning( QString("Could not read file %1").arg(fn), 2000 );
1700#endif 1700#endif
1701 QMessageBox::critical( 0, tr("ZSafe"), 1701 QMessageBox::critical( 0, tr("ZSafe"),
1702 tr("Could not import text file.") ); 1702 tr("Could not import text file.") );
1703 return; 1703 return;
1704 } 1704 }
1705 1705
1706 modified = true; 1706 modified = true;
1707 1707
1708 // clear the password list 1708 // clear the password list
1709 selectedItem = NULL; 1709 selectedItem = NULL;
1710 QListViewItem *i; 1710 QListViewItem *i;
1711 // step through all categories 1711 // step through all categories
1712 for (i = ListView->firstChild(); 1712 for (i = ListView->firstChild();
1713 i != NULL; 1713 i != NULL;
1714 i = i->nextSibling()) 1714 i = i->nextSibling())
1715 { 1715 {
1716 // step through all subitems 1716 // step through all subitems
1717 QListViewItem *si; 1717 QListViewItem *si;
1718 for (si = i->firstChild(); 1718 for (si = i->firstChild();
1719 si != NULL; ) 1719 si != NULL; )
1720 // si = si->nextSibling()) 1720 // si = si->nextSibling())
1721 { 1721 {
1722 QListViewItem *_si = si; 1722 QListViewItem *_si = si;
1723 si = si->nextSibling(); 1723 si = si->nextSibling();
1724 i->takeItem(_si); // remove from view list 1724 i->takeItem(_si); // remove from view list
1725 if (_si) delete _si; 1725 if (_si) delete _si;
1726 } 1726 }
1727 } 1727 }
1728 1728
1729#ifndef NO_OPIE 1729#ifndef NO_OPIE
1730 owarn << "ReadAllEntries(): " << oendl; 1730 owarn << "ReadAllEntries(): " << oendl;
1731#else 1731#else
1732 qWarning ("ReadAllEntries(): "); 1732 qWarning ("ReadAllEntries(): ");
1733#endif 1733#endif
1734 QTextStream t(&f); 1734 QTextStream t(&f);
1735 while ( !t.eof() ) 1735 while ( !t.eof() )
1736 { 1736 {
1737 QString s = t.readLine(); 1737 QString s = t.readLine();
1738 s.replace (QRegExp("\";\""), "\"|\""); 1738 s.replace (QRegExp("\";\""), "\"|\"");
1739 // char buffer[1024]; 1739 // char buffer[1024];
1740 int len=s.length()+1; 1740 int len=s.length()+1;
1741#ifdef WIN32 1741#ifdef WIN32
1742 char buffer[512]; 1742 char buffer[512];
1743#else 1743#else
1744 char buffer[len]; 1744 char buffer[len];
1745#endif 1745#endif
1746 strcpy (buffer, s); 1746 strcpy (buffer, s);
1747 1747
1748 QString name; 1748 QString name;
1749 QString user; 1749 QString user;
1750 QString password; 1750 QString password;
1751 QString comment; 1751 QString comment;
1752 1752
1753 // separete the entries 1753 // separete the entries
1754 char *i = strtok (buffer, "|"); 1754 char *i = strtok (buffer, "|");
1755 QString category(&i[1]); 1755 QString category(&i[1]);
1756 category.truncate(category.length() -1); 1756 category.truncate(category.length() -1);
1757 1757
1758 int idx=0; 1758 int idx=0;
1759 while (i = strtok (NULL, "|")) 1759 while (i = strtok (NULL, "|"))
1760 { 1760 {
1761 switch (idx) 1761 switch (idx)
1762 { 1762 {
1763 case 0: 1763 case 0:
1764 name = &i[1]; 1764 name = &i[1];
1765 name.truncate(name.length() -1); 1765 name.truncate(name.length() -1);
1766 // name 1766 // name
1767 break; 1767 break;
1768 case 1: 1768 case 1:
1769 // user 1769 // user
1770 user = &i[1]; 1770 user = &i[1];
1771 user.truncate(user.length() -1); 1771 user.truncate(user.length() -1);
1772 break; 1772 break;
1773 case 2: 1773 case 2:
1774 // password 1774 // password
1775 password = &i[1]; 1775 password = &i[1];
1776 password.truncate(password.length() -1); 1776 password.truncate(password.length() -1);
1777 break; 1777 break;
1778 case 3: 1778 case 3:
1779 // comment 1779 // comment
1780 comment = &i[1]; 1780 comment = &i[1];
1781 comment.truncate(comment.length() -1); 1781 comment.truncate(comment.length() -1);
1782 break; 1782 break;
1783 } 1783 }
1784 idx++; 1784 idx++;
1785 } 1785 }
1786 1786
1787 Category *cat= categories.find (category); 1787 Category *cat= categories.find (category);
1788 if (cat) 1788 if (cat)
1789 { 1789 {
1790 // use the existend item 1790 // use the existend item
1791 QListViewItem *catItem = cat->getListItem(); 1791 QListViewItem *catItem = cat->getListItem();
1792 if (catItem) 1792 if (catItem)
1793 { 1793 {
1794 QListViewItem * item = new ShadedListItem( 0, catItem ); 1794 QListViewItem * item = new ShadedListItem( 0, catItem );
1795 item->setText( 0, tr( name ) ); 1795 item->setText( 0, tr( name ) );
1796 item->setText( 1, tr( user ) ); 1796 item->setText( 1, tr( user ) );
1797 item->setText( 2, tr( password ) ); 1797 item->setText( 2, tr( password ) );
1798 item->setText( 3, tr( comment ) ); 1798 item->setText( 3, tr( comment ) );
1799 1799
1800 catItem->setOpen( TRUE ); 1800 catItem->setOpen( TRUE );
1801 } 1801 }
1802 } 1802 }
1803 else 1803 else
1804 { 1804 {
1805 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1805 QListViewItem *catI = new ShadedListItem( 1, ListView );
1806 // create and insert a new item 1806 // create and insert a new item
1807 QListViewItem * item = new ShadedListItem( 0, catI ); 1807 QListViewItem * item = new ShadedListItem( 0, catI );
1808 item->setText( 0, tr( name ) ); 1808 item->setText( 0, tr( name ) );
1809 item->setText( 1, tr( user ) ); 1809 item->setText( 1, tr( user ) );
1810 item->setText( 2, tr( password ) ); 1810 item->setText( 2, tr( password ) );
1811 item->setText( 3, tr( comment ) ); 1811 item->setText( 3, tr( comment ) );
1812 1812
1813 catI->setOpen( TRUE ); 1813 catI->setOpen( TRUE );
1814 1814
1815 Category *c1 = new Category(); 1815 Category *c1 = new Category();
1816 c1->setCategoryName(category); 1816 c1->setCategoryName(category);
1817 1817
1818 QString icon; 1818 QString icon;
1819 QString fullIconPath; 1819 QString fullIconPath;
1820 QPixmap *pix; 1820 QPixmap *pix;
1821// #ifndef WIN32 1821// #ifndef WIN32
1822 icon = conf->readEntry(APP_KEY+category); 1822 icon = conf->readEntry(APP_KEY+category);
1823// #endif 1823// #endif
1824 bool isIconAv = false; 1824 bool isIconAv = false;
1825 if (!icon.isEmpty() && !icon.isNull()) 1825 if (!icon.isEmpty() && !icon.isNull())
1826 { 1826 {
1827 // build the full path 1827 // build the full path
1828 fullIconPath = iconPath + icon; 1828 fullIconPath = iconPath + icon;
1829 pix = new QPixmap (fullIconPath); 1829 pix = new QPixmap (fullIconPath);
1830 if (!pix->isNull()) 1830 if (!pix->isNull())
1831 { 1831 {
1832 QImage img = pix->convertToImage(); 1832 QImage img = pix->convertToImage();
1833 pix->convertFromImage(img.smoothScale(14,14)); 1833 pix->convertFromImage(img.smoothScale(14,14));
1834 c1->setIconName (icon); 1834 c1->setIconName (icon);
1835 c1->setIcon (*pix); 1835 c1->setIcon (*pix);
1836 isIconAv = true; 1836 isIconAv = true;
1837 } 1837 }
1838 } 1838 }
1839 if (!isIconAv) 1839 if (!isIconAv)
1840 { 1840 {
1841 c1->setIcon (*getPredefinedIcon(category)); 1841 c1->setIcon (*getPredefinedIcon(category));
1842 } 1842 }
1843 c1->setListItem (catI); 1843 c1->setListItem (catI);
1844 c1->initListItem(); 1844 c1->initListItem();
1845 categories.insert (c1->getCategoryName(), c1); 1845 categories.insert (c1->getCategoryName(), c1);
1846 } 1846 }
1847 1847
1848 } 1848 }
1849 f.close(); 1849 f.close();
1850 1850
1851} 1851}
1852#endif // UNUSED 1852#endif // UNUSED
1853 1853
1854void ZSafe::resume(int) 1854void ZSafe::resume(int)
1855{ 1855{
1856#ifndef NO_OPIE 1856#ifndef NO_OPIE
1857 owarn << "Resume" << oendl; 1857 owarn << "Resume" << oendl;
1858#endif 1858#endif
1859 // hide the main window 1859 // hide the main window
1860 1860
1861 if ( !showpwd ) 1861 if ( !showpwd )
1862 { 1862 {
1863 infoForm->hide(); 1863 infoForm->hide();
1864 // open zsafe again 1864 // open zsafe again
1865 m_password = ""; 1865 m_password = "";
1866 selectedItem = NULL; 1866 selectedItem = NULL;
1867 1867
1868 // clear the password list 1868 // clear the password list
1869 QListViewItem *i; 1869 QListViewItem *i;
1870 // step through all categories 1870 // step through all categories
1871 for (i = ListView->firstChild(); 1871 for (i = ListView->firstChild();
1872 i != NULL; 1872 i != NULL;
1873 i = i->nextSibling()) 1873 i = i->nextSibling())
1874 { 1874 {
1875 // step through all subitems 1875 // step through all subitems
1876 QListViewItem *si; 1876 QListViewItem *si;
1877 for (si = i->firstChild(); 1877 for (si = i->firstChild();
1878 si != NULL; ) 1878 si != NULL; )
1879 { 1879 {
1880 QListViewItem *_si = si; 1880 QListViewItem *_si = si;
1881 si = si->nextSibling(); 1881 si = si->nextSibling();
1882 i->takeItem(_si); // remove from view list 1882 i->takeItem(_si); // remove from view list
1883 if (_si) delete _si; 1883 if (_si) delete _si;
1884 } 1884 }
1885 } 1885 }
1886 1886
1887 // ask for password and read again 1887 // ask for password and read again
1888 openDocument(filename); 1888 openDocument(filename);
1889 } 1889 }
1890} 1890}
1891 1891
1892//--------------------------------------------- 1892//---------------------------------------------
1893 1893
1894 1894
1895bool ZSafe::openDocument(const char* _filename, const char* ) 1895bool ZSafe::openDocument(const char* _filename, const char* )
1896{ 1896{
1897 int retval; 1897 int retval;
1898 char* entry[FIELD_SIZE]; 1898 char* entry[FIELD_SIZE];
1899// #ifndef WIN32 1899// #ifndef WIN32
1900 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); 1900 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1);
1901// #else 1901// #else
1902 // int validationFlag = 1; 1902 // int validationFlag = 1;
1903// #endif 1903// #endif
1904 1904
1905 int pwdOk = 0; 1905 int pwdOk = 0;
1906 int numberOfTries = 3; 1906 int numberOfTries = 3;
1907 for (int i=0; i < numberOfTries; i++) 1907 for (int i=0; i < numberOfTries; i++)
1908 { 1908 {
1909 QFile f(_filename); 1909 QFile f(_filename);
1910 if (f.exists()) 1910 if (f.exists())
1911 { 1911 {
1912 // ask with a dialog for the password 1912 // ask with a dialog for the password
1913 if (m_password.isEmpty()) 1913 if (m_password.isEmpty())
1914 getDocPassword(tr("Enter Password")); 1914 getDocPassword(tr("Enter Password"));
1915 if (m_password.isEmpty() && validationFlag == 0) 1915 if (m_password.isEmpty() && validationFlag == 0)
1916 { 1916 {
1917#ifndef NO_OPIE 1917#ifndef NO_OPIE
1918 owarn << "Wrong password" << oendl; 1918 owarn << "Wrong password" << oendl;
1919#else 1919#else
1920 qWarning ("Wrong password"); 1920 qWarning ("Wrong password");
1921#endif 1921#endif
1922 QMessageBox::critical( 0, tr("ZSafe"), 1922 QMessageBox::critical( 0, tr("ZSafe"),
1923 tr("Wrong password.\n\nZSafe will now exit.") ); 1923 tr("Wrong password.\n\nZSafe will now exit.") );
1924 exitZs (1); 1924 exitZs (1);
1925 } 1925 }
1926 1926
1927 retval = loadInit(_filename, m_password); 1927 retval = loadInit(_filename, m_password);
1928 if (retval != PWERR_GOOD) 1928 if (retval != PWERR_GOOD)
1929 { 1929 {
1930#ifndef NO_OPIE 1930#ifndef NO_OPIE
1931 owarn << "Error loading Document" << oendl; 1931 owarn << "Error loading Document" << oendl;
1932#lese 1932#else
1933 qWarning ("Error loading Document"); 1933 qWarning ("Error loading Document");
1934#endif 1934#endif
1935 return false; 1935 return false;
1936 } 1936 }
1937 } 1937 }
1938 else 1938 else
1939 { 1939 {
1940#ifdef WIN32 1940#ifdef WIN32
1941 this->setCaption("Qt ZSafe"); 1941 this->setCaption("Qt ZSafe");
1942#else 1942#else
1943 this->setCaption("ZSafe"); 1943 this->setCaption("ZSafe");
1944#endif 1944#endif
1945 filename = ""; 1945 filename = "";
1946 return false; 1946 return false;
1947 } 1947 }
1948 1948
1949 1949
1950 // load the validation entry 1950 // load the validation entry
1951 if (validationFlag == 0) 1951 if (validationFlag == 0)
1952 { 1952 {
1953 pwdOk = 1; 1953 pwdOk = 1;
1954 break; 1954 break;
1955 } 1955 }
1956 1956
1957 retval = loadEntry(entry); 1957 retval = loadEntry(entry);
1958 if (retval == 1 && 1958 if (retval == 1 &&
1959 !strcmp (entry[0], "ZSAFECATEGORY") && 1959 !strcmp (entry[0], "ZSAFECATEGORY") &&
1960 !strcmp (entry[1], "name") && 1960 !strcmp (entry[1], "name") &&
1961 !strcmp (entry[2], "username") && 1961 !strcmp (entry[2], "username") &&
1962 !strcmp (entry[3], "password") && 1962 !strcmp (entry[3], "password") &&
1963 !strcmp (entry[4], "comment") ) 1963 !strcmp (entry[4], "comment") )
1964 { 1964 {
1965 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1965 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1966 pwdOk = 1; 1966 pwdOk = 1;
1967 break; 1967 break;
1968 } 1968 }
1969 else 1969 else
1970 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1970 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1971 fclose (fd); 1971 fclose (fd);
1972 m_password = ""; 1972 m_password = "";
1973 1973
1974 if (i < numberOfTries - 1) 1974 if (i < numberOfTries - 1)
1975 { 1975 {
1976 switch( QMessageBox::warning( this, tr("ZSafe"), 1976 switch( QMessageBox::warning( this, tr("ZSafe"),
1977 tr("Wrong password.\nEnter again?"), 1977 tr("Wrong password.\nEnter again?"),
1978 tr("&Yes"), tr("&No."), 1978 tr("&Yes"), tr("&No."),
1979 0 1979 0
1980 ) ) 1980 ) )
1981 { 1981 {
1982 case 1: // No 1982 case 1: // No
1983 exitZs (1); 1983 exitZs (1);
1984 break; 1984 break;
1985 case 0: // Yes 1985 case 0: // Yes
1986 continue; 1986 continue;
1987 } 1987 }
1988 } 1988 }
1989 } 1989 }
1990 if (pwdOk == 0) 1990 if (pwdOk == 0)
1991 { 1991 {
1992 // unset the document entry 1992 // unset the document entry
1993 conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); 1993 conf->writeEntry(APP_KEY+"document", "INVALIDPWD");
1994 if (conf) 1994 if (conf)
1995 delete conf; 1995 delete conf;
1996 1996
1997 exitZs (1); 1997 exitZs (1);
1998 } 1998 }
1999 1999
2000 2000
2001 retval = loadEntry(entry); 2001 retval = loadEntry(entry);
2002 2002
2003 int numberOfEntries=0; 2003 int numberOfEntries=0;
2004 while (retval == 1) { 2004 while (retval == 1) {
2005 2005
2006 QString category( QString::fromUtf8(entry[0]) ); 2006 QString category( QString::fromUtf8(entry[0]) );
2007 QString name( QString::fromUtf8(entry[1]) ); 2007 QString name( QString::fromUtf8(entry[1]) );
2008 QString user( QString::fromUtf8(entry[2]) ); 2008 QString user( QString::fromUtf8(entry[2]) );
2009 QString password( QString::fromUtf8(entry[3]) ); 2009 QString password( QString::fromUtf8(entry[3]) );
2010 QString comment( QString::fromUtf8(entry[4]) ); 2010 QString comment( QString::fromUtf8(entry[4]) );
2011 QString field5( QString::fromUtf8(entry[5]) ); 2011 QString field5( QString::fromUtf8(entry[5]) );
2012 QString field6( QString::fromUtf8(entry[6]) ); 2012 QString field6( QString::fromUtf8(entry[6]) );
2013 // add the subitems to the categories 2013 // add the subitems to the categories
2014 2014
2015 Category *cat= categories.find (category); 2015 Category *cat= categories.find (category);
2016 if (cat) 2016 if (cat)
2017 { 2017 {
2018 // use the existend item 2018 // use the existend item
2019 QListViewItem *catItem = cat->getListItem(); 2019 QListViewItem *catItem = cat->getListItem();
2020 if (catItem) 2020 if (catItem)
2021 { 2021 {
2022 QListViewItem * item = new ShadedListItem( 0, catItem ); 2022 QListViewItem * item = new ShadedListItem( 0, catItem );
2023 item->setText( 0, tr( name ) ); 2023 item->setText( 0, tr( name ) );
2024 item->setText( 1, tr( user ) ); 2024 item->setText( 1, tr( user ) );
2025 item->setText( 2, tr( password ) ); 2025 item->setText( 2, tr( password ) );
2026 item->setText( 3, tr( comment ) ); 2026 item->setText( 3, tr( comment ) );
2027 item->setText( 4, tr( field5 ) ); 2027 item->setText( 4, tr( field5 ) );
2028 item->setText( 5, tr( field6 ) ); 2028 item->setText( 5, tr( field6 ) );
2029 2029
2030 if (expandTree) 2030 if (expandTree)
2031 catItem->setOpen( TRUE ); 2031 catItem->setOpen( TRUE );
2032 numberOfEntries++; 2032 numberOfEntries++;
2033 } 2033 }
2034 } 2034 }
2035 else 2035 else
2036 { 2036 {
2037 QListViewItem *catI = new ShadedListItem( 1, ListView ); 2037 QListViewItem *catI = new ShadedListItem( 1, ListView );
2038 // create and insert a new item 2038 // create and insert a new item
2039 QListViewItem * item = new ShadedListItem( 0, catI ); 2039 QListViewItem * item = new ShadedListItem( 0, catI );
2040 2040
2041 item->setText( 0, tr( name ) ); 2041 item->setText( 0, tr( name ) );
2042 item->setText( 1, tr( user ) ); 2042 item->setText( 1, tr( user ) );
2043 item->setText( 2, tr( password ) ); 2043 item->setText( 2, tr( password ) );
2044 item->setText( 3, tr( comment ) ); 2044 item->setText( 3, tr( comment ) );
2045 item->setText( 4, tr( field5 ) ); 2045 item->setText( 4, tr( field5 ) );
2046 item->setText( 5, tr( field6 ) ); 2046 item->setText( 5, tr( field6 ) );
2047 2047
2048 if (expandTree) 2048 if (expandTree)
2049 catI->setOpen( TRUE ); 2049 catI->setOpen( TRUE );
2050 2050
2051 Category *c1 = new Category(); 2051 Category *c1 = new Category();
2052 c1->setCategoryName(category); 2052 c1->setCategoryName(category);
2053 2053
2054 QString icon; 2054 QString icon;
2055 QString fullIconPath; 2055 QString fullIconPath;
2056 QPixmap *pix; 2056 QPixmap *pix;
2057// #ifndef WIN32 2057// #ifndef WIN32
2058 icon = conf->readEntry(APP_KEY+category); 2058 icon = conf->readEntry(APP_KEY+category);
2059// #endif 2059// #endif
2060 bool isIconAv = false; 2060 bool isIconAv = false;
2061 if (!icon.isEmpty() && !icon.isNull()) 2061 if (!icon.isEmpty() && !icon.isNull())
2062 { 2062 {
2063 // build the full path 2063 // build the full path
2064 fullIconPath = iconPath + icon; 2064 fullIconPath = iconPath + icon;
2065 pix = new QPixmap (fullIconPath); 2065 pix = new QPixmap (fullIconPath);
2066 if (!pix->isNull()) 2066 if (!pix->isNull())
2067 { 2067 {
2068 QImage img = pix->convertToImage(); 2068 QImage img = pix->convertToImage();
2069 pix->convertFromImage(img.smoothScale(14,14)); 2069 pix->convertFromImage(img.smoothScale(14,14));
2070 c1->setIconName (icon); 2070 c1->setIconName (icon);
2071 c1->setIcon (*pix); 2071 c1->setIcon (*pix);
2072 isIconAv = true; 2072 isIconAv = true;
2073 } 2073 }
2074 } 2074 }
2075 if (!isIconAv) 2075 if (!isIconAv)
2076 { 2076 {
2077 c1->setIcon (*getPredefinedIcon(category)); 2077 c1->setIcon (*getPredefinedIcon(category));
2078 } 2078 }
2079 2079
2080 c1->setListItem (catI); 2080 c1->setListItem (catI);
2081 c1->initListItem(); 2081 c1->initListItem();
2082 categories.insert (c1->getCategoryName(), c1); 2082 categories.insert (c1->getCategoryName(), c1);
2083 numberOfEntries++; 2083 numberOfEntries++;
2084 } 2084 }
2085 2085
2086 for (int count = 0; count < FIELD_SIZE; count++) { 2086 for (int count = 0; count < FIELD_SIZE; count++) {
2087 free(entry[count]); 2087 free(entry[count]);
2088 } 2088 }
2089 retval = loadEntry(entry); 2089 retval = loadEntry(entry);
2090 if (retval == 2) { 2090 if (retval == 2) {
2091 // m_parent->slotStatusHelpMsg("Last entry loaded"); 2091 // m_parent->slotStatusHelpMsg("Last entry loaded");
2092 } 2092 }
2093 } // end while 2093 } // end while
2094 2094
2095 if (numberOfEntries == 0) 2095 if (numberOfEntries == 0)
2096 { 2096 {
2097 2097
2098 switch( QMessageBox::warning( this, tr("ZSafe"), 2098 switch( QMessageBox::warning( this, tr("ZSafe"),
2099 tr("Empty document or\nwrong password.\nContinue?"), 2099 tr("Empty document or\nwrong password.\nContinue?"),
2100 tr("&No"), tr("&Yes."), 2100 tr("&No"), tr("&Yes."),
2101 0 2101 0
2102 ) ) { 2102 ) ) {
2103 case 0: // No 2103 case 0: // No
2104 retval = loadFinalize(); 2104 retval = loadFinalize();
2105 exitZs (1); 2105 exitZs (1);
2106 break; 2106 break;
2107 case 1: // Yes 2107 case 1: // Yes
2108 break; 2108 break;
2109 } 2109 }
2110 } 2110 }
2111 2111
2112 retval = loadFinalize(); 2112 retval = loadFinalize();
2113 2113
2114 return true; 2114 return true;
2115} 2115}
2116 2116
2117int ZSafe::loadInit(const char* _filename, const char *password) 2117int ZSafe::loadInit(const char* _filename, const char *password)
2118{ 2118{
2119 unsigned int j = 0; 2119 unsigned int j = 0;
2120 unsigned int keylength=0; 2120 unsigned int keylength=0;
2121 int count=0, count2=0, count3=0; 2121 int count=0, count2=0, count3=0;
2122 unsigned char charbuf[8]; 2122 unsigned char charbuf[8];
2123 unsigned short ciphertext[4]; 2123 unsigned short ciphertext[4];
2124 char key[128]; 2124 char key[128];
2125 Krc2* krc2 = new Krc2(); 2125 Krc2* krc2 = new Krc2();
2126 2126
2127 fd = fopen (_filename, "rb"); 2127 fd = fopen (_filename, "rb");
2128 2128
2129 QFileInfo f (_filename); 2129 QFileInfo f (_filename);
2130 load_buffer_length = f.size(); 2130 load_buffer_length = f.size();
2131 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; 2131 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2;
2132 2132
2133 if (fd == NULL) 2133 if (fd == NULL)
2134 return PWERR_OPEN; 2134 return PWERR_OPEN;
2135 2135
2136 buffer = (char *)malloc(load_buffer_length); 2136 buffer = (char *)malloc(load_buffer_length);
2137 for (j = 0; password[j] != '\0'; j++) { 2137 for (j = 0; password[j] != '\0'; j++) {
2138 key[j] = password[j]; 2138 key[j] = password[j];
2139 } 2139 }
2140 keylength = j; 2140 keylength = j;
2141 krc2->rc2_expandkey (key, keylength, 128); 2141 krc2->rc2_expandkey (key, keylength, 128);
2142 2142
2143#ifndef WIN32 2143#ifndef WIN32
2144 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); 2144 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
2145#else 2145#else
2146 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2146 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2147#endif 2147#endif
2148 2148
2149 if (size < 8) 2149 if (size < 8)
2150 return PWERR_DATA; 2150 return PWERR_DATA;
2151 2151
2152 for (count = 0; count < 4; count++) { 2152 for (count = 0; count < 4; count++) {
2153 count2 = count << 1; 2153 count2 = count << 1;
2154 iv[count] = charbuf[count2] << 8; 2154 iv[count] = charbuf[count2] << 8;
2155 iv[count] += charbuf[count2 + 1]; 2155 iv[count] += charbuf[count2 + 1];
2156 } 2156 }
2157 2157
2158 size = 0; 2158 size = 0;
2159 bufferIndex = 0; 2159 bufferIndex = 0;
2160#ifndef WIN32 2160#ifndef WIN32
2161 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) { 2161 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
2162 while (count < 8) { 2162 while (count < 8) {
2163 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); 2163 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
2164#else 2164#else
2165 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { 2165 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
2166 while (count < 8) { 2166 while (count < 8) {
2167 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2167 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2168#endif 2168#endif
2169 if (count2 == 0) { 2169 if (count2 == 0) {
2170 return PWERR_DATA; 2170 return PWERR_DATA;
2171 } 2171 }
2172 count += count2; 2172 count += count2;
2173 } /* while (count < 8) */ 2173 } /* while (count < 8) */
2174 2174
2175 size += 8; 2175 size += 8;
2176 for (count2 = 0; count2 < 8; count2 += 2) { 2176 for (count2 = 0; count2 < 8; count2 += 2) {
2177 count3 = count2 >> 1; 2177 count3 = count2 >> 1;
2178 ciphertext[count3] = charbuf[count2] << 8; 2178 ciphertext[count3] = charbuf[count2] << 8;
2179 ciphertext[count3] += charbuf[count2 + 1]; 2179 ciphertext[count3] += charbuf[count2 + 1];
2180 2180
2181 plaintext[count3] = ciphertext[count3] ^ iv[count3]; 2181 plaintext[count3] = ciphertext[count3] ^ iv[count3];
2182 iv[count3] = plaintext[count3]; 2182 iv[count3] = plaintext[count3];
2183 } /* for (count2) */ 2183 } /* for (count2) */
2184 2184
2185 krc2->rc2_decrypt (plaintext); 2185 krc2->rc2_decrypt (plaintext);
2186 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); 2186 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
2187 bufferIndex += 8; 2187 bufferIndex += 8;
2188 buffer[bufferIndex + 1] = '\0'; 2188 buffer[bufferIndex + 1] = '\0';
2189 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ 2189 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
2190 size -= buffer[size - 1]; 2190 size -= buffer[size - 1];
2191 lastcount = 0; 2191 lastcount = 0;
2192 2192
2193 /* This will point to the starting index */ 2193 /* This will point to the starting index */
2194 bufferIndex = 0; 2194 bufferIndex = 0;
2195 return PWERR_GOOD; 2195 return PWERR_GOOD;
2196} 2196}
2197 2197
2198int ZSafe::loadEntry(char *entry[FIELD_SIZE]) 2198int ZSafe::loadEntry(char *entry[FIELD_SIZE])
2199{ 2199{
2200 /* Strip off PKCS 5 padding 2200 /* Strip off PKCS 5 padding
2201 * Should check to make sure it's good here 2201 * Should check to make sure it's good here
2202 */ 2202 */
2203 int count, count1=0; 2203 int count, count1=0;
2204 2204
2205 for (count = lastcount; count < size; count++) { 2205 for (count = lastcount; count < size; count++) {
2206 if ((unsigned char) (buffer[count]) == 255) { 2206 if ((unsigned char) (buffer[count]) == 255) {
2207 if (buffer[bufferIndex] == '\0') { 2207 if (buffer[bufferIndex] == '\0') {
2208 bufferIndex++; 2208 bufferIndex++;
2209 } 2209 }
2210 entry[count1] = (char *) malloc (count - bufferIndex + 1); 2210 entry[count1] = (char *) malloc (count - bufferIndex + 1);
2211 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex); 2211 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex);
2212 entry[count1][count - bufferIndex] = '\0'; 2212 entry[count1][count - bufferIndex] = '\0';
2213 count++; 2213 count++;
2214 bufferIndex = count; 2214 bufferIndex = count;
2215 count1++; 2215 count1++;
2216 if (count1 == FIELD_SIZE) { 2216 if (count1 == FIELD_SIZE) {
2217 lastcount = count; 2217 lastcount = count;
2218 return 1; 2218 return 1;
2219 } 2219 }
2220 } /* if ((unsigned char) (buffer[count]) == 255) */ 2220 } /* if ((unsigned char) (buffer[count]) == 255) */
2221 } /* for (count = 0; count < size; count++) */ 2221 } /* for (count = 0; count < size; count++) */
2222 2222
2223 return 2; 2223 return 2;
2224} 2224}
2225 2225
2226int ZSafe::loadFinalize(void) 2226int ZSafe::loadFinalize(void)
2227{ 2227{
2228 fclose (fd); 2228 fclose (fd);
2229 if (buffer) free(buffer); 2229 if (buffer) free(buffer);
2230 return PWERR_GOOD; 2230 return PWERR_GOOD;
2231} 2231}
2232 2232
2233bool ZSafe::saveDocument(const char* _filename, 2233bool ZSafe::saveDocument(const char* _filename,
2234 bool withPwd, 2234 bool withPwd,
2235 const char* ) 2235 const char* )
2236{ 2236{
2237 if (filename.isEmpty()) 2237 if (filename.isEmpty())
2238 { 2238 {
2239 QMessageBox::critical( 0, tr("ZSafe"), 2239 QMessageBox::critical( 0, tr("ZSafe"),
2240 tr("No document defined.\nYou have to create a new document")); 2240 tr("No document defined.\nYou have to create a new document"));
2241 return false; 2241 return false;
2242 } 2242 }
2243 2243
2244 // if (m_password.isEmpty()) 2244 // if (m_password.isEmpty())
2245 // withPwd = true; // the document must be saved with a valid password 2245 // withPwd = true; // the document must be saved with a valid password
2246 if (withPwd) 2246 if (withPwd)
2247 { 2247 {
2248 bool pwdOk = FALSE; 2248 bool pwdOk = FALSE;
2249 while (!pwdOk) 2249 while (!pwdOk)
2250 { 2250 {
2251 getDocPassword(tr("Enter Password")); 2251 getDocPassword(tr("Enter Password"));
2252 if (m_password.isEmpty()) 2252 if (m_password.isEmpty())
2253 { 2253 {
2254 2254
2255 QMessageBox::critical( 0, tr("ZSafe"), 2255 QMessageBox::critical( 0, tr("ZSafe"),
2256 tr("Password is empty.\nPlease enter again.")); 2256 tr("Password is empty.\nPlease enter again."));
2257 continue; 2257 continue;
2258 } 2258 }
2259 2259
2260 QString firstPasswd = m_password; 2260 QString firstPasswd = m_password;
2261 2261
2262 getDocPassword(tr("Reenter Password")); 2262 getDocPassword(tr("Reenter Password"));
2263 if (m_password.isEmpty()) 2263 if (m_password.isEmpty())
2264 { 2264 {
2265 QMessageBox::critical( 0, tr("ZSafe"), 2265 QMessageBox::critical( 0, tr("ZSafe"),
2266 tr("Password is empty.\nPlease enter again.")); 2266 tr("Password is empty.\nPlease enter again."));
2267 continue; 2267 continue;
2268 } 2268 }
2269 if (firstPasswd != m_password) 2269 if (firstPasswd != m_password)
2270 { 2270 {
2271 2271
2272 QMessageBox::critical( 0, tr("ZSafe"), 2272 QMessageBox::critical( 0, tr("ZSafe"),
2273 tr("Passwords must be identical.\nPlease enter again.")); 2273 tr("Passwords must be identical.\nPlease enter again."));
2274 continue; 2274 continue;
2275 } 2275 }
2276 pwdOk = TRUE; 2276 pwdOk = TRUE;
2277 modified = false; 2277 modified = false;
2278 } 2278 }
2279 } 2279 }
2280 else if (modified) 2280 else if (modified)
2281 { 2281 {
2282 QString fns(_filename); 2282 QString fns(_filename);
2283 fns = fns.right (fns.length() - fns.findRev ('/') - 1); 2283 fns = fns.right (fns.length() - fns.findRev ('/') - 1);
2284 switch( QMessageBox::information( this, tr("ZSafe"), 2284 switch( QMessageBox::information( this, tr("ZSafe"),
2285 tr("Do you want to save ") + fns + tr("\nbefore continuing?"), 2285 tr("Do you want to save ") + fns + tr("\nbefore continuing?"),
2286 tr("&Save"), 2286 tr("&Save"),
2287 tr("&Don't Save"), 2287 tr("&Don't Save"),
2288 0 // Enter == button 0 2288 0 // Enter == button 0
2289 ) ) 2289 ) )
2290 { // Escape == button 2 2290 { // Escape == button 2
2291 case 0: // Save clicked, Alt-S or Enter pressed. 2291 case 0: // Save clicked, Alt-S or Enter pressed.
2292 modified = false; 2292 modified = false;
2293 break; 2293 break;
2294 case 1: // Don't Save clicked or Alt-D pressed 2294 case 1: // Don't Save clicked or Alt-D pressed
2295 modified = false; 2295 modified = false;
2296 return true; 2296 return true;
2297 } 2297 }
2298 } 2298 }
2299 modified = false; 2299 modified = false;
2300 2300
2301 if (m_password.isEmpty()) 2301 if (m_password.isEmpty())
2302 return false; 2302 return false;
2303 2303
2304 int retval = saveInit(_filename, m_password); 2304 int retval = saveInit(_filename, m_password);
2305 // int retval = saveInit(_filename, "test"); 2305 // int retval = saveInit(_filename, "test");
2306 if (retval != PWERR_GOOD) { 2306 if (retval != PWERR_GOOD) {
2307 return false; 2307 return false;
2308 } 2308 }
2309 2309
2310 char* entry[FIELD_SIZE]; 2310 char* entry[FIELD_SIZE];
2311 2311
2312 // save the validation entry 2312 // save the validation entry
2313 { 2313 {
2314 int i=0; 2314 int i=0;
2315 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1); 2315 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1);
2316 strcpy(entry[i++], "ZSAFECATEGORY"); 2316 strcpy(entry[i++], "ZSAFECATEGORY");
2317 entry[i] = (char*)malloc(strlen("name")+1); 2317 entry[i] = (char*)malloc(strlen("name")+1);
2318 strcpy(entry[i++], "name"); 2318 strcpy(entry[i++], "name");
2319 entry[i] = (char*)malloc(strlen("username")+1); 2319 entry[i] = (char*)malloc(strlen("username")+1);
2320 strcpy(entry[i++], "username"); 2320 strcpy(entry[i++], "username");
2321 entry[i] = (char*)malloc(strlen("password")+1); 2321 entry[i] = (char*)malloc(strlen("password")+1);
2322 strcpy(entry[i++], "password"); 2322 strcpy(entry[i++], "password");
2323 entry[i] = (char*)malloc(strlen("comment")+1); 2323 entry[i] = (char*)malloc(strlen("comment")+1);
2324 strcpy(entry[i++], "comment"); 2324 strcpy(entry[i++], "comment");
2325 2325
2326 entry[i] = (char*)malloc(strlen("field5")+1); 2326 entry[i] = (char*)malloc(strlen("field5")+1);
2327 strcpy(entry[i++], "field5"); 2327 strcpy(entry[i++], "field5");
2328 entry[i] = (char*)malloc(strlen("field6")+1); 2328 entry[i] = (char*)malloc(strlen("field6")+1);
2329 strcpy(entry[i++], "field6"); 2329 strcpy(entry[i++], "field6");
2330 2330
2331 retval = saveEntry(entry); 2331 retval = saveEntry(entry);
2332 for (int z=0; z<i; z++) free(entry[z]); 2332 for (int z=0; z<i; z++) free(entry[z]);
2333 if (retval == PWERR_DATA) { 2333 if (retval == PWERR_DATA) {
2334#ifndef NO_OPIE 2334#ifndef NO_OPIE
2335 owarn << "1: Error writing file, contents not saved" << oendl; 2335 owarn << "1: Error writing file, contents not saved" << oendl;
2336#else 2336#else
2337 qWarning("1: Error writing file, contents not saved"); 2337 qWarning("1: Error writing file, contents not saved");
2338#endif 2338#endif
2339 saveFinalize(); 2339 saveFinalize();
2340 return false; 2340 return false;
2341 } 2341 }
2342// #ifndef WIN32 2342// #ifndef WIN32
2343 conf->writeEntry(APP_KEY+"valzsafe", 1); 2343 conf->writeEntry(APP_KEY+"valzsafe", 1);
2344// #endif 2344// #endif
2345 saveConf(); 2345 saveConf();
2346 } 2346 }
2347 2347
2348 QListViewItem *i; 2348 QListViewItem *i;
2349 // step through all categories 2349 // step through all categories
2350 for (i = ListView->firstChild(); 2350 for (i = ListView->firstChild();
2351 i != NULL; 2351 i != NULL;
2352 i = i->nextSibling()) 2352 i = i->nextSibling())
2353 { 2353 {
2354 // step through all subitems 2354 // step through all subitems
2355 QListViewItem *si; 2355 QListViewItem *si;
2356 for (si = i->firstChild(); 2356 for (si = i->firstChild();
2357 si != NULL; 2357 si != NULL;
2358 si = si->nextSibling()) 2358 si = si->nextSibling())
2359 { 2359 {
2360 int j=0; 2360 int j=0;
2361 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1); 2361 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1);
2362 strcpy(entry[j++], i->text(0).utf8()); 2362 strcpy(entry[j++], i->text(0).utf8());
2363 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1); 2363 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1);
2364 strcpy(entry[j++], si->text(0).utf8()); 2364 strcpy(entry[j++], si->text(0).utf8());
2365 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1); 2365 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1);
2366 strcpy(entry[j++], si->text(1).utf8()); 2366 strcpy(entry[j++], si->text(1).utf8());
2367 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1); 2367 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1);
2368 strcpy(entry[j++], si->text(2).utf8()); 2368 strcpy(entry[j++], si->text(2).utf8());
2369 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1); 2369 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1);
2370 strcpy(entry[j++], si->text(3).utf8()); 2370 strcpy(entry[j++], si->text(3).utf8());
2371 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1); 2371 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1);
2372 strcpy(entry[j++], si->text(4).utf8()); 2372 strcpy(entry[j++], si->text(4).utf8());
2373 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1); 2373 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1);
2374 strcpy(entry[j++], si->text(5).utf8()); 2374 strcpy(entry[j++], si->text(5).utf8());
2375 2375
2376 retval = saveEntry(entry); 2376 retval = saveEntry(entry);
2377 for (int z=0; z<j; z++) 2377 for (int z=0; z<j; z++)
2378 { 2378 {
2379 free(entry[z]); 2379 free(entry[z]);
2380 } 2380 }
2381 if (retval == PWERR_DATA) { 2381 if (retval == PWERR_DATA) {
2382#ifndef NO_OPIE 2382#ifndef NO_OPIE
2383 owarn << "1: Error writing file, contents not saved" << oendl; 2383 owarn << "1: Error writing file, contents not saved" << oendl;
2384#else 2384#else
2385 qWarning("1: Error writing file, contents not saved"); 2385 qWarning("1: Error writing file, contents not saved");
2386#endif 2386#endif
2387 saveFinalize(); 2387 saveFinalize();
2388 return false; 2388 return false;
2389 } 2389 }
2390 2390
2391 } 2391 }
2392 } 2392 }
2393 2393
2394 if (saveFinalize() == PWERR_DATA) { 2394 if (saveFinalize() == PWERR_DATA) {
2395#ifndef NO_OPIE 2395#ifndef NO_OPIE
2396 owarn << "2: Error writing file, contents not saved" << oendl; 2396 owarn << "2: Error writing file, contents not saved" << oendl;
2397#else 2397#else
2398 qWarning("2: Error writing file, contents not saved"); 2398 qWarning("2: Error writing file, contents not saved");
2399#endif 2399#endif
2400 return false; 2400 return false;
2401 } else { 2401 } else {
2402#ifndef DESKTOP 2402#ifndef DESKTOP
2403 Global::statusMessage (tr("Password file saved.")); 2403 Global::statusMessage (tr("Password file saved."));
2404#endif 2404#endif
2405 modified = false; 2405 modified = false;
2406 return true; 2406 return true;
2407 } 2407 }
2408} 2408}
2409 2409
2410PasswordForm *newPwdDialog; 2410PasswordForm *newPwdDialog;
2411bool newPwdDialogResult = false; 2411bool newPwdDialogResult = false;
2412void ZSafe::setPasswordDialogDone() 2412void ZSafe::setPasswordDialogDone()
2413{ 2413{
2414 newPwdDialogResult = true; 2414 newPwdDialogResult = true;
2415 newPwdDialog->close(); 2415 newPwdDialog->close();
2416} 2416}
2417 2417
2418void ZSafe::getDocPassword(QString title) 2418void ZSafe::getDocPassword(QString title)
2419{ 2419{
2420#ifndef NO_OPIE 2420#ifndef NO_OPIE
2421 owarn << "getDocPassword" << oendl; 2421 owarn << "getDocPassword" << oendl;
2422#endif 2422#endif
2423 // open the 'Password' dialog 2423 // open the 'Password' dialog
2424 PasswordForm *dialog = new PasswordForm(this, title, TRUE); 2424 PasswordForm *dialog = new PasswordForm(this, title, TRUE);
2425 newPwdDialog = dialog; 2425 newPwdDialog = dialog;
2426 newPwdDialogResult = false; 2426 newPwdDialogResult = false;
2427 2427
2428 QPixmap image0( ( const char** ) zsafe_xpm ); 2428 QPixmap image0( ( const char** ) zsafe_xpm );
2429 dialog->setIcon( image0); 2429 dialog->setIcon( image0);
2430 2430
2431 connect( dialog->PasswordField, SIGNAL( returnPressed() ), 2431 connect( dialog->PasswordField, SIGNAL( returnPressed() ),
2432 this, SLOT( setPasswordDialogDone() ) ); 2432 this, SLOT( setPasswordDialogDone() ) );
2433 2433
2434 // CS: !!! 2434 // CS: !!!
2435 // int pos = filename.findRev ('/'); 2435 // int pos = filename.findRev ('/');
2436 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 2436 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
2437#ifdef WIN32 2437#ifdef WIN32
2438 dialog->setCaption("Qt " + ti); 2438 dialog->setCaption("Qt " + ti);
2439#else 2439#else
2440 dialog->setCaption(ti); 2440 dialog->setCaption(ti);
2441#endif 2441#endif
2442 // dialog->setCaption(title); 2442 // dialog->setCaption(title);
2443 2443
2444 dialog->PasswordField->setFocus(); 2444 dialog->PasswordField->setFocus();