summaryrefslogtreecommitdiffstats
path: root/ksquirrel/sq_thumbnailsunused.cpp
blob: 3861bc4ca20c53298517014dfc64517dd1dba30d (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***************************************************************************
                          sq_thumbnailsunused.cpp  -  description
                             -------------------
    begin                : Fri Jul 20 2007
    copyright            : (C) 2007 by Baryshev Dmitry
    email                : ksquirrel.iv@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <kconfig.h>

#include "sq_thumbnailsunused.h"

SQ_ThumbnailsUnused * SQ_ThumbnailsUnused::m_instance = 0;

SQ_ThumbnailsUnused::SQ_ThumbnailsUnused(TQObject *tqparent) : TQObject(tqparent), TQMap<KURL, time_t>()
{
    m_instance = this;

    cache = new KConfig("ksquirrel-unused-cache");

    load();
}

SQ_ThumbnailsUnused::~SQ_ThumbnailsUnused()
{
    save();
    delete cache;
}

bool SQ_ThumbnailsUnused::needUpdate(const KURL &u, time_t t)
{
    iterator it = find(u);

    if(it == end())
        return true;

    return it.data() != t;
}

void SQ_ThumbnailsUnused::load()
{
    cache->setGroup("General");
    int count = cache->readNumEntry("count");

    if(count <= 0)
        return;

    TQString is, s;
    time_t t;

    for(int i = 0;i < count;i++)
    {
        cache->setGroup("URL");

        is = TQString::number(i);
        s = cache->readEntry(is);

        cache->setGroup("Time");
        t = cache->readNumEntry(is);

        insert(KURL::fromPathOrURL(s), t);
    }
}

void SQ_ThumbnailsUnused::save()
{
    cache->deleteGroup("URL");
    cache->deleteGroup("Time");

    cache->setGroup("General");
    cache->writeEntry("count", size());

    iterator itEnd = end();
    TQString is;
    int i = 0;

    for(iterator it = begin();it != itEnd;++it)
    {
        is = TQString::number(i);
        cache->setGroup("URL");
        cache->writeEntry(is, it.key().prettyURL());

        cache->setGroup("Time");
        cache->writeEntry(is, it.data());

        i++;
    }
}