mirror of
https://github.com/KDE/konsole.git
synced 2026-06-11 07:26:10 -04:00
Remove 'Favorite Profile'
The only real thing a favorite profile does is to be accessible from the Settings -> Profile menu. This simplifies a lot of code and makes the flow of settings more what the user expects. Next: Merge ProfileManager & ProfileModel
This commit is contained in:
committed by
Kurt Hindenburg
parent
8aaf43185d
commit
28ba920c82
@@ -47,21 +47,21 @@ ProfileList::ProfileList(bool addShortcuts , QObject* parent)
|
||||
// create new tabs using the default profile from the menu
|
||||
_emptyListAction = new QAction(i18n("Default profile"), _group);
|
||||
|
||||
|
||||
connect(_group, &QActionGroup::triggered, this, &ProfileList::triggered);
|
||||
|
||||
// TODO - Handle re-sorts when user changes profile names
|
||||
ProfileManager* manager = ProfileManager::instance();
|
||||
const QList<Profile::Ptr> favoriteProfiles = manager->sortedFavorites();
|
||||
connect(manager, &ProfileManager::shortcutChanged, this, &ProfileList::shortcutChanged);
|
||||
connect(manager, &ProfileManager::profileChanged, this, &ProfileList::profileChanged);
|
||||
connect(manager, &ProfileManager::profileRemoved, this, &ProfileList::removeShortcutAction);
|
||||
connect(manager, &ProfileManager::profileAdded, this, &ProfileList::addShortcutAction);
|
||||
|
||||
for (const Profile::Ptr &profile : favoriteProfiles) {
|
||||
favoriteChanged(profile, true);
|
||||
for (const auto& profile : ProfileManager::instance()->allProfiles()) {
|
||||
addShortcutAction(profile);
|
||||
}
|
||||
|
||||
connect(_group, &QActionGroup::triggered, this, &Konsole::ProfileList::triggered);
|
||||
|
||||
// listen for future changes to the profiles
|
||||
connect(manager, &Konsole::ProfileManager::favoriteStatusChanged, this, &Konsole::ProfileList::favoriteChanged);
|
||||
connect(manager, &Konsole::ProfileManager::shortcutChanged, this, &Konsole::ProfileList::shortcutChanged);
|
||||
connect(manager, &Konsole::ProfileManager::profileChanged, this, &Konsole::ProfileList::profileChanged);
|
||||
}
|
||||
|
||||
void ProfileList::updateEmptyAction()
|
||||
{
|
||||
Q_ASSERT(_group);
|
||||
@@ -165,15 +165,6 @@ void ProfileList::removeShortcutAction(const Profile::Ptr &profile)
|
||||
updateEmptyAction();
|
||||
}
|
||||
|
||||
void ProfileList::favoriteChanged(const Profile::Ptr &profile, bool isFavorite)
|
||||
{
|
||||
if (isFavorite) {
|
||||
addShortcutAction(profile);
|
||||
} else {
|
||||
removeShortcutAction(profile);
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileList::triggered(QAction* action)
|
||||
{
|
||||
emit profileSelected(action->data().value<Profile::Ptr>());
|
||||
|
||||
@@ -83,7 +83,6 @@ Q_SIGNALS:
|
||||
|
||||
private Q_SLOTS:
|
||||
void triggered(QAction *action);
|
||||
void favoriteChanged(const Profile::Ptr &profile, bool isFavorite);
|
||||
void profileChanged(const Profile::Ptr &profile);
|
||||
void shortcutChanged(const Profile::Ptr &profile, const QKeySequence &sequence);
|
||||
void addShortcutAction(const Profile::Ptr &profile);
|
||||
|
||||
@@ -72,11 +72,9 @@ static void sortByNameProfileList(QList<Profile::Ptr>& list)
|
||||
|
||||
ProfileManager::ProfileManager()
|
||||
: _profiles(QSet<Profile::Ptr>())
|
||||
, _favorites(QSet<Profile::Ptr>())
|
||||
, _defaultProfile(nullptr)
|
||||
, _fallbackProfile(nullptr)
|
||||
, _loadedAllProfiles(false)
|
||||
, _loadedFavorites(false)
|
||||
, _shortcuts(QMap<QKeySequence, ShortcutData>())
|
||||
{
|
||||
//load fallback profile
|
||||
@@ -300,22 +298,11 @@ void ProfileManager::saveSettings()
|
||||
// save shortcuts
|
||||
saveShortcuts();
|
||||
|
||||
// save favorites
|
||||
saveFavorites();
|
||||
|
||||
// ensure default/favorites/shortcuts settings are synced into disk
|
||||
// ensure default/shortcuts settings are synced into disk
|
||||
KSharedConfigPtr appConfig = KSharedConfig::openConfig();
|
||||
appConfig->sync();
|
||||
}
|
||||
|
||||
QList<Profile::Ptr> ProfileManager::sortedFavorites()
|
||||
{
|
||||
QList<Profile::Ptr> favorites = findFavorites().values();
|
||||
|
||||
sortProfiles(favorites);
|
||||
return favorites;
|
||||
}
|
||||
|
||||
QList<Profile::Ptr> ProfileManager::allProfiles()
|
||||
{
|
||||
loadAllProfiles();
|
||||
@@ -481,8 +468,6 @@ bool ProfileManager::deleteProfile(Profile::Ptr profile)
|
||||
}
|
||||
}
|
||||
|
||||
// remove from favorites, profile list, shortcut list etc.
|
||||
setFavorite(profile, false);
|
||||
setShortcut(profile, QKeySequence());
|
||||
_profiles.remove(profile);
|
||||
|
||||
@@ -526,26 +511,6 @@ void ProfileManager::saveDefaultProfile()
|
||||
group.writeEntry("DefaultProfile", fileInfo.fileName());
|
||||
}
|
||||
|
||||
QSet<Profile::Ptr> ProfileManager::findFavorites()
|
||||
{
|
||||
loadFavorites();
|
||||
|
||||
return _favorites;
|
||||
}
|
||||
void ProfileManager::setFavorite(const Profile::Ptr &profile , bool favorite)
|
||||
{
|
||||
if (!_profiles.contains(profile)) {
|
||||
addProfile(profile);
|
||||
}
|
||||
|
||||
if (favorite && !_favorites.contains(profile)) {
|
||||
_favorites.insert(profile);
|
||||
emit favoriteStatusChanged(profile, favorite);
|
||||
} else if (!favorite && _favorites.contains(profile)) {
|
||||
_favorites.remove(profile);
|
||||
emit favoriteStatusChanged(profile, favorite);
|
||||
}
|
||||
}
|
||||
void ProfileManager::loadShortcuts()
|
||||
{
|
||||
KSharedConfigPtr appConfig = KSharedConfig::openConfig();
|
||||
@@ -595,21 +560,6 @@ void ProfileManager::saveShortcuts()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ProfileManager::saveFavorites()
|
||||
{
|
||||
KSharedConfigPtr appConfig = KSharedConfig::openConfig();
|
||||
KConfigGroup favoriteGroup = appConfig->group("Favorite Profiles");
|
||||
|
||||
QStringList paths;
|
||||
for (const Profile::Ptr &profile : qAsConst(_favorites)) {
|
||||
Q_ASSERT(_profiles.contains(profile) && profile);
|
||||
paths << normalizePath(profile->path());
|
||||
}
|
||||
favoriteGroup.writeEntry("Favorites", paths);
|
||||
}
|
||||
|
||||
|
||||
void ProfileManager::setShortcut(Profile::Ptr profile ,
|
||||
const QKeySequence& keySequence)
|
||||
{
|
||||
@@ -629,44 +579,6 @@ void ProfileManager::setShortcut(Profile::Ptr profile ,
|
||||
|
||||
emit shortcutChanged(profile, keySequence);
|
||||
}
|
||||
void ProfileManager::loadFavorites()
|
||||
{
|
||||
if (_loadedFavorites) {
|
||||
return;
|
||||
}
|
||||
|
||||
KSharedConfigPtr appConfig = KSharedConfig::openConfig();
|
||||
KConfigGroup favoriteGroup = appConfig->group("Favorite Profiles");
|
||||
|
||||
QSet<QString> favoriteSet;
|
||||
|
||||
if (favoriteGroup.hasKey("Favorites")) {
|
||||
const QStringList list = favoriteGroup.readEntry("Favorites", QStringList());
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
favoriteSet = QSet<QString>(list.begin(), list.end());
|
||||
#else
|
||||
favoriteSet = QSet<QString>::fromList(list);
|
||||
#endif
|
||||
}
|
||||
|
||||
// look for favorites among those already loaded
|
||||
for (const Profile::Ptr &profile : qAsConst(_profiles)) {
|
||||
const QString& path = profile->path();
|
||||
if (favoriteSet.contains(path)) {
|
||||
_favorites.insert(profile);
|
||||
favoriteSet.remove(path);
|
||||
}
|
||||
}
|
||||
// load any remaining favorites
|
||||
for (const QString &favorite : qAsConst(favoriteSet)) {
|
||||
Profile::Ptr profile = loadProfile(favorite);
|
||||
if (profile) {
|
||||
_favorites.insert(profile);
|
||||
}
|
||||
}
|
||||
|
||||
_loadedFavorites = true;
|
||||
}
|
||||
|
||||
QKeySequence ProfileManager::shortcut(Profile::Ptr profile) const
|
||||
{
|
||||
|
||||
@@ -38,11 +38,6 @@ namespace Konsole {
|
||||
/**
|
||||
* Manages profiles which specify various settings for terminal sessions
|
||||
* and their displays.
|
||||
*
|
||||
* Profiles in the manager have a concept of favorite status, which can be used
|
||||
* by widgets and dialogs in the application decide which profiles to list and
|
||||
* how to display them. The favorite status of a profile can be altered using
|
||||
* setFavorite() and retrieved using isFavorite()
|
||||
*/
|
||||
class KONSOLEPRIVATE_EXPORT ProfileManager : public QObject
|
||||
{
|
||||
@@ -69,9 +64,7 @@ public:
|
||||
* Returns a list of all available profiles
|
||||
*
|
||||
* Initially only the profile currently set as the default is loaded.
|
||||
*
|
||||
* Favorite profiles are loaded automatically when findFavorites() is called.
|
||||
*
|
||||
*
|
||||
* When this method is called, it calls loadAllProfiles() internally to
|
||||
* ensure all available profiles are loaded and usable.
|
||||
*/
|
||||
@@ -118,7 +111,6 @@ public:
|
||||
|
||||
/**
|
||||
* Registers a new type of session.
|
||||
* The favorite status of the session ( as returned by isFavorite() ) is set to false by default.
|
||||
*/
|
||||
void addProfile(const Profile::Ptr &profile);
|
||||
|
||||
@@ -165,19 +157,6 @@ public:
|
||||
*/
|
||||
Profile::Ptr fallbackProfile() const;
|
||||
|
||||
/**
|
||||
* Specifies whether a profile should be included in the user's
|
||||
* list of favorite profiles.
|
||||
*/
|
||||
void setFavorite(const Profile::Ptr &profile, bool favorite);
|
||||
|
||||
/**
|
||||
* Returns the set of the user's favorite profiles.
|
||||
*/
|
||||
QSet<Profile::Ptr> findFavorites();
|
||||
|
||||
QList<Profile::Ptr> sortedFavorites();
|
||||
|
||||
/**
|
||||
* Sorts the profile list by menuindex; those without an menuindex, sort by name.
|
||||
* The menuindex list is first and then the non-menuindex list.
|
||||
@@ -203,14 +182,6 @@ Q_SIGNALS:
|
||||
/** Emitted when a profile's properties are modified. */
|
||||
void profileChanged(const Profile::Ptr &ptr);
|
||||
|
||||
/**
|
||||
* Emitted when the favorite status of a profile changes.
|
||||
*
|
||||
* @param profile The profile to change
|
||||
* @param favorite Specifies whether the profile is a favorite or not
|
||||
*/
|
||||
void favoriteStatusChanged(const Profile::Ptr &profile, bool favorite);
|
||||
|
||||
/**
|
||||
* Emitted when the shortcut for a profile is changed.
|
||||
*
|
||||
@@ -220,7 +191,7 @@ Q_SIGNALS:
|
||||
void shortcutChanged(const Profile::Ptr &profile, const QKeySequence &newShortcut);
|
||||
|
||||
public Q_SLOTS:
|
||||
/** Saves settings (favorites, shortcuts, default profile etc.) to disk. */
|
||||
/** Saves settings (shortcuts, default profile etc.) to disk. */
|
||||
void saveSettings();
|
||||
|
||||
protected Q_SLOTS:
|
||||
@@ -237,11 +208,6 @@ private:
|
||||
// profile paths
|
||||
void saveShortcuts();
|
||||
|
||||
//loads the set of favorite profiles
|
||||
void loadFavorites();
|
||||
//saves the set of favorite profiles
|
||||
void saveFavorites();
|
||||
|
||||
// records which profile is set as the default profile
|
||||
// Note: it does not save the profile itself into disk. That is
|
||||
// what saveProfile() does.
|
||||
@@ -254,13 +220,11 @@ private:
|
||||
QString saveProfile(const Profile::Ptr &profile);
|
||||
|
||||
QSet<Profile::Ptr> _profiles; // list of all loaded profiles
|
||||
QSet<Profile::Ptr> _favorites; // list of favorite profiles
|
||||
|
||||
Profile::Ptr _defaultProfile;
|
||||
Profile::Ptr _fallbackProfile;
|
||||
|
||||
bool _loadedAllProfiles; // set to true after loadAllProfiles has been called
|
||||
bool _loadedFavorites; // set to true after loadFavorites has been called
|
||||
|
||||
struct ShortcutData {
|
||||
Profile::Ptr profileKey;
|
||||
|
||||
@@ -8,8 +8,13 @@
|
||||
|
||||
using namespace Konsole;
|
||||
|
||||
ProfileModel::ProfileModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
ProfileModel* ProfileModel::instance()
|
||||
{
|
||||
static ProfileModel self;
|
||||
return &self;
|
||||
}
|
||||
|
||||
ProfileModel::ProfileModel()
|
||||
{
|
||||
connect(ProfileManager::instance(), &ProfileManager::profileAdded,
|
||||
this, &ProfileModel::add);
|
||||
@@ -17,9 +22,7 @@ ProfileModel::ProfileModel(QObject *parent)
|
||||
this, &ProfileModel::remove);
|
||||
connect(ProfileManager::instance(), &ProfileManager::profileChanged,
|
||||
this, &ProfileModel::update);
|
||||
connect(ProfileManager::instance(), &ProfileManager::favoriteStatusChanged,
|
||||
this, &ProfileModel::update);
|
||||
|
||||
populate();
|
||||
}
|
||||
int ProfileModel::rowCount(const QModelIndex &unused) const
|
||||
{
|
||||
@@ -56,22 +59,8 @@ QVariant ProfileModel::data(const QModelIndex& idx, int role) const
|
||||
}
|
||||
|
||||
QExplicitlySharedDataPointer<Profile> profile = m_profiles.at(idx.row());
|
||||
const auto isEnabled = ProfileManager::instance()->findFavorites().contains(profile);
|
||||
|
||||
switch (idx.column()) {
|
||||
case VISIBILITY: {
|
||||
switch(role) {
|
||||
case Qt::ToolTipRole:
|
||||
return i18nc("@info:tooltip List item's checkbox for making item (profile) visible in a menu",
|
||||
"Show profile in menu");
|
||||
case Qt::DecorationRole:
|
||||
return QIcon::fromTheme(QStringLiteral("visibility"));
|
||||
case Qt::CheckStateRole:
|
||||
return isEnabled ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case NAME: {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole: return QStringLiteral("%1%2").arg(profile->name(), (idx.row() == 0 ? i18n("(Default)") : QString()));
|
||||
@@ -90,9 +79,7 @@ QVariant ProfileModel::data(const QModelIndex& idx, int role) const
|
||||
case SHORTCUT: {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole: return ProfileManager::instance()->shortcut(profile).toString();
|
||||
case Qt::ToolTipRole: return isEnabled
|
||||
? i18nc("@info:tooltip", "Double click to change shortcut")
|
||||
: i18nc("@info:tooltip", "Shortcut won't work while the profile is not marked as visible.");
|
||||
case Qt::ToolTipRole: return i18nc("@info:tooltip", "Double click to change shortcut");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -112,15 +99,7 @@ Qt::ItemFlags ProfileModel::flags(const QModelIndex& idx) const
|
||||
auto currentFlags = QAbstractTableModel::flags(idx);
|
||||
|
||||
switch(idx.column()) {
|
||||
case VISIBILITY : return currentFlags | Qt::ItemIsUserCheckable;
|
||||
case NAME: return currentFlags & (~Qt::ItemIsEditable);
|
||||
case SHORTCUT: {
|
||||
QExplicitlySharedDataPointer<Profile> profile = m_profiles.at(idx.row());
|
||||
const auto isEnabled = ProfileManager::instance()->findFavorites().contains(profile);
|
||||
if (!isEnabled) {
|
||||
return currentFlags & (~Qt::ItemIsEnabled);
|
||||
}
|
||||
} break;
|
||||
default: return currentFlags;
|
||||
}
|
||||
return currentFlags;
|
||||
@@ -132,7 +111,7 @@ bool ProfileModel::setData(const QModelIndex &idx, const QVariant &value, int ro
|
||||
return false;
|
||||
}
|
||||
|
||||
if (idx.row() != VISIBILITY || idx.row() != SHORTCUT) {
|
||||
if (idx.row() != SHORTCUT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -141,10 +120,7 @@ bool ProfileModel::setData(const QModelIndex &idx, const QVariant &value, int ro
|
||||
}
|
||||
|
||||
auto profile = m_profiles.at(idx.row());
|
||||
if (idx.row() == VISIBILITY) {
|
||||
profile->setHidden(value.toBool());
|
||||
emit dataChanged(idx, idx, {Qt::CheckStateRole});
|
||||
} else if (idx.row() == SHORTCUT) {
|
||||
if (idx.row() == SHORTCUT) {
|
||||
QKeySequence sequence = QKeySequence::fromString(value.toString());
|
||||
ProfileManager::instance()->setShortcut(profile, sequence);
|
||||
emit dataChanged(idx, idx, {Qt::DisplayRole});
|
||||
|
||||
@@ -11,9 +11,10 @@ class Profile;
|
||||
class ProfileModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static ProfileModel* instance();
|
||||
|
||||
enum Roles { ProfilePtrRole = Qt::UserRole + 1 };
|
||||
enum Column { VISIBILITY, NAME, SHORTCUT, PROFILE, COLUMNS };
|
||||
ProfileModel(QObject *parent);
|
||||
enum Column { NAME, SHORTCUT, PROFILE, COLUMNS };
|
||||
void populate();
|
||||
void add(QExplicitlySharedDataPointer<Profile> profile);
|
||||
void remove(QExplicitlySharedDataPointer<Profile> profile);
|
||||
@@ -27,6 +28,8 @@ public:
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
private:
|
||||
QList<QExplicitlySharedDataPointer<Profile>> m_profiles;
|
||||
ProfileModel();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ using namespace Konsole;
|
||||
|
||||
ProfileSettings::ProfileSettings(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_profileModel(new ProfileModel(this))
|
||||
, m_profileModel(ProfileModel::instance())
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
@@ -78,31 +78,12 @@ void ProfileSettings::doubleClicked(const QModelIndex &idx)
|
||||
|
||||
void ProfileSettings::populateTable()
|
||||
{
|
||||
// Calculate favorite column width. resizeColumnToContents()
|
||||
// is not used because it takes distance between checkbox and
|
||||
// text into account, but there is no text and it looks weird.
|
||||
const int headerMargin = style()->pixelMetric(QStyle::PM_HeaderMargin, nullptr,
|
||||
profilesList->header());
|
||||
const int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr,
|
||||
profilesList->header());
|
||||
const int favoriteHeaderWidth = headerMargin * 2 + iconWidth;
|
||||
QStyleOptionViewItem opt;
|
||||
opt.features = QStyleOptionViewItem::HasCheckIndicator | QStyleOptionViewItem::HasDecoration;
|
||||
|
||||
const QRect checkBoxRect = style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &opt, profilesList);
|
||||
|
||||
// When right edge is at x < 0 it is assumed the checkbox is
|
||||
// placed on the right item's side and the margin between right
|
||||
// checkbox edge and right item edge should be used.
|
||||
const int checkBoxMargin = checkBoxRect.right() >= 0 ? checkBoxRect.x()
|
||||
: 0 - checkBoxRect.right();
|
||||
const int favoriteItemWidth = checkBoxMargin * 2 + checkBoxRect.width();
|
||||
auto *listHeader = profilesList->header();
|
||||
|
||||
profilesList->setColumnWidth(ProfileModel::VISIBILITY, qMax(favoriteHeaderWidth, favoriteItemWidth));
|
||||
profilesList->resizeColumnToContents(ProfileModel::NAME);
|
||||
|
||||
listHeader->setSectionResizeMode(ProfileModel::VISIBILITY, QHeaderView::ResizeMode::Fixed);
|
||||
listHeader->setSectionResizeMode(ProfileModel::NAME, QHeaderView::ResizeMode::Stretch);
|
||||
listHeader->setSectionResizeMode(ProfileModel::SHORTCUT, QHeaderView::ResizeMode::ResizeToContents);
|
||||
listHeader->setStretchLastSection(false);
|
||||
@@ -178,7 +159,6 @@ void ProfileSettings::createProfile()
|
||||
|
||||
if (dialog.data()->exec() == QDialog::Accepted) {
|
||||
ProfileManager::instance()->addProfile(newProfile);
|
||||
ProfileManager::instance()->setFavorite(newProfile, true);
|
||||
ProfileManager::instance()->changeProfile(newProfile, newProfile->setProperties());
|
||||
}
|
||||
delete dialog.data();
|
||||
|
||||
@@ -23,16 +23,6 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Profiles marked as visible will appear in context and File menu. A shortcut for creating a new tab can be assigned to each entry. However, only shortcuts of visible profiles will work.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2" rowstretch="0,1">
|
||||
<property name="verticalSpacing">
|
||||
|
||||
Reference in New Issue
Block a user