int main(int argc, char *argv[]) { // Needed to allow a signal to be sent with QFileInfo // objects as parameters since it needs the information // to be added to a queue... or something qRegisterMetaType<QFileInfo>("QFileInfo"); QApplication a(argc, argv); // Used to delegate between front end and backend ViewController *vc = new ViewController(); // Initial setup stuff for ViewController so that it will // be ready for looking like the gui we want that can just // have rows added to it vc->setUpBigDog(); vc->setModel(new Model()); // Connect signals and slots so that when an image is found // the Model object can send a signal to be processed by the // same object but on the main thread (at least I think that // is how it works...) Model *currMod = vc->getModel(); QObject::connect(currMod, SIGNAL(imageFound(QFileInfo , ViewController *, QString )), currMod, SLOT(addImage(QFileInfo , ViewController *, QString ))); // Setup for recursively finding images on a separate thread QDir currDir(inputDir); std::thread myt(rFindImages, currMod, currDir, vc); myt.detach(); return a.exec(); }
void UUpdateWidget::createFolders(const QString &path) { QString tmp = path; QString folderName; int index; QDir currDir(QDir::currentPath()); QString savePath = currDir.currentPath(); QString createdFolder; // creating all subfolders while(tmp.contains('/') == true) { index = tmp.indexOf('/'); folderName = tmp.mid(0, index); tmp.remove(0, index + 1); createdFolder = currDir.currentPath() + '/' + folderName; currDir.mkdir(createdFolder); currDir.setCurrent(createdFolder); } // set root directory currDir.setCurrent(savePath); }
QString MemSpecParser::findGeneratedHeaders() const { QLinkedList<QString> fileNames, dirs, nextDirs; for (int i = 0; generated_includes[i] != 0; ++i) fileNames += QString(generated_includes[i]); QDir kdir(_kernelSrcDir); if (!kdir.cd("include")) memSpecParserError(QString("Include directory \"%1\" cannot be found.") .arg(kdir.absolutePath())); QString ret; dirs.append(kdir.absolutePath()); // Implemented a BFS of files QLinkedList<QString>::iterator f_it; while (!fileNames.isEmpty() && !dirs.isEmpty()) { // Change to the next directory QDir currDir(dirs.first()); dirs.pop_front(); // Search for all missing files in current directory f_it = fileNames.begin(); while (f_it != fileNames.end()) { QFileInfo info(currDir, *f_it); if (info.exists() && info.isFile()) { ret += "#include <" + kdir.relativeFilePath(info.absoluteFilePath()) + ">\n"; f_it = fileNames.erase(f_it); } else ++f_it; } // Append all directories to the list foreach (QString d, currDir.entryList(QDir::Dirs|QDir::NoDotAndDotDot)) nextDirs.push_back(currDir.absoluteFilePath(d)); // Switch to the next directory level if (dirs.isEmpty()) { dirs = nextDirs; nextDirs.clear(); } } // Did we find all headers? If not, then try to compile it anyway... if (!fileNames.isEmpty()) { QString s; for (f_it = fileNames.begin(); f_it != fileNames.end(); ++f_it) s += "\n" + *f_it; debugerr("Failed to find the following headers in \"" << kdir.absolutePath() << "\":" << s); } return ret; }
bool SettingsManager::pathCheck(const QString &path){ if(path.isEmpty()){ return false; } QDir dir(path); if(dir.exists()){ return false; } if(QDir::isAbsolutePath(path)){ return dir.mkpath(path); }else{ QDir currDir("."); return currDir.mkpath(path); } return false; }
void UUpdateWidget::slot_showUpdatesTable(UUpdatesModel *model) { if (model->rowCount() == 0) { qDebug() << "there is no updates"; QMessageBox::information(this, tr("Nanomite updater"), tr("There is no updates")); m_stackedWidget->setCurrentIndex(0); m_toolBarActions.at(eINSTALL_UPDATES_ACTION)->setEnabled(false); m_toolBarActions.at(eCHECK_UPDATES_ACTION)->setEnabled(true); return; } // create folder for updates QDir currDir(QDir::currentPath()); QString createdFolder = currDir.currentPath() + "/updates"; currDir.mkdir(createdFolder); currDir.setCurrent(createdFolder); // end of creating folder for updates m_updatesTableView->setModel(model); m_progressBarList.clear(); QProgressBar *progressBar; for (int i = 0; i < model->rowCount(); i++) { progressBar = new QProgressBar(m_updatesTableView); progressBar->setTextVisible(false); progressBar->setMinimum(0); progressBar->setMaximum(0); m_progressBarList.append(progressBar); m_updatesTableView->setIndexWidget(model->index(i, UUpdatesModel::eSTATUS), m_progressBarList.last()); } m_updatesTableView->resizeColumnsToContents(); m_stackedWidget->setCurrentIndex(2); m_toolBarActions.at(eINSTALL_UPDATES_ACTION)->setEnabled(true); m_toolBarActions.at(eCHECK_UPDATES_ACTION)->setEnabled(false); }
// Recursively add watches to the intotify file descriptor. // If the map is not null, insert the watch/directory pair into the map. static int recur_add_watch_then_map(int inotify_fd, const std::string& basePath, const std::string& relPath, WdDirectoryMap* wdDirectoryMap) { int rv = 0; std::deque<std::string> dirRelLocalPathQ; dirRelLocalPathQ.push_back(std::string("/")); while(!dirRelLocalPathQ.empty()) { VPLFS_dir_t dp; VPLFS_dirent_t dirp; std::string currDir(dirRelLocalPathQ.front()); dirRelLocalPathQ.pop_front(); std::string fullPath = basePath+relPath+currDir; if(VPLFS_Opendir(fullPath.c_str(), &dp) != VPL_OK) { VPL_REPORT_WARN("Error(%d,%s) opening (%s,%s,%s)", errno, strerror(errno), basePath.c_str(), relPath.c_str(), currDir.c_str()); continue; } int wd = inotify_add_watch(inotify_fd, fullPath.c_str(), WATCHED_INOTIFY_EVENTS); if(wd < 0) { VPL_REPORT_WARN("Adding watch failed: fd:%d, (%d, %s), dir:%s", inotify_fd, errno, strerror(errno), fullPath.c_str()); rv = -1; // Continue on, there might be other valid directories }else{ if(wdDirectoryMap) { std::pair<WdDirectoryMap::iterator, bool> retC = wdDirectoryMap->insert( std::pair<int, std::string>(wd, relPath+currDir)); if(retC.second == false) { VPL_REPORT_WARN("Watch insertion not successful: fd:%d, wd:%d, dir:%s", inotify_fd, wd, fullPath.c_str()); rv = -1; } } } while (VPLFS_Readdir(&dp, &dirp) == VPL_OK) { std::string dirent(dirp.filename); if(isBeginWithPeriod(dirent)) { // Optimization, not syncing hidden directory continue; } VPLFS_stat_t statBuf; if (VPLFS_Stat((fullPath+dirent).c_str(), &statBuf) != VPL_OK) { VPL_REPORT_WARN("Error(%d,%s) using stat on (%s,%s,%s)", errno, strerror(errno), relPath.c_str(), currDir.c_str(), dirent.c_str()); rv = -1; continue; } if((statBuf.type == VPLFS_TYPE_DIR) && (dirent=="." || dirent=="..")) { continue; } if(statBuf.type == VPLFS_TYPE_FILE) { // No need to have inotify on files, only directories continue; } dirRelLocalPathQ.push_back(currDir+dirent+std::string("/")); } VPLFS_Closedir(&dp); } return rv; }
bool World::Initialize(unsigned int windowWidth, unsigned int windowHeight, String windowName, bool antiAliasing, bool fullScreen, bool resizable) { if (_initialized) { return false; } _running = true; // Windows DLL locations #if defined(WIN32) && defined(ANGEL_RELEASE) String bitsPath = "bits"; char currentDir[MAX_PATH]; _getcwd(currentDir, MAX_PATH); String currDir(currentDir); StringList libs; #if !ANGEL_DISABLE_DEVIL libs.push_back("DevIL.dll"); libs.push_back("ILU.dll"); libs.push_back("ILUT.dll"); #endif #if ANGEL_DISABLE_FMOD libs.push_back("OpenAL32.dll"); #else libs.push_back("fmodex.dll"); #endif for (int i=0; i < libs.size(); i++) { String libstring = currDir + "\\" + bitsPath + "\\" + libs[i]; HMODULE work = LoadLibrary(libstring.c_str()); if (work == 0) { DWORD err = GetLastError(); _com_error error(err); LPCSTR errorText = error.ErrorMessage(); sysLog.Printf("ERROR: Couldn't load DLL (%s); %s", libs[i].c_str(), errorText); } } // does bits directory exist? DWORD dwAttrib = GetFileAttributes(bitsPath.c_str()); if (dwAttrib != INVALID_FILE_ATTRIBUTES && dwAttrib & FILE_ATTRIBUTE_DIRECTORY) { _chdir(bitsPath.c_str()); } #endif // General windowing initialization #if !ANGEL_MOBILE glfwInit(); #endif #if defined(__APPLE__) // Set up paths correctly in the .app bundle #if !ANGEL_MOBILE CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) { sysLog.Log("ERROR: Problem setting up working directory! Probably nothing will work!"); } CFRelease(resourcesURL); chdir(path); chdir(".."); #if defined(ANGEL_DEBUG) // set paths to the local resources rather than the copied ones String fileName = __FILE__; String dirPath = fileName.substr(0, fileName.size() - String("Angel/Infrastructure/World.cpp").size()); CFURLRef exeURL = CFBundleCopyExecutableURL(mainBundle); char exePath[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(exeURL, TRUE, (UInt8 *)exePath, PATH_MAX)) { sysLog.Log("ERROR: Problem setting up working directory! Probably nothing will work!"); } CFRelease(exeURL); chdir(dirPath.c_str()); StringList pathElements = SplitString(exePath, "/"); String exeName = pathElements[pathElements.size()-1]; chdir(exeName.c_str()); #endif #else CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) { std::cout << "Problem setting up working directory! Probably nothing will work!" << std::endl; } CFRelease(resourcesURL); chdir(path); chdir("Angel"); // the iPhone doesn't like having a "Resources" directory in the root of the .app bundle #endif #endif //Start scripting LuaScriptingModule::Prep(); //Reset values based on preferences antiAliasing = thePrefs.OverrideInt("WindowSettings", "antiAliasing", antiAliasing); fullScreen = thePrefs.OverrideInt("WindowSettings", "fullScreen", fullScreen); resizable = thePrefs.OverrideInt("WindowSettings", "resizable", resizable); windowHeight = thePrefs.OverrideInt("WindowSettings", "height", windowHeight); windowWidth = thePrefs.OverrideInt("WindowSettings", "width", windowWidth); windowName = thePrefs.OverrideString("WindowSettings", "name", windowName); //Windowing system setup #if !ANGEL_MOBILE if (antiAliasing) { glfwWindowHint(GLFW_SAMPLES, 4); //4x looks pretty good _antiAliased = true; } else { _antiAliased = false; } GLFWmonitor* openOn = NULL; // windowed if (fullScreen) { openOn = glfwGetPrimaryMonitor(); } if (resizable) { glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); } else { glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); } _mainWindow = glfwCreateWindow(windowWidth, windowHeight, windowName.c_str(), openOn, NULL); glfwMakeContextCurrent(_mainWindow); int fbw, fbh; glfwGetFramebufferSize(_mainWindow, &fbw, &fbh); if (fbw == windowWidth * 2) { SetHighResolutionScreen(true); } #if defined(WIN32) glfwSwapInterval(0); // because double-buffering and Windows don't get along apparently #else glfwSwapInterval(1); #endif glfwSetWindowSizeCallback(_mainWindow, Camera::ResizeCallback); glfwSetKeyCallback(_mainWindow, keyboardInput); glfwSetCharCallback(_mainWindow, charInput); glfwSetCursorPosCallback(_mainWindow, MouseMotion); glfwSetMouseButtonCallback(_mainWindow, MouseButton); glfwSetScrollCallback(_mainWindow, MouseWheel); glfwSetWindowCloseCallback(_mainWindow, windowClosed); _prevTime = glfwGetTime(); Camera::ResizeCallback(_mainWindow, fbw, fbh); #else struct timeval tv; gettimeofday(&tv, NULL); _currTime = _startTime = tv.tv_sec + (double) tv.tv_usec / 1000000.0; #endif //OpenGL state setup #if !ANGEL_MOBILE glClearDepth(1.0f); glPolygonMode(GL_FRONT, GL_FILL); #else glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f, -1.0f); #endif glShadeModel(GL_FLAT); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glCullFace(GL_BACK); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearStencil(0); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); //Get textures going InitializeTextureLoading(); //Subscribe to camera changes theSwitchboard.SubscribeTo(this, "CameraChange"); //initialize singletons #if !ANGEL_MOBILE theInput; theControllerManager.Setup(); #endif theSound; theSpatialGraph; #if !ANGEL_MOBILE RegisterConsole(new TestConsole()); #else // register fonts, since we don't have the console doing it for us on the phone RegisterFont("Resources/Fonts/Inconsolata.otf", 24, "Console"); RegisterFont("Resources/Fonts/Inconsolata.otf", 18, "ConsoleSmall"); #endif LuaScriptingModule::Initialize(); return _initialized = true; }
int mainClass::parseDataToXLSX() { QDir currDir(tempDir); lxw_workbook *workbook = workbook_new(outputFile.toUtf8().constData()); //Parse all tables to the Excel file for (int pos = 0; pos <= tables.count()-1; pos++) { if (tables[pos].islookup == false) { QString sourceFile; sourceFile = currDir.absolutePath() + currDir.separator() + tables[pos].name + ".xml"; pt::ptree tree; pt::read_xml(sourceFile.toUtf8().constData(), tree); BOOST_FOREACH(boost::property_tree::ptree::value_type const&db, tree.get_child("mysqldump") ) { const boost::property_tree::ptree & aDatabase = db.second; // value (or a subnode) BOOST_FOREACH(boost::property_tree::ptree::value_type const&ctable, aDatabase.get_child("") ) { const std::string & key = ctable.first.data(); if (key == "table_data") { const boost::property_tree::ptree & aTable = ctable.second; //Here we need to create the sheet QString tableDesc; tableDesc = tables[pos].desc; if (tableDesc == "") tableDesc = tables[pos].name; lxw_worksheet *worksheet = workbook_add_worksheet(workbook,getSheetDescription(tableDesc)); int rowNo = 1; bool inserted = false; BOOST_FOREACH(boost::property_tree::ptree::value_type const&row, aTable.get_child("") ) { const boost::property_tree::ptree & aRow = row.second; //Here we need to append a row int colNo = 0; BOOST_FOREACH(boost::property_tree::ptree::value_type const&field, aRow.get_child("") ) { const std::string & fkey = field.first.data(); if (fkey == "field") { const boost::property_tree::ptree & aField = field.second; std::string fname = aField.get<std::string>("<xmlattr>.name"); std::string fvalue = aField.data(); QString desc; QString valueType; int size; int decSize; QString fieldName = QString::fromStdString(fname); QString fieldValue = QString::fromStdString(fvalue); getFieldData(tables[pos].name,fieldName,desc,valueType,size,decSize); if (desc != "NONE") { inserted = true; if (rowNo == 1) worksheet_write_string(worksheet,0, colNo, fieldName.toUtf8().constData(), NULL); worksheet_write_string(worksheet,rowNo, colNo, fieldValue.toUtf8().constData(), NULL); colNo++; } } } if (inserted) rowNo++; } } } } } }
void MangaListWidget::initModel(QString mangaSelected) { _scansDirectory.setFilter(QDir::Dirs); QStringList dirsList = Utils::dirList(_scansDirectory); _model->removeRows(0, _model->rowCount()); QModelIndex indexMangaSelected; for (const QString& mangaName: dirsList) { QString currDirStr = _scansDirectory.path() + "/" + mangaName; QStandardItem* currItem = new QStandardItem(mangaName); currItem->setEditable(false); _model->appendRow(currItem); QDir currDir(currDirStr); QStringList currDirsList = Utils::dirList(currDir, true); QList<bool> areChaptersRead = Utils::areChaptersRead(mangaName); if (!Utils::isMangaRead(areChaptersRead)) currItem->setFont(QFont("", -1, 99)); else currItem->setFont(QFont()); if (mangaName == mangaSelected) { indexMangaSelected = _model->indexFromItem(currItem); } int k = 0; for (const QString& currChStr: currDirsList) { if (k >= areChaptersRead.size()) { QMessageBox::critical(this, "List error", "Error while tempting to edit manga read flags whithin MangaListWidget::initModel."); return; } bool isChapterRead = areChaptersRead.at(k); QStandardItem* currChItem = new QStandardItem(currChStr); currChItem->setEditable(false); setTextAccordingToRead(currChItem, isChapterRead); currItem->appendRow(currChItem); k++; } } if (indexMangaSelected.isValid()) { _view->selectionModel()->setCurrentIndex(indexMangaSelected, QItemSelectionModel::Current); } decorateMangaNames(); }