summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwm.cpp30
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp25
2 files changed, 27 insertions, 28 deletions
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
index c511661..66d26d6 100644
--- a/pwmanager/pwmanager/pwm.cpp
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -601,611 +601,611 @@ void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc)
601 doc->timer()->getLock(DocTimer::id_autoLockTimer); 601 doc->timer()->getLock(DocTimer::id_autoLockTimer);
602#ifndef PWM_EMBEDDED 602#ifndef PWM_EMBEDDED
603 AddEntryWndImpl w; 603 AddEntryWndImpl w;
604#else 604#else
605 AddEntryWndImpl w(this, "addentrywndimpl"); 605 AddEntryWndImpl w(this, "addentrywndimpl");
606#endif 606#endif
607 607
608 vector<string> catList; 608 vector<string> catList;
609 doc->getCategoryList(&catList); 609 doc->getCategoryList(&catList);
610 unsigned i, size = catList.size(); 610 unsigned i, size = catList.size();
611 for (i = 0; i < size; ++i) { 611 for (i = 0; i < size; ++i) {
612 w.addCategory(catList[i].c_str()); 612 w.addCategory(catList[i].c_str());
613 } 613 }
614 w.setCurrCategory(view->getCurrentCategory()); 614 w.setCurrCategory(view->getCurrentCategory());
615 if (pw) 615 if (pw)
616 w.pwLineEdit->setText(*pw); 616 w.pwLineEdit->setText(*pw);
617 617
618 tryAgain: 618 tryAgain:
619 if (w.exec() == 1) 619 if (w.exec() == 1)
620 { 620 {
621 PwMDataItem d; 621 PwMDataItem d;
622 622
623 //US BUG: to initialize all values of curEntr with meaningfulldata, 623 //US BUG: to initialize all values of curEntr with meaningfulldata,
624 // we call clear on it. Reason: Metadata will be uninitialized otherwise. 624 // we call clear on it. Reason: Metadata will be uninitialized otherwise.
625 // another option would be to create a constructor for PwMDataItem 625 // another option would be to create a constructor for PwMDataItem
626 d.clear(true); 626 d.clear(true);
627 627
628 d.desc = w.getDescription().latin1(); 628 d.desc = w.getDescription().latin1();
629 d.name = w.getUsername().latin1(); 629 d.name = w.getUsername().latin1();
630 d.pw = w.getPassword().latin1(); 630 d.pw = w.getPassword().latin1();
631 d.comment = w.getComment().latin1(); 631 d.comment = w.getComment().latin1();
632 d.url = w.getUrl().latin1(); 632 d.url = w.getUrl().latin1();
633 d.launcher = w.getLauncher().latin1(); 633 d.launcher = w.getLauncher().latin1();
634 PwMerror ret = doc->addEntry(w.getCategory(), &d); 634 PwMerror ret = doc->addEntry(w.getCategory(), &d);
635 if (ret == e_entryExists) { 635 if (ret == e_entryExists) {
636 KMessageBox::error(this, 636 KMessageBox::error(this,
637 i18n 637 i18n
638 ("An entry with this \"Description\",\n" 638 ("An entry with this \"Description\",\n"
639 "does already exist.\n" 639 "does already exist.\n"
640 "Please select another description."), 640 "Please select another description."),
641 i18n("entry already exists.")); 641 i18n("entry already exists."));
642 goto tryAgain; 642 goto tryAgain;
643 } else if (ret == e_maxAllowedEntr) { 643 } else if (ret == e_maxAllowedEntr) {
644 KMessageBox::error(this, i18n("The maximum possible number of\nentries" 644 KMessageBox::error(this, i18n("The maximum possible number of\nentries"
645 "has been reached.\nYou can't add more entries."), 645 "has been reached.\nYou can't add more entries."),
646 i18n("maximum number of entries")); 646 i18n("maximum number of entries"));
647 doc->timer()->putLock(DocTimer::id_autoLockTimer); 647 doc->timer()->putLock(DocTimer::id_autoLockTimer);
648 return; 648 return;
649 } 649 }
650 } 650 }
651 setVirgin(false); 651 setVirgin(false);
652 doc->timer()->putLock(DocTimer::id_autoLockTimer); 652 doc->timer()->putLock(DocTimer::id_autoLockTimer);
653} 653}
654 654
655//US ENH : changed code to run with older MOC 655//US ENH : changed code to run with older MOC
656void PwM::editPwd_slot() 656void PwM::editPwd_slot()
657{ 657{
658 editPwd_slot3(0,0,0); 658 editPwd_slot3(0,0,0);
659} 659}
660 660
661void PwM::editPwd_slot1(const QString *category) 661void PwM::editPwd_slot1(const QString *category)
662{ 662{
663 editPwd_slot3(category, 0, 0); 663 editPwd_slot3(category, 0, 0);
664} 664}
665 665
666void PwM::editPwd_slot3(const QString *category, const int *index, 666void PwM::editPwd_slot3(const QString *category, const int *index,
667 PwMDoc *_doc) 667 PwMDoc *_doc)
668{ 668{
669 PwMDoc *doc; 669 PwMDoc *doc;
670 if (_doc) { 670 if (_doc) {
671 doc = _doc; 671 doc = _doc;
672 } else { 672 } else {
673 doc = curDoc(); 673 doc = curDoc();
674 } 674 }
675 PWM_ASSERT(doc); 675 PWM_ASSERT(doc);
676 if (doc->isDocEmpty()) 676 if (doc->isDocEmpty())
677 return; 677 return;
678 if (doc->isDeepLocked()) 678 if (doc->isDeepLocked())
679 return; 679 return;
680 doc->timer()->getLock(DocTimer::id_autoLockTimer); 680 doc->timer()->getLock(DocTimer::id_autoLockTimer);
681 unsigned int curEntryIndex; 681 unsigned int curEntryIndex;
682 if (index) { 682 if (index) {
683 curEntryIndex = *index; 683 curEntryIndex = *index;
684 } else { 684 } else {
685 if (!(view->getCurEntryIndex(&curEntryIndex))) { 685 if (!(view->getCurEntryIndex(&curEntryIndex))) {
686 printDebug("couldn't get index. Maybe we have a binary entry here."); 686 printDebug("couldn't get index. Maybe we have a binary entry here.");
687 doc->timer()->putLock(DocTimer::id_autoLockTimer); 687 doc->timer()->putLock(DocTimer::id_autoLockTimer);
688 return; 688 return;
689 } 689 }
690 } 690 }
691 QString curCategory; 691 QString curCategory;
692 if (category) { 692 if (category) {
693 curCategory = *category; 693 curCategory = *category;
694 } else { 694 } else {
695 curCategory = view->getCurrentCategory(); 695 curCategory = view->getCurrentCategory();
696 } 696 }
697 PwMDataItem currItem; 697 PwMDataItem currItem;
698 if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { 698 if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) {
699 doc->timer()->putLock(DocTimer::id_autoLockTimer); 699 doc->timer()->putLock(DocTimer::id_autoLockTimer);
700 return; 700 return;
701 } 701 }
702 BUG_ON(currItem.binary); 702 BUG_ON(currItem.binary);
703 703
704 AddEntryWndImpl w; 704 AddEntryWndImpl w;
705 vector<string> catList; 705 vector<string> catList;
706 doc->getCategoryList(&catList); 706 doc->getCategoryList(&catList);
707 unsigned i, size = catList.size(); 707 unsigned i, size = catList.size();
708 for (i = 0; i < size; ++i) { 708 for (i = 0; i < size; ++i) {
709 w.addCategory(catList[i].c_str()); 709 w.addCategory(catList[i].c_str());
710 } 710 }
711 w.setCurrCategory(curCategory); 711 w.setCurrCategory(curCategory);
712 w.setDescription(currItem.desc.c_str()); 712 w.setDescription(currItem.desc.c_str());
713 w.setUsername(currItem.name.c_str()); 713 w.setUsername(currItem.name.c_str());
714 w.setPassword(currItem.pw.c_str()); 714 w.setPassword(currItem.pw.c_str());
715 w.setUrl(currItem.url.c_str()); 715 w.setUrl(currItem.url.c_str());
716 w.setLauncher(currItem.launcher.c_str()); 716 w.setLauncher(currItem.launcher.c_str());
717 w.setComment(currItem.comment.c_str()); 717 w.setComment(currItem.comment.c_str());
718 if (w.exec() == 1) { 718 if (w.exec() == 1) {
719 currItem.desc = w.getDescription().latin1(); 719 currItem.desc = w.getDescription().latin1();
720 currItem.name = w.getUsername().latin1(); 720 currItem.name = w.getUsername().latin1();
721 currItem.pw = w.getPassword().latin1(); 721 currItem.pw = w.getPassword().latin1();
722 currItem.comment = w.getComment().latin1(); 722 currItem.comment = w.getComment().latin1();
723 currItem.url = w.getUrl().latin1(); 723 currItem.url = w.getUrl().latin1();
724 currItem.launcher = w.getLauncher().latin1(); 724 currItem.launcher = w.getLauncher().latin1();
725 if (!doc->editEntry(curCategory, w.getCategory(), 725 if (!doc->editEntry(curCategory, w.getCategory(),
726 curEntryIndex, &currItem)) { 726 curEntryIndex, &currItem)) {
727 KMessageBox::error(this, 727 KMessageBox::error(this,
728 i18n("Couldn't edit the entry.\n" 728 i18n("Couldn't edit the entry.\n"
729 "Maybe you changed the category and " 729 "Maybe you changed the category and\n"
730 "this entry is already present in the new " 730 "this entry is already present\nin the new "
731 "category?"), 731 "category?"),
732 i18n("couldn't edit entry.")); 732 i18n("couldn't edit entry."));
733 doc->timer()->putLock(DocTimer::id_autoLockTimer); 733 doc->timer()->putLock(DocTimer::id_autoLockTimer);
734 return; 734 return;
735 } 735 }
736 } 736 }
737 doc->timer()->putLock(DocTimer::id_autoLockTimer); 737 doc->timer()->putLock(DocTimer::id_autoLockTimer);
738} 738}
739 739
740void PwM::deletePwd_slot() 740void PwM::deletePwd_slot()
741{ 741{
742 PWM_ASSERT(curDoc()); 742 PWM_ASSERT(curDoc());
743 if (curDoc()->isDocEmpty()) 743 if (curDoc()->isDocEmpty())
744 return; 744 return;
745 if (curDoc()->isDeepLocked()) 745 if (curDoc()->isDeepLocked())
746 return; 746 return;
747 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 747 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
748 unsigned int curEntryIndex = 0; 748 unsigned int curEntryIndex = 0;
749 if (!(view->getCurEntryIndex(&curEntryIndex))) { 749 if (!(view->getCurEntryIndex(&curEntryIndex))) {
750 printDebug("couldn't get index"); 750 printDebug("couldn't get index");
751 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 751 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
752 return; 752 return;
753 } 753 }
754 754
755 PwMDataItem currItem; 755 PwMDataItem currItem;
756 QString curCategory = view->getCurrentCategory(); 756 QString curCategory = view->getCurrentCategory();
757 if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { 757 if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) {
758 printDebug("couldn't get entry"); 758 printDebug("couldn't get entry");
759 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 759 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
760 return; 760 return;
761 } 761 }
762 if (KMessageBox:: 762 if (KMessageBox::
763 questionYesNo(this, 763 questionYesNo(this,
764 i18n 764 i18n
765 ("Do you really want to delete\nthe selected entry") + 765 ("Do you really want to delete\nthe selected entry") +
766 " \n\"" + QString(currItem.desc.c_str()) 766 " \n\"" + QString(currItem.desc.c_str())
767 + "\" ?", i18n("delete?")) 767 + "\" ?", i18n("delete?"))
768 == KMessageBox::Yes) { 768 == KMessageBox::Yes) {
769 769
770 curDoc()->delEntry(curCategory, curEntryIndex); 770 curDoc()->delEntry(curCategory, curEntryIndex);
771 } 771 }
772 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 772 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
773} 773}
774 774
775void PwM::changeMasterPwd_slot() 775void PwM::changeMasterPwd_slot()
776{ 776{
777 PWM_ASSERT(curDoc()); 777 PWM_ASSERT(curDoc());
778 curDoc()->changeCurrentPw(); 778 curDoc()->changeCurrentPw();
779} 779}
780 780
781void PwM::lockWnd_slot() 781void PwM::lockWnd_slot()
782{ 782{
783 PWM_ASSERT(curDoc()); 783 PWM_ASSERT(curDoc());
784 curDoc()->lockAll(true); 784 curDoc()->lockAll(true);
785} 785}
786 786
787void PwM::deepLockWnd_slot() 787void PwM::deepLockWnd_slot()
788{ 788{
789 PWM_ASSERT(curDoc()); 789 PWM_ASSERT(curDoc());
790 curDoc()->deepLock(); 790 curDoc()->deepLock();
791} 791}
792 792
793void PwM::unlockWnd_slot() 793void PwM::unlockWnd_slot()
794{ 794{
795 PWM_ASSERT(curDoc()); 795 PWM_ASSERT(curDoc());
796 curDoc()->lockAll(false); 796 curDoc()->lockAll(false);
797} 797}
798 798
799void PwM::config_slot() 799void PwM::config_slot()
800{ 800{
801 int oldStyle = conf()->confWndMainViewStyle(); 801 int oldStyle = conf()->confWndMainViewStyle();
802#ifdef PWM_EMBEDDED 802#ifdef PWM_EMBEDDED
803 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); 803 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true );
804 804
805 KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); 805 KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" );
806 ConfigureDialog->addModule(pwmcfg ); 806 ConfigureDialog->addModule(pwmcfg );
807 807
808 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 808 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
809 ConfigureDialog->addModule(kdelibcfg ); 809 ConfigureDialog->addModule(kdelibcfg );
810 810
811#ifndef DESKTOP_VERSION 811#ifndef DESKTOP_VERSION
812 ConfigureDialog->showMaximized(); 812 ConfigureDialog->showMaximized();
813#endif 813#endif
814 if ( ConfigureDialog->exec() ) 814 if ( ConfigureDialog->exec() )
815 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 815 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
816 delete ConfigureDialog; 816 delete ConfigureDialog;
817 817
818#else //PWM_EMBEDDED 818#else //PWM_EMBEDDED
819 // display the configuration window (modal mode) 819 // display the configuration window (modal mode)
820 if (!conf()->showConfWnd(this)) 820 if (!conf()->showConfWnd(this))
821 return; 821 return;
822#endif 822#endif
823 823
824 int newStyle = conf()->confWndMainViewStyle(); 824 int newStyle = conf()->confWndMainViewStyle();
825 // reinitialize tray 825 // reinitialize tray
826 init->initTray(); 826 init->initTray();
827 // reinitialize KWallet emulation 827 // reinitialize KWallet emulation
828 init->initKWalletEmu(); 828 init->initKWalletEmu();
829 829
830 PwMDocList *_dl = PwMDoc::getOpenDocList(); 830 PwMDocList *_dl = PwMDoc::getOpenDocList();
831 const vector<PwMDocList::listItem> *dl = _dl->getList(); 831 const vector<PwMDocList::listItem> *dl = _dl->getList();
832 vector<PwMDocList::listItem>::const_iterator i = dl->begin(), 832 vector<PwMDocList::listItem>::const_iterator i = dl->begin(),
833 end = dl->end(); 833 end = dl->end();
834 PwMDoc *doc; 834 PwMDoc *doc;
835 while (i != end) { 835 while (i != end) {
836 doc = (*i).doc; 836 doc = (*i).doc;
837 // unlock-without-mpw timeout 837 // unlock-without-mpw timeout
838 doc->timer()->start(DocTimer::id_mpwTimer); 838 doc->timer()->start(DocTimer::id_mpwTimer);
839 // auto-lock timeout 839 // auto-lock timeout
840 doc->timer()->start(DocTimer::id_autoLockTimer); 840 doc->timer()->start(DocTimer::id_autoLockTimer);
841 ++i; 841 ++i;
842 } 842 }
843 843
844 const QValueList<PwM *> *ml = init->mainWndList(); 844 const QValueList<PwM *> *ml = init->mainWndList();
845#ifndef PWM_EMBEDDED 845#ifndef PWM_EMBEDDED
846 QValueList<PwM *>::const_iterator i2 = ml->begin(), 846 QValueList<PwM *>::const_iterator i2 = ml->begin(),
847 end2 = ml->end(); 847 end2 = ml->end();
848#else 848#else
849 QValueList<PwM *>::ConstIterator i2 = ml->begin(), 849 QValueList<PwM *>::ConstIterator i2 = ml->begin(),
850 end2 = ml->end(); 850 end2 = ml->end();
851#endif 851#endif
852 PwM *pwm; 852 PwM *pwm;
853 while (i2 != end2) { 853 while (i2 != end2) {
854 pwm = *i2; 854 pwm = *i2;
855 // reinitialize the window style. 855 // reinitialize the window style.
856 if (oldStyle != newStyle) 856 if (oldStyle != newStyle)
857 pwm->curView()->initStyle(newStyle); 857 pwm->curView()->initStyle(newStyle);
858 // set the new font 858 // set the new font
859 pwm->curView()->setFont(conf()->confGlobEntryFont()); 859 pwm->curView()->setFont(conf()->confGlobEntryFont());
860 ++i2; 860 ++i2;
861 } 861 }
862} 862}
863 863
864void PwM::activateMpButton(bool activate) 864void PwM::activateMpButton(bool activate)
865{ 865{
866 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); 866 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate);
867} 867}
868 868
869void PwM::closeEvent(QCloseEvent *e) 869void PwM::closeEvent(QCloseEvent *e)
870{ 870{
871 e->accept(); 871 e->accept();
872} 872}
873 873
874void PwM::docClosed(PwMDoc *doc) 874void PwM::docClosed(PwMDoc *doc)
875{ 875{
876 PARAM_UNUSED(doc); 876 PARAM_UNUSED(doc);
877 PWM_ASSERT(doc == curDoc()); 877 PWM_ASSERT(doc == curDoc());
878 close(); 878 close();
879} 879}
880 880
881void PwM::find_slot() 881void PwM::find_slot()
882{ 882{
883 PWM_ASSERT(curDoc()); 883 PWM_ASSERT(curDoc());
884 if (curDoc()->isDocEmpty()) 884 if (curDoc()->isDocEmpty())
885 return; 885 return;
886 if (curDoc()->isDeepLocked()) 886 if (curDoc()->isDeepLocked())
887 return; 887 return;
888 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 888 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
889 FindWndImpl findWnd(view); 889 FindWndImpl findWnd(view);
890 findWnd.exec(); 890 findWnd.exec();
891 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 891 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
892} 892}
893 893
894void PwM::exportToText() 894void PwM::exportToText()
895{ 895{
896 PWM_ASSERT(curDoc()); 896 PWM_ASSERT(curDoc());
897 if (curDoc()->isDocEmpty()) { 897 if (curDoc()->isDocEmpty()) {
898 KMessageBox::information(this, 898 KMessageBox::information(this,
899 i18n 899 i18n
900 ("Sorry, there's nothing to export.\n" 900 ("Sorry, there's nothing to export.\n"
901 "Please first add some passwords."), 901 "Please first add some passwords."),
902 i18n("nothing to do")); 902 i18n("nothing to do"));
903 return; 903 return;
904 } 904 }
905 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 905 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
906 QString fn(KFileDialog::getSaveFileName(QString::null, 906 QString fn(KFileDialog::getSaveFileName(QString::null,
907 i18n("*|plain-text file"), 907 i18n("*|plain-text file"),
908 this)); 908 this));
909 if (fn == "") { 909 if (fn == "") {
910 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 910 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
911 return; 911 return;
912 } 912 }
913 913
914 PwMerror ret = curDoc()->exportToText(&fn); 914 PwMerror ret = curDoc()->exportToText(&fn);
915 if (ret != e_success) { 915 if (ret != e_success) {
916 KMessageBox::error(this, 916 KMessageBox::error(this,
917 i18n("Error: Couldn't write to file.\n" 917 i18n("Error: Couldn't write to file.\n"
918 "Please check if you have permission to write " 918 "Please check if you have permission to write\n"
919 "to the file in that directory."), 919 "to the file in that directory."),
920 i18n("error while writing")); 920 i18n("error while writing"));
921 } else 921 } else
922 showStatMsg(i18n("Successfully exported data.")); 922 showStatMsg(i18n("Successfully exported data."));
923 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 923 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
924} 924}
925 925
926bool PwM::importFromText() 926bool PwM::importFromText()
927{ 927{
928 if (!isVirgin()) { 928 if (!isVirgin()) {
929 if (KMessageBox::questionYesNo(this, 929 if (KMessageBox::questionYesNo(this,
930 i18n("Do you want to import the data " 930 i18n("Do you want to import the data\n"
931 "into the current document? (If you " 931 "into the current document? (If you\n"
932 "select \"no\", a new document will be " 932 "select \"no\", a new document will be\n"
933 "opened.)"), 933 "opened.)"),
934 i18n("import into this document?")) 934 i18n("import into this document?"))
935 == KMessageBox::No) { 935 == KMessageBox::No) {
936 // import the data to a new window. 936 // import the data to a new window.
937 PwM *newInstance = init->createMainWnd(); 937 PwM *newInstance = init->createMainWnd();
938 bool ok = newInstance->importFromText(); 938 bool ok = newInstance->importFromText();
939 if (!ok) { 939 if (!ok) {
940 newInstance->setForceQuit(true); 940 newInstance->setForceQuit(true);
941 delete_and_null(newInstance); 941 delete_and_null(newInstance);
942 } 942 }
943 return ok; 943 return ok;
944 } 944 }
945 } 945 }
946 946
947 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 947 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
948 PwMerror ret; 948 PwMerror ret;
949 QString path(KFileDialog::getOpenFileName(QString::null, 949 QString path(KFileDialog::getOpenFileName(QString::null,
950 i18n("*|PWM-exported text file"), 950 i18n("*|PWM-exported text file"),
951 this)); 951 this));
952 if (path == "") 952 if (path == "")
953 goto cancelImport; 953 goto cancelImport;
954 954
955 ret = curDoc()->importFromText(&path, 0); 955 ret = curDoc()->importFromText(&path, 0);
956 if (ret == e_fileFormat) { 956 if (ret == e_fileFormat) {
957 KMessageBox::error(this, 957 KMessageBox::error(this,
958 i18n("Could not read file-format.\n" 958 i18n("Could not read file-format.\n"
959 "This seems to be _not_ a valid file " 959 "This seems to be _not_ a valid file\n"
960 "exported by PwM."), 960 "exported by PwM."),
961 i18n("invalid file-format")); 961 i18n("invalid file-format"));
962 goto cancelImport; 962 goto cancelImport;
963 } else if (ret == e_invalidArg) { 963 } else if (ret == e_invalidArg) {
964 BUG(); 964 BUG();
965 goto cancelImport; 965 goto cancelImport;
966 } else if (ret != e_success) { 966 } else if (ret != e_success) {
967 KMessageBox::error(this, 967 KMessageBox::error(this,
968 i18n("Could not import file!\n" 968 i18n("Could not import file!\n"
969 "Do you have permission to read this file? " 969 "Do you have permission to read this file?\n"
970 "Do you have enough free memory?"), 970 "Do you have enough free memory?"),
971 i18n("import failed")); 971 i18n("import failed"));
972 goto cancelImport; 972 goto cancelImport;
973 } 973 }
974 setVirgin(false); 974 setVirgin(false);
975 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 975 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
976 return true; 976 return true;
977 977
978cancelImport: 978cancelImport:
979 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 979 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
980 return false; 980 return false;
981} 981}
982 982
983void PwM::exportToGpasman() 983void PwM::exportToGpasman()
984{ 984{
985 PWM_ASSERT(curDoc()); 985 PWM_ASSERT(curDoc());
986 if (curDoc()->isDocEmpty()) { 986 if (curDoc()->isDocEmpty()) {
987 KMessageBox::information(this, 987 KMessageBox::information(this,
988 i18n 988 i18n
989 ("Sorry, there's nothing to export.\n" 989 ("Sorry, there's nothing to export.\n"
990 "Please first add some passwords."), 990 "Please first add some passwords."),
991 i18n("nothing to do")); 991 i18n("nothing to do"));
992 return; 992 return;
993 } 993 }
994 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 994 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
995 QString fn(KFileDialog::getSaveFileName(QString::null, 995 QString fn(KFileDialog::getSaveFileName(QString::null,
996 i18n("*|Gpasman or Kpasman file"), 996 i18n("*|Gpasman or Kpasman file"),
997 this)); 997 this));
998 if (fn == "") { 998 if (fn == "") {
999 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 999 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1000 return; 1000 return;
1001 } 1001 }
1002 1002
1003 PwMerror ret = curDoc()->exportToGpasman(&fn); 1003 PwMerror ret = curDoc()->exportToGpasman(&fn);
1004 if (ret != e_success) { 1004 if (ret != e_success) {
1005 if (ret == e_noPw) { 1005 if (ret == e_noPw) {
1006 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1006 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1007 return; 1007 return;
1008 } 1008 }
1009 KMessageBox::error(this, 1009 KMessageBox::error(this,
1010 i18n("Error: Couldn't write to file.\n" 1010 i18n("Error: Couldn't write to file.\n"
1011 "Please check if you have permission to write " 1011 "Please check if you have permission to write "
1012 "to the file in that directory."), 1012 "to the file in that directory."),
1013 i18n("error while writing")); 1013 i18n("error while writing"));
1014 } else 1014 } else
1015 showStatMsg(i18n("Successfully exported data.")); 1015 showStatMsg(i18n("Successfully exported data."));
1016 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1016 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1017} 1017}
1018 1018
1019void PwM::exportToKWallet() 1019void PwM::exportToKWallet()
1020{ 1020{
1021#ifdef CONFIG_KWALLETIF 1021#ifdef CONFIG_KWALLETIF
1022 if (!checkAndAskForKWalletEmu()) 1022 if (!checkAndAskForKWalletEmu())
1023 return; 1023 return;
1024 PWM_ASSERT(curDoc()); 1024 PWM_ASSERT(curDoc());
1025 if (curDoc()->isDocEmpty()) { 1025 if (curDoc()->isDocEmpty()) {
1026 KMessageBox::information(this, 1026 KMessageBox::information(this,
1027 i18n 1027 i18n
1028 ("Sorry, there's nothing to export.\n" 1028 ("Sorry, there's nothing to export.\n"
1029 "Please first add some passwords."), 1029 "Please first add some passwords."),
1030 i18n("nothing to do")); 1030 i18n("nothing to do"));
1031 init->initKWalletEmu(); 1031 init->initKWalletEmu();
1032 return; 1032 return;
1033 } 1033 }
1034 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1034 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1035 KWalletIf walletIf(this); 1035 KWalletIf walletIf(this);
1036 if (walletIf.kwalletExport(curDoc())) { 1036 if (walletIf.kwalletExport(curDoc())) {
1037 KMessageBox::information(this, 1037 KMessageBox::information(this,
1038 i18n("Successfully exported the data of the current " 1038 i18n("Successfully exported the data of the current "
1039 "document to KWallet."), 1039 "document to KWallet."),
1040 i18n("Successfully exported data.")); 1040 i18n("Successfully exported data."));
1041 showStatMsg(i18n("Successfully exported data.")); 1041 showStatMsg(i18n("Successfully exported data."));
1042 } 1042 }
1043 init->initKWalletEmu(); 1043 init->initKWalletEmu();
1044 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1044 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1045#endif // CONFIG_KWALLETIF 1045#endif // CONFIG_KWALLETIF
1046} 1046}
1047 1047
1048bool PwM::importFromGpasman() 1048bool PwM::importFromGpasman()
1049{ 1049{
1050 if (!isVirgin()) { 1050 if (!isVirgin()) {
1051 if (KMessageBox::questionYesNo(this, 1051 if (KMessageBox::questionYesNo(this,
1052 i18n("Do you want to import the data " 1052 i18n("Do you want to import the data\n"
1053 "into the current document? (If you " 1053 "into the current document? (If you\n"
1054 "select \"no\", a new document will be " 1054 "select \"no\", a new document will be\n"
1055 "opened.)"), 1055 "opened.)"),
1056 i18n("import into this document?")) 1056 i18n("import into this document?"))
1057 == KMessageBox::No) { 1057 == KMessageBox::No) {
1058 // import the data to a new window. 1058 // import the data to a new window.
1059 PwM *newInstance = init->createMainWnd(); 1059 PwM *newInstance = init->createMainWnd();
1060 bool ok = newInstance->importFromGpasman(); 1060 bool ok = newInstance->importFromGpasman();
1061 if (!ok) { 1061 if (!ok) {
1062 newInstance->setForceQuit(true); 1062 newInstance->setForceQuit(true);
1063 delete_and_null(newInstance); 1063 delete_and_null(newInstance);
1064 } 1064 }
1065 return ok; 1065 return ok;
1066 } 1066 }
1067 } 1067 }
1068 1068
1069 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1069 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1070 PwMerror ret; 1070 PwMerror ret;
1071 QString path(KFileDialog::getOpenFileName(QString::null, 1071 QString path(KFileDialog::getOpenFileName(QString::null,
1072 i18n("*|Gpasman or Kpasman file"), this)); 1072 i18n("*|Gpasman or Kpasman file"), this));
1073 if (path == "") 1073 if (path == "")
1074 goto cancelImport; 1074 goto cancelImport;
1075 ret = curDoc()->importFromGpasman(&path); 1075 ret = curDoc()->importFromGpasman(&path);
1076 if (ret == e_wrongPw) { 1076 if (ret == e_wrongPw) {
1077 if (KMessageBox::questionYesNo(this, 1077 if (KMessageBox::questionYesNo(this,
1078 i18n 1078 i18n
1079 ("This is probably the wrong master-password" 1079 ("This is probably the wrong master-password\n"
1080 "you have typed in.\n" 1080 "you have typed in.\n"
1081 "There is no real way to determine the " 1081 "There is no real way to determine the\n"
1082 "correctness of the password in the Gpasman " 1082 "correctness of the password in the Gpasman\n"
1083 "file-format. But I think this " 1083 "file-format. But I think this\n"
1084 "password ist wrong.\n" 1084 "password ist wrong.\n"
1085 "Do you want to continue nevertheless?"), 1085 "Do you want to continue nevertheless?"),
1086 i18n("password error")) 1086 i18n("password error"))
1087 == KMessageBox::No) { 1087 == KMessageBox::No) {
1088 goto cancelImport; 1088 goto cancelImport;
1089 } 1089 }
1090 } else if (ret != e_success) { 1090 } else if (ret != e_success) {
1091 KMessageBox::error(this, 1091 KMessageBox::error(this,
1092 i18n("Could not import file!\n" 1092 i18n("Could not import file!\n"
1093 "Do you have permission to read this file?"), 1093 "Do you have permission to read this file?"),
1094 i18n("import failed")); 1094 i18n("import failed"));
1095 goto cancelImport; 1095 goto cancelImport;
1096 } 1096 }
1097 setVirgin(false); 1097 setVirgin(false);
1098 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1098 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1099 return true; 1099 return true;
1100 1100
1101cancelImport: 1101cancelImport:
1102 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1102 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1103 return false; 1103 return false;
1104} 1104}
1105 1105
1106#ifdef CONFIG_KWALLETIF 1106#ifdef CONFIG_KWALLETIF
1107bool PwM::checkAndAskForKWalletEmu() 1107bool PwM::checkAndAskForKWalletEmu()
1108{ 1108{
1109 if (init->kwalletEmu()) { 1109 if (init->kwalletEmu()) {
1110 /* KWallet emulation is enabled. We can't import/export 1110 /* KWallet emulation is enabled. We can't import/export
1111 * data from/to it, while emulation is active. 1111 * data from/to it, while emulation is active.
1112 */ 1112 */
1113 if (KMessageBox::questionYesNo(this, 1113 if (KMessageBox::questionYesNo(this,
1114 i18n("KWallet emulation is enabled.\n" 1114 i18n("KWallet emulation is enabled.\n"
1115 "You can't import or export data from/to " 1115 "You can't import or export data from/to "
1116 "the original KWallet, while the emulation " 1116 "the original KWallet, while the emulation "
1117 "is active.\n" 1117 "is active.\n"
1118 "Do you want to tempoarly disable the KWallet emulation?"), 1118 "Do you want to tempoarly disable the KWallet emulation?"),
1119 i18n("Tempoarly disable KWallet emulation?")) 1119 i18n("Tempoarly disable KWallet emulation?"))
1120 == KMessageBox::Yes) { 1120 == KMessageBox::Yes) {
1121 init->initKWalletEmu(true); 1121 init->initKWalletEmu(true);
1122 PWM_ASSERT(!init->kwalletEmu()); 1122 PWM_ASSERT(!init->kwalletEmu());
1123 return true; 1123 return true;
1124 } 1124 }
1125 return false; 1125 return false;
1126 } 1126 }
1127 return true; 1127 return true;
1128} 1128}
1129#endif // CONFIG_KWALLETIF 1129#endif // CONFIG_KWALLETIF
1130 1130
1131bool PwM::importKWallet() 1131bool PwM::importKWallet()
1132{ 1132{
1133#ifdef CONFIG_KWALLETIF 1133#ifdef CONFIG_KWALLETIF
1134 if (!checkAndAskForKWalletEmu()) 1134 if (!checkAndAskForKWalletEmu())
1135 return false; 1135 return false;
1136 KWalletIf walletIf(this); 1136 KWalletIf walletIf(this);
1137 if (!isVirgin()) { 1137 if (!isVirgin()) {
1138 if (KMessageBox::questionYesNo(this, 1138 if (KMessageBox::questionYesNo(this,
1139 i18n("Do you want to import the data " 1139 i18n("Do you want to import the data "
1140 "into the current document? (If you " 1140 "into the current document? (If you "
1141 "select \"no\", a new document will be " 1141 "select \"no\", a new document will be "
1142 "opened.)"), 1142 "opened.)"),
1143 i18n("import into this document?")) 1143 i18n("import into this document?"))
1144 == KMessageBox::No) { 1144 == KMessageBox::No) {
1145 // import the data to a new window. 1145 // import the data to a new window.
1146 PwM *newInstance = init->createMainWnd(); 1146 PwM *newInstance = init->createMainWnd();
1147 bool ok = newInstance->importKWallet(); 1147 bool ok = newInstance->importKWallet();
1148 if (!ok) { 1148 if (!ok) {
1149 newInstance->setForceQuit(true); 1149 newInstance->setForceQuit(true);
1150 delete_and_null(newInstance); 1150 delete_and_null(newInstance);
1151 goto exit_fail; 1151 goto exit_fail;
1152 } else { 1152 } else {
1153 goto exit_ok; 1153 goto exit_ok;
1154 } 1154 }
1155 } 1155 }
1156 } 1156 }
1157 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1157 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1158 if (!walletIf.kwalletImport(curDoc())) { 1158 if (!walletIf.kwalletImport(curDoc())) {
1159 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1159 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1160 showStatMsg(i18n("KWallet import failed")); 1160 showStatMsg(i18n("KWallet import failed"));
1161 goto exit_fail; 1161 goto exit_fail;
1162 } 1162 }
1163 KMessageBox::information(this, 1163 KMessageBox::information(this,
1164 i18n("Successfully imported the KWallet data " 1164 i18n("Successfully imported the KWallet data "
1165 "into the current document."), 1165 "into the current document."),
1166 i18n("successfully imported")); 1166 i18n("successfully imported"));
1167 showStatMsg(i18n("successfully imported")); 1167 showStatMsg(i18n("successfully imported"));
1168 setVirgin(false); 1168 setVirgin(false);
1169 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1169 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1170 1170
1171exit_ok: 1171exit_ok:
1172 init->initKWalletEmu(); 1172 init->initKWalletEmu();
1173 return true; 1173 return true;
1174 1174
1175exit_fail: 1175exit_fail:
1176 init->initKWalletEmu(); 1176 init->initKWalletEmu();
1177#endif // CONFIG_KWALLETIF 1177#endif // CONFIG_KWALLETIF
1178 return false; 1178 return false;
1179} 1179}
1180 1180
1181void PwM::print_slot() 1181void PwM::print_slot()
1182{ 1182{
1183 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1183 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1184#ifndef PWM_EMBEDDED 1184#ifndef PWM_EMBEDDED
1185 PwMPrint p(curDoc(), this); 1185 PwMPrint p(curDoc(), this);
1186 p.printNow(); 1186 p.printNow();
1187#else 1187#else
1188 qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); 1188 qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED");
1189#endif 1189#endif
1190 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1190 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1191} 1191}
1192 1192
1193void PwM::genNewCard_slot() 1193void PwM::genNewCard_slot()
1194{ 1194{
1195#ifdef CONFIG_KEYCARD 1195#ifdef CONFIG_KEYCARD
1196 init->keycard()->genNewCard(); 1196 init->keycard()->genNewCard();
1197#endif 1197#endif
1198} 1198}
1199 1199
1200void PwM::eraseCard_slot() 1200void PwM::eraseCard_slot()
1201{ 1201{
1202#ifdef CONFIG_KEYCARD 1202#ifdef CONFIG_KEYCARD
1203 init->keycard()->eraseCard(); 1203 init->keycard()->eraseCard();
1204#endif 1204#endif
1205} 1205}
1206 1206
1207void PwM::readCardId_slot() 1207void PwM::readCardId_slot()
1208{ 1208{
1209#ifdef CONFIG_KEYCARD 1209#ifdef CONFIG_KEYCARD
1210 init->keycard()->displayKey(); 1210 init->keycard()->displayKey();
1211#endif 1211#endif
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 8869f3a..86b6273 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -1139,281 +1139,287 @@ bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory,
1139 if (!delEntry(oldCategory, index, true)) 1139 if (!delEntry(oldCategory, index, true))
1140 return false; 1140 return false;
1141 } else { 1141 } else {
1142 d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. 1142 d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter.
1143 dti.dta[oldCategory].d[index] = *d; 1143 dti.dta[oldCategory].d[index] = *d;
1144 } 1144 }
1145 flagDirty(); 1145 flagDirty();
1146 return true; 1146 return true;
1147} 1147}
1148 1148
1149unsigned int PwMDoc::numEntries(const QString &category) 1149unsigned int PwMDoc::numEntries(const QString &category)
1150{ 1150{
1151 unsigned int cat = 0; 1151 unsigned int cat = 0;
1152 1152
1153 if (!findCategory(category, &cat)) { 1153 if (!findCategory(category, &cat)) {
1154 BUG(); 1154 BUG();
1155 return 0; 1155 return 0;
1156 } 1156 }
1157 1157
1158 return numEntries(cat); 1158 return numEntries(cat);
1159} 1159}
1160 1160
1161bool PwMDoc::serializeDta(string *d) 1161bool PwMDoc::serializeDta(string *d)
1162{ 1162{
1163 PWM_ASSERT(d); 1163 PWM_ASSERT(d);
1164 Serializer ser; 1164 Serializer ser;
1165 if (!ser.serialize(dti)) 1165 if (!ser.serialize(dti))
1166 return false; 1166 return false;
1167 d->assign(ser.getXml()); 1167 d->assign(ser.getXml());
1168 if (!d->size()) 1168 if (!d->size())
1169 return false; 1169 return false;
1170 return true; 1170 return true;
1171} 1171}
1172 1172
1173bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) 1173bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked)
1174{ 1174{
1175 PWM_ASSERT(d); 1175 PWM_ASSERT(d);
1176#ifndef PWM_EMBEDDED 1176#ifndef PWM_EMBEDDED
1177 try { 1177 try {
1178 1178
1179 Serializer ser(d->c_str()); 1179 Serializer ser(d->c_str());
1180 ser.setDefaultLockStat(entriesLocked); 1180 ser.setDefaultLockStat(entriesLocked);
1181 if (!ser.deSerialize(&dti)) 1181 if (!ser.deSerialize(&dti))
1182 return false; 1182 return false;
1183 } catch (PwMException) { 1183 } catch (PwMException) {
1184 return false; 1184 return false;
1185 } 1185 }
1186#else 1186#else
1187 Serializer ser(d->c_str()); 1187 Serializer ser(d->c_str());
1188 ser.setDefaultLockStat(entriesLocked); 1188 ser.setDefaultLockStat(entriesLocked);
1189 if (!ser.deSerialize(&dti)) 1189 if (!ser.deSerialize(&dti))
1190 return false; 1190 return false;
1191#endif 1191#endif
1192 1192
1193 emitDataChanged(this); 1193 emitDataChanged(this);
1194 return true; 1194 return true;
1195} 1195}
1196 1196
1197bool PwMDoc::getEntry(const QString &category, unsigned int index, 1197bool PwMDoc::getEntry(const QString &category, unsigned int index,
1198 PwMDataItem * d, bool unlockIfLocked) 1198 PwMDataItem * d, bool unlockIfLocked)
1199{ 1199{
1200 PWM_ASSERT(d); 1200 PWM_ASSERT(d);
1201 unsigned int cat = 0; 1201 unsigned int cat = 0;
1202 1202
1203 if (!findCategory(category, &cat)) { 1203 if (!findCategory(category, &cat)) {
1204 BUG(); 1204 BUG();
1205 return false; 1205 return false;
1206 } 1206 }
1207 1207
1208 return getEntry(cat, index, d, unlockIfLocked); 1208 return getEntry(cat, index, d, unlockIfLocked);
1209} 1209}
1210 1210
1211bool PwMDoc::getEntry(unsigned int category, unsigned int index, 1211bool PwMDoc::getEntry(unsigned int category, unsigned int index,
1212 PwMDataItem *d, bool unlockIfLocked) 1212 PwMDataItem *d, bool unlockIfLocked)
1213{ 1213{
1214 if (index > dti.dta[category].d.size() - 1) 1214 if (index > dti.dta[category].d.size() - 1)
1215 return false; 1215 return false;
1216 1216
1217 bool locked = isLocked(category, index); 1217 bool locked = isLocked(category, index);
1218 if (locked) { 1218 if (locked) {
1219 /* this entry is locked. We don't return a password, 1219 /* this entry is locked. We don't return a password,
1220 * until it's unlocked by the user by inserting 1220 * until it's unlocked by the user by inserting
1221 * chipcard or entering the mpw 1221 * chipcard or entering the mpw
1222 */ 1222 */
1223 if (unlockIfLocked) { 1223 if (unlockIfLocked) {
1224 if (!lockAt(category, index, false)) { 1224 if (!lockAt(category, index, false)) {
1225 return false; 1225 return false;
1226 } 1226 }
1227 locked = false; 1227 locked = false;
1228 } 1228 }
1229 } 1229 }
1230 1230
1231 *d = dti.dta[category].d[index]; 1231 *d = dti.dta[category].d[index];
1232 if (locked) 1232 if (locked)
1233 d->pw = LOCKED_STRING.latin1(); 1233 d->pw = LOCKED_STRING.latin1();
1234 1234
1235 return true; 1235 return true;
1236} 1236}
1237 1237
1238PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, 1238PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos,
1239 string *foundComment) 1239 string *foundComment)
1240{ 1240{
1241 PWM_ASSERT(foundComment); 1241 PWM_ASSERT(foundComment);
1242 unsigned int cat = 0; 1242 unsigned int cat = 0;
1243 1243
1244 if (!findCategory(category, &cat)) 1244 if (!findCategory(category, &cat))
1245 return e_invalidArg; 1245 return e_invalidArg;
1246 1246
1247 unsigned int i, entries = numEntries(cat); 1247 unsigned int i, entries = numEntries(cat);
1248 for (i = 0; i < entries; ++i) { 1248 for (i = 0; i < entries; ++i) {
1249 if (dti.dta[cat].d[i].listViewPos == listViewPos) { 1249 if (dti.dta[cat].d[i].listViewPos == listViewPos) {
1250 *foundComment = dti.dta[cat].d[i].comment; 1250 *foundComment = dti.dta[cat].d[i].comment;
1251 if (dti.dta[cat].d[i].binary) 1251 if (dti.dta[cat].d[i].binary)
1252 return e_binEntry; 1252 return e_binEntry;
1253 return e_normalEntry; 1253 return e_normalEntry;
1254 } 1254 }
1255 } 1255 }
1256 BUG(); 1256 BUG();
1257 return e_generic; 1257 return e_generic;
1258} 1258}
1259 1259
1260bool PwMDoc::compressDta(string *d, char algo) 1260bool PwMDoc::compressDta(string *d, char algo)
1261{ 1261{
1262 PWM_ASSERT(d); 1262 PWM_ASSERT(d);
1263 switch (algo) { 1263 switch (algo) {
1264 case PWM_COMPRESS_GZIP: { 1264 case PWM_COMPRESS_GZIP: {
1265 CompressGzip comp; 1265 CompressGzip comp;
1266 return comp.compress(d); 1266 return comp.compress(d);
1267 /*US } case PWM_COMPRESS_BZIP2: { 1267 }
1268#ifndef PWM_EMBEDDED
1269 case PWM_COMPRESS_BZIP2: {
1268 CompressBzip2 comp; 1270 CompressBzip2 comp;
1269 return comp.compress(d); 1271 return comp.compress(d);
1270*/ 1272 }
1271 } case PWM_COMPRESS_NONE: { 1273#endif
1274 case PWM_COMPRESS_NONE: {
1272 return true; 1275 return true;
1273 } default: { 1276 } default: {
1274 BUG(); 1277 BUG();
1275 } 1278 }
1276 } 1279 }
1277 return false; 1280 return false;
1278} 1281}
1279 1282
1280bool PwMDoc::decompressDta(string *d, char algo) 1283bool PwMDoc::decompressDta(string *d, char algo)
1281{ 1284{
1282 PWM_ASSERT(d); 1285 PWM_ASSERT(d);
1283 switch (algo) { 1286 switch (algo) {
1284 case PWM_COMPRESS_GZIP: { 1287 case PWM_COMPRESS_GZIP: {
1285 CompressGzip comp; 1288 CompressGzip comp;
1286 return comp.decompress(d); 1289 return comp.decompress(d);
1287 /*US } case PWM_COMPRESS_BZIP2: { 1290 }
1291#ifndef PWM_EMBEDDED
1292 case PWM_COMPRESS_BZIP2: {
1288 CompressBzip2 comp; 1293 CompressBzip2 comp;
1289 return comp.decompress(d); 1294 return comp.decompress(d);
1290 */ 1295 }
1291 } case PWM_COMPRESS_NONE: { 1296#endif
1297 case PWM_COMPRESS_NONE: {
1292 return true; 1298 return true;
1293 } 1299 }
1294 } 1300 }
1295 return false; 1301 return false;
1296} 1302}
1297 1303
1298PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) 1304PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo)
1299{ 1305{
1300 PWM_ASSERT(d); 1306 PWM_ASSERT(d);
1301 PWM_ASSERT(pw); 1307 PWM_ASSERT(pw);
1302 PWM_ASSERT(f); 1308 PWM_ASSERT(f);
1303 1309
1304 size_t encSize; 1310 size_t encSize;
1305 byte *encrypted = 0; 1311 byte *encrypted = 0;
1306 1312
1307 switch (algo) { 1313 switch (algo) {
1308 case PWM_CRYPT_BLOWFISH: { 1314 case PWM_CRYPT_BLOWFISH: {
1309 Blowfish::padNull(d); 1315 Blowfish::padNull(d);
1310 encSize = d->length(); 1316 encSize = d->length();
1311 encrypted = new byte[encSize]; 1317 encrypted = new byte[encSize];
1312 Blowfish bf; 1318 Blowfish bf;
1313 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { 1319 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) {
1314 delete [] encrypted; 1320 delete [] encrypted;
1315 return e_weakPw; 1321 return e_weakPw;
1316 } 1322 }
1317 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); 1323 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize);
1318 break; 1324 break;
1319 } 1325 }
1320 case PWM_CRYPT_AES128: 1326 case PWM_CRYPT_AES128:
1321 /*... fall through */ 1327 /*... fall through */
1322 case PWM_CRYPT_AES192: 1328 case PWM_CRYPT_AES192:
1323 case PWM_CRYPT_AES256: 1329 case PWM_CRYPT_AES256:
1324 case PWM_CRYPT_3DES: 1330 case PWM_CRYPT_3DES:
1325 case PWM_CRYPT_TWOFISH: 1331 case PWM_CRYPT_TWOFISH:
1326 case PWM_CRYPT_TWOFISH128: { 1332 case PWM_CRYPT_TWOFISH128: {
1327 if (!LibGCryptIf::available()) 1333 if (!LibGCryptIf::available())
1328 return e_cryptNotImpl; 1334 return e_cryptNotImpl;
1329 LibGCryptIf gc; 1335 LibGCryptIf gc;
1330 PwMerror err; 1336 PwMerror err;
1331 unsigned char *plain = new unsigned char[d->length() + 1024]; 1337 unsigned char *plain = new unsigned char[d->length() + 1024];
1332 memcpy(plain, d->c_str(), d->length()); 1338 memcpy(plain, d->c_str(), d->length());
1333 err = gc.encrypt(&encrypted, 1339 err = gc.encrypt(&encrypted,
1334 &encSize, 1340 &encSize,
1335 plain, 1341 plain,
1336 d->length(), 1342 d->length(),
1337 reinterpret_cast<const unsigned char *>(pw->latin1()), 1343 reinterpret_cast<const unsigned char *>(pw->latin1()),
1338 pw->length(), 1344 pw->length(),
1339 algo); 1345 algo);
1340 delete [] plain; 1346 delete [] plain;
1341 if (err != e_success) 1347 if (err != e_success)
1342 return e_cryptNotImpl; 1348 return e_cryptNotImpl;
1343 break; 1349 break;
1344 } 1350 }
1345 default: { 1351 default: {
1346 delete_ifnot_null_array(encrypted); 1352 delete_ifnot_null_array(encrypted);
1347 return e_cryptNotImpl; 1353 return e_cryptNotImpl;
1348 } } 1354 } }
1349 1355
1350 // write encrypted data to file 1356 // write encrypted data to file
1351 if (f->writeBlock(reinterpret_cast<const char *>(encrypted), 1357 if (f->writeBlock(reinterpret_cast<const char *>(encrypted),
1352 static_cast<Q_ULONG>(encSize)) 1358 static_cast<Q_ULONG>(encSize))
1353 != static_cast<Q_LONG>(encSize)) { 1359 != static_cast<Q_LONG>(encSize)) {
1354 delete_ifnot_null_array(encrypted); 1360 delete_ifnot_null_array(encrypted);
1355 return e_writeFile; 1361 return e_writeFile;
1356 } 1362 }
1357 delete_ifnot_null_array(encrypted); 1363 delete_ifnot_null_array(encrypted);
1358 return e_success; 1364 return e_success;
1359} 1365}
1360 1366
1361PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, 1367PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw,
1362 char algo, QFile *f) 1368 char algo, QFile *f)
1363{ 1369{
1364 PWM_ASSERT(d); 1370 PWM_ASSERT(d);
1365 PWM_ASSERT(pw); 1371 PWM_ASSERT(pw);
1366 PWM_ASSERT(f); 1372 PWM_ASSERT(f);
1367 1373
1368 unsigned int cryptLen = f->size() - pos; 1374 unsigned int cryptLen = f->size() - pos;
1369 byte *encrypted = new byte[cryptLen]; 1375 byte *encrypted = new byte[cryptLen];
1370 byte *decrypted = new byte[cryptLen]; 1376 byte *decrypted = new byte[cryptLen];
1371 1377
1372 f->at(pos); 1378 f->at(pos);
1373#ifndef PWM_EMBEDDED 1379#ifndef PWM_EMBEDDED
1374 if (f->readBlock(reinterpret_cast<char *>(encrypted), 1380 if (f->readBlock(reinterpret_cast<char *>(encrypted),
1375 static_cast<Q_ULONG>(cryptLen)) 1381 static_cast<Q_ULONG>(cryptLen))
1376 != static_cast<Q_LONG>(cryptLen)) { 1382 != static_cast<Q_LONG>(cryptLen)) {
1377 delete [] encrypted; 1383 delete [] encrypted;
1378 delete [] decrypted; 1384 delete [] decrypted;
1379 return e_readFile; 1385 return e_readFile;
1380 } 1386 }
1381#else 1387#else
1382 if (f->readBlock((char *)(encrypted), 1388 if (f->readBlock((char *)(encrypted),
1383 (unsigned long)(cryptLen)) 1389 (unsigned long)(cryptLen))
1384 != (long)(cryptLen)) { 1390 != (long)(cryptLen)) {
1385 delete [] encrypted; 1391 delete [] encrypted;
1386 delete [] decrypted; 1392 delete [] decrypted;
1387 return e_readFile; 1393 return e_readFile;
1388 } 1394 }
1389#endif 1395#endif
1390 switch (algo) { 1396 switch (algo) {
1391 case PWM_CRYPT_BLOWFISH: { 1397 case PWM_CRYPT_BLOWFISH: {
1392 Blowfish bf; 1398 Blowfish bf;
1393 bf.bf_setkey((byte *) pw->latin1(), pw->length()); 1399 bf.bf_setkey((byte *) pw->latin1(), pw->length());
1394 bf.bf_decrypt(decrypted, encrypted, cryptLen); 1400 bf.bf_decrypt(decrypted, encrypted, cryptLen);
1395 break; 1401 break;
1396 } 1402 }
1397 case PWM_CRYPT_AES128: 1403 case PWM_CRYPT_AES128:
1398 /*... fall through */ 1404 /*... fall through */
1399 case PWM_CRYPT_AES192: 1405 case PWM_CRYPT_AES192:
1400 case PWM_CRYPT_AES256: 1406 case PWM_CRYPT_AES256:
1401 case PWM_CRYPT_3DES: 1407 case PWM_CRYPT_3DES:
1402 case PWM_CRYPT_TWOFISH: 1408 case PWM_CRYPT_TWOFISH:
1403 case PWM_CRYPT_TWOFISH128: { 1409 case PWM_CRYPT_TWOFISH128: {
1404 if (!LibGCryptIf::available()) 1410 if (!LibGCryptIf::available())
1405 return e_cryptNotImpl; 1411 return e_cryptNotImpl;
1406 LibGCryptIf gc; 1412 LibGCryptIf gc;
1407 PwMerror err; 1413 PwMerror err;
1408 err = gc.decrypt(&decrypted, 1414 err = gc.decrypt(&decrypted,
1409 &cryptLen, 1415 &cryptLen,
1410 encrypted, 1416 encrypted,
1411 cryptLen, 1417 cryptLen,
1412 reinterpret_cast<const unsigned char *>(pw->latin1()), 1418 reinterpret_cast<const unsigned char *>(pw->latin1()),
1413 pw->length(), 1419 pw->length(),
1414 algo); 1420 algo);
1415 if (err != e_success) { 1421 if (err != e_success) {
1416 delete [] encrypted; 1422 delete [] encrypted;
1417 delete [] decrypted; 1423 delete [] decrypted;
1418 return e_cryptNotImpl; 1424 return e_cryptNotImpl;
1419 } 1425 }
@@ -2998,355 +3004,348 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
2998 int deletedPasswordsRemote = 0; 3004 int deletedPasswordsRemote = 0;
2999 int deletedPasswordsLocal = 0; 3005 int deletedPasswordsLocal = 0;
3000 int changedLocal = 0; 3006 int changedLocal = 0;
3001 int changedRemote = 0; 3007 int changedRemote = 0;
3002 3008
3003 PwMSyncItem* syncItemLocal; 3009 PwMSyncItem* syncItemLocal;
3004 PwMSyncItem* syncItemRemote; 3010 PwMSyncItem* syncItemRemote;
3005 3011
3006 QString mCurrentSyncName = manager->getCurrentSyncName(); 3012 QString mCurrentSyncName = manager->getCurrentSyncName();
3007 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3013 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3008 3014
3009 bool fullDateRange = false; 3015 bool fullDateRange = false;
3010 int take; 3016 int take;
3011 // local->resetTempSyncStat(); 3017 // local->resetTempSyncStat();
3012 QDateTime mLastSync = QDateTime::currentDateTime(); 3018 QDateTime mLastSync = QDateTime::currentDateTime();
3013 QDateTime modifiedSync = mLastSync; 3019 QDateTime modifiedSync = mLastSync;
3014 3020
3015 unsigned int index; 3021 unsigned int index;
3016 //Step 1. Find syncinfo in Local file and create if not existent. 3022 //Step 1. Find syncinfo in Local file and create if not existent.
3017 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3023 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3018 if (found == false) 3024 if (found == false)
3019 { 3025 {
3020 PwMSyncItem newSyncItemLocal; 3026 PwMSyncItem newSyncItemLocal;
3021 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); 3027 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1();
3022 newSyncItemLocal.lastSyncDate = mLastSync; 3028 newSyncItemLocal.lastSyncDate = mLastSync;
3023 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 3029 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
3024 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3030 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3025 if (found == false) { 3031 if (found == false) {
3026 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 3032 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
3027 return e_syncError; 3033 return e_syncError;
3028 } 3034 }
3029 } 3035 }
3030 3036
3031 syncItemLocal = syncLocal->getSyncDataEntry(index); 3037 syncItemLocal = syncLocal->getSyncDataEntry(index);
3032 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); 3038 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
3033 3039
3034 //Step 2. Find syncinfo in remote file and create if not existent. 3040 //Step 2. Find syncinfo in remote file and create if not existent.
3035 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3041 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3036 if (found == false) 3042 if (found == false)
3037 { 3043 {
3038 qDebug("FULLDATE 1"); 3044 qDebug("FULLDATE 1");
3039 fullDateRange = true; 3045 fullDateRange = true;
3040 PwMSyncItem newSyncItemRemote; 3046 PwMSyncItem newSyncItemRemote;
3041 newSyncItemRemote.syncName = mCurrentSyncName.latin1(); 3047 newSyncItemRemote.syncName = mCurrentSyncName.latin1();
3042 newSyncItemRemote.lastSyncDate = mLastSync; 3048 newSyncItemRemote.lastSyncDate = mLastSync;
3043 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 3049 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
3044 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3050 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3045 if (found == false) { 3051 if (found == false) {
3046 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 3052 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
3047 return e_syncError; 3053 return e_syncError;
3048 } 3054 }
3049 } 3055 }
3050 3056
3051 syncItemRemote = syncRemote->getSyncDataEntry(index); 3057 syncItemRemote = syncRemote->getSyncDataEntry(index);
3052 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); 3058 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
3053 //and remove the found entry here. We will reenter it later again. 3059 //and remove the found entry here. We will reenter it later again.
3054 //US syncRemote->delSyncDataEntry(index, true); 3060 //US syncRemote->delSyncDataEntry(index, true);
3055 3061
3056 3062
3057 if ( syncItemLocal->lastSyncDate == mLastSync ) { 3063 if ( syncItemLocal->lastSyncDate == mLastSync ) {
3058 qDebug("FULLDATE 2"); 3064 qDebug("FULLDATE 2");
3059 fullDateRange = true; 3065 fullDateRange = true;
3060 } 3066 }
3061 3067
3062 if ( ! fullDateRange ) { 3068 if ( ! fullDateRange ) {
3063 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 3069 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
3064 3070
3065 fullDateRange = true; 3071 fullDateRange = true;
3066 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 3072 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
3067 } 3073 }
3068 } 3074 }
3069 // fullDateRange = true; // debug only! 3075 // fullDateRange = true; // debug only!
3070 if ( fullDateRange ) 3076 if ( fullDateRange )
3071 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 3077 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
3072 else 3078 else
3073 mLastSync = syncItemLocal->lastSyncDate; 3079 mLastSync = syncItemLocal->lastSyncDate;
3074 3080
3075 3081
3076 qDebug("*************************** "); 3082 qDebug("*************************** ");
3077 qDebug("mLastSync %s ",mLastSync.toString().latin1() ); 3083 qDebug("mLastSync %s ",mLastSync.toString().latin1() );
3078 QStringList er = syncRemote->getIDEntryList(); 3084 QStringList er = syncRemote->getIDEntryList();
3079 PwMDataItem* inRemote ;//= er.first(); 3085 PwMDataItem* inRemote ;//= er.first();
3080 PwMDataItem* inLocal; 3086 PwMDataItem* inLocal;
3081 unsigned int catLocal, indexLocal; 3087 unsigned int catLocal, indexLocal;
3082 unsigned int catRemote, indexRemote; 3088 unsigned int catRemote, indexRemote;
3083 3089
3084 QString uid; 3090 QString uid;
3085 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 3091 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
3086 3092
3087 int modulo = (er.count()/10)+1; 3093 int modulo = (er.count()/10)+1;
3088 unsigned int incCounter = 0; 3094 unsigned int incCounter = 0;
3089 while ( incCounter < er.count()) { 3095 while ( incCounter < er.count()) {
3090 if (manager->isProgressBarCanceled()) 3096 if (manager->isProgressBarCanceled())
3091 return e_syncError; 3097 return e_syncError;
3092 if ( incCounter % modulo == 0 ) 3098 if ( incCounter % modulo == 0 )
3093 manager->showProgressBar(incCounter); 3099 manager->showProgressBar(incCounter);
3094 3100
3095 uid = er[ incCounter ]; 3101 uid = er[ incCounter ];
3096 qDebug("sync uid %s from remote file", uid.latin1()); 3102 qDebug("sync uid %s from remote file", uid.latin1());
3097 3103
3098 qApp->processEvents(); 3104 qApp->processEvents();
3099 3105
3100 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3106 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3101 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3107 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3102 PWM_ASSERT(inRemote); 3108 PWM_ASSERT(inRemote);
3103 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3109 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3104 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3110 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3105 qDebug("take %d %s ", take, inLocal->desc.c_str()); 3111 qDebug("take %d %s ", take, inLocal->desc.c_str());
3106 if ( take == 3 ) 3112 if ( take == 3 )
3107 return e_syncError; 3113 return e_syncError;
3108 if ( take == 1 ) {// take local 3114 if ( take == 1 ) {// take local
3109 int oldlistpos = inRemote->listViewPos; 3115 int oldlistpos = inRemote->listViewPos;
3110 (*inRemote) = (*inLocal); 3116 (*inRemote) = (*inLocal);
3111 inRemote->listViewPos = oldlistpos; 3117 inRemote->listViewPos = oldlistpos;
3112 ++changedRemote; 3118 ++changedRemote;
3113 } else { // take == 2 take remote 3119 } else { // take == 2 take remote
3114 int oldlistpos = inLocal->listViewPos; 3120 int oldlistpos = inLocal->listViewPos;
3115 (*inLocal) = (*inRemote); 3121 (*inLocal) = (*inRemote);
3116 inLocal->listViewPos = oldlistpos; 3122 inLocal->listViewPos = oldlistpos;
3117 ++changedLocal; 3123 ++changedLocal;
3118 } 3124 }
3119 } 3125 }
3120 } else { // no conflict 3126 } else { // no conflict
3121 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3127 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3122 inRemote->meta.update = modifiedSync; 3128 inRemote->meta.update = modifiedSync;
3123 3129
3124 //first check if we have a matching category in the local file 3130 //first check if we have a matching category in the local file
3125 const string* remotecat = syncRemote->getCategory(catRemote); 3131 const string* remotecat = syncRemote->getCategory(catRemote);
3126 //US syncRemote->insertAddressee( inRemote, false );
3127 //US syncLocal->insertAddressee( inRemote, false );
3128 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3132 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3129 3133
3130 ++addedPasswordsLocal; 3134 ++addedPasswordsLocal;
3131 } else { 3135 } else {
3132 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3136 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3133 syncRemote->delEntry(catRemote, indexRemote, true); 3137 syncRemote->delEntry(catRemote, indexRemote, true);
3134 //USsyncRemote->removeAddressee( inRemote );
3135 ++deletedPasswordsRemote; 3138 ++deletedPasswordsRemote;
3136 } 3139 }
3137 } 3140 }
3138 3141
3139 ++incCounter; 3142 ++incCounter;
3140 } 3143 }
3141 3144
3142 3145
3143 er.clear(); 3146 er.clear();
3144 QStringList el = syncLocal->getIDEntryList(); 3147 QStringList el = syncLocal->getIDEntryList();
3145 modulo = (el.count()/10)+1; 3148 modulo = (el.count()/10)+1;
3146 3149
3147 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3150 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3148 incCounter = 0; 3151 incCounter = 0;
3149 while ( incCounter < el.count()) { 3152 while ( incCounter < el.count()) {
3150 qApp->processEvents(); 3153 qApp->processEvents();
3151 if (manager->isProgressBarCanceled()) 3154 if (manager->isProgressBarCanceled())
3152 return e_syncError; 3155 return e_syncError;
3153 if ( incCounter % modulo == 0 ) 3156 if ( incCounter % modulo == 0 )
3154 manager->showProgressBar(incCounter); 3157 manager->showProgressBar(incCounter);
3155 uid = el[ incCounter ]; 3158 uid = el[ incCounter ];
3156 qDebug("sync uid %s from local file", uid.latin1()); 3159 qDebug("sync uid %s from local file", uid.latin1());
3157 3160
3158 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3161 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3159 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3162 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3160 PWM_ASSERT(inLocal); 3163 PWM_ASSERT(inLocal);
3161 3164
3162 if ( inRemote == 0 ) { 3165 if ( inRemote == 0 ) {
3163 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3166 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3164 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3167 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3165 syncLocal->delEntry(catLocal, indexLocal, true); 3168 syncLocal->delEntry(catLocal, indexLocal, true);
3166 //USsyncLocal->removeAddressee( inLocal );
3167 ++deletedPasswordsLocal; 3169 ++deletedPasswordsLocal;
3168 } else { 3170 } else {
3169 if ( ! manager->mWriteBackExistingOnly ) { 3171 if ( ! manager->mWriteBackExistingOnly ) {
3170 ++addedPasswordsRemote; 3172 ++addedPasswordsRemote;
3171 inLocal->meta.update = modifiedSync; 3173 inLocal->meta.update = modifiedSync;
3172 3174
3173 //first check if we have a matching category in the remote file 3175 //first check if we have a matching category in the remote file
3174 const string* localcat = syncLocal->getCategory(catLocal); 3176 const string* localcat = syncLocal->getCategory(catLocal);
3175 3177
3176 //USsyncLocal->insertAddressee( inLocal, false );
3177 PwMDataItem newEntry; 3178 PwMDataItem newEntry;
3178 newEntry = *inLocal; 3179 newEntry = *inLocal;
3179 inRemote = &newEntry; 3180 inRemote = &newEntry;
3180 3181
3181 //USsyncRemote->insertAddressee( inRemote, false ); 3182 //USsyncRemote->insertAddressee( inRemote, false );
3182 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 3183 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
3183 3184
3184 } 3185 }
3185 } 3186 }
3186 3187
3187 } 3188 }
3188 ++incCounter; 3189 ++incCounter;
3189 } 3190 }
3190 el.clear(); 3191 el.clear();
3191 manager->hideProgressBar(); 3192 manager->hideProgressBar();
3192 3193
3193 // Now write the info back into the sync data space of the files 3194 // Now write the info back into the sync data space of the files
3194 3195
3195 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 3196 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
3196 // get rid of micro seconds 3197 // get rid of micro seconds
3197 QTime t = mLastSync.time(); 3198 QTime t = mLastSync.time();
3198 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3199 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3199 3200
3200 3201
3201 syncItemLocal->lastSyncDate = mLastSync; 3202 syncItemLocal->lastSyncDate = mLastSync;
3202 syncItemRemote->lastSyncDate = mLastSync; 3203 syncItemRemote->lastSyncDate = mLastSync;
3203 3204
3204 QString mes; 3205 QString mes;
3205 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); 3206 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote );
3206 if ( manager->mShowSyncSummary ) { 3207 if ( manager->mShowSyncSummary ) {
3207 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3208 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3208 } 3209 }
3209 qDebug( mes ); 3210 qDebug( mes );
3210 return e_success; 3211 return e_success;
3211} 3212}
3212 3213
3213 3214
3214int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3215int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3215{ 3216{
3216 // 0 equal 3217 // 0 equal
3217 // 1 take local 3218 // 1 take local
3218 // 2 take remote 3219 // 2 take remote
3219 // 3 cancel 3220 // 3 cancel
3220 QDateTime localMod = local->meta.update; 3221 QDateTime localMod = local->meta.update;
3221 QDateTime remoteMod = remote->meta.update; 3222 QDateTime remoteMod = remote->meta.update;
3222 3223
3223 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
3224
3225 if ( localMod == remoteMod ) 3224 if ( localMod == remoteMod )
3226 return 0; 3225 return 0;
3227 3226
3228 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3227 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3229 3228
3230 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3229 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3231 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3230 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3232 //full = true; //debug only 3231 //full = true; //debug only
3233 if ( full ) { 3232 if ( full ) {
3234 bool equ = ( (*local) == (*remote) ); 3233 bool equ = ( (*local) == (*remote) );
3235 if ( equ ) { 3234 if ( equ ) {
3236 //qDebug("equal "); 3235 //qDebug("equal ");
3237 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3236 if ( mode < SYNC_PREF_FORCE_LOCAL )
3238 return 0; 3237 return 0;
3239 3238
3240 }//else //debug only 3239 }//else //debug only
3241 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); 3240 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
3242 } 3241 }
3243 3242
3244 int result; 3243 int result;
3245 bool localIsNew; 3244 bool localIsNew;
3246 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 3245 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
3247 3246
3248 if ( full && mode < SYNC_PREF_NEWEST ) 3247 if ( full && mode < SYNC_PREF_NEWEST )
3249 mode = SYNC_PREF_ASK; 3248 mode = SYNC_PREF_ASK;
3250 3249
3251 switch( mode ) { 3250 switch( mode ) {
3252 case SYNC_PREF_LOCAL: 3251 case SYNC_PREF_LOCAL:
3253 if ( lastSync > remoteMod ) 3252 if ( lastSync > remoteMod )
3254 return 1; 3253 return 1;
3255 if ( lastSync > localMod ) 3254 if ( lastSync > localMod )
3256 return 2; 3255 return 2;
3257 return 1; 3256 return 1;
3258 break; 3257 break;
3259 case SYNC_PREF_REMOTE: 3258 case SYNC_PREF_REMOTE:
3260 if ( lastSync > remoteMod ) 3259 if ( lastSync > remoteMod )
3261 return 1; 3260 return 1;
3262 if ( lastSync > localMod ) 3261 if ( lastSync > localMod )
3263 return 2; 3262 return 2;
3264 return 2; 3263 return 2;
3265 break; 3264 break;
3266 case SYNC_PREF_NEWEST: 3265 case SYNC_PREF_NEWEST:
3267 if ( localMod > remoteMod ) 3266 if ( localMod > remoteMod )
3268 return 1; 3267 return 1;
3269 else 3268 else
3270 return 2; 3269 return 2;
3271 break; 3270 break;
3272 case SYNC_PREF_ASK: 3271 case SYNC_PREF_ASK:
3273 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3272 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3274 if ( lastSync > remoteMod ) 3273 if ( lastSync > remoteMod )
3275 return 1; 3274 return 1;
3276 if ( lastSync > localMod ) 3275 if ( lastSync > localMod )
3277 return 2; 3276 return 2;
3278 localIsNew = localMod >= remoteMod; 3277 localIsNew = localMod >= remoteMod;
3279 //qDebug("conflict! ************************************** "); 3278 //qDebug("conflict! ************************************** ");
3280 { 3279 {
3281 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3280 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3282 result = acd.executeD(localIsNew); 3281 result = acd.executeD(localIsNew);
3283 return result; 3282 return result;
3284 } 3283 }
3285 break; 3284 break;
3286 case SYNC_PREF_FORCE_LOCAL: 3285 case SYNC_PREF_FORCE_LOCAL:
3287 return 1; 3286 return 1;
3288 break; 3287 break;
3289 case SYNC_PREF_FORCE_REMOTE: 3288 case SYNC_PREF_FORCE_REMOTE:
3290 return 2; 3289 return 2;
3291 break; 3290 break;
3292 3291
3293 default: 3292 default:
3294 // SYNC_PREF_TAKE_BOTH not implemented 3293 // SYNC_PREF_TAKE_BOTH not implemented
3295 break; 3294 break;
3296 } 3295 }
3297 return 0; 3296 return 0;
3298} 3297}
3299 3298
3300 3299
3301 3300
3302 3301
3303//this are the overwritten callbackmethods from the syncinterface 3302//this are the overwritten callbackmethods from the syncinterface
3304bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3303bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3305{ 3304{
3306 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3305 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3307 3306
3308 //1) unlock local file first if necessary (ask for password) 3307 //1) unlock local file first if necessary (ask for password)
3309 if (this->isDeepLocked()) { 3308 if (this->isDeepLocked()) {
3310 PwMerror ret = this->deepLock(false); 3309 PwMerror ret = this->deepLock(false);
3311 if (ret != e_success) 3310 if (ret != e_success)
3312 return false; 3311 return false;
3313 } 3312 }
3314 3313
3315 //2) construct and open a new doc on the stack(automatic cleanup of remote file). 3314 //2) construct and open a new doc on the stack(automatic cleanup of remote file).
3316 PwMDoc syncTarget(this, "synctarget"); 3315 PwMDoc syncTarget(this, "synctarget");
3317 PwMDoc* pSyncTarget = &syncTarget; 3316 PwMDoc* pSyncTarget = &syncTarget;
3318 3317
3319 3318
3320 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); 3319 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3321 3320
3322 if (err == e_alreadyOpen) { 3321 if (err == e_alreadyOpen) {
3323 PwMDocList::listItem li; 3322 PwMDocList::listItem li;
3324 if (getOpenDocList()->find(filename.latin1(), &li)) 3323 if (getOpenDocList()->find(filename.latin1(), &li))
3325 pSyncTarget = li.doc; 3324 pSyncTarget = li.doc;
3326 else { 3325 else {
3327 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3326 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3328 return false; 3327 return false;
3329 } 3328 }
3330 } 3329 }
3331 else if (err != e_success) { 3330 else if (err != e_success) {
3332 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3331 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3333 return false; 3332 return false;
3334 } 3333 }
3335 3334
3336 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3335 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3337 3336
3338 3337
3339 //3) unlock remote file first if necessary (ask for password) 3338 //3) unlock remote file first if necessary (ask for password)
3340 if (pSyncTarget->isDeepLocked()) { 3339 if (pSyncTarget->isDeepLocked()) {
3341 PwMerror ret = pSyncTarget->deepLock(false); 3340 PwMerror ret = pSyncTarget->deepLock(false);
3342 if (ret != e_success) 3341 if (ret != e_success)
3343 return false; 3342 return false;
3344 } 3343 }
3345 3344
3346 3345
3347 err = syncronize(manager, this, pSyncTarget, mode ); 3346 err = syncronize(manager, this, pSyncTarget, mode );
3348 3347
3349 if (err == e_success) { 3348 if (err == e_success) {
3350 if ( manager->mWriteBackFile ){ 3349 if ( manager->mWriteBackFile ){
3351 qDebug("Saving remote PWManager file"); 3350 qDebug("Saving remote PWManager file");
3352 err = pSyncTarget->saveDoc(conf()->confGlobCompression()); 3351 err = pSyncTarget->saveDoc(conf()->confGlobCompression());