~verzegnassi-stefano/edit/brand-name-not-translatable

« back to all changes in this revision

Viewing changes to backend/modules/EdIt/mytype.cpp

  • Committer: pawstr
  • Date: 2015-01-23 19:41:38 UTC
  • Revision ID: pawstr@gmail.com-20150123194138-bd8zysyrzcqa0uq6
All files added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "mytype.h"
 
2
 
 
3
MyType::MyType(QObject *parent) :
 
4
    QObject(parent),
 
5
    m_message("")
 
6
{
 
7
 
 
8
}
 
9
 
 
10
MyType::~MyType() {
 
11
 
 
12
}
 
13
 
 
14
bool MyType::write(QString source, const QString &data)
 
15
{
 
16
    if (source.isEmpty())
 
17
        return false;
 
18
 
 
19
    if(source.startsWith("file://"))
 
20
        source.remove("file://");
 
21
 
 
22
    //maybe useful in the future but i doesn't work anyway xD
 
23
//    QDir dir = QFileInfo(source).absoluteDir();
 
24
//    if(!dir.exists())
 
25
//        dir.mkdir(".");
 
26
 
 
27
    QFile file(source);
 
28
    if (!file.open(QFile::ReadWrite))
 
29
        return false;
 
30
 
 
31
    QTextStream out(&file);
 
32
    out << data;
 
33
    file.close();
 
34
    return true;
 
35
}
 
36
 
 
37
QString MyType::read(QString source)
 
38
{
 
39
    if (source.isEmpty())
 
40
        return "";
 
41
 
 
42
    if(source.startsWith("file://"))
 
43
        source.remove("file://");
 
44
 
 
45
    QFile file(source);
 
46
    if (!file.open(QFile::ReadOnly | QFile::Truncate))
 
47
        return "";
 
48
 
 
49
    QString data = file.readAll();
 
50
    return data;
 
51
}
 
52
 
 
53
bool MyType::rename(QString source, const QString &fileName)
 
54
{
 
55
    if (source.isEmpty())
 
56
        return false;
 
57
 
 
58
    if(source.startsWith("file://"))
 
59
        source.remove("file://");
 
60
 
 
61
    QFile file(source);
 
62
    return file.rename(fileName);
 
63
}
 
64
 
 
65
bool MyType::remove(QString source)
 
66
{
 
67
    if (source.isEmpty())
 
68
        return false;
 
69
 
 
70
    if(source.startsWith("file://"))
 
71
        source.remove("file://");
 
72
 
 
73
    QFile file(source);
 
74
    return file.remove();
 
75
}
 
76
 
 
77
QString MyType::getFileName(QString source)
 
78
{
 
79
    if (source.isEmpty())
 
80
        return "";
 
81
 
 
82
    if(source.startsWith("file://"))
 
83
        source.remove("file://");
 
84
 
 
85
    QFileInfo fi(source);
 
86
    QString name = fi.completeBaseName();
 
87
    QRegularExpression rx("\((\\d+)\)");
 
88
    QRegularExpressionMatch match = rx.match(name);
 
89
    if(match.hasMatch())
 
90
        name.remove(match.capturedStart(0)-1,match.capturedLength(0)+2);
 
91
    return name;
 
92
 
 
93
}
 
94
 
 
95
QString MyType::getSuffix(QString source)
 
96
{
 
97
    if (source.isEmpty())
 
98
        return "";
 
99
 
 
100
    if(source.startsWith("file://"))
 
101
        source.remove("file://");
 
102
 
 
103
    QFileInfo fi(source);
 
104
    return fi.suffix();
 
105
}
 
106
 
 
107
QString MyType::getFullName(QString source)
 
108
{
 
109
    if (source.isEmpty())
 
110
        return "";
 
111
 
 
112
    if(source.startsWith("file://"))
 
113
        source.remove("file://");
 
114
 
 
115
    QFileInfo fi(source);
 
116
    return fi.fileName();
 
117
}
 
118
 
 
119
bool MyType::exists(QString source)
 
120
{
 
121
    if (source.isEmpty())
 
122
        return false;
 
123
 
 
124
    if(source.startsWith("file://"))
 
125
        source.remove("file://");
 
126
 
 
127
    QFileInfo fi(source);
 
128
    return fi.exists();
 
129
}
 
130
 
 
131
bool MyType::isWritable(QString source)
 
132
{
 
133
    if (source.isEmpty())
 
134
        return false;
 
135
 
 
136
    if(source.startsWith("file://"))
 
137
        source.remove("file://");
 
138
 
 
139
    QFileInfo fi(source);
 
140
    return fi.isWritable();
 
141
}
 
142
 
 
143
QStringList MyType::getLocalFileList(QString path)
 
144
{
 
145
    QStringList list;
 
146
 
 
147
    if (path.isEmpty())
 
148
        return list;
 
149
 
 
150
    if(path.startsWith("file://"))
 
151
        path.remove("file://");
 
152
 
 
153
    QDir dir(path);
 
154
    list = dir.entryList(QDir::Files);
 
155
 
 
156
    return list;
 
157
}
 
158