author | zcarsten <zcarsten> | 2003-08-06 20:15:19 (UTC) |
---|---|---|
committer | zcarsten <zcarsten> | 2003-08-06 20:15:19 (UTC) |
commit | e14f10f07d8477ee49cd487587732e27a3307878 (patch) (unidiff) | |
tree | e46ff1986ce5c0cbba2283d80a878df432f874d8 | |
parent | ba25812361114b7cf059a3a1fb3aed42f8a7ebde (diff) | |
download | opie-e14f10f07d8477ee49cd487587732e27a3307878.zip opie-e14f10f07d8477ee49cd487587732e27a3307878.tar.gz opie-e14f10f07d8477ee49cd487587732e27a3307878.tar.bz2 |
addCategory corrected
-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index ef16b46..e86b3d2 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp | |||
@@ -2588,52 +2588,58 @@ void ZSafe::addCategory() | |||
2588 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 2588 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
2589 | QTextStream t( &f ); // use a text stream | 2589 | QTextStream t( &f ); // use a text stream |
2590 | QString s; | 2590 | QString s; |
2591 | while ( !t.eof() ) { // until end of file... | 2591 | while ( !t.eof() ) { // until end of file... |
2592 | s = t.readLine(); // line of text excluding '\n' | 2592 | s = t.readLine(); // line of text excluding '\n' |
2593 | list.append(s); | 2593 | list.append(s); |
2594 | } | 2594 | } |
2595 | f.close(); | 2595 | f.close(); |
2596 | } | 2596 | } |
2597 | #endif | 2597 | #endif |
2598 | QStringList::Iterator it = list.begin(); | 2598 | QStringList::Iterator it = list.begin(); |
2599 | QString categ; | 2599 | QString categ; |
2600 | QString firstCategory; | ||
2600 | dialog->CategoryField->clear(); // remove all items | 2601 | dialog->CategoryField->clear(); // remove all items |
2601 | while( it != list.end() ) | 2602 | while( it != list.end() ) |
2602 | { | 2603 | { |
2603 | QString *cat = new QString (*it); | 2604 | QString *cat = new QString (*it); |
2604 | if (cat->contains("-field1", FALSE)) | 2605 | if (cat->contains("-field1", FALSE)) |
2605 | { | 2606 | { |
2606 | #ifdef DESKTOP | 2607 | #ifdef DESKTOP |
2607 | #ifndef WIN32 | 2608 | #ifndef WIN32 |
2608 | categ = cat->section ("-field1", 0, 0); | 2609 | categ = cat->section ("-field1", 0, 0); |
2609 | #else | 2610 | #else |
2610 | int pos = cat->find ("-field1"); | 2611 | int pos = cat->find ("-field1"); |
2611 | categ = cat->left (pos); | 2612 | categ = cat->left (pos); |
2612 | #endif | 2613 | #endif |
2613 | #else | 2614 | #else |
2614 | int pos = cat->find ("-field1"); | 2615 | int pos = cat->find ("-field1"); |
2615 | cat->truncate(pos); | 2616 | cat->truncate(pos); |
2616 | categ = *cat; | 2617 | categ = *cat; |
2617 | #endif | 2618 | #endif |
2618 | if (!categ.isEmpty()) | 2619 | if (!categ.isEmpty()) |
2619 | { | 2620 | { |
2620 | dialog->CategoryField->insertItem (categ, -1); | 2621 | dialog->CategoryField->insertItem (categ, -1); |
2622 | if (firstCategory.isEmpty()) | ||
2623 | firstCategory = categ; | ||
2621 | } | 2624 | } |
2622 | } | 2625 | } |
2623 | ++it; | 2626 | ++it; |
2624 | } | 2627 | } |
2625 | 2628 | ||
2626 | 2629 | ||
2627 | setCategoryDialogFields(dialog); | 2630 | if (firstCategory.isEmpty()) |
2631 | setCategoryDialogFields(dialog); | ||
2632 | else | ||
2633 | setCategoryDialogFields(dialog, firstCategory); | ||
2628 | 2634 | ||
2629 | // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); | 2635 | // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); |
2630 | 2636 | ||
2631 | if (initIcons) | 2637 | if (initIcons) |
2632 | { | 2638 | { |
2633 | Wait waitDialog(this, tr("Wait dialog")); | 2639 | Wait waitDialog(this, tr("Wait dialog")); |
2634 | waitDialog.waitLabel->setText(tr("Gathering icons...")); | 2640 | waitDialog.waitLabel->setText(tr("Gathering icons...")); |
2635 | waitDialog.show(); | 2641 | waitDialog.show(); |
2636 | qApp->processEvents(); | 2642 | qApp->processEvents(); |
2637 | 2643 | ||
2638 | #ifdef DESKTOP | 2644 | #ifdef DESKTOP |
2639 | QDir d(iconPath); | 2645 | QDir d(iconPath); |
@@ -2777,36 +2783,51 @@ void ZSafe::delCategory() | |||
2777 | 2783 | ||
2778 | selectedItem = NULL; | 2784 | selectedItem = NULL; |
2779 | break; | 2785 | break; |
2780 | case 1: // Don't delete | 2786 | case 1: // Don't delete |
2781 | break; | 2787 | break; |
2782 | } | 2788 | } |
2783 | 2789 | ||
2784 | } | 2790 | } |
2785 | } | 2791 | } |
2786 | 2792 | ||
2787 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) | 2793 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) |
2788 | { | 2794 | { |
2789 | dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); | 2795 | if (!dialog) |
2790 | dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); | 2796 | return; |
2791 | dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); | ||
2792 | dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); | ||
2793 | dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); | ||
2794 | dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); | ||
2795 | 2797 | ||
2796 | QString icon; | 2798 | QString icon; |
2797 | Category *cat= categories.find (selectedItem->text(0)); | 2799 | if (selectedItem) |
2798 | if (cat) | ||
2799 | { | 2800 | { |
2800 | icon = cat->getIconName(); | 2801 | dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); |
2802 | dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); | ||
2803 | dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); | ||
2804 | dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); | ||
2805 | dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); | ||
2806 | dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); | ||
2807 | |||
2808 | Category *cat= categories.find (selectedItem->text(0)); | ||
2809 | if (cat) | ||
2810 | { | ||
2811 | icon = cat->getIconName(); | ||
2812 | } | ||
2813 | } | ||
2814 | else | ||
2815 | { | ||
2816 | dialog->Field1->setText(tr("Name")); | ||
2817 | dialog->Field2->setText(tr("Username")); | ||
2818 | dialog->Field3->setText(tr("Password")); | ||
2819 | dialog->Field4->setText(tr("Comment")); | ||
2820 | dialog->Field5->setText(tr("Field 4")); | ||
2821 | dialog->Field6->setText(tr("Field 5")); | ||
2801 | } | 2822 | } |
2802 | 2823 | ||
2803 | #ifdef DESKTOP | 2824 | #ifdef DESKTOP |
2804 | QDir d(iconPath); | 2825 | QDir d(iconPath); |
2805 | #else | 2826 | #else |
2806 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 2827 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2807 | #endif | 2828 | #endif |
2808 | d.setFilter( QDir::Files); | 2829 | d.setFilter( QDir::Files); |
2809 | 2830 | ||
2810 | const QFileInfoList *list = d.entryInfoList(); | 2831 | const QFileInfoList *list = d.entryInfoList(); |
2811 | int i=0; | 2832 | int i=0; |
2812 | QFileInfoListIterator it( *list ); // create list iterator | 2833 | QFileInfoListIterator it( *list ); // create list iterator |
@@ -2829,24 +2850,27 @@ void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) | |||
2829 | dialog->IconField->setCurrentItem(i+1); | 2850 | dialog->IconField->setCurrentItem(i+1); |
2830 | break; | 2851 | break; |
2831 | } | 2852 | } |
2832 | ++i; | 2853 | ++i; |
2833 | } | 2854 | } |
2834 | ++it; | 2855 | ++it; |
2835 | } | 2856 | } |
2836 | } | 2857 | } |
2837 | } | 2858 | } |
2838 | 2859 | ||
2839 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) | 2860 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) |
2840 | { | 2861 | { |
2862 | if (!dialog) | ||
2863 | return; | ||
2864 | |||
2841 | dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); | 2865 | dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); |
2842 | dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); | 2866 | dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); |
2843 | dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); | 2867 | dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); |
2844 | dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); | 2868 | dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); |
2845 | dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); | 2869 | dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); |
2846 | dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); | 2870 | dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); |
2847 | 2871 | ||
2848 | QString icon; | 2872 | QString icon; |
2849 | Category *cat= categories.find (category); | 2873 | Category *cat= categories.find (category); |
2850 | if (cat) | 2874 | if (cat) |
2851 | { | 2875 | { |
2852 | icon = cat->getIconName(); | 2876 | icon = cat->getIconName(); |