GUI: Allow giving project file to command line.

GUI now recognizes -p <project file> command line parameter. When
given (with path to valid project file) GUI automatically loads
the project file and starts checking paths in it.

Ticket: #2613 (GUI: Should accept project file from command line)
This commit is contained in:
Kimmo Varis 2011-04-07 15:34:15 +03:00
parent 803203a876
commit a5c12172f9
2 changed files with 58 additions and 27 deletions

View File

@ -117,7 +117,7 @@ MainWindow::MainWindow() :
args.removeFirst();
if (!args.isEmpty())
{
DoCheckFiles(args);
HandleCLIParams(args);
}
}
@ -127,6 +127,21 @@ MainWindow::~MainWindow()
delete mProject;
}
void MainWindow::HandleCLIParams(const QStringList &params)
{
if (params.contains("-p"))
{
QString projFile;
const int ind = params.indexOf("-p");
if ((ind + 1) < params.length())
projFile = params[ind + 1];
LoadProjectFile(projFile);
}
else
DoCheckFiles(params);
}
void MainWindow::LoadSettings()
{
if (mSettings->value(SETTINGS_WINDOW_MAXIMIZED, false).toBool())
@ -730,39 +745,43 @@ void MainWindow::OpenProjectFile()
if (!filepath.isEmpty())
{
QFileInfo inf(filepath);
const QString filename = inf.fileName();
FormatAndSetTitle(tr("Project: ") + QString(" ") + filename);
LoadProjectFile(filepath);
}
}
mUI.mActionCloseProjectFile->setEnabled(true);
mUI.mActionEditProjectFile->setEnabled(true);
delete mProject;
mProject = new Project(filepath, this);
mProject->Open();
QString rootpath = mProject->GetProjectFile()->GetRootPath();
void MainWindow::LoadProjectFile(const QString &filePath)
{
QFileInfo inf(filePath);
const QString filename = inf.fileName();
FormatAndSetTitle(tr("Project: ") + QString(" ") + filename);
// If root path not give or "current dir" then use project file's directory
// as check path
if (rootpath.isEmpty() || rootpath == ".")
mCurrentDirectory = inf.canonicalPath();
else
mCurrentDirectory = rootpath;
mUI.mActionCloseProjectFile->setEnabled(true);
mUI.mActionEditProjectFile->setEnabled(true);
delete mProject;
mProject = new Project(filePath, this);
mProject->Open();
QString rootpath = mProject->GetProjectFile()->GetRootPath();
QStringList paths = mProject->GetProjectFile()->GetCheckPaths();
if (!paths.isEmpty())
// If root path not give or "current dir" then use project file's directory
// as check path
if (rootpath.isEmpty() || rootpath == ".")
mCurrentDirectory = inf.canonicalPath();
else
mCurrentDirectory = rootpath;
QStringList paths = mProject->GetProjectFile()->GetCheckPaths();
if (!paths.isEmpty())
{
for (int i = 0; i < paths.size(); i++)
{
for (int i = 0; i < paths.size(); i++)
if (!QDir::isAbsolutePath(paths[i]))
{
if (!QDir::isAbsolutePath(paths[i]))
{
QString path = mCurrentDirectory + "/";
path += paths[i];
paths[i] = QDir::cleanPath(path);
}
QString path = mCurrentDirectory + "/";
path += paths[i];
paths[i] = QDir::cleanPath(path);
}
DoCheckFiles(paths);
}
DoCheckFiles(paths);
}
}

View File

@ -360,6 +360,18 @@ protected:
*/
void AddIncludeDirs(const QStringList &includeDirs, Settings &result);
/**
* @brief Handle command line parameters given to GUI.
* @param params List of string given to command line.
*/
void HandleCLIParams(const QStringList &params);
/**
* @brief Load project file to the GUI.
* @param filePath Filename (inc. path) of project file to load.
*/
void LoadProjectFile(const QString &filePath);
/**
* @brief Program settings
*