Added support for checking files via commandline arguments.

This commit is contained in:
Vesa Pikki 2009-07-16 08:20:29 +03:00
parent cffa4772b0
commit 962757c257
5 changed files with 70 additions and 51 deletions

View File

@ -31,8 +31,6 @@ int main(int argc, char *argv[])
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
MainWindow window; MainWindow window;
window.show(); window.show();
return app.exec(); return app.exec();

View File

@ -91,7 +91,13 @@ MainWindow::MainWindow() :
QStringList args = QCoreApplication::arguments();
//Remove the application itself
args.removeFirst();
if (!args.isEmpty())
{
DoCheckFiles(args);
}
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -185,43 +191,18 @@ void MainWindow::SaveSettings()
mUI.mResults->SaveSettings(); mUI.mResults->SaveSettings();
} }
void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) void MainWindow::DoCheckFiles(const QStringList &files)
{ {
QStringList selected; if (files.isEmpty())
// NOTE: we use QFileDialog::getOpenFileNames() and
// QFileDialog::getExistingDirectory() because they show native Windows
// selection dialog which is a lot more usable than QT:s own dialog.
if (mode == QFileDialog::ExistingFiles)
{ {
selected = QFileDialog::getOpenFileNames(this, return;
tr("Select files to check"),
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
if (selected.isEmpty())
mCurrentDirectory.clear();
FormatAndSetTitle();
} }
else if (mode == QFileDialog::DirectoryOnly)
{
QString dir = QFileDialog::getExistingDirectory(this,
tr("Select directory to check"),
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
if (!dir.isEmpty())
{
mCurrentDirectory = dir;
selected.append(dir);
FormatAndSetTitle(dir);
}
}
if (selected.count() > 0)
{
ClearResults(); ClearResults();
QStringList fileNames; QStringList fileNames;
QString selection; QString selection;
foreach(selection, selected) foreach(selection, files)
{ {
fileNames << RemoveUnacceptedFiles(GetFilesRecursively(selection)); fileNames << RemoveUnacceptedFiles(GetFilesRecursively(selection));
} }
@ -253,17 +234,49 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
Settings checkSettings = GetCppcheckSettings(); Settings checkSettings = GetCppcheckSettings();
mThread->Check(checkSettings, false); mThread->Check(checkSettings, false);
}
QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode)
{
QStringList selected;
// NOTE: we use QFileDialog::getOpenFileNames() and
// QFileDialog::getExistingDirectory() because they show native Windows
// selection dialog which is a lot more usable than QT:s own dialog.
if (mode == QFileDialog::ExistingFiles)
{
selected = QFileDialog::getOpenFileNames(this,
tr("Select files to check"),
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
if (selected.isEmpty())
mCurrentDirectory.clear();
FormatAndSetTitle();
} }
else if (mode == QFileDialog::DirectoryOnly)
{
QString dir = QFileDialog::getExistingDirectory(this,
tr("Select directory to check"),
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
if (!dir.isEmpty())
{
mCurrentDirectory = dir;
selected.append(dir);
FormatAndSetTitle(dir);
}
}
return selected;
} }
void MainWindow::CheckFiles() void MainWindow::CheckFiles()
{ {
DoCheckFiles(QFileDialog::ExistingFiles); DoCheckFiles(SelectFilesToCheck(QFileDialog::ExistingFiles));
} }
void MainWindow::CheckDirectory() void MainWindow::CheckDirectory()
{ {
DoCheckFiles(QFileDialog::DirectoryOnly); DoCheckFiles(SelectFilesToCheck(QFileDialog::DirectoryOnly));
} }
Settings MainWindow::GetCppcheckSettings() Settings MainWindow::GetCppcheckSettings()

View File

@ -205,8 +205,16 @@ protected:
* directory to check. Use native dialogs instead of QT:s own dialogs. * directory to check. Use native dialogs instead of QT:s own dialogs.
* *
* @param mode Dialog open mode (files or directories) * @param mode Dialog open mode (files or directories)
* @return QStringList of files or directories that were selected to check
*/ */
void DoCheckFiles(QFileDialog::FileMode mode); QStringList SelectFilesToCheck(QFileDialog::FileMode mode);
/**
* @brief Check all files specified in parameter files
*
* @param files List of files and/or directories to check
*/
void DoCheckFiles(const QStringList &files);
/** /**
* @brief Get all files recursively from given path * @brief Get all files recursively from given path

View File

@ -1793,7 +1793,7 @@ bool Tokenizer::simplifyConditionOperator()
} }
else else
{ {
tok->insertToken(str.substr(pos1, pos2-pos1).c_str()); tok->insertToken(str.substr(pos1, pos2 - pos1).c_str());
pos1 = pos2 + 1; pos1 = pos2 + 1;
} }
tok = tok->next(); tok = tok->next();