-
Notifications
You must be signed in to change notification settings - Fork 0
/
basiccontroller.cpp
139 lines (108 loc) · 4.84 KB
/
basiccontroller.cpp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "basiccontroller.h"
#include "srcback/inc/IpfsClient.hh"
#include "srcback/inc/CmdClient.hh"
#include "srcback/inc/MultichainClient.hh"
#include "srcback/inc/MultichainInitialization.hh"
#include <iostream>
#include <vector>
string chainName = "";
string streamName = "";
string keyName = "";
namespace {
namespace Test {
const int MAX_NUMBER_OF_FILES = 3;
const QString FILE_NAME = QStringLiteral("File%0");
const QString FILE_PROCESS_MESSAGE =
QStringLiteral("Process of \"%0\" has been finished");
} // namespace Test
} // namespace
BasicController::BasicController(QObject *parent) : QObject(parent) {
QObject::connect(&dropFileAreaController,
&DropFileAreaController::startDroppedFileProcessing, this,
&BasicController::processDroppedFile);
std::ifstream infile("../GlobalVariables.txt");
if(infile.fail()){
cout << endl << endl << endl << "---> Brak Pliku: GlobalVariables!!!" << endl << endl << endl ;
}
else{
StringFinder finder;
chainName = finder.GetFirstValue(infile, "test_chain_name:");
streamName = finder.GetFirstValue(infile, "test_stream_name:");
keyName = finder.GetFirstValue(infile, "test_key_name:");
infile.close();
}
}
std::vector<std::pair<QString, QObject *>>
BasicController::getObjectsToRegister() {
return {{"controller", this},
{"dropFileAreaController", &dropFileAreaController},
{"customMessageDialogController", &customMessageDialogController}};
}
void BasicController::processDroppedFile(const std::string &filePath) {
std::string temp = "file://";
string fileName = filePath.substr(temp.length(), filePath.length() - temp.length());
CmdClient cmdClient;
cmdClient.ClearConsole();
MultichainInitialization multichainInitialization;
if(multichainInitialization.IsConnected()){
IpfsClient ipfsClient;
string fileAddress = ipfsClient.AddFileToIpfs(fileName);
MultichainClient multichainClient;
multichainClient.publishData(chainName, streamName, keyName, fileAddress, fileName);
multichainClient.ClearConsole();
cout << "Dodano plik: " << fileName << endl;
}
/*
MultichainClient multichainClient;
multichainClient.initChain(chainName, streamName);
multichainClient.createStream(chainName, streamName);
multichainClient.subscribeToStream(chainName, streamName);
multichainClient.publishData(chainName, streamName, keyName, fileAddress, fileName);
multichainClient.listStreamItems(chainName, streamName);
ObtainedAddressFromStream = multichainClient.returnFileAddress(chainName, streamName, fileName);
std::cout << endl << "Odzyskany adres pliku: " << ObtainedAddressFromStream << endl;
ipfsClient.SafeFileFromIpfsToFile(ObtainedAddressFromStream, "/home/node_a/Pulpit/ImportantData.txt");
fileList = multichainClient.listChainFiles( chainName, streamName); // fileList is a vector of file names existing in
// chain names can repeat themselves
cout << "Lista plikow:" << endl;
for (const string &i : fileList) {
cout << i << endl;
}
*/
}
void BasicController::onListViewButtonReleased() {
listViewAreaFiles.clear();
MultichainClient multichainClient;
MultichainInitialization multichainInitialization;
if(multichainInitialization.IsConnected()){
vector<string> res = multichainClient.listChainFiles(multichainInitialization.chainName, multichainInitialization.streamName);
auto last = std::unique(res.begin(), res.end()); //
res.erase(last, res.end()); //czyszczenie powtarzajacych sie rekordow - przeniesc do funkcji zwracajacej!
for (size_t i = 0; i < res.size(); i++)
{
listViewAreaFiles.push_back(QString::fromStdString(res[i]));
//cout << res[i] << endl;
}
}
emit updateListViewArea(); //tutaj uzupelniam comboboxa
multichainClient.ClearConsole();
//customMessageDialogController.showMessageDialog("Update list view area", "List view area has been just updated");
}
void BasicController::onListViewFileSelected(const QString &fileName) {
customMessageDialogController.showMessageDialog(
"File selected", "File from list view area has been just selected");
StringFinder stringFinder;
string tmp = Test::FILE_PROCESS_MESSAGE.arg(fileName).toStdString();
string tmp2 = "\"";
string filePath = stringFinder.GetFirstValue(tmp , tmp2 , tmp2);
// ^ wyciagniecie z komunikatu stringa ze scierzka
MultichainClient multichainClient;
IpfsClient ipfsClient;
string ObtainedAddressFromStream = multichainClient.returnFileAddress(chainName, streamName, filePath);
ipfsClient.SafeFileFromIpfsToFile(ObtainedAddressFromStream, filePath);
multichainClient.ClearConsole();
cout << "Pobrano plik: " << filePath << endl;
}
const QStringList &BasicController::getListViewAreaFiles() const {
return listViewAreaFiles;
}