Switch to unified view

a/src/query/history.h b/src/query/history.h
...
...
14
 *   Free Software Foundation, Inc.,
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
16
 */
17
#ifndef _HISTORY_H_INCLUDED_
17
#ifndef _HISTORY_H_INCLUDED_
18
#define _HISTORY_H_INCLUDED_
18
#define _HISTORY_H_INCLUDED_
19
/* @(#$Id: history.h,v 1.3 2006-01-30 11:15:28 dockes Exp $  (C) 2004 J.F.Dockes */
19
/* @(#$Id: history.h,v 1.4 2006-09-11 09:08:44 dockes Exp $  (C) 2004 J.F.Dockes */
20
21
/**
22
 * Dynamic configuration storage
23
 *
24
 * The term "history" is a misnomer as this code is now used to save
25
 * all dynamic parameters except those that are stored in the global
26
 * recollrc QT preferences file. Examples:
27
 *  - History of documents selected for preview
28
 *  - Active and inactive external databases (these should depend on the 
29
 *    configuration directory and cant be stored in recollrc).
30
 *  - ...
31
 *
32
 * The storage is performed in a ConSimple file, with subkeys and
33
 * encodings which depend on the data stored.
34
 *
35
 */
20
36
21
#include <string>
37
#include <string>
22
#include <list>
38
#include <list>
23
#include <utility>
39
#include <utility>
24
40
25
#include "conftree.h"
41
#include "conftree.h"
26
42
27
/** Holder for data returned when querying history */
43
#ifndef NO_NAMESPACES
44
using namespace std;
45
#endif
46
28
class RclDHistoryEntry {
47
class HistoryEntry {
48
 public:
49
    virtual bool decode(const string &value) = 0;
50
    virtual bool encode(string& value) = 0;
51
    virtual bool equal(const HistoryEntry &other) = 0;
52
};
53
54
55
/** Document history entry */
56
class RclDHistoryEntry : public HistoryEntry {
29
 public:
57
 public:
30
    RclDHistoryEntry() : unixtime(0) {}
58
    RclDHistoryEntry() : unixtime(0) {}
59
    RclDHistoryEntry(long t, const string& f, const string& i) 
60
  : unixtime(t), fn(f), ipath(i) {}
61
    virtual ~RclDHistoryEntry() {}
62
    virtual bool decode(const string &value);
63
    virtual bool encode(string& value);
64
    virtual bool equal(const HistoryEntry& other);
31
    long unixtime;
65
    long unixtime;
32
    string fn;
66
    string fn;
33
    string ipath;
67
    string ipath;
34
};
68
};
35
69
70
71
/** String storage generic object */
72
class RclSListEntry : public HistoryEntry {
73
 public:
74
    RclSListEntry() {}
75
    RclSListEntry(const string& v) : value(v) {}
76
    virtual ~RclSListEntry() {}
77
    virtual bool decode(const string &enc);
78
    virtual bool encode(string& enc);
79
    virtual bool equal(const HistoryEntry& other);
80
81
    string value;
82
};
83
36
/** 
84
/** 
37
 * The documents history class. This is based on a ConfTree for no
85
 * The history class. This uses a ConfSimple for storage, and should be 
38
 * imperative reason
86
 * renamed something like dynconf, as it is used to stored quite a few 
87
 * things beyond doc history: all dynamic configuration parameters that are 
88
 * not suitable for QT settings because they are specific to a RECOLL_CONFDIR
39
 */
89
 */
40
class RclDHistory {
90
class RclHistory {
41
 public:
91
 public:
42
    RclDHistory(const std::string &fn, unsigned int maxsize=1000);
92
    RclHistory(const string &fn, unsigned int maxsize=100)
93
  : m_mlen(maxsize), m_data(fn.c_str()) {}
43
    bool ok() {return m_data.getStatus() == ConfSimple::STATUS_RW;}
94
    bool ok() {return m_data.getStatus() == ConfSimple::STATUS_RW;}
44
95
96
    // Specific methods for history entries
45
    bool enterDocument(const std::string fn, const std::string ipath);
97
    bool enterDoc(const string fn, const string ipath);
46
    std::list<RclDHistoryEntry> getDocHistory();
98
    list<RclDHistoryEntry> getDocHistory();
99
100
    // Generic methods used for string lists, designated by the subkey value
101
    bool enterString(const string sk, const string value);
102
    list<string> getStringList(const string sk);
103
    bool eraseAll(const string& sk);
47
104
48
 private:
105
 private:
49
    bool decodeValue(const string &value, RclDHistoryEntry *e);
50
    unsigned int m_mlen;
106
    unsigned int m_mlen;
51
    ConfSimple m_data;
107
    ConfSimple m_data;
108
    bool insertNew(const string& sk, HistoryEntry &n, HistoryEntry &s);
109
    template<typename Tp> list<Tp> getHistory(const string& sk);
52
};
110
};
53
111
112
template<typename Tp> list<Tp> RclHistory::getHistory(const string &sk)
113
{
114
    list<Tp> mlist;
115
    Tp entry;
116
    list<string> names = m_data.getNames(sk);
117
    for (list<string>::const_iterator it = names.begin(); 
118
   it != names.end(); it++) {
119
  string value;
120
  if (m_data.get(*it, value, sk)) {
121
      if (!entry.decode(value))
122
      continue;
123
      mlist.push_front(entry);
124
  }
125
    }
126
    return mlist;
127
}
54
128
55
#endif /* _HISTORY_H_INCLUDED_ */
129
#endif /* _HISTORY_H_INCLUDED_ */