-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimagelist.cpp
More file actions
73 lines (67 loc) · 2.19 KB
/
imagelist.cpp
File metadata and controls
73 lines (67 loc) · 2.19 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
#include "imagelist.h"
#include <glob.h>
#include <QString>
#include <QFile>
#include <QIODevice>
#include <QTextStream>
#include <QDebug>
#include <fstream>
#include <QDir>
#include <QStandardPaths>
ImageList::ImageList()
{
}
string ImageList::getPath(){
//QString path = QDir::homePath();
//string projectPath = path.toStdString() + "/Desktop/XMLGenerator/input";
//QString myPath = QString(RESOURCES_PATH);
QString myPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/catoonize/generated";
string projectPath = myPath.toStdString();
return projectPath;
}
vector<string> ImageList::getNameList()
{
string path = getPath();
int start_position_to_erase = path.find_last_of("/");
path.erase(start_position_to_erase, path.length()-start_position_to_erase);
path = path + "/namesList.txt";
if (std::ifstream(path)){
QFile file(QString::fromStdString(path));
if(!file.open(QIODevice::ReadOnly)) {
qDebug()<<"Cannot read file";
}
QTextStream in(&file);
while(!in.atEnd()) {
QString line = in.readLine();
namesList.push_back(line.toStdString());
}
file.close();
}else{
glob_t glob_result;
path = getPath();
string filePath = path+"/*";
string names;
glob(filePath.c_str(),GLOB_TILDE,NULL,&glob_result);
for(unsigned int i=0; i<glob_result.gl_pathc; ++i){
names = glob_result.gl_pathv[i];
names = names.substr(path.length()+1);
namesList.push_back(names);
}
}
return namesList;
}
//creates a function that stores the names left in a file
void ImageList::createFileWithNames(vector<string> namesLeft){
string path = getPath();
int start_position_to_erase = path.find_last_of("/");
path.erase(start_position_to_erase, path.length()-start_position_to_erase);
path = path + "/namesList.txt";
QFile file(QString::fromStdString(path));
if(file.open(QIODevice::ReadWrite|QIODevice::Truncate))
{
QTextStream stream( &file );
for ( auto &name : namesLeft ) {
stream << QString::fromStdString(name) << endl;
}
}
}