GUI: Ask file location from user if not found.

When loading report from XML there is no full paths so the file's real
path is not known and cppcheck cannot open it. So if the file has no
absolute path then we ask where the file is located from the user.
This commit is contained in:
Kimmo Varis 2010-07-11 14:22:55 +03:00
parent f894b19209
commit b8793b1529
2 changed files with 43 additions and 1 deletions

View File

@ -24,6 +24,7 @@
#include <QDir>
#include <QMessageBox>
#include <QFileInfo>
#include <QFileDialog>
#include <QClipboard>
#include "erroritem.h"
#include "resultstree.h"
@ -444,7 +445,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
void ResultsTree::StartApplication(QStandardItem *target, int application)
{
//If there are now application's specified, tell the user about it
//If there are no applications specified, tell the user about it
if (mApplications->GetApplicationCount() == 0)
{
QMessageBox msg(QMessageBox::Information,
@ -468,6 +469,26 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
//Replace (file) with filename
QString file = data["file"].toString();
QFileInfo info(file);
if (!info.exists())
{
if (info.isAbsolute())
{
QMessageBox msgbox(this);
msgbox.setWindowTitle("Cppcheck");
msgbox.setText(tr("Could not find the file!"));
msgbox.setIcon(QMessageBox::Critical);
msgbox.exec();
}
else
{
QString dir = AskFileDir(file);
dir += '/';
file = dir + file;
}
}
if (file.indexOf(" ") > -1)
{
file.insert(0, "\"");
@ -498,6 +519,21 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
}
}
QString ResultsTree::AskFileDir(const QString &file)
{
QString text = tr("Could not find file:\n%1\nPlease select the directory where file is located.").arg(file);
QMessageBox msgbox(this);
msgbox.setWindowTitle("Cppcheck");
msgbox.setText(text);
msgbox.setIcon(QMessageBox::Warning);
msgbox.exec();
QString dir = QFileDialog::getExistingDirectory(this, tr("Select Directory"),
"",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
return dir;
}
void ResultsTree::CopyFilename()
{
CopyPath(mContextItem, false);

View File

@ -262,6 +262,12 @@ protected:
*/
void LoadSettings();
/**
* @brief Ask directory where file is located.
* @param file File name.
* @return Directory user chose.
*/
QString AskFileDir(const QString &file);
/**
* @brief Create a new QStandardItem