summaryrefslogtreecommitdiff
authorzcarsten <zcarsten>2003-08-01 07:01:38 (UTC)
committer zcarsten <zcarsten>2003-08-01 07:01:38 (UTC)
commitcb45aa10043fdd6fddcab42ef0e07ddafc3d506d (patch) (unidiff)
tree3d9e33ec1a9d9d3e93a0b72b9adf9d6e3c08e2ba
parent274bfafbda8d1d9af6cc5d1ced828a97a47c3f55 (diff)
downloadopie-cb45aa10043fdd6fddcab42ef0e07ddafc3d506d.zip
opie-cb45aa10043fdd6fddcab42ef0e07ddafc3d506d.tar.gz
opie-cb45aa10043fdd6fddcab42ef0e07ddafc3d506d.tar.bz2
editCategory improved: icon field is changed depending on the selected category
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index abf6511..ef16b46 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -1259,2315 +1259,2399 @@ void ZSafe::writeAllEntries()
1259 if (filename.isEmpty()) 1259 if (filename.isEmpty())
1260 { 1260 {
1261 QMessageBox::critical( 0, tr("ZSafe"), 1261 QMessageBox::critical( 0, tr("ZSafe"),
1262 tr("No document defined.\nYou have to create a new document")); 1262 tr("No document defined.\nYou have to create a new document"));
1263 return; 1263 return;
1264 } 1264 }
1265 1265
1266 // open the file dialog 1266 // open the file dialog
1267#ifndef DESKTOP 1267#ifndef DESKTOP
1268#ifndef NO_OPIE 1268#ifndef NO_OPIE
1269 QMap<QString, QStringList> mimeTypes; 1269 QMap<QString, QStringList> mimeTypes;
1270 mimeTypes.insert(tr("All"), QStringList() ); 1270 mimeTypes.insert(tr("All"), QStringList() );
1271 mimeTypes.insert(tr("Text"), "text/*" ); 1271 mimeTypes.insert(tr("Text"), "text/*" );
1272 QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 1272 QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
1273 QDir::homeDirPath() + "/Documents/application/zsafe", 1273 QDir::homeDirPath() + "/Documents/application/zsafe",
1274 QString::null, 1274 QString::null,
1275 mimeTypes, 1275 mimeTypes,
1276 this, 1276 this,
1277 tr ("Export text file")); 1277 tr ("Export text file"));
1278#else 1278#else
1279 QString fn = ScQtFileEdit::getSaveAsFileName(this, 1279 QString fn = ScQtFileEdit::getSaveAsFileName(this,
1280 tr ("Export text file"), 1280 tr ("Export text file"),
1281 QDir::homeDirPath() + "/Documents/application/zsafe", 1281 QDir::homeDirPath() + "/Documents/application/zsafe",
1282 "*.txt"); 1282 "*.txt");
1283#endif 1283#endif
1284#else 1284#else
1285 QString fn = QFileDialog::getSaveFileName( 1285 QString fn = QFileDialog::getSaveFileName(
1286 QDir::homeDirPath() + "/Documents/application/zsafe", 1286 QDir::homeDirPath() + "/Documents/application/zsafe",
1287 "ZSafe (*.txt)", 1287 "ZSafe (*.txt)",
1288 this, 1288 this,
1289 "ZSafe File Dialog" 1289 "ZSafe File Dialog"
1290 "Choose a text file" ); 1290 "Choose a text file" );
1291#endif 1291#endif
1292 1292
1293 // open the new document 1293 // open the new document
1294 if (fn && fn.length() > 0 ) 1294 if (fn && fn.length() > 0 )
1295 { 1295 {
1296 QFile f( fn ); 1296 QFile f( fn );
1297 if ( !f.open( IO_WriteOnly ) ) { 1297 if ( !f.open( IO_WriteOnly ) ) {
1298 qWarning( QString("Could not write to file %1").arg(fn), 1298 qWarning( QString("Could not write to file %1").arg(fn),
1299 2000 ); 1299 2000 );
1300 QMessageBox::critical( 0, "ZSafe", 1300 QMessageBox::critical( 0, "ZSafe",
1301 QString("Could not export to text file.") ); 1301 QString("Could not export to text file.") );
1302 return; 1302 return;
1303 } 1303 }
1304 QTextStream t( &f ); 1304 QTextStream t( &f );
1305 1305
1306 QListViewItem *i; 1306 QListViewItem *i;
1307 // step through all categories 1307 // step through all categories
1308 for (i = ListView->firstChild(); 1308 for (i = ListView->firstChild();
1309 i != NULL; 1309 i != NULL;
1310 i = i->nextSibling()) 1310 i = i->nextSibling())
1311 { 1311 {
1312 // step through all subitems 1312 // step through all subitems
1313 QListViewItem *si; 1313 QListViewItem *si;
1314 for (si = i->firstChild(); 1314 for (si = i->firstChild();
1315 si != NULL; 1315 si != NULL;
1316 si = si->nextSibling()) 1316 si = si->nextSibling())
1317 { 1317 {
1318 QString oneEntry; 1318 QString oneEntry;
1319 oneEntry += "\""; 1319 oneEntry += "\"";
1320 oneEntry += i->text(0); 1320 oneEntry += i->text(0);
1321 oneEntry += "\";"; 1321 oneEntry += "\";";
1322 oneEntry += "\""; 1322 oneEntry += "\"";
1323 oneEntry += si->text(0); 1323 oneEntry += si->text(0);
1324 oneEntry += "\";"; 1324 oneEntry += "\";";
1325 oneEntry += "\""; 1325 oneEntry += "\"";
1326 oneEntry += si->text(1); 1326 oneEntry += si->text(1);
1327 oneEntry += "\";"; 1327 oneEntry += "\";";
1328 oneEntry += "\""; 1328 oneEntry += "\"";
1329 oneEntry += si->text(2); 1329 oneEntry += si->text(2);
1330 oneEntry += "\";"; 1330 oneEntry += "\";";
1331 oneEntry += "\""; 1331 oneEntry += "\"";
1332 QString comment = si->text(3); 1332 QString comment = si->text(3);
1333 comment.replace (QRegExp("\n"), "<br>"); 1333 comment.replace (QRegExp("\n"), "<br>");
1334 oneEntry += comment; 1334 oneEntry += comment;
1335 oneEntry += "\";"; 1335 oneEntry += "\";";
1336 oneEntry += "\""; 1336 oneEntry += "\"";
1337 oneEntry += si->text(4); 1337 oneEntry += si->text(4);
1338 oneEntry += "\";"; 1338 oneEntry += "\";";
1339 oneEntry += "\""; 1339 oneEntry += "\"";
1340 oneEntry += si->text(5); 1340 oneEntry += si->text(5);
1341 oneEntry += "\""; 1341 oneEntry += "\"";
1342 // qWarning (oneEntry); 1342 // qWarning (oneEntry);
1343 t << oneEntry << endl; 1343 t << oneEntry << endl;
1344 1344
1345 // qWarning (si->text(0)); 1345 // qWarning (si->text(0));
1346 } 1346 }
1347 } 1347 }
1348 f.close(); 1348 f.close();
1349 } 1349 }
1350} 1350}
1351 1351
1352void ZSafe::readAllEntries() 1352void ZSafe::readAllEntries()
1353{ 1353{
1354 if (filename.isEmpty()) 1354 if (filename.isEmpty())
1355 { 1355 {
1356 QMessageBox::critical( 0, tr("ZSafe"), 1356 QMessageBox::critical( 0, tr("ZSafe"),
1357 tr("No document defined.\nYou have to create a new document")); 1357 tr("No document defined.\nYou have to create a new document"));
1358 return; 1358 return;
1359 } 1359 }
1360 1360
1361 // open the file dialog 1361 // open the file dialog
1362#ifndef DESKTOP 1362#ifndef DESKTOP
1363#ifndef NO_OPIE 1363#ifndef NO_OPIE
1364 QMap<QString, QStringList> mimeTypes; 1364 QMap<QString, QStringList> mimeTypes;
1365 mimeTypes.insert(tr("All"), QStringList() ); 1365 mimeTypes.insert(tr("All"), QStringList() );
1366 mimeTypes.insert(tr("Text"), "text/*" ); 1366 mimeTypes.insert(tr("Text"), "text/*" );
1367 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1367 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1368 QDir::homeDirPath() + "/Documents/application/zsafe", 1368 QDir::homeDirPath() + "/Documents/application/zsafe",
1369 QString::null, 1369 QString::null,
1370 mimeTypes, 1370 mimeTypes,
1371 this, 1371 this,
1372 tr ("Import text file")); 1372 tr ("Import text file"));
1373#else 1373#else
1374 QString fn = ScQtFileEdit::getOpenFileName(this, 1374 QString fn = ScQtFileEdit::getOpenFileName(this,
1375 tr ("Import text file"), 1375 tr ("Import text file"),
1376 QDir::homeDirPath() + "/Documents/application/zsafe", 1376 QDir::homeDirPath() + "/Documents/application/zsafe",
1377 "*.txt"); 1377 "*.txt");
1378#endif 1378#endif
1379#else 1379#else
1380 QString fn = QFileDialog::getOpenFileName( 1380 QString fn = QFileDialog::getOpenFileName(
1381 QDir::homeDirPath() + "/Documents/application/zsafe", 1381 QDir::homeDirPath() + "/Documents/application/zsafe",
1382 "ZSafe (*.txt)", 1382 "ZSafe (*.txt)",
1383 this, 1383 this,
1384 "ZSafe File Dialog" 1384 "ZSafe File Dialog"
1385 "Choose a text file" ); 1385 "Choose a text file" );
1386#endif 1386#endif
1387 1387
1388 if (fn && fn.length() > 0 ) 1388 if (fn && fn.length() > 0 )
1389 { 1389 {
1390 QFile f( fn ); 1390 QFile f( fn );
1391 if ( !f.open( IO_ReadOnly ) ) 1391 if ( !f.open( IO_ReadOnly ) )
1392 { 1392 {
1393 qWarning( QString("Could not read file %1").arg(fn), 1393 qWarning( QString("Could not read file %1").arg(fn),
1394 2000 ); 1394 2000 );
1395 QMessageBox::critical( 0, "ZSafe", 1395 QMessageBox::critical( 0, "ZSafe",
1396 QString("Could not import text file.") ); 1396 QString("Could not import text file.") );
1397 return; 1397 return;
1398 } 1398 }
1399 1399
1400 modified = true; 1400 modified = true;
1401 1401
1402 // clear the password list 1402 // clear the password list
1403 selectedItem = NULL; 1403 selectedItem = NULL;
1404 QListViewItem *i; 1404 QListViewItem *i;
1405 // step through all categories 1405 // step through all categories
1406 for (i = ListView->firstChild(); 1406 for (i = ListView->firstChild();
1407 i != NULL; 1407 i != NULL;
1408 i = i->nextSibling()) 1408 i = i->nextSibling())
1409 { 1409 {
1410 // step through all subitems 1410 // step through all subitems
1411 QListViewItem *si; 1411 QListViewItem *si;
1412 for (si = i->firstChild(); 1412 for (si = i->firstChild();
1413 si != NULL; ) 1413 si != NULL; )
1414 // si = si->nextSibling()) 1414 // si = si->nextSibling())
1415 { 1415 {
1416 QListViewItem *_si = si; 1416 QListViewItem *_si = si;
1417 si = si->nextSibling(); 1417 si = si->nextSibling();
1418 i->takeItem(_si); // remove from view list 1418 i->takeItem(_si); // remove from view list
1419 if (_si) delete _si; 1419 if (_si) delete _si;
1420 } 1420 }
1421 } 1421 }
1422 1422
1423 qWarning ("ReadAllEntries(): "); 1423 qWarning ("ReadAllEntries(): ");
1424 1424
1425 QTextStream t(&f); 1425 QTextStream t(&f);
1426 while ( !t.eof() ) 1426 while ( !t.eof() )
1427 { 1427 {
1428 QString s = t.readLine(); 1428 QString s = t.readLine();
1429 s.replace (QRegExp("\";\""), "\"|\""); 1429 s.replace (QRegExp("\";\""), "\"|\"");
1430 // char buffer[1024]; 1430 // char buffer[1024];
1431#ifndef WIN32 1431#ifndef WIN32
1432 char buffer[s.length()+1]; 1432 char buffer[s.length()+1];
1433#else 1433#else
1434 char buffer[4048]; 1434 char buffer[4048];
1435#endif 1435#endif
1436 strcpy (buffer, s); 1436 strcpy (buffer, s);
1437 1437
1438 QString name; 1438 QString name;
1439 QString user; 1439 QString user;
1440 QString password; 1440 QString password;
1441 QString comment; 1441 QString comment;
1442 QString field5=""; 1442 QString field5="";
1443 QString field6=""; 1443 QString field6="";
1444 1444
1445 // separete the entries 1445 // separete the entries
1446 char *i = strtok (buffer, "|"); 1446 char *i = strtok (buffer, "|");
1447 QString category(&i[1]); 1447 QString category(&i[1]);
1448 category.truncate(category.length() -1); 1448 category.truncate(category.length() -1);
1449 1449
1450 int idx=0; 1450 int idx=0;
1451 while ((i = strtok (NULL, "|")) != NULL) 1451 while ((i = strtok (NULL, "|")) != NULL)
1452 { 1452 {
1453 switch (idx) 1453 switch (idx)
1454 { 1454 {
1455 case 0: 1455 case 0:
1456 name = &i[1]; 1456 name = &i[1];
1457 name.truncate(name.length() -1); 1457 name.truncate(name.length() -1);
1458 // name 1458 // name
1459 break; 1459 break;
1460 case 1: 1460 case 1:
1461 // user 1461 // user
1462 user = &i[1]; 1462 user = &i[1];
1463 user.truncate(user.length() -1); 1463 user.truncate(user.length() -1);
1464 break; 1464 break;
1465 case 2: 1465 case 2:
1466 // password 1466 // password
1467 password = &i[1]; 1467 password = &i[1];
1468 password.truncate(password.length() -1); 1468 password.truncate(password.length() -1);
1469 break; 1469 break;
1470 case 3: 1470 case 3:
1471 // comment 1471 // comment
1472 comment = &i[1]; 1472 comment = &i[1];
1473 comment.truncate(comment.length() -1); 1473 comment.truncate(comment.length() -1);
1474 break; 1474 break;
1475 case 4: 1475 case 4:
1476 // field5 1476 // field5
1477 field5 = &i[1]; 1477 field5 = &i[1];
1478 field5.truncate(field5.length() -1); 1478 field5.truncate(field5.length() -1);
1479 break; 1479 break;
1480 case 5: 1480 case 5:
1481 // field6 1481 // field6
1482 field6 = &i[1]; 1482 field6 = &i[1];
1483 field6.truncate(field6.length() -1); 1483 field6.truncate(field6.length() -1);
1484 break; 1484 break;
1485 } 1485 }
1486 idx++; 1486 idx++;
1487 } 1487 }
1488 1488
1489 Category *cat= categories.find (category); 1489 Category *cat= categories.find (category);
1490 if (cat) 1490 if (cat)
1491 { 1491 {
1492 // use the existend item 1492 // use the existend item
1493 QListViewItem *catItem = cat->getListItem(); 1493 QListViewItem *catItem = cat->getListItem();
1494 if (catItem) 1494 if (catItem)
1495 { 1495 {
1496 QListViewItem * item = new ShadedListItem( 0, catItem ); 1496 QListViewItem * item = new ShadedListItem( 0, catItem );
1497 item->setText( 0, tr( name ) ); 1497 item->setText( 0, tr( name ) );
1498 item->setText( 1, tr( user ) ); 1498 item->setText( 1, tr( user ) );
1499 item->setText( 2, tr( password ) ); 1499 item->setText( 2, tr( password ) );
1500 item->setText( 3, tr( comment ) ); 1500 item->setText( 3, tr( comment ) );
1501 item->setText( 4, tr( field5 ) ); 1501 item->setText( 4, tr( field5 ) );
1502 item->setText( 5, tr( field6 ) ); 1502 item->setText( 5, tr( field6 ) );
1503 catItem->setOpen( TRUE ); 1503 catItem->setOpen( TRUE );
1504 } 1504 }
1505 } 1505 }
1506 else 1506 else
1507 { 1507 {
1508 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1508 QListViewItem *catI = new ShadedListItem( 1, ListView );
1509 // create and insert a new item 1509 // create and insert a new item
1510 QListViewItem * item = new ShadedListItem( 0, catI ); 1510 QListViewItem * item = new ShadedListItem( 0, catI );
1511 item->setText( 0, tr( name ) ); 1511 item->setText( 0, tr( name ) );
1512 item->setText( 1, tr( user ) ); 1512 item->setText( 1, tr( user ) );
1513 item->setText( 2, tr( password ) ); 1513 item->setText( 2, tr( password ) );
1514 item->setText( 3, tr( comment ) ); 1514 item->setText( 3, tr( comment ) );
1515 item->setText( 4, tr( field5 ) ); 1515 item->setText( 4, tr( field5 ) );
1516 item->setText( 5, tr( field6 ) ); 1516 item->setText( 5, tr( field6 ) );
1517 catI->setOpen( TRUE ); 1517 catI->setOpen( TRUE );
1518 1518
1519 Category *c1 = new Category(); 1519 Category *c1 = new Category();
1520 c1->setCategoryName(category); 1520 c1->setCategoryName(category);
1521 1521
1522 QString icon; 1522 QString icon;
1523 QString fullIconPath; 1523 QString fullIconPath;
1524 QPixmap *pix; 1524 QPixmap *pix;
1525// #ifndef WIN32 1525// #ifndef WIN32
1526 icon = conf->readEntry(APP_KEY+category); 1526 icon = conf->readEntry(APP_KEY+category);
1527// #endif 1527// #endif
1528 bool isIconAv = false; 1528 bool isIconAv = false;
1529 if (!icon.isEmpty() && !icon.isNull()) 1529 if (!icon.isEmpty() && !icon.isNull())
1530 { 1530 {
1531 // build the full path 1531 // build the full path
1532 fullIconPath = iconPath + icon; 1532 fullIconPath = iconPath + icon;
1533 pix = new QPixmap (fullIconPath); 1533 pix = new QPixmap (fullIconPath);
1534 if (pix) 1534 if (pix)
1535 { 1535 {
1536 QImage img = pix->convertToImage(); 1536 QImage img = pix->convertToImage();
1537 pix->convertFromImage(img.smoothScale(14,14)); 1537 pix->convertFromImage(img.smoothScale(14,14));
1538 c1->setIconName (icon); 1538 c1->setIconName (icon);
1539 c1->setIcon (*pix); 1539 c1->setIcon (*pix);
1540 isIconAv = true; 1540 isIconAv = true;
1541 } 1541 }
1542 } 1542 }
1543 if (!isIconAv) 1543 if (!isIconAv)
1544 { 1544 {
1545 c1->setIcon (*getPredefinedIcon(category)); 1545 c1->setIcon (*getPredefinedIcon(category));
1546 } 1546 }
1547 c1->setListItem (catI); 1547 c1->setListItem (catI);
1548 c1->initListItem(); 1548 c1->initListItem();
1549 categories.insert (c1->getCategoryName(), c1); 1549 categories.insert (c1->getCategoryName(), c1);
1550 } 1550 }
1551 1551
1552 } 1552 }
1553 f.close(); 1553 f.close();
1554 1554
1555 } 1555 }
1556 else 1556 else
1557 { 1557 {
1558 } 1558 }
1559 1559
1560} 1560}
1561 1561
1562#ifdef UNUSED 1562#ifdef UNUSED
1563void ZSafe::writeAllEntries() 1563void ZSafe::writeAllEntries()
1564{ 1564{
1565 // open the file for writing 1565 // open the file for writing
1566 QString fn = filename + ".txt"; 1566 QString fn = filename + ".txt";
1567 QFile f( fn ); 1567 QFile f( fn );
1568 if ( !f.open( IO_WriteOnly ) ) { 1568 if ( !f.open( IO_WriteOnly ) ) {
1569 qWarning( QString("Could not write to file %1").arg(fn), 1569 qWarning( QString("Could not write to file %1").arg(fn),
1570 2000 ); 1570 2000 );
1571 QMessageBox::critical( 0, tr("ZSafe"), 1571 QMessageBox::critical( 0, tr("ZSafe"),
1572 tr("Could not export to text file.") ); 1572 tr("Could not export to text file.") );
1573 return; 1573 return;
1574 } 1574 }
1575 QTextStream t( &f ); 1575 QTextStream t( &f );
1576 1576
1577 QListViewItem *i; 1577 QListViewItem *i;
1578 // step through all categories 1578 // step through all categories
1579 for (i = ListView->firstChild(); 1579 for (i = ListView->firstChild();
1580 i != NULL; 1580 i != NULL;
1581 i = i->nextSibling()) 1581 i = i->nextSibling())
1582 { 1582 {
1583 // step through all subitems 1583 // step through all subitems
1584 QListViewItem *si; 1584 QListViewItem *si;
1585 for (si = i->firstChild(); 1585 for (si = i->firstChild();
1586 si != NULL; 1586 si != NULL;
1587 si = si->nextSibling()) 1587 si = si->nextSibling())
1588 { 1588 {
1589 QString oneEntry; 1589 QString oneEntry;
1590 oneEntry += "\""; 1590 oneEntry += "\"";
1591 oneEntry += i->text(0); 1591 oneEntry += i->text(0);
1592 oneEntry += "\";"; 1592 oneEntry += "\";";
1593 oneEntry += "\""; 1593 oneEntry += "\"";
1594 oneEntry += si->text(0); 1594 oneEntry += si->text(0);
1595 oneEntry += "\";"; 1595 oneEntry += "\";";
1596 oneEntry += "\""; 1596 oneEntry += "\"";
1597 oneEntry += si->text(1); 1597 oneEntry += si->text(1);
1598 oneEntry += "\";"; 1598 oneEntry += "\";";
1599 oneEntry += "\""; 1599 oneEntry += "\"";
1600 oneEntry += si->text(2); 1600 oneEntry += si->text(2);
1601 oneEntry += "\";"; 1601 oneEntry += "\";";
1602 oneEntry += "\""; 1602 oneEntry += "\"";
1603 // oneEntry += si->text(3); 1603 // oneEntry += si->text(3);
1604 QString comment = si->text(3); 1604 QString comment = si->text(3);
1605 comment.replace (QRegExp("\n"), "<br>"); 1605 comment.replace (QRegExp("\n"), "<br>");
1606 oneEntry += comment; 1606 oneEntry += comment;
1607 oneEntry += "\""; 1607 oneEntry += "\"";
1608 // qWarning (oneEntry); 1608 // qWarning (oneEntry);
1609 t << oneEntry << endl; 1609 t << oneEntry << endl;
1610 1610
1611 // qWarning (si->text(0)); 1611 // qWarning (si->text(0));
1612 } 1612 }
1613 } 1613 }
1614 f.close(); 1614 f.close();
1615} 1615}
1616 1616
1617void ZSafe::readAllEntries() 1617void ZSafe::readAllEntries()
1618{ 1618{
1619 QString fn = filename + ".txt"; 1619 QString fn = filename + ".txt";
1620 QFile f( fn ); 1620 QFile f( fn );
1621 if ( !f.open( IO_ReadOnly ) ) 1621 if ( !f.open( IO_ReadOnly ) )
1622 { 1622 {
1623 qWarning( QString("Could not read file %1").arg(fn), 1623 qWarning( QString("Could not read file %1").arg(fn),
1624 2000 ); 1624 2000 );
1625 QMessageBox::critical( 0, tr("ZSafe"), 1625 QMessageBox::critical( 0, tr("ZSafe"),
1626 tr("Could not import text file.") ); 1626 tr("Could not import text file.") );
1627 return; 1627 return;
1628 } 1628 }
1629 1629
1630 modified = true; 1630 modified = true;
1631 1631
1632 // clear the password list 1632 // clear the password list
1633 selectedItem = NULL; 1633 selectedItem = NULL;
1634 QListViewItem *i; 1634 QListViewItem *i;
1635 // step through all categories 1635 // step through all categories
1636 for (i = ListView->firstChild(); 1636 for (i = ListView->firstChild();
1637 i != NULL; 1637 i != NULL;
1638 i = i->nextSibling()) 1638 i = i->nextSibling())
1639 { 1639 {
1640 // step through all subitems 1640 // step through all subitems
1641 QListViewItem *si; 1641 QListViewItem *si;
1642 for (si = i->firstChild(); 1642 for (si = i->firstChild();
1643 si != NULL; ) 1643 si != NULL; )
1644 // si = si->nextSibling()) 1644 // si = si->nextSibling())
1645 { 1645 {
1646 QListViewItem *_si = si; 1646 QListViewItem *_si = si;
1647 si = si->nextSibling(); 1647 si = si->nextSibling();
1648 i->takeItem(_si); // remove from view list 1648 i->takeItem(_si); // remove from view list
1649 if (_si) delete _si; 1649 if (_si) delete _si;
1650 } 1650 }
1651 } 1651 }
1652 1652
1653 qWarning ("ReadAllEntries(): "); 1653 qWarning ("ReadAllEntries(): ");
1654 1654
1655 QTextStream t(&f); 1655 QTextStream t(&f);
1656 while ( !t.eof() ) 1656 while ( !t.eof() )
1657 { 1657 {
1658 QString s = t.readLine(); 1658 QString s = t.readLine();
1659 s.replace (QRegExp("\";\""), "\"|\""); 1659 s.replace (QRegExp("\";\""), "\"|\"");
1660 // char buffer[1024]; 1660 // char buffer[1024];
1661 int len=s.length()+1; 1661 int len=s.length()+1;
1662#ifdef WIN32 1662#ifdef WIN32
1663 char buffer[512]; 1663 char buffer[512];
1664#else 1664#else
1665 char buffer[len]; 1665 char buffer[len];
1666#endif 1666#endif
1667 strcpy (buffer, s); 1667 strcpy (buffer, s);
1668 1668
1669 QString name; 1669 QString name;
1670 QString user; 1670 QString user;
1671 QString password; 1671 QString password;
1672 QString comment; 1672 QString comment;
1673 1673
1674 // separete the entries 1674 // separete the entries
1675 char *i = strtok (buffer, "|"); 1675 char *i = strtok (buffer, "|");
1676 QString category(&i[1]); 1676 QString category(&i[1]);
1677 category.truncate(category.length() -1); 1677 category.truncate(category.length() -1);
1678 1678
1679 int idx=0; 1679 int idx=0;
1680 while (i = strtok (NULL, "|")) 1680 while (i = strtok (NULL, "|"))
1681 { 1681 {
1682 switch (idx) 1682 switch (idx)
1683 { 1683 {
1684 case 0: 1684 case 0:
1685 name = &i[1]; 1685 name = &i[1];
1686 name.truncate(name.length() -1); 1686 name.truncate(name.length() -1);
1687 // name 1687 // name
1688 break; 1688 break;
1689 case 1: 1689 case 1:
1690 // user 1690 // user
1691 user = &i[1]; 1691 user = &i[1];
1692 user.truncate(user.length() -1); 1692 user.truncate(user.length() -1);
1693 break; 1693 break;
1694 case 2: 1694 case 2:
1695 // password 1695 // password
1696 password = &i[1]; 1696 password = &i[1];
1697 password.truncate(password.length() -1); 1697 password.truncate(password.length() -1);
1698 break; 1698 break;
1699 case 3: 1699 case 3:
1700 // comment 1700 // comment
1701 comment = &i[1]; 1701 comment = &i[1];
1702 comment.truncate(comment.length() -1); 1702 comment.truncate(comment.length() -1);
1703 break; 1703 break;
1704 } 1704 }
1705 idx++; 1705 idx++;
1706 } 1706 }
1707 1707
1708 Category *cat= categories.find (category); 1708 Category *cat= categories.find (category);
1709 if (cat) 1709 if (cat)
1710 { 1710 {
1711 // use the existend item 1711 // use the existend item
1712 QListViewItem *catItem = cat->getListItem(); 1712 QListViewItem *catItem = cat->getListItem();
1713 if (catItem) 1713 if (catItem)
1714 { 1714 {
1715 QListViewItem * item = new ShadedListItem( 0, catItem ); 1715 QListViewItem * item = new ShadedListItem( 0, catItem );
1716 item->setText( 0, tr( name ) ); 1716 item->setText( 0, tr( name ) );
1717 item->setText( 1, tr( user ) ); 1717 item->setText( 1, tr( user ) );
1718 item->setText( 2, tr( password ) ); 1718 item->setText( 2, tr( password ) );
1719 item->setText( 3, tr( comment ) ); 1719 item->setText( 3, tr( comment ) );
1720 catItem->setOpen( TRUE ); 1720 catItem->setOpen( TRUE );
1721 } 1721 }
1722 } 1722 }
1723 else 1723 else
1724 { 1724 {
1725 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1725 QListViewItem *catI = new ShadedListItem( 1, ListView );
1726 // create and insert a new item 1726 // create and insert a new item
1727 QListViewItem * item = new ShadedListItem( 0, catI ); 1727 QListViewItem * item = new ShadedListItem( 0, catI );
1728 item->setText( 0, tr( name ) ); 1728 item->setText( 0, tr( name ) );
1729 item->setText( 1, tr( user ) ); 1729 item->setText( 1, tr( user ) );
1730 item->setText( 2, tr( password ) ); 1730 item->setText( 2, tr( password ) );
1731 item->setText( 3, tr( comment ) ); 1731 item->setText( 3, tr( comment ) );
1732 catI->setOpen( TRUE ); 1732 catI->setOpen( TRUE );
1733 1733
1734 Category *c1 = new Category(); 1734 Category *c1 = new Category();
1735 c1->setCategoryName(category); 1735 c1->setCategoryName(category);
1736 1736
1737 QString icon; 1737 QString icon;
1738 QString fullIconPath; 1738 QString fullIconPath;
1739 QPixmap *pix; 1739 QPixmap *pix;
1740// #ifndef WIN32 1740// #ifndef WIN32
1741 icon = conf->readEntry(APP_KEY+category); 1741 icon = conf->readEntry(APP_KEY+category);
1742// #endif 1742// #endif
1743 bool isIconAv = false; 1743 bool isIconAv = false;
1744 if (!icon.isEmpty() && !icon.isNull()) 1744 if (!icon.isEmpty() && !icon.isNull())
1745 { 1745 {
1746 // build the full path 1746 // build the full path
1747 fullIconPath = iconPath + icon; 1747 fullIconPath = iconPath + icon;
1748 pix = new QPixmap (fullIconPath); 1748 pix = new QPixmap (fullIconPath);
1749 if (pix) 1749 if (pix)
1750 { 1750 {
1751 QImage img = pix->convertToImage(); 1751 QImage img = pix->convertToImage();
1752 pix->convertFromImage(img.smoothScale(14,14)); 1752 pix->convertFromImage(img.smoothScale(14,14));
1753 c1->setIconName (icon); 1753 c1->setIconName (icon);
1754 c1->setIcon (*pix); 1754 c1->setIcon (*pix);
1755 isIconAv = true; 1755 isIconAv = true;
1756 } 1756 }
1757 } 1757 }
1758 if (!isIconAv) 1758 if (!isIconAv)
1759 { 1759 {
1760 c1->setIcon (*getPredefinedIcon(category)); 1760 c1->setIcon (*getPredefinedIcon(category));
1761 } 1761 }
1762 c1->setListItem (catI); 1762 c1->setListItem (catI);
1763 c1->initListItem(); 1763 c1->initListItem();
1764 categories.insert (c1->getCategoryName(), c1); 1764 categories.insert (c1->getCategoryName(), c1);
1765 } 1765 }
1766 1766
1767 } 1767 }
1768 f.close(); 1768 f.close();
1769 1769
1770} 1770}
1771#endif // UNUSED 1771#endif // UNUSED
1772 1772
1773void ZSafe::resume(int) 1773void ZSafe::resume(int)
1774{ 1774{
1775 qWarning ("Resume"); 1775 qWarning ("Resume");
1776 // hide the main window 1776 // hide the main window
1777 1777
1778 infoForm->hide(); 1778 infoForm->hide();
1779 // open zsafe again 1779 // open zsafe again
1780 m_password = ""; 1780 m_password = "";
1781 selectedItem = NULL; 1781 selectedItem = NULL;
1782 1782
1783 // clear the password list 1783 // clear the password list
1784 QListViewItem *i; 1784 QListViewItem *i;
1785 // step through all categories 1785 // step through all categories
1786 for (i = ListView->firstChild(); 1786 for (i = ListView->firstChild();
1787 i != NULL; 1787 i != NULL;
1788 i = i->nextSibling()) 1788 i = i->nextSibling())
1789 { 1789 {
1790 // step through all subitems 1790 // step through all subitems
1791 QListViewItem *si; 1791 QListViewItem *si;
1792 for (si = i->firstChild(); 1792 for (si = i->firstChild();
1793 si != NULL; ) 1793 si != NULL; )
1794 { 1794 {
1795 QListViewItem *_si = si; 1795 QListViewItem *_si = si;
1796 si = si->nextSibling(); 1796 si = si->nextSibling();
1797 i->takeItem(_si); // remove from view list 1797 i->takeItem(_si); // remove from view list
1798 if (_si) delete _si; 1798 if (_si) delete _si;
1799 } 1799 }
1800 } 1800 }
1801 1801
1802 // ask for password and read again 1802 // ask for password and read again
1803 openDocument(filename); 1803 openDocument(filename);
1804} 1804}
1805 1805
1806//--------------------------------------------- 1806//---------------------------------------------
1807 1807
1808 1808
1809bool ZSafe::openDocument(const char* _filename, const char* ) 1809bool ZSafe::openDocument(const char* _filename, const char* )
1810{ 1810{
1811 int retval; 1811 int retval;
1812 char* entry[FIELD_SIZE]; 1812 char* entry[FIELD_SIZE];
1813// #ifndef WIN32 1813// #ifndef WIN32
1814 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); 1814 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1);
1815// #else 1815// #else
1816 // int validationFlag = 1; 1816 // int validationFlag = 1;
1817// #endif 1817// #endif
1818 1818
1819 int pwdOk = 0; 1819 int pwdOk = 0;
1820 int numberOfTries = 3; 1820 int numberOfTries = 3;
1821 for (int i=0; i < numberOfTries; i++) 1821 for (int i=0; i < numberOfTries; i++)
1822 { 1822 {
1823 QFile f(_filename); 1823 QFile f(_filename);
1824 if (f.exists()) 1824 if (f.exists())
1825 { 1825 {
1826 // ask with a dialog for the password 1826 // ask with a dialog for the password
1827 if (m_password.isEmpty()) 1827 if (m_password.isEmpty())
1828 getDocPassword(tr("Enter Password")); 1828 getDocPassword(tr("Enter Password"));
1829 if (m_password.isEmpty() && validationFlag == 0) 1829 if (m_password.isEmpty() && validationFlag == 0)
1830 { 1830 {
1831 qWarning ("Wrong password"); 1831 qWarning ("Wrong password");
1832 QMessageBox::critical( 0, tr("ZSafe"), 1832 QMessageBox::critical( 0, tr("ZSafe"),
1833 tr("Wrong password.\n\nZSafe will now exit.") ); 1833 tr("Wrong password.\n\nZSafe will now exit.") );
1834 exitZs (1); 1834 exitZs (1);
1835 } 1835 }
1836 1836
1837 retval = loadInit(_filename, m_password); 1837 retval = loadInit(_filename, m_password);
1838 if (retval != PWERR_GOOD) 1838 if (retval != PWERR_GOOD)
1839 { 1839 {
1840 qWarning ("Error loading Document"); 1840 qWarning ("Error loading Document");
1841 return false; 1841 return false;
1842 } 1842 }
1843 } 1843 }
1844 else 1844 else
1845 { 1845 {
1846#ifdef WIN32 1846#ifdef WIN32
1847 this->setCaption("Qt ZSafe"); 1847 this->setCaption("Qt ZSafe");
1848#else 1848#else
1849 this->setCaption("ZSafe"); 1849 this->setCaption("ZSafe");
1850#endif 1850#endif
1851 filename = ""; 1851 filename = "";
1852 return false; 1852 return false;
1853 } 1853 }
1854 1854
1855 1855
1856 // load the validation entry 1856 // load the validation entry
1857 if (validationFlag == 0) 1857 if (validationFlag == 0)
1858 { 1858 {
1859 pwdOk = 1; 1859 pwdOk = 1;
1860 break; 1860 break;
1861 } 1861 }
1862 1862
1863 retval = loadEntry(entry); 1863 retval = loadEntry(entry);
1864 if (retval == 1 && 1864 if (retval == 1 &&
1865 !strcmp (entry[0], "ZSAFECATEGORY") && 1865 !strcmp (entry[0], "ZSAFECATEGORY") &&
1866 !strcmp (entry[1], "name") && 1866 !strcmp (entry[1], "name") &&
1867 !strcmp (entry[2], "username") && 1867 !strcmp (entry[2], "username") &&
1868 !strcmp (entry[3], "password") && 1868 !strcmp (entry[3], "password") &&
1869 !strcmp (entry[4], "comment") ) 1869 !strcmp (entry[4], "comment") )
1870 { 1870 {
1871 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1871 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1872 pwdOk = 1; 1872 pwdOk = 1;
1873 break; 1873 break;
1874 } 1874 }
1875 else 1875 else
1876 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1876 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1877 fclose (fd); 1877 fclose (fd);
1878 m_password = ""; 1878 m_password = "";
1879 1879
1880 if (i < numberOfTries - 1) 1880 if (i < numberOfTries - 1)
1881 { 1881 {
1882 switch( QMessageBox::warning( this, tr("ZSafe"), 1882 switch( QMessageBox::warning( this, tr("ZSafe"),
1883 tr("Wrong password.\nEnter again?"), 1883 tr("Wrong password.\nEnter again?"),
1884 tr("&Yes"), tr("&No."), 1884 tr("&Yes"), tr("&No."),
1885 0 1885 0
1886 ) ) 1886 ) )
1887 { 1887 {
1888 case 1: // No 1888 case 1: // No
1889 exitZs (1); 1889 exitZs (1);
1890 break; 1890 break;
1891 case 0: // Yes 1891 case 0: // Yes
1892 continue; 1892 continue;
1893 } 1893 }
1894 } 1894 }
1895 } 1895 }
1896 if (pwdOk == 0) 1896 if (pwdOk == 0)
1897 { 1897 {
1898 // unset the document entry 1898 // unset the document entry
1899 conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); 1899 conf->writeEntry(APP_KEY+"document", "INVALIDPWD");
1900 if (conf) 1900 if (conf)
1901 delete conf; 1901 delete conf;
1902 1902
1903 exitZs (1); 1903 exitZs (1);
1904 } 1904 }
1905 1905
1906 1906
1907 retval = loadEntry(entry); 1907 retval = loadEntry(entry);
1908 1908
1909 int numberOfEntries=0; 1909 int numberOfEntries=0;
1910 while (retval == 1) { 1910 while (retval == 1) {
1911 1911
1912 QString category(entry[0]); 1912 QString category(entry[0]);
1913 QString name(entry[1]); 1913 QString name(entry[1]);
1914 QString user(entry[2]); 1914 QString user(entry[2]);
1915 QString password(entry[3]); 1915 QString password(entry[3]);
1916 QString comment(entry[4]); 1916 QString comment(entry[4]);
1917 QString field5(entry[5]); 1917 QString field5(entry[5]);
1918 QString field6(entry[6]); 1918 QString field6(entry[6]);
1919 // add the subitems to the categories 1919 // add the subitems to the categories
1920 1920
1921 Category *cat= categories.find (category); 1921 Category *cat= categories.find (category);
1922 if (cat) 1922 if (cat)
1923 { 1923 {
1924 // use the existend item 1924 // use the existend item
1925 QListViewItem *catItem = cat->getListItem(); 1925 QListViewItem *catItem = cat->getListItem();
1926 if (catItem) 1926 if (catItem)
1927 { 1927 {
1928 QListViewItem * item = new ShadedListItem( 0, catItem ); 1928 QListViewItem * item = new ShadedListItem( 0, catItem );
1929 item->setText( 0, tr( name ) ); 1929 item->setText( 0, tr( name ) );
1930 item->setText( 1, tr( user ) ); 1930 item->setText( 1, tr( user ) );
1931 item->setText( 2, tr( password ) ); 1931 item->setText( 2, tr( password ) );
1932 item->setText( 3, tr( comment ) ); 1932 item->setText( 3, tr( comment ) );
1933 item->setText( 4, tr( field5 ) ); 1933 item->setText( 4, tr( field5 ) );
1934 item->setText( 5, tr( field6 ) ); 1934 item->setText( 5, tr( field6 ) );
1935 if (expandTree) 1935 if (expandTree)
1936 catItem->setOpen( TRUE ); 1936 catItem->setOpen( TRUE );
1937 numberOfEntries++; 1937 numberOfEntries++;
1938 } 1938 }
1939 } 1939 }
1940 else 1940 else
1941 { 1941 {
1942 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1942 QListViewItem *catI = new ShadedListItem( 1, ListView );
1943 // create and insert a new item 1943 // create and insert a new item
1944 QListViewItem * item = new ShadedListItem( 0, catI ); 1944 QListViewItem * item = new ShadedListItem( 0, catI );
1945 item->setText( 0, tr( name ) ); 1945 item->setText( 0, tr( name ) );
1946 item->setText( 1, tr( user ) ); 1946 item->setText( 1, tr( user ) );
1947 item->setText( 2, tr( password ) ); 1947 item->setText( 2, tr( password ) );
1948 item->setText( 3, tr( comment ) ); 1948 item->setText( 3, tr( comment ) );
1949 item->setText( 4, tr( field5 ) ); 1949 item->setText( 4, tr( field5 ) );
1950 item->setText( 5, tr( field6 ) ); 1950 item->setText( 5, tr( field6 ) );
1951 if (expandTree) 1951 if (expandTree)
1952 catI->setOpen( TRUE ); 1952 catI->setOpen( TRUE );
1953 1953
1954 Category *c1 = new Category(); 1954 Category *c1 = new Category();
1955 c1->setCategoryName(category); 1955 c1->setCategoryName(category);
1956 1956
1957 QString icon; 1957 QString icon;
1958 QString fullIconPath; 1958 QString fullIconPath;
1959 QPixmap *pix; 1959 QPixmap *pix;
1960// #ifndef WIN32 1960// #ifndef WIN32
1961 icon = conf->readEntry(APP_KEY+category); 1961 icon = conf->readEntry(APP_KEY+category);
1962// #endif 1962// #endif
1963 bool isIconAv = false; 1963 bool isIconAv = false;
1964 if (!icon.isEmpty() && !icon.isNull()) 1964 if (!icon.isEmpty() && !icon.isNull())
1965 { 1965 {
1966 // build the full path 1966 // build the full path
1967 fullIconPath = iconPath + icon; 1967 fullIconPath = iconPath + icon;
1968 pix = new QPixmap (fullIconPath); 1968 pix = new QPixmap (fullIconPath);
1969 if (pix) 1969 if (pix)
1970 { 1970 {
1971 QImage img = pix->convertToImage(); 1971 QImage img = pix->convertToImage();
1972 pix->convertFromImage(img.smoothScale(14,14)); 1972 pix->convertFromImage(img.smoothScale(14,14));
1973 c1->setIconName (icon); 1973 c1->setIconName (icon);
1974 c1->setIcon (*pix); 1974 c1->setIcon (*pix);
1975 isIconAv = true; 1975 isIconAv = true;
1976 } 1976 }
1977 } 1977 }
1978 if (!isIconAv) 1978 if (!isIconAv)
1979 { 1979 {
1980 c1->setIcon (*getPredefinedIcon(category)); 1980 c1->setIcon (*getPredefinedIcon(category));
1981 } 1981 }
1982 1982
1983 c1->setListItem (catI); 1983 c1->setListItem (catI);
1984 c1->initListItem(); 1984 c1->initListItem();
1985 categories.insert (c1->getCategoryName(), c1); 1985 categories.insert (c1->getCategoryName(), c1);
1986 numberOfEntries++; 1986 numberOfEntries++;
1987 } 1987 }
1988 1988
1989 for (int count = 0; count < FIELD_SIZE; count++) { 1989 for (int count = 0; count < FIELD_SIZE; count++) {
1990 free(entry[count]); 1990 free(entry[count]);
1991 } 1991 }
1992 retval = loadEntry(entry); 1992 retval = loadEntry(entry);
1993 if (retval == 2) { 1993 if (retval == 2) {
1994 // m_parent->slotStatusHelpMsg("Last entry loaded"); 1994 // m_parent->slotStatusHelpMsg("Last entry loaded");
1995 } 1995 }
1996 } // end while 1996 } // end while
1997 1997
1998 if (numberOfEntries == 0) 1998 if (numberOfEntries == 0)
1999 { 1999 {
2000 2000
2001 switch( QMessageBox::warning( this, tr("ZSafe"), 2001 switch( QMessageBox::warning( this, tr("ZSafe"),
2002 tr("Empty document or\nwrong password.\nContinue?"), 2002 tr("Empty document or\nwrong password.\nContinue?"),
2003 tr("&No"), tr("&Yes."), 2003 tr("&No"), tr("&Yes."),
2004 0 2004 0
2005 ) ) { 2005 ) ) {
2006 case 0: // No 2006 case 0: // No
2007 retval = loadFinalize(); 2007 retval = loadFinalize();
2008 exitZs (1); 2008 exitZs (1);
2009 break; 2009 break;
2010 case 1: // Yes 2010 case 1: // Yes
2011 break; 2011 break;
2012 } 2012 }
2013 } 2013 }
2014 2014
2015 retval = loadFinalize(); 2015 retval = loadFinalize();
2016 2016
2017 return true; 2017 return true;
2018} 2018}
2019 2019
2020int ZSafe::loadInit(const char* _filename, const char *password) 2020int ZSafe::loadInit(const char* _filename, const char *password)
2021{ 2021{
2022 unsigned int j = 0; 2022 unsigned int j = 0;
2023 unsigned int keylength=0; 2023 unsigned int keylength=0;
2024 int count=0, count2=0, count3=0; 2024 int count=0, count2=0, count3=0;
2025 unsigned char charbuf[8]; 2025 unsigned char charbuf[8];
2026 unsigned short ciphertext[4]; 2026 unsigned short ciphertext[4];
2027 char key[128]; 2027 char key[128];
2028 Krc2* krc2 = new Krc2(); 2028 Krc2* krc2 = new Krc2();
2029 2029
2030 fd = fopen (_filename, "rb"); 2030 fd = fopen (_filename, "rb");
2031 2031
2032 QFileInfo f (_filename); 2032 QFileInfo f (_filename);
2033 load_buffer_length = f.size(); 2033 load_buffer_length = f.size();
2034 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; 2034 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2;
2035 2035
2036 if (fd == NULL) 2036 if (fd == NULL)
2037 return PWERR_OPEN; 2037 return PWERR_OPEN;
2038 2038
2039 buffer = (char *)malloc(load_buffer_length); 2039 buffer = (char *)malloc(load_buffer_length);
2040 for (j = 0; password[j] != '\0'; j++) { 2040 for (j = 0; password[j] != '\0'; j++) {
2041 key[j] = password[j]; 2041 key[j] = password[j];
2042 } 2042 }
2043 keylength = j; 2043 keylength = j;
2044 krc2->rc2_expandkey (key, keylength, 128); 2044 krc2->rc2_expandkey (key, keylength, 128);
2045 2045
2046#ifndef WIN32 2046#ifndef WIN32
2047 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); 2047 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
2048#else 2048#else
2049 printf ("LoadInit() read1"); 2049 printf ("LoadInit() read1");
2050 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2050 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2051#endif 2051#endif
2052 2052
2053 if (size < 8) 2053 if (size < 8)
2054 return PWERR_DATA; 2054 return PWERR_DATA;
2055 2055
2056 for (count = 0; count < 4; count++) { 2056 for (count = 0; count < 4; count++) {
2057 count2 = count << 1; 2057 count2 = count << 1;
2058 iv[count] = charbuf[count2] << 8; 2058 iv[count] = charbuf[count2] << 8;
2059 iv[count] += charbuf[count2 + 1]; 2059 iv[count] += charbuf[count2 + 1];
2060 } 2060 }
2061 2061
2062 size = 0; 2062 size = 0;
2063 bufferIndex = 0; 2063 bufferIndex = 0;
2064#ifndef WIN32 2064#ifndef WIN32
2065 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) { 2065 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
2066 while (count < 8) { 2066 while (count < 8) {
2067 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); 2067 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
2068#else 2068#else
2069 printf ("LoadInit() read2"); 2069 printf ("LoadInit() read2");
2070 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { 2070 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
2071 while (count < 8) { 2071 while (count < 8) {
2072 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2072 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2073#endif 2073#endif
2074 if (count2 == 0) { 2074 if (count2 == 0) {
2075 return PWERR_DATA; 2075 return PWERR_DATA;
2076 } 2076 }
2077 count += count2; 2077 count += count2;
2078 } /* while (count < 8) */ 2078 } /* while (count < 8) */
2079 2079
2080 size += 8; 2080 size += 8;
2081 for (count2 = 0; count2 < 8; count2 += 2) { 2081 for (count2 = 0; count2 < 8; count2 += 2) {
2082 count3 = count2 >> 1; 2082 count3 = count2 >> 1;
2083 ciphertext[count3] = charbuf[count2] << 8; 2083 ciphertext[count3] = charbuf[count2] << 8;
2084 ciphertext[count3] += charbuf[count2 + 1]; 2084 ciphertext[count3] += charbuf[count2 + 1];
2085 2085
2086 plaintext[count3] = ciphertext[count3] ^ iv[count3]; 2086 plaintext[count3] = ciphertext[count3] ^ iv[count3];
2087 iv[count3] = plaintext[count3]; 2087 iv[count3] = plaintext[count3];
2088 } /* for (count2) */ 2088 } /* for (count2) */
2089 2089
2090 krc2->rc2_decrypt (plaintext); 2090 krc2->rc2_decrypt (plaintext);
2091 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); 2091 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
2092 bufferIndex += 8; 2092 bufferIndex += 8;
2093 buffer[bufferIndex + 1] = '\0'; 2093 buffer[bufferIndex + 1] = '\0';
2094 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ 2094 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
2095 size -= buffer[size - 1]; 2095 size -= buffer[size - 1];
2096 lastcount = 0; 2096 lastcount = 0;
2097 2097
2098 /* This will point to the starting index */ 2098 /* This will point to the starting index */
2099 bufferIndex = 0; 2099 bufferIndex = 0;
2100 return PWERR_GOOD; 2100 return PWERR_GOOD;
2101} 2101}
2102 2102
2103int ZSafe::loadEntry(char *entry[FIELD_SIZE]) 2103int ZSafe::loadEntry(char *entry[FIELD_SIZE])
2104{ 2104{
2105 /* Strip off PKCS 5 padding 2105 /* Strip off PKCS 5 padding
2106 * Should check to make sure it's good here 2106 * Should check to make sure it's good here
2107 */ 2107 */
2108 int count, count1=0; 2108 int count, count1=0;
2109 2109
2110 for (count = lastcount; count < size; count++) { 2110 for (count = lastcount; count < size; count++) {
2111 if ((unsigned char) (buffer[count]) == 255) { 2111 if ((unsigned char) (buffer[count]) == 255) {
2112 if (buffer[bufferIndex] == '\0') { 2112 if (buffer[bufferIndex] == '\0') {
2113 bufferIndex++; 2113 bufferIndex++;
2114 } 2114 }
2115 entry[count1] = (char *) malloc (count - bufferIndex + 1); 2115 entry[count1] = (char *) malloc (count - bufferIndex + 1);
2116 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex); 2116 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex);
2117 entry[count1][count - bufferIndex] = '\0'; 2117 entry[count1][count - bufferIndex] = '\0';
2118 count++; 2118 count++;
2119 bufferIndex = count; 2119 bufferIndex = count;
2120 count1++; 2120 count1++;
2121 if (count1 == FIELD_SIZE) { 2121 if (count1 == FIELD_SIZE) {
2122 lastcount = count; 2122 lastcount = count;
2123 return 1; 2123 return 1;
2124 } 2124 }
2125 } /* if ((unsigned char) (buffer[count]) == 255) */ 2125 } /* if ((unsigned char) (buffer[count]) == 255) */
2126 } /* for (count = 0; count < size; count++) */ 2126 } /* for (count = 0; count < size; count++) */
2127 2127
2128 return 2; 2128 return 2;
2129} 2129}
2130 2130
2131int ZSafe::loadFinalize(void) 2131int ZSafe::loadFinalize(void)
2132{ 2132{
2133 fclose (fd); 2133 fclose (fd);
2134 if (buffer) free(buffer); 2134 if (buffer) free(buffer);
2135 return PWERR_GOOD; 2135 return PWERR_GOOD;
2136} 2136}
2137 2137
2138bool ZSafe::saveDocument(const char* _filename, 2138bool ZSafe::saveDocument(const char* _filename,
2139 bool withPwd, 2139 bool withPwd,
2140 const char* ) 2140 const char* )
2141{ 2141{
2142 if (filename.isEmpty()) 2142 if (filename.isEmpty())
2143 { 2143 {
2144 QMessageBox::critical( 0, tr("ZSafe"), 2144 QMessageBox::critical( 0, tr("ZSafe"),
2145 tr("No document defined.\nYou have to create a new document")); 2145 tr("No document defined.\nYou have to create a new document"));
2146 return false; 2146 return false;
2147 } 2147 }
2148 2148
2149 // if (m_password.isEmpty()) 2149 // if (m_password.isEmpty())
2150 // withPwd = true; // the document must be saved with a valid password 2150 // withPwd = true; // the document must be saved with a valid password
2151 if (withPwd) 2151 if (withPwd)
2152 { 2152 {
2153 bool pwdOk = FALSE; 2153 bool pwdOk = FALSE;
2154 while (!pwdOk) 2154 while (!pwdOk)
2155 { 2155 {
2156 getDocPassword(tr("Enter Password")); 2156 getDocPassword(tr("Enter Password"));
2157 if (m_password.isEmpty()) 2157 if (m_password.isEmpty())
2158 { 2158 {
2159 2159
2160 QMessageBox::critical( 0, tr("ZSafe"), 2160 QMessageBox::critical( 0, tr("ZSafe"),
2161 tr("Password is empty.\nPlease enter again.")); 2161 tr("Password is empty.\nPlease enter again."));
2162 continue; 2162 continue;
2163 } 2163 }
2164 2164
2165 QString firstPasswd = m_password; 2165 QString firstPasswd = m_password;
2166 2166
2167 getDocPassword(tr("Reenter Password")); 2167 getDocPassword(tr("Reenter Password"));
2168 if (m_password.isEmpty()) 2168 if (m_password.isEmpty())
2169 { 2169 {
2170 QMessageBox::critical( 0, tr("ZSafe"), 2170 QMessageBox::critical( 0, tr("ZSafe"),
2171 tr("Password is empty.\nPlease enter again.")); 2171 tr("Password is empty.\nPlease enter again."));
2172 continue; 2172 continue;
2173 } 2173 }
2174 if (firstPasswd != m_password) 2174 if (firstPasswd != m_password)
2175 { 2175 {
2176 2176
2177 QMessageBox::critical( 0, tr("ZSafe"), 2177 QMessageBox::critical( 0, tr("ZSafe"),
2178 tr("Passwords must be identical.\nPlease enter again.")); 2178 tr("Passwords must be identical.\nPlease enter again."));
2179 continue; 2179 continue;
2180 } 2180 }
2181 pwdOk = TRUE; 2181 pwdOk = TRUE;
2182 modified = false; 2182 modified = false;
2183 } 2183 }
2184 } 2184 }
2185 else if (modified) 2185 else if (modified)
2186 { 2186 {
2187 QString fns(_filename); 2187 QString fns(_filename);
2188 fns = fns.right (fns.length() - fns.findRev ('/') - 1); 2188 fns = fns.right (fns.length() - fns.findRev ('/') - 1);
2189 switch( QMessageBox::information( this, tr("ZSafe"), 2189 switch( QMessageBox::information( this, tr("ZSafe"),
2190 tr("Do you want to save ") + fns + tr("\nbefore continuing?"), 2190 tr("Do you want to save ") + fns + tr("\nbefore continuing?"),
2191 tr("&Save"), 2191 tr("&Save"),
2192 tr("&Don't Save"), 2192 tr("&Don't Save"),
2193 0 // Enter == button 0 2193 0 // Enter == button 0
2194 ) ) 2194 ) )
2195 { // Escape == button 2 2195 { // Escape == button 2
2196 case 0: // Save clicked, Alt-S or Enter pressed. 2196 case 0: // Save clicked, Alt-S or Enter pressed.
2197 modified = false; 2197 modified = false;
2198 break; 2198 break;
2199 case 1: // Don't Save clicked or Alt-D pressed 2199 case 1: // Don't Save clicked or Alt-D pressed
2200 modified = false; 2200 modified = false;
2201 return true; 2201 return true;
2202 } 2202 }
2203 } 2203 }
2204 modified = false; 2204 modified = false;
2205 2205
2206 if (m_password.isEmpty()) 2206 if (m_password.isEmpty())
2207 return false; 2207 return false;
2208 2208
2209 int retval = saveInit(_filename, m_password); 2209 int retval = saveInit(_filename, m_password);
2210 // int retval = saveInit(_filename, "test"); 2210 // int retval = saveInit(_filename, "test");
2211 if (retval != PWERR_GOOD) { 2211 if (retval != PWERR_GOOD) {
2212 return false; 2212 return false;
2213 } 2213 }
2214 2214
2215 char* entry[FIELD_SIZE]; 2215 char* entry[FIELD_SIZE];
2216 2216
2217 // save the validation entry 2217 // save the validation entry
2218 { 2218 {
2219 int i=0; 2219 int i=0;
2220 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1); 2220 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1);
2221 strcpy(entry[i++], "ZSAFECATEGORY"); 2221 strcpy(entry[i++], "ZSAFECATEGORY");
2222 entry[i] = (char*)malloc(strlen("name")+1); 2222 entry[i] = (char*)malloc(strlen("name")+1);
2223 strcpy(entry[i++], "name"); 2223 strcpy(entry[i++], "name");
2224 entry[i] = (char*)malloc(strlen("username")+1); 2224 entry[i] = (char*)malloc(strlen("username")+1);
2225 strcpy(entry[i++], "username"); 2225 strcpy(entry[i++], "username");
2226 entry[i] = (char*)malloc(strlen("password")+1); 2226 entry[i] = (char*)malloc(strlen("password")+1);
2227 strcpy(entry[i++], "password"); 2227 strcpy(entry[i++], "password");
2228 entry[i] = (char*)malloc(strlen("comment")+1); 2228 entry[i] = (char*)malloc(strlen("comment")+1);
2229 strcpy(entry[i++], "comment"); 2229 strcpy(entry[i++], "comment");
2230 2230
2231 entry[i] = (char*)malloc(strlen("field5")+1); 2231 entry[i] = (char*)malloc(strlen("field5")+1);
2232 strcpy(entry[i++], "field5"); 2232 strcpy(entry[i++], "field5");
2233 entry[i] = (char*)malloc(strlen("field6")+1); 2233 entry[i] = (char*)malloc(strlen("field6")+1);
2234 strcpy(entry[i++], "field6"); 2234 strcpy(entry[i++], "field6");
2235 2235
2236 retval = saveEntry(entry); 2236 retval = saveEntry(entry);
2237 for (int z=0; z<i; z++) free(entry[z]); 2237 for (int z=0; z<i; z++) free(entry[z]);
2238 if (retval == PWERR_DATA) { 2238 if (retval == PWERR_DATA) {
2239 qWarning("1: Error writing file, contents not saved"); 2239 qWarning("1: Error writing file, contents not saved");
2240 saveFinalize(); 2240 saveFinalize();
2241 return false; 2241 return false;
2242 } 2242 }
2243// #ifndef WIN32 2243// #ifndef WIN32
2244 conf->writeEntry(APP_KEY+"valzsafe", 1); 2244 conf->writeEntry(APP_KEY+"valzsafe", 1);
2245// #endif 2245// #endif
2246 saveConf(); 2246 saveConf();
2247 } 2247 }
2248 2248
2249 QListViewItem *i; 2249 QListViewItem *i;
2250 // step through all categories 2250 // step through all categories
2251 for (i = ListView->firstChild(); 2251 for (i = ListView->firstChild();
2252 i != NULL; 2252 i != NULL;
2253 i = i->nextSibling()) 2253 i = i->nextSibling())
2254 { 2254 {
2255 // step through all subitems 2255 // step through all subitems
2256 QListViewItem *si; 2256 QListViewItem *si;
2257 for (si = i->firstChild(); 2257 for (si = i->firstChild();
2258 si != NULL; 2258 si != NULL;
2259 si = si->nextSibling()) 2259 si = si->nextSibling())
2260 { 2260 {
2261 int j=0; 2261 int j=0;
2262 entry[j] = (char*)malloc(strlen(i->text(0))+1); 2262 entry[j] = (char*)malloc(strlen(i->text(0))+1);
2263 strcpy(entry[j++], i->text(0)); 2263 strcpy(entry[j++], i->text(0));
2264 entry[j] = (char*)malloc(strlen(si->text(0))+1); 2264 entry[j] = (char*)malloc(strlen(si->text(0))+1);
2265 strcpy(entry[j++], si->text(0)); 2265 strcpy(entry[j++], si->text(0));
2266 entry[j] = (char*)malloc(strlen(si->text(1))+1); 2266 entry[j] = (char*)malloc(strlen(si->text(1))+1);
2267 strcpy(entry[j++], si->text(1)); 2267 strcpy(entry[j++], si->text(1));
2268 entry[j] = (char*)malloc(strlen(si->text(2))+1); 2268 entry[j] = (char*)malloc(strlen(si->text(2))+1);
2269 strcpy(entry[j++], si->text(2)); 2269 strcpy(entry[j++], si->text(2));
2270 entry[j] = (char*)malloc(strlen(si->text(3))+1); 2270 entry[j] = (char*)malloc(strlen(si->text(3))+1);
2271 strcpy(entry[j++], si->text(3)); 2271 strcpy(entry[j++], si->text(3));
2272 2272
2273 entry[j] = (char*)malloc(strlen(si->text(4))+1); 2273 entry[j] = (char*)malloc(strlen(si->text(4))+1);
2274 strcpy(entry[j++], si->text(4)); 2274 strcpy(entry[j++], si->text(4));
2275 entry[j] = (char*)malloc(strlen(si->text(5))+1); 2275 entry[j] = (char*)malloc(strlen(si->text(5))+1);
2276 strcpy(entry[j++], si->text(5)); 2276 strcpy(entry[j++], si->text(5));
2277 2277
2278 retval = saveEntry(entry); 2278 retval = saveEntry(entry);
2279 for (int z=0; z<j; z++) 2279 for (int z=0; z<j; z++)
2280 { 2280 {
2281 free(entry[z]); 2281 free(entry[z]);
2282 } 2282 }
2283 if (retval == PWERR_DATA) { 2283 if (retval == PWERR_DATA) {
2284 qWarning("1: Error writing file, contents not saved"); 2284 qWarning("1: Error writing file, contents not saved");
2285 saveFinalize(); 2285 saveFinalize();
2286 return false; 2286 return false;
2287 } 2287 }
2288 2288
2289 } 2289 }
2290 } 2290 }
2291 2291
2292 if (saveFinalize() == PWERR_DATA) { 2292 if (saveFinalize() == PWERR_DATA) {
2293 qWarning("2: Error writing file, contents not saved"); 2293 qWarning("2: Error writing file, contents not saved");
2294 return false; 2294 return false;
2295 } else { 2295 } else {
2296#ifndef DESKTOP 2296#ifndef DESKTOP
2297 Global::statusMessage (tr("Password file saved.")); 2297 Global::statusMessage (tr("Password file saved."));
2298#endif 2298#endif
2299 modified = false; 2299 modified = false;
2300 return true; 2300 return true;
2301 } 2301 }
2302} 2302}
2303 2303
2304PasswordForm *newPwdDialog; 2304PasswordForm *newPwdDialog;
2305bool newPwdDialogResult = false; 2305bool newPwdDialogResult = false;
2306void ZSafe::setPasswordDialogDone() 2306void ZSafe::setPasswordDialogDone()
2307{ 2307{
2308 newPwdDialogResult = true; 2308 newPwdDialogResult = true;
2309 newPwdDialog->close(); 2309 newPwdDialog->close();
2310} 2310}
2311 2311
2312void ZSafe::getDocPassword(QString title) 2312void ZSafe::getDocPassword(QString title)
2313{ 2313{
2314qWarning ("getDocPassword"); 2314qWarning ("getDocPassword");
2315 // open the 'Password' dialog 2315 // open the 'Password' dialog
2316 PasswordForm *dialog = new PasswordForm(this, title, TRUE); 2316 PasswordForm *dialog = new PasswordForm(this, title, TRUE);
2317 newPwdDialog = dialog; 2317 newPwdDialog = dialog;
2318 newPwdDialogResult = false; 2318 newPwdDialogResult = false;
2319 2319
2320 connect( dialog->PasswordField, SIGNAL( returnPressed() ), 2320 connect( dialog->PasswordField, SIGNAL( returnPressed() ),
2321 this, SLOT( setPasswordDialogDone() ) ); 2321 this, SLOT( setPasswordDialogDone() ) );
2322 2322
2323 // CS: !!! 2323 // CS: !!!
2324 // int pos = filename.findRev ('/'); 2324 // int pos = filename.findRev ('/');
2325 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 2325 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
2326#ifdef WIN32 2326#ifdef WIN32
2327 dialog->setCaption("Qt " + ti); 2327 dialog->setCaption("Qt " + ti);
2328#else 2328#else
2329 dialog->setCaption(ti); 2329 dialog->setCaption(ti);
2330#endif 2330#endif
2331 // dialog->setCaption(title); 2331 // dialog->setCaption(title);
2332 2332
2333 dialog->PasswordField->setFocus(); 2333 dialog->PasswordField->setFocus();
2334 DialogCode result = (DialogCode) dialog->exec(); 2334 DialogCode result = (DialogCode) dialog->exec();
2335#ifdef DESKTOP 2335#ifdef DESKTOP
2336 result = Accepted; 2336 result = Accepted;
2337#endif 2337#endif
2338 2338
2339 QString password; 2339 QString password;
2340 if (result == Accepted || newPwdDialogResult) 2340 if (result == Accepted || newPwdDialogResult)
2341 { 2341 {
2342 m_password = dialog->PasswordField->text(); 2342 m_password = dialog->PasswordField->text();
2343 } 2343 }
2344 else 2344 else
2345 { 2345 {
2346 exitZs (1); 2346 exitZs (1);
2347 } 2347 }
2348} 2348}
2349 2349
2350int ZSafe::saveInit(const char *_filename, const char *password) 2350int ZSafe::saveInit(const char *_filename, const char *password)
2351{ 2351{
2352 char key[128]; 2352 char key[128];
2353 unsigned int j = 0; 2353 unsigned int j = 0;
2354 unsigned int keylength; 2354 unsigned int keylength;
2355 // int val; 2355 // int val;
2356 int count2; 2356 int count2;
2357 Krc2* krc2 = new Krc2(); 2357 Krc2* krc2 = new Krc2();
2358 2358
2359 /* first we should check the permissions of the filename */ 2359 /* first we should check the permissions of the filename */
2360/* 2360/*
2361 if (QFile::exists(_filename)) { 2361 if (QFile::exists(_filename)) {
2362 val = checkFile(_filename); 2362 val = checkFile(_filename);
2363 if (val != PWERR_GOOD) 2363 if (val != PWERR_GOOD)
2364 return val; 2364 return val;
2365 } else 2365 } else
2366 { 2366 {
2367 val = creat (_filename, (S_IRUSR | S_IWUSR)); 2367 val = creat (_filename, (S_IRUSR | S_IWUSR));
2368 if (val == -1) 2368 if (val == -1)
2369 return PWERR_OPEN; 2369 return PWERR_OPEN;
2370 else 2370 else
2371 close(val); 2371 close(val);
2372 } 2372 }
2373*/ 2373*/
2374 QFileInfo f (_filename); 2374 QFileInfo f (_filename);
2375 save_buffer_length = f.size(); 2375 save_buffer_length = f.size();
2376 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; 2376 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024;
2377 2377
2378 fd = fopen (_filename, "wb"); 2378 fd = fopen (_filename, "wb");
2379 if (fd == NULL) 2379 if (fd == NULL)
2380 return PWERR_OPEN; 2380 return PWERR_OPEN;
2381 2381
2382 buffer = (char*)malloc(save_buffer_length); 2382 buffer = (char*)malloc(save_buffer_length);
2383 2383
2384 /* make the key ready */ 2384 /* make the key ready */
2385 for (j = 0; password[j] != '\0'; j++) { 2385 for (j = 0; password[j] != '\0'; j++) {
2386 key[j] = password[j]; 2386 key[j] = password[j];
2387 } 2387 }
2388 keylength = j; 2388 keylength = j;
2389 krc2->rc2_expandkey (key, keylength, 128); 2389 krc2->rc2_expandkey (key, keylength, 128);
2390 2390
2391 /* First, we make the IV */ 2391 /* First, we make the IV */
2392 for (count2 = 0; count2 < 4; count2++) { 2392 for (count2 = 0; count2 < 4; count2++) {
2393 iv[count2] = rand (); 2393 iv[count2] = rand ();
2394 putc ((unsigned char) (iv[count2] >> 8), fd); 2394 putc ((unsigned char) (iv[count2] >> 8), fd);
2395 putc ((unsigned char) (iv[count2] & 0xff), fd); 2395 putc ((unsigned char) (iv[count2] & 0xff), fd);
2396 } 2396 }
2397 2397
2398 bufferIndex = 0; 2398 bufferIndex = 0;
2399 return PWERR_GOOD; 2399 return PWERR_GOOD;
2400} 2400}
2401 2401
2402 2402
2403int ZSafe::saveEntry(char *entry[FIELD_SIZE]) 2403int ZSafe::saveEntry(char *entry[FIELD_SIZE])
2404{ 2404{
2405 char *text1; 2405 char *text1;
2406 int count2, count3; 2406 int count2, count3;
2407 unsigned short ciphertext[4]; 2407 unsigned short ciphertext[4];
2408 Krc2* krc2 = new Krc2(); 2408 Krc2* krc2 = new Krc2();
2409 2409
2410 buffer = (char*)memset(buffer, '\0', save_buffer_length); 2410 buffer = (char*)memset(buffer, '\0', save_buffer_length);
2411 2411
2412 for (count2 = 0; count2 < FIELD_SIZE; count2++) { 2412 for (count2 = 0; count2 < FIELD_SIZE; count2++) {
2413 text1 = entry[count2]; 2413 text1 = entry[count2];
2414 if (strlen (text1) == 0) { 2414 if (strlen (text1) == 0) {
2415 strncat(buffer, " ", strlen(" ")); 2415 strncat(buffer, " ", strlen(" "));
2416 } else { 2416 } else {
2417 strncat(buffer, text1, strlen(text1)); 2417 strncat(buffer, text1, strlen(text1));
2418 } 2418 }
2419 /* Use 255 as the marker. \n is too tough to test for */ 2419 /* Use 255 as the marker. \n is too tough to test for */
2420 buffer[strlen (buffer)] = 255; 2420 buffer[strlen (buffer)] = 255;
2421 } /*for (count2 = 0; count2 < 5; count2++)*/ 2421 } /*for (count2 = 0; count2 < 5; count2++)*/
2422 count2 = 0; 2422 count2 = 0;
2423 /* I'm using CBC mode and encrypting the data straight from top down. 2423 /* I'm using CBC mode and encrypting the data straight from top down.
2424 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. 2424 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
2425 * PKCS 5 padding (explained at the code section 2425 * PKCS 5 padding (explained at the code section
2426 */ 2426 */
2427 while (count2 < (int)strlen (buffer)) { 2427 while (count2 < (int)strlen (buffer)) {
2428#ifndef WORDS_BIGENDIAN 2428#ifndef WORDS_BIGENDIAN
2429 plaintext[bufferIndex] = buffer[count2 + 1] << 8; 2429 plaintext[bufferIndex] = buffer[count2 + 1] << 8;
2430 plaintext[bufferIndex] += buffer[count2] & 0xff; 2430 plaintext[bufferIndex] += buffer[count2] & 0xff;
2431#endif 2431#endif
2432#ifdef WORDS_BIGENDIAN 2432#ifdef WORDS_BIGENDIAN
2433 plaintext[bufferIndex] = buffer[count2] << 8; 2433 plaintext[bufferIndex] = buffer[count2] << 8;
2434 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; 2434 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
2435#endif 2435#endif
2436 bufferIndex++; 2436 bufferIndex++;
2437 if (bufferIndex == 4) { 2437 if (bufferIndex == 4) {
2438 krc2->rc2_encrypt (plaintext); 2438 krc2->rc2_encrypt (plaintext);
2439 2439
2440 for (count3 = 0; count3 < 4; count3++) { 2440 for (count3 = 0; count3 < 4; count3++) {
2441 ciphertext[count3] = iv[count3] ^ plaintext[count3]; 2441 ciphertext[count3] = iv[count3] ^ plaintext[count3];
2442 2442
2443 /* Now store the ciphertext as the iv */ 2443 /* Now store the ciphertext as the iv */
2444 iv[count3] = plaintext[count3]; 2444 iv[count3] = plaintext[count3];
2445 2445
2446 /* reset the buffer index */ 2446 /* reset the buffer index */
2447 bufferIndex = 0; 2447 bufferIndex = 0;
2448 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; 2448 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA;
2449 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; 2449 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA;
2450 } /*for (count3 = 0; count3 < 5; count3++)*/ 2450 } /*for (count3 = 0; count3 < 5; count3++)*/
2451 } /*if (bufferIndex == 5)*/ 2451 } /*if (bufferIndex == 5)*/
2452 /* increment a short, not a byte */ 2452 /* increment a short, not a byte */
2453 count2 += 2; 2453 count2 += 2;
2454 } /*while (count2 < strlen (buffer))*/ 2454 } /*while (count2 < strlen (buffer))*/
2455 int ret = PWERR_GOOD; 2455 int ret = PWERR_GOOD;
2456 return ret; 2456 return ret;
2457} 2457}
2458 2458
2459int ZSafe::saveFinalize(void) 2459int ZSafe::saveFinalize(void)
2460{ 2460{
2461 int count1, retval = PWERR_GOOD; 2461 int count1, retval = PWERR_GOOD;
2462 unsigned short ciphertext[4]; 2462 unsigned short ciphertext[4];
2463 Krc2* krc2 = new Krc2(); 2463 Krc2* krc2 = new Krc2();
2464 2464
2465 /* Tack on the PKCS 5 padding 2465 /* Tack on the PKCS 5 padding
2466 * How it works is we fill up the last n bytes with the value n 2466 * How it works is we fill up the last n bytes with the value n
2467 * 2467 *
2468 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left 2468 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
2469 * over, leaving us 3 short, so we fill it in with 3's. 2469 * over, leaving us 3 short, so we fill it in with 3's.
2470 * 2470 *
2471 * If we come out even, we fill it with 8 8s 2471 * If we come out even, we fill it with 8 8s
2472 * 2472 *
2473 * um, except that in this instance we are using 4 shorts instead of 8 bytes. 2473 * um, except that in this instance we are using 4 shorts instead of 8 bytes.
2474 * so, half everything 2474 * so, half everything
2475 */ 2475 */
2476 for (count1 = bufferIndex; count1 < 4; count1++) { 2476 for (count1 = bufferIndex; count1 < 4; count1++) {
2477 plaintext[count1] = (4 - bufferIndex); 2477 plaintext[count1] = (4 - bufferIndex);
2478 } 2478 }
2479 krc2->rc2_encrypt (plaintext); 2479 krc2->rc2_encrypt (plaintext);
2480 for (count1 = 0; count1 < 4; count1++) { 2480 for (count1 = 0; count1 < 4; count1++) {
2481 ciphertext[count1] = iv[count1] ^ plaintext[count1]; 2481 ciphertext[count1] = iv[count1] ^ plaintext[count1];
2482 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; 2482 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA;
2483 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; 2483 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA;
2484 } 2484 }
2485 2485
2486 fclose (fd); 2486 fclose (fd);
2487 free(buffer); 2487 free(buffer);
2488 return retval; 2488 return retval;
2489} 2489}
2490 2490
2491void ZSafe::quitMe () 2491void ZSafe::quitMe ()
2492{ 2492{
2493 qWarning ("QUIT..."); 2493 qWarning ("QUIT...");
2494 2494
2495 if (modified) 2495 if (modified)
2496 { 2496 {
2497 switch( QMessageBox::information( this, tr("ZSafe"), 2497 switch( QMessageBox::information( this, tr("ZSafe"),
2498 tr("Do you want to save\nbefore exiting?"), 2498 tr("Do you want to save\nbefore exiting?"),
2499 tr("&Save"), 2499 tr("&Save"),
2500 tr("S&ave with\nnew\npassword"), 2500 tr("S&ave with\nnew\npassword"),
2501 tr("&Don't Save"), 2501 tr("&Don't Save"),
2502 0 // Enter == button 0 2502 0 // Enter == button 0
2503 ) ) 2503 ) )
2504 { // Escape == button 2 2504 { // Escape == button 2
2505 case 0: // Save clicked, Alt-S or Enter pressed. 2505 case 0: // Save clicked, Alt-S or Enter pressed.
2506 // save 2506 // save
2507 modified = false; 2507 modified = false;
2508 saveDocument(filename, FALSE); 2508 saveDocument(filename, FALSE);
2509 exitZs (1); 2509 exitZs (1);
2510 break; 2510 break;
2511 case 1: // 2511 case 1: //
2512 // Save with new password 2512 // Save with new password
2513 modified = false; 2513 modified = false;
2514 saveDocument(filename, TRUE); 2514 saveDocument(filename, TRUE);
2515 exitZs (1); 2515 exitZs (1);
2516 break; 2516 break;
2517 case 2: // Don't Save clicked or Alt-D pressed 2517 case 2: // Don't Save clicked or Alt-D pressed
2518 // don't save but exitZs 2518 // don't save but exitZs
2519 exitZs (1); 2519 exitZs (1);
2520 break; 2520 break;
2521 } 2521 }
2522 } 2522 }
2523 exitZs (1); 2523 exitZs (1);
2524 2524
2525} 2525}
2526 2526
2527void ZSafe::categoryFieldActivated( const QString& category) 2527void ZSafe::categoryFieldActivated( const QString& category)
2528{ 2528{
2529 if (categoryDialog) 2529 if (categoryDialog)
2530 setCategoryDialogFields(categoryDialog, category); 2530 setCategoryDialogFields(categoryDialog, category);
2531} 2531}
2532 2532
2533void ZSafe::addCategory() 2533void ZSafe::addCategory()
2534{ 2534{
2535 if (filename.isEmpty()) 2535 if (filename.isEmpty())
2536 { 2536 {
2537 QMessageBox::critical( 0, tr("ZSafe"), 2537 QMessageBox::critical( 0, tr("ZSafe"),
2538 tr("No document defined.\nYou have to create a new document")); 2538 tr("No document defined.\nYou have to create a new document"));
2539 return; 2539 return;
2540 } 2540 }
2541 else 2541 else
2542 { 2542 {
2543 // open the 'Category' dialog 2543 // open the 'Category' dialog
2544 bool initIcons = false; 2544 bool initIcons = false;
2545 // open the 'Category' dialog 2545 // open the 'Category' dialog
2546 CategoryDialog *dialog; 2546 CategoryDialog *dialog;
2547 if (categoryDialog) 2547 if (categoryDialog)
2548 { 2548 {
2549 dialog = categoryDialog; 2549 dialog = categoryDialog;
2550 } 2550 }
2551 else 2551 else
2552 { 2552 {
2553 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 2553 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
2554#ifdef WIN32 2554#ifdef WIN32
2555 categoryDialog->setCaption ("Qt " + tr("Category")); 2555 categoryDialog->setCaption ("Qt " + tr("Category"));
2556#endif 2556#endif
2557 dialog = categoryDialog; 2557 dialog = categoryDialog;
2558 connect( dialog->CategoryField, 2558 connect( dialog->CategoryField,
2559 SIGNAL( activated ( const QString &)), 2559 SIGNAL( activated ( const QString &)),
2560 this, SLOT( categoryFieldActivated( const QString & ) ) ); 2560 this, SLOT( categoryFieldActivated( const QString & ) ) );
2561 initIcons = true; 2561 initIcons = true;
2562 } 2562 }
2563 2563
2564#ifdef DESKTOP 2564#ifdef DESKTOP
2565#ifndef WIN32 2565#ifndef WIN32
2566 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 2566 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
2567#else 2567#else
2568 // read all categories from the config file and store 2568 // read all categories from the config file and store
2569 // into a list 2569 // into a list
2570 QFile f (cfgFile); 2570 QFile f (cfgFile);
2571 QStringList list; 2571 QStringList list;
2572 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2572 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2573 QTextStream t( &f ); // use a text stream 2573 QTextStream t( &f ); // use a text stream
2574 QString s; 2574 QString s;
2575 int n = 1; 2575 int n = 1;
2576 while ( !t.eof() ) { // until end of file... 2576 while ( !t.eof() ) { // until end of file...
2577 s = t.readLine(); // line of text excluding '\n' 2577 s = t.readLine(); // line of text excluding '\n'
2578 list.append(s); 2578 list.append(s);
2579 } 2579 }
2580 f.close(); 2580 f.close();
2581 } 2581 }
2582#endif 2582#endif
2583#else 2583#else
2584 // read all categories from the config file and store 2584 // read all categories from the config file and store
2585 // into a list 2585 // into a list
2586 QFile f (cfgFile); 2586 QFile f (cfgFile);
2587 QStringList list; 2587 QStringList list;
2588 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2588 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2589 QTextStream t( &f ); // use a text stream 2589 QTextStream t( &f ); // use a text stream
2590 QString s; 2590 QString s;
2591 while ( !t.eof() ) { // until end of file... 2591 while ( !t.eof() ) { // until end of file...
2592 s = t.readLine(); // line of text excluding '\n' 2592 s = t.readLine(); // line of text excluding '\n'
2593 list.append(s); 2593 list.append(s);
2594 } 2594 }
2595 f.close(); 2595 f.close();
2596 } 2596 }
2597#endif 2597#endif
2598 QStringList::Iterator it = list.begin(); 2598 QStringList::Iterator it = list.begin();
2599 QString categ; 2599 QString categ;
2600 dialog->CategoryField->clear(); // remove all items 2600 dialog->CategoryField->clear(); // remove all items
2601 while( it != list.end() ) 2601 while( it != list.end() )
2602 { 2602 {
2603 QString *cat = new QString (*it); 2603 QString *cat = new QString (*it);
2604 if (cat->contains("-field1", FALSE)) 2604 if (cat->contains("-field1", FALSE))
2605 { 2605 {
2606#ifdef DESKTOP 2606#ifdef DESKTOP
2607#ifndef WIN32 2607#ifndef WIN32
2608 categ = cat->section ("-field1", 0, 0); 2608 categ = cat->section ("-field1", 0, 0);
2609#else 2609#else
2610 int pos = cat->find ("-field1"); 2610 int pos = cat->find ("-field1");
2611 categ = cat->left (pos); 2611 categ = cat->left (pos);
2612#endif 2612#endif
2613#else 2613#else
2614 int pos = cat->find ("-field1"); 2614 int pos = cat->find ("-field1");
2615 cat->truncate(pos); 2615 cat->truncate(pos);
2616 categ = *cat; 2616 categ = *cat;
2617#endif 2617#endif
2618 if (!categ.isEmpty()) 2618 if (!categ.isEmpty())
2619 { 2619 {
2620 dialog->CategoryField->insertItem (categ, -1); 2620 dialog->CategoryField->insertItem (categ, -1);
2621 } 2621 }
2622 } 2622 }
2623 ++it; 2623 ++it;
2624 } 2624 }
2625 2625
2626 2626
2627 setCategoryDialogFields(dialog); 2627 setCategoryDialogFields(dialog);
2628 2628
2629 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); 2629 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE);
2630 2630
2631 if (initIcons) 2631 if (initIcons)
2632 { 2632 {
2633 Wait waitDialog(this, tr("Wait dialog")); 2633 Wait waitDialog(this, tr("Wait dialog"));
2634 waitDialog.waitLabel->setText(tr("Gathering icons...")); 2634 waitDialog.waitLabel->setText(tr("Gathering icons..."));
2635 waitDialog.show(); 2635 waitDialog.show();
2636 qApp->processEvents(); 2636 qApp->processEvents();
2637 2637
2638#ifdef DESKTOP 2638#ifdef DESKTOP
2639 QDir d(iconPath); 2639 QDir d(iconPath);
2640#else 2640#else
2641 QDir d(QPEApplication::qpeDir() + "/pics/"); 2641 QDir d(QPEApplication::qpeDir() + "/pics/");
2642#endif 2642#endif
2643 d.setFilter( QDir::Files); 2643 d.setFilter( QDir::Files);
2644 2644
2645 const QFileInfoList *list = d.entryInfoList(); 2645 const QFileInfoList *list = d.entryInfoList();
2646 QFileInfoListIterator it( *list ); // create list iterator 2646 QFileInfoListIterator it( *list ); // create list iterator
2647 QFileInfo *fi; // pointer for traversing 2647 QFileInfo *fi; // pointer for traversing
2648 2648
2649 dialog->IconField->insertItem("predefined"); 2649 dialog->IconField->insertItem("predefined");
2650 while ( (fi=it.current()) ) { // for each file... 2650 while ( (fi=it.current()) ) { // for each file...
2651 QString fileName = fi->fileName(); 2651 QString fileName = fi->fileName();
2652 if(fileName.right(4) == ".png"){ 2652 if(fileName.right(4) == ".png"){
2653 fileName = fileName.mid(0,fileName.length()-4); 2653 fileName = fileName.mid(0,fileName.length()-4);
2654#ifdef DESKTOP 2654#ifdef DESKTOP
2655 QPixmap imageOfFile; 2655 QPixmap imageOfFile;
2656 imageOfFile.load(iconPath + fi->fileName()); 2656 imageOfFile.load(iconPath + fi->fileName());
2657#else 2657#else
2658 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 2658 QPixmap imageOfFile(Resource::loadPixmap(fileName));
2659#endif 2659#endif
2660 QImage foo = imageOfFile.convertToImage(); 2660 QImage foo = imageOfFile.convertToImage();
2661 foo = foo.smoothScale(16,16); 2661 foo = foo.smoothScale(16,16);
2662 imageOfFile.convertFromImage(foo); 2662 imageOfFile.convertFromImage(foo);
2663 dialog->IconField->insertItem(imageOfFile,fileName); 2663 dialog->IconField->insertItem(imageOfFile,fileName);
2664 } 2664 }
2665 ++it; 2665 ++it;
2666 } 2666 }
2667 waitDialog.hide(); 2667 waitDialog.hide();
2668 } 2668 }
2669 2669
2670#ifndef WIN32 2670#ifndef WIN32
2671 dialog->show(); 2671 dialog->show();
2672#endif 2672#endif
2673#ifndef DESKTOP 2673#ifndef DESKTOP
2674 // dialog->move (20, 100); 2674 // dialog->move (20, 100);
2675#endif 2675#endif
2676 DialogCode result = (DialogCode) dialog->exec(); 2676 DialogCode result = (DialogCode) dialog->exec();
2677#ifdef DESKTOP 2677#ifdef DESKTOP
2678 result = Accepted; 2678 result = Accepted;
2679#endif 2679#endif
2680 2680
2681 QString category; 2681 QString category;
2682 QString icon; 2682 QString icon;
2683 QString fullIconPath; 2683 QString fullIconPath;
2684 QPixmap *pix; 2684 QPixmap *pix;
2685 if (result == Accepted) 2685 if (result == Accepted)
2686 { 2686 {
2687 modified = true; 2687 modified = true;
2688 category = dialog->CategoryField->currentText(); 2688 category = dialog->CategoryField->currentText();
2689 icon = dialog->IconField->currentText()+".png"; 2689 icon = dialog->IconField->currentText()+".png";
2690 2690
2691 qWarning (category); 2691 qWarning (category);
2692 2692
2693 QListViewItem *li = new ShadedListItem( 1, ListView ); 2693 QListViewItem *li = new ShadedListItem( 1, ListView );
2694 Category *c1 = new Category(); 2694 Category *c1 = new Category();
2695 c1->setCategoryName(category); 2695 c1->setCategoryName(category);
2696 2696
2697 // if (!icon.isEmpty() && !icon.isNull()) 2697 // if (!icon.isEmpty() && !icon.isNull())
2698 if (icon != "predefined.png") 2698 if (icon != "predefined.png")
2699 { 2699 {
2700 // build the full path 2700 // build the full path
2701 fullIconPath = iconPath + icon; 2701 fullIconPath = iconPath + icon;
2702 pix = new QPixmap (fullIconPath); 2702 pix = new QPixmap (fullIconPath);
2703 // pix->resize(14, 14); 2703 // pix->resize(14, 14);
2704 if (pix) 2704 if (pix)
2705 { 2705 {
2706 // save the full pixmap name into the config file 2706 // save the full pixmap name into the config file
2707// #ifndef WIN32 2707// #ifndef WIN32
2708 conf->writeEntry(APP_KEY+category, icon); 2708 conf->writeEntry(APP_KEY+category, icon);
2709// #endif 2709// #endif
2710 saveConf(); 2710 saveConf();
2711 QImage img = pix->convertToImage(); 2711 QImage img = pix->convertToImage();
2712 pix->convertFromImage(img.smoothScale(14,14)); 2712 pix->convertFromImage(img.smoothScale(14,14));
2713 c1->setIcon (*pix); 2713 c1->setIcon (*pix);
2714 c1->setIconName(icon); 2714 c1->setIconName(icon);
2715 } 2715 }
2716 else 2716 else
2717 { 2717 {
2718 QPixmap folder( ( const char** ) general_data ); 2718 QPixmap folder( ( const char** ) general_data );
2719 c1->setIcon (folder); 2719 c1->setIcon (folder);
2720 } 2720 }
2721 } 2721 }
2722 else 2722 else
2723 { 2723 {
2724 c1->setIcon (*getPredefinedIcon(category)); 2724 c1->setIcon (*getPredefinedIcon(category));
2725 } 2725 }
2726 2726
2727 c1->setListItem (li); 2727 c1->setListItem (li);
2728 c1->initListItem(); 2728 c1->initListItem();
2729 categories.insert (c1->getCategoryName(), c1); 2729 categories.insert (c1->getCategoryName(), c1);
2730 2730
2731 saveCategoryDialogFields(dialog); 2731 saveCategoryDialogFields(dialog);
2732 } 2732 }
2733 else 2733 else
2734 { 2734 {
2735 // delete dialog; 2735 // delete dialog;
2736 dialog->hide(); 2736 dialog->hide();
2737 return; 2737 return;
2738 } 2738 }
2739 2739
2740 } 2740 }
2741 2741
2742} 2742}
2743 2743
2744void ZSafe::delCategory() 2744void ZSafe::delCategory()
2745{ 2745{
2746 if (!selectedItem) 2746 if (!selectedItem)
2747 return; 2747 return;
2748 if (isCategory(selectedItem)) 2748 if (isCategory(selectedItem))
2749 { 2749 {
2750 switch( QMessageBox::information( this, tr("ZSafe"), 2750 switch( QMessageBox::information( this, tr("ZSafe"),
2751 tr("Do you want to delete?"), 2751 tr("Do you want to delete?"),
2752 tr("&Delete"), tr("D&on't Delete"), 2752 tr("&Delete"), tr("D&on't Delete"),
2753 0 // Enter == button 0 2753 0 // Enter == button 0
2754 ) ) { // Escape == button 2 2754 ) ) { // Escape == button 2
2755 case 0: // Delete clicked, Alt-S or Enter pressed. 2755 case 0: // Delete clicked, Alt-S or Enter pressed.
2756 // Delete from the category list 2756 // Delete from the category list
2757 modified = true; 2757 modified = true;
2758 categories.remove (selectedItem->text(0)); 2758 categories.remove (selectedItem->text(0));
2759// #ifndef WIN32 2759// #ifndef WIN32
2760 conf->removeEntry (selectedItem->text(0)); 2760 conf->removeEntry (selectedItem->text(0));
2761// #endif 2761// #endif
2762 saveConf(); 2762 saveConf();
2763 2763
2764 // Delete the selected item and all subitems 2764 // Delete the selected item and all subitems
2765 // step through all subitems 2765 // step through all subitems
2766 QListViewItem *si; 2766 QListViewItem *si;
2767 for (si = selectedItem->firstChild(); 2767 for (si = selectedItem->firstChild();
2768 si != NULL; ) 2768 si != NULL; )
2769 { 2769 {
2770 QListViewItem *_si = si; 2770 QListViewItem *_si = si;
2771 si = si->nextSibling(); 2771 si = si->nextSibling();
2772 selectedItem->takeItem(_si); // remove from view list 2772 selectedItem->takeItem(_si); // remove from view list
2773 if (_si) delete _si; 2773 if (_si) delete _si;
2774 } 2774 }
2775 ListView->takeItem(selectedItem); 2775 ListView->takeItem(selectedItem);
2776 delete selectedItem; 2776 delete selectedItem;
2777 2777
2778 selectedItem = NULL; 2778 selectedItem = NULL;
2779 break; 2779 break;
2780 case 1: // Don't delete 2780 case 1: // Don't delete
2781 break; 2781 break;
2782 } 2782 }
2783 2783
2784 } 2784 }
2785} 2785}
2786 2786
2787void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) 2787void ZSafe::setCategoryDialogFields(CategoryDialog *dialog)
2788{ 2788{
2789 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 2789 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name")));
2790 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 2790 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username")));
2791 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 2791 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password")));
2792 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 2792 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
2793 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); 2793 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4")));
2794 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); 2794 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5")));
2795
2796 QString icon;
2797 Category *cat= categories.find (selectedItem->text(0));
2798 if (cat)
2799 {
2800 icon = cat->getIconName();
2801 }
2802
2803#ifdef DESKTOP
2804 QDir d(iconPath);
2805#else
2806 QDir d(QPEApplication::qpeDir() + "/pics/");
2807#endif
2808 d.setFilter( QDir::Files);
2809
2810 const QFileInfoList *list = d.entryInfoList();
2811 int i=0;
2812 QFileInfoListIterator it( *list ); // create list iterator
2813 QFileInfo *fi; // pointer for traversing
2814 if (icon.isEmpty() || icon.isNull())
2815 {
2816 dialog->IconField->setCurrentItem(0);
2817 }
2818 else
2819 {
2820 while ( (fi=it.current()) )
2821 { // for each file...
2822 QString fileName = fi->fileName();
2823 if(fileName.right(4) == ".png")
2824 {
2825 fileName = fileName.mid(0,fileName.length()-4);
2826
2827 if(fileName+".png"==icon)
2828 {
2829 dialog->IconField->setCurrentItem(i+1);
2830 break;
2831 }
2832 ++i;
2833 }
2834 ++it;
2835 }
2836 }
2795} 2837}
2796 2838
2797void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) 2839void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category)
2798{ 2840{
2799 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); 2841 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name")));
2800 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); 2842 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username")));
2801 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); 2843 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password")));
2802 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); 2844 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment")));
2803 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); 2845 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4")));
2804 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); 2846 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5")));
2847
2848 QString icon;
2849 Category *cat= categories.find (category);
2850 if (cat)
2851 {
2852 icon = cat->getIconName();
2853 }
2854
2855#ifdef DESKTOP
2856 QDir d(iconPath);
2857#else
2858 QDir d(QPEApplication::qpeDir() + "/pics/");
2859#endif
2860 d.setFilter( QDir::Files);
2861
2862 const QFileInfoList *list = d.entryInfoList();
2863 int i=0;
2864 QFileInfoListIterator it( *list ); // create list iterator
2865 QFileInfo *fi; // pointer for traversing
2866 if (icon.isEmpty() || icon.isNull())
2867 {
2868 dialog->IconField->setCurrentItem(0);
2869 }
2870 else
2871 {
2872 while ( (fi=it.current()) )
2873 { // for each file...
2874 QString fileName = fi->fileName();
2875 if(fileName.right(4) == ".png")
2876 {
2877 fileName = fileName.mid(0,fileName.length()-4);
2878
2879 if(fileName+".png"==icon)
2880 {
2881 dialog->IconField->setCurrentItem(i+1);
2882 break;
2883 }
2884 ++i;
2885 }
2886 ++it;
2887 }
2888 }
2805} 2889}
2806 2890
2807void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) 2891void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog)
2808{ 2892{
2809 QString app_key = APP_KEY; 2893 QString app_key = APP_KEY;
2810#ifndef DESKTOP 2894#ifndef DESKTOP
2811 conf->setGroup ("fieldDefs"); 2895 conf->setGroup ("fieldDefs");
2812#else 2896#else
2813#ifndef WIN32 2897#ifndef WIN32
2814 app_key += "/fieldDefs/"; 2898 app_key += "/fieldDefs/";
2815#endif 2899#endif
2816#endif 2900#endif
2817 QString category = dialog->CategoryField->currentText(); 2901 QString category = dialog->CategoryField->currentText();
2818// #ifndef WIN32 2902// #ifndef WIN32
2819 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); 2903 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text());
2820 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); 2904 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text());
2821 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); 2905 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text());
2822 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); 2906 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text());
2823 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); 2907 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text());
2824 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); 2908 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text());
2825// #endif 2909// #endif
2826 saveConf(); 2910 saveConf();
2827#ifndef DESKTOP 2911#ifndef DESKTOP
2828 conf->setGroup ("zsafe"); 2912 conf->setGroup ("zsafe");
2829#endif 2913#endif
2830} 2914}
2831 2915
2832void ZSafe::editCategory() 2916void ZSafe::editCategory()
2833{ 2917{
2834 if (!selectedItem) 2918 if (!selectedItem)
2835 return; 2919 return;
2836 if (isCategory(selectedItem)) 2920 if (isCategory(selectedItem))
2837 { 2921 {
2838 QString category = selectedItem->text(0); 2922 QString category = selectedItem->text(0);
2839 bool initIcons = false; 2923 bool initIcons = false;
2840 // open the 'Category' dialog 2924 // open the 'Category' dialog
2841 CategoryDialog *dialog; 2925 CategoryDialog *dialog;
2842 if (categoryDialog) 2926 if (categoryDialog)
2843 { 2927 {
2844 dialog = categoryDialog; 2928 dialog = categoryDialog;
2845 } 2929 }
2846 else 2930 else
2847 { 2931 {
2848 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 2932 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
2849#ifdef WIN32 2933#ifdef WIN32
2850 categoryDialog->setCaption ("Qt " + tr("Category")); 2934 categoryDialog->setCaption ("Qt " + tr("Category"));
2851#endif 2935#endif
2852 dialog = categoryDialog; 2936 dialog = categoryDialog;
2853 connect( dialog->CategoryField, 2937 connect( dialog->CategoryField,
2854 SIGNAL( activated ( const QString &)), 2938 SIGNAL( activated ( const QString &)),
2855 this, SLOT( categoryFieldActivated( const QString & ) ) ); 2939 this, SLOT( categoryFieldActivated( const QString & ) ) );
2856 initIcons = true; 2940 initIcons = true;
2857 } 2941 }
2858 setCategoryDialogFields(dialog); 2942 setCategoryDialogFields(dialog);
2859 2943
2860#ifdef DESKTOP 2944#ifdef DESKTOP
2861#ifndef WIN32 2945#ifndef WIN32
2862 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 2946 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
2863#else 2947#else
2864 // read all categories from the config file and store 2948 // read all categories from the config file and store
2865 // into a list 2949 // into a list
2866 QFile f (cfgFile); 2950 QFile f (cfgFile);
2867 QStringList list; 2951 QStringList list;
2868 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2952 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2869 QTextStream t( &f ); // use a text stream 2953 QTextStream t( &f ); // use a text stream
2870 QString s; 2954 QString s;
2871 int n = 1; 2955 int n = 1;
2872 while ( !t.eof() ) { // until end of file... 2956 while ( !t.eof() ) { // until end of file...
2873 s = t.readLine(); // line of text excluding '\n' 2957 s = t.readLine(); // line of text excluding '\n'
2874 list.append(s); 2958 list.append(s);
2875 } 2959 }
2876 f.close(); 2960 f.close();
2877 } 2961 }
2878#endif 2962#endif
2879#else 2963#else
2880 // read all categories from the config file and store 2964 // read all categories from the config file and store
2881 // into a list 2965 // into a list
2882 QFile f (cfgFile); 2966 QFile f (cfgFile);
2883 QStringList list; 2967 QStringList list;
2884 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2968 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2885 QTextStream t( &f ); // use a text stream 2969 QTextStream t( &f ); // use a text stream
2886 QString s; 2970 QString s;
2887 while ( !t.eof() ) { // until end of file... 2971 while ( !t.eof() ) { // until end of file...
2888 s = t.readLine(); // line of text excluding '\n' 2972 s = t.readLine(); // line of text excluding '\n'
2889 list.append(s); 2973 list.append(s);
2890 } 2974 }
2891 f.close(); 2975 f.close();
2892 } 2976 }
2893#endif 2977#endif
2894 QStringList::Iterator it = list.begin(); 2978 QStringList::Iterator it = list.begin();
2895 QString categ; 2979 QString categ;
2896 dialog->CategoryField->clear(); // remove all items 2980 dialog->CategoryField->clear(); // remove all items
2897 int i=0; 2981 int i=0;
2898 bool foundCategory = false; 2982 bool foundCategory = false;
2899 while( it != list.end() ) 2983 while( it != list.end() )
2900 { 2984 {
2901 QString *cat = new QString (*it); 2985 QString *cat = new QString (*it);
2902 if (cat->contains("-field1", FALSE)) 2986 if (cat->contains("-field1", FALSE))
2903 { 2987 {
2904#ifdef DESKTOP 2988#ifdef DESKTOP
2905#ifndef WIN32 2989#ifndef WIN32
2906 categ = cat->section ("-field1", 0, 0); 2990 categ = cat->section ("-field1", 0, 0);
2907#else 2991#else
2908 int pos = cat->find ("-field1"); 2992 int pos = cat->find ("-field1");
2909 categ = cat->left (pos); 2993 categ = cat->left (pos);
2910#endif 2994#endif
2911#else 2995#else
2912 int pos = cat->find ("-field1"); 2996 int pos = cat->find ("-field1");
2913 cat->truncate(pos); 2997 cat->truncate(pos);
2914 categ = *cat; 2998 categ = *cat;
2915#endif 2999#endif
2916 if (!categ.isEmpty()) 3000 if (!categ.isEmpty())
2917 { 3001 {
2918 dialog->CategoryField->insertItem (categ, i); 3002 dialog->CategoryField->insertItem (categ, i);
2919 if (category.compare(categ) == 0) 3003 if (category.compare(categ) == 0)
2920 { 3004 {
2921 dialog->CategoryField->setCurrentItem(i); 3005 dialog->CategoryField->setCurrentItem(i);
2922 foundCategory = true; 3006 foundCategory = true;
2923 } 3007 }
2924 i++; 3008 i++;
2925 } 3009 }
2926 } 3010 }
2927 ++it; 3011 ++it;
2928 } 3012 }
2929 if (!foundCategory) 3013 if (!foundCategory)
2930 { 3014 {
2931 dialog->CategoryField->insertItem (category, i); 3015 dialog->CategoryField->insertItem (category, i);
2932 dialog->CategoryField->setCurrentItem(i); 3016 dialog->CategoryField->setCurrentItem(i);
2933 } 3017 }
2934 3018
2935 QString icon; 3019 QString icon;
2936 Category *cat= categories.find (selectedItem->text(0)); 3020 Category *cat= categories.find (selectedItem->text(0));
2937 if (cat) 3021 if (cat)
2938 { 3022 {
2939 icon = cat->getIconName(); 3023 icon = cat->getIconName();
2940 } 3024 }
2941 3025
2942 if (initIcons) 3026 if (initIcons)
2943 { 3027 {
2944 3028
2945 Wait waitDialog(this, tr("Wait dialog")); 3029 Wait waitDialog(this, tr("Wait dialog"));
2946 waitDialog.waitLabel->setText(tr("Gathering icons...")); 3030 waitDialog.waitLabel->setText(tr("Gathering icons..."));
2947 waitDialog.show(); 3031 waitDialog.show();
2948 qApp->processEvents(); 3032 qApp->processEvents();
2949 3033
2950#ifdef DESKTOP 3034#ifdef DESKTOP
2951 QDir d(iconPath); 3035 QDir d(iconPath);
2952#else 3036#else
2953 QDir d(QPEApplication::qpeDir() + "/pics/"); 3037 QDir d(QPEApplication::qpeDir() + "/pics/");
2954#endif 3038#endif
2955 d.setFilter( QDir::Files); 3039 d.setFilter( QDir::Files);
2956 3040
2957 const QFileInfoList *list = d.entryInfoList(); 3041 const QFileInfoList *list = d.entryInfoList();
2958 int i=0; 3042 int i=0;
2959 QFileInfoListIterator it( *list ); // create list iterator 3043 QFileInfoListIterator it( *list ); // create list iterator
2960 QFileInfo *fi; // pointer for traversing 3044 QFileInfo *fi; // pointer for traversing
2961 if (icon.isEmpty() || icon.isNull()) 3045 if (icon.isEmpty() || icon.isNull())
2962 { 3046 {
2963 dialog->IconField->setCurrentItem(0); 3047 dialog->IconField->setCurrentItem(0);
2964 } 3048 }
2965 3049
2966 dialog->IconField->insertItem("predefined"); 3050 dialog->IconField->insertItem("predefined");
2967 while ( (fi=it.current()) ) { // for each file... 3051 while ( (fi=it.current()) ) { // for each file...
2968 QString fileName = fi->fileName(); 3052 QString fileName = fi->fileName();
2969 if(fileName.right(4) == ".png") 3053 if(fileName.right(4) == ".png")
2970 { 3054 {
2971 fileName = fileName.mid(0,fileName.length()-4); 3055 fileName = fileName.mid(0,fileName.length()-4);
2972#ifdef DESKTOP 3056#ifdef DESKTOP
2973 QPixmap imageOfFile; 3057 QPixmap imageOfFile;
2974 imageOfFile.load(iconPath + fi->fileName()); 3058 imageOfFile.load(iconPath + fi->fileName());
2975#else 3059#else
2976 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 3060 QPixmap imageOfFile(Resource::loadPixmap(fileName));
2977#endif 3061#endif
2978 QImage foo = imageOfFile.convertToImage(); 3062 QImage foo = imageOfFile.convertToImage();
2979 foo = foo.smoothScale(16,16); 3063 foo = foo.smoothScale(16,16);
2980 imageOfFile.convertFromImage(foo); 3064 imageOfFile.convertFromImage(foo);
2981 dialog->IconField->insertItem(imageOfFile,fileName); 3065 dialog->IconField->insertItem(imageOfFile,fileName);
2982 if(fileName+".png"==icon) 3066 if(fileName+".png"==icon)
2983 dialog->IconField->setCurrentItem(i+1); 3067 dialog->IconField->setCurrentItem(i+1);
2984 ++i; 3068 ++i;
2985 } 3069 }
2986 ++it; 3070 ++it;
2987 } 3071 }
2988 waitDialog.hide(); 3072 waitDialog.hide();
2989 } 3073 }
2990 else 3074 else
2991 { 3075 {
2992#ifdef DESKTOP 3076#ifdef DESKTOP
2993 // QDir d(QDir::homeDirPath() + "/pics/"); 3077 // QDir d(QDir::homeDirPath() + "/pics/");
2994 QDir d(iconPath); 3078 QDir d(iconPath);
2995#else 3079#else
2996 QDir d(QPEApplication::qpeDir() + "/pics/"); 3080 QDir d(QPEApplication::qpeDir() + "/pics/");
2997#endif 3081#endif
2998 d.setFilter( QDir::Files); 3082 d.setFilter( QDir::Files);
2999 3083
3000 const QFileInfoList *list = d.entryInfoList(); 3084 const QFileInfoList *list = d.entryInfoList();
3001 int i=0; 3085 int i=0;
3002 QFileInfoListIterator it( *list ); // create list iterator 3086 QFileInfoListIterator it( *list ); // create list iterator
3003 QFileInfo *fi; // pointer for traversing 3087 QFileInfo *fi; // pointer for traversing
3004 if (icon.isEmpty() || icon.isNull()) 3088 if (icon.isEmpty() || icon.isNull())
3005 { 3089 {
3006 dialog->IconField->setCurrentItem(0); 3090 dialog->IconField->setCurrentItem(0);
3007 } 3091 }
3008 else 3092 else
3009 { 3093 {
3010 3094
3011 while ( (fi=it.current()) ) 3095 while ( (fi=it.current()) )
3012 { // for each file... 3096 { // for each file...
3013 QString fileName = fi->fileName(); 3097 QString fileName = fi->fileName();
3014 if(fileName.right(4) == ".png") 3098 if(fileName.right(4) == ".png")
3015 { 3099 {
3016 fileName = fileName.mid(0,fileName.length()-4); 3100 fileName = fileName.mid(0,fileName.length()-4);
3017 3101
3018 3102
3019 if(fileName+".png"==icon) 3103 if(fileName+".png"==icon)
3020 { 3104 {
3021 dialog->IconField->setCurrentItem(i+1); 3105 dialog->IconField->setCurrentItem(i+1);
3022 break; 3106 break;
3023 } 3107 }
3024 ++i; 3108 ++i;
3025 } 3109 }
3026 ++it; 3110 ++it;
3027 } 3111 }
3028 } 3112 }
3029 } 3113 }
3030 3114
3031 // dialog->show(); 3115 // dialog->show();
3032#ifndef DESKTOP 3116#ifndef DESKTOP
3033 // dialog->move (20, 100); 3117 // dialog->move (20, 100);
3034#endif 3118#endif
3035 DialogCode result = (DialogCode) dialog->exec(); 3119 DialogCode result = (DialogCode) dialog->exec();
3036#ifdef DESKTOP 3120#ifdef DESKTOP
3037 result = Accepted; 3121 result = Accepted;
3038#endif 3122#endif
3039 3123
3040 QString fullIconPath; 3124 QString fullIconPath;
3041 QPixmap *pix; 3125 QPixmap *pix;
3042 if (result == Accepted) 3126 if (result == Accepted)
3043 { 3127 {
3044 modified = true; 3128 modified = true;
3045 if (category != dialog->CategoryField->currentText()) 3129 if (category != dialog->CategoryField->currentText())
3046 { 3130 {
3047 categories.remove (category); 3131 categories.remove (category);
3048// #ifndef WIN32 3132// #ifndef WIN32
3049 conf->removeEntry(category); 3133 conf->removeEntry(category);
3050// #endif 3134// #endif
3051 saveConf(); 3135 saveConf();
3052 } 3136 }
3053 3137
3054 category = dialog->CategoryField->currentText(); 3138 category = dialog->CategoryField->currentText();
3055 icon = dialog->IconField->currentText()+".png"; 3139 icon = dialog->IconField->currentText()+".png";
3056 3140
3057 if (cat) 3141 if (cat)
3058 { 3142 {
3059 qWarning("Category found"); 3143 qWarning("Category found");
3060 3144
3061 // if (!icon.isEmpty() && !icon.isNull()) 3145 // if (!icon.isEmpty() && !icon.isNull())
3062 if (icon != "predefined.png") 3146 if (icon != "predefined.png")
3063 { 3147 {
3064 // build the full path 3148 // build the full path
3065 fullIconPath = iconPath + icon; 3149 fullIconPath = iconPath + icon;
3066 pix = new QPixmap (fullIconPath); 3150 pix = new QPixmap (fullIconPath);
3067 if (pix) 3151 if (pix)
3068 { 3152 {
3069 // save the full pixmap name into the config file 3153 // save the full pixmap name into the config file
3070// #ifndef WIN32 3154// #ifndef WIN32
3071 conf->writeEntry(APP_KEY+category, icon); 3155 conf->writeEntry(APP_KEY+category, icon);
3072// #endif 3156// #endif
3073 saveConf(); 3157 saveConf();
3074 QImage img = pix->convertToImage(); 3158 QImage img = pix->convertToImage();
3075 pix->convertFromImage(img.smoothScale(14,14)); 3159 pix->convertFromImage(img.smoothScale(14,14));
3076 cat->setIconName (icon); 3160 cat->setIconName (icon);
3077 cat->setIcon (*pix); 3161 cat->setIcon (*pix);
3078 } 3162 }
3079 } 3163 }
3080 else 3164 else
3081 { 3165 {
3082// #ifndef WIN32 3166// #ifndef WIN32
3083 conf->removeEntry (category); 3167 conf->removeEntry (category);
3084// #endif 3168// #endif
3085 saveConf(); 3169 saveConf();
3086 cat->setIcon (*getPredefinedIcon(category)); 3170 cat->setIcon (*getPredefinedIcon(category));
3087 } 3171 }
3088 3172
3089 // change the category name of the selected category 3173 // change the category name of the selected category
3090 QListViewItem *catItem = cat->getListItem(); 3174 QListViewItem *catItem = cat->getListItem();
3091 if (catItem) 3175 if (catItem)
3092 { 3176 {
3093 qWarning (category); 3177 qWarning (category);
3094 catItem->setText( 0, tr( category ) ); 3178 catItem->setText( 0, tr( category ) );
3095 cat->setCategoryName (tr(category)); 3179 cat->setCategoryName (tr(category));
3096 cat->initListItem(); 3180 cat->initListItem();
3097 categories.insert (category, cat); 3181 categories.insert (category, cat);
3098 } 3182 }
3099 } 3183 }
3100 saveCategoryDialogFields(dialog); 3184 saveCategoryDialogFields(dialog);
3101 } 3185 }
3102 else 3186 else
3103 { 3187 {
3104 // delete dialog; 3188 // delete dialog;
3105 dialog->hide(); 3189 dialog->hide();
3106 return; 3190 return;
3107 } 3191 }
3108 3192
3109 } 3193 }
3110} 3194}
3111 3195
3112void ZSafe::cutItem() 3196void ZSafe::cutItem()
3113{ 3197{
3114 if (!selectedItem) 3198 if (!selectedItem)
3115 return; 3199 return;
3116 if (!isCategory(selectedItem)) 3200 if (!isCategory(selectedItem))
3117 { 3201 {
3118 IsCut = true; 3202 IsCut = true;
3119 copiedItem = selectedItem; 3203 copiedItem = selectedItem;
3120 } 3204 }
3121} 3205}
3122 3206
3123void ZSafe::copyItem() 3207void ZSafe::copyItem()
3124{ 3208{
3125 if (!selectedItem) 3209 if (!selectedItem)
3126 return; 3210 return;
3127 if (!isCategory(selectedItem)) 3211 if (!isCategory(selectedItem))
3128 { 3212 {
3129 IsCopy = true; 3213 IsCopy = true;
3130 copiedItem = selectedItem; 3214 copiedItem = selectedItem;
3131 } 3215 }
3132} 3216}
3133 3217
3134// paste item into category 3218// paste item into category
3135void ZSafe::pasteItem() 3219void ZSafe::pasteItem()
3136{ 3220{
3137 if (!selectedItem) 3221 if (!selectedItem)
3138 return; 3222 return;
3139 if (isCategory(selectedItem)) 3223 if (isCategory(selectedItem))
3140 { 3224 {
3141 modified = true; 3225 modified = true;
3142 if (IsCut) 3226 if (IsCut)
3143 { 3227 {
3144 if (copiedItem) 3228 if (copiedItem)
3145 { 3229 {
3146 // add the new item 3230 // add the new item
3147 QListViewItem *i = new ShadedListItem (0, selectedItem); 3231 QListViewItem *i = new ShadedListItem (0, selectedItem);
3148 // i->setOpen (TRUE); 3232 // i->setOpen (TRUE);
3149 i->setText (0, copiedItem->text(0)); 3233 i->setText (0, copiedItem->text(0));
3150 i->setText (1, copiedItem->text(1)); 3234 i->setText (1, copiedItem->text(1));
3151 i->setText (2, copiedItem->text(2)); 3235 i->setText (2, copiedItem->text(2));
3152 i->setText (3, copiedItem->text(3)); 3236 i->setText (3, copiedItem->text(3));
3153 i->setText (4, copiedItem->text(4)); 3237 i->setText (4, copiedItem->text(4));
3154 i->setText (5, copiedItem->text(5)); 3238 i->setText (5, copiedItem->text(5));
3155 selectedItem->setOpen( TRUE ); 3239 selectedItem->setOpen( TRUE );
3156 3240
3157 // remove the cutted item 3241 // remove the cutted item
3158 copiedItem->parent()->takeItem(copiedItem); 3242 copiedItem->parent()->takeItem(copiedItem);
3159 selectedItem = NULL; 3243 selectedItem = NULL;
3160 } 3244 }
3161 } 3245 }
3162 else if (IsCopy) 3246 else if (IsCopy)
3163 { 3247 {
3164 if (copiedItem) 3248 if (copiedItem)
3165 { 3249 {
3166 // add the new item 3250 // add the new item
3167 QListViewItem *i = new ShadedListItem (0, selectedItem); 3251 QListViewItem *i = new ShadedListItem (0, selectedItem);
3168 // i->setOpen (TRUE); 3252 // i->setOpen (TRUE);
3169 i->setText (0, copiedItem->text(0)); 3253 i->setText (0, copiedItem->text(0));
3170 i->setText (1, copiedItem->text(1)); 3254 i->setText (1, copiedItem->text(1));
3171 i->setText (2, copiedItem->text(2)); 3255 i->setText (2, copiedItem->text(2));
3172 i->setText (3, copiedItem->text(3)); 3256 i->setText (3, copiedItem->text(3));
3173 i->setText (4, copiedItem->text(4)); 3257 i->setText (4, copiedItem->text(4));
3174 i->setText (5, copiedItem->text(5)); 3258 i->setText (5, copiedItem->text(5));
3175 selectedItem->setOpen( TRUE ); 3259 selectedItem->setOpen( TRUE );
3176 } 3260 }
3177 } 3261 }
3178 } 3262 }
3179 IsCut = false; 3263 IsCut = false;
3180 IsCopy = false; 3264 IsCopy = false;
3181} 3265}
3182 3266
3183void ZSafe::newDocument() 3267void ZSafe::newDocument()
3184{ 3268{
3185 3269
3186 // open the file dialog 3270 // open the file dialog
3187#ifndef DESKTOP 3271#ifndef DESKTOP
3188#ifndef NO_OPIE 3272#ifndef NO_OPIE
3189 QMap<QString, QStringList> mimeTypes; 3273 QMap<QString, QStringList> mimeTypes;
3190 mimeTypes.insert(tr("All"), QStringList() ); 3274 mimeTypes.insert(tr("All"), QStringList() );
3191 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3275 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3192 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 3276 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
3193 QDir::homeDirPath() + "/Documents/application/zsafe", 3277 QDir::homeDirPath() + "/Documents/application/zsafe",
3194 QString::null, 3278 QString::null,
3195 mimeTypes, 3279 mimeTypes,
3196 this, 3280 this,
3197 tr ("Create new ZSafe document")); 3281 tr ("Create new ZSafe document"));
3198#else 3282#else
3199 QString newFile = ScQtFileEdit::getSaveAsFileName(this, 3283 QString newFile = ScQtFileEdit::getSaveAsFileName(this,
3200 tr ("Create new ZSafe document"), 3284 tr ("Create new ZSafe document"),
3201 QDir::homeDirPath() + "/Documents/application/zsafe", 3285 QDir::homeDirPath() + "/Documents/application/zsafe",
3202 "*.zsf"); 3286 "*.zsf");
3203#endif 3287#endif
3204#else 3288#else
3205 QString newFile = QFileDialog::getSaveFileName( 3289 QString newFile = QFileDialog::getSaveFileName(
3206 QDir::homeDirPath() + "/Documents/application/zsafe", 3290 QDir::homeDirPath() + "/Documents/application/zsafe",
3207 "ZSafe (*.zsf)", 3291 "ZSafe (*.zsf)",
3208 this, 3292 this,
3209 "ZSafe File Dialog" 3293 "ZSafe File Dialog"
3210 "Choose a ZSafe file" ); 3294 "Choose a ZSafe file" );
3211#endif 3295#endif
3212 3296
3213 // open the new document 3297 // open the new document
3214 if (newFile && newFile.length() > 0 ) 3298 if (newFile && newFile.length() > 0 )
3215 { 3299 {
3216 // save the previous opened document 3300 // save the previous opened document
3217 if (!filename.isEmpty()) 3301 if (!filename.isEmpty())
3218 saveDocument(filename, FALSE); 3302 saveDocument(filename, FALSE);
3219 3303
3220 modified = true; 3304 modified = true;
3221 3305
3222 // clear the password list 3306 // clear the password list
3223 QListViewItem *i; 3307 QListViewItem *i;
3224 QListViewItem *c = NULL; 3308 QListViewItem *c = NULL;
3225 // step through all categories 3309 // step through all categories
3226 for (i = ListView->firstChild(); 3310 for (i = ListView->firstChild();
3227 i != NULL; 3311 i != NULL;
3228 i = i->nextSibling()) 3312 i = i->nextSibling())
3229 { 3313 {
3230 if (c) delete c; // delete the previous category 3314 if (c) delete c; // delete the previous category
3231 3315
3232 c = i; 3316 c = i;
3233 // step through all subitems 3317 // step through all subitems
3234 QListViewItem *si; 3318 QListViewItem *si;
3235 for (si = i->firstChild(); 3319 for (si = i->firstChild();
3236 si != NULL; ) 3320 si != NULL; )
3237 { 3321 {
3238 QListViewItem *_si = si; 3322 QListViewItem *_si = si;
3239 si = si->nextSibling(); 3323 si = si->nextSibling();
3240 i->takeItem(_si); // remove from view list 3324 i->takeItem(_si); // remove from view list
3241 if (_si) delete _si; 3325 if (_si) delete _si;
3242 } 3326 }
3243 } 3327 }
3244 if (c) delete c; // delete the previous category 3328 if (c) delete c; // delete the previous category
3245 categories.clear(); 3329 categories.clear();
3246 3330
3247 // m_password = ""; 3331 // m_password = "";
3248 selectedItem = NULL; 3332 selectedItem = NULL;
3249 3333
3250 filename = newFile; 3334 filename = newFile;
3251 3335
3252 // save the current filename to the config file 3336 // save the current filename to the config file
3253 conf->writeEntry(APP_KEY+"document", filename); 3337 conf->writeEntry(APP_KEY+"document", filename);
3254 saveConf(); 3338 saveConf();
3255 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3339 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3256#ifdef WIN32 3340#ifdef WIN32
3257 this->setCaption("Qt ZSafe: " + ti); 3341 this->setCaption("Qt ZSafe: " + ti);
3258#else 3342#else
3259 this->setCaption("ZSafe: " + ti); 3343 this->setCaption("ZSafe: " + ti);
3260#endif 3344#endif
3261 3345
3262 // openDocument(filename); 3346 // openDocument(filename);
3263 3347
3264 QMessageBox::information( this, tr("ZSafe"), 3348 QMessageBox::information( this, tr("ZSafe"),
3265 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); 3349 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0);
3266 3350
3267 saveDocumentWithPwd(); 3351 saveDocumentWithPwd();
3268 } 3352 }
3269} 3353}
3270 3354
3271void ZSafe::loadDocument() 3355void ZSafe::loadDocument()
3272{ 3356{
3273 3357
3274 // open the file dialog 3358 // open the file dialog
3275#ifndef DESKTOP 3359#ifndef DESKTOP
3276#ifndef NO_OPIE 3360#ifndef NO_OPIE
3277 QMap<QString, QStringList> mimeTypes; 3361 QMap<QString, QStringList> mimeTypes;
3278 mimeTypes.insert(tr("All"), QStringList() ); 3362 mimeTypes.insert(tr("All"), QStringList() );
3279 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3363 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3280 QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 3364 QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
3281 QDir::homeDirPath() + "/Documents/application/zsafe", 3365 QDir::homeDirPath() + "/Documents/application/zsafe",
3282 QString::null, 3366 QString::null,
3283 mimeTypes, 3367 mimeTypes,
3284 this, 3368 this,
3285 tr ("Open ZSafe document")); 3369 tr ("Open ZSafe document"));
3286#else 3370#else
3287 QString newFile = ScQtFileEdit::getOpenFileName(this, 3371 QString newFile = ScQtFileEdit::getOpenFileName(this,
3288 tr ("Open ZSafe document"), 3372 tr ("Open ZSafe document"),
3289 QDir::homeDirPath() + "/Documents/application/zsafe", 3373 QDir::homeDirPath() + "/Documents/application/zsafe",
3290 "*.zsf"); 3374 "*.zsf");
3291#endif 3375#endif
3292#else 3376#else
3293 QString newFile = QFileDialog::getOpenFileName( 3377 QString newFile = QFileDialog::getOpenFileName(
3294 QDir::homeDirPath() + "/Documents/application/zsafe", 3378 QDir::homeDirPath() + "/Documents/application/zsafe",
3295 "ZSafe (*.zsf)", 3379 "ZSafe (*.zsf)",
3296 this, 3380 this,
3297 "ZSafe File Dialog" 3381 "ZSafe File Dialog"
3298 "Choose a ZSafe file" ); 3382 "Choose a ZSafe file" );
3299#endif 3383#endif
3300 3384
3301 // open the new document 3385 // open the new document
3302 if (newFile && newFile.length() > 0 ) 3386 if (newFile && newFile.length() > 0 )
3303 { 3387 {
3304 // save the previous opened document 3388 // save the previous opened document
3305 if (!filename.isEmpty()) 3389 if (!filename.isEmpty())
3306 saveDocument(filename, FALSE); 3390 saveDocument(filename, FALSE);
3307 3391
3308 // clear the password list 3392 // clear the password list
3309 QListViewItem *i; 3393 QListViewItem *i;
3310 QListViewItem *c = NULL; 3394 QListViewItem *c = NULL;
3311 // step through all categories 3395 // step through all categories
3312 for (i = ListView->firstChild(); 3396 for (i = ListView->firstChild();
3313 i != NULL; 3397 i != NULL;
3314 i = i->nextSibling()) 3398 i = i->nextSibling())
3315 { 3399 {
3316 if (c) delete c; // delete the previous category 3400 if (c) delete c; // delete the previous category
3317 3401
3318 c = i; 3402 c = i;
3319 // step through all subitems 3403 // step through all subitems
3320 QListViewItem *si; 3404 QListViewItem *si;
3321 for (si = i->firstChild(); 3405 for (si = i->firstChild();
3322 si != NULL; ) 3406 si != NULL; )
3323 { 3407 {
3324 QListViewItem *_si = si; 3408 QListViewItem *_si = si;
3325 si = si->nextSibling(); 3409 si = si->nextSibling();
3326 i->takeItem(_si); // remove from view list 3410 i->takeItem(_si); // remove from view list
3327 if (_si) delete _si; 3411 if (_si) delete _si;
3328 } 3412 }
3329 } 3413 }
3330 if (c) delete c; // delete the previous category 3414 if (c) delete c; // delete the previous category
3331 categories.clear(); 3415 categories.clear();
3332 m_password = ""; 3416 m_password = "";
3333 selectedItem = NULL; 3417 selectedItem = NULL;
3334 filename = newFile; 3418 filename = newFile;
3335 3419
3336 // save the current filename to the config file 3420 // save the current filename to the config file
3337 conf->writeEntry(APP_KEY+"document", filename); 3421 conf->writeEntry(APP_KEY+"document", filename);
3338 saveConf(); 3422 saveConf();
3339 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3423 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3340#ifdef WIN32 3424#ifdef WIN32
3341 this->setCaption("Qt ZSafe: " + ti); 3425 this->setCaption("Qt ZSafe: " + ti);
3342#else 3426#else
3343 this->setCaption("ZSafe: " + ti); 3427 this->setCaption("ZSafe: " + ti);
3344#endif 3428#endif
3345 3429
3346 openDocument(filename); 3430 openDocument(filename);
3347 } 3431 }
3348} 3432}
3349 3433
3350void ZSafe::saveDocumentAs() 3434void ZSafe::saveDocumentAs()
3351{ 3435{
3352 3436
3353#ifndef DESKTOP 3437#ifndef DESKTOP
3354#ifndef NO_OPIE 3438#ifndef NO_OPIE
3355 QMap<QString, QStringList> mimeTypes; 3439 QMap<QString, QStringList> mimeTypes;
3356 mimeTypes.insert(tr("All"), QStringList() ); 3440 mimeTypes.insert(tr("All"), QStringList() );
3357 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3441 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3358 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 3442 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
3359 QDir::homeDirPath() + "/Documents/application/zsafe", 3443 QDir::homeDirPath() + "/Documents/application/zsafe",
3360 QString::null, 3444 QString::null,
3361 mimeTypes, 3445 mimeTypes,
3362 this, 3446 this,
3363 tr ("Save ZSafe document as..")); 3447 tr ("Save ZSafe document as.."));
3364#else 3448#else
3365 QString newFile = ScQtFileEdit::getSaveAsFileName(this, 3449 QString newFile = ScQtFileEdit::getSaveAsFileName(this,
3366 tr ("Save ZSafe document as.."), 3450 tr ("Save ZSafe document as.."),
3367 QDir::homeDirPath() + "/Documents/application/zsafe", 3451 QDir::homeDirPath() + "/Documents/application/zsafe",
3368 "*.zsf"); 3452 "*.zsf");
3369#endif 3453#endif
3370#else 3454#else
3371 // open the file dialog 3455 // open the file dialog
3372 QString newFile = QFileDialog::getSaveFileName( 3456 QString newFile = QFileDialog::getSaveFileName(
3373 QDir::homeDirPath() + "/Documents/application/zsafe", 3457 QDir::homeDirPath() + "/Documents/application/zsafe",
3374 "ZSafe (*.zsf)", 3458 "ZSafe (*.zsf)",
3375 this, 3459 this,
3376 "ZSafe File Dialog" 3460 "ZSafe File Dialog"
3377 "Choose a ZSafe file" ); 3461 "Choose a ZSafe file" );
3378#endif 3462#endif
3379 3463
3380 // open the new document 3464 // open the new document
3381 if (newFile && newFile.length() > 0 ) 3465 if (newFile && newFile.length() > 0 )
3382 { 3466 {
3383 // save the previous opened document 3467 // save the previous opened document
3384 if (!filename.isEmpty()) 3468 if (!filename.isEmpty())
3385 saveDocument(filename, FALSE); 3469 saveDocument(filename, FALSE);
3386 3470
3387 selectedItem = NULL; 3471 selectedItem = NULL;
3388 filename = newFile; 3472 filename = newFile;
3389 3473
3390 // save the current filename to the config file 3474 // save the current filename to the config file
3391 conf->writeEntry(APP_KEY+"document", filename); 3475 conf->writeEntry(APP_KEY+"document", filename);
3392 saveConf(); 3476 saveConf();
3393 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3477 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3394#ifdef WIN32 3478#ifdef WIN32
3395 this->setCaption("Qt ZSafe: " + ti); 3479 this->setCaption("Qt ZSafe: " + ti);
3396#else 3480#else
3397 this->setCaption("ZSafe: " + ti); 3481 this->setCaption("ZSafe: " + ti);
3398#endif 3482#endif
3399 3483
3400 QMessageBox::information( this, tr("ZSafe"), 3484 QMessageBox::information( this, tr("ZSafe"),
3401 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); 3485 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0);
3402 3486
3403 saveDocumentWithPwd(); 3487 saveDocumentWithPwd();
3404 } 3488 }
3405} 3489}
3406 3490
3407void ZSafe::saveDocumentWithoutPwd() 3491void ZSafe::saveDocumentWithoutPwd()
3408{ 3492{
3409 saveDocument(filename, FALSE); 3493 saveDocument(filename, FALSE);
3410} 3494}
3411 3495
3412void ZSafe::saveDocumentWithPwd() 3496void ZSafe::saveDocumentWithPwd()
3413{ 3497{
3414 saveDocument(filename, TRUE); 3498 saveDocument(filename, TRUE);
3415} 3499}
3416 3500
3417void ZSafe::about() 3501void ZSafe::about()
3418{ 3502{
3419 QString info; 3503 QString info;
3420 info = "<html><body><div align=""center"">"; 3504 info = "<html><body><div align=""center"">";
3421 info += "<b>"; 3505 info += "<b>";
3422 info += tr("Zaurus Password Manager<br>"); 3506 info += tr("Zaurus Password Manager<br>");
3423 info += tr("ZSafe version 2.1.2<br>"); 3507 info += tr("ZSafe version 2.1.2<br>");
3424 info += "</b>"; 3508 info += "</b>";
3425 info += tr("by Carsten Schneider<br>"); 3509 info += tr("by Carsten Schneider<br>");
3426 info += "zcarsten@gmx.net<br>"; 3510 info += "zcarsten@gmx.net<br>";
3427 info += "http://z-soft.z-portal.info/zsafe"; 3511 info += "http://z-soft.z-portal.info/zsafe";
3428 info += "<br>"; 3512 info += "<br>";
3429 info += tr("Translations by Robert Ernst<br>"); 3513 info += tr("Translations by Robert Ernst<br>");
3430 info += "robert.ernst@linux-solutions.at<br>"; 3514 info += "robert.ernst@linux-solutions.at<br>";
3431 info += "<br></div>"; 3515 info += "<br></div>";
3432 info += "</body></html>"; 3516 info += "</body></html>";
3433 3517
3434 // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0); 3518 // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0);
3435 3519
3436 QMessageBox mb( this, tr("ZSafe")); 3520 QMessageBox mb( this, tr("ZSafe"));
3437 mb.setText (info); 3521 mb.setText (info);
3438 mb.setButtonText (QMessageBox::Ok, tr ("&OK")); 3522 mb.setButtonText (QMessageBox::Ok, tr ("&OK"));
3439 QPixmap zsafe_img((const char**) zsafe_xpm); 3523 QPixmap zsafe_img((const char**) zsafe_xpm);
3440 mb.setIconPixmap (zsafe_img); 3524 mb.setIconPixmap (zsafe_img);
3441 mb.exec(); 3525 mb.exec();
3442} 3526}
3443 3527
3444void ZSafe::setExpandFlag() 3528void ZSafe::setExpandFlag()
3445{ 3529{
3446 expandTree = !expandTree; 3530 expandTree = !expandTree;
3447 file->setItemChecked('o', expandTree); 3531 file->setItemChecked('o', expandTree);
3448#ifndef DESKTOP 3532#ifndef DESKTOP
3449 conf->setGroup ("zsafePrefs"); 3533 conf->setGroup ("zsafePrefs");
3450#endif 3534#endif
3451// #ifndef WIN32 3535// #ifndef WIN32
3452 conf->writeEntry (APP_KEY+"expandTree", expandTree); 3536 conf->writeEntry (APP_KEY+"expandTree", expandTree);
3453// #endif 3537// #endif
3454 saveConf(); 3538 saveConf();
3455 3539
3456} 3540}
3457 3541
3458void ZSafe::paintEvent( QPaintEvent * ) 3542void ZSafe::paintEvent( QPaintEvent * )
3459{ 3543{
3460 if (raiseFlag) 3544 if (raiseFlag)
3461 { 3545 {
3462 raiseFlag = false; 3546 raiseFlag = false;
3463 raiseTimer.start (1, true); 3547 raiseTimer.start (1, true);
3464 if (infoForm->isVisible()) 3548 if (infoForm->isVisible())
3465 infoForm->raise(); 3549 infoForm->raise();
3466 } 3550 }
3467} 3551}
3468 3552
3469void ZSafe::resizeEvent ( QResizeEvent * ) 3553void ZSafe::resizeEvent ( QResizeEvent * )
3470{ 3554{
3471 // qWarning ("resizeEvent"); 3555 // qWarning ("resizeEvent");
3472#ifndef DESKTOP 3556#ifndef DESKTOP
3473 DeskW = appl->desktop()->width(); 3557 DeskW = appl->desktop()->width();
3474 DeskH = appl->desktop()->height(); 3558 DeskH = appl->desktop()->height();
3475#else 3559#else
3476 DeskW = this->width(); 3560 DeskW = this->width();
3477 DeskH = this->height(); 3561 DeskH = this->height();
3478#endif 3562#endif
3479 qWarning( QString("Width : %1").arg(DeskW), 2000 ); 3563 qWarning( QString("Width : %1").arg(DeskW), 2000 );
3480 qWarning( QString("Height: %1").arg(DeskH), 2000 ); 3564 qWarning( QString("Height: %1").arg(DeskH), 2000 );
3481 3565
3482 New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) ); 3566 New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) );
3483 Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) ); 3567 Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) );
3484 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); 3568 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
3485 Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) ); 3569 Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) );
3486} 3570}
3487 3571
3488void ZSafe::slotRaiseTimer() 3572void ZSafe::slotRaiseTimer()
3489{ 3573{
3490 if (infoForm->isVisible()) 3574 if (infoForm->isVisible())
3491 infoForm->raise(); 3575 infoForm->raise();
3492 raiseFlag = true; 3576 raiseFlag = true;
3493} 3577}
3494 3578
3495QPixmap * ZSafe::getPredefinedIcon(QString category) 3579QPixmap * ZSafe::getPredefinedIcon(QString category)
3496{ 3580{
3497 QPixmap *pm; 3581 QPixmap *pm;
3498 if (category == "Bank cards") 3582 if (category == "Bank cards")
3499 pm = new QPixmap((const char**)bank_cards_data); 3583 pm = new QPixmap((const char**)bank_cards_data);
3500 else if (category == "Passwords") 3584 else if (category == "Passwords")
3501 pm = new QPixmap((const char**)passwords_data); 3585 pm = new QPixmap((const char**)passwords_data);
3502 else if (category == "Software") 3586 else if (category == "Software")
3503 pm = new QPixmap((const char**)software_data); 3587 pm = new QPixmap((const char**)software_data);
3504 else if (category == "General") 3588 else if (category == "General")
3505 pm = new QPixmap((const char**)general_data); 3589 pm = new QPixmap((const char**)general_data);
3506 else 3590 else
3507 pm = new QPixmap((const char**)general_data); 3591 pm = new QPixmap((const char**)general_data);
3508 return pm; 3592 return pm;
3509} 3593}
3510 3594
3511void ZSafe::setDocument(const QString& fileref) 3595void ZSafe::setDocument(const QString& fileref)
3512{ 3596{
3513#ifndef DESKTOP 3597#ifndef DESKTOP
3514 // stop the timer to prevent loading of the default document 3598 // stop the timer to prevent loading of the default document
3515 docuTimer.stop(); 3599 docuTimer.stop();
3516 3600
3517 DocLnk link(fileref); 3601 DocLnk link(fileref);
3518 if ( link.isValid() ) 3602 if ( link.isValid() )
3519 { 3603 {
3520 // if (filename != link.file()) 3604 // if (filename != link.file())
3521 // saveDocument(filename, FALSE); 3605 // saveDocument(filename, FALSE);
3522 filename = link.file(); 3606 filename = link.file();
3523 } 3607 }
3524 else 3608 else
3525 { 3609 {
3526 // if (filename != fileref) 3610 // if (filename != fileref)
3527 // saveDocument(filename, FALSE); 3611 // saveDocument(filename, FALSE);
3528 filename = fileref; 3612 filename = fileref;
3529 } 3613 }
3530 // save the current filename to the config file 3614 // save the current filename to the config file
3531 conf->writeEntry(APP_KEY+"document", filename); 3615 conf->writeEntry(APP_KEY+"document", filename);
3532 saveConf(); 3616 saveConf();
3533 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3617 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3534#ifdef WIN32 3618#ifdef WIN32
3535 this->setCaption("Qt ZSafe: " + ti); 3619 this->setCaption("Qt ZSafe: " + ti);
3536#else 3620#else
3537 this->setCaption("ZSafe: " + ti); 3621 this->setCaption("ZSafe: " + ti);
3538#endif 3622#endif
3539 3623
3540 // clear the password list 3624 // clear the password list
3541 QListViewItem *i; 3625 QListViewItem *i;
3542 QListViewItem *c = NULL; 3626 QListViewItem *c = NULL;
3543 // step through all categories 3627 // step through all categories
3544 for (i = ListView->firstChild(); 3628 for (i = ListView->firstChild();
3545 i != NULL; 3629 i != NULL;
3546 i = i->nextSibling()) 3630 i = i->nextSibling())
3547 { 3631 {
3548 if (c) delete c; // delete the previous category 3632 if (c) delete c; // delete the previous category
3549 3633
3550 c = i; 3634 c = i;
3551 // step through all subitems 3635 // step through all subitems
3552 QListViewItem *si; 3636 QListViewItem *si;
3553 for (si = i->firstChild(); 3637 for (si = i->firstChild();
3554 si != NULL; ) 3638 si != NULL; )
3555 { 3639 {
3556 QListViewItem *_si = si; 3640 QListViewItem *_si = si;
3557 si = si->nextSibling(); 3641 si = si->nextSibling();
3558 i->takeItem(_si); // remove from view list 3642 i->takeItem(_si); // remove from view list
3559 if (_si) delete _si; 3643 if (_si) delete _si;
3560 } 3644 }
3561 } 3645 }
3562 if (c) delete c; // delete the previous category 3646 if (c) delete c; // delete the previous category
3563 categories.clear(); 3647 categories.clear();
3564 3648
3565 m_password = ""; 3649 m_password = "";
3566 selectedItem = NULL; 3650 selectedItem = NULL;
3567 3651
3568 openDocument(filename); 3652 openDocument(filename);
3569#endif 3653#endif
3570} 3654}
3571 3655
3572 3656
3573 3657