GUI: Show default application with [Default] text.

Instead of keeping the default application as a first item in
the application list point the default application by adding a
"[Default]" text after its name.
This commit is contained in:
Kimmo Varis 2011-02-25 11:45:04 +02:00
parent b7aa14f0e8
commit eabec80154
4 changed files with 47 additions and 15 deletions

View File

@ -27,7 +27,8 @@
ApplicationList::ApplicationList(QObject *parent) : ApplicationList::ApplicationList(QObject *parent) :
QObject(parent) QObject(parent),
mDefaultApplicationIndex(-1)
{ {
//ctor //ctor
} }
@ -42,6 +43,7 @@ void ApplicationList::LoadSettings(QSettings *programSettings)
QStringList names = programSettings->value(SETTINGS_APPLICATION_NAMES, QStringList()).toStringList(); QStringList names = programSettings->value(SETTINGS_APPLICATION_NAMES, QStringList()).toStringList();
QStringList paths = programSettings->value(SETTINGS_APPLICATION_PATHS, QStringList()).toStringList(); QStringList paths = programSettings->value(SETTINGS_APPLICATION_PATHS, QStringList()).toStringList();
int defapp = programSettings->value(SETTINGS_APPLICATION_DEFAULT, -1).toInt();
if (names.empty() && paths.empty()) if (names.empty() && paths.empty())
{ {
@ -51,27 +53,33 @@ void ApplicationList::LoadSettings(QSettings *programSettings)
if (QFileInfo("/usr/bin/gedit").isExecutable()) if (QFileInfo("/usr/bin/gedit").isExecutable())
{ {
AddApplicationType("gedit", "/usr/bin/gedit +(line) (file)"); AddApplicationType("gedit", "/usr/bin/gedit +(line) (file)");
defapp = 0;
break; break;
} }
// use as default for kde environments // use as default for kde environments
if (QFileInfo("/usr/bin/kate").isExecutable()) if (QFileInfo("/usr/bin/kate").isExecutable())
{ {
AddApplicationType("kate", "/usr/bin/kate -l(line) (file)"); AddApplicationType("kate", "/usr/bin/kate -l(line) (file)");
defapp = 0;
break; break;
} }
// use as default for windows environments // use as default for windows environments
if (FindDefaultWindowsEditor()) if (FindDefaultWindowsEditor())
{
defapp = 0;
break; break;
}
} }
while (0); while (0);
} }
if (names.size() == paths.size()) if (names.size() > 0 && (names.size() == paths.size()))
{ {
for (int i = 0; i < names.size(); i++) for (int i = 0; i < names.size(); i++)
{ {
AddApplicationType(names[i], paths[i]); AddApplicationType(names[i], paths[i]);
} }
mDefaultApplicationIndex = 1;
} }
} }
@ -88,6 +96,7 @@ void ApplicationList::SaveSettings(QSettings *programSettings)
programSettings->setValue(SETTINGS_APPLICATION_NAMES, names); programSettings->setValue(SETTINGS_APPLICATION_NAMES, names);
programSettings->setValue(SETTINGS_APPLICATION_PATHS, paths); programSettings->setValue(SETTINGS_APPLICATION_PATHS, paths);
programSettings->setValue(SETTINGS_APPLICATION_DEFAULT, mDefaultApplicationIndex);
} }
@ -146,11 +155,11 @@ void ApplicationList::RemoveApplication(const int index)
mApplications.removeAt(index); mApplications.removeAt(index);
} }
void ApplicationList::MoveFirst(const int index) void ApplicationList::SetDefault(const int index)
{ {
if (index < mApplications.size() && index > 0) if (index < mApplications.size() && index >= 0)
{ {
mApplications.move(index, 0); mDefaultApplicationIndex = index;
} }
} }
@ -166,11 +175,13 @@ void ApplicationList::Copy(ApplicationList *list)
{ {
AddApplicationType(list->GetApplicationName(i), list->GetApplicationPath(i)); AddApplicationType(list->GetApplicationName(i), list->GetApplicationPath(i));
} }
mDefaultApplicationIndex = list->GetDefaultApplication();
} }
void ApplicationList::Clear() void ApplicationList::Clear()
{ {
mApplications.clear(); mApplications.clear();
mDefaultApplicationIndex = -1;
} }
bool ApplicationList::FindDefaultWindowsEditor() bool ApplicationList::FindDefaultWindowsEditor()

