sptk2 logo
SPTK Home Page
DirectoryDS.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <memory>
30#include <sptk5/CSmallPixmapIDs.h>
31#include <sptk5/MemoryDS.h>
32#include <sptk5/RegularExpression.h>
33#include <sptk5/Strings.h>
34#include <sptk5/sptk-config.h>
35#include <sys/stat.h>
36
37namespace sptk {
38
47static constexpr int DDS_SHOW_ALL = 0;
48static constexpr int DDS_HIDE_FILES = 1;
49static constexpr int DDS_HIDE_DOT_FILES = 2;
50static constexpr int DDS_HIDE_DIRECTORIES = 4;
51static constexpr int DDS_NO_SORT = 8;
52
62class SP_EXPORT DirectoryDS
63 : public MemoryDS
64{
65public:
73 DirectoryDS(const String& _directory = "", const String& _pattern = "", int _showPolicy = 0)
74 : MemoryDS()
75 , m_showPolicy(_showPolicy)
76 {
77 if (!_directory.empty())
78 {
79 directory(_directory);
80 }
81 if (!_pattern.empty())
82 {
83 pattern(_pattern);
84 }
85 }
86
91 int showPolicy() const
92 {
93 return m_showPolicy;
94 }
95
99 void showPolicy(int type)
100 {
101 m_showPolicy = type;
102 }
103
107 void directory(const String& d);
108
113 {
114 return m_directory;
115 }
116
121 void pattern(const String& wildcards)
122 {
123 Strings patterns(wildcards, ";", Strings::SplitMode::DELIMITER);
124 m_patterns.clear();
125 for (const auto& pattern: patterns)
126 {
127 auto matchPattern = wildcardToRegexp(pattern);
128 m_patterns.push_back(matchPattern);
129 }
130 }
131
135 bool open() override;
136
142 static std::shared_ptr<RegularExpression> wildcardToRegexp(const String& wildcard);
143
144protected:
150 static String getFileType(const fs::directory_entry& file, CSmallPixmapType& image,
151 DateTime& modificationTime);
152
153private:
157 String m_directory;
158
162 std::vector<std::shared_ptr<RegularExpression>> m_patterns;
163
167 int m_showPolicy;
168
174 static String absolutePath(const String& path);
175
181 FieldList makeFileListEntry(const fs::directory_entry& file, size_t& index) const;
182
183 static CSmallPixmapType imageTypeFromExtention(const String& ext);
184};
188} // namespace sptk
Definition: DateTime.h:86
Directory datasource.
Definition: DirectoryDS.h:64
static String getFileType(const fs::directory_entry &file, CSmallPixmapType &image, DateTime &modificationTime)
int showPolicy() const
Definition: DirectoryDS.h:91
void showPolicy(int type)
Definition: DirectoryDS.h:99
bool open() override
void directory(const String &d)
String directory() const
Definition: DirectoryDS.h:112
void pattern(const String &wildcards)
Definition: DirectoryDS.h:121
DirectoryDS(const String &_directory="", const String &_pattern="", int _showPolicy=0)
Definition: DirectoryDS.h:73
static std::shared_ptr< RegularExpression > wildcardToRegexp(const String &wildcard)
Definition: FieldList.h:50
Base (memory) datasource.
Definition: MemoryDS.h:52
Definition: String.h:49
Definition: Strings.h:52
CSmallPixmapType
Definition: CSmallPixmapIDs.h:42

Fri Oct 14 2022 09:58:31: SPTK 5.4.1