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:
parent
b7aa14f0e8
commit
eabec80154
|
@ -27,7 +27,8 @@
|
|||
|
||||
|
||||
ApplicationList::ApplicationList(QObject *parent) :
|
||||
QObject(parent)
|
||||
QObject(parent),
|
||||
mDefaultApplicationIndex(-1)
|
||||
{
|
||||
//ctor
|
||||
}
|
||||
|
@ -42,6 +43,7 @@ void ApplicationList::LoadSettings(QSettings *programSettings)
|
|||
|
||||
QStringList names = programSettings->value(SETTINGS_APPLICATION_NAMES, 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())
|
||||
{
|
||||
|
@ -51,27 +53,33 @@ void ApplicationList::LoadSettings(QSettings *programSettings)
|
|||
if (QFileInfo("/usr/bin/gedit").isExecutable())
|
||||
{
|
||||
AddApplicationType("gedit", "/usr/bin/gedit +(line) (file)");
|
||||
defapp = 0;
|
||||
break;
|
||||
}
|
||||
// use as default for kde environments
|
||||
if (QFileInfo("/usr/bin/kate").isExecutable())
|
||||
{
|
||||
AddApplicationType("kate", "/usr/bin/kate -l(line) (file)");
|
||||
defapp = 0;
|
||||
break;
|
||||
}
|
||||
// use as default for windows environments
|
||||
if (FindDefaultWindowsEditor())
|
||||
{
|
||||
defapp = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (0);
|
||||
}
|
||||
|
||||
if (names.size() == paths.size())
|
||||
if (names.size() > 0 && (names.size() == paths.size()))
|
||||
{
|
||||
for (int i = 0; i < names.size(); 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_PATHS, paths);
|
||||
programSettings->setValue(SETTINGS_APPLICATION_DEFAULT, mDefaultApplicationIndex);
|
||||
|
||||
}
|
||||
|
||||
|
@ -146,11 +155,11 @@ void ApplicationList::RemoveApplication(const int 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));
|
||||
}
|
||||
mDefaultApplicationIndex = list->GetDefaultApplication();
|
||||
}
|
||||
|
||||
void ApplicationList::Clear()
|
||||
{
|
||||
mApplications.clear();
|
||||
mDefaultApplicationIndex = -1;
|
||||
}
|
||||
|
||||
bool ApplicationList::FindDefaultWindowsEditor()
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
typedef struct
|
||||
{
|
||||
/**
|
||||
* @brief Applicaton's name
|
||||
* @brief Application's name
|
||||
*
|
||||
*/
|
||||
QString Name;
|
||||
|
@ -106,6 +106,15 @@ public:
|
|||
*/
|
||||
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
|
||||
*
|
||||
|
@ -133,14 +142,10 @@ public:
|
|||
void RemoveApplication(const int index);
|
||||
|
||||
/**
|
||||
* @brief Move certain application as first.
|
||||
* 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.
|
||||
*
|
||||
* @brief Set application as default application.
|
||||
* @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
|
||||
|
@ -148,6 +153,7 @@ public:
|
|||
* @param list Copying source
|
||||
*/
|
||||
void Copy(ApplicationList *list);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
|
@ -162,12 +168,19 @@ protected:
|
|||
*/
|
||||
bool FindDefaultWindowsEditor();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief List of applications
|
||||
*
|
||||
*/
|
||||
QList<ApplicationType> mApplications;
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Index of the default application.
|
||||
*
|
||||
*/
|
||||
int mDefaultApplicationIndex;
|
||||
};
|
||||
/// @}
|
||||
#endif // APPLICATIONLIST_H
|
||||
|
|
|
@ -77,6 +77,7 @@ ShowTypes;
|
|||
#define SETTINGS_SAVE_FULL_PATH "Save full path"
|
||||
#define SETTINGS_APPLICATION_NAMES "Application names"
|
||||
#define SETTINGS_APPLICATION_PATHS "Application paths"
|
||||
#define SETTINGS_APPLICATION_DEFAULT "Default Application"
|
||||
#define SETTINGS_LANGUAGE "Application language"
|
||||
#define SETTINGS_GLOBAL_INCLUDE_PATHS "Global include paths"
|
||||
#define SETTINGS_INLINE_SUPPRESSIONS "Inline suppressions"
|
||||
|
|
|
@ -247,7 +247,7 @@ void SettingsDialog::DefaultApplication()
|
|||
if (selected.size() > 0)
|
||||
{
|
||||
int index = mUI.mListWidget->row(selected[0]);
|
||||
mTempApplications->MoveFirst(index);
|
||||
mTempApplications->SetDefault(index);
|
||||
mUI.mListWidget->clear();
|
||||
PopulateApplicationList();
|
||||
}
|
||||
|
@ -255,9 +255,16 @@ void SettingsDialog::DefaultApplication()
|
|||
|
||||
void SettingsDialog::PopulateApplicationList()
|
||||
{
|
||||
const int defapp = mTempApplications->GetDefaultApplication();
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue