File: filecache.h

package info (click to toggle)
kio-mtp 0.75%2Bgit20140304-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 420 kB
  • ctags: 67
  • sloc: cpp: 1,436; makefile: 5; sh: 1
file content (79 lines) | stat: -rw-r--r-- 2,433 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
    Cache for recent files accessed.
    Copyright (C) 2012  Philipp Schmidt <philschmidt@gmx.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#ifndef FILECACHE_H
#define FILECACHE_H

#define KIO_MTP                     7000

#include <stdint.h>

#include <QDateTime>
#include <QHash>
#include <QPair>

/**
 * @class FileCache Implements a time based cache for file ids, mapping their path to their ID. Does _not_ store the device they are on.
 */
class FileCache : public QObject
{
    Q_OBJECT

private:
    QHash<QString, QPair<QDateTime, uint32_t> > cache;

// private slots:
//     void insertItem( const QString& path, QPair<QDateTime, uint32_t> item );
//     void removeItem( const QString& path );
// 
// signals:
//     void s_insertItem( const QString& path, QPair<QDateTime, uint32_t> item );
//     void s_removeItem( const QString& path );

public:
    explicit FileCache ( QObject* parent = 0 );

    /**
     * Returns the ID of the item at the given path, else 0.
     * Automatically discards old items.
     *
     * @param path The Path to query the cache for
     * @return The ID of the Item if it exists, else 0
     */
    uint32_t queryPath( const QString& path, int timeToLive = 60 );

    /**
     * Adds a Path to the Cache with the given id and ttl.
     *
     * @param path The path of the file/folder
     * @param id The file ID on the storage
     * @param timeToLive The time in seconds the entry should be valid
     */
    void addPath( const QString& path, uint32_t id, int timeToLive = 60 );

    /**
     * Remove the given path from the cache, i.e. if it got deleted
     *
     * @param path The path that should be removed
     */
    void removePath (const QString& path );
};

#endif // FILECACHE_H