summaryrefslogtreecommitdiff
authorzcarsten <zcarsten>2003-08-06 20:15:19 (UTC)
committer zcarsten <zcarsten>2003-08-06 20:15:19 (UTC)
commite14f10f07d8477ee49cd487587732e27a3307878 (patch) (unidiff)
treee46ff1986ce5c0cbba2283d80a878df432f874d8
parentba25812361114b7cf059a3a1fb3aed42f8a7ebde (diff)
downloadopie-e14f10f07d8477ee49cd487587732e27a3307878.zip
opie-e14f10f07d8477ee49cd487587732e27a3307878.tar.gz
opie-e14f10f07d8477ee49cd487587732e27a3307878.tar.bz2
addCategory corrected
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp44
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
@@ -2576,76 +2576,82 @@ void ZSafe::addCategory()
2576 while ( !t.eof() ) { // until end of file... 2576 while ( !t.eof() ) { // until end of file...
2577 s = t.readLine(); // line of text excluding '\n' 2577 s = t.readLine(); // line of text excluding '\n'
2578 list.append(s); 2578 list.append(s);
2579 } 2579 }
2580 f.close(); 2580 f.close();
2581 } 2581 }
2582#endif 2582#endif
2583#else 2583#else
2584 // read all categories from the config file and store 2584 // read all categories from the config file and store
2585 // into a list 2585 // into a list
2586 QFile f (cfgFile); 2586 QFile f (cfgFile);
2587 QStringList list; 2587 QStringList list;
2588 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2588 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2589 QTextStream t( &f ); // use a text stream 2589 QTextStream t( &f ); // use a text stream
2590 QString s; 2590 QString s;
2591 while ( !t.eof() ) { // until end of file... 2591 while ( !t.eof() ) { // until end of file...
2592 s = t.readLine(); // line of text excluding '\n' 2592 s = t.readLine(); // line of text excluding '\n'
2593 list.append(s); 2593 list.append(s);
2594 } 2594 }
2595 f.close(); 2595 f.close();
2596 } 2596 }
2597#endif 2597#endif
2598 QStringList::Iterator it = list.begin(); 2598 QStringList::Iterator it = list.begin();
2599 QString categ; 2599 QString categ;
2600 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);
2640#else 2646#else
2641 QDir d(QPEApplication::qpeDir() + "/pics/"); 2647 QDir d(QPEApplication::qpeDir() + "/pics/");
2642#endif 2648#endif
2643 d.setFilter( QDir::Files); 2649 d.setFilter( QDir::Files);
2644 2650
2645 const QFileInfoList *list = d.entryInfoList(); 2651 const QFileInfoList *list = d.entryInfoList();
2646 QFileInfoListIterator it( *list ); // create list iterator 2652 QFileInfoListIterator it( *list ); // create list iterator
2647 QFileInfo *fi; // pointer for traversing 2653 QFileInfo *fi; // pointer for traversing
2648 2654
2649 dialog->IconField->insertItem("predefined"); 2655 dialog->IconField->insertItem("predefined");
2650 while ( (fi=it.current()) ) { // for each file... 2656 while ( (fi=it.current()) ) { // for each file...
2651 QString fileName = fi->fileName(); 2657 QString fileName = fi->fileName();
@@ -2765,100 +2771,118 @@ void ZSafe::delCategory()
2765 // step through all subitems 2771 // step through all subitems
2766 QListViewItem *si; 2772 QListViewItem *si;
2767 for (si = selectedItem->firstChild(); 2773 for (si = selectedItem->firstChild();
2768 si != NULL; ) 2774 si != NULL; )
2769 { 2775 {
2770 QListViewItem *_si = si; 2776 QListViewItem *_si = si;
2771 si = si->nextSibling(); 2777 si = si->nextSibling();
2772 selectedItem->takeItem(_si); // remove from view list 2778 selectedItem->takeItem(_si); // remove from view list
2773 if (_si) delete _si; 2779 if (_si) delete _si;
2774 } 2780 }
2775 ListView->takeItem(selectedItem); 2781 ListView->takeItem(selectedItem);
2776 delete selectedItem; 2782 delete selectedItem;
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
2787void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) 2793void 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
2813 QFileInfo *fi; // pointer for traversing 2834 QFileInfo *fi; // pointer for traversing
2814 if (icon.isEmpty() || icon.isNull()) 2835 if (icon.isEmpty() || icon.isNull())
2815 { 2836 {
2816 dialog->IconField->setCurrentItem(0); 2837 dialog->IconField->setCurrentItem(0);
2817 } 2838 }
2818 else 2839 else
2819 { 2840 {
2820 while ( (fi=it.current()) ) 2841 while ( (fi=it.current()) )
2821 { // for each file... 2842 { // for each file...
2822 QString fileName = fi->fileName(); 2843 QString fileName = fi->fileName();
2823 if(fileName.right(4) == ".png") 2844 if(fileName.right(4) == ".png")
2824 { 2845 {
2825 fileName = fileName.mid(0,fileName.length()-4); 2846 fileName = fileName.mid(0,fileName.length()-4);
2826 2847
2827 if(fileName+".png"==icon) 2848 if(fileName+".png"==icon)
2828 { 2849 {
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
2839void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) 2860void 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();
2853 } 2877 }
2854 2878
2855#ifdef DESKTOP 2879#ifdef DESKTOP
2856 QDir d(iconPath); 2880 QDir d(iconPath);
2857#else 2881#else
2858 QDir d(QPEApplication::qpeDir() + "/pics/"); 2882 QDir d(QPEApplication::qpeDir() + "/pics/");
2859#endif 2883#endif
2860 d.setFilter( QDir::Files); 2884 d.setFilter( QDir::Files);
2861 2885
2862 const QFileInfoList *list = d.entryInfoList(); 2886 const QFileInfoList *list = d.entryInfoList();
2863 int i=0; 2887 int i=0;
2864 QFileInfoListIterator it( *list ); // create list iterator 2888 QFileInfoListIterator it( *list ); // create list iterator