2009-05-23 12:37:30 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2009-05-30 07:48:12 +02:00
|
|
|
* Copyright (C) 2007-2009 Daniel Marjamäki and Cppcheck team.
|
2009-05-23 12:37:30 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "applicationlist.h"
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
ApplicationList::ApplicationList()
|
|
|
|
{
|
|
|
|
//ctor
|
|
|
|
}
|
|
|
|
|
|
|
|
ApplicationList::~ApplicationList()
|
|
|
|
{
|
2009-05-24 11:08:51 +02:00
|
|
|
Clear();
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationList::LoadSettings(QSettings &programSettings)
|
|
|
|
{
|
|
|
|
|
|
|
|
QStringList names = programSettings.value(tr("Application names"), QStringList()).toStringList();
|
|
|
|
QStringList paths = programSettings.value(tr("Application paths"), QStringList()).toStringList();
|
2009-05-23 13:26:04 +02:00
|
|
|
if (names.size() == paths.size())
|
|
|
|
{
|
|
|
|
for (int i = 0;i < names.size();i++)
|
|
|
|
{
|
|
|
|
AddApplicationType(names[i], paths[i]);
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationList::SaveSettings(QSettings &programSettings)
|
|
|
|
{
|
|
|
|
QStringList names;
|
|
|
|
QStringList paths;
|
|
|
|
|
2009-05-23 13:26:04 +02:00
|
|
|
for (int i = 0;i < GetApplicationCount();i++)
|
|
|
|
{
|
|
|
|
names << GetApplicationName(i);
|
|
|
|
paths << GetApplicationPath(i);
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
|
2009-05-23 13:26:04 +02:00
|
|
|
programSettings.setValue(tr("Application names"), names);
|
|
|
|
programSettings.setValue(tr("Application paths"), paths);
|
2009-05-23 12:37:30 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-06-20 19:55:28 +02:00
|
|
|
int ApplicationList::GetApplicationCount() const
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
|
|
|
return mApplications.size();
|
|
|
|
}
|
|
|
|
|
2009-06-20 19:55:28 +02:00
|
|
|
QString ApplicationList::GetApplicationName(const int index) const
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
|
|
|
if (index >= 0 && index < mApplications.size())
|
|
|
|
{
|
|
|
|
return mApplications[index].Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2009-06-20 19:55:28 +02:00
|
|
|
QString ApplicationList::GetApplicationPath(const int index) const
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
|
|
|
if (index >= 0 && index < mApplications.size())
|
|
|
|
{
|
|
|
|
return mApplications[index].Path;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ApplicationList::SetApplicationType(const int index,
|
|
|
|
const QString &name,
|
|
|
|
const QString &path)
|
|
|
|
{
|
|
|
|
if (index >= 0 && index < mApplications.size())
|
|
|
|
{
|
|
|
|
mApplications[index].Name = name;
|
|
|
|
mApplications[index].Path = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationList::AddApplicationType(const QString &name, const QString &path)
|
|
|
|
{
|
2009-05-24 10:55:54 +02:00
|
|
|
if (name.isEmpty() || path.isEmpty())
|
|
|
|
{
|
2009-05-24 10:53:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
ApplicationType type;
|
|
|
|
type.Name = name;
|
|
|
|
type.Path = path;
|
2009-05-23 13:26:04 +02:00
|
|
|
mApplications << type;
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationList::RemoveApplication(const int index)
|
|
|
|
{
|
2009-05-23 13:26:04 +02:00
|
|
|
mApplications.removeAt(index);
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
|
2009-05-23 17:45:05 +02:00
|
|
|
|
|
|
|
void ApplicationList::MoveFirst(const int index)
|
|
|
|
{
|
|
|
|
if (index < mApplications.size() && index > 0)
|
|
|
|
{
|
|
|
|
mApplications.move(index, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-24 11:08:51 +02:00
|
|
|
|
|
|
|
void ApplicationList::Copy(ApplicationList &list)
|
|
|
|
{
|
|
|
|
Clear();
|
2009-05-24 11:09:37 +02:00
|
|
|
for (int i = 0;i < list.GetApplicationCount();i++)
|
2009-05-24 11:08:51 +02:00
|
|
|
{
|
2009-05-24 11:09:37 +02:00
|
|
|
AddApplicationType(list.GetApplicationName(i), list.GetApplicationPath(i));
|
2009-05-24 11:08:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationList::Clear()
|
|
|
|
{
|
|
|
|
mApplications.clear();
|
|
|
|
}
|
|
|
|
|