author | llornkcor <llornkcor> | 2004-07-10 01:04:49 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-07-10 01:04:49 (UTC) |
commit | f16bf63fc655c1e85fed6ce96c464553b260f796 (patch) (side-by-side diff) | |
tree | 798963e12adcddf320802101982001afa8ee639e | |
parent | 944adb8bf2741a16cf627d19e08f51c08920ad89 (diff) | |
download | opie-f16bf63fc655c1e85fed6ce96c464553b260f796.zip opie-f16bf63fc655c1e85fed6ce96c464553b260f796.tar.gz opie-f16bf63fc655c1e85fed6ce96c464553b260f796.tar.bz2 |
add right click menu, and drag and drop for desktop version. show icons
-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 132 | ||||
-rw-r--r-- | noncore/apps/zsafe/zsafe.h | 8 |
2 files changed, 122 insertions, 18 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index 189453e..5cad7cb 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp @@ -9,96 +9,97 @@ ** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html ** ** Compile Flags: ** Zaurus arm : -DNO_OPIE ** Zaurus Opie arm: none ** Linux Desktop : -DDESKTOP ** Windows Desktop: -DDESKTOP -DWIN32 ** ** for japanese version additional use: -DJPATCH_HDE ** ****************************************************************************/ #include "zsafe.h" #include "newdialog.h" #include "searchdialog.h" #include "categorydialog.h" #include "passworddialog.h" #include "infoform.h" #include "zlistview.h" #include "shadedlistitem.h" #ifndef DESKTOP #ifndef NO_OPIE #include <opie2/ofiledialog.h> #include <opie2/odebug.h> using namespace Opie::Core; using namespace Opie::Ui; #else #include "scqtfileedit.h" #endif #endif #include <qclipboard.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #ifndef WIN32 #include <unistd.h> #endif #include <string.h> #include <errno.h> #include <qmenubar.h> #include <qpopupmenu.h> #ifdef DESKTOP #include <qfiledialog.h> +#include <qdragobject.h> #ifndef WIN32 #include <qsettings.h> #else #include "qsettings.h" #endif #include <qapplication.h> #else #include <qfile.h> #include <qpe/fileselector.h> #include <qpe/global.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/config.h> #endif #include <qtimer.h> #include <qlayout.h> #include <qmessagebox.h> #include <qfile.h> #include <qtextstream.h> #include <qheader.h> #include <qlistview.h> #include <qtoolbutton.h> #include <qvariant.h> #include <qtooltip.h> #include <qwhatsthis.h> #include <qimage.h> #include <qpixmap.h> #include <qlineedit.h> #include <qmultilineedit.h> #include <qregexp.h> #include <qdir.h> #include <qtextbrowser.h> #include <qlabel.h> #include <qcombobox.h> #include "krc2.h" #include "wait.h" extern int DeskW, DeskH; #ifdef DESKTOP extern QApplication *appl; #else extern QPEApplication *appl; #endif #ifdef JPATCH_HDE @@ -348,234 +349,274 @@ static const char* const general_data[] = { // exit ZSafe and clear the clipboard for security reasons void ZSafe::exitZs (int ec) { QClipboard *cb = QApplication::clipboard(); cb->clear(); exit (ec); } // save the configuration into the file void ZSafe::saveConf () { if (conf) { delete conf; #ifdef DESKTOP #ifndef WIN32 conf = new QSettings (); conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); #else conf = new QSettings (cfgFile); conf->insertSearchPath (QSettings::Unix, cfgFile); #endif #else conf = new Config (cfgFile, Config::File); conf->setGroup ("zsafe"); #endif } } /* * Constructs a ZSafe which is a child of 'parent', with the * name 'name' and widget flags set to 'f' * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ), Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l) { IsCut = false; IsCopy = false; modified = false; + showpwd = false; // set the config file cfgFile=QDir::homeDirPath(); cfgFile += "/.zsafe.cfg"; // set the icon path #ifdef NO_OPIE QString qpedir ((const char *)getenv("QPEDIR")); #else QString qpedir ((const char *)getenv("OPIEDIR")); #endif #ifdef DESKTOP iconPath = QDir::homeDirPath() + "/pics/"; #else if (qpedir.isEmpty()) iconPath = "/home/QtPalmtop/pics/"; else iconPath = qpedir + "/pics/"; #endif // create a zsafe configuration object #ifdef DESKTOP #ifndef WIN32 conf = new QSettings (); conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); #else conf = new QSettings (cfgFile); conf->insertSearchPath (QSettings::Unix, cfgFile); #endif #else conf = new Config (cfgFile, Config::File); conf->setGroup ("zsafePrefs"); #endif #ifdef DESKTOP // #ifndef WIN32 expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false); // #endif #else expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0); #endif #ifndef DESKTOP conf->setGroup ("zsafe"); #endif QPixmap copy_img((const char**) copy_xpm); QPixmap cut_img((const char**) cut_xpm); QPixmap edit_img((const char**) edit_xpm); QPixmap editdelete_img((const char**) editdelete_xpm); QPixmap find_img((const char**) find_xpm); QPixmap folder_open_img((const char**) folder_open_xpm); QPixmap help_icon_img((const char**) help_icon_xpm); QPixmap new_img((const char**) new_xpm); QPixmap paste_img((const char**) paste_xpm); QPixmap quit_icon_img((const char**) quit_icon_xpm); QPixmap save_img((const char**) save_xpm); QPixmap trash_img((const char**) trash_xpm); QPixmap expand_img((const char**) expand_xpm); QPixmap export_img((const char**) export_xpm); QPixmap import_img((const char**) import_xpm); QPixmap bank_cards( ( const char** ) bank_cards_data ); QPixmap passwords( ( const char** ) passwords_data ); QPixmap software( ( const char** ) software_data ); QPixmap general( ( const char** ) general_data ); - if ( !name ) + QPixmap image0( ( const char** ) zsafe_xpm ); + if ( !name ) setName( "ZSafe" ); #ifdef DESKTOP #ifdef WIN32 setGeometry(100, 150, DeskW, DeskH-30 ); #else resize( DeskW, DeskH-30 ); #endif #else #ifdef JPATCH_HDE int DeskS; if(DeskW > DeskH) { DeskS = DeskW; } else { DeskS = DeskH; } resize( DeskW, DeskH ); setMinimumSize( QSize( DeskS, DeskS ) ); setMaximumSize( QSize( DeskS, DeskS ) ); #else resize( DeskW, DeskH-30 ); #endif #endif setCaption( tr( "ZSafe" ) ); QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe"; QString filename = conf->readEntry(APP_KEY+"document"); if (filename.isEmpty() || filename.isNull()) { - if ( !QDir( zsafeAppDirPath ).exists() ) + + // check if the directory application exists, if not + // create it +// #ifndef WIN32 + // QString d1("Documents/application"); +// #else + QString d1(QDir::homeDirPath() + "/Documents/application"); +// #endif + QDir pd1(d1); + if (!pd1.exists()) + { + + QDir pd2(QDir::homeDirPath() + "/Documents"); + if (!pd2.exists()) { + QDir pd3(QDir::homeDirPath()); + if (!pd3.mkdir("Documents", FALSE)) { + } + } + + if (!pd2.mkdir("application", FALSE)) { - //FIXME: Pending someone to look into why QDir.mkdir does not work as expected - QString cmdline = QString().sprintf( "mkdir -p %s", (const char*) zsafeAppDirPath ); - ::system( cmdline ); + QMessageBox::critical( 0, tr("ZSafe"), +#ifdef JPATCH_HDE + tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>")); +#else + tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1)); +#endif + exitZs (1); } - if ( !QDir( zsafeAppDirPath ).exists() ) + } +// #ifndef WIN32 + // QString d2("Documents/application/zsafe"); +// #else + QString d2(QDir::homeDirPath() + "/Documents/application/zsafe"); +// #endif + QDir pd2(d2); + if (!pd2.exists()) + { + if (!pd1.mkdir("zsafe", FALSE)) { - QMessageBox::critical( 0, "ZSafe", tr("Can't create application data directory.\nZSafe will now exit.")); - exitZs (1); + QMessageBox::critical( 0, tr("ZSafe"), +#ifdef JPATCH_HDE + tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P")); +#else + tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2)); +#endif + exitZs (1); } - } - + } + // set the default filename filename = zsafeAppDirPath + "/passwords.zsf"; // save the current filename to the config file conf->writeEntry(APP_KEY+"document", filename); saveConf(); - + } //if (filename == "INVALIDPWD") //filename = ""; QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); #ifdef WIN32 this->setCaption("Qt ZSafe: " + ti); #else this->setCaption("ZSafe: " + ti); #endif selectedItem = NULL; lastSearchedCategory = NULL; lastSearchedItem = NULL; lastSearchedName = ""; lastSearchedUsername = ""; lastSearchedComment = ""; infoForm = new InfoForm(); categoryDialog = NULL; + infoForm->setIcon( image0); // add a menu bar QMenuBar *menu = new QMenuBar( this ); // add file menu // QPopupMenu *file = new QPopupMenu( this ); file = new QPopupMenu( this ); // #ifdef DESKTOP file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) ); file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) ); file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) ); file->insertSeparator(); // #endif file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) ); file->insertItem( save_img, tr("S&ave document with new Password"), this, SLOT(saveDocumentWithPwd()) ); file->insertSeparator(); file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) ); file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) ); file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) ); file->insertSeparator(); file->insertItem( expand_img, tr("&Open entries expanded"), this, SLOT(setExpandFlag()), 0, 'o'); file->setItemChecked('o', expandTree); file->insertSeparator(); file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) ); menu->insertItem( tr("&File"), file ); QPopupMenu *cat = new QPopupMenu( this ); cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) ); cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) ); cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) ); menu->insertItem( tr("&Category"), cat ); QPopupMenu *it = new QPopupMenu( this ); it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) ); it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) ); it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) ); it->insertSeparator(); it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) ); it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) ); it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) ); it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) ); menu->insertItem( tr("&Entry"), it ); QPopupMenu *help = new QPopupMenu( this ); @@ -621,96 +662,103 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) ListView = new ZListView( this, "ListView" ); ListView->addColumn( tr( "Name" ) ); ListView->addColumn( tr( "Field 2" ) ); ListView->addColumn( tr( "Field 3" ) ); ListView->addColumn( tr( "Comment" ) ); ListView->addColumn( tr( "Field 4" ) ); ListView->addColumn( tr( "Field 5" ) ); ListView->setAllColumnsShowFocus(TRUE); #ifdef DESKTOP ListView->setResizePolicy(QScrollView::AutoOneFit); // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) ); #else ListView->setResizePolicy(QScrollView::AutoOneFit); // ListView->setGeometry( QRect( 0, 22, // this->width(), this->height() - 30 ) ); // ListView->setMaximumSize( QSize( 440, 290 ) ); #endif ListView->setVScrollBarMode( QListView::Auto ); QBoxLayout * l = new QVBoxLayout( this ); l->addWidget (menu); l->addWidget (ListView); #ifndef DESKTOP // start a timer (100 ms) to load the default document docuTimer.start( 100, true ); connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) ); raiseFlag = true; connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) ); #else // open the default document openDocument(filename); #endif // signals and slots connections for QTollButton connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) ); connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) ); connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) ); connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) ); // signals and slots connections for QListView connect( ListView, SIGNAL( selectionChanged(QListViewItem*) ), this, SLOT( listViewSelected(QListViewItem*) ) ); connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( showInfo(QListViewItem*) ) ); connect( ListView, SIGNAL( returnPressed(QListViewItem*) ), this, SLOT( showInfo(QListViewItem*) ) ); +#ifndef DESKTOP + QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold); +#endif + connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), + this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); + + this->setIcon( image0); } const QColor *ZSafe::evenRowColor = &Qt::white; // const QColor *ZSafe::oddRowColor = &Qt::lightGray; const QColor *ZSafe::oddRowColor = new QColor(216,240,255); /* * Destroys the object and frees any allocated resources */ ZSafe::~ZSafe() { // no need to delete child widgets, Qt does it all for us quitMe(); } // load the default document void ZSafe::slotLoadDocu() { openDocument (filename); } void ZSafe::deletePwd() { 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 modified = true; selectedItem->parent()->takeItem(selectedItem); selectedItem = NULL; break; case 1: // Don't delete break; } } else { delCategory(); } } @@ -1471,97 +1519,97 @@ void ZSafe::readAllEntries() } Category *cat= categories.find (category); if (cat) { // use the existend item QListViewItem *catItem = cat->getListItem(); if (catItem) { QListViewItem * item = new ShadedListItem( 0, catItem ); item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); item->setText( 4, tr( field5 ) ); item->setText( 5, tr( field6 ) ); catItem->setOpen( TRUE ); } } else { QListViewItem *catI = new ShadedListItem( 1, ListView ); // create and insert a new item QListViewItem * item = new ShadedListItem( 0, catI ); item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); item->setText( 4, tr( field5 ) ); item->setText( 5, tr( field6 ) ); catI->setOpen( TRUE ); Category *c1 = new Category(); c1->setCategoryName(category); QString icon; QString fullIconPath; QPixmap *pix; // #ifndef WIN32 icon = conf->readEntry(APP_KEY+category); // #endif bool isIconAv = false; if (!icon.isEmpty() && !icon.isNull()) { // build the full path fullIconPath = iconPath + icon; pix = new QPixmap (fullIconPath); - if (pix) + if (!pix->isNull()) { QImage img = pix->convertToImage(); pix->convertFromImage(img.smoothScale(14,14)); c1->setIconName (icon); c1->setIcon (*pix); isIconAv = true; } } if (!isIconAv) { c1->setIcon (*getPredefinedIcon(category)); } c1->setListItem (catI); c1->initListItem(); categories.insert (c1->getCategoryName(), c1); } } f.close(); } else { } } #ifdef UNUSED void ZSafe::writeAllEntries() { // open the file for writing QString fn = filename + ".txt"; QFile f( fn ); if ( !f.open( IO_WriteOnly ) ) { owarn << "Could not write to file " << fn << oendl; QMessageBox::critical( 0, tr("ZSafe"), tr("Could not export to text file.") ); return; } QTextStream t( &f ); QListViewItem *i; // step through all categories for (i = ListView->firstChild(); i != NULL; i = i->nextSibling()) { // step through all subitems @@ -1686,151 +1734,154 @@ void ZSafe::readAllEntries() break; } idx++; } Category *cat= categories.find (category); if (cat) { // use the existend item QListViewItem *catItem = cat->getListItem(); if (catItem) { QListViewItem * item = new ShadedListItem( 0, catItem ); item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); catItem->setOpen( TRUE ); } } else { QListViewItem *catI = new ShadedListItem( 1, ListView ); // create and insert a new item QListViewItem * item = new ShadedListItem( 0, catI ); item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); catI->setOpen( TRUE ); Category *c1 = new Category(); c1->setCategoryName(category); QString icon; QString fullIconPath; QPixmap *pix; // #ifndef WIN32 icon = conf->readEntry(APP_KEY+category); // #endif bool isIconAv = false; if (!icon.isEmpty() && !icon.isNull()) { // build the full path fullIconPath = iconPath + icon; pix = new QPixmap (fullIconPath); - if (pix) + if (!pix->isNull()) { QImage img = pix->convertToImage(); pix->convertFromImage(img.smoothScale(14,14)); c1->setIconName (icon); c1->setIcon (*pix); isIconAv = true; } } if (!isIconAv) { c1->setIcon (*getPredefinedIcon(category)); } c1->setListItem (catI); c1->initListItem(); categories.insert (c1->getCategoryName(), c1); } } f.close(); } #endif // UNUSED void ZSafe::resume(int) { owarn << "Resume" << oendl; // hide the main window + if ( !showpwd ) + { infoForm->hide(); // open zsafe again m_password = ""; selectedItem = NULL; // clear the password list QListViewItem *i; // step through all categories for (i = ListView->firstChild(); i != NULL; i = i->nextSibling()) { // step through all subitems QListViewItem *si; for (si = i->firstChild(); si != NULL; ) { QListViewItem *_si = si; si = si->nextSibling(); i->takeItem(_si); // remove from view list if (_si) delete _si; } } // ask for password and read again openDocument(filename); + } } //--------------------------------------------- bool ZSafe::openDocument(const char* _filename, const char* ) { int retval; char* entry[FIELD_SIZE]; // #ifndef WIN32 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); // #else // int validationFlag = 1; // #endif int pwdOk = 0; int numberOfTries = 3; for (int i=0; i < numberOfTries; i++) { QFile f(_filename); if (f.exists()) { // ask with a dialog for the password if (m_password.isEmpty()) getDocPassword(tr("Enter Password")); if (m_password.isEmpty() && validationFlag == 0) { owarn << "Wrong password" << oendl; QMessageBox::critical( 0, tr("ZSafe"), tr("Wrong password.\n\nZSafe will now exit.") ); exitZs (1); } retval = loadInit(_filename, m_password); if (retval != PWERR_GOOD) { owarn << "Error loading Document" << oendl; return false; } } else { #ifdef WIN32 this->setCaption("Qt ZSafe"); #else this->setCaption("ZSafe"); #endif filename = ""; @@ -1909,97 +1960,97 @@ bool ZSafe::openDocument(const char* _filename, const char* ) // use the existend item QListViewItem *catItem = cat->getListItem(); if (catItem) { QListViewItem * item = new ShadedListItem( 0, catItem ); item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); item->setText( 4, tr( field5 ) ); item->setText( 5, tr( field6 ) ); if (expandTree) catItem->setOpen( TRUE ); numberOfEntries++; } } else { QListViewItem *catI = new ShadedListItem( 1, ListView ); // create and insert a new item QListViewItem * item = new ShadedListItem( 0, catI ); item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); item->setText( 4, tr( field5 ) ); item->setText( 5, tr( field6 ) ); if (expandTree) catI->setOpen( TRUE ); Category *c1 = new Category(); c1->setCategoryName(category); QString icon; QString fullIconPath; QPixmap *pix; // #ifndef WIN32 icon = conf->readEntry(APP_KEY+category); // #endif bool isIconAv = false; if (!icon.isEmpty() && !icon.isNull()) { // build the full path fullIconPath = iconPath + icon; pix = new QPixmap (fullIconPath); - if (pix) + if (!pix->isNull()) { QImage img = pix->convertToImage(); pix->convertFromImage(img.smoothScale(14,14)); c1->setIconName (icon); c1->setIcon (*pix); isIconAv = true; } } if (!isIconAv) { c1->setIcon (*getPredefinedIcon(category)); } c1->setListItem (catI); c1->initListItem(); categories.insert (c1->getCategoryName(), c1); numberOfEntries++; } for (int count = 0; count < FIELD_SIZE; count++) { free(entry[count]); } retval = loadEntry(entry); if (retval == 2) { // m_parent->slotStatusHelpMsg("Last entry loaded"); } } // end while if (numberOfEntries == 0) { switch( QMessageBox::warning( this, tr("ZSafe"), tr("Empty document or\nwrong password.\nContinue?"), tr("&No"), tr("&Yes."), 0 ) ) { case 0: // No retval = loadFinalize(); exitZs (1); break; case 1: // Yes break; } } retval = loadFinalize(); return true; @@ -2257,96 +2308,99 @@ bool ZSafe::saveDocument(const char* _filename, strcpy(entry[j++], si->text(3).utf8()); entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1); strcpy(entry[j++], si->text(4).utf8()); entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1); strcpy(entry[j++], si->text(5).utf8()); retval = saveEntry(entry); for (int z=0; z<j; z++) { free(entry[z]); } if (retval == PWERR_DATA) { owarn << "1: Error writing file, contents not saved" << oendl; saveFinalize(); return false; } } } if (saveFinalize() == PWERR_DATA) { owarn << "2: Error writing file, contents not saved" << oendl; return false; } else { #ifndef DESKTOP Global::statusMessage (tr("Password file saved.")); #endif modified = false; return true; } } PasswordForm *newPwdDialog; bool newPwdDialogResult = false; void ZSafe::setPasswordDialogDone() { newPwdDialogResult = true; newPwdDialog->close(); } void ZSafe::getDocPassword(QString title) { owarn << "getDocPassword" << oendl; // open the 'Password' dialog PasswordForm *dialog = new PasswordForm(this, title, TRUE); newPwdDialog = dialog; newPwdDialogResult = false; + QPixmap image0( ( const char** ) zsafe_xpm ); + dialog->setIcon( image0); + connect( dialog->PasswordField, SIGNAL( returnPressed() ), this, SLOT( setPasswordDialogDone() ) ); // CS: !!! // int pos = filename.findRev ('/'); QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); #ifdef WIN32 dialog->setCaption("Qt " + ti); #else dialog->setCaption(ti); #endif // dialog->setCaption(title); dialog->PasswordField->setFocus(); DialogCode result = (DialogCode) dialog->exec(); #ifdef DESKTOP result = Accepted; #endif QString password; if (result == Accepted || newPwdDialogResult) { m_password = dialog->PasswordField->text(); } else { exitZs (1); } } int ZSafe::saveInit(const char *_filename, const char *password) { char key[128]; unsigned int j = 0; unsigned int keylength; // int val; int count2; Krc2* krc2 = new Krc2(); /* first we should check the permissions of the filename */ /* if (QFile::exists(_filename)) { val = checkFile(_filename); if (val != PWERR_GOOD) return val; } else { val = creat (_filename, (S_IRUSR | S_IWUSR)); @@ -2647,97 +2701,97 @@ void ZSafe::addCategory() 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"; owarn << category << oendl; 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) + if (!pix->isNull()) { // 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"), @@ -3116,97 +3170,97 @@ void ZSafe::editCategory() 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) { owarn << "Category found" << oendl; // if (!icon.isEmpty() && !icon.isNull()) if (icon != "predefined.png") { // build the full path fullIconPath = iconPath + icon; pix = new QPixmap (fullIconPath); - if (pix) + if (!pix->isNull()) { // 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) { owarn << category << oendl; 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) @@ -3647,49 +3701,95 @@ void ZSafe::setDocument(const QString& fileref) { // if (filename != fileref) // saveDocument(filename, FALSE); filename = fileref; } // save the current filename to the config file conf->writeEntry(APP_KEY+"document", filename); saveConf(); QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); #ifdef WIN32 this->setCaption("Qt ZSafe: " + ti); #else this->setCaption("ZSafe: " + ti); #endif // clear the password list QListViewItem *i; QListViewItem *c = NULL; // step through all categories for (i = ListView->firstChild(); i != NULL; i = i->nextSibling()) { if (c) delete c; // delete the previous category c = i; // step through all subitems QListViewItem *si; for (si = i->firstChild(); si != NULL; ) { QListViewItem *_si = si; si = si->nextSibling(); i->takeItem(_si); // remove from view list if (_si) delete _si; } } if (c) delete c; // delete the previous category categories.clear(); m_password = ""; selectedItem = NULL; openDocument(filename); #endif } +void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) { + if(item ==0) return; + switch (mouse) { + case 1: + { +#ifdef DESKTOP + QDragObject *d = new QTextDrag( item->text(column) , this ); + d->dragCopy(); +#endif + } + break; + case 2: + { + QClipboard *cb = QApplication::clipboard(); + + QIconSet copy_img((const char**) copy_xpm); + QIconSet edit_img((const char**) edit_xpm); + QPixmap folder_open_img((const char**) folder_open_xpm); + QPixmap editdelete_img((const char**) editdelete_xpm); + + QPopupMenu *m = new QPopupMenu(this); + int copyItem = m->insertItem( copy_img, tr( "Copy to Clipboard" )); + int editItem = m->insertItem(edit_img, tr( "Edit" )); + int showItem = m->insertItem(folder_open_img, tr( "Show Info" )); + int cancelItem = m->insertItem( editdelete_img, tr( "Cancel" )); + m->setFocus(); + int me=m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y() ) ) ; + if(me == copyItem) { + copyClip( item->text(column) ) ; + } else if (me == cancelItem) { + cb->clear(); + } else if (me == editItem) { + editPwd(); + } else if (me == showItem) { + showInfo(item); + } + } + break; + }; +} + +void ZSafe::copyClip( const QString &text) { + QClipboard *cb = QApplication::clipboard(); + cb->setText( text); +} + diff --git a/noncore/apps/zsafe/zsafe.h b/noncore/apps/zsafe/zsafe.h index eef5cdc..ca041ff 100644 --- a/noncore/apps/zsafe/zsafe.h +++ b/noncore/apps/zsafe/zsafe.h @@ -16,116 +16,117 @@ #include <stdio.h> #include "infoform.h" #include "categorylist.h" #include "shadedlistitem.h" #include <qvariant.h> #include <qdialog.h> #include <qwidgetstack.h> #include <qtimer.h> class QVBoxLayout; class QHBoxLayout; class QGridLayout; class ZListView; class QListViewItem; class QToolButton; class QTextBrowser; class QPopupMenu; #ifdef DESKTOP // #ifndef WIN32 class QSettings; // #endif #else class Config; #endif class CategoryDialog; class QPixmap; // number of fields for one entry #define FIELD_SIZE 7 class ZSafe : public QDialog { Q_OBJECT protected: void paintEvent( QPaintEvent * e ); void resizeEvent ( QResizeEvent * ); bool raiseFlag; QTimer raiseTimer; public: ZSafe( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = WDestructiveClose ); ~ZSafe(); - static const QColor *evenRowColor; - static const QColor *oddRowColor; + static const QColor *evenRowColor; + static const QColor *oddRowColor; QToolButton* Edit; QToolButton* Delete; QToolButton* Find; QToolButton* New; ZListView* ListView; QString cfgFile; QString iconPath; InfoForm *infoForm; CategoryDialog *categoryDialog; QListViewItem *selectedItem; // current selected item QListViewItem *copiedItem; // copied item bool IsCopy; bool IsCut; bool modified; // true if database is modified + bool showpwd; // show PWD Dialog QListViewItem *lastSearchedCategory; QListViewItem *lastSearchedItem; QString lastSearchedName; QString lastSearchedUsername; QString lastSearchedComment; CategoryList categories; // list of categories bool isCategory(QListViewItem *_item); void getDocPassword(QString title); QString filename; enum { PWERR_GOOD, // success PWERR_OPEN, // can't open filedescriptor / can't create file PWERR_PERM, // permissions are bad PWERR_SYML, // is a symlink PWERR_STAT, // can't get file status PWERR_DATA // can't read correct data }; long load_buffer_length; long save_buffer_length; /** password for the file */ QString m_password; /** globals needed for file loading */ int lastcount, size; /** these three are needed in all save functions and initialized in save _init() */ FILE *fd; unsigned short iv[4]; char *buffer; /** these two are global because save_entry() and save_finalize() both n eed them */ int bufferIndex; unsigned short plaintext[4]; #ifdef DESKTOP // #ifndef WIN32 QSettings *conf; // #endif #else Config *conf; #endif bool expandTree; QPopupMenu *file; @@ -138,56 +139,59 @@ public: int loadFinalize(void); bool saveDocument(const char* filename, bool withPwd, const char* format=0); int saveInit(const char *filename, const char *password); int saveEntry(char *entry[4]); int saveFinalize(void); void saveConf(); QPixmap * getPredefinedIcon(QString category); QString getFieldLabel (QListViewItem *_item, QString field, QString def); QString getFieldLabel (QString category, QString field, QString def); void setCategoryDialogFields(CategoryDialog *dialog); void setCategoryDialogFields(CategoryDialog *dialog, QString category); void saveCategoryDialogFields(CategoryDialog *dialog); void resume(int signum); void exitZs (int ec); public slots: virtual void deletePwd(); virtual void editPwd(); virtual void newPwd(); virtual void findPwd(); virtual void quitMe(); virtual void listViewSelected( QListViewItem *_item); virtual void showInfo( QListViewItem *_item); virtual void writeAllEntries(); virtual void readAllEntries(); virtual void removeAsciiFile(); virtual void setPasswordDialogDone(); virtual void addCategory(); virtual void delCategory(); virtual void editCategory(); virtual void cutItem(); virtual void copyItem(); virtual void pasteItem(); virtual void newDocument(); virtual void loadDocument(); virtual void saveDocumentAs(); virtual void saveDocumentWithoutPwd(); virtual void saveDocumentWithPwd(); virtual void about(); virtual void setExpandFlag(); virtual void categoryFieldActivated( const QString& str); + virtual void ListPressed(int, QListViewItem *, const QPoint&, int); + virtual void copyClip( const QString &text); + private slots: void setDocument(const QString& fileref); void slotLoadDocu(); void slotRaiseTimer(); }; #endif // ZSAFE_H |