Diffstat (limited to 'noncore/apps/zsafe/zsafe.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 137 |
1 files changed, 53 insertions, 84 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index f3d57f8..41c572a 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp | |||
@@ -363,13 +363,13 @@ static const char* const general_data[] = { | |||
363 | if (conf) | 363 | if (conf) |
364 | { | 364 | { |
365 | delete conf; | 365 | delete conf; |
366 | 366 | ||
367 | #ifdef DESKTOP | 367 | #ifdef DESKTOP |
368 | #ifndef Q_WS_WIN | 368 | #ifndef Q_WS_WIN |
369 | conf = new QSettings (); | 369 | conf = new QSettings(); |
370 | conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); | 370 | conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); |
371 | #else | 371 | #else |
372 | conf = new QSettings (cfgFile); | 372 | conf = new QSettings (cfgFile); |
373 | conf->insertSearchPath (QSettings::Unix, cfgFile); | 373 | conf->insertSearchPath (QSettings::Unix, cfgFile); |
374 | #endif | 374 | #endif |
375 | #else | 375 | #else |
@@ -490,29 +490,27 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) | |||
490 | #endif | 490 | #endif |
491 | 491 | ||
492 | #endif | 492 | #endif |
493 | setCaption( tr( "ZSafe" ) ); | 493 | setCaption( tr( "ZSafe" ) ); |
494 | QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe"; | 494 | QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe"; |
495 | QString filename = conf->readEntry(APP_KEY+"document"); | 495 | QString filename = conf->readEntry(APP_KEY+"document"); |
496 | if (filename.isEmpty() || filename.isNull()) | 496 | if ( !QFileInfo(filename).exists() || !QDir(zsafeAppDirPath).exists() ) |
497 | { | 497 | { |
498 | |||
499 | // check if the directory application exists, if not | 498 | // check if the directory application exists, if not |
500 | // create it | 499 | // create it |
501 | // #ifndef Q_WS_WIN | 500 | // #ifndef Q_WS_WIN |
502 | // QString d1("Documents/application"); | 501 | // QString d1("Documents/application"); |
503 | // #else | 502 | // #else |
504 | QString d1(QDir::homeDirPath() + "/Documents/application"); | 503 | QString d1(QDir::homeDirPath() + "/Documents/application"); |
505 | // #endif | 504 | // #endif |
506 | QDir pd1(d1); | 505 | QDir pd1(d1); |
507 | if (!pd1.exists()) | 506 | if (!pd1.exists()) |
508 | { | 507 | { |
509 | |||
510 | QDir pd2(QDir::homeDirPath() + "/Documents"); | 508 | QDir pd2(QDir::homeDirPath() + "/Documents"); |
511 | if (!pd2.exists()) { | 509 | if (!pd2.exists()) { |
512 | QDir pd3(QDir::homeDirPath()); | 510 | QDir pd3(QDir::homeDirPath()); |
513 | if (!pd3.mkdir("Documents", FALSE)) { | 511 | if (!pd3.mkdir("Documents", FALSE)) { |
514 | } | 512 | } |
515 | } | 513 | } |
516 | 514 | ||
517 | if (!pd2.mkdir("application", FALSE)) | 515 | if (!pd2.mkdir("application", FALSE)) |
518 | { | 516 | { |
@@ -542,13 +540,12 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) | |||
542 | tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2)); | 540 | tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2)); |
543 | #endif | 541 | #endif |
544 | exitZs (1); | 542 | exitZs (1); |
545 | } | 543 | } |
546 | } | 544 | } |
547 | 545 | ||
548 | // set the default filename | ||
549 | filename = zsafeAppDirPath + "/passwords.zsf"; | 546 | filename = zsafeAppDirPath + "/passwords.zsf"; |
550 | 547 | ||
551 | // save the current filename to the config file | 548 | // save the current filename to the config file |
552 | conf->writeEntry(APP_KEY+"document", filename); | 549 | conf->writeEntry(APP_KEY+"document", filename); |
553 | saveConf(); | 550 | saveConf(); |
554 | } | 551 | } |
@@ -1336,38 +1333,13 @@ void ZSafe::writeAllEntries() | |||
1336 | QMessageBox::critical( 0, tr("ZSafe"), | 1333 | QMessageBox::critical( 0, tr("ZSafe"), |
1337 | tr("No document defined.\nYou have to create a new document")); | 1334 | tr("No document defined.\nYou have to create a new document")); |
1338 | return; | 1335 | return; |
1339 | } | 1336 | } |
1340 | 1337 | ||
1341 | // open the file dialog | 1338 | // open the file dialog |
1342 | #ifndef DESKTOP | 1339 | QString fn = zsaveDialog(); |
1343 | #ifndef NO_OPIE | ||
1344 | QMap<QString, QStringList> mimeTypes; | ||
1345 | mimeTypes.insert(tr("All"), QStringList() ); | ||
1346 | mimeTypes.insert(tr("Text"), "text/*" ); | ||
1347 | QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | ||
1348 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
1349 | QString::null, | ||
1350 | mimeTypes, | ||
1351 | this, | ||
1352 | tr ("Export text file")); | ||
1353 | #else | ||
1354 | QString fn = ScQtFileEdit::getSaveAsFileName(this, | ||
1355 | tr ("Export text file"), | ||
1356 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
1357 | "*.txt"); | ||
1358 | #endif | ||
1359 | #else | ||
1360 | QString fn = QFileDialog::getSaveFileName( | ||
1361 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
1362 | "ZSafe (*.txt)", | ||
1363 | this, | ||
1364 | "ZSafe File Dialog" | ||
1365 | "Choose a text file" ); | ||
1366 | #endif | ||
1367 | |||
1368 | // open the new document | 1340 | // open the new document |
1369 | if (fn && fn.length() > 0 ) | 1341 | if (fn && fn.length() > 0 ) |
1370 | { | 1342 | { |
1371 | QFile f( fn ); | 1343 | QFile f( fn ); |
1372 | if ( !f.open( IO_WriteOnly ) ) { | 1344 | if ( !f.open( IO_WriteOnly ) ) { |
1373 | #ifndef NO_OPIE | 1345 | #ifndef NO_OPIE |
@@ -1918,12 +1890,14 @@ void ZSafe::resume(int) | |||
1918 | 1890 | ||
1919 | //--------------------------------------------- | 1891 | //--------------------------------------------- |
1920 | 1892 | ||
1921 | 1893 | ||
1922 | bool ZSafe::openDocument(const char* _filename, const char* ) | 1894 | bool ZSafe::openDocument(const char* _filename, const char* ) |
1923 | { | 1895 | { |
1896 | QString name= _filename; | ||
1897 | qWarning("openDocument "+name); | ||
1924 | int retval; | 1898 | int retval; |
1925 | char* entry[FIELD_SIZE]; | 1899 | char* entry[FIELD_SIZE]; |
1926 | // #ifndef Q_WS_WIN | 1900 | // #ifndef Q_WS_WIN |
1927 | int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); | 1901 | int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); |
1928 | // #else | 1902 | // #else |
1929 | // int validationFlag = 1; | 1903 | // int validationFlag = 1; |
@@ -1967,13 +1941,27 @@ bool ZSafe::openDocument(const char* _filename, const char* ) | |||
1967 | #ifdef Q_WS_WIN | 1941 | #ifdef Q_WS_WIN |
1968 | this->setCaption("Qt ZSafe"); | 1942 | this->setCaption("Qt ZSafe"); |
1969 | #else | 1943 | #else |
1970 | this->setCaption("ZSafe"); | 1944 | this->setCaption("ZSafe"); |
1971 | #endif | 1945 | #endif |
1972 | filename = ""; | 1946 | filename = ""; |
1947 | switch( QMessageBox::warning( this, tr("ZSafe"), | ||
1948 | tr("<P>You must create a new document first. Ok to create?</P>"), | ||
1949 | tr("&Yes"), tr("&No."), | ||
1950 | 0 | ||
1951 | ) ) | ||
1952 | { | ||
1953 | case 1: // No | ||
1973 | return false; | 1954 | return false; |
1955 | break; | ||
1956 | case 0: // Yes | ||
1957 | newDocument(); | ||
1958 | return false; | ||
1959 | break; | ||
1960 | } | ||
1961 | |||
1974 | } | 1962 | } |
1975 | 1963 | ||
1976 | 1964 | ||
1977 | // load the validation entry | 1965 | // load the validation entry |
1978 | if (validationFlag == 0) | 1966 | if (validationFlag == 0) |
1979 | { | 1967 | { |
@@ -3444,37 +3432,13 @@ void ZSafe::pasteItem() | |||
3444 | } | 3432 | } |
3445 | 3433 | ||
3446 | void ZSafe::newDocument() | 3434 | void ZSafe::newDocument() |
3447 | { | 3435 | { |
3448 | 3436 | ||
3449 | // open the file dialog | 3437 | // open the file dialog |
3450 | #ifndef DESKTOP | 3438 | QString newFile = zsaveDialog(); |
3451 | #ifndef NO_OPIE | ||
3452 | QMap<QString, QStringList> mimeTypes; | ||
3453 | mimeTypes.insert(tr("All"), QStringList() ); | ||
3454 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); | ||
3455 | QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | ||
3456 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3457 | QString::null, | ||
3458 | mimeTypes, | ||
3459 | this, | ||
3460 | tr ("Create new ZSafe document")); | ||
3461 | #else | ||
3462 | QString newFile = ScQtFileEdit::getSaveAsFileName(this, | ||
3463 | tr ("Create new ZSafe document"), | ||
3464 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3465 | "*.zsf"); | ||
3466 | #endif | ||
3467 | #else | ||
3468 | QString newFile = QFileDialog::getSaveFileName( | ||
3469 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3470 | "ZSafe (*.zsf)", | ||
3471 | this, | ||
3472 | "ZSafe File Dialog" | ||
3473 | "Choose a ZSafe file" ); | ||
3474 | #endif | ||
3475 | 3439 | ||
3476 | // open the new document | 3440 | // open the new document |
3477 | if (newFile && newFile.length() > 0 ) | 3441 | if (newFile && newFile.length() > 0 ) |
3478 | { | 3442 | { |
3479 | // save the previous opened document | 3443 | // save the previous opened document |
3480 | if (!filename.isEmpty()) | 3444 | if (!filename.isEmpty()) |
@@ -3610,39 +3574,13 @@ void ZSafe::loadDocument() | |||
3610 | } | 3574 | } |
3611 | } | 3575 | } |
3612 | 3576 | ||
3613 | void ZSafe::saveDocumentAs() | 3577 | void ZSafe::saveDocumentAs() |
3614 | { | 3578 | { |
3615 | 3579 | ||
3616 | #ifndef DESKTOP | 3580 | QString newFile = zsaveDialog(); |
3617 | #ifndef NO_OPIE | ||
3618 | QMap<QString, QStringList> mimeTypes; | ||
3619 | mimeTypes.insert(tr("All"), QStringList() ); | ||
3620 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); | ||
3621 | QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | ||
3622 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3623 | QString::null, | ||
3624 | mimeTypes, | ||
3625 | this, | ||
3626 | tr ("Save ZSafe document as..")); | ||
3627 | #else | ||
3628 | QString newFile = ScQtFileEdit::getSaveAsFileName(this, | ||
3629 | tr ("Save ZSafe document as.."), | ||
3630 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3631 | "*.zsf"); | ||
3632 | #endif | ||
3633 | #else | ||
3634 | // open the file dialog | ||
3635 | QString newFile = QFileDialog::getSaveFileName( | ||
3636 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3637 | "ZSafe (*.zsf)", | ||
3638 | this, | ||
3639 | "ZSafe File Dialog" | ||
3640 | "Choose a ZSafe file" ); | ||
3641 | #endif | ||
3642 | |||
3643 | // open the new document | 3581 | // open the new document |
3644 | if (newFile && newFile.length() > 0 ) | 3582 | if (newFile && newFile.length() > 0 ) |
3645 | { | 3583 | { |
3646 | // save the previous opened document | 3584 | // save the previous opened document |
3647 | if (!filename.isEmpty()) | 3585 | if (!filename.isEmpty()) |
3648 | saveDocument(filename, FALSE); | 3586 | saveDocument(filename, FALSE); |
@@ -3850,12 +3788,14 @@ void ZSafe::setDocument(const QString& fileref) | |||
3850 | categories.clear(); | 3788 | categories.clear(); |
3851 | 3789 | ||
3852 | m_password = ""; | 3790 | m_password = ""; |
3853 | selectedItem = NULL; | 3791 | selectedItem = NULL; |
3854 | 3792 | ||
3855 | openDocument(filename); | 3793 | openDocument(filename); |
3794 | #else | ||
3795 | Q_UNUSED(fileref); | ||
3856 | #endif | 3796 | #endif |
3857 | } | 3797 | } |
3858 | 3798 | ||
3859 | 3799 | ||
3860 | void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) { | 3800 | void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) { |
3861 | if(item ==0) return; | 3801 | if(item ==0) return; |
@@ -3901,6 +3841,35 @@ void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int colum | |||
3901 | void ZSafe::copyClip( const QString &text) { | 3841 | void ZSafe::copyClip( const QString &text) { |
3902 | QClipboard *cb = QApplication::clipboard(); | 3842 | QClipboard *cb = QApplication::clipboard(); |
3903 | cb->setText( text); | 3843 | cb->setText( text); |
3904 | } | 3844 | } |
3905 | 3845 | ||
3906 | 3846 | ||
3847 | QString ZSafe::zsaveDialog() { | ||
3848 | |||
3849 | QString fn; | ||
3850 | #ifndef DESKTOP | ||
3851 | #ifndef NO_OPIE | ||
3852 | QMap<QString, QStringList> mimeTypes; | ||
3853 | mimeTypes.insert(tr("All"), QStringList() ); | ||
3854 | mimeTypes.insert(tr("Text"), "text/*" ); | ||
3855 | fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | ||
3856 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3857 | QString::null, | ||
3858 | mimeTypes, | ||
3859 | this, | ||
3860 | tr ("Export text file")); | ||
3861 | #else | ||
3862 | fn = ScQtFileEdit::getSaveAsFileName(this, | ||
3863 | tr ("Export text file"), | ||
3864 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3865 | "*.txt"); | ||
3866 | #endif | ||
3867 | #else | ||
3868 | fn = QFileDialog::getSaveFileName( | ||
3869 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3870 | "ZSafe (*.txt)", | ||
3871 | this, | ||
3872 | "ZSafe"); | ||
3873 | #endif | ||
3874 | return fn; | ||
3875 | } | ||