-rw-r--r-- | pwmanager/pwmanager/commentbox.cpp | 10 | ||||
-rw-r--r-- | pwmanager/pwmanager/commentbox.h | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/listviewpwm.cpp | 8 | ||||
-rw-r--r-- | pwmanager/pwmanager/listviewpwm.h | 1 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwm.cpp | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 58 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmview.cpp | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle_0.cpp | 20 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle_0.h | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle_1.cpp | 19 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle_1.h | 2 |
12 files changed, 121 insertions, 11 deletions
diff --git a/pwmanager/pwmanager/commentbox.cpp b/pwmanager/pwmanager/commentbox.cpp index 51f88b2..5416856 100644 --- a/pwmanager/pwmanager/commentbox.cpp +++ b/pwmanager/pwmanager/commentbox.cpp @@ -136,148 +136,148 @@ void CommentBox::switchTo(commentBoxMode newMode) // setup new mode switch (newMode) { case mode_text: textDta = new QTextEdit(parentWidget); textDta->setTextFormat(Qt::PlainText); textDta->setReadOnly(true); textDta->show(); break; case mode_html: htmlDta = new KHTMLPart(parentWidget, 0, parentWidget); htmlDta->show(); break; default: BUG(); break; } mode = newMode; } void CommentBox::show() { switch (mode) { case mode_text: PWM_ASSERT(textDta); textDta->show(); break; case mode_html: PWM_ASSERT(htmlDta); htmlDta->show(); break; default: break; } } void CommentBox::hide() { switch (mode) { case mode_text: PWM_ASSERT(textDta); textDta->hide(); break; case mode_html: PWM_ASSERT(htmlDta); htmlDta->hide(); break; default: break; } } void CommentBox::resize(const QSize &size) { switch (mode) { case mode_text: PWM_ASSERT(textDta); textDta->resize(size); break; case mode_html: PWM_ASSERT(htmlDta); htmlDta->view()->resize(size); break; default: break; } } QSize CommentBox::size() { switch (mode) { case mode_text: PWM_ASSERT(textDta); return textDta->size(); break; case mode_html: PWM_ASSERT(htmlDta); return htmlDta->view()->size(); break; default: break; } return QSize(); } //////////////////////////////////////////////////////////////////////// #else CommentBox::CommentBox(QWidget *_parentWidget) - : QMultiLineEdit(_parentWidget) + : QTextBrowser(_parentWidget) { - this->setReadOnly(true); + //this->setReadOnly(true); setFocusPolicy( QWidget::ClickFocus ); } CommentBox::~CommentBox() { } void CommentBox::clear() { this->hide(); } void CommentBox::setText(const QString &text) { - QMultiLineEdit::setText( text); - if (!this->isVisible()) - this->show(); + QTextBrowser::setText( text); + if (!isVisible()) + show(); } bool CommentBox::getText(QString *text) { *text = this->text(); return true; } void CommentBox::setContent(const QString &dta) { // if there's no data, hide the comment-box if (dta.isEmpty()) { clear(); return; } // we assume it's plain text setText(dta); } #endif diff --git a/pwmanager/pwmanager/commentbox.h b/pwmanager/pwmanager/commentbox.h index 352867c..3103353 100644 --- a/pwmanager/pwmanager/commentbox.h +++ b/pwmanager/pwmanager/commentbox.h @@ -1,124 +1,124 @@ /*************************************************************************** * * * copyright (C) 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef COMMENTBOX_H #define COMMENTBOX_H #include <qstring.h> #include <qsize.h> class QWidget; class QTextEdit; class KHTMLPart; #ifndef PWM_EMBEDDED class CommentBox { protected: enum commentBoxMode { mode_notSet = 0, mode_text, mode_html }; public: CommentBox(QWidget *_parentWidget); ~CommentBox(); /** clear all data in the comment box */ void clear(); /** show the comment box */ void show(); /** hide the comment box */ void hide(); /** resize the comment box */ void resize(const QSize &size); void resize(int w, int h) { resize(QSize(w, h)); } /** get the size of the comment box */ QSize size(); /** if neccessary switch to text-mode and * insert this text into the comment box */ void setText(const QString &text); /** get the text of the comment box. * If it's not in text-mode it returns false */ bool getText(QString *text); /** if neccessary switch to HTML-mode and * insert this html code into the comment box */ void setHtml(QString code); /** checks "dta" for its type, sets the correct * mode and writes "dta" to the comment box */ void setContent(const QString &dta); protected: /** switch the current mode */ void switchTo(commentBoxMode newMode); /** clear all text data */ void clearText(); /** clear all HTML data */ void clearHtml(); protected: /** parent widget for this comment box */ QWidget *parentWidget; /** current comment box usage type */ commentBoxMode mode; /** if the comment box is a normal textbox, data is stored here */ QTextEdit *textDta; /** if the comment box is a HTML box, data is stored here */ KHTMLPart *htmlDta; }; #else -#include <qmultilineedit.h> +#include <qtextbrowser.h> /** Implementation of the advanced HTML comment box */ //US ENH: CommentBox must be derived from QWidget, to allow the splitter to set a initial size // without conflicting with the two display modes -class CommentBox : public QMultiLineEdit +class CommentBox : public QTextBrowser { public: CommentBox(QWidget *_parentWidget); ~CommentBox(); /** clear all data in the comment box */ void clear(); /** if neccessary switch to text-mode and * insert this text into the comment box */ void setText(const QString &text); /** get the text of the comment box. * If it's not in text-mode it returns false */ bool getText(QString *text); /** if neccessary switch to HTML-mode and * insert this html code into the comment box */ void setContent(const QString &dta); }; #endif #endif diff --git a/pwmanager/pwmanager/listviewpwm.cpp b/pwmanager/pwmanager/listviewpwm.cpp index 85e788c..8d46fff 100644 --- a/pwmanager/pwmanager/listviewpwm.cpp +++ b/pwmanager/pwmanager/listviewpwm.cpp @@ -1,113 +1,121 @@ /*************************************************************************** * * * copyright (C) 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #include "listviewpwm.h" #include "pwmexception.h" #include "pwmview.h" #include <qpainter.h> #include <qpixmap.h> #include <kiconloader.h> #ifdef PWM_EMBEDDED #include <kglobal.h> #endif ListViewPwM::ListViewPwM(QWidget *parent, const char *name) : KListView(parent, name) { // setResizeMode(QListView::AllColumns); setAllColumnsShowFocus (true ); } bool ListViewPwM::event(QEvent *e) { if (e->type() == QEvent::LayoutHint) emit layoutChanged(); + if (e->type() == QEvent::KeyPress) { + QKeyEvent* ke = (QKeyEvent*) e; + if ( ke->key() == Qt::Key_Space) { + emit toggleOverview(); + return true; + } + + } return KListView::event(e); } QPixmap * ListViewItemPwM::onPix = 0; QPixmap * ListViewItemPwM::offPix = 0; ListViewItemPwM::ListViewItemPwM(QListView *parent) : QCheckListItem(parent, "", QCheckListItem::CheckBox) { if (!onPix) { PWM_ASSERT(!offPix); KIconLoader* picons; #ifndef PWM_EMBEDDED KIconLoader il; picons = &il; #else picons = KGlobal::iconLoader(); #endif KIconLoader il; #ifndef PWM_EMBEDDED static QPixmap onP(picons->loadIcon("button_ok", KIcon::Small)); #else static QPixmap onP(picons->loadIcon("decrypted", KIcon::Small)); #endif onPix = &onP; static QPixmap offP(picons->loadIcon("encrypted", KIcon::Small)); offPix = &offP; } } void ListViewItemPwM::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align) { // qDebug("ListViewItemPwM::paintCell column=%i", column); if (!p) return; //US BUG: if (column != COLUMN_DESC) { QCheckListItem::paintCell(p, cg, column, width, align); return; } QPixmap *curPix = isOn() ? onPix : offPix; int pixSpace = curPix->width(); pixSpace += 4; #ifndef PWM_EMBEDDED QRect window(p->viewport()); // clear the rectangle (we have to clear it first. see QT doc) p->eraseRect(0, 0, pixSpace, window.height()); // now draw the pixmap int y = (height() - curPix->height()) / 2; p->drawPixmap(1, y, *curPix); window.moveLeft(pixSpace); p->setViewport(window); #else p->eraseRect(0, 0, pixSpace, height()); // now draw the pixmap int y = (height() - curPix->height()) / 2; p->drawPixmap(1, y, *curPix); p->translate( pixSpace, 0 ); #endif QListViewItem::paintCell(p, cg, column, width - pixSpace, align); } #ifndef PWM_EMBEDDED #include "listviewpwm.moc" #endif diff --git a/pwmanager/pwmanager/listviewpwm.h b/pwmanager/pwmanager/listviewpwm.h index e6471c6..840ee73 100644 --- a/pwmanager/pwmanager/listviewpwm.h +++ b/pwmanager/pwmanager/listviewpwm.h @@ -1,57 +1,58 @@ /*************************************************************************** * * * copyright (C) 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef __LISTVIEW_H #define __LISTVIEW_H #include <klistview.h> /** PwManager implementation of the list view. * Derived from KListView. */ class ListViewPwM : public KListView { Q_OBJECT public: ListViewPwM(QWidget *parent = 0, const char *name = 0); signals: void layoutChanged(); + void toggleOverview(); protected: virtual bool event(QEvent *e); }; class ListViewItemPwM : public QCheckListItem { public: ListViewItemPwM(QListView *parent); protected: void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align); protected: /** pixmap to display for an item with state "on" */ static QPixmap *onPix; /** pixmap to display for an item with state "off" */ static QPixmap *offPix; }; #endif diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp index aed8ec0..9187380 100644 --- a/pwmanager/pwmanager/pwm.cpp +++ b/pwmanager/pwmanager/pwm.cpp @@ -634,210 +634,210 @@ void PwM::addPwd_slot() void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) { PwMDoc *doc; if (_doc) { doc = _doc; } else { doc = curDoc(); } PWM_ASSERT(doc); doc->timer()->getLock(DocTimer::id_autoLockTimer); #ifndef PWM_EMBEDDED AddEntryWndImpl w; #else AddEntryWndImpl w(doc, this, "addentrywndimpl"); #endif w.setCaption( i18n ("Add new password") ); vector<string> catList; doc->getCategoryList(&catList); unsigned i, size = catList.size(); for (i = 0; i < size; ++i) { w.addCategory(catList[i].c_str()); } w.setCurrCategory(view->getCurrentCategory()); if (pw) w.pwLineEdit->setText(*pw); tryAgain: w.descLineEdit->setFocus(); if (w.exec() == 1) { PwMDataItem d; //US BUG: to initialize all values of curEntr with meaningfulldata, // we call clear on it. Reason: Metadata will be uninitialized otherwise. // another option would be to create a constructor for PwMDataItem d.clear(true); d.desc = w.getDescription().latin1(); d.name = w.getUsername().latin1(); d.pw = w.getPassword().latin1(); d.comment = w.getComment().latin1(); d.url = w.getUrl().latin1(); d.launcher = w.getLauncher().latin1(); PwMerror ret = doc->addEntry(w.getCategory(), &d); if (ret == e_entryExists) { KMessageBox::error(this, i18n ("An entry with this \"Description\",\n" "does already exist.\n" "Please select another description."), i18n("entry already exists.")); goto tryAgain; } else if (ret == e_maxAllowedEntr) { KMessageBox::error(this, i18n("The maximum possible number of\nentries" "has been reached.\nYou can't add more entries."), i18n("maximum number of entries")); doc->timer()->putLock(DocTimer::id_autoLockTimer); return; } } setVirgin(false); doc->timer()->putLock(DocTimer::id_autoLockTimer); } //US ENH : changed code to run with older MOC void PwM::editPwd_slot() { editPwd_slot3(0,0,0); } void PwM::editPwd_slot1(const QString *category) { editPwd_slot3(category, 0, 0); } void PwM::editPwd_slot3(const QString *category, const int *index, PwMDoc *_doc) { PwMDoc *doc; if (_doc) { doc = _doc; } else { doc = curDoc(); } PWM_ASSERT(doc); if (doc->isDocEmpty()) return; if (doc->isDeepLocked()) return; doc->timer()->getLock(DocTimer::id_autoLockTimer); unsigned int curEntryIndex; if (index) { curEntryIndex = *index; } else { if (!(view->getCurEntryIndex(&curEntryIndex))) { + qDebug("couldn't get index. Maybe we have a binary entry here. "); printDebug("couldn't get index. Maybe we have a binary entry here."); doc->timer()->putLock(DocTimer::id_autoLockTimer); return; } } QString curCategory; if (category) { curCategory = *category; } else { curCategory = view->getCurrentCategory(); } PwMDataItem currItem; if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { doc->timer()->putLock(DocTimer::id_autoLockTimer); return; } BUG_ON(currItem.binary); - AddEntryWndImpl w(doc); w.setCaption( i18n ("Edit password") ); vector<string> catList; doc->getCategoryList(&catList); unsigned i, size = catList.size(); for (i = 0; i < size; ++i) { w.addCategory(catList[i].c_str()); } w.setCurrCategory(curCategory); w.setDescription(currItem.desc.c_str()); w.setUsername(currItem.name.c_str()); w.setPassword(currItem.pw.c_str()); w.setUrl(currItem.url.c_str()); w.setLauncher(currItem.launcher.c_str()); w.setComment(currItem.comment.c_str()); w.descLineEdit->setFocus(); if (w.exec() == 1) { currItem.desc = w.getDescription().latin1(); currItem.name = w.getUsername().latin1(); currItem.pw = w.getPassword().latin1(); currItem.comment = w.getComment().latin1(); currItem.url = w.getUrl().latin1(); currItem.launcher = w.getLauncher().latin1(); if (!doc->editEntry(curCategory, w.getCategory(), curEntryIndex, &currItem)) { KMessageBox::error(this, i18n("Couldn't edit the entry.\n" "Maybe you changed the category and\n" "this entry is already present\nin the new " "category?"), i18n("couldn't edit entry.")); doc->timer()->putLock(DocTimer::id_autoLockTimer); return; } } doc->timer()->putLock(DocTimer::id_autoLockTimer); } void PwM::deletePwd_slot() { PWM_ASSERT(curDoc()); if (curDoc()->isDocEmpty()) return; if (curDoc()->isDeepLocked()) return; curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); unsigned int curEntryIndex = 0; if (!(view->getCurEntryIndex(&curEntryIndex))) { printDebug("couldn't get index"); curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); return; } PwMDataItem currItem; QString curCategory = view->getCurrentCategory(); if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { printDebug("couldn't get entry"); curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); return; } if (KMessageBox:: questionYesNo(this, i18n ("Do you really want to delete\nthe selected entry") + " \n\"" + QString(currItem.desc.c_str()) + "\" ?", i18n("delete?")) == KMessageBox::Yes) { curDoc()->delEntry(curCategory, curEntryIndex); } curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); } void PwM::changeMasterPwd_slot() { PWM_ASSERT(curDoc()); curDoc()->changeCurrentPw(); } void PwM::lockWnd_slot() { PWM_ASSERT(curDoc()); curDoc()->lockAll(true); } void PwM::deepLockWnd_slot() { PWM_ASSERT(curDoc()); curDoc()->deepLock(); } void PwM::unlockWnd_slot() { PWM_ASSERT(curDoc()); curDoc()->lockAll(false); } diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 1f15ffd..6fbe110 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp @@ -1148,215 +1148,271 @@ bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, } else { d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. dti.dta[oldCategory].d[index] = *d; } flagDirty(); return true; } unsigned int PwMDoc::numEntries(const QString &category) { unsigned int cat = 0; if (!findCategory(category, &cat)) { BUG(); return 0; } return numEntries(cat); } bool PwMDoc::serializeDta(string *d) { PWM_ASSERT(d); Serializer ser; if (!ser.serialize(dti)) return false; d->assign(ser.getXml()); if (!d->size()) return false; return true; } bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) { PWM_ASSERT(d); #ifndef PWM_EMBEDDED try { Serializer ser(d->c_str()); ser.setDefaultLockStat(entriesLocked); if (!ser.deSerialize(&dti)) return false; } catch (PwMException) { return false; } #else Serializer ser(d->c_str()); ser.setDefaultLockStat(entriesLocked); if (!ser.deSerialize(&dti)) return false; #endif emitDataChanged(this); return true; } bool PwMDoc::getEntry(const QString &category, unsigned int index, PwMDataItem * d, bool unlockIfLocked) { PWM_ASSERT(d); unsigned int cat = 0; if (!findCategory(category, &cat)) { BUG(); return false; } return getEntry(cat, index, d, unlockIfLocked); } bool PwMDoc::getEntry(unsigned int category, unsigned int index, PwMDataItem *d, bool unlockIfLocked) { if (index > dti.dta[category].d.size() - 1) return false; bool locked = isLocked(category, index); if (locked) { /* this entry is locked. We don't return a password, * until it's unlocked by the user by inserting * chipcard or entering the mpw */ if (unlockIfLocked) { if (!lockAt(category, index, false)) { return false; } locked = false; } } *d = dti.dta[category].d[index]; if (locked) d->pw = LOCKED_STRING.latin1(); return true; } - PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, string *foundComment) { PWM_ASSERT(foundComment); unsigned int cat = 0; if (!findCategory(category, &cat)) return e_invalidArg; unsigned int i, entries = numEntries(cat); for (i = 0; i < entries; ++i) { if (dti.dta[cat].d[i].listViewPos == listViewPos) { *foundComment = dti.dta[cat].d[i].comment; if (dti.dta[cat].d[i].binary) return e_binEntry; return e_normalEntry; } } BUG(); return e_generic; } +PwMerror PwMDoc::getCommentByLvp_long(const QString &category, int listViewPos, + string *foundComment) +{ + PWM_ASSERT(foundComment); + unsigned int cat = 0; + + if (!findCategory(category, &cat)) + return e_invalidArg; + + unsigned int i, entries = numEntries(cat); + for (i = 0; i < entries; ++i) { + if (dti.dta[cat].d[i].listViewPos == listViewPos) { + if (dti.dta[cat].d[i].binary) + return e_binEntry; + PwMCategoryItem* catItem = getCategoryEntry(cat); + QString retval; + QString tempval = QString (dti.dta[cat].d[i].desc.c_str()); + if ( !tempval.isEmpty() ) { + retval += "<b>" +QString ( catItem->desc_text.c_str() )+ ":</b> "+ tempval+"<br>" ; + } + tempval = QString (dti.dta[cat].d[i].name.c_str()); + if ( !tempval.isEmpty() ) { + retval += "<b>" +QString ( catItem->name_text.c_str() ) + ":</b> "+ tempval+"<br>" ; + } + tempval = QString (dti.dta[cat].d[i].pw.c_str()); + if ( !tempval.isEmpty() ) { + if ( dti.dta[cat].d[i].lockStat ) + retval += "<b>" +QString ( catItem->pw_text.c_str() )+ ":</b> " + i18n("<LOCKED>") +"<br>" ; + else + retval += "<b>" +QString ( catItem->pw_text.c_str() )+ ":</b> " + tempval+"<br>" ; + } + tempval = QString (dti.dta[cat].d[i].url.c_str()); + if ( !tempval.isEmpty() ) { + retval += "<b>" +i18n("URL:")+ "</b> " + tempval+"<br>" ; + } + tempval = QString (dti.dta[cat].d[i].launcher.c_str()); + if ( !tempval.isEmpty() ) { + retval += "<b>" +i18n("Launcher:")+ "</b> " + tempval+"<br>" ; + } + tempval = QString (dti.dta[cat].d[i].comment.c_str()); + if ( !tempval.isEmpty() ) { + tempval.replace(QRegExp ( "\n" ), "<br>" ); + retval += "<b>" +i18n("Comment:")+ "</b><br>" + tempval+"<br>" ; + } + + string ret ( retval.latin1() ); + + + // *foundComment = dti.dta[cat].d[i].comment; + *foundComment = ret; + return e_normalEntry; + } + } + BUG(); + return e_generic; +} + bool PwMDoc::compressDta(string *d, char algo) { PWM_ASSERT(d); switch (algo) { case PWM_COMPRESS_GZIP: { CompressGzip comp; return comp.compress(d); } #ifndef PWM_EMBEDDED case PWM_COMPRESS_BZIP2: { CompressBzip2 comp; return comp.compress(d); } #endif case PWM_COMPRESS_NONE: { return true; } default: { BUG(); } } return false; } bool PwMDoc::decompressDta(string *d, char algo) { PWM_ASSERT(d); switch (algo) { case PWM_COMPRESS_GZIP: { CompressGzip comp; return comp.decompress(d); } #ifndef PWM_EMBEDDED case PWM_COMPRESS_BZIP2: { CompressBzip2 comp; return comp.decompress(d); } #endif case PWM_COMPRESS_NONE: { return true; } } return false; } PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo, char hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase ) { PWM_ASSERT(d); PWM_ASSERT(pw); PWM_ASSERT(f); size_t encSize; byte *encrypted = 0; switch (algo) { case PWM_CRYPT_BLOWFISH: { Blowfish::padNull(d); encSize = d->length(); encrypted = new byte[encSize]; Blowfish bf; if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { delete [] encrypted; return e_weakPw; } bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); break; } case PWM_CRYPT_AES128: /*... fall through */ case PWM_CRYPT_AES192: case PWM_CRYPT_AES256: case PWM_CRYPT_3DES: case PWM_CRYPT_TWOFISH: case PWM_CRYPT_TWOFISH128: { if (!LibGCryptIf::available()) return e_cryptNotImpl; LibGCryptIf gc; PwMerror err; unsigned char *plain = new unsigned char[d->length() + 1024]; memcpy(plain, d->c_str(), d->length()); err = gc.encrypt(&encrypted, &encSize, plain, d->length(), reinterpret_cast<const unsigned char *>(pw->latin1()), pw->length(), algo, hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase ); delete [] plain; if (err != e_success) return e_cryptNotImpl; break; } default: { diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index 9fcdda7..45dd729 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h @@ -441,192 +441,194 @@ public: * "openLocked is must be set to either of these values: * 0 == open with all entries unlocked * 1 == open with all entries locked * 2 == open deep-locked */ PwMerror openDoc(const QString *file, int openLocked); /** export document to ascii-textfile */ PwMerror exportToText(const QString *file); /** export document to gpasman / kpasman file */ PwMerror exportToGpasman(const QString *file); /** import document from ascii-textfile */ PwMerror importFromText(const QString *file, int format = -1); /** import document from gpasman / kpasman file */ PwMerror importFromGpasman(const QString *file); /** add new entry */ PwMerror addEntry(const QString &category, PwMDataItem *d, bool dontFlagDirty = false, bool updateMeta = true); /** add new category. This function doesn't flag the document dirty! */ PwMerror addCategory(const QString &category, unsigned int *categoryIndex, bool checkIfExist = true); /** rename an existing category */ bool renameCategory(const QString &category, const QString &newName); /** rename an existing category */ bool renameCategory(unsigned int category, const QString &newName, bool dontFlagDirty = false); /** delete an existing category */ bool delCategory(const QString &category); /** delete an existing category */ bool delCategory(unsigned int category, bool dontFlagDirty = false); /** returns a list of all category-names */ void getCategoryList(vector<string> *list); /** returns a list of all category-names */ void getCategoryList(QStringList *list); /** returns a list of all entry-descs in the given category */ void getEntryList(const QString &category, QStringList *list); /** returns a list of all entry-descs in the given category */ void getEntryList(const QString &category, vector<string> *list); /** returns a list of all entry-descs in the given category */ void getEntryList(unsigned int category, vector<string> *list); /** returns a list of all entry-descs in the given category */ void getEntryList(unsigned int category, QStringList *list); /** delete entry */ bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); /** delete entry */ bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); /** edit entry */ bool editEntry(const QString &oldCategory, const QString &newCategory, unsigned int index, PwMDataItem *d, bool updateMeta = true); /** edit entry */ bool editEntry(unsigned int oldCategory, const QString &newCategory, unsigned int index, PwMDataItem *d, bool updateMeta = true); /** finds the category with the "name" and return it's index */ bool findCategory(const QString &name, unsigned int *index); /** search for an entry "find" and check while searching only for * the data-fields specified by "searchIn". To set the "searchIn" * value, we may use one or more of the SEARCH_IN_* defines at * the top of this header-file. It returns the positions of all * matched entries in "foundPositions". If "breakAfterFound" is true, * the function terminates after the first occurence of the entry * and doesn't go on searching. So foundPositions->size() is never * > 1 if breakAfterFound is true. */ void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, vector<unsigned int> *foundPositions, bool breakAfterFound = false, bool caseSensitive = true, bool exactWordMatch = true, bool sortByLvp = false); /** see the above funtion. This function allows to set the category by name. */ void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, vector<unsigned int> *foundPositions, bool breakAfterFound = false, bool caseSensitive = true, bool exactWordMatch = true, bool sortByLvp = false); /** returns number of entries */ unsigned int numEntries(const QString &category); unsigned int numEntries(unsigned int category) { return dti.dta[category].d.size(); } /** returns number of categories */ unsigned int numCategories() { return dti.dta.size(); } /** returns the name of the category at "index" */ const string* getCategory(unsigned int index) { return (&(dti.dta[index].name)); } /** returns the data of item at "index". * It unlocks the entry if it's locked and unlockIfLocked is true. * If the entry is locked, but unlockIfLocked is false, it'll not return * the pw. */ bool getEntry(const QString &category, unsigned int index, PwMDataItem *d, bool unlockIfLocked = false); bool getEntry(unsigned int category, unsigned int index, PwMDataItem *d, bool unlockIfLocked = false); /** returns the comment-string by looking at the category * and the listViewPos */ PwMerror getCommentByLvp(const QString &category, int listViewPos, string *foundComment); + PwMerror getCommentByLvp_long(const QString &category, int listViewPos, + string *foundComment); /** checks if a password is already available. (currentPw) */ bool isPwAvailable() { return (currentPw != ""); } /** un/lock entry at "index". If needed, ask for password. */ bool lockAt(const QString &category, unsigned int index, bool lock = true); bool lockAt(unsigned int category, unsigned int index, bool lock = true); /** returns the lock-status at "index" */ bool isLocked(const QString &category, unsigned int index); bool isLocked(unsigned int category, unsigned int index) { return dti.dta[category].d[index].lockStat; } /** returns the deeplock status */ bool isDeepLocked() { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } /** (un)lock all entries */ bool lockAll(bool lock); /** unlocks all entries tempoarly. * 1st NOTE: Be very careful with this function! :) * 2nd NOTE: After you have called unlockAll_Tempoary(); , * please DON'T forget to call unlockAll_Tempoary(true); * _before_ the user (or someone else) is able to change * the document! * 3rd NOTE: Please DON'T change "dta" while the data is tempoary * unlocked! This will cause corruption. */ bool unlockAll_tempoary(bool revert = false); /** deep-(un)locks the document. * deep-locking writes all data to the file, deletes all data * in memory, but doesn't close the document. * deep-locking is only available, if the user previously saved * the doc to a file (with a password). * If "saveToFile" is false, it does NOT write the data to the file! */ PwMerror deepLock(bool lock = true, bool saveToFile = true); /** is unlockable without pw? */ bool unlockWoPw() { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } /** get the "currentPassword" */ const QString& getCurrentPw() { return currentPw; } /** open a window and request the user to change the mpw */ void changeCurrentPw(); /** set the "listViewPos" variable of "dta" */ void setListViewPos(const QString &category, unsigned int index, int pos); /** set the "listViewPos" variable of "dta" */ void setListViewPos(unsigned int category, unsigned int index, int pos); /** get the "listViewPos" variable of "dta" */ int getListViewPos(const QString &category, unsigned int index); /** set the maximum number of entries allowed */ void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) { maxEntries = num; } /** get the maximum number of entries allowed */ unsigned int getMaxNumEntries() { return maxEntries; } /** ensure all listViewPos of all dta items are set. (are ! -1). * If there are some undefined entries, add them to the end of * the listViewPos(itions). */ void ensureLvp(); /** execute the "launcher" of this entry */ bool execLauncher(const QString &category, unsigned int entryIndex); /** see above */ bool execLauncher(unsigned int category, unsigned int entryIndex); /** open a browser with the URL-section of the given entry */ bool goToURL(const QString &category, unsigned int entryIndex); /** see above */ bool goToURL(unsigned int category, unsigned int entryIndex); /** returns true if there is no entry present in the document. * Note: The "default" Category is present everytime, so * it's checked for it's entries. */ bool isDocEmpty() { if (numCategories() > 1) return false; if (numEntries(0)) return false; return true; } /** returns the filename of this doc */ const QString& getFilename() { return filename; } /** returns the title of the doc */ QString getTitle(); /** sets the list-view-pointer hold in the doc */ void setListViewPointer(PwMView *_listView) { listView = _listView; } /** returns the list-view-pointer */ PwMView * getListViewPointer() { return listView; } /** try to delete the doc. The user may be asked to save * the data. The user may cancel the whole operation. * false is returned, then. */ diff --git a/pwmanager/pwmanager/pwmview.cpp b/pwmanager/pwmanager/pwmview.cpp index 7f7dd6f..0092692 100644 --- a/pwmanager/pwmanager/pwmview.cpp +++ b/pwmanager/pwmanager/pwmview.cpp @@ -18,193 +18,193 @@ **************************************************************************/ #include "pwmview.h" #include "pwmexception.h" #include "globalstuff.h" #include "pwm.h" #include "rencatwnd.h" #ifndef PWM_EMBEDDED #include "configuration.h" #else #include "pwmprefs.h" #endif #include "commentbox.h" #include <kmessagebox.h> #include <klocale.h> #include <qlineedit.h> #include <qpoint.h> #include <qapplication.h> #include <qlayout.h> //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. //US ENH: for examle in listviewpwm.cpp //US ENH: Because of that I transfer them into the headerfile. /* #define COLUMN_DESC 0 #define COLUMN_NAME 1 #define COLUMN_PW 2 #define COLUMN_URL 3 #define COLUMN_LAUNCHER 4 */ PwMView::PwMView(PwM *_mainClass, QWidget *parent, PwMDoc *_doc, const char *name) : PwMViewStyle(parent, name) { PWM_ASSERT(_mainClass); PWM_ASSERT(parent); PWM_ASSERT(_doc); setView(this); doc = _doc; doc->setListViewPointer(this); mainClass = _mainClass; resize(_mainClass->size()); initStyle(conf()->confWndMainViewStyle()); initCtxMenu(); doc->setCurrentView(this); connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); connect(this, SIGNAL(editPW()), mainClass, SLOT(editPwd_slot())); } PwMView::~PwMView() { } void PwMView::initCtxMenu() { ctxMenu = new QPopupMenu(this); ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); ctxMenu->insertSeparator(); ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); ctxMenu->insertSeparator(); ctxMenu->insertItem(i18n("copy password to clipboard"), this, SLOT(copyPwToClip())); ctxMenu->insertItem(i18n("copy username to clipboard"), this, SLOT(copyNameToClip())); ctxMenu->insertItem(i18n("copy description to clipboard"), this, SLOT(copyDescToClip())); ctxMenu->insertItem(i18n("copy url to clipboard"), this, SLOT(copyUrlToClip())); ctxMenu->insertItem(i18n("copy launcher to clipboard"), this, SLOT(copyLauncherToClip())); ctxMenu->insertItem(i18n("copy comment to clipboard"), this, SLOT(copyCommentToClip())); ctxMenu->insertSeparator(); ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, SLOT(execLauncher_slot())); ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, SLOT(goToURL_slot())); } void PwMView::resizeEvent(QResizeEvent *) { resizeView(size()); } void PwMView::refreshCommentTextEdit(QListViewItem *curItem) { PWM_ASSERT(commentBox); if (!curItem) return; string comment; PwMerror ret; - ret = document()->getCommentByLvp(getCurrentCategory(), + ret = document()->getCommentByLvp_long(getCurrentCategory(), lv->childCount() - lv->itemIndex(curItem) - 1, &comment); if (ret == e_binEntry) { commentBox->setContent(i18n("This is a binary entry.\n" "It is not a normal password-entry, as it contains " "binary data, which PwManager can't display here.")); } else if (ret == e_normalEntry) { commentBox->setContent(comment.c_str()); } else { BUG(); return; } lv->ensureItemVisible(curItem); } void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) { refreshCommentTextEdit(lv->currentItem()); } bool PwMView::getCurEntryIndex(unsigned int *index) { QListViewItem *current = lv->currentItem(); if (!current) return false; return getDocEntryIndex(index, current); } bool PwMView::getDocEntryIndex(unsigned int *index, const QListViewItem *item) { vector<unsigned int> foundPositions; PwMDataItem curItem; curItem.desc = item->text(COLUMN_DESC).latin1(); curItem.name = item->text(COLUMN_NAME).latin1(); document()->getCommentByLvp(getCurrentCategory(), lv->childCount() - lv->itemIndex(item) - 1, &curItem.comment); curItem.url = item->text(COLUMN_URL).latin1(); curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | SEARCH_IN_LAUNCHER, &foundPositions, true); if (foundPositions.size()) { *index = foundPositions[0]; return true; } return false; } void PwMView::handleToggle(QListViewItem *item) { PWM_ASSERT(doc); if (!item) return; QCheckListItem *clItem = (QCheckListItem *)item; QString curCat(getCurrentCategory()); // find document position of this entry. unsigned int curEntryDocIndex; if (!getDocEntryIndex(&curEntryDocIndex, item)) return; // hack to refresh the comment, if only one item is present if (lv->childCount() == 1) refreshCommentTextEdit(lv->currentItem()); if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) return; // this is just a click somewhere on the entry if (doc->isDeepLocked()) { PwMerror ret; ret = doc->deepLock(false); if (ret != e_success) clItem->setOn(false); return; } doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); } void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) { if (!item) return; ctxMenu->move(point); /* don't use ctxMenu->exec() here, as it generates race conditions * with the card interface code. Believe it or not. :) */ ctxMenu->show(); } void PwMView::updateCategories() { //qDebug("PwMView::updateCategories() "); QString oldSel(getCurrentCategory()); diff --git a/pwmanager/pwmanager/pwmviewstyle_0.cpp b/pwmanager/pwmanager/pwmviewstyle_0.cpp index 1fc8a34..d82eb15 100644 --- a/pwmanager/pwmanager/pwmviewstyle_0.cpp +++ b/pwmanager/pwmanager/pwmviewstyle_0.cpp @@ -1,112 +1,132 @@ /*************************************************************************** * * * copyright (C) 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #include "pwmviewstyle_0.h" #include "pwmview.h" #include "listviewpwm.h" #include "commentbox.h" #include <klocale.h> #include "pwmprefs.h" PwMViewStyle_0::PwMViewStyle_0(PwMView *view) : QObject() { vbox1 = new QVBox(view); vbox1->setSpacing(3); hbox1 = new QHBox(vbox1); hbox1->setSpacing(3); categoriesTitle = new QLabel(hbox1); categoriesTitle->setText(i18n("Categories:")); categoriesCombo = new QComboBox(hbox1); renCatButton = new QPushButton(i18n("&Rename"), hbox1); delCatButton = new QPushButton(i18n("&Delete"), hbox1); #ifndef PWM_EMBEDDED splitter1 = new QSplitter(vbox1); splitter1->setOrientation(Qt::Vertical); #else splitter1 = new KDGanttMinimizeSplitter( Qt::Vertical, vbox1); splitter1->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); //US topLayout->addWidget(mMiniSplitter ); #endif lv = new ListViewPwM(splitter1); commentBox = new CommentBox(splitter1); // set sizes and styles commentBox->resize(commentBox->size().width(), 60); categoriesTitle->setAlignment(Qt::AlignVCenter | Qt::AlignRight); // connections connect(categoriesCombo, SIGNAL(activated(int)), view, SLOT(shiftToView())); connect(renCatButton, SIGNAL(clicked()), view, SLOT(renCatButton_slot())); connect(delCatButton, SIGNAL(clicked()), view, SLOT(delCatButton_slot())); + connect(lv, SIGNAL(toggleOverview()), + this, SLOT(toggleSplitter())); } PwMViewStyle_0::~PwMViewStyle_0() { delete vbox1; } +void PwMViewStyle_0::toggleSplitter() +{ + + QValueList<int> si = splitter1->sizes(); + splitter1->toggle(); + QValueList<int> si2 = splitter1->sizes(); + //qDebug("PwMViewStyle_0::toggleSplitter() %d %d %d %d", si[0],si[1],si2[0],si2[1] ); + if ( si[0] == si2[0] && si[1] == si2[1] && si2[1] == 1 ) { + int diff = si[0]/2; + if ( diff > 200 ) + diff = 200; + si[0] -= diff; + si[1] += diff; + splitter1->toggle(); + splitter1->setSizes( si ); + } + +} void PwMViewStyle_0::delCategory(const QString &cat) { PWM_ASSERT(categoriesCombo); int i, count = categoriesCombo->count(); for (i = 0; i < count; ++i) { if (categoriesCombo->text(i) == cat) { categoriesCombo->removeItem(i); return; } } BUG(); } void PwMViewStyle_0::selectCategory(const QString &cat) { PWM_ASSERT(categoriesCombo); int i, count = categoriesCombo->count(); for (i = 0; i < count; ++i) { if (categoriesCombo->text(i) == cat) { categoriesCombo->setCurrentItem(i); return; } } // fall back to 0 categoriesCombo->setCurrentItem(0); } //US ENH: I need a place to load the view dependend settings. Eg. splittersize void PwMViewStyle_0::restoreSettings(PWMPrefs* prefs) { //load and store the size of the listviewcolumns lv->restoreLayout(prefs->getConfig(), "listview"); splitter1->setSizes( prefs->mCommentSplitter ); commentBox->setFont( prefs->mViewFont ); } //US ENH: I need a place to load the view dependend settings. Eg. splittersize void PwMViewStyle_0::saveSettings(PWMPrefs* prefs) { //store the size of the listviewcolumns lv->saveLayout(prefs->getConfig(), "listview"); prefs->mCommentSplitter = splitter1->sizes(); } diff --git a/pwmanager/pwmanager/pwmviewstyle_0.h b/pwmanager/pwmanager/pwmviewstyle_0.h index bd93c06..6d3c1d1 100644 --- a/pwmanager/pwmanager/pwmviewstyle_0.h +++ b/pwmanager/pwmanager/pwmviewstyle_0.h @@ -1,105 +1,107 @@ /*************************************************************************** * * * copyright (C) 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef PWMVIEWSTYLE_0_H #define PWMVIEWSTYLE_0_H #include <qhbox.h> #include <qvbox.h> #include <qpushbutton.h> #ifndef PWM_EMBEDDED #include <qtextedit.h> #include <qsplitter.h> #else #include <qmultilineedit.h> #include <KDGanttMinimizeSplitter.h> #endif #include <qlabel.h> #include <qcombobox.h> class PwMView; class ListViewPwM; class CommentBox; class PWMPrefs; class PwMViewStyle_0 : public QObject { + Q_OBJECT public: PwMViewStyle_0(PwMView *view); ~PwMViewStyle_0(); ListViewPwM * getLv() { return lv; } CommentBox * getCommentBox() { return commentBox; } /** returns the currently selected category */ QString getCurrentCategory() { return categoriesCombo->currentText(); } /** add Category to the view */ void addCategory(const QString &cat) { categoriesCombo->insertItem(cat); } /** delete Category from view */ void delCategory(const QString &cat); /** delete all categories from view */ void delAllCategories() { categoriesCombo->clear(); } /** select the specified category */ void selectCategory(const QString &cat); /** returns the number of categories in this view. * This value dosn't say anything about the number of * categories in the document. */ int numCategories() { return categoriesCombo->count(); } /** resize the view */ void resize(const QSize &size) { vbox1->resize(size); } //US ENH: I need a place to load the view dependend settings. Eg. splittersize void restoreSettings(PWMPrefs* prefs); void saveSettings(PWMPrefs* prefs); - +public slots: + void toggleSplitter(); protected: /** main list view */ ListViewPwM *lv; /** categories combo-box */ QComboBox *categoriesCombo; /** title string for the categories combo or list box */ QLabel *categoriesTitle; /** hbox1 for widget style */ QHBox *hbox1; /** vbox1 for widget style */ QVBox *vbox1; /** splitter for commentTextEdit */ #ifndef PWM_EMBEDDED QSplitter *splitter1; #else KDGanttMinimizeSplitter * splitter1; #endif /** push button to change the category name */ QPushButton *renCatButton; /** push button to delete the category */ QPushButton *delCatButton; /** comment box */ CommentBox *commentBox; }; #endif diff --git a/pwmanager/pwmanager/pwmviewstyle_1.cpp b/pwmanager/pwmanager/pwmviewstyle_1.cpp index 4a7ffd7..7294f34 100644 --- a/pwmanager/pwmanager/pwmviewstyle_1.cpp +++ b/pwmanager/pwmanager/pwmviewstyle_1.cpp @@ -10,164 +10,183 @@ ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #include "pwmviewstyle_1.h" #include "pwmview.h" #include "listviewpwm.h" #include "commentbox.h" #include <klocale.h> #include "pwmprefs.h" #ifndef DESKTOP_VERSION #include <qpe/qpeapplication.h> #else #include <qapplication.h> #endif #define INITIAL_CATEGORIES_WIDTH 100 PwMViewStyle_1::PwMViewStyle_1(PwMView *view) : QObject() { #ifndef PWM_EMBEDDED splitter = new QSplitter(view); #else if ( QApplication::desktop()->width() > 240 ) { splitter = new KDGanttMinimizeSplitter( Qt::Horizontal, view); splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Left ); // topLayout = new QHBoxLayout( this ); // mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); // mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); } else { splitter = new KDGanttMinimizeSplitter( Qt::Vertical, view); splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); // topLayout = new QHBoxLayout( this ); // mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); // mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); } //US topLayout->addWidget(mMiniSplitter ); #endif vbox1 = new QVBox(splitter); categoriesTitle = new QLabel(vbox1); categoriesList = new QListBox(vbox1); #ifndef PWM_EMBEDDED splitter2 = new QSplitter(splitter); splitter2->setOrientation(Qt::Vertical); #else splitter2 = new KDGanttMinimizeSplitter( Qt::Vertical, splitter); splitter2->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); //US topLayout->addWidget(mMiniSplitter ); #endif lv = new ListViewPwM(splitter2); commentBox = new CommentBox(splitter2); // set sizes and styles //US commentBox->resize(commentBox->size().width(), 60); QValueList<int> sizes; #ifndef PWM_EMBEDDED sizes.push_back(INITIAL_CATEGORIES_WIDTH); sizes.push_back(view->height() - INITIAL_CATEGORIES_WIDTH); #else sizes.append(INITIAL_CATEGORIES_WIDTH); sizes.append(view->height() - INITIAL_CATEGORIES_WIDTH); #endif //US splitter->setSizes(sizes); categoriesTitle->setAlignment(Qt::AlignHCenter); #ifndef PWM_EMBEDDED categoriesTitle->setFrameShape(QFrame::MenuBarPanel); #else categoriesTitle->setFrameShape(QFrame::StyledPanel); #endif categoriesTitle->setText(i18n("Categories:")); catCtxMenu = new QPopupMenu(view); catCtxMenu->insertItem(i18n("&Rename"), view, SLOT(renCatButton_slot())); catCtxMenu->insertItem(i18n("&Delete"), view, SLOT(delCatButton_slot())); #ifndef DESKTOP_VERSION QPEApplication::setStylusOperation( categoriesList->viewport(), QPEApplication::RightOnHold ); #endif // connections connect(categoriesList, SIGNAL(highlighted(int)), view, SLOT(shiftToView())); connect(categoriesList, SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)), this, SLOT(catRightClick(QListBoxItem *, const QPoint &))); + + connect(lv, SIGNAL(toggleOverview()), + this, SLOT(toggleSplitter())); } PwMViewStyle_1::~PwMViewStyle_1() { delete catCtxMenu; delete splitter; } +void PwMViewStyle_1::toggleSplitter() +{ + QValueList<int> si = splitter2->sizes(); + splitter2->toggle(); + QValueList<int> si2 = splitter2->sizes(); + //qDebug("PwMViewStyle_1::toggleSplitter() %d %d %d %d", si[0],si[1],si2[0],si2[1] ); + if ( si[0] == si2[0] && si[1] == si2[1] && si2[1] == 1 ) { + int diff = si[0]/2; + if ( diff > 200 ) + diff = 200; + si[0] -= diff; + si[1] += diff; + splitter2->toggle(); + splitter2->setSizes( si ); + } +} void PwMViewStyle_1::catRightClick(QListBoxItem *item, const QPoint &point) { if (!item) return; catCtxMenu->move(point); catCtxMenu->show(); } void PwMViewStyle_1::delCategory(const QString &cat) { PWM_ASSERT(categoriesList); int i, count = categoriesList->count(); for (i = 0; i < count; ++i) { if (categoriesList->text(i) == cat) { categoriesList->removeItem(i); return; } } BUG(); } void PwMViewStyle_1::selectCategory(const QString &cat) { PWM_ASSERT(categoriesList); int i, count = categoriesList->count(); for (i = 0; i < count; ++i) { if (categoriesList->text(i) == cat) { categoriesList->setCurrentItem(i); return; } } // fall back to 0 categoriesList->setCurrentItem(0); } //US ENH: I need a place to load the view dependend settings. Eg. splittersize void PwMViewStyle_1::restoreSettings(PWMPrefs* prefs) { //load and store the size of the listviewcolumns lv->restoreLayout(prefs->getConfig(), "listview"); splitter->setSizes( prefs->mCategorySplitter ); splitter2->setSizes( prefs->mCommentSplitter ); commentBox->setFont( prefs->mViewFont ); } //US ENH: I need a place to load the view dependend settings. Eg. splittersize void PwMViewStyle_1::saveSettings(PWMPrefs* prefs) { //store the size of the listviewcolumns lv->saveLayout(prefs->getConfig(), "listview"); prefs->mCategorySplitter = splitter->sizes(); prefs->mCommentSplitter = splitter2->sizes(); } #ifndef PWM_EMBEDDED #include "pwmviewstyle_1.moc" #endif diff --git a/pwmanager/pwmanager/pwmviewstyle_1.h b/pwmanager/pwmanager/pwmviewstyle_1.h index a7f100c..4f7a256 100644 --- a/pwmanager/pwmanager/pwmviewstyle_1.h +++ b/pwmanager/pwmanager/pwmviewstyle_1.h @@ -1,112 +1,114 @@ /*************************************************************************** * * * copyright (C) 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef PWMVIEWSTYLE_1_H #define PWMVIEWSTYLE_1_H #include <qvbox.h> #ifndef PWM_EMBEDDED #include <qtextedit.h> #include <qsplitter.h> #else #include <qmultilineedit.h> #include <KDGanttMinimizeSplitter.h> #endif #include <qlabel.h> #include <qlistbox.h> #include <qpopupmenu.h> class PwMView; class ListViewPwM; class CommentBox; class PWMPrefs; class PwMViewStyle_1 : public QObject { Q_OBJECT public: PwMViewStyle_1(PwMView *view); ~PwMViewStyle_1(); ListViewPwM * getLv() { return lv; } CommentBox * getCommentBox() { return commentBox; } /** returns the currently selected category */ QString getCurrentCategory() { return categoriesList->currentText(); } /** add Category to the view */ void addCategory(const QString &cat) { categoriesList->insertItem(cat); } /** delete Category from view */ void delCategory(const QString &cat); /** delete all categories from view */ void delAllCategories() { categoriesList->clear(); } /** select the specified category */ void selectCategory(const QString &cat); /** returns the number of categories in this view. * This value dosn't say anything about the number of * categories in the document. */ int numCategories() { return categoriesList->count(); } /** resize the view */ void resize(const QSize &size) { splitter->resize(size); } //US ENH: I need a place to load the view dependend settings. Eg. splittersize void restoreSettings(PWMPrefs* prefs); void saveSettings(PWMPrefs* prefs); +public slots: + void toggleSplitter(); protected slots: /** user clicked right button in category list */ void catRightClick(QListBoxItem *item, const QPoint &point); protected: /** main list view */ ListViewPwM *lv; #ifndef PWM_EMBEDDED /** main splitter widget */ QSplitter *splitter; /** commentTextEdit splitter */ QSplitter *splitter2; #else /** main splitter widget */ KDGanttMinimizeSplitter *splitter; /** commentTextEdit splitter */ KDGanttMinimizeSplitter *splitter2; #endif /** categories list-box */ QListBox *categoriesList; /** title string for the categories combo or list box */ QLabel *categoriesTitle; /** hbox1 for widget style */ QVBox *vbox1; /** text-edit to display the comment */ CommentBox *commentBox; /** category list context menu */ QPopupMenu *catCtxMenu; }; #endif |