Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Konsole
Commits
87e25c62
Commit
87e25c62
authored
Sep 23, 2022
by
Jose Flores
Committed by
Kurt Hindenburg
Sep 30, 2022
Browse files
Checks if a profile is editable before showing the edit profile menu action
parent
7c508753
Pipeline
#238742
passed with stage
in 5 minutes and 43 seconds
Changes
5
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/profile/Profile.cpp
View file @
87e25c62
...
...
@@ -11,6 +11,7 @@
#include
"Profile.h"
// Qt
#include
<QFileInfo>
#include
<QTextCodec>
// KDE
...
...
@@ -250,6 +251,20 @@ bool Profile::isBuiltin() const
return
path
()
==
BUILTIN_MAGIC_PATH
;
}
bool
Profile
::
isEditable
()
const
{
// Read-only profiles (i.e. with non-user-writable .profile location)
// aren't editable. This includes the built-in profile, which is hardcoded.
return
!
isBuiltin
()
&&
QFileInfo
(
path
()).
isWritable
();
}
bool
Profile
::
isDeletable
()
const
{
// To delete a file, parent dir must be writable
const
QFileInfo
fileInfo
(
path
());
return
!
isBuiltin
()
&&
fileInfo
.
exists
()
&&
QFileInfo
(
fileInfo
.
path
()).
isWritable
();
}
bool
Profile
::
isHidden
()
const
{
return
_hidden
;
...
...
src/profile/Profile.h
View file @
87e25c62
...
...
@@ -474,6 +474,16 @@ public:
*/
bool
isBuiltin
()
const
;
/**
* Returns true if this profile is editable.
*/
bool
isEditable
()
const
;
/**
* Returns true if this profile can be deleted.
*/
bool
isDeletable
()
const
;
/**
* Returns true if this is a 'hidden' profile which should not be
* displayed in menus or saved to disk.
...
...
src/session/SessionController.cpp
View file @
87e25c62
...
...
@@ -946,7 +946,7 @@ void SessionController::switchProfile(const Profile::Ptr &profile)
void
SessionController
::
setEditProfileActionText
(
const
Profile
::
Ptr
&
profile
)
{
QAction
*
action
=
actionCollection
()
->
action
(
QStringLiteral
(
"edit-current-profile"
));
if
(
profile
->
is
Builtin
())
{
if
(
!
profile
->
is
Editable
())
{
action
->
setText
(
i18n
(
"Create New Profile..."
));
}
else
{
action
->
setText
(
i18n
(
"Edit Current Profile..."
));
...
...
@@ -981,8 +981,8 @@ void SessionController::editCurrentProfile()
auto
profile
=
SessionManager
::
instance
()
->
sessionProfile
(
session
());
auto
state
=
EditProfileDialog
::
ExistingProfile
;
// Don't edit
the built-in
profile, instead create a new one
if
(
profile
->
is
Builtin
())
{
// Don't edit
uneditable
profile
s
, instead create a new one
if
(
!
profile
->
is
Editable
())
{
auto
newProfile
=
Profile
::
Ptr
(
new
Profile
(
profile
));
newProfile
->
clone
(
profile
,
true
);
const
QString
uniqueName
=
ProfileManager
::
instance
()
->
generateUniqueName
();
...
...
src/settings/ProfileSettings.cpp
View file @
87e25c62
...
...
@@ -101,11 +101,10 @@ void ProfileSettings::tableSelectionChanged(const QItemSelection &selected)
const
auto
profile
=
currentProfile
();
const
bool
isNotDefault
=
profile
!=
ProfileManager
::
instance
()
->
defaultProfile
();
// See comment about isProfileWritable(profile) in editSelected()
editProfileButton
->
setEnabled
(
isProfileWritable
(
profile
));
editProfileButton
->
setEnabled
(
profile
&&
profile
->
isEditable
());
// Do not allow the current default profile of the session to be removed
deleteProfileButton
->
setEnabled
(
isNotDefault
&&
isP
rofileDeletable
(
profile
));
deleteProfileButton
->
setEnabled
(
profile
&&
isNotDefault
&&
p
rofile
->
is
Deletable
());
setAsDefaultButton
->
setEnabled
(
isNotDefault
);
}
...
...
@@ -154,10 +153,8 @@ void ProfileSettings::editSelected()
{
const
auto
profile
=
currentProfile
();
// Read-only profiles (i.e. with non-user-writable .profile location)
// aren't editable, and can only be cloned using the "New" button.
// This includes the built-in profile, which is hardcoded.
if
(
!
isProfileWritable
(
profile
))
{
// Uneditable profiles can only be cloned using the "New" button.
if
(
!
(
profile
&&
profile
->
isEditable
()))
{
return
;
}
...
...
@@ -178,19 +175,3 @@ Profile::Ptr ProfileSettings::currentProfile() const
return
selection
->
selectedIndexes
().
at
(
ProfileModel
::
PROFILE
).
data
(
ProfileModel
::
ProfilePtrRole
).
value
<
Profile
::
Ptr
>
();
}
bool
ProfileSettings
::
isProfileDeletable
(
Profile
::
Ptr
profile
)
const
{
if
(
!
profile
||
profile
->
isBuiltin
())
{
return
false
;
}
const
QFileInfo
fileInfo
(
profile
->
path
());
return
fileInfo
.
exists
()
&&
QFileInfo
(
fileInfo
.
path
()).
isWritable
();
// To delete a file, parent dir must be writable
}
bool
ProfileSettings
::
isProfileWritable
(
Profile
::
Ptr
profile
)
const
{
return
profile
&&
!
profile
->
isBuiltin
()
// Built-in profile is hardcoded and never stored.
&&
QFileInfo
(
profile
->
path
()).
isWritable
();
}
src/settings/ProfileSettings.h
View file @
87e25c62
...
...
@@ -59,9 +59,6 @@ private Q_SLOTS:
private:
QExplicitlySharedDataPointer
<
Profile
>
currentProfile
()
const
;
bool
isProfileDeletable
(
QExplicitlySharedDataPointer
<
Profile
>
profile
)
const
;
bool
isProfileWritable
(
QExplicitlySharedDataPointer
<
Profile
>
profile
)
const
;
// updates the profile table to be in sync with the
// session manager
void
populateTable
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment