summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/pwm.cpp
Side-by-side diff
Diffstat (limited to 'pwmanager/pwmanager/pwm.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwm.cpp85
1 files changed, 83 insertions, 2 deletions
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
index 66d26d6..ac0c978 100644
--- a/pwmanager/pwmanager/pwm.cpp
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -56,6 +56,7 @@
#include "addentrywndimpl.h"
#include "globalstuff.h"
#include "findwndimpl.h"
+#include "csv.h"
#ifdef CONFIG_KWALLETIF
# include "kwalletif.h"
@@ -113,7 +114,8 @@ enum {
// Button IDs for "export" popup menu (in "file" popup menu)
enum {
BUTTON_POPUP_EXPORT_TEXT = 0,
- BUTTON_POPUP_EXPORT_GPASMAN
+ BUTTON_POPUP_EXPORT_GPASMAN,
+ BUTTON_POPUP_EXPORT_CSV
#ifdef CONFIG_KWALLETIF
,BUTTON_POPUP_EXPORT_KWALLET
#endif
@@ -121,7 +123,8 @@ enum {
// Button IDs for "import" popup menu (in "file" popup menu)
enum {
BUTTON_POPUP_IMPORT_TEXT = 0,
- BUTTON_POPUP_IMPORT_GPASMAN
+ BUTTON_POPUP_IMPORT_GPASMAN,
+ BUTTON_POPUP_IMPORT_CSV
#ifdef CONFIG_KWALLETIF
,BUTTON_POPUP_IMPORT_KWALLET
#endif
@@ -181,10 +184,12 @@ PwM::PwM(PwMInit *_init, PwMDoc *doc,
PwM::~PwM()
{
+ //qDebug("PwM::~PwM()");
disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)),
this, SLOT(docClosed(PwMDoc *)));
conf()->confWndMainWndSize(size());
emit closed(this);
+ //qDebug("PwM::~PwM() emited closed(this)");
delete view;
}
@@ -241,6 +246,8 @@ void PwM::initMenubar()
SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT);
exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN);
+ exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this,
+ SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV);
#ifdef CONFIG_KWALLETIF
exportPopup->insertItem(i18n("&KWallet..."), this,
SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET);
@@ -253,6 +260,8 @@ void PwM::initMenubar()
SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT);
importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN);
+ importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this,
+ SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV);
#ifdef CONFIG_KWALLETIF
importPopup->insertItem(i18n("&KWallet..."), this,
SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET);
@@ -1016,6 +1025,78 @@ void PwM::exportToGpasman()
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
}
+
+
+void PwM::exportToCsv()
+{
+ PWM_ASSERT(curDoc());
+ if (curDoc()->isDocEmpty()) {
+ KMessageBox::information(this,
+ i18n
+ ("Sorry, there is nothing to export;\n"
+ "please add some passwords first."),
+ i18n("Nothing to Do"));
+ return;
+ }
+
+ curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
+ QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this));
+ if (fn.isEmpty()) {
+ curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
+ return;
+ }
+
+ Csv csv(this);
+ if (!csv.exportData(fn, curDoc())) {
+ curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
+ showStatMsg(i18n("CSV file export failed."));
+ return;
+ }
+ showStatMsg(i18n("Successfully exported data."));
+ curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
+}
+
+bool PwM::importCsv()
+{
+ Csv csv(this);
+ if (!isVirgin()) {
+ if (KMessageBox::questionYesNo(this,
+ i18n("Do you want to import the data\n"
+ "into the current document? (If you\n"
+ "select \"no\", a new document will be\n"
+ "opened.)"),
+ i18n("Import into This Document?"))
+ == KMessageBox::No) {
+ // import the data to a new window.
+ PwM *newInstance = init->createMainWnd();
+ bool ok = newInstance->importCsv();
+ if (!ok) {
+ newInstance->setForceQuit(true);
+ delete_and_null(newInstance);
+ }
+ return ok;
+ }
+ }
+
+ QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this);
+ if (filename.isEmpty())
+ return false;
+ curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
+ if (!csv.importData(filename, curDoc())) {
+ curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
+ showStatMsg(i18n("CSV file import failed."));
+ return false;
+ }
+ curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
+ KMessageBox::information(this,
+ i18n("Successfully imported the CSV data\n"
+ "into the current document."), i18n("Successfully Imported"));
+ showStatMsg(i18n("Successfully imported"));
+ setVirgin(false);
+ return true;
+}
+
+
void PwM::exportToKWallet()
{
#ifdef CONFIG_KWALLETIF