-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 26 |
1 files changed, 25 insertions, 1 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 @@ -2552,124 +2552,130 @@ void ZSafe::addCategory() { categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); #ifdef WIN32 categoryDialog->setCaption ("Qt " + tr("Category")); #endif dialog = categoryDialog; connect( dialog->CategoryField, SIGNAL( activated ( const QString &)), this, SLOT( categoryFieldActivated( const QString & ) ) ); initIcons = true; } #ifdef DESKTOP #ifndef WIN32 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); #else // read all categories from the config file and store // into a list QFile f (cfgFile); QStringList list; if ( f.open(IO_ReadOnly) ) { // file opened successfully QTextStream t( &f ); // use a text stream QString s; int n = 1; while ( !t.eof() ) { // until end of file... s = t.readLine(); // line of text excluding '\n' list.append(s); } f.close(); } #endif #else // read all categories from the config file and store // into a list QFile f (cfgFile); QStringList list; if ( f.open(IO_ReadOnly) ) { // file opened successfully QTextStream t( &f ); // use a text stream QString s; while ( !t.eof() ) { // until end of file... s = t.readLine(); // line of text excluding '\n' list.append(s); } f.close(); } #endif QStringList::Iterator it = list.begin(); QString categ; + QString firstCategory; dialog->CategoryField->clear(); // remove all items while( it != list.end() ) { QString *cat = new QString (*it); if (cat->contains("-field1", FALSE)) { #ifdef DESKTOP #ifndef WIN32 categ = cat->section ("-field1", 0, 0); #else int pos = cat->find ("-field1"); categ = cat->left (pos); #endif #else int pos = cat->find ("-field1"); cat->truncate(pos); categ = *cat; #endif if (!categ.isEmpty()) { dialog->CategoryField->insertItem (categ, -1); + if (firstCategory.isEmpty()) + firstCategory = categ; } } ++it; } + if (firstCategory.isEmpty()) setCategoryDialogFields(dialog); + else + setCategoryDialogFields(dialog, firstCategory); // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); if (initIcons) { Wait waitDialog(this, tr("Wait dialog")); waitDialog.waitLabel->setText(tr("Gathering icons...")); waitDialog.show(); qApp->processEvents(); #ifdef DESKTOP QDir d(iconPath); #else QDir d(QPEApplication::qpeDir() + "/pics/"); #endif d.setFilter( QDir::Files); const QFileInfoList *list = d.entryInfoList(); QFileInfoListIterator it( *list ); // create list iterator QFileInfo *fi; // pointer for traversing dialog->IconField->insertItem("predefined"); while ( (fi=it.current()) ) { // for each file... QString fileName = fi->fileName(); if(fileName.right(4) == ".png"){ fileName = fileName.mid(0,fileName.length()-4); #ifdef DESKTOP QPixmap imageOfFile; imageOfFile.load(iconPath + fi->fileName()); #else QPixmap imageOfFile(Resource::loadPixmap(fileName)); #endif QImage foo = imageOfFile.convertToImage(); foo = foo.smoothScale(16,16); imageOfFile.convertFromImage(foo); dialog->IconField->insertItem(imageOfFile,fileName); } ++it; } waitDialog.hide(); } #ifndef WIN32 dialog->show(); #endif #ifndef DESKTOP // dialog->move (20, 100); #endif @@ -2741,148 +2747,166 @@ void ZSafe::addCategory() } void ZSafe::delCategory() { if (!selectedItem) return; if (isCategory(selectedItem)) { switch( QMessageBox::information( this, tr("ZSafe"), tr("Do you want to delete?"), tr("&Delete"), tr("D&on't Delete"), 0 // Enter == button 0 ) ) { // Escape == button 2 case 0: // Delete clicked, Alt-S or Enter pressed. // Delete from the category list modified = true; categories.remove (selectedItem->text(0)); // #ifndef WIN32 conf->removeEntry (selectedItem->text(0)); // #endif saveConf(); // Delete the selected item and all subitems // step through all subitems QListViewItem *si; for (si = selectedItem->firstChild(); si != NULL; ) { QListViewItem *_si = si; si = si->nextSibling(); selectedItem->takeItem(_si); // remove from view list if (_si) delete _si; } ListView->takeItem(selectedItem); delete selectedItem; selectedItem = NULL; break; case 1: // Don't delete break; } } } void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) { + if (!dialog) + return; + + QString icon; + if (selectedItem) + { dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); - QString icon; Category *cat= categories.find (selectedItem->text(0)); if (cat) { icon = cat->getIconName(); } + } + else + { + dialog->Field1->setText(tr("Name")); + dialog->Field2->setText(tr("Username")); + dialog->Field3->setText(tr("Password")); + dialog->Field4->setText(tr("Comment")); + dialog->Field5->setText(tr("Field 4")); + dialog->Field6->setText(tr("Field 5")); + } #ifdef DESKTOP QDir d(iconPath); #else QDir d(QPEApplication::qpeDir() + "/pics/"); #endif d.setFilter( QDir::Files); const QFileInfoList *list = d.entryInfoList(); int i=0; QFileInfoListIterator it( *list ); // create list iterator QFileInfo *fi; // pointer for traversing if (icon.isEmpty() || icon.isNull()) { dialog->IconField->setCurrentItem(0); } else { while ( (fi=it.current()) ) { // for each file... QString fileName = fi->fileName(); if(fileName.right(4) == ".png") { fileName = fileName.mid(0,fileName.length()-4); if(fileName+".png"==icon) { dialog->IconField->setCurrentItem(i+1); break; } ++i; } ++it; } } } void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) { + if (!dialog) + return; + dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); QString icon; Category *cat= categories.find (category); if (cat) { icon = cat->getIconName(); } #ifdef DESKTOP QDir d(iconPath); #else QDir d(QPEApplication::qpeDir() + "/pics/"); #endif d.setFilter( QDir::Files); const QFileInfoList *list = d.entryInfoList(); int i=0; QFileInfoListIterator it( *list ); // create list iterator QFileInfo *fi; // pointer for traversing if (icon.isEmpty() || icon.isNull()) { dialog->IconField->setCurrentItem(0); } else { while ( (fi=it.current()) ) { // for each file... QString fileName = fi->fileName(); if(fileName.right(4) == ".png") { fileName = fileName.mid(0,fileName.length()-4); if(fileName+".png"==icon) { dialog->IconField->setCurrentItem(i+1); break; } ++i; } ++it; } } |