projectmanager.cpp
来自「This a source insight software in Linux.」· C++ 代码 · 共 745 行 · 第 1/2 页
CPP
745 行
return QString::null; m_pConf->setGroup("Project"); return m_pConf->readEntry("FileTypes");}/** * Reads the project's options from the configuration file. * @param opt A structure to fill with the read options */void ProjectManager::getOptions(Options& opt) const{ // Must have an open persistent project if (!m_bOpen || m_bTempProj) return; // Get project properties m_pConf->setGroup("Project"); opt.slFileTypes = m_pConf->readListEntry("FileTypes", ' '); opt.bKernel = m_pConf->readBoolEntry("Kernel", DEF_IS_KERNEL); opt.bInvIndex = m_pConf->readBoolEntry("InvIndex", DEF_INV_INDEX); opt.nAutoRebuildTime = m_pConf->readNumEntry("AutoRebuildTime"); // Get auto-completion options m_pConf->setGroup("AutoCompletion"); opt.bACEnabled = m_pConf->readBoolEntry("Enabled"); opt.nACMinChars = m_pConf->readUnsignedNumEntry("MinChars", DEF_AC_MIN_CHARS); opt.nACDelay = m_pConf->readUnsignedNumEntry("Delay", DEF_AC_DELAY); opt.nACMaxEntries = m_pConf->readUnsignedNumEntry("MaxEntries", DEF_AC_MAX_ENTRIES);}/** * Sets project options. * @param opt A structure containing the new parameters to set */void ProjectManager::setOptions(const Options& opt){ // Must have an open persistent project if (!m_bOpen || m_bTempProj) return; // Write the options to the configuratio nfile writeOptions(m_pConf, opt); // Create the argument list for invoking Cscope m_slArgs = QStringList(); if (opt.bKernel) m_slArgs << "-k"; if (opt.bInvIndex) m_slArgs << "-q";}/** * Reads the paths of the files that were open when the project was closed, * and fills a list used to restore the previous session. * The list is composed of the file paths and the current position of the * cursor inside each file (@see FileLocation). * @param list The list to fill */void ProjectManager::getOpenFiles(OpenFileList& list) const{ QStringList slEntry; QStringList::Iterator itr; QString sPath; uint nLine, nCol; // Must have an open persistent project if (!m_bOpen || m_bTempProj) return; // Read the file paths m_pConf->setGroup("Session"); slEntry = m_pConf->readListEntry("OpenFiles"); // Transform the entry into a list of file locations for (itr = slEntry.begin(); itr != slEntry.end(); ++itr) { sPath = (*itr).section(':', 0, 0); nLine = (*itr).section(':', 1, 1).toUInt(); nCol = (*itr).section(':', 2, 2).toUInt(); list.append(new FileLocation(sPath, nLine, nCol)); }}/** * Writes a list of open files to the project's configuration file. * The list is composed of the file paths and the current position of the * cursor inside each file. * The method is called before a project is closed, so these file paths can * be read when the project is restored. * @param list The list of file paths to write */void ProjectManager::setOpenFiles(OpenFileList& list){ FileLocation* pLoc; QString sLoc; QStringList slEntry; // Must have an open persistent project if (!m_bOpen || m_bTempProj) return; // Turn the object list into a string list, so that it can be written in // the configuration file for (pLoc = list.first(); pLoc != NULL; pLoc = list.next()) { sLoc = ""; QTextOStream(&sLoc) << pLoc->m_sPath << ":" << pLoc->m_nLine << ":" << pLoc->m_nCol; slEntry.append(sLoc); } // Write the file paths m_pConf->setGroup("Session"); m_pConf->writeEntry("OpenFiles", slEntry);}/** * @return The full path of the file that was active when the session was * closed */QString ProjectManager::getLastOpenFile() const{ // Must have an open persistent project if (!m_bOpen || m_bTempProj) return ""; // Read the file paths m_pConf->setGroup("Session"); return m_pConf->readEntry("LastOpenFile");}/** * @param sPath The full path of the currently active file */void ProjectManager::setLastOpenFile(const QString& sPath){ // Must have an open persistent project if (!m_bOpen || m_bTempProj) return; // Read the file paths m_pConf->setGroup("Session"); m_pConf->writeEntry("LastOpenFile", sPath);}/** * Reads the names of the files corresponding to queries that were locked * when the project was closed, and fills a list used to restore the * previous session. * @param slQueryFiles The list to fill */void ProjectManager::getQueryFiles(QStringList& slQueryFiles) const{ // Must have an open persistent project if (!m_bOpen || m_bTempProj) return; // Read the file paths m_pConf->setGroup("Session"); slQueryFiles = m_pConf->readListEntry("QueryFiles");}/** * Writes a list of query file names to the project's configuration file. * The method is called before a project is closed, so these file names can * be read when the project is restored. * @param slQueryFiles The list of file names to write */void ProjectManager::setQueryFiles(QStringList& slQueryFiles){ // Must have an open persistent project if (!m_bOpen || m_bTempProj) return; // Write the file names m_pConf->setGroup("Session"); m_pConf->writeEntry("QueryFiles", slQueryFiles);}/** * Reads the names of the files corresponding to call trees that were opened * when the project was closed, and fills a list used to restore the * previous session. * @param slQueryFiles The list to fill */void ProjectManager::getCallTreeFiles(QStringList& slQueryFiles) const{ // Must have an open persistent project if (!m_bOpen || m_bTempProj) return; // Read the file paths m_pConf->setGroup("Session"); slQueryFiles = m_pConf->readListEntry("CallTreeFiles");}/** * Writes a list of call tree file names to the project's configuration file. * The method is called before a project is closed, so these file names can * be read when the project is restored. * @param slQueryFiles The list of file names to write */void ProjectManager::setCallTreeFiles(QStringList& slQueryFiles){ // Must have an open persistent project if (!m_bOpen || m_bTempProj) return; // Write the file names m_pConf->setGroup("Session"); m_pConf->writeEntry("CallTreeFiles", slQueryFiles);}/** * Reads the value of the project's root directory from the project's * configuration file. * @return The root directory of the active project */QString ProjectManager::getRoot() const{ // Empty root if no project is currently open if (!m_bOpen) return ""; // Return the file-system root if using a temporary project if (m_bTempProj) return "/"; m_pConf->setGroup("Project"); return m_pConf->readEntry("RootPath", "/");}/** * Sets a new root directory for a project. * @param sRoot The full path of the new root directory */void ProjectManager::setRoot(const QString& sRoot){ // Do nothing if there is no open project, or using a temporary project if (!m_bOpen || m_bTempProj) return; m_pConf->setGroup("Project"); m_pConf->writeEntry("RootPath", sRoot);} /** * Copies the list of previously queried symbols to the target object. * @param slSymHistory The list object to copy into */void ProjectManager::getSymHistory(QStringList& slSymHistory) const{ slSymHistory = m_slSymHistory;}/** * Copies the list of previously queried symbols from the target object. * @param slSymHistory The list object to copy from */void ProjectManager::setSymHistory(QStringList& slSymHistory){ m_slSymHistory = slSymHistory;}/** * Determines if the cscope.out file for this project exists. * @return true if the database exists, false otherwise */bool ProjectManager::dbExists(){ if (!m_bOpen) return false; return m_dir.exists("cscope.out");}/** * Fills a structure with default properties for a new project. * Default properties are partly based on the system profile. * @param opt The structure to fill */void ProjectManager::getDefOptions(Options& opt){ // Initialise MIME-type list opt.slFileTypes.append("*.c"); opt.slFileTypes.append("*.h"); // Set other options opt.bKernel = DEF_IS_KERNEL; opt.bInvIndex = DEF_INV_INDEX; opt.nACMinChars = DEF_AC_MIN_CHARS; opt.nACDelay = DEF_AC_DELAY; opt.nACMaxEntries = DEF_AC_MAX_ENTRIES; // Set profile-dependant options if (Config().getSysProfile() == KScopeConfig::Fast) { opt.nAutoRebuildTime = 10; opt.bACEnabled = true; } else { opt.nAutoRebuildTime = -1; opt.bACEnabled = false; }}/** * Creates the "cscope.files" and "cscope.proj" file objects for the given * project. * @param sPath The project directory, in which the files reside * @param ppFilesFile Holds the new "cscope.files" object, upon return * @param ppConf Holds the new "cscope.proj" object, upon return */void ProjectManager::initConfig(const QString& sPath, QFile** ppFilesFile, KConfig** ppConf){ QString sFilesFile, sConfFile; // Attach to the source files file sFilesFile = sPath + "/cscope.files"; *ppFilesFile = new QFile(sFilesFile); // Open the configuraton file sConfFile = sPath + "/cscope.proj"; *ppConf = new KConfig(sConfFile);}/** * Determines if the given file is a Cscope cross-reference database. * @param sPath The full path of the file to check * @return true if the given file is a cscope.out file, false otherwise */bool ProjectManager::isCscopeOut(const QString& sPath){ QFile file(sPath); QString sLine; int nVer; char szDir[PATH_MAX]; // Try to open the file if (!file.open(IO_ReadOnly)) return false; // Check if the first line matches the expected format sLine = QTextStream(&file).readLine(); return sscanf(sLine.latin1(), "cscope %d %s", &nVer, szDir) == 2;}/** * Writes a set of project options to the given configuration file. * @param pConf An initialised configuration file * @param opt The options to write */void ProjectManager::writeOptions(KConfig* pConf, const Options& opt){ // Set new project options pConf->setGroup("Project"); pConf->writeEntry("FileTypes", opt.slFileTypes.join(" ")); pConf->writeEntry("Kernel", opt.bKernel); pConf->writeEntry("InvIndex", opt.bInvIndex); pConf->writeEntry("AutoRebuildTime", opt.nAutoRebuildTime); // Set auto-completion options pConf->setGroup("AutoCompletion"); pConf->writeEntry("Enabled", opt.bACEnabled); pConf->writeEntry("MinChars", opt.nACMinChars); pConf->writeEntry("Delay", opt.nACDelay); pConf->writeEntry("MaxEntries", opt.nACMaxEntries);}#include "projectmanager.moc"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?