aboutsummaryrefslogtreecommitdiff
path: root/src/utils.h
blob: 9d2520f8d0aa9be96ae7ecff306575f0fd843f0a (plain) (blame)
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
#ifndef UTILS_H
#define UTILS_H

#include <QObject>
#include <QDebug>
#include <QFileInfo>
#include <QStandardPaths>
#include <QDir>
#include <QTextDocument>
#include <QUuid>

class utils : public QObject
{
    Q_OBJECT

public:
    utils(QObject* parent=0);
    virtual ~utils();
public slots:
    static QString refreshCacheSize(const QString cache_dir);
    static bool delete_cache(const QString cache_dir);
    static QString toCamelCase(const QString &s);
    static QString generateRandomId(int length);
    static QString genRand(int length);
    static QString convertSectoDay(qint64 secs);
    static QString returnPath(QString pathname);

    static QString EncodeXML ( const QString& encodeMe ){

        QString temp;
        int length = encodeMe.size();
        for (int index = 0; index < length; index++)
        {
            QChar character(encodeMe.at(index));

            switch (character.unicode())
            {
            case '&':
                temp += "&amp;"; break;

            case '\'':
                temp += "&apos;"; break;

            case '"':
                temp += "&quot;"; break;

            case '<':
                temp += "&lt;"; break;

            case '>':
                temp += "&gt;"; break;

            default:
                temp += character;
                break;
            }
        }

        return temp;
    }

    static QString DecodeXML ( const QString& decodeMe ) {

        QString temp(decodeMe);

        temp.replace("&amp;", "&");
        temp.replace("&apos;", "'");
        temp.replace("&quot;", "\"");
        temp.replace("&lt;", "<");
        temp.replace("&gt;", ">");

        return temp;
    }

    static QString htmlToPlainText(QString str);

private slots:
    //use refreshCacheSize
    static quint64 dir_size(const QString &directory);



};

#endif // UTILS_H