-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 70 |
1 files changed, 62 insertions, 8 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index ea4d687..91277f6 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -203,12 +203,13 @@ struct PwMDataItem | |||
203 | lockStat = true; | 203 | lockStat = true; |
204 | listViewPos = -1; | 204 | listViewPos = -1; |
205 | binary = false; | 205 | binary = false; |
206 | if (clearMeta) | 206 | if (clearMeta) |
207 | meta.clear(); | 207 | meta.clear(); |
208 | } | 208 | } |
209 | |||
209 | }; | 210 | }; |
210 | 211 | ||
211 | struct PwMCategoryItem | 212 | struct PwMCategoryItem |
212 | { | 213 | { |
213 | /** all PwMDataItems (all passwords) within this category */ | 214 | /** all PwMDataItems (all passwords) within this category */ |
214 | vector<PwMDataItem>d; | 215 | vector<PwMDataItem>d; |
@@ -219,12 +220,37 @@ struct PwMCategoryItem | |||
219 | { | 220 | { |
220 | d.clear(); | 221 | d.clear(); |
221 | name = ""; | 222 | name = ""; |
222 | } | 223 | } |
223 | }; | 224 | }; |
224 | 225 | ||
226 | struct PwMSyncItem | ||
227 | { | ||
228 | string syncName; | ||
229 | QDateTime lastSyncDate; | ||
230 | |||
231 | void clear() | ||
232 | { | ||
233 | lastSyncDate = QDateTime(); | ||
234 | syncName = ""; | ||
235 | } | ||
236 | }; | ||
237 | |||
238 | struct PwMItem | ||
239 | { | ||
240 | vector<PwMCategoryItem> dta; | ||
241 | vector<PwMSyncItem> syncDta; | ||
242 | |||
243 | void clear() | ||
244 | { | ||
245 | dta.clear(); | ||
246 | syncDta.clear(); | ||
247 | } | ||
248 | }; | ||
249 | |||
250 | |||
225 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ | 251 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ |
226 | class dta_lvp_greater | 252 | class dta_lvp_greater |
227 | { | 253 | { |
228 | public: | 254 | public: |
229 | bool operator() (const pair<unsigned int, unsigned int> &d1, | 255 | bool operator() (const pair<unsigned int, unsigned int> &d1, |
230 | const pair<unsigned int, unsigned int> &d2) | 256 | const pair<unsigned int, unsigned int> &d2) |
@@ -437,19 +463,20 @@ public: | |||
437 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 463 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
438 | bool caseSensitive = true, bool exactWordMatch = true, | 464 | bool caseSensitive = true, bool exactWordMatch = true, |
439 | bool sortByLvp = false); | 465 | bool sortByLvp = false); |
440 | /** returns number of entries */ | 466 | /** returns number of entries */ |
441 | unsigned int numEntries(const QString &category); | 467 | unsigned int numEntries(const QString &category); |
442 | unsigned int numEntries(unsigned int category) | 468 | unsigned int numEntries(unsigned int category) |
443 | { return dta[category].d.size(); } | 469 | { return dti.dta[category].d.size(); } |
444 | /** returns number of categories */ | 470 | /** returns number of categories */ |
445 | unsigned int numCategories() | 471 | unsigned int numCategories() |
446 | { return dta.size(); } | 472 | { return dti.dta.size(); } |
447 | /** returns the name of the category at "index" */ | 473 | /** returns the name of the category at "index" */ |
448 | const string* getCategory(unsigned int index) | 474 | const string* getCategory(unsigned int index) |
449 | { return (&(dta[index].name)); } | 475 | { return (&(dti.dta[index].name)); } |
476 | |||
450 | /** returns the data of item at "index". | 477 | /** returns the data of item at "index". |
451 | * It unlocks the entry if it's locked and unlockIfLocked is true. | 478 | * It unlocks the entry if it's locked and unlockIfLocked is true. |
452 | * If the entry is locked, but unlockIfLocked is false, it'll not return | 479 | * If the entry is locked, but unlockIfLocked is false, it'll not return |
453 | * the pw. | 480 | * the pw. |
454 | */ | 481 | */ |
455 | bool getEntry(const QString &category, unsigned int index, | 482 | bool getEntry(const QString &category, unsigned int index, |
@@ -469,13 +496,13 @@ public: | |||
469 | bool lock = true); | 496 | bool lock = true); |
470 | bool lockAt(unsigned int category, unsigned int index, | 497 | bool lockAt(unsigned int category, unsigned int index, |
471 | bool lock = true); | 498 | bool lock = true); |
472 | /** returns the lock-status at "index" */ | 499 | /** returns the lock-status at "index" */ |
473 | bool isLocked(const QString &category, unsigned int index); | 500 | bool isLocked(const QString &category, unsigned int index); |
474 | bool isLocked(unsigned int category, unsigned int index) | 501 | bool isLocked(unsigned int category, unsigned int index) |
475 | { return dta[category].d[index].lockStat; } | 502 | { return dti.dta[category].d[index].lockStat; } |
476 | /** returns the deeplock status */ | 503 | /** returns the deeplock status */ |
477 | bool isDeepLocked() | 504 | bool isDeepLocked() |
478 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } | 505 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } |
479 | /** (un)lock all entries */ | 506 | /** (un)lock all entries */ |
480 | bool lockAll(bool lock); | 507 | bool lockAll(bool lock); |
481 | /** unlocks all entries tempoarly. | 508 | /** unlocks all entries tempoarly. |
@@ -571,19 +598,19 @@ public: | |||
571 | { ++dataChangedLock; } | 598 | { ++dataChangedLock; } |
572 | /** put the dataChanged lock */ | 599 | /** put the dataChanged lock */ |
573 | void putDataChangedLock() | 600 | void putDataChangedLock() |
574 | { --dataChangedLock; } | 601 | { --dataChangedLock; } |
575 | /** returns the revision count of the item at cat/index */ | 602 | /** returns the revision count of the item at cat/index */ |
576 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) | 603 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) |
577 | { return dta[category].d[index].rev; } | 604 | { return dti.dta[category].d[index].rev; } |
578 | /** returns a const pointer to the entries meta */ | 605 | /** returns a const pointer to the entries meta */ |
579 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) | 606 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) |
580 | { return &(dta[category].d[index].meta); } | 607 | { return &(dti.dta[category].d[index].meta); } |
581 | /** is the entry at "category" "index" a binary entry? */ | 608 | /** is the entry at "category" "index" a binary entry? */ |
582 | bool isBinEntry(unsigned int category, unsigned int index) | 609 | bool isBinEntry(unsigned int category, unsigned int index) |
583 | { return dta[category].d[index].binary; } | 610 | { return dti.dta[category].d[index].binary; } |
584 | 611 | ||
585 | public slots: | 612 | public slots: |
586 | /** wrapper for PwMTray */ | 613 | /** wrapper for PwMTray */ |
587 | void _deepUnlock(); | 614 | void _deepUnlock(); |
588 | 615 | ||
589 | signals: | 616 | signals: |
@@ -610,14 +637,16 @@ public: | |||
610 | emit dataChanged(document); | 637 | emit dataChanged(document); |
611 | } | 638 | } |
612 | 639 | ||
613 | protected: | 640 | protected: |
614 | /** current file for this doc */ | 641 | /** current file for this doc */ |
615 | QString filename; | 642 | QString filename; |
643 | //US ENH: we need a place where we keep the syncentries. So I invented | ||
644 | // struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem | ||
616 | /** holds all data */ | 645 | /** holds all data */ |
617 | vector<PwMCategoryItem> dta; | 646 | PwMItem dti; |
618 | /** maximum number of entries */ | 647 | /** maximum number of entries */ |
619 | unsigned int maxEntries; | 648 | unsigned int maxEntries; |
620 | /** currently used password to encrypt data */ | 649 | /** currently used password to encrypt data */ |
621 | QString currentPw; | 650 | QString currentPw; |
622 | /** current global document status flags */ | 651 | /** current global document status flags */ |
623 | unsigned int curDocStat; | 652 | unsigned int curDocStat; |
@@ -704,21 +733,46 @@ protected: | |||
704 | 733 | ||
705 | public: | 734 | public: |
706 | #ifdef PWM_EMBEDDED | 735 | #ifdef PWM_EMBEDDED |
707 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. | 736 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. |
708 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); | 737 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); |
709 | 738 | ||
739 | //takePwMDataItem returns the following values | ||
740 | // 0 equal | ||
741 | // 1 take local | ||
742 | // 2 take remote | ||
743 | // 3 cancel | ||
744 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); | ||
710 | 745 | ||
711 | //the following methods are the overwritten callbackmethods from the syncinterface | 746 | //the following methods are the overwritten callbackmethods from the syncinterface |
712 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 747 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
713 | 748 | ||
714 | //called by the syncmanager to indicate that the work has to be marked as dirty. | 749 | //called by the syncmanager to indicate that the work has to be marked as dirty. |
715 | virtual void sync_setModified(); | 750 | virtual void sync_setModified(); |
716 | //called by the syncmanager to ask if the dirty flag is set. | 751 | //called by the syncmanager to ask if the dirty flag is set. |
717 | virtual bool sync_isModified(); | 752 | virtual bool sync_isModified(); |
718 | //called by the syncmanager to indicate that the work has to be saved. | 753 | //called by the syncmanager to indicate that the work has to be saved. |
719 | virtual void sync_save(); | 754 | virtual void sync_save(); |
755 | |||
720 | #endif | 756 | #endif |
757 | private: | ||
758 | //US ENH: helpermethods to access the sync data for a certain syncname. | ||
759 | // It returns the syncdatas index | ||
760 | bool findSyncData(const QString &syncname, unsigned int *index); | ||
761 | |||
762 | /** add new syncdataentry */ | ||
763 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); | ||
764 | |||
765 | /** returns a pointer to the syncdata */ | ||
766 | PwMSyncItem* getSyncDataEntry(unsigned int index) | ||
767 | { return &(dti.syncDta[index]); } | ||
768 | |||
769 | /** delete entry */ | ||
770 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); | ||
771 | |||
772 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); | ||
773 | |||
774 | QStringList getIDEntryList(); | ||
721 | 775 | ||
722 | }; | 776 | }; |
723 | 777 | ||
724 | #endif | 778 | #endif |