CViewer::CViewer(const std::string &p_fileName): CWindow(), m_fileName(p_fileName), m_firstLine(0), m_image(NULL), m_font(CResourceManager::instance().getFont()) { // Init clip rect m_clip.x = 0; m_clip.y = 0; m_clip.w = SCREEN_WIDTH - 2 * VIEWER_MARGIN; // Create background image m_image = SDL_utils::createImage(SCREEN_WIDTH, SCREEN_HEIGHT, SDL_MapRGB(Globals::g_screen->format, COLOR_BG_1)); { SDL_Rect l_rect; l_rect.x = 0; l_rect.y = 0; l_rect.w = SCREEN_WIDTH; l_rect.h = Y_LIST; SDL_FillRect(m_image, &l_rect, SDL_MapRGB(m_image->format, COLOR_BORDER)); } // Print title SDL_Surface *l_surfaceTmp = SDL_utils::renderText(m_font, m_fileName, Globals::g_colorTextTitle); if (l_surfaceTmp->w > m_image->w - 2 * VIEWER_MARGIN) { SDL_Rect l_rect; l_rect.x = l_surfaceTmp->w - (m_image->w - 2 * VIEWER_MARGIN); l_rect.y = 0; l_rect.w = m_image->w - 2 * VIEWER_MARGIN; l_rect.h = l_surfaceTmp->h; SDL_utils::applySurface(VIEWER_MARGIN, Y_HEADER, l_surfaceTmp, m_image, &l_rect); } else { SDL_utils::applySurface(VIEWER_MARGIN, Y_HEADER, l_surfaceTmp, m_image); } m_clip.h = l_surfaceTmp->h; SDL_FreeSurface(l_surfaceTmp); // Read file #ifdef ZIPIT_Z2 extern int readtextfile(std::string filename, std::vector<std::string> &txtman); if (!readtextfile(m_fileName, m_lines)) #else std::ifstream l_file(m_fileName.c_str()); if (l_file.is_open()) { std::string l_line(""); while (!l_file.eof()) { std::getline(l_file, l_line); m_lines.push_back(l_line); } l_file.close(); } else #endif std::cerr << "Error: unable to open file " << m_fileName << std::endl; INHIBIT(std::cout << "CViewer: " << m_lines.size() << " lines read" << std::endl;) }
const bool CFileLister::list(const std::string &p_path) { // Open dir DIR *l_dir = opendir(p_path.c_str()); if (l_dir == NULL) { std::cerr << "CFileLister::list: Error opening dir " << p_path << std::endl; return false; } // Clean up m_listFiles.clear(); m_listDirs.clear(); // Read dir std::string l_file(""); std::string l_fileFull(""); struct stat l_stat; struct dirent *l_dirent = readdir(l_dir); while (l_dirent != NULL) { l_file = l_dirent->d_name; // Filter the '.' and '..' dirs if (l_file != "." && l_file != "..") { // Stat the file l_fileFull = p_path + "/" + l_file; if (stat(l_fileFull.c_str(), &l_stat) == -1) { std::cerr << "CFileLister::list: Error stat " << l_fileFull << std::endl; } else { // Check type if (S_ISDIR(l_stat.st_mode)) // It's a directory m_listDirs.push_back(T_FILE(l_file, l_stat.st_size)); else // It's a file m_listFiles.push_back(T_FILE(l_file, l_stat.st_size)); } } // Next l_dirent = readdir(l_dir); } // Close dir closedir(l_dir); // Sort lists sort(m_listFiles.begin(), m_listFiles.end(), compareNoCase); sort(m_listDirs.begin(), m_listDirs.end(), compareNoCase); // Add "..", always at the first place m_listDirs.insert(m_listDirs.begin(), T_FILE("..", 0)); return true; }
int main (int argc, char *argv[]) { bool l_trace_scanning=false; bool l_trace_parsing=false; dfm_driver driver(l_trace_scanning, l_trace_parsing); // Parses DFM files if (argc<2) { std::cerr<<"usage:"<<std::endl<<std::string(argv[0])<<" <files>"<<std::endl; return(-1); } for (int i=1;i<argc;i++) { driver.scan_begin(); std::string l_file(argv[i]); driver.setFileName(l_file); driver.openLog(); std::stringstream l_os; if (driver.parse ()==0) { l_os << "file succesfully parsed:"<<l_file<<":res="<< driver._result << std::endl; driver.log(l_os); if (driver.validateUi()==0) { l_os << "Associated Qt5 form succesfully parsed"<< std::endl; driver.log(l_os); } else { l_os << "Could not parse the associated Qt5 form " << "but you might open the file in the designer :-)" << std::endl; driver.log(l_os); } } else { l_os << "Could not parse file:"<<l_file<<":res="<< driver._result << std::endl; driver.log(l_os); } driver.scan_end(); } return(0); }
void Widget::m_Set_Over() { if (m_score_num > m_record_num) { m_record_num = m_score_num; QFile l_file("Config.txt"); if (l_file.open(QIODevice::ReadWrite)) { l_file.resize(0); QTextStream l_stream(&l_file); l_stream<<m_record_num; l_file.close(); m_Set_Label_Content(); } } if (m_timer.isActive()) m_timer.stop(); }
void Widget::m_Layout_Right_Frame() { m_record_num = 0; m_score_num = 0; m_spd_num = 0; m_time_num = 0; //Read Config QFile l_file("Config.txt"); if (l_file.open(QIODevice::ReadWrite)) { QTextStream l_stream(&l_file); m_record_num = l_stream.readLine().toInt(); l_file.close(); } m_record = new QLabel(); m_score = new QLabel(); m_sped = new QLabel(); m_time = new QLabel(); //Set Label Content m_Set_Label_Content(); //Layout All the Labels QVBoxLayout *l_layout = new QVBoxLayout(); l_layout->addWidget(m_record); l_layout->addWidget(m_score); l_layout->addWidget(m_sped); l_layout->addWidget(m_time); l_layout->addWidget(new QLabel("W: Up")); l_layout->addWidget(new QLabel("S: Down")); l_layout->addWidget(new QLabel("A: Left")); l_layout->addWidget(new QLabel("D: Right")); l_layout->addWidget(new QLabel("P: Pause/Start")); l_layout->addWidget(new QLabel("R: Replay")); l_layout->setMargin(5); l_layout->setSpacing(20); m_right_frame.setLayout(l_layout); QPalette l_palette = m_right_frame.palette(); m_right_frame.setAutoFillBackground(true); l_palette.setColor(QPalette::Window, QColor(48, 100, 100)); l_palette.setColor(QPalette::WindowText, QColor(0, 0, 0, 200)); m_right_frame.setPalette(l_palette); m_right_frame.setFixedSize(100, 500); }
void Widget::m_Set_Start() { if (m_score_num > m_record_num) { m_record_num = m_score_num; QFile l_file("Config.txt"); if (l_file.open(QIODevice::ReadWrite)) { QTextStream l_stream(&l_file); m_record_num = l_stream.readLine().toInt(); l_file.close(); } } m_score_num = 0; m_spd_num = 0; m_time_num = 0; if (!m_timer.isActive()) m_timer.start(1000); }
/// \brief main function of simpleTextFile. int main(int nargs, char *argv[]) { std::cout << "simbleTextFile test start" << std::endl; // First parameter should be file name or -h for help. if (nargs != 2) { usage(argv[0],std::cerr); return 1; } QString l_argument(argv[1]); if (l_argument == "-h") { usage(argv[0]); return 0; } QFile l_file(l_argument); // Check if file exists. if (! l_file.exists()) { std::cerr << "File " << l_file.fileName().toStdString() << " does not exists.\n"; return 1; } Share::Resource::Config::getInstance()->setLocalStorage(true); Share::Resource::Config::getInstance()->setEncryptedByDefault(false); Share::Resource::Config::getInstance()->setPublicByDefault(false); Share::Auth l_auth; Share::Resource::Id l_id = shareFile(l_file,l_auth); //md5Resource(); // Compare md5sum and size of l_file and resource return 0; }
void my_parser::parse(void) { std::ifstream l_file(m_name.c_str()); if(!l_file) { std::cout << "ERROR : Could not open file \"" << m_name << "\"" << std::endl ; exit(-1); } const uint32_t l_size = 10; char l_buf[l_size]; bool l_end = false; while(! (l_end = l_file.eof())) { l_file.read(l_buf,l_size); if (! XML_Parse(m_parser, l_buf,l_file.gcount(),l_end)) { std::cout << "ERROR : Parse error at line " << XML_GetCurrentLineNumber(m_parser) << " :" << XML_ErrorString(XML_GetErrorCode(m_parser)) << std::endl; exit(-1); } } l_file.close(); std::cout << "PARSE SUCCESSFULL" << std::endl ; }