forked from psemiletov/tea-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
98 lines (65 loc) · 2.15 KB
/
utils.h
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
98
/*
this code is Public Domain
Peter Semiletov
*/
#ifndef UTILS_H
#define UTILS_H
#include <QObject>
#include <QHash>
#include <QFileInfo>
#include <QStringList>
class CFilesList: public QObject
{
public:
QStringList list;
void get (const QString &path);
void iterate (QFileInfo &fi);
};
class CFTypeChecker: public QObject
{
public:
QStringList lexts;
QStringList lnames;
CFTypeChecker (const QString &fnames, const QString &exts);
bool check (const QString &fname);
};
QString hash_keyval_to_string (const QHash<QString, QString> &h);
QString hash_get_val (QHash<QString, QString> &h, const QString &key, const QString &def_val);
QString file_get_ext (const QString &file_name);
bool file_exists (const QString &fileName);
void qstring_list_print (const QStringList &l);
bool qstring_save (const QString &fileName, const QString &data, const char *enc = "UTF-8");
QString qstring_load (const QString &fileName, const char *enc = "UTF-8");
QStringList read_dir_entries (const QString &path);
QHash<QString, QString> hash_load (const QString &fname);
QHash<QString, QString> hash_load_keyval (const QString &fname);
QHash<QString, QString> stringlist_to_hash (const QStringList &l);
QString hash_keyval_to_string (QHash<QString, QString> *h);
bool is_image (const QString &filename);
QString string_between (const QString &source, const QString &sep1, const QString &sep2);
QByteArray file_load (const QString &fileName);
QString change_file_ext (const QString &s, const QString &ext);
QString get_insert_image (const QString &file_name, const QString &full_path, const QString &markup_mode);
bool char_is_shit (const QChar &c);
inline int get_value (int total, int perc)
{
return static_cast <int> (total * perc / 100);
}
inline double get_percent (double total, double value)
{
return (value / total) * 100;
}
inline float get_percent (float total, float value)
{
return (value / total) * 100;
}
inline bool is_dir (const QString &path)
{
return QFileInfo(path).isDir();
}
inline QString get_file_path (const QString &fileName)
{
return QFileInfo (fileName).absolutePath();
}
QStringList bytearray_to_stringlist (QList<QByteArray> a);
#endif