Changeset View
Changeset View
Standalone View
Standalone View
runners/bookmarks/browser.h
Show All 14 Lines | |||||
15 | * You should have received a copy of the GNU Library General Public | 15 | * You should have received a copy of the GNU Library General Public | ||
16 | * License along with this program; if not, write to the | 16 | * License along with this program; if not, write to the | ||
17 | * Free Software Foundation, Inc., | 17 | * Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #ifndef BROWSER_H | 21 | #ifndef BROWSER_H | ||
22 | #define BROWSER_H | 22 | #define BROWSER_H | ||
23 | | ||||
23 | #include <QObject> | 24 | #include <QObject> | ||
25 | #include <QFile> | ||||
26 | #include <QFileInfo> | ||||
27 | #include <QDateTime> | ||||
24 | #include <QString> | 28 | #include <QString> | ||
25 | #include "bookmarkmatch.h" | 29 | #include "bookmarkmatch.h" | ||
26 | 30 | | |||
27 | class Browser | 31 | class Browser | ||
28 | { | 32 | { | ||
29 | public: | 33 | public: | ||
30 | virtual ~Browser() {} | 34 | virtual ~Browser() {} | ||
31 | virtual QList<BookmarkMatch> match(const QString& term, bool addEveryThing) = 0; | 35 | virtual QList<BookmarkMatch> match(const QString& term, bool addEveryThing) = 0; | ||
32 | virtual void prepare() {} | 36 | virtual void prepare() {} | ||
33 | 37 | | |||
38 | enum CacheResult{ | ||||
39 | Error, | ||||
40 | Copied, | ||||
41 | Unchanged | ||||
42 | }; | ||||
43 | | ||||
34 | public Q_SLOTS: | 44 | public Q_SLOTS: | ||
35 | virtual void teardown() {} | 45 | virtual void teardown() {} | ||
46 | | ||||
47 | protected: | ||||
48 | /* | ||||
49 | * Updates the cached file if the source has been modified | ||||
50 | */ | ||||
51 | CacheResult updateCacheFile(const QString &source, const QString &cache) { | ||||
52 | if (source.isEmpty() || cache.isEmpty()) { | ||||
53 | return Error; | ||||
54 | } | ||||
55 | QFileInfo cacheInfo(cache); | ||||
56 | if (!QFileInfo::exists(cache) || !cacheInfo.isFile()) { | ||||
57 | return QFile(source).copy(cache) ? Copied : Error; | ||||
58 | } | ||||
59 | | ||||
60 | QFileInfo sourceInfo(source); | ||||
61 | if (sourceInfo.lastModified() > cacheInfo.lastModified()) { | ||||
62 | QFile::remove(cache); | ||||
63 | return QFile(source).copy(cache) ? Copied : Error; | ||||
64 | } | ||||
65 | return Unchanged; | ||||
66 | } | ||||
36 | }; | 67 | }; | ||
37 | 68 | | |||
38 | 69 | | |||
39 | #endif // BROWSER_H | 70 | #endif // BROWSER_H |