author | zcarsten <zcarsten> | 2003-08-06 20:59:20 (UTC) |
---|---|---|
committer | zcarsten <zcarsten> | 2003-08-06 20:59:20 (UTC) |
commit | 557e7a9f407e77a3f5bcfda5de9a8408379165ac (patch) (side-by-side diff) | |
tree | 4ad5296b9f4858b3e0791c321116449d7c99ef00 | |
parent | e14f10f07d8477ee49cd487587732e27a3307878 (diff) | |
download | opie-557e7a9f407e77a3f5bcfda5de9a8408379165ac.zip opie-557e7a9f407e77a3f5bcfda5de9a8408379165ac.tar.gz opie-557e7a9f407e77a3f5bcfda5de9a8408379165ac.tar.bz2 |
bug fixed: icon handling
-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index e86b3d2..9341425 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp @@ -2429,833 +2429,837 @@ int ZSafe::saveEntry(char *entry[FIELD_SIZE]) plaintext[bufferIndex] = buffer[count2 + 1] << 8; plaintext[bufferIndex] += buffer[count2] & 0xff; #endif #ifdef WORDS_BIGENDIAN plaintext[bufferIndex] = buffer[count2] << 8; plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; #endif bufferIndex++; if (bufferIndex == 4) { krc2->rc2_encrypt (plaintext); for (count3 = 0; count3 < 4; count3++) { ciphertext[count3] = iv[count3] ^ plaintext[count3]; /* Now store the ciphertext as the iv */ iv[count3] = plaintext[count3]; /* reset the buffer index */ bufferIndex = 0; if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; } /*for (count3 = 0; count3 < 5; count3++)*/ } /*if (bufferIndex == 5)*/ /* increment a short, not a byte */ count2 += 2; } /*while (count2 < strlen (buffer))*/ int ret = PWERR_GOOD; return ret; } int ZSafe::saveFinalize(void) { int count1, retval = PWERR_GOOD; unsigned short ciphertext[4]; Krc2* krc2 = new Krc2(); /* Tack on the PKCS 5 padding * How it works is we fill up the last n bytes with the value n * * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left * over, leaving us 3 short, so we fill it in with 3's. * * If we come out even, we fill it with 8 8s * * um, except that in this instance we are using 4 shorts instead of 8 bytes. * so, half everything */ for (count1 = bufferIndex; count1 < 4; count1++) { plaintext[count1] = (4 - bufferIndex); } krc2->rc2_encrypt (plaintext); for (count1 = 0; count1 < 4; count1++) { ciphertext[count1] = iv[count1] ^ plaintext[count1]; if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; } fclose (fd); free(buffer); return retval; } void ZSafe::quitMe () { qWarning ("QUIT..."); if (modified) { switch( QMessageBox::information( this, tr("ZSafe"), tr("Do you want to save\nbefore exiting?"), tr("&Save"), tr("S&ave with\nnew\npassword"), tr("&Don't Save"), 0 // Enter == button 0 ) ) { // Escape == button 2 case 0: // Save clicked, Alt-S or Enter pressed. // save modified = false; saveDocument(filename, FALSE); exitZs (1); break; case 1: // // Save with new password modified = false; saveDocument(filename, TRUE); exitZs (1); break; case 2: // Don't Save clicked or Alt-D pressed // don't save but exitZs exitZs (1); break; } } exitZs (1); } void ZSafe::categoryFieldActivated( const QString& category) { if (categoryDialog) setCategoryDialogFields(categoryDialog, category); } void ZSafe::addCategory() { if (filename.isEmpty()) { QMessageBox::critical( 0, tr("ZSafe"), tr("No document defined.\nYou have to create a new document")); return; } else { // open the 'Category' dialog bool initIcons = false; // open the 'Category' dialog CategoryDialog *dialog; if (categoryDialog) { dialog = categoryDialog; } else { 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 DialogCode result = (DialogCode) dialog->exec(); #ifdef DESKTOP result = Accepted; #endif QString category; QString icon; QString fullIconPath; QPixmap *pix; if (result == Accepted) { modified = true; category = dialog->CategoryField->currentText(); icon = dialog->IconField->currentText()+".png"; qWarning (category); QListViewItem *li = new ShadedListItem( 1, ListView ); Category *c1 = new Category(); c1->setCategoryName(category); // if (!icon.isEmpty() && !icon.isNull()) if (icon != "predefined.png") { // build the full path fullIconPath = iconPath + icon; pix = new QPixmap (fullIconPath); // pix->resize(14, 14); if (pix) { // save the full pixmap name into the config file // #ifndef WIN32 conf->writeEntry(APP_KEY+category, icon); // #endif saveConf(); QImage img = pix->convertToImage(); pix->convertFromImage(img.smoothScale(14,14)); c1->setIcon (*pix); c1->setIconName(icon); } else { QPixmap folder( ( const char** ) general_data ); c1->setIcon (folder); } } else { c1->setIcon (*getPredefinedIcon(category)); } c1->setListItem (li); c1->initListItem(); categories.insert (c1->getCategoryName(), c1); saveCategoryDialogFields(dialog); } else { // delete dialog; dialog->hide(); return; } } } 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"))); Category *cat= categories.find (selectedItem->text(0)); if (cat) { icon = cat->getIconName(); } + else + icon = conf->readEntry(APP_KEY+selectedItem->text(0)); } 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(); } + else + icon = conf->readEntry(APP_KEY+category); #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::saveCategoryDialogFields(CategoryDialog *dialog) { QString app_key = APP_KEY; #ifndef DESKTOP conf->setGroup ("fieldDefs"); #else #ifndef WIN32 app_key += "/fieldDefs/"; #endif #endif QString category = dialog->CategoryField->currentText(); // #ifndef WIN32 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); // #endif saveConf(); #ifndef DESKTOP conf->setGroup ("zsafe"); #endif } void ZSafe::editCategory() { if (!selectedItem) return; if (isCategory(selectedItem)) { QString category = selectedItem->text(0); bool initIcons = false; // open the 'Category' dialog CategoryDialog *dialog; if (categoryDialog) { dialog = categoryDialog; } else { 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; } setCategoryDialogFields(dialog); #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; dialog->CategoryField->clear(); // remove all items int i=0; bool foundCategory = false; 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, i); if (category.compare(categ) == 0) { dialog->CategoryField->setCurrentItem(i); foundCategory = true; } i++; } } ++it; } if (!foundCategory) { dialog->CategoryField->insertItem (category, i); dialog->CategoryField->setCurrentItem(i); } QString icon; Category *cat= categories.find (selectedItem->text(0)); if (cat) { icon = cat->getIconName(); } 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(); int i=0; QFileInfoListIterator it( *list ); // create list iterator QFileInfo *fi; // pointer for traversing if (icon.isEmpty() || icon.isNull()) { dialog->IconField->setCurrentItem(0); } 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); if(fileName+".png"==icon) dialog->IconField->setCurrentItem(i+1); ++i; } ++it; } waitDialog.hide(); } else { #ifdef DESKTOP // QDir d(QDir::homeDirPath() + "/pics/"); 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; } } } // dialog->show(); #ifndef DESKTOP // dialog->move (20, 100); #endif DialogCode result = (DialogCode) dialog->exec(); #ifdef DESKTOP result = Accepted; #endif QString fullIconPath; QPixmap *pix; if (result == Accepted) { modified = true; if (category != dialog->CategoryField->currentText()) { categories.remove (category); // #ifndef WIN32 conf->removeEntry(category); // #endif saveConf(); } category = dialog->CategoryField->currentText(); icon = dialog->IconField->currentText()+".png"; if (cat) { qWarning("Category found"); // if (!icon.isEmpty() && !icon.isNull()) if (icon != "predefined.png") { // build the full path fullIconPath = iconPath + icon; pix = new QPixmap (fullIconPath); if (pix) { // save the full pixmap name into the config file // #ifndef WIN32 conf->writeEntry(APP_KEY+category, icon); // #endif saveConf(); QImage img = pix->convertToImage(); pix->convertFromImage(img.smoothScale(14,14)); cat->setIconName (icon); cat->setIcon (*pix); } } else { // #ifndef WIN32 conf->removeEntry (category); // #endif saveConf(); cat->setIcon (*getPredefinedIcon(category)); } // change the category name of the selected category QListViewItem *catItem = cat->getListItem(); if (catItem) { qWarning (category); catItem->setText( 0, tr( category ) ); cat->setCategoryName (tr(category)); cat->initListItem(); categories.insert (category, cat); } } saveCategoryDialogFields(dialog); } else { // delete dialog; dialog->hide(); return; } } } void ZSafe::cutItem() { if (!selectedItem) return; if (!isCategory(selectedItem)) { IsCut = true; copiedItem = selectedItem; } } void ZSafe::copyItem() { if (!selectedItem) return; if (!isCategory(selectedItem)) { IsCopy = true; copiedItem = selectedItem; } } // paste item into category void ZSafe::pasteItem() { if (!selectedItem) return; if (isCategory(selectedItem)) { modified = true; if (IsCut) { if (copiedItem) { // add the new item QListViewItem *i = new ShadedListItem (0, selectedItem); // i->setOpen (TRUE); i->setText (0, copiedItem->text(0)); i->setText (1, copiedItem->text(1)); i->setText (2, copiedItem->text(2)); i->setText (3, copiedItem->text(3)); i->setText (4, copiedItem->text(4)); |