View File

@ -56,7 +56,7 @@ public:
typedef struct typedef struct
{ {
/** /**
* @brief Applicaton's name * @brief Application's name
* *
*/ */
QString Name; QString Name;
@ -106,6 +106,15 @@ public:
*/ */
QString GetApplicationPath(const int index) const; QString GetApplicationPath(const int index) const;
/**
* @brief Return the default application.
* @return Index of the default application.
*/
int GetDefaultApplication() const
{
return mDefaultApplicationIndex;
}
/** /**
* @brief Modify an application * @brief Modify an application
* *
@ -133,14 +142,10 @@ public:
void RemoveApplication(const int index); void RemoveApplication(const int index);
/** /**
* @brief Move certain application as first. * @brief Set application as default application.
* Position of the application is used by the application to determine
* which of the applications is the default application. First application
* (index 0) is the default application.
*
* @param index Index of the application to make the default one * @param index Index of the application to make the default one
*/ */
void MoveFirst(const int index); void SetDefault(const int index);
/** /**
* @brief Remove all applications from this list and copy all applications from * @brief Remove all applications from this list and copy all applications from
@ -148,6 +153,7 @@ public:
* @param list Copying source * @param list Copying source
*/ */
void Copy(ApplicationList *list); void Copy(ApplicationList *list);
protected: protected:
/** /**
@ -162,12 +168,19 @@ protected:
*/ */
bool FindDefaultWindowsEditor(); bool FindDefaultWindowsEditor();
private:
/** /**
* @brief List of applications * @brief List of applications
* *
*/ */
QList<ApplicationType> mApplications; QList<ApplicationType> mApplications;
private:
/**
* @brief Index of the default application.
*
*/
int mDefaultApplicationIndex;
}; };
/// @} /// @}
#endif // APPLICATIONLIST_H #endif // APPLICATIONLIST_H

View File

@ -77,6 +77,7 @@ ShowTypes;
#define SETTINGS_SAVE_FULL_PATH "Save full path" #define SETTINGS_SAVE_FULL_PATH "Save full path"
#define SETTINGS_APPLICATION_NAMES "Application names" #define SETTINGS_APPLICATION_NAMES "Application names"
#define SETTINGS_APPLICATION_PATHS "Application paths" #define SETTINGS_APPLICATION_PATHS "Application paths"
#define SETTINGS_APPLICATION_DEFAULT "Default Application"
#define SETTINGS_LANGUAGE "Application language" #define SETTINGS_LANGUAGE "Application language"
#define SETTINGS_GLOBAL_INCLUDE_PATHS "Global include paths" #define SETTINGS_GLOBAL_INCLUDE_PATHS "Global include paths"
#define SETTINGS_INLINE_SUPPRESSIONS "Inline suppressions" #define SETTINGS_INLINE_SUPPRESSIONS "Inline suppressions"

View File

@ -247,7 +247,7 @@ void SettingsDialog::DefaultApplication()
if (selected.size() > 0) if (selected.size() > 0)
{ {
int index = mUI.mListWidget->row(selected[0]); int index = mUI.mListWidget->row(selected[0]);
mTempApplications->MoveFirst(index); mTempApplications->SetDefault(index);
mUI.mListWidget->clear(); mUI.mListWidget->clear();
PopulateApplicationList(); PopulateApplicationList();
} }
@ -255,9 +255,16 @@ void SettingsDialog::DefaultApplication()
void SettingsDialog::PopulateApplicationList() void SettingsDialog::PopulateApplicationList()
{ {
const int defapp = mTempApplications->GetDefaultApplication();
for (int i = 0; i < mTempApplications->GetApplicationCount(); i++) for (int i = 0; i < mTempApplications->GetApplicationCount(); i++)
{ {
mUI.mListWidget->addItem(mTempApplications->GetApplicationName(i)); QString name = mTempApplications->GetApplicationName(i);
if (i == defapp)
{
name += " ";
name += tr("[Default]");
}
mUI.mListWidget->addItem(name);
} }
// If list contains items select first item // If list contains items select first item