summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-07-10 01:59:00 (UTC)
committer llornkcor <llornkcor>2004-07-10 01:59:00 (UTC)
commit9a51654b784192af0b02536e308f62bf5a5ae57c (patch) (unidiff)
tree16ec1ec15173f76d1c0134d63b03aafb89e484a8
parent9c40b0465fc9d553077f020bed889bb1ac1a472f (diff)
downloadopie-9a51654b784192af0b02536e308f62bf5a5ae57c.zip
opie-9a51654b784192af0b02536e308f62bf5a5ae57c.tar.gz
opie-9a51654b784192af0b02536e308f62bf5a5ae57c.tar.bz2
spelling
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index 824b841..0864293 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -396,3073 +396,3073 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
396 modified = false; 396 modified = false;
397 showpwd = false; 397 showpwd = false;
398 398
399 // set the config file 399 // set the config file
400 cfgFile=QDir::homeDirPath(); 400 cfgFile=QDir::homeDirPath();
401 cfgFile += "/.zsafe.cfg"; 401 cfgFile += "/.zsafe.cfg";
402 // set the icon path 402 // set the icon path
403#ifdef NO_OPIE 403#ifdef NO_OPIE
404 QString qpedir ((const char *)getenv("QPEDIR")); 404 QString qpedir ((const char *)getenv("QPEDIR"));
405#else 405#else
406 QString qpedir ((const char *)getenv("OPIEDIR")); 406 QString qpedir ((const char *)getenv("OPIEDIR"));
407#endif 407#endif
408 408
409#ifdef DESKTOP 409#ifdef DESKTOP
410 iconPath = QDir::homeDirPath() + "/pics/"; 410 iconPath = QDir::homeDirPath() + "/pics/";
411#else 411#else
412 if (qpedir.isEmpty()) 412 if (qpedir.isEmpty())
413 iconPath = "/home/QtPalmtop/pics/"; 413 iconPath = "/home/QtPalmtop/pics/";
414 else 414 else
415 iconPath = qpedir + "/pics/"; 415 iconPath = qpedir + "/pics/";
416#endif 416#endif
417 417
418 // create a zsafe configuration object 418 // create a zsafe configuration object
419#ifdef DESKTOP 419#ifdef DESKTOP
420#ifndef WIN32 420#ifndef WIN32
421 conf = new QSettings (); 421 conf = new QSettings ();
422 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); 422 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath());
423#else 423#else
424 conf = new QSettings (cfgFile); 424 conf = new QSettings (cfgFile);
425 conf->insertSearchPath (QSettings::Unix, cfgFile); 425 conf->insertSearchPath (QSettings::Unix, cfgFile);
426#endif 426#endif
427#else 427#else
428 conf = new Config (cfgFile, Config::File); 428 conf = new Config (cfgFile, Config::File);
429 conf->setGroup ("zsafePrefs"); 429 conf->setGroup ("zsafePrefs");
430#endif 430#endif
431#ifdef DESKTOP 431#ifdef DESKTOP
432// #ifndef WIN32 432// #ifndef WIN32
433 expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false); 433 expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false);
434// #endif 434// #endif
435#else 435#else
436 expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0); 436 expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0);
437#endif 437#endif
438#ifndef DESKTOP 438#ifndef DESKTOP
439 conf->setGroup ("zsafe"); 439 conf->setGroup ("zsafe");
440#endif 440#endif
441 441
442 QPixmap copy_img((const char**) copy_xpm); 442 QPixmap copy_img((const char**) copy_xpm);
443 QPixmap cut_img((const char**) cut_xpm); 443 QPixmap cut_img((const char**) cut_xpm);
444 QPixmap edit_img((const char**) edit_xpm); 444 QPixmap edit_img((const char**) edit_xpm);
445 QPixmap editdelete_img((const char**) editdelete_xpm); 445 QPixmap editdelete_img((const char**) editdelete_xpm);
446 QPixmap find_img((const char**) find_xpm); 446 QPixmap find_img((const char**) find_xpm);
447 QPixmap folder_open_img((const char**) folder_open_xpm); 447 QPixmap folder_open_img((const char**) folder_open_xpm);
448 QPixmap help_icon_img((const char**) help_icon_xpm); 448 QPixmap help_icon_img((const char**) help_icon_xpm);
449 QPixmap new_img((const char**) new_xpm); 449 QPixmap new_img((const char**) new_xpm);
450 QPixmap paste_img((const char**) paste_xpm); 450 QPixmap paste_img((const char**) paste_xpm);
451 QPixmap quit_icon_img((const char**) quit_icon_xpm); 451 QPixmap quit_icon_img((const char**) quit_icon_xpm);
452 QPixmap save_img((const char**) save_xpm); 452 QPixmap save_img((const char**) save_xpm);
453 QPixmap trash_img((const char**) trash_xpm); 453 QPixmap trash_img((const char**) trash_xpm);
454 QPixmap expand_img((const char**) expand_xpm); 454 QPixmap expand_img((const char**) expand_xpm);
455 QPixmap export_img((const char**) export_xpm); 455 QPixmap export_img((const char**) export_xpm);
456 QPixmap import_img((const char**) import_xpm); 456 QPixmap import_img((const char**) import_xpm);
457 457
458 QPixmap bank_cards( ( const char** ) bank_cards_data ); 458 QPixmap bank_cards( ( const char** ) bank_cards_data );
459 QPixmap passwords( ( const char** ) passwords_data ); 459 QPixmap passwords( ( const char** ) passwords_data );
460 QPixmap software( ( const char** ) software_data ); 460 QPixmap software( ( const char** ) software_data );
461 QPixmap general( ( const char** ) general_data ); 461 QPixmap general( ( const char** ) general_data );
462 QPixmap image0( ( const char** ) zsafe_xpm ); 462 QPixmap image0( ( const char** ) zsafe_xpm );
463 if ( !name ) 463 if ( !name )
464 setName( "ZSafe" ); 464 setName( "ZSafe" );
465 465
466#ifdef DESKTOP 466#ifdef DESKTOP
467#ifdef WIN32 467#ifdef WIN32
468 setGeometry(100, 150, DeskW, DeskH-30 ); 468 setGeometry(100, 150, DeskW, DeskH-30 );
469#else 469#else
470 resize( DeskW, DeskH-30 ); 470 resize( DeskW, DeskH-30 );
471#endif 471#endif
472 472
473#else 473#else
474 474
475#ifdef JPATCH_HDE 475#ifdef JPATCH_HDE
476 int DeskS; 476 int DeskS;
477 if(DeskW > DeskH) 477 if(DeskW > DeskH)
478 { 478 {
479 DeskS = DeskW; 479 DeskS = DeskW;
480 } 480 }
481 else 481 else
482 { 482 {
483 DeskS = DeskH; 483 DeskS = DeskH;
484 } 484 }
485 resize( DeskW, DeskH ); 485 resize( DeskW, DeskH );
486 setMinimumSize( QSize( DeskS, DeskS ) ); 486 setMinimumSize( QSize( DeskS, DeskS ) );
487 setMaximumSize( QSize( DeskS, DeskS ) ); 487 setMaximumSize( QSize( DeskS, DeskS ) );
488#else 488#else
489 resize( DeskW, DeskH-30 ); 489 resize( DeskW, DeskH-30 );
490#endif 490#endif
491 491
492#endif 492#endif
493 setCaption( tr( "ZSafe" ) ); 493 setCaption( tr( "ZSafe" ) );
494 QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe"; 494 QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe";
495 QString filename = conf->readEntry(APP_KEY+"document"); 495 QString filename = conf->readEntry(APP_KEY+"document");
496 if (filename.isEmpty() || filename.isNull()) 496 if (filename.isEmpty() || filename.isNull())
497 { 497 {
498 498
499 // check if the directory application exists, if not 499 // check if the directory application exists, if not
500 // create it 500 // create it
501// #ifndef WIN32 501// #ifndef WIN32
502 // QString d1("Documents/application"); 502 // QString d1("Documents/application");
503// #else 503// #else
504 QString d1(QDir::homeDirPath() + "/Documents/application"); 504 QString d1(QDir::homeDirPath() + "/Documents/application");
505// #endif 505// #endif
506 QDir pd1(d1); 506 QDir pd1(d1);
507 if (!pd1.exists()) 507 if (!pd1.exists())
508 { 508 {
509 509
510 QDir pd2(QDir::homeDirPath() + "/Documents"); 510 QDir pd2(QDir::homeDirPath() + "/Documents");
511 if (!pd2.exists()) { 511 if (!pd2.exists()) {
512 QDir pd3(QDir::homeDirPath()); 512 QDir pd3(QDir::homeDirPath());
513 if (!pd3.mkdir("Documents", FALSE)) { 513 if (!pd3.mkdir("Documents", FALSE)) {
514 } 514 }
515 } 515 }
516 516
517 if (!pd2.mkdir("application", FALSE)) 517 if (!pd2.mkdir("application", FALSE))
518 { 518 {
519 QMessageBox::critical( 0, tr("ZSafe"), 519 QMessageBox::critical( 0, tr("ZSafe"),
520#ifdef JPATCH_HDE 520#ifdef JPATCH_HDE
521 tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>")); 521 tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>"));
522#else 522#else
523 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1)); 523 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1));
524#endif 524#endif
525 exitZs (1); 525 exitZs (1);
526 } 526 }
527 } 527 }
528// #ifndef WIN32 528// #ifndef WIN32
529 // QString d2("Documents/application/zsafe"); 529 // QString d2("Documents/application/zsafe");
530// #else 530// #else
531 QString d2(QDir::homeDirPath() + "/Documents/application/zsafe"); 531 QString d2(QDir::homeDirPath() + "/Documents/application/zsafe");
532// #endif 532// #endif
533 QDir pd2(d2); 533 QDir pd2(d2);
534 if (!pd2.exists()) 534 if (!pd2.exists())
535 { 535 {
536 if (!pd1.mkdir("zsafe", FALSE)) 536 if (!pd1.mkdir("zsafe", FALSE))
537 { 537 {
538 QMessageBox::critical( 0, tr("ZSafe"), 538 QMessageBox::critical( 0, tr("ZSafe"),
539#ifdef JPATCH_HDE 539#ifdef JPATCH_HDE
540 tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P")); 540 tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P"));
541#else 541#else
542 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2)); 542 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2));
543#endif 543#endif
544 exitZs (1); 544 exitZs (1);
545 } 545 }
546 } 546 }
547 547
548 // set the default filename 548 // set the default filename
549 filename = zsafeAppDirPath + "/passwords.zsf"; 549 filename = zsafeAppDirPath + "/passwords.zsf";
550 550
551 // save the current filename to the config file 551 // save the current filename to the config file
552 conf->writeEntry(APP_KEY+"document", filename); 552 conf->writeEntry(APP_KEY+"document", filename);
553 saveConf(); 553 saveConf();
554 } 554 }
555 //if (filename == "INVALIDPWD") 555 //if (filename == "INVALIDPWD")
556 //filename = ""; 556 //filename = "";
557 557
558 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 558 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
559#ifdef WIN32 559#ifdef WIN32
560 this->setCaption("Qt ZSafe: " + ti); 560 this->setCaption("Qt ZSafe: " + ti);
561#else 561#else
562 this->setCaption("ZSafe: " + ti); 562 this->setCaption("ZSafe: " + ti);
563#endif 563#endif
564 564
565 selectedItem = NULL; 565 selectedItem = NULL;
566 lastSearchedCategory = NULL; 566 lastSearchedCategory = NULL;
567 lastSearchedItem = NULL; 567 lastSearchedItem = NULL;
568 lastSearchedName = ""; 568 lastSearchedName = "";
569 lastSearchedUsername = ""; 569 lastSearchedUsername = "";
570 lastSearchedComment = ""; 570 lastSearchedComment = "";
571 571
572 infoForm = new InfoForm(); 572 infoForm = new InfoForm();
573 categoryDialog = NULL; 573 categoryDialog = NULL;
574 infoForm->setIcon( image0); 574 infoForm->setIcon( image0);
575 575
576 // add a menu bar 576 // add a menu bar
577 QMenuBar *menu = new QMenuBar( this ); 577 QMenuBar *menu = new QMenuBar( this );
578 578
579 // add file menu 579 // add file menu
580 // QPopupMenu *file = new QPopupMenu( this ); 580 // QPopupMenu *file = new QPopupMenu( this );
581 file = new QPopupMenu( this ); 581 file = new QPopupMenu( this );
582 582
583// #ifdef DESKTOP 583// #ifdef DESKTOP
584 file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) ); 584 file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) );
585 file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) ); 585 file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) );
586 file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) ); 586 file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) );
587 file->insertSeparator(); 587 file->insertSeparator();
588// #endif 588// #endif
589 589
590 file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) ); 590 file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) );
591 file->insertItem( save_img, tr("S&ave document with new Password"), this, 591 file->insertItem( save_img, tr("S&ave document with new Password"), this,
592 SLOT(saveDocumentWithPwd()) ); 592 SLOT(saveDocumentWithPwd()) );
593 file->insertSeparator(); 593 file->insertSeparator();
594 file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) ); 594 file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) );
595 file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) ); 595 file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) );
596 file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) ); 596 file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) );
597 file->insertSeparator(); 597 file->insertSeparator();
598 file->insertItem( expand_img, tr("&Open entries expanded"), this, 598 file->insertItem( expand_img, tr("&Open entries expanded"), this,
599 SLOT(setExpandFlag()), 0, 'o'); 599 SLOT(setExpandFlag()), 0, 'o');
600 file->setItemChecked('o', expandTree); 600 file->setItemChecked('o', expandTree);
601 file->insertSeparator(); 601 file->insertSeparator();
602 file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) ); 602 file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) );
603 menu->insertItem( tr("&File"), file ); 603 menu->insertItem( tr("&File"), file );
604 604
605 QPopupMenu *cat = new QPopupMenu( this ); 605 QPopupMenu *cat = new QPopupMenu( this );
606 cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) ); 606 cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) );
607 cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) ); 607 cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) );
608 cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) ); 608 cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) );
609 menu->insertItem( tr("&Category"), cat ); 609 menu->insertItem( tr("&Category"), cat );
610 610
611 QPopupMenu *it = new QPopupMenu( this ); 611 QPopupMenu *it = new QPopupMenu( this );
612 it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) ); 612 it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) );
613 it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) ); 613 it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) );
614 it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) ); 614 it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) );
615 it->insertSeparator(); 615 it->insertSeparator();
616 it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) ); 616 it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) );
617 it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) ); 617 it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) );
618 it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) ); 618 it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) );
619 it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) ); 619 it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) );
620 menu->insertItem( tr("&Entry"), it ); 620 menu->insertItem( tr("&Entry"), it );
621 621
622 QPopupMenu *help = new QPopupMenu( this ); 622 QPopupMenu *help = new QPopupMenu( this );
623 help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) ); 623 help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) );
624 menu->insertItem( tr("&Help"), help ); 624 menu->insertItem( tr("&Help"), help );
625 625
626 // toolbar icons 626 // toolbar icons
627 627
628 New = new QToolButton( menu, "New" ); 628 New = new QToolButton( menu, "New" );
629 New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) ); 629 New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) );
630 New->setMouseTracking( TRUE ); 630 New->setMouseTracking( TRUE );
631 New->setText( "" ); 631 New->setText( "" );
632 New->setPixmap( new_img ); 632 New->setPixmap( new_img );
633 QToolTip::add( New, tr( "New entry" ) ); 633 QToolTip::add( New, tr( "New entry" ) );
634 634
635 Edit = new QToolButton( menu, "Edit" ); 635 Edit = new QToolButton( menu, "Edit" );
636 Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) ); 636 Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) );
637 Edit->setText( "" ); 637 Edit->setText( "" );
638 Edit->setPixmap( edit_img ); 638 Edit->setPixmap( edit_img );
639 QToolTip::add( Edit, tr( "Edit category or entry" ) ); 639 QToolTip::add( Edit, tr( "Edit category or entry" ) );
640 640
641 Delete = new QToolButton( menu, "Delete" ); 641 Delete = new QToolButton( menu, "Delete" );
642 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); 642 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
643 Delete->setText( "" ); 643 Delete->setText( "" );
644 Delete->setPixmap( trash_img ); 644 Delete->setPixmap( trash_img );
645 QToolTip::add( Delete, tr( "Delete category or entry" ) ); 645 QToolTip::add( Delete, tr( "Delete category or entry" ) );
646 646
647 Find = new QToolButton( menu, "Find" ); 647 Find = new QToolButton( menu, "Find" );
648 Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) ); 648 Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) );
649 Find->setText( "" ); 649 Find->setText( "" );
650 Find->setPixmap( find_img ); 650 Find->setPixmap( find_img );
651 QToolTip::add( Find, tr( "Find entry" ) ); 651 QToolTip::add( Find, tr( "Find entry" ) );
652 652
653/* 653/*
654 QBoxLayout * h = new QHBoxLayout( this ); 654 QBoxLayout * h = new QHBoxLayout( this );
655 h->addWidget (menu); 655 h->addWidget (menu);
656 h->addWidget (New); 656 h->addWidget (New);
657 h->addWidget (Edit); 657 h->addWidget (Edit);
658 h->addWidget (Delete); 658 h->addWidget (Delete);
659 h->addWidget (Find); 659 h->addWidget (Find);
660*/ 660*/
661 661
662 ListView = new ZListView( this, "ListView" ); 662 ListView = new ZListView( this, "ListView" );
663 ListView->addColumn( tr( "Name" ) ); 663 ListView->addColumn( tr( "Name" ) );
664 ListView->addColumn( tr( "Field 2" ) ); 664 ListView->addColumn( tr( "Field 2" ) );
665 ListView->addColumn( tr( "Field 3" ) ); 665 ListView->addColumn( tr( "Field 3" ) );
666 ListView->addColumn( tr( "Comment" ) ); 666 ListView->addColumn( tr( "Comment" ) );
667 ListView->addColumn( tr( "Field 4" ) ); 667 ListView->addColumn( tr( "Field 4" ) );
668 ListView->addColumn( tr( "Field 5" ) ); 668 ListView->addColumn( tr( "Field 5" ) );
669 ListView->setAllColumnsShowFocus(TRUE); 669 ListView->setAllColumnsShowFocus(TRUE);
670 670
671#ifdef DESKTOP 671#ifdef DESKTOP
672 ListView->setResizePolicy(QScrollView::AutoOneFit); 672 ListView->setResizePolicy(QScrollView::AutoOneFit);
673 // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) ); 673 // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) );
674#else 674#else
675 ListView->setResizePolicy(QScrollView::AutoOneFit); 675 ListView->setResizePolicy(QScrollView::AutoOneFit);
676 // ListView->setGeometry( QRect( 0, 22, 676 // ListView->setGeometry( QRect( 0, 22,
677 // this->width(), this->height() - 30 ) ); 677 // this->width(), this->height() - 30 ) );
678 // ListView->setMaximumSize( QSize( 440, 290 ) ); 678 // ListView->setMaximumSize( QSize( 440, 290 ) );
679#endif 679#endif
680 ListView->setVScrollBarMode( QListView::Auto ); 680 ListView->setVScrollBarMode( QListView::Auto );
681 681
682 QBoxLayout * l = new QVBoxLayout( this ); 682 QBoxLayout * l = new QVBoxLayout( this );
683 l->addWidget (menu); 683 l->addWidget (menu);
684 l->addWidget (ListView); 684 l->addWidget (ListView);
685 685
686#ifndef DESKTOP 686#ifndef DESKTOP
687 // start a timer (100 ms) to load the default document 687 // start a timer (100 ms) to load the default document
688 docuTimer.start( 100, true ); 688 docuTimer.start( 100, true );
689 connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) ); 689 connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) );
690 raiseFlag = true; 690 raiseFlag = true;
691 connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) ); 691 connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) );
692#else 692#else
693 // open the default document 693 // open the default document
694 openDocument(filename); 694 openDocument(filename);
695#endif 695#endif
696 696
697 // signals and slots connections for QTollButton 697 // signals and slots connections for QTollButton
698 connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) ); 698 connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) );
699 connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) ); 699 connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) );
700 connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) ); 700 connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) );
701 connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) ); 701 connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) );
702 // signals and slots connections for QListView 702 // signals and slots connections for QListView
703 connect( ListView, SIGNAL( selectionChanged(QListViewItem*) ), 703 connect( ListView, SIGNAL( selectionChanged(QListViewItem*) ),
704 this, SLOT( listViewSelected(QListViewItem*) ) ); 704 this, SLOT( listViewSelected(QListViewItem*) ) );
705 connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ), 705 connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ),
706 this, SLOT( showInfo(QListViewItem*) ) ); 706 this, SLOT( showInfo(QListViewItem*) ) );
707 connect( ListView, SIGNAL( returnPressed(QListViewItem*) ), 707 connect( ListView, SIGNAL( returnPressed(QListViewItem*) ),
708 this, SLOT( showInfo(QListViewItem*) ) ); 708 this, SLOT( showInfo(QListViewItem*) ) );
709 709
710 #ifndef DESKTOP 710 #ifndef DESKTOP
711 QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold); 711 QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold);
712#endif 712#endif
713 connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 713 connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
714 this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); 714 this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) );
715 715
716 this->setIcon( image0); 716 this->setIcon( image0);
717} 717}
718 718
719const QColor *ZSafe::evenRowColor = &Qt::white; 719const QColor *ZSafe::evenRowColor = &Qt::white;
720// const QColor *ZSafe::oddRowColor = &Qt::lightGray; 720// const QColor *ZSafe::oddRowColor = &Qt::lightGray;
721const QColor *ZSafe::oddRowColor = new QColor(216,240,255); 721const QColor *ZSafe::oddRowColor = new QColor(216,240,255);
722 722
723/* 723/*
724 * Destroys the object and frees any allocated resources 724 * Destroys the object and frees any allocated resources
725 */ 725 */
726ZSafe::~ZSafe() 726ZSafe::~ZSafe()
727{ 727{
728 // no need to delete child widgets, Qt does it all for us 728 // no need to delete child widgets, Qt does it all for us
729 quitMe(); 729 quitMe();
730} 730}
731 731
732// load the default document 732// load the default document
733void ZSafe::slotLoadDocu() 733void ZSafe::slotLoadDocu()
734{ 734{
735 openDocument (filename); 735 openDocument (filename);
736} 736}
737 737
738void ZSafe::deletePwd() 738void ZSafe::deletePwd()
739{ 739{
740 740
741 if (!selectedItem) 741 if (!selectedItem)
742 return; 742 return;
743 if (!isCategory(selectedItem)) 743 if (!isCategory(selectedItem))
744 { 744 {
745 switch( QMessageBox::information( this, tr("ZSafe"), 745 switch( QMessageBox::information( this, tr("ZSafe"),
746 tr("Do you want to delete?"), 746 tr("Do you want to delete?"),
747 tr("&Delete"), tr("D&on't Delete"), 747 tr("&Delete"), tr("D&on't Delete"),
748 0 // Enter == button 0 748 0 // Enter == button 0
749 ) ) { // Escape == button 2 749 ) ) { // Escape == button 2
750 case 0: // Delete clicked, Alt-S or Enter pressed. 750 case 0: // Delete clicked, Alt-S or Enter pressed.
751 // Delete 751 // Delete
752 modified = true; 752 modified = true;
753 selectedItem->parent()->takeItem(selectedItem); 753 selectedItem->parent()->takeItem(selectedItem);
754 selectedItem = NULL; 754 selectedItem = NULL;
755 break; 755 break;
756 case 1: // Don't delete 756 case 1: // Don't delete
757 break; 757 break;
758 } 758 }
759 } 759 }
760 else 760 else
761 { 761 {
762 delCategory(); 762 delCategory();
763 } 763 }
764} 764}
765 765
766void ZSafe::editPwd() 766void ZSafe::editPwd()
767{ 767{
768 if (!selectedItem) 768 if (!selectedItem)
769 return; 769 return;
770 if (!isCategory(selectedItem)) 770 if (!isCategory(selectedItem))
771 { 771 {
772 // open the 'New Entry' dialog 772 // open the 'New Entry' dialog
773 NewDialog *dialog = new NewDialog(this, tr("Edit Entry"), TRUE); 773 NewDialog *dialog = new NewDialog(this, tr("Edit Entry"), TRUE);
774#ifdef WIN32 774#ifdef WIN32
775 dialog->setCaption ("Qt " + tr("Edit Entry")); 775 dialog->setCaption ("Qt " + tr("Edit Entry"));
776 dialog->setGeometry(200, 250, 220, 310 ); 776 dialog->setGeometry(200, 250, 220, 310 );
777#endif 777#endif
778 778
779 // set the labels 779 // set the labels
780 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 780 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
781 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 781 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
782 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 782 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
783 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 783 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
784 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); 784 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
785 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); 785 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
786 786
787 // set the fields 787 // set the fields
788 dialog->NameField->setText(selectedItem->text (0)); 788 dialog->NameField->setText(selectedItem->text (0));
789 dialog->UsernameField->setText(selectedItem->text (1)); 789 dialog->UsernameField->setText(selectedItem->text (1));
790 dialog->PasswordField->setText(selectedItem->text (2)); 790 dialog->PasswordField->setText(selectedItem->text (2));
791 QString comment = selectedItem->text (3); 791 QString comment = selectedItem->text (3);
792 comment.replace (QRegExp("<br>"), "\n"); 792 comment.replace (QRegExp("<br>"), "\n");
793 dialog->Field5->setText(selectedItem->text (4)); 793 dialog->Field5->setText(selectedItem->text (4));
794 dialog->Field6->setText(selectedItem->text (5)); 794 dialog->Field6->setText(selectedItem->text (5));
795 dialog->CommentField->insertLine(comment); 795 dialog->CommentField->insertLine(comment);
796 dialog->CommentField->setCursorPosition(0,0); 796 dialog->CommentField->setCursorPosition(0,0);
797 797
798 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); 798 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog );
799 799
800#ifdef DESKTOP 800#ifdef DESKTOP
801 result = Accepted; 801 result = Accepted;
802#endif 802#endif
803 if (result == Accepted) 803 if (result == Accepted)
804 { 804 {
805 modified = true; 805 modified = true;
806 // edit the selected item 806 // edit the selected item
807 QString name = dialog->NameField->text(); 807 QString name = dialog->NameField->text();
808 selectedItem->setText (0, tr (name)); 808 selectedItem->setText (0, tr (name));
809 QString user = dialog->UsernameField->text(); 809 QString user = dialog->UsernameField->text();
810 selectedItem->setText (1, tr (user)); 810 selectedItem->setText (1, tr (user));
811 QString pwd = dialog->PasswordField->text(); 811 QString pwd = dialog->PasswordField->text();
812 selectedItem->setText (2, tr (pwd)); 812 selectedItem->setText (2, tr (pwd));
813 QString comment = dialog->CommentField->text(); 813 QString comment = dialog->CommentField->text();
814 comment.replace (QRegExp("\n"), "<br>"); 814 comment.replace (QRegExp("\n"), "<br>");
815 selectedItem->setText (3, tr (comment)); 815 selectedItem->setText (3, tr (comment));
816 QString f5 = dialog->Field5->text(); 816 QString f5 = dialog->Field5->text();
817 selectedItem->setText (4, tr (f5)); 817 selectedItem->setText (4, tr (f5));
818 QString f6 = dialog->Field6->text(); 818 QString f6 = dialog->Field6->text();
819 selectedItem->setText (5, tr (f6)); 819 selectedItem->setText (5, tr (f6));
820 } 820 }
821 821
822 delete dialog; 822 delete dialog;
823 } 823 }
824 else 824 else
825 { 825 {
826 editCategory(); 826 editCategory();
827 } 827 }
828} 828}
829 829
830void ZSafe::newPwd() 830void ZSafe::newPwd()
831{ 831{
832 if (!selectedItem) 832 if (!selectedItem)
833 return; 833 return;
834 834
835 if (!isCategory(selectedItem)) 835 if (!isCategory(selectedItem))
836 selectedItem = selectedItem->parent(); 836 selectedItem = selectedItem->parent();
837 837
838 if (isCategory(selectedItem)) 838 if (isCategory(selectedItem))
839 { 839 {
840 QString cat = selectedItem->text(0); 840 QString cat = selectedItem->text(0);
841 841
842 // open the 'New Entry' dialog 842 // open the 'New Entry' dialog
843 NewDialog *dialog = new NewDialog(this, tr("New Entry"), TRUE); 843 NewDialog *dialog = new NewDialog(this, tr("New Entry"), TRUE);
844#ifdef WIN32 844#ifdef WIN32
845 dialog->setCaption ("Qt " + tr("New Entry")); 845 dialog->setCaption ("Qt " + tr("New Entry"));
846 dialog->setGeometry(200, 250, 220, 310 ); 846 dialog->setGeometry(200, 250, 220, 310 );
847#endif 847#endif
848 // set the labels 848 // set the labels
849 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 849 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
850 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 850 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
851 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 851 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
852 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 852 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
853 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); 853 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
854 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); 854 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
855retype: 855retype:
856 856
857 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); 857 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog );
858#ifdef DESKTOP 858#ifdef DESKTOP
859 result = Accepted; 859 result = Accepted;
860#endif 860#endif
861 861
862 if (result == Accepted) 862 if (result == Accepted)
863 { 863 {
864 864
865 QString name = dialog->NameField->text(); 865 QString name = dialog->NameField->text();
866 if (cat == name) 866 if (cat == name)
867 { 867 {
868 QMessageBox::critical( 0, tr("ZSafe"), 868 QMessageBox::critical( 0, tr("ZSafe"),
869 tr("Entry name must be different\nfrom the category name.") ); 869 tr("Entry name must be different\nfrom the category name.") );
870 goto retype; // it's not a good programming style :-) 870 goto retype; // it's not a good programming style :-)
871 } 871 }
872 872
873 modified = true; 873 modified = true;
874 // add the new item 874 // add the new item
875 QListViewItem *i = new ShadedListItem (0, selectedItem); 875 QListViewItem *i = new ShadedListItem (0, selectedItem);
876 i->setOpen (TRUE); 876 i->setOpen (TRUE);
877 877
878 i->setText (0, tr (name)); 878 i->setText (0, tr (name));
879 QString user = dialog->UsernameField->text(); 879 QString user = dialog->UsernameField->text();
880 i->setText (1, tr (user)); 880 i->setText (1, tr (user));
881 QString pwd = dialog->PasswordField->text(); 881 QString pwd = dialog->PasswordField->text();
882 i->setText (2, tr (pwd)); 882 i->setText (2, tr (pwd));
883 QString comment = dialog->CommentField->text(); 883 QString comment = dialog->CommentField->text();
884 comment.replace (QRegExp("\n"), "<br>"); 884 comment.replace (QRegExp("\n"), "<br>");
885 i->setText (3, tr (comment)); 885 i->setText (3, tr (comment));
886 QString f5 = dialog->Field5->text(); 886 QString f5 = dialog->Field5->text();
887 i->setText (4, tr (f5)); 887 i->setText (4, tr (f5));
888 QString f6 = dialog->Field6->text(); 888 QString f6 = dialog->Field6->text();
889 i->setText (5, tr (f6)); 889 i->setText (5, tr (f6));
890 } 890 }
891 891
892 delete dialog; 892 delete dialog;
893 } 893 }
894} 894}
895 895
896void ZSafe::findPwd() 896void ZSafe::findPwd()
897{ 897{
898 898
899 // open the 'Search' dialog 899 // open the 'Search' dialog
900 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE); 900 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE);
901#ifdef WIN32 901#ifdef WIN32
902 dialog->setCaption ("Qt " + tr("Search")); 902 dialog->setCaption ("Qt " + tr("Search"));
903#endif 903#endif
904 904
905#ifdef DESKTOP 905#ifdef DESKTOP
906#endif 906#endif
907 if (lastSearchedName) 907 if (lastSearchedName)
908 dialog->NameField->setText(lastSearchedName); 908 dialog->NameField->setText(lastSearchedName);
909 else 909 else
910 dialog->NameField->setText(""); 910 dialog->NameField->setText("");
911 if (lastSearchedUsername) 911 if (lastSearchedUsername)
912 dialog->UsernameField->setText(lastSearchedUsername); 912 dialog->UsernameField->setText(lastSearchedUsername);
913 else 913 else
914 dialog->UsernameField->setText(""); 914 dialog->UsernameField->setText("");
915 if (lastSearchedComment) 915 if (lastSearchedComment)
916 dialog->CommentField->setText(lastSearchedComment); 916 dialog->CommentField->setText(lastSearchedComment);
917 else 917 else
918 dialog->CommentField->setText(""); 918 dialog->CommentField->setText("");
919 DialogCode result = (DialogCode) dialog->exec(); 919 DialogCode result = (DialogCode) dialog->exec();
920#ifdef DESKTOP 920#ifdef DESKTOP
921 result = Accepted; 921 result = Accepted;
922#endif 922#endif
923 923
924 QString name; 924 QString name;
925 QString username; 925 QString username;
926 QString comment; 926 QString comment;
927 if (result == Accepted) 927 if (result == Accepted)
928 { 928 {
929 name = dialog->NameField->text(); 929 name = dialog->NameField->text();
930 username = dialog->UsernameField->text(); 930 username = dialog->UsernameField->text();
931 comment = dialog->CommentField->text(); 931 comment = dialog->CommentField->text();
932#ifndef NO_OPIE 932#ifndef NO_OPIE
933 owarn << name << oendl; 933 owarn << name << oendl;
934#else 934#else
935 qWarning (name); 935 qWarning (name);
936#endif 936#endif
937 } 937 }
938 else 938 else
939 { 939 {
940 delete dialog; 940 delete dialog;
941 return; 941 return;
942 } 942 }
943 943
944 if (!name.isEmpty() && name != lastSearchedName || 944 if (!name.isEmpty() && name != lastSearchedName ||
945 lastSearchedName.isEmpty() && !name.isEmpty()) 945 lastSearchedName.isEmpty() && !name.isEmpty())
946 { 946 {
947 // set search at the beginning if a new name is given 947 // set search at the beginning if a new name is given
948 lastSearchedCategory = NULL; 948 lastSearchedCategory = NULL;
949 lastSearchedItem = NULL; 949 lastSearchedItem = NULL;
950 } 950 }
951 lastSearchedName = name; 951 lastSearchedName = name;
952 if (!username.isEmpty() && username != lastSearchedUsername || 952 if (!username.isEmpty() && username != lastSearchedUsername ||
953 lastSearchedUsername.isEmpty() && !username.isEmpty()) 953 lastSearchedUsername.isEmpty() && !username.isEmpty())
954 { 954 {
955 // set search at the beginning if a new name is given 955 // set search at the beginning if a new name is given
956 lastSearchedCategory = NULL; 956 lastSearchedCategory = NULL;
957 lastSearchedItem = NULL; 957 lastSearchedItem = NULL;
958 } 958 }
959 lastSearchedUsername = username; 959 lastSearchedUsername = username;
960 if (!comment.isEmpty() && comment != lastSearchedComment || 960 if (!comment.isEmpty() && comment != lastSearchedComment ||
961 lastSearchedComment.isEmpty() && !comment.isEmpty()) 961 lastSearchedComment.isEmpty() && !comment.isEmpty())
962 { 962 {
963 // set search at the beginning if a new name is given 963 // set search at the beginning if a new name is given
964 lastSearchedCategory = NULL; 964 lastSearchedCategory = NULL;
965 lastSearchedItem = NULL; 965 lastSearchedItem = NULL;
966 } 966 }
967 lastSearchedComment = comment; 967 lastSearchedComment = comment;
968 968
969 ListView->clearSelection(); 969 ListView->clearSelection();
970 970
971 bool found=FALSE; 971 bool found=FALSE;
972 // step through all categories 972 // step through all categories
973 QListViewItem *i; 973 QListViewItem *i;
974 if (lastSearchedCategory) 974 if (lastSearchedCategory)
975 i = lastSearchedCategory; 975 i = lastSearchedCategory;
976 else 976 else
977 i = ListView->firstChild(); 977 i = ListView->firstChild();
978 for (; 978 for (;
979 i != NULL; 979 i != NULL;
980 i = i->nextSibling()) 980 i = i->nextSibling())
981 { 981 {
982#ifndef NO_OPIE 982#ifndef NO_OPIE
983 owarn << i->text(0) << oendl; 983 owarn << i->text(0) << oendl;
984#endif 984#endif
985 i->setSelected(FALSE); 985 i->setSelected(FALSE);
986 986
987 // step through all subitems 987 // step through all subitems
988 QListViewItem *si; 988 QListViewItem *si;
989 if (lastSearchedItem) 989 if (lastSearchedItem)
990 si = lastSearchedItem; 990 si = lastSearchedItem;
991 else 991 else
992 si = i->firstChild(); 992 si = i->firstChild();
993 // for (si = i->firstChild(); 993 // for (si = i->firstChild();
994 for (; 994 for (;
995 si != NULL; 995 si != NULL;
996 si = si->nextSibling()) 996 si = si->nextSibling())
997 { 997 {
998#ifndef NO_OPIE 998#ifndef NO_OPIE
999 owarn << si->text(0) << oendl; 999 owarn << si->text(0) << oendl;
1000#else 1000#else
1001 qWarning (si->text(0)); 1001 qWarning (si->text(0));
1002#endif 1002#endif
1003 if (si->isSelected()) 1003 if (si->isSelected())
1004 si->setSelected(FALSE); 1004 si->setSelected(FALSE);
1005 // ListView->repaintItem(si); 1005 // ListView->repaintItem(si);
1006 1006
1007 bool n=TRUE; 1007 bool n=TRUE;
1008 bool u=TRUE; 1008 bool u=TRUE;
1009 bool c=TRUE; 1009 bool c=TRUE;
1010 if (!name.isEmpty()) 1010 if (!name.isEmpty())
1011 n = (si->text(0)).contains (name, FALSE); 1011 n = (si->text(0)).contains (name, FALSE);
1012 if (!username.isEmpty()) 1012 if (!username.isEmpty())
1013 u = (si->text(1)).contains (username, FALSE); 1013 u = (si->text(1)).contains (username, FALSE);
1014 if (!comment.isEmpty()) 1014 if (!comment.isEmpty())
1015 c = (si->text(3)).contains (comment, FALSE); 1015 c = (si->text(3)).contains (comment, FALSE);
1016 1016
1017 if ((n && u && c ) && !found) 1017 if ((n && u && c ) && !found)
1018 { 1018 {
1019#ifndef NO_OPIE 1019#ifndef NO_OPIE
1020 owarn << "Found" << oendl; 1020 owarn << "Found" << oendl;
1021#else 1021#else
1022 qWarning ("Found"); 1022 qWarning ("Found");
1023#endif 1023#endif
1024 selectedItem = si; 1024 selectedItem = si;
1025 si->setSelected(TRUE); 1025 si->setSelected(TRUE);
1026 ListView->setCurrentItem(si); 1026 ListView->setCurrentItem(si);
1027 ListView->ensureItemVisible(si); 1027 ListView->ensureItemVisible(si);
1028 ListView->triggerUpdate(); 1028 ListView->triggerUpdate();
1029 1029
1030 lastSearchedCategory = i; 1030 lastSearchedCategory = i;
1031 // set to the next item 1031 // set to the next item
1032 lastSearchedItem = si->nextSibling(); 1032 lastSearchedItem = si->nextSibling();
1033 if (!lastSearchedItem) 1033 if (!lastSearchedItem)
1034 { 1034 {
1035 // no next item within category -> set next category 1035 // no next item within category -> set next category
1036 lastSearchedCategory = i->nextSibling(); 1036 lastSearchedCategory = i->nextSibling();
1037 if (!lastSearchedCategory) 1037 if (!lastSearchedCategory)
1038 lastSearchedItem = NULL; // END 1038 lastSearchedItem = NULL; // END
1039 } 1039 }
1040 1040
1041 found = TRUE; 1041 found = TRUE;
1042 delete dialog; 1042 delete dialog;
1043 update(); 1043 update();
1044 return; 1044 return;
1045 } 1045 }
1046 } 1046 }
1047 lastSearchedCategory = i->nextSibling(); 1047 lastSearchedCategory = i->nextSibling();
1048 lastSearchedItem = NULL; 1048 lastSearchedItem = NULL;
1049 } 1049 }
1050 lastSearchedCategory = NULL; 1050 lastSearchedCategory = NULL;
1051 lastSearchedItem = NULL; 1051 lastSearchedItem = NULL;
1052 delete dialog; 1052 delete dialog;
1053 update(); 1053 update();
1054 QMessageBox::information( this, tr("ZSafe"), 1054 QMessageBox::information( this, tr("ZSafe"),
1055 tr("Entry not found"), tr("&OK"), 0); 1055 tr("Entry not found"), tr("&OK"), 0);
1056 1056
1057} 1057}
1058 1058
1059QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def) 1059QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def)
1060{ 1060{
1061 QString category; 1061 QString category;
1062 if (_item) 1062 if (_item)
1063 { 1063 {
1064 if (isCategory(_item)) 1064 if (isCategory(_item))
1065 { 1065 {
1066 category = _item->text(0); 1066 category = _item->text(0);
1067 } 1067 }
1068 else 1068 else
1069 { 1069 {
1070 QListViewItem *cat = _item->parent(); 1070 QListViewItem *cat = _item->parent();
1071 category = cat->text(0); 1071 category = cat->text(0);
1072 } 1072 }
1073 } 1073 }
1074 else 1074 else
1075 { 1075 {
1076 return def; 1076 return def;
1077 } 1077 }
1078 1078
1079 QString app_key = APP_KEY; 1079 QString app_key = APP_KEY;
1080#ifndef DESKTOP 1080#ifndef DESKTOP
1081#ifndef WIN32 1081#ifndef WIN32
1082 conf->setGroup ("fieldDefs"); 1082 conf->setGroup ("fieldDefs");
1083#endif 1083#endif
1084#else 1084#else
1085#ifndef WIN32 1085#ifndef WIN32
1086 app_key += "/fieldDefs/"; 1086 app_key += "/fieldDefs/";
1087#endif 1087#endif
1088#endif 1088#endif
1089// #ifndef WIN32 1089// #ifndef WIN32
1090 QString label = conf->readEntry(app_key+category+"-field"+field,def); 1090 QString label = conf->readEntry(app_key+category+"-field"+field,def);
1091// #else 1091// #else
1092// QString label(def); 1092// QString label(def);
1093// #endif 1093// #endif
1094 1094
1095#ifndef DESKTOP 1095#ifndef DESKTOP
1096 conf->setGroup ("zsafe"); 1096 conf->setGroup ("zsafe");
1097#endif 1097#endif
1098 return label; 1098 return label;
1099} 1099}
1100 1100
1101QString ZSafe::getFieldLabel (QString category, QString field, QString def) 1101QString ZSafe::getFieldLabel (QString category, QString field, QString def)
1102{ 1102{
1103 QString app_key = APP_KEY; 1103 QString app_key = APP_KEY;
1104#ifndef DESKTOP 1104#ifndef DESKTOP
1105 conf->setGroup ("fieldDefs"); 1105 conf->setGroup ("fieldDefs");
1106#else 1106#else
1107#ifndef WIN32 1107#ifndef WIN32
1108 app_key += "/fieldDefs/"; 1108 app_key += "/fieldDefs/";
1109#endif 1109#endif
1110#endif 1110#endif
1111// #ifndef WIN32 1111// #ifndef WIN32
1112 QString label = conf->readEntry(app_key+category+"-field"+field, 1112 QString label = conf->readEntry(app_key+category+"-field"+field,
1113 def); 1113 def);
1114// #else 1114// #else
1115 // QString label(def); 1115 // QString label(def);
1116// #endif 1116// #endif
1117#ifndef DESKTOP 1117#ifndef DESKTOP
1118 conf->setGroup ("zsafe"); 1118 conf->setGroup ("zsafe");
1119#endif 1119#endif
1120 return label; 1120 return label;
1121} 1121}
1122 1122
1123void ZSafe::showInfo( QListViewItem *_item) 1123void ZSafe::showInfo( QListViewItem *_item)
1124{ 1124{
1125 if (!_item) 1125 if (!_item)
1126 return; 1126 return;
1127 if (selectedItem != NULL) 1127 if (selectedItem != NULL)
1128 selectedItem->setSelected(FALSE); 1128 selectedItem->setSelected(FALSE);
1129 1129
1130 selectedItem = _item; 1130 selectedItem = _item;
1131 selectedItem->setSelected(TRUE); 1131 selectedItem->setSelected(TRUE);
1132 1132
1133 if (!isCategory(_item)) 1133 if (!isCategory(_item))
1134 { 1134 {
1135/* 1135/*
1136 QString label=selectedItem->text(0); 1136 QString label=selectedItem->text(0);
1137 label+="\n"; 1137 label+="\n";
1138 label+=selectedItem->text(1); 1138 label+=selectedItem->text(1);
1139 label+="\n"; 1139 label+="\n";
1140 label+=selectedItem->text(2); 1140 label+=selectedItem->text(2);
1141 label+="\n"; 1141 label+="\n";
1142 label+=selectedItem->text(3); 1142 label+=selectedItem->text(3);
1143*/ 1143*/
1144 1144
1145 QString text; 1145 QString text;
1146 QString entry; 1146 QString entry;
1147 1147
1148 text = "<html><body><div align=""center""><u><b>"; 1148 text = "<html><body><div align=""center""><u><b>";
1149 text += selectedItem->text(0); 1149 text += selectedItem->text(0);
1150 text += "</b></u><br></div><br>"; 1150 text += "</b></u><br></div><br>";
1151 1151
1152 entry = selectedItem->text(1); 1152 entry = selectedItem->text(1);
1153 if (!entry.isEmpty() && entry.compare(" ")) 1153 if (!entry.isEmpty() && entry.compare(" "))
1154 { 1154 {
1155 text += "<u><b>"; 1155 text += "<u><b>";
1156 text += getFieldLabel (selectedItem, "2", tr("Username")); 1156 text += getFieldLabel (selectedItem, "2", tr("Username"));
1157 text += ":<br></b></u><blockquote>"; 1157 text += ":<br></b></u><blockquote>";
1158 text += entry; 1158 text += entry;
1159 text += "</blockquote>"; 1159 text += "</blockquote>";
1160 // text += "<br>"; 1160 // text += "<br>";
1161 } 1161 }
1162 1162
1163 entry = selectedItem->text(2); 1163 entry = selectedItem->text(2);
1164 if (!entry.isEmpty() && entry.compare(" ")) 1164 if (!entry.isEmpty() && entry.compare(" "))
1165 { 1165 {
1166 text += "<u><b>"; 1166 text += "<u><b>";
1167 text += getFieldLabel (selectedItem, "3", tr("Password")); 1167 text += getFieldLabel (selectedItem, "3", tr("Password"));
1168 text += ":<br> </b></u><blockquote>"; 1168 text += ":<br> </b></u><blockquote>";
1169 text += entry; 1169 text += entry;
1170 text += "</blockquote>"; 1170 text += "</blockquote>";
1171 // text += "<br>"; 1171 // text += "<br>";
1172 } 1172 }
1173 1173
1174 entry = selectedItem->text(4); 1174 entry = selectedItem->text(4);
1175 if (!entry.isEmpty() && entry.compare(" ")) 1175 if (!entry.isEmpty() && entry.compare(" "))
1176 { 1176 {
1177 text += "<u><b>"; 1177 text += "<u><b>";
1178 text += getFieldLabel (selectedItem, "5", tr("Field 4")); 1178 text += getFieldLabel (selectedItem, "5", tr("Field 4"));
1179 text += ":<br> </b></u><blockquote>"; 1179 text += ":<br> </b></u><blockquote>";
1180 text += entry; 1180 text += entry;
1181 text += "</blockquote>"; 1181 text += "</blockquote>";
1182 // text += "<br>"; 1182 // text += "<br>";
1183 } 1183 }
1184 1184
1185 entry = selectedItem->text(5); 1185 entry = selectedItem->text(5);
1186 if (!entry.isEmpty() && entry.compare(" ")) 1186 if (!entry.isEmpty() && entry.compare(" "))
1187 { 1187 {
1188 text += "<u><b>"; 1188 text += "<u><b>";
1189 text += getFieldLabel (selectedItem, "6", tr("Field 5")); 1189 text += getFieldLabel (selectedItem, "6", tr("Field 5"));
1190 text += ":<br> </b></u><blockquote>"; 1190 text += ":<br> </b></u><blockquote>";
1191 text += entry; 1191 text += entry;
1192 text += "</blockquote>"; 1192 text += "</blockquote>";
1193 // text += "<br>"; 1193 // text += "<br>";
1194 } 1194 }
1195 1195
1196 entry = selectedItem->text(3); 1196 entry = selectedItem->text(3);
1197 if (!entry.isEmpty() && entry.compare(" ")) 1197 if (!entry.isEmpty() && entry.compare(" "))
1198 { 1198 {
1199 text += "<u><b>"; 1199 text += "<u><b>";
1200 text += getFieldLabel (selectedItem, "4", tr("Comment")); 1200 text += getFieldLabel (selectedItem, "4", tr("Comment"));
1201 text += ":<br> </b></u>"; 1201 text += ":<br> </b></u>";
1202 QString comment = selectedItem->text(3); 1202 QString comment = selectedItem->text(3);
1203 comment.replace (QRegExp("\n"), "<br>"); 1203 comment.replace (QRegExp("\n"), "<br>");
1204 text += comment; 1204 text += comment;
1205 // text += "<br>"; 1205 // text += "<br>";
1206 } 1206 }
1207 1207
1208 text += "</body></html>"; 1208 text += "</body></html>";
1209 1209
1210 infoForm->InfoText->setText(text); 1210 infoForm->InfoText->setText(text);
1211 infoForm->hide(); 1211 infoForm->hide();
1212 QPEApplication::showDialog( infoForm ); 1212 QPEApplication::showDialog( infoForm );
1213 } 1213 }
1214} 1214}
1215 1215
1216void ZSafe::listViewSelected( QListViewItem *_item) 1216void ZSafe::listViewSelected( QListViewItem *_item)
1217{ 1217{
1218 if (!_item) 1218 if (!_item)
1219 return; 1219 return;
1220 if (selectedItem != NULL) 1220 if (selectedItem != NULL)
1221 selectedItem->setSelected(FALSE); 1221 selectedItem->setSelected(FALSE);
1222 1222
1223 selectedItem = _item; 1223 selectedItem = _item;
1224 1224
1225#ifndef DESKTOP 1225#ifndef DESKTOP
1226 // set the column text dependent on the selected item 1226 // set the column text dependent on the selected item
1227 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1227 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1228 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1228 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1229 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1229 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1230 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1230 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1231 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1231 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1232 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1232 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1233#endif 1233#endif
1234#ifdef WIN32 1234#ifdef WIN32
1235 // set the column text dependent on the selected item 1235 // set the column text dependent on the selected item
1236 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1236 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1237 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1237 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1238 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1238 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1239 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1239 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1240 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1240 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1241 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1241 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1242#endif 1242#endif
1243 1243
1244} 1244}
1245 1245
1246bool ZSafe::isCategory(QListViewItem *_item) 1246bool ZSafe::isCategory(QListViewItem *_item)
1247{ 1247{
1248 if (_item == NULL) 1248 if (_item == NULL)
1249 return FALSE; 1249 return FALSE;
1250 1250
1251 QString categoryName = _item->text (0); 1251 QString categoryName = _item->text (0);
1252 if (categories.find (categoryName)) 1252 if (categories.find (categoryName))
1253 return TRUE; 1253 return TRUE;
1254 else 1254 else
1255 return FALSE; 1255 return FALSE;
1256} 1256}
1257 1257
1258void ZSafe::removeAsciiFile() 1258void ZSafe::removeAsciiFile()
1259{ 1259{
1260 // QString fn = filename + ".txt"; 1260 // QString fn = filename + ".txt";
1261 // open the file dialog 1261 // open the file dialog
1262#ifndef DESKTOP 1262#ifndef DESKTOP
1263#ifndef NO_OPIE 1263#ifndef NO_OPIE
1264 QMap<QString, QStringList> mimeTypes; 1264 QMap<QString, QStringList> mimeTypes;
1265 mimeTypes.insert(tr("All"), QStringList() ); 1265 mimeTypes.insert(tr("All"), QStringList() );
1266 mimeTypes.insert(tr("Text"), "text/*" ); 1266 mimeTypes.insert(tr("Text"), "text/*" );
1267 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1267 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1268 QDir::homeDirPath() + "/Documents/application/zsafe", 1268 QDir::homeDirPath() + "/Documents/application/zsafe",
1269 QString::null, 1269 QString::null,
1270 mimeTypes, 1270 mimeTypes,
1271 this, 1271 this,
1272 tr ("Remove text file")); 1272 tr ("Remove text file"));
1273#else 1273#else
1274 QString fn = ScQtFileEdit::getOpenFileName(this, 1274 QString fn = ScQtFileEdit::getOpenFileName(this,
1275 tr ("Remove text file"), 1275 tr ("Remove text file"),
1276 QDir::homeDirPath() + "/Documents/application/zsafe", 1276 QDir::homeDirPath() + "/Documents/application/zsafe",
1277 "*.txt"); 1277 "*.txt");
1278#endif 1278#endif
1279#else 1279#else
1280 QString fn = QFileDialog::getOpenFileName( 1280 QString fn = QFileDialog::getOpenFileName(
1281 QDir::homeDirPath() + "/Documents/application/zsafe", 1281 QDir::homeDirPath() + "/Documents/application/zsafe",
1282 "ZSafe (*.txt)", 1282 "ZSafe (*.txt)",
1283 this, 1283 this,
1284 "ZSafe File Dialog" 1284 "ZSafe File Dialog"
1285 "Choose a text file" ); 1285 "Choose a text file" );
1286#endif 1286#endif
1287 1287
1288 if (fn && fn.length() > 0 ) 1288 if (fn && fn.length() > 0 )
1289 { 1289 {
1290 QFile f( fn ); 1290 QFile f( fn );
1291 if ( !f.remove() ) 1291 if ( !f.remove() )
1292 { 1292 {
1293#ifndef NO_OPIE 1293#ifndef NO_OPIE
1294 owarn << "Could not remove file " << fn << oendl; 1294 owarn << "Could not remove file " << fn << oendl;
1295#else 1295#else
1296 qWarning( QString("Could not remove file %1").arg(fn),2000 ); 1296 qWarning( QString("Could not remove file %1").arg(fn),2000 );
1297#endif 1297#endif
1298 QMessageBox::critical( 0, tr("ZSafe"), 1298 QMessageBox::critical( 0, tr("ZSafe"),
1299 tr("Could not remove text file.") ); 1299 tr("Could not remove text file.") );
1300 return; 1300 return;
1301 } 1301 }
1302 } 1302 }
1303} 1303}
1304 1304
1305void ZSafe::writeAllEntries() 1305void ZSafe::writeAllEntries()
1306{ 1306{
1307 if (filename.isEmpty()) 1307 if (filename.isEmpty())
1308 { 1308 {
1309 QMessageBox::critical( 0, tr("ZSafe"), 1309 QMessageBox::critical( 0, tr("ZSafe"),
1310 tr("No document defined.\nYou have to create a new document")); 1310 tr("No document defined.\nYou have to create a new document"));
1311 return; 1311 return;
1312 } 1312 }
1313 1313
1314 // open the file dialog 1314 // open the file dialog
1315#ifndef DESKTOP 1315#ifndef DESKTOP
1316#ifndef NO_OPIE 1316#ifndef NO_OPIE
1317 QMap<QString, QStringList> mimeTypes; 1317 QMap<QString, QStringList> mimeTypes;
1318 mimeTypes.insert(tr("All"), QStringList() ); 1318 mimeTypes.insert(tr("All"), QStringList() );
1319 mimeTypes.insert(tr("Text"), "text/*" ); 1319 mimeTypes.insert(tr("Text"), "text/*" );
1320 QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 1320 QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
1321 QDir::homeDirPath() + "/Documents/application/zsafe", 1321 QDir::homeDirPath() + "/Documents/application/zsafe",
1322 QString::null, 1322 QString::null,
1323 mimeTypes, 1323 mimeTypes,
1324 this, 1324 this,
1325 tr ("Export text file")); 1325 tr ("Export text file"));
1326#else 1326#else
1327 QString fn = ScQtFileEdit::getSaveAsFileName(this, 1327 QString fn = ScQtFileEdit::getSaveAsFileName(this,
1328 tr ("Export text file"), 1328 tr ("Export text file"),
1329 QDir::homeDirPath() + "/Documents/application/zsafe", 1329 QDir::homeDirPath() + "/Documents/application/zsafe",
1330 "*.txt"); 1330 "*.txt");
1331#endif 1331#endif
1332#else 1332#else
1333 QString fn = QFileDialog::getSaveFileName( 1333 QString fn = QFileDialog::getSaveFileName(
1334 QDir::homeDirPath() + "/Documents/application/zsafe", 1334 QDir::homeDirPath() + "/Documents/application/zsafe",
1335 "ZSafe (*.txt)", 1335 "ZSafe (*.txt)",
1336 this, 1336 this,
1337 "ZSafe File Dialog" 1337 "ZSafe File Dialog"
1338 "Choose a text file" ); 1338 "Choose a text file" );
1339#endif 1339#endif
1340 1340
1341 // open the new document 1341 // open the new document
1342 if (fn && fn.length() > 0 ) 1342 if (fn && fn.length() > 0 )
1343 { 1343 {
1344 QFile f( fn ); 1344 QFile f( fn );
1345 if ( !f.open( IO_WriteOnly ) ) { 1345 if ( !f.open( IO_WriteOnly ) ) {
1346#ifndef NO_OPIE 1346#ifndef NO_OPIE
1347 owarn << "Could not write to file " << fn << oendl; 1347 owarn << "Could not write to file " << fn << oendl;
1348#else 1348#else
1349 qWarning( QString("Could not write to file %1").arg(fn),2000 ); 1349 qWarning( QString("Could not write to file %1").arg(fn),2000 );
1350#endif 1350#endif
1351 QMessageBox::critical( 0, "ZSafe", 1351 QMessageBox::critical( 0, "ZSafe",
1352 QString("Could not export to text file.") ); 1352 QString("Could not export to text file.") );
1353 return; 1353 return;
1354 } 1354 }
1355 QTextStream t( &f ); 1355 QTextStream t( &f );
1356 1356
1357 QListViewItem *i; 1357 QListViewItem *i;
1358 // step through all categories 1358 // step through all categories
1359 for (i = ListView->firstChild(); 1359 for (i = ListView->firstChild();
1360 i != NULL; 1360 i != NULL;
1361 i = i->nextSibling()) 1361 i = i->nextSibling())
1362 { 1362 {
1363 // step through all subitems 1363 // step through all subitems
1364 QListViewItem *si; 1364 QListViewItem *si;
1365 for (si = i->firstChild(); 1365 for (si = i->firstChild();
1366 si != NULL; 1366 si != NULL;
1367 si = si->nextSibling()) 1367 si = si->nextSibling())
1368 { 1368 {
1369 QString oneEntry; 1369 QString oneEntry;
1370 oneEntry += "\""; 1370 oneEntry += "\"";
1371 oneEntry += i->text(0); 1371 oneEntry += i->text(0);
1372 oneEntry += "\";"; 1372 oneEntry += "\";";
1373 oneEntry += "\""; 1373 oneEntry += "\"";
1374 oneEntry += si->text(0); 1374 oneEntry += si->text(0);
1375 oneEntry += "\";"; 1375 oneEntry += "\";";
1376 oneEntry += "\""; 1376 oneEntry += "\"";
1377 oneEntry += si->text(1); 1377 oneEntry += si->text(1);
1378 oneEntry += "\";"; 1378 oneEntry += "\";";
1379 oneEntry += "\""; 1379 oneEntry += "\"";
1380 oneEntry += si->text(2); 1380 oneEntry += si->text(2);
1381 oneEntry += "\";"; 1381 oneEntry += "\";";
1382 oneEntry += "\""; 1382 oneEntry += "\"";
1383 QString comment = si->text(3); 1383 QString comment = si->text(3);
1384 comment.replace (QRegExp("\n"), "<br>"); 1384 comment.replace (QRegExp("\n"), "<br>");
1385 oneEntry += comment; 1385 oneEntry += comment;
1386 oneEntry += "\";"; 1386 oneEntry += "\";";
1387 oneEntry += "\""; 1387 oneEntry += "\"";
1388 oneEntry += si->text(4); 1388 oneEntry += si->text(4);
1389 oneEntry += "\";"; 1389 oneEntry += "\";";
1390 oneEntry += "\""; 1390 oneEntry += "\"";
1391 oneEntry += si->text(5); 1391 oneEntry += si->text(5);
1392 oneEntry += "\""; 1392 oneEntry += "\"";
1393 // owarn << oneEntry << oendl; 1393 // owarn << oneEntry << oendl;
1394 t << oneEntry << endl; 1394 t << oneEntry << endl;
1395 1395
1396 // owarn << si->text(0) << oendl; 1396 // owarn << si->text(0) << oendl;
1397 } 1397 }
1398 } 1398 }
1399 f.close(); 1399 f.close();
1400 } 1400 }
1401} 1401}
1402 1402
1403void ZSafe::readAllEntries() 1403void ZSafe::readAllEntries()
1404{ 1404{
1405 if (filename.isEmpty()) 1405 if (filename.isEmpty())
1406 { 1406 {
1407 QMessageBox::critical( 0, tr("ZSafe"), 1407 QMessageBox::critical( 0, tr("ZSafe"),
1408 tr("No document defined.\nYou have to create a new document")); 1408 tr("No document defined.\nYou have to create a new document"));
1409 return; 1409 return;
1410 } 1410 }
1411 1411
1412 // open the file dialog 1412 // open the file dialog
1413#ifndef DESKTOP 1413#ifndef DESKTOP
1414#ifndef NO_OPIE 1414#ifndef NO_OPIE
1415 QMap<QString, QStringList> mimeTypes; 1415 QMap<QString, QStringList> mimeTypes;
1416 mimeTypes.insert(tr("All"), QStringList() ); 1416 mimeTypes.insert(tr("All"), QStringList() );
1417 mimeTypes.insert(tr("Text"), "text/*" ); 1417 mimeTypes.insert(tr("Text"), "text/*" );
1418 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1418 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1419 QDir::homeDirPath() + "/Documents/application/zsafe", 1419 QDir::homeDirPath() + "/Documents/application/zsafe",
1420 QString::null, 1420 QString::null,
1421 mimeTypes, 1421 mimeTypes,
1422 this, 1422 this,
1423 tr ("Import text file")); 1423 tr ("Import text file"));
1424#else 1424#else
1425 QString fn = ScQtFileEdit::getOpenFileName(this, 1425 QString fn = ScQtFileEdit::getOpenFileName(this,
1426 tr ("Import text file"), 1426 tr ("Import text file"),
1427 QDir::homeDirPath() + "/Documents/application/zsafe", 1427 QDir::homeDirPath() + "/Documents/application/zsafe",
1428 "*.txt"); 1428 "*.txt");
1429#endif 1429#endif
1430#else 1430#else
1431 QString fn = QFileDialog::getOpenFileName( 1431 QString fn = QFileDialog::getOpenFileName(
1432 QDir::homeDirPath() + "/Documents/application/zsafe", 1432 QDir::homeDirPath() + "/Documents/application/zsafe",
1433 "ZSafe (*.txt)", 1433 "ZSafe (*.txt)",
1434 this, 1434 this,
1435 "ZSafe File Dialog" 1435 "ZSafe File Dialog"
1436 "Choose a text file" ); 1436 "Choose a text file" );
1437#endif 1437#endif
1438 1438
1439 if (fn && fn.length() > 0 ) 1439 if (fn && fn.length() > 0 )
1440 { 1440 {
1441 QFile f( fn ); 1441 QFile f( fn );
1442 if ( !f.open( IO_ReadOnly ) ) 1442 if ( !f.open( IO_ReadOnly ) )
1443 { 1443 {
1444#ifndef NO_OPIE 1444#ifndef NO_OPIE
1445 owarn << "Could not read file " << fn << oendl; 1445 owarn << "Could not read file " << fn << oendl;
1446#else 1446#else
1447 qWarning( QString("Could not read file %1").arg(fn), 2000 ); 1447 qWarning( QString("Could not read file %1").arg(fn), 2000 );
1448#endif 1448#endif
1449 QMessageBox::critical( 0, "ZSafe", 1449 QMessageBox::critical( 0, "ZSafe",
1450 QString("Could not import text file.") ); 1450 QString("Could not import text file.") );
1451 return; 1451 return;
1452 } 1452 }
1453 1453
1454 modified = true; 1454 modified = true;
1455 1455
1456 // clear the password list 1456 // clear the password list
1457 selectedItem = NULL; 1457 selectedItem = NULL;
1458 QListViewItem *i; 1458 QListViewItem *i;
1459 // step through all categories 1459 // step through all categories
1460 for (i = ListView->firstChild(); 1460 for (i = ListView->firstChild();
1461 i != NULL; 1461 i != NULL;
1462 i = i->nextSibling()) 1462 i = i->nextSibling())
1463 { 1463 {
1464 // step through all subitems 1464 // step through all subitems
1465 QListViewItem *si; 1465 QListViewItem *si;
1466 for (si = i->firstChild(); 1466 for (si = i->firstChild();
1467 si != NULL; ) 1467 si != NULL; )
1468 // si = si->nextSibling()) 1468 // si = si->nextSibling())
1469 { 1469 {
1470 QListViewItem *_si = si; 1470 QListViewItem *_si = si;
1471 si = si->nextSibling(); 1471 si = si->nextSibling();
1472 i->takeItem(_si); // remove from view list 1472 i->takeItem(_si); // remove from view list
1473 if (_si) delete _si; 1473 if (_si) delete _si;
1474 } 1474 }
1475 } 1475 }
1476 1476
1477#ifndef NO_OPIE 1477#ifndef NO_OPIE
1478 owarn << "ReadAllEntries(): " << oendl; 1478 owarn << "ReadAllEntries(): " << oendl;
1479#else 1479#else
1480 qWarning ("ReadAllEntries(): "); 1480 qWarning ("ReadAllEntries(): ");
1481#endif 1481#endif
1482 1482
1483 QTextStream t(&f); 1483 QTextStream t(&f);
1484 while ( !t.eof() ) 1484 while ( !t.eof() )
1485 { 1485 {
1486 QString s = t.readLine(); 1486 QString s = t.readLine();
1487 s.replace (QRegExp("\";\""), "\"|\""); 1487 s.replace (QRegExp("\";\""), "\"|\"");
1488 // char buffer[1024]; 1488 // char buffer[1024];
1489#ifndef WIN32 1489#ifndef WIN32
1490 char buffer[s.length()+1]; 1490 char buffer[s.length()+1];
1491#else 1491#else
1492 char buffer[4048]; 1492 char buffer[4048];
1493#endif 1493#endif
1494 1494
1495 1495
1496 /* modify QString -> QCString::utf8 */ 1496 /* modify QString -> QCString::utf8 */
1497 1497
1498 strcpy (buffer, s.utf8()); 1498 strcpy (buffer, s.utf8());
1499 1499
1500 QString name; 1500 QString name;
1501 QString user; 1501 QString user;
1502 QString password; 1502 QString password;
1503 QString comment; 1503 QString comment;
1504 QString field5=""; 1504 QString field5="";
1505 QString field6=""; 1505 QString field6="";
1506 1506
1507 // separete the entries 1507 // separete the entries
1508 char *i = strtok (buffer, "|"); 1508 char *i = strtok (buffer, "|");
1509 QString category(QString::fromUtf8(&i[1])); 1509 QString category(QString::fromUtf8(&i[1]));
1510 category.truncate(category.length() -1); 1510 category.truncate(category.length() -1);
1511 1511
1512 int idx=0; 1512 int idx=0;
1513 while ((i = strtok (NULL, "|")) != NULL) 1513 while ((i = strtok (NULL, "|")) != NULL)
1514 { 1514 {
1515 switch (idx) 1515 switch (idx)
1516 { 1516 {
1517 case 0: 1517 case 0:
1518 name = QString::fromUtf8(&i[1]); 1518 name = QString::fromUtf8(&i[1]);
1519 name.truncate(name.length() -1); 1519 name.truncate(name.length() -1);
1520 // name 1520 // name
1521 break; 1521 break;
1522 case 1: 1522 case 1:
1523 // user 1523 // user
1524 user = QString::fromUtf8(&i[1]); 1524 user = QString::fromUtf8(&i[1]);
1525 user.truncate(user.length() -1); 1525 user.truncate(user.length() -1);
1526 break; 1526 break;
1527 case 2: 1527 case 2:
1528 // password 1528 // password
1529 password = QString::fromUtf8(&i[1]); 1529 password = QString::fromUtf8(&i[1]);
1530 password.truncate(password.length() -1); 1530 password.truncate(password.length() -1);
1531 break; 1531 break;
1532 case 3: 1532 case 3:
1533 // comment 1533 // comment
1534 comment = QString::fromUtf8(&i[1]); 1534 comment = QString::fromUtf8(&i[1]);
1535 comment.truncate(comment.length() -1); 1535 comment.truncate(comment.length() -1);
1536 break; 1536 break;
1537 case 4: 1537 case 4:
1538 // field5 1538 // field5
1539 field5 = QString::fromUtf8(&i[1]); 1539 field5 = QString::fromUtf8(&i[1]);
1540 field5.truncate(field5.length() -1); 1540 field5.truncate(field5.length() -1);
1541 break; 1541 break;
1542 case 5: 1542 case 5:
1543 // field6 1543 // field6
1544 field6 = QString::fromUtf8(&i[1]); 1544 field6 = QString::fromUtf8(&i[1]);
1545 field6.truncate(field6.length() -1); 1545 field6.truncate(field6.length() -1);
1546 break; 1546 break;
1547 } 1547 }
1548 idx++; 1548 idx++;
1549 } 1549 }
1550 1550
1551 Category *cat= categories.find (category); 1551 Category *cat= categories.find (category);
1552 if (cat) 1552 if (cat)
1553 { 1553 {
1554 // use the existend item 1554 // use the existend item
1555 QListViewItem *catItem = cat->getListItem(); 1555 QListViewItem *catItem = cat->getListItem();
1556 if (catItem) 1556 if (catItem)
1557 { 1557 {
1558 QListViewItem * item = new ShadedListItem( 0, catItem ); 1558 QListViewItem * item = new ShadedListItem( 0, catItem );
1559 item->setText( 0, tr( name ) ); 1559 item->setText( 0, tr( name ) );
1560 item->setText( 1, tr( user ) ); 1560 item->setText( 1, tr( user ) );
1561 item->setText( 2, tr( password ) ); 1561 item->setText( 2, tr( password ) );
1562 item->setText( 3, tr( comment ) ); 1562 item->setText( 3, tr( comment ) );
1563 item->setText( 4, tr( field5 ) ); 1563 item->setText( 4, tr( field5 ) );
1564 item->setText( 5, tr( field6 ) ); 1564 item->setText( 5, tr( field6 ) );
1565 catItem->setOpen( TRUE ); 1565 catItem->setOpen( TRUE );
1566 } 1566 }
1567 } 1567 }
1568 else 1568 else
1569 { 1569 {
1570 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1570 QListViewItem *catI = new ShadedListItem( 1, ListView );
1571 // create and insert a new item 1571 // create and insert a new item
1572 QListViewItem * item = new ShadedListItem( 0, catI ); 1572 QListViewItem * item = new ShadedListItem( 0, catI );
1573 item->setText( 0, tr( name ) ); 1573 item->setText( 0, tr( name ) );
1574 item->setText( 1, tr( user ) ); 1574 item->setText( 1, tr( user ) );
1575 item->setText( 2, tr( password ) ); 1575 item->setText( 2, tr( password ) );
1576 item->setText( 3, tr( comment ) ); 1576 item->setText( 3, tr( comment ) );
1577 item->setText( 4, tr( field5 ) ); 1577 item->setText( 4, tr( field5 ) );
1578 item->setText( 5, tr( field6 ) ); 1578 item->setText( 5, tr( field6 ) );
1579 1579
1580 catI->setOpen( TRUE ); 1580 catI->setOpen( TRUE );
1581 1581
1582 Category *c1 = new Category(); 1582 Category *c1 = new Category();
1583 c1->setCategoryName(category); 1583 c1->setCategoryName(category);
1584 1584
1585 QString icon; 1585 QString icon;
1586 QString fullIconPath; 1586 QString fullIconPath;
1587 QPixmap *pix; 1587 QPixmap *pix;
1588// #ifndef WIN32 1588// #ifndef WIN32
1589 icon = conf->readEntry(APP_KEY+category); 1589 icon = conf->readEntry(APP_KEY+category);
1590// #endif 1590// #endif
1591 bool isIconAv = false; 1591 bool isIconAv = false;
1592 if (!icon.isEmpty() && !icon.isNull()) 1592 if (!icon.isEmpty() && !icon.isNull())
1593 { 1593 {
1594 // build the full path 1594 // build the full path
1595 fullIconPath = iconPath + icon; 1595 fullIconPath = iconPath + icon;
1596 pix = new QPixmap (fullIconPath); 1596 pix = new QPixmap (fullIconPath);
1597 if (!pix->isNull()) 1597 if (!pix->isNull())
1598 { 1598 {
1599 QImage img = pix->convertToImage(); 1599 QImage img = pix->convertToImage();
1600 pix->convertFromImage(img.smoothScale(14,14)); 1600 pix->convertFromImage(img.smoothScale(14,14));
1601 c1->setIconName (icon); 1601 c1->setIconName (icon);
1602 c1->setIcon (*pix); 1602 c1->setIcon (*pix);
1603 isIconAv = true; 1603 isIconAv = true;
1604 } 1604 }
1605 } 1605 }
1606 if (!isIconAv) 1606 if (!isIconAv)
1607 { 1607 {
1608 c1->setIcon (*getPredefinedIcon(category)); 1608 c1->setIcon (*getPredefinedIcon(category));
1609 } 1609 }
1610 c1->setListItem (catI); 1610 c1->setListItem (catI);
1611 c1->initListItem(); 1611 c1->initListItem();
1612 categories.insert (c1->getCategoryName(), c1); 1612 categories.insert (c1->getCategoryName(), c1);
1613 } 1613 }
1614 1614
1615 } 1615 }
1616 f.close(); 1616 f.close();
1617 1617
1618 } 1618 }
1619 else 1619 else
1620 { 1620 {
1621 } 1621 }
1622 1622
1623} 1623}
1624 1624
1625#ifdef UNUSED 1625#ifdef UNUSED
1626void ZSafe::writeAllEntries() 1626void ZSafe::writeAllEntries()
1627{ 1627{
1628 if (filename.isEmpty()) 1628 if (filename.isEmpty())
1629 { 1629 {
1630 QMessageBox::critical( 0, tr("ZSafe"), 1630 QMessageBox::critical( 0, tr("ZSafe"),
1631 tr("<P>No document defined. You have to create a new document</P>")); 1631 tr("<P>No document defined. You have to create a new document</P>"));
1632 return; 1632 return;
1633 } 1633 }
1634 1634
1635 // open the file for writing 1635 // open the file for writing
1636 QString fn = filename + ".txt"; 1636 QString fn = filename + ".txt";
1637 QFile f( fn ); 1637 QFile f( fn );
1638 if ( !f.open( IO_WriteOnly ) ) { 1638 if ( !f.open( IO_WriteOnly ) ) {
1639#ifndef NO_OPIE 1639#ifndef NO_OPIE
1640 owarn << "Could not write to file " << fn << oendl; 1640 owarn << "Could not write to file " << fn << oendl;
1641#else 1641#else
1642 qWarning( QString("Could not write to file %1").arg(fn), 2000 ); 1642 qWarning( QString("Could not write to file %1").arg(fn), 2000 );
1643#endif 1643#endif
1644 QMessageBox::critical( 0, tr("ZSafe"), 1644 QMessageBox::critical( 0, tr("ZSafe"),
1645 tr("Could not export to text file.") ); 1645 tr("Could not export to text file.") );
1646 return; 1646 return;
1647 } 1647 }
1648 QTextStream t( &f ); 1648 QTextStream t( &f );
1649 1649
1650 QListViewItem *i; 1650 QListViewItem *i;
1651 // step through all categories 1651 // step through all categories
1652 for (i = ListView->firstChild(); 1652 for (i = ListView->firstChild();
1653 i != NULL; 1653 i != NULL;
1654 i = i->nextSibling()) 1654 i = i->nextSibling())
1655 { 1655 {
1656 // step through all subitems 1656 // step through all subitems
1657 QListViewItem *si; 1657 QListViewItem *si;
1658 for (si = i->firstChild(); 1658 for (si = i->firstChild();
1659 si != NULL; 1659 si != NULL;
1660 si = si->nextSibling()) 1660 si = si->nextSibling())
1661 { 1661 {
1662 QString oneEntry; 1662 QString oneEntry;
1663 oneEntry += "\""; 1663 oneEntry += "\"";
1664 oneEntry += i->text(0); 1664 oneEntry += i->text(0);
1665 oneEntry += "\";"; 1665 oneEntry += "\";";
1666 oneEntry += "\""; 1666 oneEntry += "\"";
1667 oneEntry += si->text(0); 1667 oneEntry += si->text(0);
1668 oneEntry += "\";"; 1668 oneEntry += "\";";
1669 oneEntry += "\""; 1669 oneEntry += "\"";
1670 oneEntry += si->text(1); 1670 oneEntry += si->text(1);
1671 oneEntry += "\";"; 1671 oneEntry += "\";";
1672 oneEntry += "\""; 1672 oneEntry += "\"";
1673 oneEntry += si->text(2); 1673 oneEntry += si->text(2);
1674 oneEntry += "\";"; 1674 oneEntry += "\";";
1675 oneEntry += "\""; 1675 oneEntry += "\"";
1676 // oneEntry += si->text(3); 1676 // oneEntry += si->text(3);
1677 QString comment = si->text(3); 1677 QString comment = si->text(3);
1678 comment.replace (QRegExp("\n"), "<br>"); 1678 comment.replace (QRegExp("\n"), "<br>");
1679 oneEntry += comment; 1679 oneEntry += comment;
1680 oneEntry += "\""; 1680 oneEntry += "\"";
1681 // owarn << oneEntry << oendl; 1681 // owarn << oneEntry << oendl;
1682 t << oneEntry << endl; 1682 t << oneEntry << endl;
1683 1683
1684 // owarn << si->text(0) << oendl; 1684 // owarn << si->text(0) << oendl;
1685 } 1685 }
1686 } 1686 }
1687 f.close(); 1687 f.close();
1688} 1688}
1689 1689
1690void ZSafe::readAllEntries() 1690void ZSafe::readAllEntries()
1691{ 1691{
1692 QString fn = filename + ".txt"; 1692 QString fn = filename + ".txt";
1693 QFile f( fn ); 1693 QFile f( fn );
1694 if ( !f.open( IO_ReadOnly ) ) 1694 if ( !f.open( IO_ReadOnly ) )
1695 { 1695 {
1696#ifndef NO_OPIE 1696#ifndef NO_OPIE
1697 owarn << "Could not read file " << fn << oendl; 1697 owarn << "Could not read file " << fn << oendl;
1698#else 1698#else
1699 qWarning( QString("Could not read file %1").arg(fn), 2000 ); 1699 qWarning( QString("Could not read file %1").arg(fn), 2000 );
1700#endif 1700#endif
1701 QMessageBox::critical( 0, tr("ZSafe"), 1701 QMessageBox::critical( 0, tr("ZSafe"),
1702 tr("Could not import text file.") ); 1702 tr("Could not import text file.") );
1703 return; 1703 return;
1704 } 1704 }
1705 1705
1706 modified = true; 1706 modified = true;
1707 1707
1708 // clear the password list 1708 // clear the password list
1709 selectedItem = NULL; 1709 selectedItem = NULL;
1710 QListViewItem *i; 1710 QListViewItem *i;
1711 // step through all categories 1711 // step through all categories
1712 for (i = ListView->firstChild(); 1712 for (i = ListView->firstChild();
1713 i != NULL; 1713 i != NULL;
1714 i = i->nextSibling()) 1714 i = i->nextSibling())
1715 { 1715 {
1716 // step through all subitems 1716 // step through all subitems
1717 QListViewItem *si; 1717 QListViewItem *si;
1718 for (si = i->firstChild(); 1718 for (si = i->firstChild();
1719 si != NULL; ) 1719 si != NULL; )
1720 // si = si->nextSibling()) 1720 // si = si->nextSibling())
1721 { 1721 {
1722 QListViewItem *_si = si; 1722 QListViewItem *_si = si;
1723 si = si->nextSibling(); 1723 si = si->nextSibling();
1724 i->takeItem(_si); // remove from view list 1724 i->takeItem(_si); // remove from view list
1725 if (_si) delete _si; 1725 if (_si) delete _si;
1726 } 1726 }
1727 } 1727 }
1728 1728
1729#ifndef NO_OPIE 1729#ifndef NO_OPIE
1730 owarn << "ReadAllEntries(): " << oendl; 1730 owarn << "ReadAllEntries(): " << oendl;
1731#else 1731#else
1732 qWarning ("ReadAllEntries(): "); 1732 qWarning ("ReadAllEntries(): ");
1733#endif 1733#endif
1734 QTextStream t(&f); 1734 QTextStream t(&f);
1735 while ( !t.eof() ) 1735 while ( !t.eof() )
1736 { 1736 {
1737 QString s = t.readLine(); 1737 QString s = t.readLine();
1738 s.replace (QRegExp("\";\""), "\"|\""); 1738 s.replace (QRegExp("\";\""), "\"|\"");
1739 // char buffer[1024]; 1739 // char buffer[1024];
1740 int len=s.length()+1; 1740 int len=s.length()+1;
1741#ifdef WIN32 1741#ifdef WIN32
1742 char buffer[512]; 1742 char buffer[512];
1743#else 1743#else
1744 char buffer[len]; 1744 char buffer[len];
1745#endif 1745#endif
1746 strcpy (buffer, s); 1746 strcpy (buffer, s);
1747 1747
1748 QString name; 1748 QString name;
1749 QString user; 1749 QString user;
1750 QString password; 1750 QString password;
1751 QString comment; 1751 QString comment;
1752 1752
1753 // separete the entries 1753 // separete the entries
1754 char *i = strtok (buffer, "|"); 1754 char *i = strtok (buffer, "|");
1755 QString category(&i[1]); 1755 QString category(&i[1]);
1756 category.truncate(category.length() -1); 1756 category.truncate(category.length() -1);
1757 1757
1758 int idx=0; 1758 int idx=0;
1759 while (i = strtok (NULL, "|")) 1759 while (i = strtok (NULL, "|"))
1760 { 1760 {
1761 switch (idx) 1761 switch (idx)
1762 { 1762 {
1763 case 0: 1763 case 0:
1764 name = &i[1]; 1764 name = &i[1];
1765 name.truncate(name.length() -1); 1765 name.truncate(name.length() -1);
1766 // name 1766 // name
1767 break; 1767 break;
1768 case 1: 1768 case 1:
1769 // user 1769 // user
1770 user = &i[1]; 1770 user = &i[1];
1771 user.truncate(user.length() -1); 1771 user.truncate(user.length() -1);
1772 break; 1772 break;
1773 case 2: 1773 case 2:
1774 // password 1774 // password
1775 password = &i[1]; 1775 password = &i[1];
1776 password.truncate(password.length() -1); 1776 password.truncate(password.length() -1);
1777 break; 1777 break;
1778 case 3: 1778 case 3:
1779 // comment 1779 // comment
1780 comment = &i[1]; 1780 comment = &i[1];
1781 comment.truncate(comment.length() -1); 1781 comment.truncate(comment.length() -1);
1782 break; 1782 break;
1783 } 1783 }
1784 idx++; 1784 idx++;
1785 } 1785 }
1786 1786
1787 Category *cat= categories.find (category); 1787 Category *cat= categories.find (category);
1788 if (cat) 1788 if (cat)
1789 { 1789 {
1790 // use the existend item 1790 // use the existend item
1791 QListViewItem *catItem = cat->getListItem(); 1791 QListViewItem *catItem = cat->getListItem();
1792 if (catItem) 1792 if (catItem)
1793 { 1793 {
1794 QListViewItem * item = new ShadedListItem( 0, catItem ); 1794 QListViewItem * item = new ShadedListItem( 0, catItem );
1795 item->setText( 0, tr( name ) ); 1795 item->setText( 0, tr( name ) );
1796 item->setText( 1, tr( user ) ); 1796 item->setText( 1, tr( user ) );
1797 item->setText( 2, tr( password ) ); 1797 item->setText( 2, tr( password ) );
1798 item->setText( 3, tr( comment ) ); 1798 item->setText( 3, tr( comment ) );
1799 1799
1800 catItem->setOpen( TRUE ); 1800 catItem->setOpen( TRUE );
1801 } 1801 }
1802 } 1802 }
1803 else 1803 else
1804 { 1804 {
1805 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1805 QListViewItem *catI = new ShadedListItem( 1, ListView );
1806 // create and insert a new item 1806 // create and insert a new item
1807 QListViewItem * item = new ShadedListItem( 0, catI ); 1807 QListViewItem * item = new ShadedListItem( 0, catI );
1808 item->setText( 0, tr( name ) ); 1808 item->setText( 0, tr( name ) );
1809 item->setText( 1, tr( user ) ); 1809 item->setText( 1, tr( user ) );
1810 item->setText( 2, tr( password ) ); 1810 item->setText( 2, tr( password ) );
1811 item->setText( 3, tr( comment ) ); 1811 item->setText( 3, tr( comment ) );
1812 1812
1813 catI->setOpen( TRUE ); 1813 catI->setOpen( TRUE );
1814 1814
1815 Category *c1 = new Category(); 1815 Category *c1 = new Category();
1816 c1->setCategoryName(category); 1816 c1->setCategoryName(category);
1817 1817
1818 QString icon; 1818 QString icon;
1819 QString fullIconPath; 1819 QString fullIconPath;
1820 QPixmap *pix; 1820 QPixmap *pix;
1821// #ifndef WIN32 1821// #ifndef WIN32
1822 icon = conf->readEntry(APP_KEY+category); 1822 icon = conf->readEntry(APP_KEY+category);
1823// #endif 1823// #endif
1824 bool isIconAv = false; 1824 bool isIconAv = false;
1825 if (!icon.isEmpty() && !icon.isNull()) 1825 if (!icon.isEmpty() && !icon.isNull())
1826 { 1826 {
1827 // build the full path 1827 // build the full path
1828 fullIconPath = iconPath + icon; 1828 fullIconPath = iconPath + icon;
1829 pix = new QPixmap (fullIconPath); 1829 pix = new QPixmap (fullIconPath);
1830 if (!pix->isNull()) 1830 if (!pix->isNull())
1831 { 1831 {
1832 QImage img = pix->convertToImage(); 1832 QImage img = pix->convertToImage();
1833 pix->convertFromImage(img.smoothScale(14,14)); 1833 pix->convertFromImage(img.smoothScale(14,14));
1834 c1->setIconName (icon); 1834 c1->setIconName (icon);
1835 c1->setIcon (*pix); 1835 c1->setIcon (*pix);
1836 isIconAv = true; 1836 isIconAv = true;
1837 } 1837 }
1838 } 1838 }
1839 if (!isIconAv) 1839 if (!isIconAv)
1840 { 1840 {
1841 c1->setIcon (*getPredefinedIcon(category)); 1841 c1->setIcon (*getPredefinedIcon(category));
1842 } 1842 }
1843 c1->setListItem (catI); 1843 c1->setListItem (catI);
1844 c1->initListItem(); 1844 c1->initListItem();
1845 categories.insert (c1->getCategoryName(), c1); 1845 categories.insert (c1->getCategoryName(), c1);
1846 } 1846 }
1847 1847
1848 } 1848 }
1849 f.close(); 1849 f.close();
1850 1850
1851} 1851}
1852#endif // UNUSED 1852#endif // UNUSED
1853 1853
1854void ZSafe::resume(int) 1854void ZSafe::resume(int)
1855{ 1855{
1856#ifndef NO_OPIE 1856#ifndef NO_OPIE
1857 owarn << "Resume" << oendl; 1857 owarn << "Resume" << oendl;
1858#endif 1858#endif
1859 // hide the main window 1859 // hide the main window
1860 1860
1861 if ( !showpwd ) 1861 if ( !showpwd )
1862 { 1862 {
1863 infoForm->hide(); 1863 infoForm->hide();
1864 // open zsafe again 1864 // open zsafe again
1865 m_password = ""; 1865 m_password = "";
1866 selectedItem = NULL; 1866 selectedItem = NULL;
1867 1867
1868 // clear the password list 1868 // clear the password list
1869 QListViewItem *i; 1869 QListViewItem *i;
1870 // step through all categories 1870 // step through all categories
1871 for (i = ListView->firstChild(); 1871 for (i = ListView->firstChild();
1872 i != NULL; 1872 i != NULL;
1873 i = i->nextSibling()) 1873 i = i->nextSibling())
1874 { 1874 {
1875 // step through all subitems 1875 // step through all subitems
1876 QListViewItem *si; 1876 QListViewItem *si;
1877 for (si = i->firstChild(); 1877 for (si = i->firstChild();
1878 si != NULL; ) 1878 si != NULL; )
1879 { 1879 {
1880 QListViewItem *_si = si; 1880 QListViewItem *_si = si;
1881 si = si->nextSibling(); 1881 si = si->nextSibling();
1882 i->takeItem(_si); // remove from view list 1882 i->takeItem(_si); // remove from view list
1883 if (_si) delete _si; 1883 if (_si) delete _si;
1884 } 1884 }
1885 } 1885 }
1886 1886
1887 // ask for password and read again 1887 // ask for password and read again
1888 openDocument(filename); 1888 openDocument(filename);
1889 } 1889 }
1890} 1890}
1891 1891
1892//--------------------------------------------- 1892//---------------------------------------------
1893 1893
1894 1894
1895bool ZSafe::openDocument(const char* _filename, const char* ) 1895bool ZSafe::openDocument(const char* _filename, const char* )
1896{ 1896{
1897 int retval; 1897 int retval;
1898 char* entry[FIELD_SIZE]; 1898 char* entry[FIELD_SIZE];
1899// #ifndef WIN32 1899// #ifndef WIN32
1900 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); 1900 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1);
1901// #else 1901// #else
1902 // int validationFlag = 1; 1902 // int validationFlag = 1;
1903// #endif 1903// #endif
1904 1904
1905 int pwdOk = 0; 1905 int pwdOk = 0;
1906 int numberOfTries = 3; 1906 int numberOfTries = 3;
1907 for (int i=0; i < numberOfTries; i++) 1907 for (int i=0; i < numberOfTries; i++)
1908 { 1908 {
1909 QFile f(_filename); 1909 QFile f(_filename);
1910 if (f.exists()) 1910 if (f.exists())
1911 { 1911 {
1912 // ask with a dialog for the password 1912 // ask with a dialog for the password
1913 if (m_password.isEmpty()) 1913 if (m_password.isEmpty())
1914 getDocPassword(tr("Enter Password")); 1914 getDocPassword(tr("Enter Password"));
1915 if (m_password.isEmpty() && validationFlag == 0) 1915 if (m_password.isEmpty() && validationFlag == 0)
1916 { 1916 {
1917#ifndef NO_OPIE 1917#ifndef NO_OPIE
1918 owarn << "Wrong password" << oendl; 1918 owarn << "Wrong password" << oendl;
1919#else 1919#else
1920 qWarning ("Wrong password"); 1920 qWarning ("Wrong password");
1921#endif 1921#endif
1922 QMessageBox::critical( 0, tr("ZSafe"), 1922 QMessageBox::critical( 0, tr("ZSafe"),
1923 tr("Wrong password.\n\nZSafe will now exit.") ); 1923 tr("Wrong password.\n\nZSafe will now exit.") );
1924 exitZs (1); 1924 exitZs (1);
1925 } 1925 }
1926 1926
1927 retval = loadInit(_filename, m_password); 1927 retval = loadInit(_filename, m_password);
1928 if (retval != PWERR_GOOD) 1928 if (retval != PWERR_GOOD)
1929 { 1929 {
1930#ifndef NO_OPIE 1930#ifndef NO_OPIE
1931 owarn << "Error loading Document" << oendl; 1931 owarn << "Error loading Document" << oendl;
1932#lese 1932#else
1933 qWarning ("Error loading Document"); 1933 qWarning ("Error loading Document");
1934#endif 1934#endif
1935 return false; 1935 return false;
1936 } 1936 }
1937 } 1937 }
1938 else 1938 else
1939 { 1939 {
1940#ifdef WIN32 1940#ifdef WIN32
1941 this->setCaption("Qt ZSafe"); 1941 this->setCaption("Qt ZSafe");
1942#else 1942#else
1943 this->setCaption("ZSafe"); 1943 this->setCaption("ZSafe");
1944#endif 1944#endif
1945 filename = ""; 1945 filename = "";
1946 return false; 1946 return false;
1947 } 1947 }
1948 1948
1949 1949
1950 // load the validation entry 1950 // load the validation entry
1951 if (validationFlag == 0) 1951 if (validationFlag == 0)
1952 { 1952 {
1953 pwdOk = 1; 1953 pwdOk = 1;
1954 break; 1954 break;
1955 } 1955 }
1956 1956
1957 retval = loadEntry(entry); 1957 retval = loadEntry(entry);
1958 if (retval == 1 && 1958 if (retval == 1 &&
1959 !strcmp (entry[0], "ZSAFECATEGORY") && 1959 !strcmp (entry[0], "ZSAFECATEGORY") &&
1960 !strcmp (entry[1], "name") && 1960 !strcmp (entry[1], "name") &&
1961 !strcmp (entry[2], "username") && 1961 !strcmp (entry[2], "username") &&
1962 !strcmp (entry[3], "password") && 1962 !strcmp (entry[3], "password") &&
1963 !strcmp (entry[4], "comment") ) 1963 !strcmp (entry[4], "comment") )
1964 { 1964 {
1965 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1965 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1966 pwdOk = 1; 1966 pwdOk = 1;
1967 break; 1967 break;
1968 } 1968 }
1969 else 1969 else
1970 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1970 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1971 fclose (fd); 1971 fclose (fd);
1972 m_password = ""; 1972 m_password = "";
1973 1973
1974 if (i < numberOfTries - 1) 1974 if (i < numberOfTries - 1)
1975 { 1975 {
1976 switch( QMessageBox::warning( this, tr("ZSafe"), 1976 switch( QMessageBox::warning( this, tr("ZSafe"),
1977 tr("Wrong password.\nEnter again?"), 1977 tr("Wrong password.\nEnter again?"),
1978 tr("&Yes"), tr("&No."), 1978 tr("&Yes"), tr("&No."),
1979 0 1979 0
1980 ) ) 1980 ) )
1981 { 1981 {
1982 case 1: // No 1982 case 1: // No
1983 exitZs (1); 1983 exitZs (1);
1984 break; 1984 break;
1985 case 0: // Yes 1985 case 0: // Yes
1986 continue; 1986 continue;
1987 } 1987 }
1988 } 1988 }
1989 } 1989 }
1990 if (pwdOk == 0) 1990 if (pwdOk == 0)
1991 { 1991 {
1992 // unset the document entry 1992 // unset the document entry
1993 conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); 1993 conf->writeEntry(APP_KEY+"document", "INVALIDPWD");
1994 if (conf) 1994 if (conf)
1995 delete conf; 1995 delete conf;
1996 1996
1997 exitZs (1); 1997 exitZs (1);
1998 } 1998 }
1999 1999
2000 2000
2001 retval = loadEntry(entry); 2001 retval = loadEntry(entry);
2002 2002
2003 int numberOfEntries=0; 2003 int numberOfEntries=0;
2004 while (retval == 1) { 2004 while (retval == 1) {
2005 2005
2006 QString category( QString::fromUtf8(entry[0]) ); 2006 QString category( QString::fromUtf8(entry[0]) );
2007 QString name( QString::fromUtf8(entry[1]) ); 2007 QString name( QString::fromUtf8(entry[1]) );
2008 QString user( QString::fromUtf8(entry[2]) ); 2008 QString user( QString::fromUtf8(entry[2]) );
2009 QString password( QString::fromUtf8(entry[3]) ); 2009 QString password( QString::fromUtf8(entry[3]) );
2010 QString comment( QString::fromUtf8(entry[4]) ); 2010 QString comment( QString::fromUtf8(entry[4]) );
2011 QString field5( QString::fromUtf8(entry[5]) ); 2011 QString field5( QString::fromUtf8(entry[5]) );
2012 QString field6( QString::fromUtf8(entry[6]) ); 2012 QString field6( QString::fromUtf8(entry[6]) );
2013 // add the subitems to the categories 2013 // add the subitems to the categories
2014 2014
2015 Category *cat= categories.find (category); 2015 Category *cat= categories.find (category);
2016 if (cat) 2016 if (cat)
2017 { 2017 {
2018 // use the existend item 2018 // use the existend item
2019 QListViewItem *catItem = cat->getListItem(); 2019 QListViewItem *catItem = cat->getListItem();
2020 if (catItem) 2020 if (catItem)
2021 { 2021 {
2022 QListViewItem * item = new ShadedListItem( 0, catItem ); 2022 QListViewItem * item = new ShadedListItem( 0, catItem );
2023 item->setText( 0, tr( name ) ); 2023 item->setText( 0, tr( name ) );
2024 item->setText( 1, tr( user ) ); 2024 item->setText( 1, tr( user ) );
2025 item->setText( 2, tr( password ) ); 2025 item->setText( 2, tr( password ) );
2026 item->setText( 3, tr( comment ) ); 2026 item->setText( 3, tr( comment ) );
2027 item->setText( 4, tr( field5 ) ); 2027 item->setText( 4, tr( field5 ) );
2028 item->setText( 5, tr( field6 ) ); 2028 item->setText( 5, tr( field6 ) );
2029 2029
2030 if (expandTree) 2030 if (expandTree)
2031 catItem->setOpen( TRUE ); 2031 catItem->setOpen( TRUE );
2032 numberOfEntries++; 2032 numberOfEntries++;
2033 } 2033 }
2034 } 2034 }
2035 else 2035 else
2036 { 2036 {
2037 QListViewItem *catI = new ShadedListItem( 1, ListView ); 2037 QListViewItem *catI = new ShadedListItem( 1, ListView );
2038 // create and insert a new item 2038 // create and insert a new item
2039 QListViewItem * item = new ShadedListItem( 0, catI ); 2039 QListViewItem * item = new ShadedListItem( 0, catI );
2040 2040
2041 item->setText( 0, tr( name ) ); 2041 item->setText( 0, tr( name ) );
2042 item->setText( 1, tr( user ) ); 2042 item->setText( 1, tr( user ) );
2043 item->setText( 2, tr( password ) ); 2043 item->setText( 2, tr( password ) );
2044 item->setText( 3, tr( comment ) ); 2044 item->setText( 3, tr( comment ) );
2045 item->setText( 4, tr( field5 ) ); 2045 item->setText( 4, tr( field5 ) );
2046 item->setText( 5, tr( field6 ) ); 2046 item->setText( 5, tr( field6 ) );
2047 2047
2048 if (expandTree) 2048 if (expandTree)
2049 catI->setOpen( TRUE ); 2049 catI->setOpen( TRUE );
2050 2050
2051 Category *c1 = new Category(); 2051 Category *c1 = new Category();
2052 c1->setCategoryName(category); 2052 c1->setCategoryName(category);
2053 2053
2054 QString icon; 2054 QString icon;
2055 QString fullIconPath; 2055 QString fullIconPath;
2056 QPixmap *pix; 2056 QPixmap *pix;
2057// #ifndef WIN32 2057// #ifndef WIN32
2058 icon = conf->readEntry(APP_KEY+category); 2058 icon = conf->readEntry(APP_KEY+category);
2059// #endif 2059// #endif
2060 bool isIconAv = false; 2060 bool isIconAv = false;
2061 if (!icon.isEmpty() && !icon.isNull()) 2061 if (!icon.isEmpty() && !icon.isNull())
2062 { 2062 {
2063 // build the full path 2063 // build the full path
2064 fullIconPath = iconPath + icon; 2064 fullIconPath = iconPath + icon;
2065 pix = new QPixmap (fullIconPath); 2065 pix = new QPixmap (fullIconPath);
2066 if (!pix->isNull()) 2066 if (!pix->isNull())
2067 { 2067 {
2068 QImage img = pix->convertToImage(); 2068 QImage img = pix->convertToImage();
2069 pix->convertFromImage(img.smoothScale(14,14)); 2069 pix->convertFromImage(img.smoothScale(14,14));
2070 c1->setIconName (icon); 2070 c1->setIconName (icon);
2071 c1->setIcon (*pix); 2071 c1->setIcon (*pix);
2072 isIconAv = true; 2072 isIconAv = true;
2073 } 2073 }
2074 } 2074 }
2075 if (!isIconAv) 2075 if (!isIconAv)
2076 { 2076 {
2077 c1->setIcon (*getPredefinedIcon(category)); 2077 c1->setIcon (*getPredefinedIcon(category));
2078 } 2078 }
2079 2079
2080 c1->setListItem (catI); 2080 c1->setListItem (catI);
2081 c1->initListItem(); 2081 c1->initListItem();
2082 categories.insert (c1->getCategoryName(), c1); 2082 categories.insert (c1->getCategoryName(), c1);
2083 numberOfEntries++; 2083 numberOfEntries++;
2084 } 2084 }
2085 2085
2086 for (int count = 0; count < FIELD_SIZE; count++) { 2086 for (int count = 0; count < FIELD_SIZE; count++) {
2087 free(entry[count]); 2087 free(entry[count]);
2088 } 2088 }
2089 retval = loadEntry(entry); 2089 retval = loadEntry(entry);
2090 if (retval == 2) { 2090 if (retval == 2) {
2091 // m_parent->slotStatusHelpMsg("Last entry loaded"); 2091 // m_parent->slotStatusHelpMsg("Last entry loaded");
2092 } 2092 }
2093 } // end while 2093 } // end while
2094 2094
2095 if (numberOfEntries == 0) 2095 if (numberOfEntries == 0)
2096 { 2096 {
2097 2097
2098 switch( QMessageBox::warning( this, tr("ZSafe"), 2098 switch( QMessageBox::warning( this, tr("ZSafe"),
2099 tr("Empty document or\nwrong password.\nContinue?"), 2099 tr("Empty document or\nwrong password.\nContinue?"),
2100 tr("&No"), tr("&Yes."), 2100 tr("&No"), tr("&Yes."),
2101 0 2101 0
2102 ) ) { 2102 ) ) {
2103 case 0: // No 2103 case 0: // No
2104 retval = loadFinalize(); 2104 retval = loadFinalize();
2105 exitZs (1); 2105 exitZs (1);
2106 break; 2106 break;
2107 case 1: // Yes 2107 case 1: // Yes
2108 break; 2108 break;
2109 } 2109 }
2110 } 2110 }
2111 2111
2112 retval = loadFinalize(); 2112 retval = loadFinalize();
2113 2113
2114 return true; 2114 return true;
2115} 2115}
2116 2116
2117int ZSafe::loadInit(const char* _filename, const char *password) 2117int ZSafe::loadInit(const char* _filename, const char *password)
2118{ 2118{
2119 unsigned int j = 0; 2119 unsigned int j = 0;
2120 unsigned int keylength=0; 2120 unsigned int keylength=0;
2121 int count=0, count2=0, count3=0; 2121 int count=0, count2=0, count3=0;
2122 unsigned char charbuf[8]; 2122 unsigned char charbuf[8];
2123 unsigned short ciphertext[4]; 2123 unsigned short ciphertext[4];
2124 char key[128]; 2124 char key[128];
2125 Krc2* krc2 = new Krc2(); 2125 Krc2* krc2 = new Krc2();
2126 2126
2127 fd = fopen (_filename, "rb"); 2127 fd = fopen (_filename, "rb");
2128 2128
2129 QFileInfo f (_filename); 2129 QFileInfo f (_filename);
2130 load_buffer_length = f.size(); 2130 load_buffer_length = f.size();
2131 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; 2131 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2;
2132 2132
2133 if (fd == NULL) 2133 if (fd == NULL)
2134 return PWERR_OPEN; 2134 return PWERR_OPEN;
2135 2135
2136 buffer = (char *)malloc(load_buffer_length); 2136 buffer = (char *)malloc(load_buffer_length);
2137 for (j = 0; password[j] != '\0'; j++) { 2137 for (j = 0; password[j] != '\0'; j++) {
2138 key[j] = password[j]; 2138 key[j] = password[j];
2139 } 2139 }
2140 keylength = j; 2140 keylength = j;
2141 krc2->rc2_expandkey (key, keylength, 128); 2141 krc2->rc2_expandkey (key, keylength, 128);
2142 2142
2143#ifndef WIN32 2143#ifndef WIN32
2144 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); 2144 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
2145#else 2145#else
2146 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2146 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2147#endif 2147#endif
2148 2148
2149 if (size < 8) 2149 if (size < 8)
2150 return PWERR_DATA; 2150 return PWERR_DATA;
2151 2151
2152 for (count = 0; count < 4; count++) { 2152 for (count = 0; count < 4; count++) {
2153 count2 = count << 1; 2153 count2 = count << 1;
2154 iv[count] = charbuf[count2] << 8; 2154 iv[count] = charbuf[count2] << 8;
2155 iv[count] += charbuf[count2 + 1]; 2155 iv[count] += charbuf[count2 + 1];
2156 } 2156 }
2157 2157
2158 size = 0; 2158 size = 0;
2159 bufferIndex = 0; 2159 bufferIndex = 0;
2160#ifndef WIN32 2160#ifndef WIN32
2161 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) { 2161 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
2162 while (count < 8) { 2162 while (count < 8) {
2163 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); 2163 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
2164#else 2164#else
2165 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { 2165 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
2166 while (count < 8) { 2166 while (count < 8) {
2167 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2167 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2168#endif 2168#endif
2169 if (count2 == 0) { 2169 if (count2 == 0) {
2170 return PWERR_DATA; 2170 return PWERR_DATA;
2171 } 2171 }
2172 count += count2; 2172 count += count2;
2173 } /* while (count < 8) */ 2173 } /* while (count < 8) */
2174 2174
2175 size += 8; 2175 size += 8;
2176 for (count2 = 0; count2 < 8; count2 += 2) { 2176 for (count2 = 0; count2 < 8; count2 += 2) {
2177 count3 = count2 >> 1; 2177 count3 = count2 >> 1;
2178 ciphertext[count3] = charbuf[count2] << 8; 2178 ciphertext[count3] = charbuf[count2] << 8;
2179 ciphertext[count3] += charbuf[count2 + 1]; 2179 ciphertext[count3] += charbuf[count2 + 1];
2180 2180
2181 plaintext[count3] = ciphertext[count3] ^ iv[count3]; 2181 plaintext[count3] = ciphertext[count3] ^ iv[count3];
2182 iv[count3] = plaintext[count3]; 2182 iv[count3] = plaintext[count3];
2183 } /* for (count2) */ 2183 } /* for (count2) */
2184 2184
2185 krc2->rc2_decrypt (plaintext); 2185 krc2->rc2_decrypt (plaintext);
2186 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); 2186 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
2187 bufferIndex += 8; 2187 bufferIndex += 8;
2188 buffer[bufferIndex + 1] = '\0'; 2188 buffer[bufferIndex + 1] = '\0';
2189 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ 2189 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
2190 size -= buffer[size - 1]; 2190 size -= buffer[size - 1];
2191 lastcount = 0; 2191 lastcount = 0;
2192 2192
2193 /* This will point to the starting index */ 2193 /* This will point to the starting index */
2194 bufferIndex = 0; 2194 bufferIndex = 0;
2195 return PWERR_GOOD; 2195 return PWERR_GOOD;
2196} 2196}
2197 2197
2198int ZSafe::loadEntry(char *entry[FIELD_SIZE]) 2198int ZSafe::loadEntry(char *entry[FIELD_SIZE])
2199{ 2199{
2200 /* Strip off PKCS 5 padding 2200 /* Strip off PKCS 5 padding
2201 * Should check to make sure it's good here 2201 * Should check to make sure it's good here
2202 */ 2202 */
2203 int count, count1=0; 2203 int count, count1=0;
2204 2204
2205 for (count = lastcount; count < size; count++) { 2205 for (count = lastcount; count < size; count++) {
2206 if ((unsigned char) (buffer[count]) == 255) { 2206 if ((unsigned char) (buffer[count]) == 255) {
2207 if (buffer[bufferIndex] == '\0') { 2207 if (buffer[bufferIndex] == '\0') {
2208 bufferIndex++; 2208 bufferIndex++;
2209 } 2209 }
2210 entry[count1] = (char *) malloc (count - bufferIndex + 1); 2210 entry[count1] = (char *) malloc (count - bufferIndex + 1);
2211 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex); 2211 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex);
2212 entry[count1][count - bufferIndex] = '\0'; 2212 entry[count1][count - bufferIndex] = '\0';
2213 count++; 2213 count++;
2214 bufferIndex = count; 2214 bufferIndex = count;
2215 count1++; 2215 count1++;
2216 if (count1 == FIELD_SIZE) { 2216 if (count1 == FIELD_SIZE) {
2217 lastcount = count; 2217 lastcount = count;
2218 return 1; 2218 return 1;
2219 } 2219 }
2220 } /* if ((unsigned char) (buffer[count]) == 255) */ 2220 } /* if ((unsigned char) (buffer[count]) == 255) */
2221 } /* for (count = 0; count < size; count++) */ 2221 } /* for (count = 0; count < size; count++) */
2222 2222
2223 return 2; 2223 return 2;
2224} 2224}
2225 2225
2226int ZSafe::loadFinalize(void) 2226int ZSafe::loadFinalize(void)
2227{ 2227{
2228 fclose (fd); 2228 fclose (fd);
2229 if (buffer) free(buffer); 2229 if (buffer) free(buffer);
2230 return PWERR_GOOD; 2230 return PWERR_GOOD;
2231} 2231}
2232 2232
2233bool ZSafe::saveDocument(const char* _filename, 2233bool ZSafe::saveDocument(const char* _filename,
2234 bool withPwd, 2234 bool withPwd,
2235 const char* ) 2235 const char* )
2236{ 2236{
2237 if (filename.isEmpty()) 2237 if (filename.isEmpty())
2238 { 2238 {
2239 QMessageBox::critical( 0, tr("ZSafe"), 2239 QMessageBox::critical( 0, tr("ZSafe"),
2240 tr("No document defined.\nYou have to create a new document")); 2240 tr("No document defined.\nYou have to create a new document"));
2241 return false; 2241 return false;
2242 } 2242 }
2243 2243
2244 // if (m_password.isEmpty()) 2244 // if (m_password.isEmpty())
2245 // withPwd = true; // the document must be saved with a valid password 2245 // withPwd = true; // the document must be saved with a valid password
2246 if (withPwd) 2246 if (withPwd)
2247 { 2247 {
2248 bool pwdOk = FALSE; 2248 bool pwdOk = FALSE;
2249 while (!pwdOk) 2249 while (!pwdOk)
2250 { 2250 {
2251 getDocPassword(tr("Enter Password")); 2251 getDocPassword(tr("Enter Password"));
2252 if (m_password.isEmpty()) 2252 if (m_password.isEmpty())
2253 { 2253 {
2254 2254
2255 QMessageBox::critical( 0, tr("ZSafe"), 2255 QMessageBox::critical( 0, tr("ZSafe"),
2256 tr("Password is empty.\nPlease enter again.")); 2256 tr("Password is empty.\nPlease enter again."));
2257 continue; 2257 continue;
2258 } 2258 }
2259 2259
2260 QString firstPasswd = m_password; 2260 QString firstPasswd = m_password;
2261 2261
2262 getDocPassword(tr("Reenter Password")); 2262 getDocPassword(tr("Reenter Password"));
2263 if (m_password.isEmpty()) 2263 if (m_password.isEmpty())
2264 { 2264 {
2265 QMessageBox::critical( 0, tr("ZSafe"), 2265 QMessageBox::critical( 0, tr("ZSafe"),
2266 tr("Password is empty.\nPlease enter again.")); 2266 tr("Password is empty.\nPlease enter again."));
2267 continue; 2267 continue;
2268 } 2268 }
2269 if (firstPasswd != m_password) 2269 if (firstPasswd != m_password)
2270 { 2270 {
2271 2271
2272 QMessageBox::critical( 0, tr("ZSafe"), 2272 QMessageBox::critical( 0, tr("ZSafe"),
2273 tr("Passwords must be identical.\nPlease enter again.")); 2273 tr("Passwords must be identical.\nPlease enter again."));
2274 continue; 2274 continue;
2275 } 2275 }
2276 pwdOk = TRUE; 2276 pwdOk = TRUE;
2277 modified = false; 2277 modified = false;
2278 } 2278 }
2279 } 2279 }
2280 else if (modified) 2280 else if (modified)
2281 { 2281 {
2282 QString fns(_filename); 2282 QString fns(_filename);
2283 fns = fns.right (fns.length() - fns.findRev ('/') - 1); 2283 fns = fns.right (fns.length() - fns.findRev ('/') - 1);
2284 switch( QMessageBox::information( this, tr("ZSafe"), 2284 switch( QMessageBox::information( this, tr("ZSafe"),
2285 tr("Do you want to save ") + fns + tr("\nbefore continuing?"), 2285 tr("Do you want to save ") + fns + tr("\nbefore continuing?"),
2286 tr("&Save"), 2286 tr("&Save"),
2287 tr("&Don't Save"), 2287 tr("&Don't Save"),
2288 0 // Enter == button 0 2288 0 // Enter == button 0
2289 ) ) 2289 ) )
2290 { // Escape == button 2 2290 { // Escape == button 2
2291 case 0: // Save clicked, Alt-S or Enter pressed. 2291 case 0: // Save clicked, Alt-S or Enter pressed.
2292 modified = false; 2292 modified = false;
2293 break; 2293 break;
2294 case 1: // Don't Save clicked or Alt-D pressed 2294 case 1: // Don't Save clicked or Alt-D pressed
2295 modified = false; 2295 modified = false;
2296 return true; 2296 return true;
2297 } 2297 }
2298 } 2298 }
2299 modified = false; 2299 modified = false;
2300 2300
2301 if (m_password.isEmpty()) 2301 if (m_password.isEmpty())
2302 return false; 2302 return false;
2303 2303
2304 int retval = saveInit(_filename, m_password); 2304 int retval = saveInit(_filename, m_password);
2305 // int retval = saveInit(_filename, "test"); 2305 // int retval = saveInit(_filename, "test");
2306 if (retval != PWERR_GOOD) { 2306 if (retval != PWERR_GOOD) {
2307 return false; 2307 return false;
2308 } 2308 }
2309 2309
2310 char* entry[FIELD_SIZE]; 2310 char* entry[FIELD_SIZE];
2311 2311
2312 // save the validation entry 2312 // save the validation entry
2313 { 2313 {
2314 int i=0; 2314 int i=0;
2315 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1); 2315 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1);
2316 strcpy(entry[i++], "ZSAFECATEGORY"); 2316 strcpy(entry[i++], "ZSAFECATEGORY");
2317 entry[i] = (char*)malloc(strlen("name")+1); 2317 entry[i] = (char*)malloc(strlen("name")+1);
2318 strcpy(entry[i++], "name"); 2318 strcpy(entry[i++], "name");
2319 entry[i] = (char*)malloc(strlen("username")+1); 2319 entry[i] = (char*)malloc(strlen("username")+1);
2320 strcpy(entry[i++], "username"); 2320 strcpy(entry[i++], "username");
2321 entry[i] = (char*)malloc(strlen("password")+1); 2321 entry[i] = (char*)malloc(strlen("password")+1);
2322 strcpy(entry[i++], "password"); 2322 strcpy(entry[i++], "password");
2323 entry[i] = (char*)malloc(strlen("comment")+1); 2323 entry[i] = (char*)malloc(strlen("comment")+1);
2324 strcpy(entry[i++], "comment"); 2324 strcpy(entry[i++], "comment");
2325 2325
2326 entry[i] = (char*)malloc(strlen("field5")+1); 2326 entry[i] = (char*)malloc(strlen("field5")+1);
2327 strcpy(entry[i++], "field5"); 2327 strcpy(entry[i++], "field5");
2328 entry[i] = (char*)malloc(strlen("field6")+1); 2328 entry[i] = (char*)malloc(strlen("field6")+1);
2329 strcpy(entry[i++], "field6"); 2329 strcpy(entry[i++], "field6");
2330 2330
2331 retval = saveEntry(entry); 2331 retval = saveEntry(entry);
2332 for (int z=0; z<i; z++) free(entry[z]); 2332 for (int z=0; z<i; z++) free(entry[z]);
2333 if (retval == PWERR_DATA) { 2333 if (retval == PWERR_DATA) {
2334#ifndef NO_OPIE 2334#ifndef NO_OPIE
2335 owarn << "1: Error writing file, contents not saved" << oendl; 2335 owarn << "1: Error writing file, contents not saved" << oendl;
2336#else 2336#else
2337 qWarning("1: Error writing file, contents not saved"); 2337 qWarning("1: Error writing file, contents not saved");
2338#endif 2338#endif
2339 saveFinalize(); 2339 saveFinalize();
2340 return false; 2340 return false;
2341 } 2341 }
2342// #ifndef WIN32 2342// #ifndef WIN32
2343 conf->writeEntry(APP_KEY+"valzsafe", 1); 2343 conf->writeEntry(APP_KEY+"valzsafe", 1);
2344// #endif 2344// #endif
2345 saveConf(); 2345 saveConf();
2346 } 2346 }
2347 2347
2348 QListViewItem *i; 2348 QListViewItem *i;
2349 // step through all categories 2349 // step through all categories
2350 for (i = ListView->firstChild(); 2350 for (i = ListView->firstChild();
2351 i != NULL; 2351 i != NULL;
2352 i = i->nextSibling()) 2352 i = i->nextSibling())
2353 { 2353 {
2354 // step through all subitems 2354 // step through all subitems
2355 QListViewItem *si; 2355 QListViewItem *si;
2356 for (si = i->firstChild(); 2356 for (si = i->firstChild();
2357 si != NULL; 2357 si != NULL;
2358 si = si->nextSibling()) 2358 si = si->nextSibling())
2359 { 2359 {
2360 int j=0; 2360 int j=0;
2361 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1); 2361 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1);
2362 strcpy(entry[j++], i->text(0).utf8()); 2362 strcpy(entry[j++], i->text(0).utf8());
2363 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1); 2363 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1);
2364 strcpy(entry[j++], si->text(0).utf8()); 2364 strcpy(entry[j++], si->text(0).utf8());
2365 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1); 2365 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1);
2366 strcpy(entry[j++], si->text(1).utf8()); 2366 strcpy(entry[j++], si->text(1).utf8());
2367 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1); 2367 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1);
2368 strcpy(entry[j++], si->text(2).utf8()); 2368 strcpy(entry[j++], si->text(2).utf8());
2369 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1); 2369 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1);
2370 strcpy(entry[j++], si->text(3).utf8()); 2370 strcpy(entry[j++], si->text(3).utf8());
2371 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1); 2371 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1);
2372 strcpy(entry[j++], si->text(4).utf8()); 2372 strcpy(entry[j++], si->text(4).utf8());
2373 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1); 2373 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1);
2374 strcpy(entry[j++], si->text(5).utf8()); 2374 strcpy(entry[j++], si->text(5).utf8());
2375 2375
2376 retval = saveEntry(entry); 2376 retval = saveEntry(entry);
2377 for (int z=0; z<j; z++) 2377 for (int z=0; z<j; z++)
2378 { 2378 {
2379 free(entry[z]); 2379 free(entry[z]);
2380 } 2380 }
2381 if (retval == PWERR_DATA) { 2381 if (retval == PWERR_DATA) {
2382#ifndef NO_OPIE 2382#ifndef NO_OPIE
2383 owarn << "1: Error writing file, contents not saved" << oendl; 2383 owarn << "1: Error writing file, contents not saved" << oendl;
2384#else 2384#else
2385 qWarning("1: Error writing file, contents not saved"); 2385 qWarning("1: Error writing file, contents not saved");
2386#endif 2386#endif
2387 saveFinalize(); 2387 saveFinalize();
2388 return false; 2388 return false;
2389 } 2389 }
2390 2390
2391 } 2391 }
2392 } 2392 }
2393 2393
2394 if (saveFinalize() == PWERR_DATA) { 2394 if (saveFinalize() == PWERR_DATA) {
2395#ifndef NO_OPIE 2395#ifndef NO_OPIE
2396 owarn << "2: Error writing file, contents not saved" << oendl; 2396 owarn << "2: Error writing file, contents not saved" << oendl;
2397#else 2397#else
2398 qWarning("2: Error writing file, contents not saved"); 2398 qWarning("2: Error writing file, contents not saved");
2399#endif 2399#endif
2400 return false; 2400 return false;
2401 } else { 2401 } else {
2402#ifndef DESKTOP 2402#ifndef DESKTOP
2403 Global::statusMessage (tr("Password file saved.")); 2403 Global::statusMessage (tr("Password file saved."));
2404#endif 2404#endif
2405 modified = false; 2405 modified = false;
2406 return true; 2406 return true;
2407 } 2407 }
2408} 2408}
2409 2409
2410PasswordForm *newPwdDialog; 2410PasswordForm *newPwdDialog;
2411bool newPwdDialogResult = false; 2411bool newPwdDialogResult = false;
2412void ZSafe::setPasswordDialogDone() 2412void ZSafe::setPasswordDialogDone()
2413{ 2413{
2414 newPwdDialogResult = true; 2414 newPwdDialogResult = true;
2415 newPwdDialog->close(); 2415 newPwdDialog->close();
2416} 2416}
2417 2417
2418void ZSafe::getDocPassword(QString title) 2418void ZSafe::getDocPassword(QString title)
2419{ 2419{
2420#ifndef NO_OPIE 2420#ifndef NO_OPIE
2421 owarn << "getDocPassword" << oendl; 2421 owarn << "getDocPassword" << oendl;
2422#endif 2422#endif
2423 // open the 'Password' dialog 2423 // open the 'Password' dialog
2424 PasswordForm *dialog = new PasswordForm(this, title, TRUE); 2424 PasswordForm *dialog = new PasswordForm(this, title, TRUE);
2425 newPwdDialog = dialog; 2425 newPwdDialog = dialog;
2426 newPwdDialogResult = false; 2426 newPwdDialogResult = false;
2427 2427
2428 QPixmap image0( ( const char** ) zsafe_xpm ); 2428 QPixmap image0( ( const char** ) zsafe_xpm );
2429 dialog->setIcon( image0); 2429 dialog->setIcon( image0);
2430 2430
2431 connect( dialog->PasswordField, SIGNAL( returnPressed() ), 2431 connect( dialog->PasswordField, SIGNAL( returnPressed() ),
2432 this, SLOT( setPasswordDialogDone() ) ); 2432 this, SLOT( setPasswordDialogDone() ) );
2433 2433
2434 // CS: !!! 2434 // CS: !!!
2435 // int pos = filename.findRev ('/'); 2435 // int pos = filename.findRev ('/');
2436 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 2436 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
2437#ifdef WIN32 2437#ifdef WIN32
2438 dialog->setCaption("Qt " + ti); 2438 dialog->setCaption("Qt " + ti);
2439#else 2439#else
2440 dialog->setCaption(ti); 2440 dialog->setCaption(ti);
2441#endif 2441#endif
2442 // dialog->setCaption(title); 2442 // dialog->setCaption(title);
2443 2443
2444 dialog->PasswordField->setFocus(); 2444 dialog->PasswordField->setFocus();
2445 DialogCode result = (DialogCode) dialog->exec(); 2445 DialogCode result = (DialogCode) dialog->exec();
2446#ifdef DESKTOP 2446#ifdef DESKTOP
2447 result = Accepted; 2447 result = Accepted;
2448#endif 2448#endif
2449 2449
2450 QString password; 2450 QString password;
2451 if (result == Accepted || newPwdDialogResult) 2451 if (result == Accepted || newPwdDialogResult)
2452 { 2452 {
2453 m_password = dialog->PasswordField->text(); 2453 m_password = dialog->PasswordField->text();
2454 } 2454 }
2455 else 2455 else
2456 { 2456 {
2457 exitZs (1); 2457 exitZs (1);
2458 } 2458 }
2459} 2459}
2460 2460
2461int ZSafe::saveInit(const char *_filename, const char *password) 2461int ZSafe::saveInit(const char *_filename, const char *password)
2462{ 2462{
2463 char key[128]; 2463 char key[128];
2464 unsigned int j = 0; 2464 unsigned int j = 0;
2465 unsigned int keylength; 2465 unsigned int keylength;
2466 // int val; 2466 // int val;
2467 int count2; 2467 int count2;
2468 Krc2* krc2 = new Krc2(); 2468 Krc2* krc2 = new Krc2();
2469 2469
2470 /* first we should check the permissions of the filename */ 2470 /* first we should check the permissions of the filename */
2471/* 2471/*
2472 if (QFile::exists(_filename)) { 2472 if (QFile::exists(_filename)) {
2473 val = checkFile(_filename); 2473 val = checkFile(_filename);
2474 if (val != PWERR_GOOD) 2474 if (val != PWERR_GOOD)
2475 return val; 2475 return val;
2476 } else 2476 } else
2477 { 2477 {
2478 val = creat (_filename, (S_IRUSR | S_IWUSR)); 2478 val = creat (_filename, (S_IRUSR | S_IWUSR));
2479 if (val == -1) 2479 if (val == -1)
2480 return PWERR_OPEN; 2480 return PWERR_OPEN;
2481 else 2481 else
2482 close(val); 2482 close(val);
2483 } 2483 }
2484*/ 2484*/
2485 QFileInfo f (_filename); 2485 QFileInfo f (_filename);
2486 save_buffer_length = f.size(); 2486 save_buffer_length = f.size();
2487 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; 2487 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024;
2488 2488
2489 fd = fopen (_filename, "wb"); 2489 fd = fopen (_filename, "wb");
2490 if (fd == NULL) 2490 if (fd == NULL)
2491 return PWERR_OPEN; 2491 return PWERR_OPEN;
2492 2492
2493 buffer = (char*)malloc(save_buffer_length); 2493 buffer = (char*)malloc(save_buffer_length);
2494 2494
2495 /* make the key ready */ 2495 /* make the key ready */
2496 for (j = 0; password[j] != '\0'; j++) { 2496 for (j = 0; password[j] != '\0'; j++) {
2497 key[j] = password[j]; 2497 key[j] = password[j];
2498 } 2498 }
2499 keylength = j; 2499 keylength = j;
2500 krc2->rc2_expandkey (key, keylength, 128); 2500 krc2->rc2_expandkey (key, keylength, 128);
2501 2501
2502 /* First, we make the IV */ 2502 /* First, we make the IV */
2503 for (count2 = 0; count2 < 4; count2++) { 2503 for (count2 = 0; count2 < 4; count2++) {
2504 iv[count2] = rand (); 2504 iv[count2] = rand ();
2505 putc ((unsigned char) (iv[count2] >> 8), fd); 2505 putc ((unsigned char) (iv[count2] >> 8), fd);
2506 putc ((unsigned char) (iv[count2] & 0xff), fd); 2506 putc ((unsigned char) (iv[count2] & 0xff), fd);
2507 } 2507 }
2508 2508
2509 bufferIndex = 0; 2509 bufferIndex = 0;
2510 return PWERR_GOOD; 2510 return PWERR_GOOD;
2511} 2511}
2512 2512
2513 2513
2514int ZSafe::saveEntry(char *entry[FIELD_SIZE]) 2514int ZSafe::saveEntry(char *entry[FIELD_SIZE])
2515{ 2515{
2516 char *text1; 2516 char *text1;
2517 int count2, count3; 2517 int count2, count3;
2518 unsigned short ciphertext[4]; 2518 unsigned short ciphertext[4];
2519 Krc2* krc2 = new Krc2(); 2519 Krc2* krc2 = new Krc2();
2520 2520
2521 buffer = (char*)memset(buffer, '\0', save_buffer_length); 2521 buffer = (char*)memset(buffer, '\0', save_buffer_length);
2522 2522
2523 for (count2 = 0; count2 < FIELD_SIZE; count2++) { 2523 for (count2 = 0; count2 < FIELD_SIZE; count2++) {
2524 text1 = entry[count2]; 2524 text1 = entry[count2];
2525 if (strlen (text1) == 0) { 2525 if (strlen (text1) == 0) {
2526 strncat(buffer, " ", strlen(" ")); 2526 strncat(buffer, " ", strlen(" "));
2527 } else { 2527 } else {
2528 strncat(buffer, text1, strlen(text1)); 2528 strncat(buffer, text1, strlen(text1));
2529 } 2529 }
2530 /* Use 255 as the marker. \n is too tough to test for */ 2530 /* Use 255 as the marker. \n is too tough to test for */
2531 buffer[strlen (buffer)] = 255; 2531 buffer[strlen (buffer)] = 255;
2532 } /*for (count2 = 0; count2 < 5; count2++)*/ 2532 } /*for (count2 = 0; count2 < 5; count2++)*/
2533 count2 = 0; 2533 count2 = 0;
2534 /* I'm using CBC mode and encrypting the data straight from top down. 2534 /* I'm using CBC mode and encrypting the data straight from top down.
2535 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. 2535 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
2536 * PKCS 5 padding (explained at the code section 2536 * PKCS 5 padding (explained at the code section
2537 */ 2537 */
2538 while (count2 < (int)strlen (buffer)) { 2538 while (count2 < (int)strlen (buffer)) {
2539#ifndef WORDS_BIGENDIAN 2539#ifndef WORDS_BIGENDIAN
2540 plaintext[bufferIndex] = buffer[count2 + 1] << 8; 2540 plaintext[bufferIndex] = buffer[count2 + 1] << 8;
2541 plaintext[bufferIndex] += buffer[count2] & 0xff; 2541 plaintext[bufferIndex] += buffer[count2] & 0xff;
2542#endif 2542#endif
2543#ifdef WORDS_BIGENDIAN 2543#ifdef WORDS_BIGENDIAN
2544 plaintext[bufferIndex] = buffer[count2] << 8; 2544 plaintext[bufferIndex] = buffer[count2] << 8;
2545 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; 2545 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
2546#endif 2546#endif
2547 bufferIndex++; 2547 bufferIndex++;
2548 if (bufferIndex == 4) { 2548 if (bufferIndex == 4) {
2549 krc2->rc2_encrypt (plaintext); 2549 krc2->rc2_encrypt (plaintext);
2550 2550
2551 for (count3 = 0; count3 < 4; count3++) { 2551 for (count3 = 0; count3 < 4; count3++) {
2552 ciphertext[count3] = iv[count3] ^ plaintext[count3]; 2552 ciphertext[count3] = iv[count3] ^ plaintext[count3];
2553 2553
2554 /* Now store the ciphertext as the iv */ 2554 /* Now store the ciphertext as the iv */
2555 iv[count3] = plaintext[count3]; 2555 iv[count3] = plaintext[count3];
2556 2556
2557 /* reset the buffer index */ 2557 /* reset the buffer index */
2558 bufferIndex = 0; 2558 bufferIndex = 0;
2559 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; 2559 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA;
2560 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; 2560 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA;
2561 } /*for (count3 = 0; count3 < 5; count3++)*/ 2561 } /*for (count3 = 0; count3 < 5; count3++)*/
2562 } /*if (bufferIndex == 5)*/ 2562 } /*if (bufferIndex == 5)*/
2563 /* increment a short, not a byte */ 2563 /* increment a short, not a byte */
2564 count2 += 2; 2564 count2 += 2;
2565 } /*while (count2 < strlen (buffer))*/ 2565 } /*while (count2 < strlen (buffer))*/
2566 int ret = PWERR_GOOD; 2566 int ret = PWERR_GOOD;
2567 return ret; 2567 return ret;
2568} 2568}
2569 2569
2570int ZSafe::saveFinalize(void) 2570int ZSafe::saveFinalize(void)
2571{ 2571{
2572 int count1, retval = PWERR_GOOD; 2572 int count1, retval = PWERR_GOOD;
2573 unsigned short ciphertext[4]; 2573 unsigned short ciphertext[4];
2574 Krc2* krc2 = new Krc2(); 2574 Krc2* krc2 = new Krc2();
2575 2575
2576 /* Tack on the PKCS 5 padding 2576 /* Tack on the PKCS 5 padding
2577 * How it works is we fill up the last n bytes with the value n 2577 * How it works is we fill up the last n bytes with the value n
2578 * 2578 *
2579 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left 2579 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
2580 * over, leaving us 3 short, so we fill it in with 3's. 2580 * over, leaving us 3 short, so we fill it in with 3's.
2581 * 2581 *
2582 * If we come out even, we fill it with 8 8s 2582 * If we come out even, we fill it with 8 8s
2583 * 2583 *
2584 * um, except that in this instance we are using 4 shorts instead of 8 bytes. 2584 * um, except that in this instance we are using 4 shorts instead of 8 bytes.
2585 * so, half everything 2585 * so, half everything
2586 */ 2586 */
2587 for (count1 = bufferIndex; count1 < 4; count1++) { 2587 for (count1 = bufferIndex; count1 < 4; count1++) {
2588 plaintext[count1] = (4 - bufferIndex); 2588 plaintext[count1] = (4 - bufferIndex);
2589 } 2589 }
2590 krc2->rc2_encrypt (plaintext); 2590 krc2->rc2_encrypt (plaintext);
2591 for (count1 = 0; count1 < 4; count1++) { 2591 for (count1 = 0; count1 < 4; count1++) {
2592 ciphertext[count1] = iv[count1] ^ plaintext[count1]; 2592 ciphertext[count1] = iv[count1] ^ plaintext[count1];
2593 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; 2593 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA;
2594 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; 2594 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA;
2595 } 2595 }
2596 2596
2597 fclose (fd); 2597 fclose (fd);
2598 free(buffer); 2598 free(buffer);
2599 return retval; 2599 return retval;
2600} 2600}
2601 2601
2602void ZSafe::quitMe () 2602void ZSafe::quitMe ()
2603{ 2603{
2604#ifndef NO_OPIE 2604#ifndef NO_OPIE
2605 owarn << "QUIT..." << oendl; 2605 owarn << "QUIT..." << oendl;
2606#endif 2606#endif
2607 2607
2608 if (modified) 2608 if (modified)
2609 { 2609 {
2610 switch( QMessageBox::information( this, tr("ZSafe"), 2610 switch( QMessageBox::information( this, tr("ZSafe"),
2611 tr("Do you want to save\nbefore exiting?"), 2611 tr("Do you want to save\nbefore exiting?"),
2612 tr("&Save"), 2612 tr("&Save"),
2613 tr("S&ave with\nnew\npassword"), 2613 tr("S&ave with\nnew\npassword"),
2614 tr("&Don't Save"), 2614 tr("&Don't Save"),
2615 0 // Enter == button 0 2615 0 // Enter == button 0
2616 ) ) 2616 ) )
2617 { // Escape == button 2 2617 { // Escape == button 2
2618 case 0: // Save clicked, Alt-S or Enter pressed. 2618 case 0: // Save clicked, Alt-S or Enter pressed.
2619 // save 2619 // save
2620 modified = false; 2620 modified = false;
2621 saveDocument(filename, FALSE); 2621 saveDocument(filename, FALSE);
2622 exitZs (1); 2622 exitZs (1);
2623 break; 2623 break;
2624 case 1: // 2624 case 1: //
2625 // Save with new password 2625 // Save with new password
2626 modified = false; 2626 modified = false;
2627 saveDocument(filename, TRUE); 2627 saveDocument(filename, TRUE);
2628 exitZs (1); 2628 exitZs (1);
2629 break; 2629 break;
2630 case 2: // Don't Save clicked or Alt-D pressed 2630 case 2: // Don't Save clicked or Alt-D pressed
2631 // don't save but exitZs 2631 // don't save but exitZs
2632 exitZs (1); 2632 exitZs (1);
2633 break; 2633 break;
2634 } 2634 }
2635 } 2635 }
2636 exitZs (1); 2636 exitZs (1);
2637 2637
2638} 2638}
2639 2639
2640void ZSafe::categoryFieldActivated( const QString& category) 2640void ZSafe::categoryFieldActivated( const QString& category)
2641{ 2641{
2642 if (categoryDialog) 2642 if (categoryDialog)
2643 setCategoryDialogFields(categoryDialog, category); 2643 setCategoryDialogFields(categoryDialog, category);
2644} 2644}
2645 2645
2646void ZSafe::addCategory() 2646void ZSafe::addCategory()
2647{ 2647{
2648 if (filename.isEmpty()) 2648 if (filename.isEmpty())
2649 { 2649 {
2650 QMessageBox::critical( 0, tr("ZSafe"), 2650 QMessageBox::critical( 0, tr("ZSafe"),
2651 tr("No document defined.\nYou have to create a new document")); 2651 tr("No document defined.\nYou have to create a new document"));
2652 return; 2652 return;
2653 } 2653 }
2654 else 2654 else
2655 { 2655 {
2656 // open the 'Category' dialog 2656 // open the 'Category' dialog
2657 bool initIcons = false; 2657 bool initIcons = false;
2658 // open the 'Category' dialog 2658 // open the 'Category' dialog
2659 CategoryDialog *dialog; 2659 CategoryDialog *dialog;
2660 if (categoryDialog) 2660 if (categoryDialog)
2661 { 2661 {
2662 dialog = categoryDialog; 2662 dialog = categoryDialog;
2663 } 2663 }
2664 else 2664 else
2665 { 2665 {
2666 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 2666 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
2667#ifdef WIN32 2667#ifdef WIN32
2668 categoryDialog->setCaption ("Qt " + tr("Category")); 2668 categoryDialog->setCaption ("Qt " + tr("Category"));
2669#endif 2669#endif
2670 dialog = categoryDialog; 2670 dialog = categoryDialog;
2671 connect( dialog->CategoryField, 2671 connect( dialog->CategoryField,
2672 SIGNAL( activated(const QString&)), 2672 SIGNAL( activated(const QString&)),
2673 this, SLOT( categoryFieldActivated(const QString&) ) ); 2673 this, SLOT( categoryFieldActivated(const QString&) ) );
2674 initIcons = true; 2674 initIcons = true;
2675 } 2675 }
2676 2676
2677#ifdef DESKTOP 2677#ifdef DESKTOP
2678#ifndef WIN32 2678#ifndef WIN32
2679 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 2679 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
2680#else 2680#else
2681 // read all categories from the config file and store 2681 // read all categories from the config file and store
2682 // into a list 2682 // into a list
2683 QFile f (cfgFile); 2683 QFile f (cfgFile);
2684 QStringList list; 2684 QStringList list;
2685 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2685 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2686 QTextStream t( &f ); // use a text stream 2686 QTextStream t( &f ); // use a text stream
2687 QString s; 2687 QString s;
2688 int n = 1; 2688 int n = 1;
2689 while ( !t.eof() ) { // until end of file... 2689 while ( !t.eof() ) { // until end of file...
2690 s = t.readLine(); // line of text excluding '\n' 2690 s = t.readLine(); // line of text excluding '\n'
2691 list.append(s); 2691 list.append(s);
2692 } 2692 }
2693 f.close(); 2693 f.close();
2694 } 2694 }
2695#endif 2695#endif
2696#else 2696#else
2697 // read all categories from the config file and store 2697 // read all categories from the config file and store
2698 // into a list 2698 // into a list
2699 QFile f (cfgFile); 2699 QFile f (cfgFile);
2700 QStringList list; 2700 QStringList list;
2701 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2701 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2702 QTextStream t( &f ); // use a text stream 2702 QTextStream t( &f ); // use a text stream
2703 QString s; 2703 QString s;
2704 while ( !t.eof() ) { // until end of file... 2704 while ( !t.eof() ) { // until end of file...
2705 s = t.readLine(); // line of text excluding '\n' 2705 s = t.readLine(); // line of text excluding '\n'
2706 list.append(s); 2706 list.append(s);
2707 } 2707 }
2708 f.close(); 2708 f.close();
2709 } 2709 }
2710#endif 2710#endif
2711 QStringList::Iterator it = list.begin(); 2711 QStringList::Iterator it = list.begin();
2712 QString categ; 2712 QString categ;
2713 QString firstCategory; 2713 QString firstCategory;
2714 dialog->CategoryField->clear(); // remove all items 2714 dialog->CategoryField->clear(); // remove all items
2715 while( it != list.end() ) 2715 while( it != list.end() )
2716 { 2716 {
2717 QString *cat = new QString (*it); 2717 QString *cat = new QString (*it);
2718 if (cat->contains("-field1", FALSE)) 2718 if (cat->contains("-field1", FALSE))
2719 { 2719 {
2720#ifdef DESKTOP 2720#ifdef DESKTOP
2721#ifndef WIN32 2721#ifndef WIN32
2722 categ = cat->section ("-field1", 0, 0); 2722 categ = cat->section ("-field1", 0, 0);
2723#else 2723#else
2724 int pos = cat->find ("-field1"); 2724 int pos = cat->find ("-field1");
2725 categ = cat->left (pos); 2725 categ = cat->left (pos);
2726#endif 2726#endif
2727#else 2727#else
2728 int pos = cat->find ("-field1"); 2728 int pos = cat->find ("-field1");
2729 cat->truncate(pos); 2729 cat->truncate(pos);
2730 categ = *cat; 2730 categ = *cat;
2731#endif 2731#endif
2732 if (!categ.isEmpty()) 2732 if (!categ.isEmpty())
2733 { 2733 {
2734 dialog->CategoryField->insertItem (categ, -1); 2734 dialog->CategoryField->insertItem (categ, -1);
2735 if (firstCategory.isEmpty()) 2735 if (firstCategory.isEmpty())
2736 firstCategory = categ; 2736 firstCategory = categ;
2737 } 2737 }
2738 } 2738 }
2739 ++it; 2739 ++it;
2740 } 2740 }
2741 2741
2742 2742
2743 if (firstCategory.isEmpty()) 2743 if (firstCategory.isEmpty())
2744 setCategoryDialogFields(dialog); 2744 setCategoryDialogFields(dialog);
2745 else 2745 else
2746 setCategoryDialogFields(dialog, firstCategory); 2746 setCategoryDialogFields(dialog, firstCategory);
2747 2747
2748 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); 2748 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE);
2749 2749
2750 if (initIcons) 2750 if (initIcons)
2751 { 2751 {
2752 Wait waitDialog(this, tr("Wait dialog")); 2752 Wait waitDialog(this, tr("Wait dialog"));
2753 waitDialog.waitLabel->setText(tr("Gathering icons...")); 2753 waitDialog.waitLabel->setText(tr("Gathering icons..."));
2754 waitDialog.show(); 2754 waitDialog.show();
2755 qApp->processEvents(); 2755 qApp->processEvents();
2756 2756
2757#ifdef DESKTOP 2757#ifdef DESKTOP
2758 QDir d(iconPath); 2758 QDir d(iconPath);
2759#else 2759#else
2760 QDir d(QPEApplication::qpeDir() + "/pics/"); 2760 QDir d(QPEApplication::qpeDir() + "/pics/");
2761#endif 2761#endif
2762 d.setFilter( QDir::Files); 2762 d.setFilter( QDir::Files);
2763 2763
2764 const QFileInfoList *list = d.entryInfoList(); 2764 const QFileInfoList *list = d.entryInfoList();
2765 QFileInfoListIterator it( *list ); // create list iterator 2765 QFileInfoListIterator it( *list ); // create list iterator
2766 QFileInfo *fi; // pointer for traversing 2766 QFileInfo *fi; // pointer for traversing
2767 2767
2768 dialog->IconField->insertItem("predefined"); 2768 dialog->IconField->insertItem("predefined");
2769 while ( (fi=it.current()) ) { // for each file... 2769 while ( (fi=it.current()) ) { // for each file...
2770 QString fileName = fi->fileName(); 2770 QString fileName = fi->fileName();
2771 if(fileName.right(4) == ".png"){ 2771 if(fileName.right(4) == ".png"){
2772 fileName = fileName.mid(0,fileName.length()-4); 2772 fileName = fileName.mid(0,fileName.length()-4);
2773#ifdef DESKTOP 2773#ifdef DESKTOP
2774 QPixmap imageOfFile; 2774 QPixmap imageOfFile;
2775 imageOfFile.load(iconPath + fi->fileName()); 2775 imageOfFile.load(iconPath + fi->fileName());
2776#else 2776#else
2777 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 2777 QPixmap imageOfFile(Resource::loadPixmap(fileName));
2778#endif 2778#endif
2779 QImage foo = imageOfFile.convertToImage(); 2779 QImage foo = imageOfFile.convertToImage();
2780 foo = foo.smoothScale(16,16); 2780 foo = foo.smoothScale(16,16);
2781 imageOfFile.convertFromImage(foo); 2781 imageOfFile.convertFromImage(foo);
2782 dialog->IconField->insertItem(imageOfFile,fileName); 2782 dialog->IconField->insertItem(imageOfFile,fileName);
2783 } 2783 }
2784 ++it; 2784 ++it;
2785 } 2785 }
2786 waitDialog.hide(); 2786 waitDialog.hide();
2787 } 2787 }
2788 2788
2789#ifndef WIN32 2789#ifndef WIN32
2790 dialog->show(); 2790 dialog->show();
2791#endif 2791#endif
2792#ifndef DESKTOP 2792#ifndef DESKTOP
2793 // dialog->move (20, 100); 2793 // dialog->move (20, 100);
2794#endif 2794#endif
2795 DialogCode result = (DialogCode) dialog->exec(); 2795 DialogCode result = (DialogCode) dialog->exec();
2796#ifdef DESKTOP 2796#ifdef DESKTOP
2797 result = Accepted; 2797 result = Accepted;
2798#endif 2798#endif
2799 2799
2800 QString category; 2800 QString category;
2801 QString icon; 2801 QString icon;
2802 QString fullIconPath; 2802 QString fullIconPath;
2803 QPixmap *pix; 2803 QPixmap *pix;
2804 if (result == Accepted) 2804 if (result == Accepted)
2805 { 2805 {
2806 modified = true; 2806 modified = true;
2807 category = dialog->CategoryField->currentText(); 2807 category = dialog->CategoryField->currentText();
2808 icon = dialog->IconField->currentText()+".png"; 2808 icon = dialog->IconField->currentText()+".png";
2809 2809
2810#ifndef NO_OPIE 2810#ifndef NO_OPIE
2811 owarn << category << oendl; 2811 owarn << category << oendl;
2812#endif 2812#endif
2813 2813
2814 QListViewItem *li = new ShadedListItem( 1, ListView ); 2814 QListViewItem *li = new ShadedListItem( 1, ListView );
2815 Category *c1 = new Category(); 2815 Category *c1 = new Category();
2816 c1->setCategoryName(category); 2816 c1->setCategoryName(category);
2817 2817
2818 // if (!icon.isEmpty() && !icon.isNull()) 2818 // if (!icon.isEmpty() && !icon.isNull())
2819 if (icon != "predefined.png") 2819 if (icon != "predefined.png")
2820 { 2820 {
2821 // build the full path 2821 // build the full path
2822 fullIconPath = iconPath + icon; 2822 fullIconPath = iconPath + icon;
2823 pix = new QPixmap (fullIconPath); 2823 pix = new QPixmap (fullIconPath);
2824 // pix->resize(14, 14); 2824 // pix->resize(14, 14);
2825 if (!pix->isNull()) 2825 if (!pix->isNull())
2826 { 2826 {
2827 // save the full pixmap name into the config file 2827 // save the full pixmap name into the config file
2828// #ifndef WIN32 2828// #ifndef WIN32
2829 conf->writeEntry(APP_KEY+category, icon); 2829 conf->writeEntry(APP_KEY+category, icon);
2830// #endif 2830// #endif
2831 saveConf(); 2831 saveConf();
2832 QImage img = pix->convertToImage(); 2832 QImage img = pix->convertToImage();
2833 pix->convertFromImage(img.smoothScale(14,14)); 2833 pix->convertFromImage(img.smoothScale(14,14));
2834 c1->setIcon (*pix); 2834 c1->setIcon (*pix);
2835 c1->setIconName(icon); 2835 c1->setIconName(icon);
2836 } 2836 }
2837 else 2837 else
2838 { 2838 {
2839 QPixmap folder( ( const char** ) general_data ); 2839 QPixmap folder( ( const char** ) general_data );
2840 c1->setIcon (folder); 2840 c1->setIcon (folder);
2841 } 2841 }
2842 } 2842 }
2843 else 2843 else
2844 { 2844 {
2845 c1->setIcon (*getPredefinedIcon(category)); 2845 c1->setIcon (*getPredefinedIcon(category));
2846 } 2846 }
2847 2847
2848 c1->setListItem (li); 2848 c1->setListItem (li);
2849 c1->initListItem(); 2849 c1->initListItem();
2850 categories.insert (c1->getCategoryName(), c1); 2850 categories.insert (c1->getCategoryName(), c1);
2851 2851
2852 saveCategoryDialogFields(dialog); 2852 saveCategoryDialogFields(dialog);
2853 } 2853 }
2854 else 2854 else
2855 { 2855 {
2856 // delete dialog; 2856 // delete dialog;
2857 dialog->hide(); 2857 dialog->hide();
2858 return; 2858 return;
2859 } 2859 }
2860 2860
2861 } 2861 }
2862 2862
2863} 2863}
2864 2864
2865void ZSafe::delCategory() 2865void ZSafe::delCategory()
2866{ 2866{
2867 if (!selectedItem) 2867 if (!selectedItem)
2868 return; 2868 return;
2869 if (isCategory(selectedItem)) 2869 if (isCategory(selectedItem))
2870 { 2870 {
2871 switch( QMessageBox::information( this, tr("ZSafe"), 2871 switch( QMessageBox::information( this, tr("ZSafe"),
2872 tr("Do you want to delete?"), 2872 tr("Do you want to delete?"),
2873 tr("&Delete"), tr("D&on't Delete"), 2873 tr("&Delete"), tr("D&on't Delete"),
2874 0 // Enter == button 0 2874 0 // Enter == button 0
2875 ) ) { // Escape == button 2 2875 ) ) { // Escape == button 2
2876 case 0: // Delete clicked, Alt-S or Enter pressed. 2876 case 0: // Delete clicked, Alt-S or Enter pressed.
2877 // Delete from the category list 2877 // Delete from the category list
2878 modified = true; 2878 modified = true;
2879 categories.remove (selectedItem->text(0)); 2879 categories.remove (selectedItem->text(0));
2880// #ifndef WIN32 2880// #ifndef WIN32
2881 conf->removeEntry (selectedItem->text(0)); 2881 conf->removeEntry (selectedItem->text(0));
2882// #endif 2882// #endif
2883 saveConf(); 2883 saveConf();
2884 2884
2885 // Delete the selected item and all subitems 2885 // Delete the selected item and all subitems
2886 // step through all subitems 2886 // step through all subitems
2887 QListViewItem *si; 2887 QListViewItem *si;
2888 for (si = selectedItem->firstChild(); 2888 for (si = selectedItem->firstChild();
2889 si != NULL; ) 2889 si != NULL; )
2890 { 2890 {
2891 QListViewItem *_si = si; 2891 QListViewItem *_si = si;
2892 si = si->nextSibling(); 2892 si = si->nextSibling();
2893 selectedItem->takeItem(_si); // remove from view list 2893 selectedItem->takeItem(_si); // remove from view list
2894 if (_si) delete _si; 2894 if (_si) delete _si;
2895 } 2895 }
2896 ListView->takeItem(selectedItem); 2896 ListView->takeItem(selectedItem);
2897 delete selectedItem; 2897 delete selectedItem;
2898 2898
2899 selectedItem = NULL; 2899 selectedItem = NULL;
2900 break; 2900 break;
2901 case 1: // Don't delete 2901 case 1: // Don't delete
2902 break; 2902 break;
2903 } 2903 }
2904 2904
2905 } 2905 }
2906} 2906}
2907 2907
2908void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) 2908void ZSafe::setCategoryDialogFields(CategoryDialog *dialog)
2909{ 2909{
2910 if (!dialog) 2910 if (!dialog)
2911 return; 2911 return;
2912 2912
2913 QString icon; 2913 QString icon;
2914 if (selectedItem) 2914 if (selectedItem)
2915 { 2915 {
2916 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 2916 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name")));
2917 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 2917 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username")));
2918 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 2918 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password")));
2919 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 2919 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
2920 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); 2920 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4")));
2921 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); 2921 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5")));
2922 2922
2923 Category *cat= categories.find (selectedItem->text(0)); 2923 Category *cat= categories.find (selectedItem->text(0));
2924 if (cat) 2924 if (cat)
2925 { 2925 {
2926 icon = cat->getIconName(); 2926 icon = cat->getIconName();
2927 } 2927 }
2928 else 2928 else
2929 icon = conf->readEntry(APP_KEY+selectedItem->text(0)); 2929 icon = conf->readEntry(APP_KEY+selectedItem->text(0));
2930 } 2930 }
2931 else 2931 else
2932 { 2932 {
2933 dialog->Field1->setText(tr("Name")); 2933 dialog->Field1->setText(tr("Name"));
2934 dialog->Field2->setText(tr("Username")); 2934 dialog->Field2->setText(tr("Username"));
2935 dialog->Field3->setText(tr("Password")); 2935 dialog->Field3->setText(tr("Password"));
2936 dialog->Field4->setText(tr("Comment")); 2936 dialog->Field4->setText(tr("Comment"));
2937 dialog->Field5->setText(tr("Field 4")); 2937 dialog->Field5->setText(tr("Field 4"));
2938 dialog->Field6->setText(tr("Field 5")); 2938 dialog->Field6->setText(tr("Field 5"));
2939 } 2939 }
2940 2940
2941#ifdef DESKTOP 2941#ifdef DESKTOP
2942 QDir d(iconPath); 2942 QDir d(iconPath);
2943#else 2943#else
2944 QDir d(QPEApplication::qpeDir() + "/pics/"); 2944 QDir d(QPEApplication::qpeDir() + "/pics/");
2945#endif 2945#endif
2946 d.setFilter( QDir::Files); 2946 d.setFilter( QDir::Files);
2947 2947
2948 const QFileInfoList *list = d.entryInfoList(); 2948 const QFileInfoList *list = d.entryInfoList();
2949 int i=0; 2949 int i=0;
2950 QFileInfoListIterator it( *list ); // create list iterator 2950 QFileInfoListIterator it( *list ); // create list iterator
2951 QFileInfo *fi; // pointer for traversing 2951 QFileInfo *fi; // pointer for traversing
2952 if (icon.isEmpty() || icon.isNull()) 2952 if (icon.isEmpty() || icon.isNull())
2953 { 2953 {
2954 dialog->IconField->setCurrentItem(0); 2954 dialog->IconField->setCurrentItem(0);
2955 } 2955 }
2956 else 2956 else
2957 { 2957 {
2958 while ( (fi=it.current()) ) 2958 while ( (fi=it.current()) )
2959 { // for each file... 2959 { // for each file...
2960 QString fileName = fi->fileName(); 2960 QString fileName = fi->fileName();
2961 if(fileName.right(4) == ".png") 2961 if(fileName.right(4) == ".png")
2962 { 2962 {
2963 fileName = fileName.mid(0,fileName.length()-4); 2963 fileName = fileName.mid(0,fileName.length()-4);
2964 2964
2965 if(fileName+".png"==icon) 2965 if(fileName+".png"==icon)
2966 { 2966 {
2967 dialog->IconField->setCurrentItem(i+1); 2967 dialog->IconField->setCurrentItem(i+1);
2968 break; 2968 break;
2969 } 2969 }
2970 ++i; 2970 ++i;
2971 } 2971 }
2972 ++it; 2972 ++it;
2973 } 2973 }
2974 } 2974 }
2975} 2975}
2976 2976
2977void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) 2977void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category)
2978{ 2978{
2979 if (!dialog) 2979 if (!dialog)
2980 return; 2980 return;
2981 2981
2982 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); 2982 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name")));
2983 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); 2983 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username")));
2984 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); 2984 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password")));
2985 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); 2985 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment")));
2986 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); 2986 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4")));
2987 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); 2987 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5")));
2988 2988
2989 QString icon; 2989 QString icon;
2990 Category *cat= categories.find (category); 2990 Category *cat= categories.find (category);
2991 if (cat) 2991 if (cat)
2992 { 2992 {
2993 icon = cat->getIconName(); 2993 icon = cat->getIconName();
2994 } 2994 }
2995 else 2995 else
2996 icon = conf->readEntry(APP_KEY+category); 2996 icon = conf->readEntry(APP_KEY+category);
2997 2997
2998#ifdef DESKTOP 2998#ifdef DESKTOP
2999 QDir d(iconPath); 2999 QDir d(iconPath);
3000#else 3000#else
3001 QDir d(QPEApplication::qpeDir() + "/pics/"); 3001 QDir d(QPEApplication::qpeDir() + "/pics/");
3002#endif 3002#endif
3003 d.setFilter( QDir::Files); 3003 d.setFilter( QDir::Files);
3004 3004
3005 const QFileInfoList *list = d.entryInfoList(); 3005 const QFileInfoList *list = d.entryInfoList();
3006 int i=0; 3006 int i=0;
3007 QFileInfoListIterator it( *list ); // create list iterator 3007 QFileInfoListIterator it( *list ); // create list iterator
3008 QFileInfo *fi; // pointer for traversing 3008 QFileInfo *fi; // pointer for traversing
3009 if (icon.isEmpty() || icon.isNull()) 3009 if (icon.isEmpty() || icon.isNull())
3010 { 3010 {
3011 dialog->IconField->setCurrentItem(0); 3011 dialog->IconField->setCurrentItem(0);
3012 } 3012 }
3013 else 3013 else
3014 { 3014 {
3015 while ( (fi=it.current()) ) 3015 while ( (fi=it.current()) )
3016 { // for each file... 3016 { // for each file...
3017 QString fileName = fi->fileName(); 3017 QString fileName = fi->fileName();
3018 if(fileName.right(4) == ".png") 3018 if(fileName.right(4) == ".png")
3019 { 3019 {
3020 fileName = fileName.mid(0,fileName.length()-4); 3020 fileName = fileName.mid(0,fileName.length()-4);
3021 3021
3022 if(fileName+".png"==icon) 3022 if(fileName+".png"==icon)
3023 { 3023 {
3024 dialog->IconField->setCurrentItem(i+1); 3024 dialog->IconField->setCurrentItem(i+1);
3025 break; 3025 break;
3026 } 3026 }
3027 ++i; 3027 ++i;
3028 } 3028 }
3029 ++it; 3029 ++it;
3030 } 3030 }
3031 } 3031 }
3032} 3032}
3033 3033
3034void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) 3034void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog)
3035{ 3035{
3036 QString app_key = APP_KEY; 3036 QString app_key = APP_KEY;
3037#ifndef DESKTOP 3037#ifndef DESKTOP
3038 conf->setGroup ("fieldDefs"); 3038 conf->setGroup ("fieldDefs");
3039#else 3039#else
3040#ifndef WIN32 3040#ifndef WIN32
3041 app_key += "/fieldDefs/"; 3041 app_key += "/fieldDefs/";
3042#endif 3042#endif
3043#endif 3043#endif
3044 QString category = dialog->CategoryField->currentText(); 3044 QString category = dialog->CategoryField->currentText();
3045// #ifndef WIN32 3045// #ifndef WIN32
3046 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); 3046 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text());
3047 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); 3047 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text());
3048 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); 3048 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text());
3049 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); 3049 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text());
3050 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); 3050 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text());
3051 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); 3051 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text());
3052// #endif 3052// #endif
3053 saveConf(); 3053 saveConf();
3054#ifndef DESKTOP 3054#ifndef DESKTOP
3055 conf->setGroup ("zsafe"); 3055 conf->setGroup ("zsafe");
3056#endif 3056#endif
3057} 3057}
3058 3058
3059void ZSafe::editCategory() 3059void ZSafe::editCategory()
3060{ 3060{
3061 if (!selectedItem) 3061 if (!selectedItem)
3062 return; 3062 return;
3063 if (isCategory(selectedItem)) 3063 if (isCategory(selectedItem))
3064 { 3064 {
3065 QString category = selectedItem->text(0); 3065 QString category = selectedItem->text(0);
3066 bool initIcons = false; 3066 bool initIcons = false;
3067 // open the 'Category' dialog 3067 // open the 'Category' dialog
3068 CategoryDialog *dialog; 3068 CategoryDialog *dialog;
3069 if (categoryDialog) 3069 if (categoryDialog)
3070 { 3070 {
3071 dialog = categoryDialog; 3071 dialog = categoryDialog;
3072 } 3072 }
3073 else 3073 else
3074 { 3074 {
3075 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 3075 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
3076#ifdef WIN32 3076#ifdef WIN32
3077 categoryDialog->setCaption ("Qt " + tr("Category")); 3077 categoryDialog->setCaption ("Qt " + tr("Category"));
3078#endif 3078#endif
3079 dialog = categoryDialog; 3079 dialog = categoryDialog;
3080 connect( dialog->CategoryField, 3080 connect( dialog->CategoryField,
3081 SIGNAL( activated(const QString&)), 3081 SIGNAL( activated(const QString&)),
3082 this, SLOT( categoryFieldActivated(const QString&) ) ); 3082 this, SLOT( categoryFieldActivated(const QString&) ) );
3083 initIcons = true; 3083 initIcons = true;
3084 } 3084 }
3085 setCategoryDialogFields(dialog); 3085 setCategoryDialogFields(dialog);
3086 3086
3087#ifdef DESKTOP 3087#ifdef DESKTOP
3088#ifndef WIN32 3088#ifndef WIN32
3089 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 3089 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
3090#else 3090#else
3091 // read all categories from the config file and store 3091 // read all categories from the config file and store
3092 // into a list 3092 // into a list
3093 QFile f (cfgFile); 3093 QFile f (cfgFile);
3094 QStringList list; 3094 QStringList list;
3095 if ( f.open(IO_ReadOnly) ) { // file opened successfully 3095 if ( f.open(IO_ReadOnly) ) { // file opened successfully
3096 QTextStream t( &f ); // use a text stream 3096 QTextStream t( &f ); // use a text stream
3097 QString s; 3097 QString s;
3098 int n = 1; 3098 int n = 1;
3099 while ( !t.eof() ) { // until end of file... 3099 while ( !t.eof() ) { // until end of file...
3100 s = t.readLine(); // line of text excluding '\n' 3100 s = t.readLine(); // line of text excluding '\n'
3101 list.append(s); 3101 list.append(s);
3102 } 3102 }
3103 f.close(); 3103 f.close();
3104 } 3104 }
3105#endif 3105#endif
3106#else 3106#else
3107 // read all categories from the config file and store 3107 // read all categories from the config file and store
3108 // into a list 3108 // into a list
3109 QFile f (cfgFile); 3109 QFile f (cfgFile);
3110 QStringList list; 3110 QStringList list;
3111 if ( f.open(IO_ReadOnly) ) { // file opened successfully 3111 if ( f.open(IO_ReadOnly) ) { // file opened successfully
3112 QTextStream t( &f ); // use a text stream 3112 QTextStream t( &f ); // use a text stream
3113 QString s; 3113 QString s;
3114 while ( !t.eof() ) { // until end of file... 3114 while ( !t.eof() ) { // until end of file...
3115 s = t.readLine(); // line of text excluding '\n' 3115 s = t.readLine(); // line of text excluding '\n'
3116 list.append(s); 3116 list.append(s);
3117 } 3117 }
3118 f.close(); 3118 f.close();
3119 } 3119 }
3120#endif 3120#endif
3121 QStringList::Iterator it = list.begin(); 3121 QStringList::Iterator it = list.begin();
3122 QString categ; 3122 QString categ;
3123 dialog->CategoryField->clear(); // remove all items 3123 dialog->CategoryField->clear(); // remove all items
3124 int i=0; 3124 int i=0;
3125 bool foundCategory = false; 3125 bool foundCategory = false;
3126 while( it != list.end() ) 3126 while( it != list.end() )
3127 { 3127 {
3128 QString *cat = new QString (*it); 3128 QString *cat = new QString (*it);
3129 if (cat->contains("-field1", FALSE)) 3129 if (cat->contains("-field1", FALSE))
3130 { 3130 {
3131#ifdef DESKTOP 3131#ifdef DESKTOP
3132#ifndef WIN32 3132#ifndef WIN32
3133 categ = cat->section ("-field1", 0, 0); 3133 categ = cat->section ("-field1", 0, 0);
3134#else 3134#else
3135 int pos = cat->find ("-field1"); 3135 int pos = cat->find ("-field1");
3136 categ = cat->left (pos); 3136 categ = cat->left (pos);
3137#endif 3137#endif
3138#else 3138#else
3139 int pos = cat->find ("-field1"); 3139 int pos = cat->find ("-field1");
3140 cat->truncate(pos); 3140 cat->truncate(pos);
3141 categ = *cat; 3141 categ = *cat;
3142#endif 3142#endif
3143 if (!categ.isEmpty()) 3143 if (!categ.isEmpty())
3144 { 3144 {
3145 dialog->CategoryField->insertItem (categ, i); 3145 dialog->CategoryField->insertItem (categ, i);
3146 if (category.compare(categ) == 0) 3146 if (category.compare(categ) == 0)
3147 { 3147 {
3148 dialog->CategoryField->setCurrentItem(i); 3148 dialog->CategoryField->setCurrentItem(i);
3149 foundCategory = true; 3149 foundCategory = true;
3150 } 3150 }
3151 i++; 3151 i++;
3152 } 3152 }
3153 } 3153 }
3154 ++it; 3154 ++it;
3155 } 3155 }
3156 if (!foundCategory) 3156 if (!foundCategory)
3157 { 3157 {
3158 dialog->CategoryField->insertItem (category, i); 3158 dialog->CategoryField->insertItem (category, i);
3159 dialog->CategoryField->setCurrentItem(i); 3159 dialog->CategoryField->setCurrentItem(i);
3160 } 3160 }
3161 3161
3162 QString icon; 3162 QString icon;
3163 Category *cat= categories.find (selectedItem->text(0)); 3163 Category *cat= categories.find (selectedItem->text(0));
3164 if (cat) 3164 if (cat)
3165 { 3165 {
3166 icon = cat->getIconName(); 3166 icon = cat->getIconName();
3167 } 3167 }
3168 3168
3169 if (initIcons) 3169 if (initIcons)
3170 { 3170 {
3171 3171
3172 Wait waitDialog(this, tr("Wait dialog")); 3172 Wait waitDialog(this, tr("Wait dialog"));
3173 waitDialog.waitLabel->setText(tr("Gathering icons...")); 3173 waitDialog.waitLabel->setText(tr("Gathering icons..."));
3174 waitDialog.show(); 3174 waitDialog.show();
3175 qApp->processEvents(); 3175 qApp->processEvents();
3176 3176
3177#ifdef DESKTOP 3177#ifdef DESKTOP
3178 QDir d(iconPath); 3178 QDir d(iconPath);
3179#else 3179#else
3180 QDir d(QPEApplication::qpeDir() + "/pics/"); 3180 QDir d(QPEApplication::qpeDir() + "/pics/");
3181#endif 3181#endif
3182 d.setFilter( QDir::Files); 3182 d.setFilter( QDir::Files);
3183 3183
3184 const QFileInfoList *list = d.entryInfoList(); 3184 const QFileInfoList *list = d.entryInfoList();
3185 int i=0; 3185 int i=0;
3186 QFileInfoListIterator it( *list ); // create list iterator 3186 QFileInfoListIterator it( *list ); // create list iterator
3187 QFileInfo *fi; // pointer for traversing 3187 QFileInfo *fi; // pointer for traversing
3188 if (icon.isEmpty() || icon.isNull()) 3188 if (icon.isEmpty() || icon.isNull())
3189 { 3189 {
3190 dialog->IconField->setCurrentItem(0); 3190 dialog->IconField->setCurrentItem(0);
3191 } 3191 }
3192 3192
3193 dialog->IconField->insertItem("predefined"); 3193 dialog->IconField->insertItem("predefined");
3194 while ( (fi=it.current()) ) { // for each file... 3194 while ( (fi=it.current()) ) { // for each file...
3195 QString fileName = fi->fileName(); 3195 QString fileName = fi->fileName();
3196 if(fileName.right(4) == ".png") 3196 if(fileName.right(4) == ".png")
3197 { 3197 {
3198 fileName = fileName.mid(0,fileName.length()-4); 3198 fileName = fileName.mid(0,fileName.length()-4);
3199#ifdef DESKTOP 3199#ifdef DESKTOP
3200 QPixmap imageOfFile; 3200 QPixmap imageOfFile;
3201 imageOfFile.load(iconPath + fi->fileName()); 3201 imageOfFile.load(iconPath + fi->fileName());
3202#else 3202#else
3203 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 3203 QPixmap imageOfFile(Resource::loadPixmap(fileName));
3204#endif 3204#endif
3205 QImage foo = imageOfFile.convertToImage(); 3205 QImage foo = imageOfFile.convertToImage();
3206 foo = foo.smoothScale(16,16); 3206 foo = foo.smoothScale(16,16);
3207 imageOfFile.convertFromImage(foo); 3207 imageOfFile.convertFromImage(foo);
3208 dialog->IconField->insertItem(imageOfFile,fileName); 3208 dialog->IconField->insertItem(imageOfFile,fileName);
3209 if(fileName+".png"==icon) 3209 if(fileName+".png"==icon)
3210 dialog->IconField->setCurrentItem(i+1); 3210 dialog->IconField->setCurrentItem(i+1);
3211 ++i; 3211 ++i;
3212 } 3212 }
3213 ++it; 3213 ++it;
3214 } 3214 }
3215 waitDialog.hide(); 3215 waitDialog.hide();
3216 } 3216 }
3217 else 3217 else
3218 { 3218 {
3219#ifdef DESKTOP 3219#ifdef DESKTOP
3220 // QDir d(QDir::homeDirPath() + "/pics/"); 3220 // QDir d(QDir::homeDirPath() + "/pics/");
3221 QDir d(iconPath); 3221 QDir d(iconPath);
3222#else 3222#else
3223 QDir d(QPEApplication::qpeDir() + "/pics/"); 3223 QDir d(QPEApplication::qpeDir() + "/pics/");
3224#endif 3224#endif
3225 d.setFilter( QDir::Files); 3225 d.setFilter( QDir::Files);
3226 3226
3227 const QFileInfoList *list = d.entryInfoList(); 3227 const QFileInfoList *list = d.entryInfoList();
3228 int i=0; 3228 int i=0;
3229 QFileInfoListIterator it( *list ); // create list iterator 3229 QFileInfoListIterator it( *list ); // create list iterator
3230 QFileInfo *fi; // pointer for traversing 3230 QFileInfo *fi; // pointer for traversing
3231 if (icon.isEmpty() || icon.isNull()) 3231 if (icon.isEmpty() || icon.isNull())
3232 { 3232 {
3233 dialog->IconField->setCurrentItem(0); 3233 dialog->IconField->setCurrentItem(0);
3234 } 3234 }
3235 else 3235 else
3236 { 3236 {
3237 3237
3238 while ( (fi=it.current()) ) 3238 while ( (fi=it.current()) )
3239 { // for each file... 3239 { // for each file...
3240 QString fileName = fi->fileName(); 3240 QString fileName = fi->fileName();
3241 if(fileName.right(4) == ".png") 3241 if(fileName.right(4) == ".png")
3242 { 3242 {
3243 fileName = fileName.mid(0,fileName.length()-4); 3243 fileName = fileName.mid(0,fileName.length()-4);
3244 3244
3245 3245
3246 if(fileName+".png"==icon) 3246 if(fileName+".png"==icon)
3247 { 3247 {
3248 dialog->IconField->setCurrentItem(i+1); 3248 dialog->IconField->setCurrentItem(i+1);
3249 break; 3249 break;
3250 } 3250 }
3251 ++i; 3251 ++i;
3252 } 3252 }
3253 ++it; 3253 ++it;
3254 } 3254 }
3255 } 3255 }
3256 } 3256 }
3257 3257
3258 // dialog->show(); 3258 // dialog->show();
3259#ifndef DESKTOP 3259#ifndef DESKTOP
3260 // dialog->move (20, 100); 3260 // dialog->move (20, 100);
3261#endif 3261#endif
3262 DialogCode result = (DialogCode) dialog->exec(); 3262 DialogCode result = (DialogCode) dialog->exec();
3263#ifdef DESKTOP 3263#ifdef DESKTOP
3264 result = Accepted; 3264 result = Accepted;
3265#endif 3265#endif
3266 3266
3267 QString fullIconPath; 3267 QString fullIconPath;
3268 QPixmap *pix; 3268 QPixmap *pix;
3269 if (result == Accepted) 3269 if (result == Accepted)
3270 { 3270 {
3271 modified = true; 3271 modified = true;
3272 if (category != dialog->CategoryField->currentText()) 3272 if (category != dialog->CategoryField->currentText())
3273 { 3273 {
3274 categories.remove (category); 3274 categories.remove (category);
3275// #ifndef WIN32 3275// #ifndef WIN32
3276 conf->removeEntry(category); 3276 conf->removeEntry(category);
3277// #endif 3277// #endif
3278 saveConf(); 3278 saveConf();
3279 } 3279 }
3280 3280
3281 category = dialog->CategoryField->currentText(); 3281 category = dialog->CategoryField->currentText();
3282 icon = dialog->IconField->currentText()+".png"; 3282 icon = dialog->IconField->currentText()+".png";
3283 3283
3284 if (cat) 3284 if (cat)
3285 { 3285 {
3286#ifndef NO_OPIE 3286#ifndef NO_OPIE
3287 owarn << "Category found" << oendl; 3287 owarn << "Category found" << oendl;
3288#else 3288#else
3289 qWarning("Category found"); 3289 qWarning("Category found");
3290#endif 3290#endif
3291 3291
3292 // if (!icon.isEmpty() && !icon.isNull()) 3292 // if (!icon.isEmpty() && !icon.isNull())
3293 if (icon != "predefined.png") 3293 if (icon != "predefined.png")
3294 { 3294 {
3295 // build the full path 3295 // build the full path
3296 fullIconPath = iconPath + icon; 3296 fullIconPath = iconPath + icon;
3297 pix = new QPixmap (fullIconPath); 3297 pix = new QPixmap (fullIconPath);
3298 if (!pix->isNull()) 3298 if (!pix->isNull())
3299 { 3299 {
3300 // save the full pixmap name into the config file 3300 // save the full pixmap name into the config file
3301// #ifndef WIN32 3301// #ifndef WIN32
3302 conf->writeEntry(APP_KEY+category, icon); 3302 conf->writeEntry(APP_KEY+category, icon);
3303// #endif 3303// #endif
3304 saveConf(); 3304 saveConf();
3305 QImage img = pix->convertToImage(); 3305 QImage img = pix->convertToImage();
3306 pix->convertFromImage(img.smoothScale(14,14)); 3306 pix->convertFromImage(img.smoothScale(14,14));
3307 cat->setIconName (icon); 3307 cat->setIconName (icon);
3308 cat->setIcon (*pix); 3308 cat->setIcon (*pix);
3309 } 3309 }
3310 } 3310 }
3311 else 3311 else
3312 { 3312 {
3313// #ifndef WIN32 3313// #ifndef WIN32
3314 conf->removeEntry (category); 3314 conf->removeEntry (category);
3315// #endif 3315// #endif
3316 saveConf(); 3316 saveConf();
3317 cat->setIcon (*getPredefinedIcon(category)); 3317 cat->setIcon (*getPredefinedIcon(category));
3318 } 3318 }
3319 3319
3320 // change the category name of the selected category 3320 // change the category name of the selected category
3321 QListViewItem *catItem = cat->getListItem(); 3321 QListViewItem *catItem = cat->getListItem();
3322 if (catItem) 3322 if (catItem)
3323 { 3323 {
3324#ifndef NO_OPIE 3324#ifndef NO_OPIE
3325 owarn << category << oendl; 3325 owarn << category << oendl;
3326#else 3326#else
3327 qWarning (category); 3327 qWarning (category);
3328#endif 3328#endif
3329 catItem->setText( 0, tr( category ) ); 3329 catItem->setText( 0, tr( category ) );
3330 cat->setCategoryName (tr(category)); 3330 cat->setCategoryName (tr(category));
3331 3331
3332 cat->initListItem(); 3332 cat->initListItem();
3333 categories.insert (category, cat); 3333 categories.insert (category, cat);
3334 } 3334 }
3335 } 3335 }
3336 saveCategoryDialogFields(dialog); 3336 saveCategoryDialogFields(dialog);
3337 } 3337 }
3338 else 3338 else
3339 { 3339 {
3340 // delete dialog; 3340 // delete dialog;
3341 dialog->hide(); 3341 dialog->hide();
3342 return; 3342 return;
3343 } 3343 }
3344 3344
3345 } 3345 }
3346} 3346}
3347 3347
3348void ZSafe::cutItem() 3348void ZSafe::cutItem()
3349{ 3349{
3350 if (!selectedItem) 3350 if (!selectedItem)
3351 return; 3351 return;
3352 if (!isCategory(selectedItem)) 3352 if (!isCategory(selectedItem))
3353 { 3353 {
3354 IsCut = true; 3354 IsCut = true;
3355 copiedItem = selectedItem; 3355 copiedItem = selectedItem;
3356 } 3356 }
3357} 3357}
3358 3358
3359void ZSafe::copyItem() 3359void ZSafe::copyItem()
3360{ 3360{
3361 if (!selectedItem) 3361 if (!selectedItem)
3362 return; 3362 return;
3363 if (!isCategory(selectedItem)) 3363 if (!isCategory(selectedItem))
3364 { 3364 {
3365 IsCopy = true; 3365 IsCopy = true;
3366 copiedItem = selectedItem; 3366 copiedItem = selectedItem;
3367 } 3367 }
3368} 3368}
3369 3369
3370// paste item into category 3370// paste item into category
3371void ZSafe::pasteItem() 3371void ZSafe::pasteItem()
3372{ 3372{
3373 if (!selectedItem) 3373 if (!selectedItem)
3374 return; 3374 return;
3375 if (isCategory(selectedItem)) 3375 if (isCategory(selectedItem))
3376 { 3376 {
3377 modified = true; 3377 modified = true;
3378 if (IsCut) 3378 if (IsCut)
3379 { 3379 {
3380 if (copiedItem) 3380 if (copiedItem)
3381 { 3381 {
3382 // add the new item 3382 // add the new item
3383 QListViewItem *i = new ShadedListItem (0, selectedItem); 3383 QListViewItem *i = new ShadedListItem (0, selectedItem);
3384 // i->setOpen (TRUE); 3384 // i->setOpen (TRUE);
3385 i->setText (0, copiedItem->text(0)); 3385 i->setText (0, copiedItem->text(0));
3386 i->setText (1, copiedItem->text(1)); 3386 i->setText (1, copiedItem->text(1));
3387 i->setText (2, copiedItem->text(2)); 3387 i->setText (2, copiedItem->text(2));
3388 i->setText (3, copiedItem->text(3)); 3388 i->setText (3, copiedItem->text(3));
3389 i->setText (4, copiedItem->text(4)); 3389 i->setText (4, copiedItem->text(4));
3390 i->setText (5, copiedItem->text(5)); 3390 i->setText (5, copiedItem->text(5));
3391 selectedItem->setOpen( TRUE ); 3391 selectedItem->setOpen( TRUE );
3392 3392
3393 // remove the cutted item 3393 // remove the cutted item
3394 copiedItem->parent()->takeItem(copiedItem); 3394 copiedItem->parent()->takeItem(copiedItem);
3395 selectedItem = NULL; 3395 selectedItem = NULL;
3396 } 3396 }
3397 } 3397 }
3398 else if (IsCopy) 3398 else if (IsCopy)
3399 { 3399 {
3400 if (copiedItem) 3400 if (copiedItem)
3401 { 3401 {
3402 // add the new item 3402 // add the new item
3403 QListViewItem *i = new ShadedListItem (0, selectedItem); 3403 QListViewItem *i = new ShadedListItem (0, selectedItem);
3404 // i->setOpen (TRUE); 3404 // i->setOpen (TRUE);
3405 i->setText (0, copiedItem->text(0)); 3405 i->setText (0, copiedItem->text(0));
3406 i->setText (1, copiedItem->text(1)); 3406 i->setText (1, copiedItem->text(1));
3407 i->setText (2, copiedItem->text(2)); 3407 i->setText (2, copiedItem->text(2));
3408 i->setText (3, copiedItem->text(3)); 3408 i->setText (3, copiedItem->text(3));
3409 i->setText (4, copiedItem->text(4)); 3409 i->setText (4, copiedItem->text(4));
3410 i->setText (5, copiedItem->text(5)); 3410 i->setText (5, copiedItem->text(5));
3411 selectedItem->setOpen( TRUE ); 3411 selectedItem->setOpen( TRUE );
3412 } 3412 }
3413 } 3413 }
3414 } 3414 }
3415 IsCut = false; 3415 IsCut = false;
3416 IsCopy = false; 3416 IsCopy = false;
3417} 3417}
3418 3418
3419void ZSafe::newDocument() 3419void ZSafe::newDocument()
3420{ 3420{
3421 3421
3422 // open the file dialog 3422 // open the file dialog
3423#ifndef DESKTOP 3423#ifndef DESKTOP
3424#ifndef NO_OPIE 3424#ifndef NO_OPIE
3425 QMap<QString, QStringList> mimeTypes; 3425 QMap<QString, QStringList> mimeTypes;
3426 mimeTypes.insert(tr("All"), QStringList() ); 3426 mimeTypes.insert(tr("All"), QStringList() );
3427 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3427 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3428 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 3428 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
3429 QDir::homeDirPath() + "/Documents/application/zsafe", 3429 QDir::homeDirPath() + "/Documents/application/zsafe",
3430 QString::null, 3430 QString::null,
3431 mimeTypes, 3431 mimeTypes,
3432 this, 3432 this,
3433 tr ("Create new ZSafe document")); 3433 tr ("Create new ZSafe document"));
3434#else 3434#else
3435 QString newFile = ScQtFileEdit::getSaveAsFileName(this, 3435 QString newFile = ScQtFileEdit::getSaveAsFileName(this,
3436 tr ("Create new ZSafe document"), 3436 tr ("Create new ZSafe document"),
3437 QDir::homeDirPath() + "/Documents/application/zsafe", 3437 QDir::homeDirPath() + "/Documents/application/zsafe",
3438 "*.zsf"); 3438 "*.zsf");
3439#endif 3439#endif
3440#else 3440#else
3441 QString newFile = QFileDialog::getSaveFileName( 3441 QString newFile = QFileDialog::getSaveFileName(
3442 QDir::homeDirPath() + "/Documents/application/zsafe", 3442 QDir::homeDirPath() + "/Documents/application/zsafe",
3443 "ZSafe (*.zsf)", 3443 "ZSafe (*.zsf)",
3444 this, 3444 this,
3445 "ZSafe File Dialog" 3445 "ZSafe File Dialog"
3446 "Choose a ZSafe file" ); 3446 "Choose a ZSafe file" );
3447#endif 3447#endif
3448 3448
3449 // open the new document 3449 // open the new document
3450 if (newFile && newFile.length() > 0 ) 3450 if (newFile && newFile.length() > 0 )
3451 { 3451 {
3452 // save the previous opened document 3452 // save the previous opened document
3453 if (!filename.isEmpty()) 3453 if (!filename.isEmpty())
3454 saveDocument(filename, FALSE); 3454 saveDocument(filename, FALSE);
3455 3455
3456 modified = true; 3456 modified = true;
3457 3457
3458 // clear the password list 3458 // clear the password list
3459 QListViewItem *i; 3459 QListViewItem *i;
3460 QListViewItem *c = NULL; 3460 QListViewItem *c = NULL;
3461 // step through all categories 3461 // step through all categories
3462 for (i = ListView->firstChild(); 3462 for (i = ListView->firstChild();
3463 i != NULL; 3463 i != NULL;
3464 i = i->nextSibling()) 3464 i = i->nextSibling())
3465 { 3465 {
3466 if (c) delete c; // delete the previous category 3466 if (c) delete c; // delete the previous category
3467 3467
3468 c = i; 3468 c = i;