Commit 6e3e109f28c6c5412593ba417f806f3a7afc28f2

Authored by Josh Klontz
1 parent 1dffec6c

removed crawl gallery

Showing 1 changed file with 0 additions and 113 deletions
openbr/plugins/gallery/crawl.cpp deleted
1   -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2   - * Copyright 2012 The MITRE Corporation *
3   - * *
4   - * Licensed under the Apache License, Version 2.0 (the "License"); *
5   - * you may not use this file except in compliance with the License. *
6   - * You may obtain a copy of the License at *
7   - * *
8   - * http://www.apache.org/licenses/LICENSE-2.0 *
9   - * *
10   - * Unless required by applicable law or agreed to in writing, software *
11   - * distributed under the License is distributed on an "AS IS" BASIS, *
12   - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13   - * See the License for the specific language governing permissions and *
14   - * limitations under the License. *
15   - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
16   -
17   -#include <QStandardPaths>
18   -
19   -#include <openbr/plugins/openbr_internal.h>
20   -
21   -namespace br
22   -{
23   -
24   -/*!
25   - * \ingroup galleries
26   - * \brief Crawl a root location for image files.
27   - * \author Josh Klontz \cite jklontz
28   - */
29   -class crawlGallery : public Gallery
30   -{
31   - Q_OBJECT
32   - Q_PROPERTY(bool autoRoot READ get_autoRoot WRITE set_autoRoot RESET reset_autoRoot STORED false)
33   - Q_PROPERTY(int depth READ get_depth WRITE set_depth RESET reset_depth STORED false)
34   - Q_PROPERTY(bool depthFirst READ get_depthFirst WRITE set_depthFirst RESET reset_depthFirst STORED false)
35   - Q_PROPERTY(int images READ get_images WRITE set_images RESET reset_images STORED false)
36   - Q_PROPERTY(bool json READ get_json WRITE set_json RESET reset_json STORED false)
37   - Q_PROPERTY(int timeLimit READ get_timeLimit WRITE set_timeLimit RESET reset_timeLimit STORED false)
38   - BR_PROPERTY(bool, autoRoot, false)
39   - BR_PROPERTY(int, depth, INT_MAX)
40   - BR_PROPERTY(bool, depthFirst, false)
41   - BR_PROPERTY(int, images, INT_MAX)
42   - BR_PROPERTY(bool, json, false)
43   - BR_PROPERTY(int, timeLimit, INT_MAX)
44   -
45   - QTime elapsed;
46   - TemplateList templates;
47   -
48   - void crawl(QFileInfo url, int currentDepth = 0)
49   - {
50   - if ((templates.size() >= images) || (currentDepth >= depth) || (elapsed.elapsed()/1000 >= timeLimit))
51   - return;
52   -
53   - if (url.filePath().startsWith("file://"))
54   - url = QFileInfo(url.filePath().mid(7));
55   -
56   - if (url.isDir()) {
57   - const QDir dir(url.absoluteFilePath());
58   - const QFileInfoList files = dir.entryInfoList(QDir::Files);
59   - const QFileInfoList subdirs = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
60   - foreach (const QFileInfo &first, depthFirst ? subdirs : files)
61   - crawl(first, currentDepth + 1);
62   - foreach (const QFileInfo &second, depthFirst ? files : subdirs)
63   - crawl(second, currentDepth + 1);
64   - } else if (url.isFile()) {
65   - const QString suffix = url.suffix();
66   - if ((suffix == "bmp") || (suffix == "jpg") || (suffix == "jpeg") || (suffix == "png") || (suffix == "tiff")) {
67   - File f;
68   - if (json) f.set("URL", "file://"+url.canonicalFilePath());
69   - else f.name = "file://"+url.canonicalFilePath();
70   - templates.append(f);
71   - }
72   - }
73   - }
74   -
75   - void init()
76   - {
77   - elapsed.start();
78   - const QString root = file.name.mid(0, file.name.size()-6); // Remove .crawl suffix";
79   - if (!root.isEmpty()) {
80   - crawl(root);
81   - } else {
82   - if (autoRoot) {
83   - foreach (const QString &path, QStandardPaths::standardLocations(QStandardPaths::HomeLocation))
84   - crawl(path);
85   - } else {
86   - QFile file;
87   - file.open(stdin, QFile::ReadOnly);
88   - while (!file.atEnd()) {
89   - const QString url = QString::fromLocal8Bit(file.readLine()).simplified();
90   - if (!url.isEmpty())
91   - crawl(url);
92   - }
93   - }
94   - }
95   - }
96   -
97   - TemplateList readBlock(bool *done)
98   - {
99   - *done = true;
100   - return templates;
101   - }
102   -
103   - void write(const Template &)
104   - {
105   - qFatal("Not supported");
106   - }
107   -};
108   -
109   -BR_REGISTER(Gallery, crawlGallery)
110   -
111   -} // namespace br
112   -
113   -#include "gallery/crawl.moc"