-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenamefile.cpp
More file actions
76 lines (60 loc) · 1.59 KB
/
renamefile.cpp
File metadata and controls
76 lines (60 loc) · 1.59 KB
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
#include "renamefile.h"
const QString &RenameFile::getCurrName() const
{
return baseName;
}
void RenameFile::setCurrName(const QString &newCurrName)
{
baseName = newCurrName;
}
const QString &RenameFile::getNewName() const
{
return newBaseName;
}
void RenameFile::setNewName(const QString &newNewName)
{
newBaseName = newNewName;
}
const QModelIndex &RenameFile::getModelIndex() const
{
return modIndex;
}
void RenameFile::setModelIndex(const QModelIndex &newModelIndex)
{
modIndex = newModelIndex;
}
QFile *RenameFile::getFile() const
{
return file;
}
void RenameFile::setFile(QFile *newFile)
{
file = newFile;
}
bool RenameFile::renameFile()
{
if(newBaseName != "" && newBaseName != baseName){
return file->rename(filePath+"/" + newBaseName + fileEnding);
}
return false;
}
RenameFile::RenameFile(const QModelIndex &modelIndex)
{
modIndex = modelIndex;
filePath = modelIndex.siblingAtColumn(5).data().toString();
file = new QFile(filePath+"/"+modelIndex.data().toString());
/* separate file-ending (after last dot) from file-name */
int dotPos = modelIndex.data().toString().lastIndexOf('.');
if(dotPos > -1){
baseName = modelIndex.data().toString().left(dotPos);
fileEnding = modelIndex.data().toString().right(modelIndex.data().toString().length() - dotPos);
}
else{
baseName = modelIndex.data().toString();
fileEnding = "";
}
newBaseName = baseName;
}
bool RenameFile::renameFileLessThan(const RenameFile* a,const RenameFile* b){
return a->modIndex.row() < b->modIndex.row();
}