Changeset 234 in flair-src for trunk/tools/FlairGCS/src/file_ui.cpp
- Timestamp:
- 04/10/18 17:05:27 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/FlairGCS/src/file_ui.cpp
r214 r234 4 4 // %flair:license} 5 5 #include "file_ui.h" 6 #include "communication.h" 7 6 8 #include <stdio.h> 7 8 9 #include <cstring> 9 10 #include <cstdlib> … … 22 23 #include <QStringList> 23 24 #include <QFormLayout> 24 25 #ifndef WIN32 26 #include <arpa/inet.h> 27 #else 28 #include <winsock2.h> 29 #include <ws2tcpip.h> 30 #endif 31 25 #include <QThread> 26 27 #include <unistd.h> 32 28 using namespace std; 33 29 34 file_ui::file_ui() { 30 file_ui::file_ui(UDTSOCKET socket,QString name): QObject() { 31 this->socket=socket; 32 this->name=name; 33 34 bool blocking = true; 35 if (UDT::setsockopt(socket, 0, UDT_SNDSYN, &blocking, sizeof(bool))!= 0) { 36 printf("UDT::setsockopt error (UDT_SNDSYN) %s\n",UDT::getlasterror().getErrorMessage()); 37 } 38 39 linger _linger; 40 _linger.l_onoff=1; 41 _linger.l_linger=180; 42 43 if (UDT::setsockopt(socket, 0, UDT_LINGER, &_linger, sizeof(struct linger)) != 0) 44 printf("UDT::setsockopt error (UDT_LINGER) %s\n",UDT::getlasterror().getErrorMessage()); 45 35 46 dialog = new QDialog(); 47 //fprintf(stderr,"creator file ui %x\n",thread()); 36 48 dialog->setWindowTitle("log files"); 37 49 QGridLayout *main_layout = new QGridLayout(dialog); … … 42 54 input_text->setText("add your log comment here"); 43 55 input_cleared = false; 44 45 56 ok_button->setEnabled(false); 46 57 … … 56 67 main_layout->addWidget(ok_button, 3, 0); 57 68 58 connect(ok_button, SIGNAL(clicked()), this, SLOT(save()), 59 Qt::QueuedConnection); 60 connect(this, SIGNAL(showDialog()), dialog, SLOT(show()), 61 Qt::QueuedConnection); 62 connect(this, SIGNAL(appendToLog(QString)), log_text, SLOT(append(QString)), 63 Qt::QueuedConnection); 64 connect(input_text, SIGNAL(cursorPositionChanged()), this, 65 SLOT(clearInputText()), Qt::QueuedConnection); 69 //connect for multithreaded stuffs 70 connect(ok_button, SIGNAL(clicked()), this, SLOT(save()),Qt::QueuedConnection); 71 connect(input_text, SIGNAL(cursorPositionChanged()), this,SLOT(clearInputText()),Qt::DirectConnection); 72 connect(this, SIGNAL(appendToLog(QString)), log_text, SLOT(append(QString))); 66 73 67 74 file_names = new QStringList(); 68 } 69 70 file_ui::~file_ui() { delete dialog; } 71 72 void file_ui::log(QString text) { appendToLog(text); } 75 76 dialog->show(); 77 } 78 79 file_ui::~file_ui() { 80 delete dialog; 81 } 82 83 void file_ui::receive(void) { 84 char *recv_buf; 85 int bytesRead; 86 bool flag_new_seq = true; 87 QString folder_name; 88 //fprintf(stderr,"file_ui thread %x\n",thread()); 89 while(1) { 90 // receive file info 91 recv_buf = (char *)malloc(1024); 92 bytesRead = UDT::recvmsg(socket, recv_buf, 1024); 93 if (bytesRead <= 0) { 94 free(recv_buf); 95 break; 96 } 97 98 int size; 99 memcpy(&size, &recv_buf[1], sizeof(int)); 100 if (recv_buf[0] == FILE_INFO_BIG_ENDIAN) 101 size = qFromBigEndian(size); 102 103 // printf("file_ui recu %i %x\n",bytesRead,recv_buf[0]); 104 if ((recv_buf[0]==FILE_INFO_LITTLE_ENDIAN || recv_buf[0]==FILE_INFO_BIG_ENDIAN) && size>0) { 105 if (flag_new_seq == true) { 106 // create directory for storage 107 QDateTime dateTime = QDateTime::currentDateTime(); 108 folder_name = dateTime.toString("yyyyMMdd_hhmm") + "_" + name; 109 if (QDir().exists(folder_name) == true) { 110 folder_name = dateTime.toString("yyyyMMdd_hhmm_ss") + "_" + name; 111 } 112 QDir().mkdir(folder_name); 113 114 flag_new_seq = false; 115 appendToLog("Creating directory " + folder_name); 116 } 117 118 QString file_name=QString::fromAscii((const char *)&recv_buf[5], bytesRead - 5); 119 QString file_path=folder_name+"/"+file_name; 120 appendToLog(QString("receiving %1 (%2 bytes)").arg(file_name).arg(size)); 121 QFile fichier(file_path); 122 123 if (!fichier.open(QIODevice::WriteOnly)) { 124 appendToLog(" could not write to file!"); 125 } else { 126 // receive file 127 recv_buf = (char *)realloc((void *)recv_buf, size); 128 bytesRead = UDT::recvmsg(socket, recv_buf, size); 129 if (bytesRead != size) { 130 appendToLog(QString(" error receiving file! (%1/%2)").arg(bytesRead).arg(size)); 131 free(recv_buf); 132 break; 133 } else { 134 appendToLog(" ok"); 135 } 136 137 QDataStream stream(&fichier); 138 stream.writeRawData(recv_buf, size); 139 fichier.close(); 140 141 addFile(file_path); 142 } 143 144 free(recv_buf); 145 } else if (recv_buf[0] == END_SENDING_FILES) { 146 //end ack 147 UDT::sendmsg(socket,&recv_buf[0],1); 148 endOfFiles(); 149 UDT::close(socket); 150 printf("disconnected from log files\n"); 151 break; 152 } 153 } 154 } 73 155 74 156 void file_ui::addFile(QString file_path) { … … 86 168 dbt2csv(file_path.replace(QString(".txt"), QString(".dbt"))); 87 169 } 88 89 if (file_names->size() == 1) {90 input_cleared = false;91 showDialog();92 }93 170 } 94 171 … … 101 178 if (info.size() > max_file_size) { 102 179 max_file_size = info.size(); 103 csv_combo->setCurrentIndex(i + 104 1); // first item of combobox is already taken 180 csv_combo->setCurrentIndex(i+1); // first item of combobox is already taken 105 181 } 106 182 } … … 112 188 QStringList data_type; 113 189 114 QString filename = 115 file_path.section('/', -1); // remove path for displaying on logs 190 QString filename =file_path.section('/', -1); // remove path for displaying on logs 116 191 appendToLog(QString("converting %1 to csv").arg(filename)); 117 192 … … 145 220 break; 146 221 QString txt_line = txt_in.readLine(); 147 data_type.append(txt_line.section( 148 "(", 149 -1)); // on part de la fin pour trouver la premiere parenthese ouvrante 222 data_type.append(txt_line.section("(",-1)); // on part de la fin pour trouver la premiere parenthese ouvrante 150 223 // printf("type %s\n",txt_line.section("(",-1).toLocal8Bit().constData()); 151 224 } … … 241 314 } 242 315 243 log_text->clear();244 input_cleared = true; // avoid clearing it with setText245 input_text->setText("add your log comment here");246 file_names->clear();247 csv_combo->clear();248 csv_combo->addItem(QString("(no base time)"));249 250 dialog->setVisible(false);251 ok_button->setEnabled(false);252 316 emit finished(); 253 317 }
Note:
See TracChangeset
for help on using the changeset viewer.