/** * \brief Create directory tree * * \param parent Actual directory */ void Scanner::createDirTree(Directory* parent) { int depth = parent->getDepth() + 1; if (depth > _max_depth) { parent->setSize(Directory::dirSize(parent->getName(), _force)); parent->detectAge(); return; } MSG_DEBUG(msg_module, "scanning %s", parent->getName().c_str()); Directory *aux_dir; std::string entry_path, entry_name; struct dirent *entry; struct stat st; uint64_t size = 0; DIR *dir = opendir(parent->getName().c_str()); if (!dir) { throw std::invalid_argument(std::string("Cannot open " + parent->getName())); } if (lstat(parent->getName().c_str(), &st) == -1) { MSG_ERROR(msg_module, "Could not determine status of '%s' (%s)", parent->getName().c_str(), strerror(errno)); } size += st.st_size; /* Iterate through subdirectories */ while ((entry = readdir(dir))) { /* Get entry name and full path */ entry_name = entry->d_name; entry_path = parent->getName() + '/' + entry_name; if (entry_name == "." || entry_name == ".." || lstat(entry_path.c_str(), &st)) { continue; } else if (S_ISDIR(st.st_mode)) { aux_dir = new Directory(entry_path, st.st_mtime, depth, parent); MSG_DEBUG(msg_module, "%s with depth %d added to scanner tree", entry_path.c_str(), aux_dir->getDepth()); parent->addChild(aux_dir); } else { size += st.st_size; } } closedir(dir); /* Create subtrees */ for (auto child: parent->getChildren()) { createDirTree(child); size += child->getSize(); } /* Sort children so the oldest will always be on index 0 */ if (!parent->getChildren().empty()) { parent->sortChildren(); } parent->updateAge(); parent->setSize(size); }
/** * \brief Create directory tree * * \param basedir Root directory * \param maxdepth maximal depth */ void Scanner::createDirTree(std::string basedir, int maxdepth, bool force) { struct stat st; if (!lstat(basedir.c_str(), &st) && S_ISDIR(st.st_mode)) { /* Create root directory */ _rootdir = new Directory(basedir, st.st_mtime, Directory::dirDepth(basedir)); /* set right max depth */ _max_depth = maxdepth + _rootdir->getDepth(); _force = force; MSG_DEBUG(msg_module, "Real max. depth is %d", _max_depth); MSG_DEBUG(msg_module, "%s with depth %d added to scanner tree", basedir.c_str(), _rootdir->getDepth()); /* Add subdirectories (recursively) */ createDirTree(_rootdir); } else { throw std::invalid_argument(std::string("Cannot acces directory " + basedir)); } }
void MyShareData::loadData() { #ifdef Q_OS_LINUX QString ini_path(getenv("HOME")); ini_path += "/.config/"; #endif #ifdef Q_OS_WIN32 QString ini_path(QCoreApplication::applicationDirPath()); #endif QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, ini_path); QSettings m_settings(QSettings::IniFormat, QSettings::UserScope, "Obywatel GCC", "Guiter Text"); m_settings.setValue("editor/chords", 1); m_settings.setValue("editor/shift", 0); MyShareData::m_columns_count = m_settings.value("editor/column_count", 3).toInt(); MyShareData::m_scrolling_delay = m_settings.value("editor/scrolling_delay", 8).toInt(); MyShareData::m_scrolling_speed = m_settings.value("editor/scrolling_speed", 200).toInt(); MyShareData::m_fullscreen = m_settings.value("app/fullscreen", false).toBool(); MyShareData::m_text_color = m_settings.value("editor/text_color", QColor(255, 255, 255)).value<QColor>(); MyShareData::m_background_color = m_settings.value("editor/background_color", QColor(0, 0, 0)).value<QColor>(); MyShareData::m_chords_color = m_settings.value("editor/chords_color", QColor(255, 0, 0)).value<QColor>(); MyShareData::m_chords = m_settings.value("editor/chords", 1).toInt(); MyShareData::m_chords_shift = m_settings.value("editor/shift", 0).toInt(); MyShareData::m_auto_column = m_settings.value("editor/auto_column", true).toBool(); QFont font; font.setPointSize(14); MyShareData::m_font = m_settings.value("editor/font", font).value<QFont>(); MyShareData::m_encode = m_settings.value("editor/code", "UTF-8").toString(); MyShareData::m_files_history.setMaxSize(m_settings.value("app/files_history_max_size", 10).toInt()); MyShareData::m_favourites_max_size = m_settings.value("app/favourites_max_size", 20).toInt(); MyShareData::kse_new = m_settings.value("shortcuts/new", QKeySequence(Qt::CTRL + Qt::Key_N)).value<QKeySequence>(); MyShareData::kse_open = m_settings.value("shortcuts/open", QKeySequence(Qt::CTRL + Qt::Key_O)).value<QKeySequence>(); MyShareData::kse_save = m_settings.value("shortcuts/save", QKeySequence(Qt::CTRL + Qt::Key_S)).value<QKeySequence>(); MyShareData::kse_save_as = m_settings.value("shortcuts/save_as", QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S)).value<QKeySequence>(); MyShareData::kse_reload = m_settings.value("shortcuts/reload", QKeySequence(Qt::Key_F5)).value<QKeySequence>(); MyShareData::kse_chords_up = m_settings.value("shortcuts/chords_up", QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Up)).value<QKeySequence>(); MyShareData::kse_chords_down = m_settings.value("shortcuts/chords_down", QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Down)).value<QKeySequence>(); MyShareData::kse_shift_up = m_settings.value("shortcuts/shift_up", QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Right)).value<QKeySequence>(); MyShareData::kse_shift_down = m_settings.value("shortcuts/shift_down", QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Left)).value<QKeySequence>(); MyShareData::kse_fullscreen = m_settings.value("shortcuts/fullscreen", QKeySequence(Qt::Key_F11)).value<QKeySequence>(); MyShareData::kse_properties = m_settings.value("shortcuts/properties", QKeySequence(Qt::CTRL + Qt::Key_P)).value<QKeySequence>(); MyShareData::kse_find = m_settings.value("shortcuts/find", QKeySequence(Qt::CTRL + Qt::Key_F)).value<QKeySequence>(); MyShareData::kse_quick_options = m_settings.value("shortcuts/quick_options", QKeySequence(Qt::CTRL + Qt::Key_G)).value<QKeySequence>(); MyShareData::kse_close = m_settings.value("shortcuts/close", QKeySequence(Qt::CTRL + Qt::Key_Q)).value<QKeySequence>(); //------------Bazy tekstów------------ int size = m_settings.beginReadArray("bases"); for(int i = 0; i < size; i++) { m_settings.setArrayIndex(i); QString key = m_settings.value("key").toString(); TreeItem* item = createDirTree(m_settings.value("path").toString(), nullptr); MyShareData::m_text_bases.insert(key, item); } m_settings.endArray(); //------------Lista ostatnich plików------------ size = m_settings.beginReadArray("recent"); for(int i = 0; i < size && i < MyShareData::m_files_history.getMaxSize(); i++) { m_settings.setArrayIndex(i); QString path = m_settings.value("path").toString(); MyShareData::AddLastOpenAction(path, false); } m_settings.endArray(); //------------Ulubione------------ size = m_settings.beginReadArray("favourites"); for(int i = 0; i < size; i++) { m_settings.setArrayIndex(i); QString path = m_settings.value("path").toString(); int weight = m_settings.value("weight").toInt(); MyShareData::AddFavouriteAction(path, weight); } m_settings.endArray(); }