Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 78277a8c authored by Robert Knight's avatar Robert Knight

* Change behavior of 'New Profile' button to copying the selected

(or default) profile rather than creating a new profile which inherits from it.
Profiles created previously should not be affected.  This should remove the
possible confusion arising from the previously used inheritance behavior
* Support editing and deleting of multiple profiles at once by selecting them in
the Manage Profiles dialog and clicking 'Edit Profile'/'Delete Profile'.  String
changes deferred to KDE 4.2
* Fix memory leak and selection loss in Manage Profiles dialog when profiles
are added/removed/changed

BUG: 162461

Squashed commit of the following:

commit c6c482f76c840dfa34c36c2eee32f5e2aed499e7
Author: Robert Knight <robertknight@gmail.com>
Date:   Thu Jun 26 00:45:20 2008 +0100

    Avoid the selection being cleared when profiles are added/removed/changed in ManageProfilesDialog.  Finish addition/update/removal of items when profileAdded()/profileRemoved()/profileChanged() signals are emitted by the SessionManager.

commit 0125653d41738768d074bcd3c6445dd98eefa619
Author: Robert Knight <robertknight@gmail.com>
Date:   Wed Jun 25 11:21:44 2008 +0100

    Set model in ManageProfilesDialog setup rather than ManageProfilesDialog::updateTableModel()

commit 32704ba0bf076ec3c305515e350c016a7bdaf2f3
Author: Robert Knight <robertknight@gmail.com>
Date:   Sun Jun 22 19:42:33 2008 +0100

    Avoid creating a new QStandardItemModel on every profile table update.  Refactor creation/update of items for profiles.

commit dcd9eb9e91d64525359561cca2f8f6f54a35a2de
Author: Robert Knight <robertknight@gmail.com>
Date:   Fri Jun 13 19:52:33 2008 +0100

    * Disable previewing of a property when editing multiple profiles
    where the profiles have conflicting original values for the property
    * Change EditProfileDialog::_profileKey to EditProfileDialog::_profile

commit 020ef2d5f090a1cc2b1814c4d429051cb3cf98bc
Author: Robert Knight <robertknight@gmail.com>
Date:   Fri Jun 13 19:28:31 2008 +0100

    Add stub functions for SessionManagerTest

commit 655b0e6fa8e8891874ca5aa7bee6f81f3d76d065
Author: Robert Knight <robertknight@gmail.com>
Date:   Fri Jun 13 19:27:03 2008 +0100

    Include KDE 3 profiles when displaying available profiles
    via "konsole --list-profiles"

    Re-use SessionManager::availableProfilePaths() to get the list
    of all profiles to load in SessionManager::loadAllProfiles()

commit 93c02e6312c8a38d89a137c7260183dcf86946fa
Author: Robert Knight <robertknight@gmail.com>
Date:   Wed Jun 11 04:02:26 2008 +0100

    Export SessionManager class for testing.

commit a35eaba16cad3a3301a4636d032d789df669df9e
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 22:34:33 2008 +0100

    Add SessionManager test stub

commit 347dadcd1c50157eb264bbb17423003a658bd8f5
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 22:17:43 2008 +0100

    Display profile names in 'Name' field when editing multiple profiles.

commit 4d8e895fd9c95dbd954e224edcbcd68c24429bad
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 22:06:49 2008 +0100

    Add test for Profile::asGroup()

commit 527535f7786d5c7744436012dbbd889348cec6a1
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 21:58:15 2008 +0100

    Limit length of dialog caption when editing many profiles.

commit eb6e199e6e130b7b33ff97f124162dbb2107bba1
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 21:50:53 2008 +0100

    Re-insert accidentally removed if() condition to check that deleted profile is not the default.

commit e11d4d7dac1ae1df4c401a04e8497521f240d8f0
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 20:32:01 2008 +0100

    ManageProfilesDialog formatting tidy-up.

commit 69dd69a9aa8df9dfa4f1473e53b99e17898c8549
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 18:57:40 2008 +0100

    When updating a profile group via SessionManager::changeProfile(), update the group's properties before calling changeProfile() on the group's members.  Otherwise the profile group's property values will be out of sync with those of the member profiles.

commit d74de728f0c19ca9786f2429fbd819938eaabe3e
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 18:56:04 2008 +0100

    Add updated Profile.h missing from previous commit.

commit 67f6ec24f6871a931d3b80cc11313a1c0c8fd240
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 18:54:06 2008 +0100

    Make profile groups hidden by default.

commit f4653c6953b356107ab347f173e8d04296abcbac
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 18:41:49 2008 +0100

    When modifying a profile group with SessionManager::changeProfile(), iterate through the group's profiles and call changeProfile() on each of them.  Otherwise the profiles in the group are not saved to disk when they are updated.

commit cc3c14e3c2d43f75591396b154e6b6f4b430d9a9
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 18:35:24 2008 +0100

    Add Profile::asGroup() convenience methods which return the profile dynamically cast to a Profile group.

commit e2db97ee0bcb4bb3f4a8d7356846c37a04708c88
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 03:43:20 2008 +0100

    Make profile group hidden, prevents creation of nameless '.profile' file on disk.

commit 872113584bce97ae739a7ba46d02ee2d63f2990d
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 03:22:45 2008 +0100

    Clear corresponding shortcuts when deleting a profile.

commit 0c9353ffde887ac408d87c258587d84cfa2a4d6f
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 03:08:47 2008 +0100

    KDE4ProfileReader - Check that profile exists before trying to load it with KConfig

commit af7caa25931684da0d8f0f495d5acab8e6de1b41
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 02:57:50 2008 +0100

    Fix enabling/disabling of buttons in ManageProfilesDialog when number of selected rows changes.

commit d98184d6684cd9a58a702ab2b23bfa0105f25a0f
Author: Robert Knight <robertknight@gmail.com>
Date:   Sat May 31 02:44:51 2008 +0100

    Add a test for Profile::clone()

commit b536355cde13523f12ed927b9a5e64b63954f21c
Author: Robert Knight <robertknight@gmail.com>
Date:   Fri May 30 02:58:03 2008 +0100

    Implement testProfile(), testProfileGroup().  Export Profile class for use in tests.

commit 8458de3fffe3755cd5ba9ebdda5795a422cfcb5f
Author: Robert Knight <robertknight@gmail.com>
Date:   Fri May 30 02:01:42 2008 +0100

    Tidy up Profile docs.

commit 6ed40ae0adc6128057b7d1c71c4bbb1259768102
Author: Robert Knight <robertknight@gmail.com>
Date:   Fri May 30 01:53:02 2008 +0100

    Push ProfileGroup::isPropertyValueUnique() up to Profile::canInheritProperty()

commit b992e0268c1708814a5843b13e321b9b4a86c05a
Author: Robert Knight <robertknight@gmail.com>
Date:   Fri May 30 00:30:45 2008 +0100

    Add Profile test stub.

commit 7c7b63e50a2bb7bcd7a26d895e77860b6a5effde
Author: Robert Knight <robertknight@gmail.com>
Date:   Thu May 29 06:12:52 2008 +0100

    Document ProfileGroup

commit 838a628dd395bdaf6ae04fb027b1efcccbbe9f32
Author: Robert Knight <robertknight@gmail.com>
Date:   Thu May 29 01:26:48 2008 +0100

    Remove unused and incorrect Profile::terminal()

commit 87e1ad1174ffa8fd1bafe37b4d52c9782708c9ea
Author: Robert Knight <robertknight@gmail.com>
Date:   Thu May 29 01:23:52 2008 +0100

    Remove unused kDebug() statements.

commit 56c78128f083ef846308a09038251786677dd087
Author: Robert Knight <robertknight@gmail.com>
Date:   Thu May 29 01:22:41 2008 +0100

    Profile documentation corrections.

commit 965803c401692720c57a65bf1534f774e1b99365
Author: Robert Knight <robertknight@gmail.com>
Date:   Thu May 29 01:10:23 2008 +0100

    Document SessionManager::fallbackProfile()

commit a222673b15f6e8c8bb53e95046ee786369deb127
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 20:49:12 2008 +0100

    Disable 'New Profile' and 'Set as Default' buttons when multiple profiles are selected.  Remove incorrect comment about QAbstractItemView signals.  selectionChanged() is a slot not a signal.

commit e5e9db39487595d92fe2e7d3fa16cca731c417ec
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 20:19:18 2008 +0100

    Change the way new profiles are created.  Instead of creating an almost-empty profile which inherits from the selected profile, create a new profile which inherits from the fallback profile and then clone the properties of the currently selected profile into the new profile.

commit f56cc534b2ebd691c6b3449e982c74c7e564a35a
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 20:18:14 2008 +0100

    Expose the hard-coded fallback profile in the SessionManager

commit b00327479d222be60484bd781a131598f2c2482f
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 20:17:35 2008 +0100

    Add method Profile::clone() to copy an existing profile, optionally copying all properties or just those differing from the current values.

commit 951620449c3a621d38f6607c0ea44e2a1a0ac087
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 19:24:49 2008 +0100

    Treat a ProfileGroup with only one profile the same as a standard Profile in EditProfileDialog.

commit ecdf120b67a6b14a871cd808654fe6653bb56aeb
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 19:24:08 2008 +0100

    Make ProfileGroup instances with only one profile behave the same as a standard Profile with respect to 'unique' properties such as Name and Path.

commit f72040f310946f92eff318c52da706fce00fa17e
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 19:14:27 2008 +0100

    Fix double-deletion of profile group.

commit 1523239e9cbde518eb89fc70e6711463a7f7bb2a
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 18:57:17 2008 +0100

    Only look at indexes in column 0 when retrieving the selected profiles.

commit 5706a8ee16bc1b87777563023e4ddf5253815c48
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 18:52:47 2008 +0100

    Move to next property when skipping a 'unique' property.

commit 803eef6767620dd7a6e9b87cc97f1c110dfa66a6
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 18:49:20 2008 +0100

    Modify Edit/Delete actions in ManageProfilesDialog to allow editing/deleting of multiple profiles.

commit eec6947620d51b2a41ed74a03e1a7b695d0ee811
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 18:48:36 2008 +0100

    Modify EditProfileDialog to show a different caption depending on whether the passed in profile is a single profile or a group of profiles.  Disable the profile name edit and label when editing a group of profiles.

commit 13ee83b2bb888da4009bee0cb25926fc02f34701
Author: Robert Knight <robertknight@gmail.com>
Date:   Mon May 26 18:47:22 2008 +0100

    Add ProfileGroup class which provides a composite allowing multiple profiles to be treated as one.

commit 1310a4ee66e6ba9eb91f1a0dfd79c5415c3a9f4f
Author: Robert Knight <robertknight@gmail.com>
Date:   Sun May 25 00:07:47 2008 +0100

    Undo string changes in Manage Profiles dialog so that this branch can be merged before 4.1

commit edc46b4085d61d1cc14a47c429aac5fc9f52a59f
Author: Robert Knight <robertknight@gmail.com>
Date:   Fri May 23 18:34:09 2008 +0100

    Change 'New Profile' button to 'Copy Profile' to clarify how it works.  Change 'Edit Profile' to 'Edit' and 'Delete Profile' to 'Delete' to clarify that they can work on more than one profile.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=824515
parent a9b8d756
......@@ -100,7 +100,7 @@ void EditProfileDialog::save()
if ( _tempProfile->isEmpty() )
return;
SessionManager::instance()->changeProfile(_profileKey,_tempProfile->setProperties());
SessionManager::instance()->changeProfile(_profile,_tempProfile->setProperties());
// ensure that these settings are not undone by a call
// to unpreview()
......@@ -122,18 +122,48 @@ void EditProfileDialog::accept()
unpreviewAll();
KDialog::accept();
}
void EditProfileDialog::updateCaption(const QString& profileName)
QString EditProfileDialog::groupProfileNames(const ProfileGroup::Ptr group, int maxLength)
{
setCaption( i18n("Edit Profile \"%1\"",profileName) );
QString caption;
int count = group->profiles().count();
for (int i=0;i < count;i++)
{
caption += group->profiles()[i]->name();
if (i < (count-1))
{
caption += ',';
// limit caption length to prevent very long window titles
if (maxLength > 0 && caption.length() > maxLength)
{
caption += "...";
break;
}
}
}
return caption;
}
void EditProfileDialog::updateCaption(const Profile::Ptr profile)
{
const int MAX_GROUP_CAPTION_LENGTH = 25;
ProfileGroup::Ptr group = profile->asGroup();
if (group && group->profiles().count() > 1)
{
QString caption = groupProfileNames(group,MAX_GROUP_CAPTION_LENGTH);
setCaption( i18n("Edit Profile \"%1\"",caption) );
// STRINGFREEZE - Change caption for groups after KDE 4.1 is released
// setCaption( i18n("Editing %1 profiles",group->profiles().count()) )
}
else
setCaption( i18n("Edit Profile \"%1\"",profile->name()) );
}
void EditProfileDialog::setProfile(Profile::Ptr profile)
{
_profileKey = profile;
_profile = profile;
Q_ASSERT( profile );
// update caption
updateCaption(profile->name());
updateCaption(profile);
// mark each page of the dialog as out of date
// and force an update of the currently visible page
......@@ -149,7 +179,7 @@ void EditProfileDialog::setProfile(Profile::Ptr profile)
}
const Profile::Ptr EditProfileDialog::lookupProfile() const
{
return _profileKey;
return _profile;
}
void EditProfileDialog::preparePage(int page)
{
......@@ -191,9 +221,18 @@ void EditProfileDialog::selectProfileName()
}
void EditProfileDialog::setupGeneralPage(const Profile::Ptr info)
{
// basic profile options
_ui->profileNameEdit->setText( info->name() );
{
ProfileGroup::Ptr group = info->asGroup();
if (!group || group->profiles().count() < 2)
_ui->profileNameEdit->setText( info->name() );
else
{
_ui->profileNameEdit->setText( groupProfileNames(group,-1) );
_ui->profileNameLabel->setEnabled(false);
_ui->profileNameEdit->setEnabled(false);
}
}
ShellCommand command( info->command() , info->arguments() );
_ui->commandEdit->setText( command.fullCommand() );
......@@ -352,7 +391,7 @@ void EditProfileDialog::selectIcon()
void EditProfileDialog::profileNameChanged(const QString& text)
{
_tempProfile->setProperty(Profile::Name,text);
updateCaption(_tempProfile->name());
updateCaption(_tempProfile);
}
void EditProfileDialog::startInSameDir(bool sameDir)
{
......@@ -576,7 +615,7 @@ void EditProfileDialog::unpreviewAll()
// undo any preview changes
if ( !map.isEmpty() )
SessionManager::instance()->changeProfile(_profileKey,map,false);
SessionManager::instance()->changeProfile(_profile,map,false);
}
void EditProfileDialog::unpreview(int property)
{
......@@ -587,7 +626,7 @@ void EditProfileDialog::unpreview(int property)
QHash<Profile::Property,QVariant> map;
map.insert((Profile::Property)property,_previewedProperties[property]);
SessionManager::instance()->changeProfile(_profileKey,map,false);
SessionManager::instance()->changeProfile(_profile,map,false);
_previewedProperties.remove(property);
}
......@@ -618,11 +657,22 @@ void EditProfileDialog::preview(int property , const QVariant& value)
const Profile::Ptr original = lookupProfile();
if (!_previewedProperties.contains(property))
// skip previews for profile groups if the profiles in the group
// have conflicting original values for the property
//
// TODO - Save the original values for each profile and use to unpreview properties
ProfileGroup::Ptr group = original->asGroup();
if (group && group->profiles().count() > 1 &&
original->property<QVariant>((Profile::Property)property).isNull())
return;
if (!_previewedProperties.contains(property))
{
_previewedProperties.insert(property , original->property<QVariant>((Profile::Property)property) );
}
// temporary change to color scheme
SessionManager::instance()->changeProfile( _profileKey , map , false);
SessionManager::instance()->changeProfile( _profile , map , false);
}
void EditProfileDialog::previewColorScheme(const QModelIndex& index)
{
......
......@@ -197,9 +197,11 @@ private:
void unpreviewAll();
void enableIfNonEmptySelection(QWidget* widget,QItemSelectionModel* selectionModel);
void updateCaption(const QString& profileName);
void updateCaption(const Profile::Ptr profile);
void updateTransparencyWarning();
static QString groupProfileNames(const ProfileGroup::Ptr group, int maxLength = -1);
struct RadioOption
{
QAbstractButton* button;
......@@ -219,7 +221,7 @@ private:
Ui::EditProfileDialog* _ui;
Profile::Ptr _tempProfile;
Profile::Ptr _profileKey;
Profile::Ptr _profile;
// keeps track of pages which need to be updated to match the current
// profile. all elements in this vector are set to true when the
......
This diff is collapsed.
......@@ -86,21 +86,29 @@ private slots:
// selection changes
void tableSelectionChanged(const QItemSelection&);
// updates the profile table to be in sync with the
// session manager
void updateTableModel();
void updateFavoriteStatus(Profile::Ptr profile, bool favorite);
void addItems(const Profile::Ptr);
void updateItems(const Profile::Ptr);
void removeItems(const Profile::Ptr);
private:
Profile::Ptr selectedKey() const; // return the profile associated with the currently selected
// item in the profile table
Profile::Ptr currentProfile() const;
QList<Profile::Ptr> selectedProfiles() const;
// updates the font of the items to match
// their default / non-default profile status
void updateDefaultItem();
void updateItemsForProfile(const Profile::Ptr profile, QList<QStandardItem*>& items) const;
// updates the profile table to be in sync with the
// session manager
void populateTable();
int rowForProfile(const Profile::Ptr info) const;
void updateDefaultItem(); // updates the font of the items to match
// their default / non-default profile status
Ui::ManageProfilesDialog* _ui;
QStandardItemModel* _sessionModel;
static const int ProfileNameColumn = 0;
static const int FavoriteStatusColumn = 1;
static const int ShortcutColumn = 2;
static const int ProfileKeyRole = Qt::UserRole + 1;
......
......@@ -38,7 +38,7 @@
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Edit the selected profile</string>
<string>Edit the selected profile(s)</string>
</property>
<property name="text" >
<string>Edit Profile...</string>
......@@ -51,7 +51,7 @@
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Delete the selected profile</string>
<string>Delete the selected profile(s)</string>
</property>
<property name="text" >
<string>Delete Profile</string>
......@@ -93,7 +93,7 @@
<bool>true</bool>
</property>
<property name="selectionMode" >
<enum>QAbstractItemView::SingleSelection</enum>
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior" >
<enum>QAbstractItemView::SelectRows</enum>
......
......@@ -141,6 +141,9 @@ FallbackProfile::FallbackProfile()
{
// Fallback settings
setProperty(Name,i18n("Shell"));
// magic path for the fallback profile which is not a valid
// non-directory file name
setProperty(Path,"FALLBACK/");
setProperty(Command,getenv("SHELL"));
setProperty(Icon,"utilities-terminal");
setProperty(Arguments,QStringList() << getenv("SHELL"));
......@@ -180,12 +183,34 @@ FallbackProfile::FallbackProfile()
// Fallback should not be shown in menus
setHidden(true);
}
Profile::Profile(Profile::Ptr parent)
: _parent(parent)
,_hidden(false)
{
}
void Profile::clone(Profile::Ptr profile, bool differentOnly)
{
const PropertyInfo* properties = DefaultPropertyNames;
while (properties->name != 0)
{
Property current = properties->property;
QVariant otherValue = profile->property<QVariant>(current);
switch (current)
{
case Name:
case Path:
break;
default:
if (!differentOnly ||
property<QVariant>(current) !=
otherValue)
{
setProperty(current,otherValue);
}
}
properties++;
}
}
Profile::~Profile()
{
}
......@@ -352,6 +377,9 @@ void KDE4ProfileReader::readProperties(const KConfig& config, Profile::Ptr profi
bool KDE4ProfileReader::readProfile(const QString& path , Profile::Ptr profile , QString& parentProfile)
{
if (!QFile::exists(path))
return false;
KConfig config(path,KConfig::NoGlobals);
KConfigGroup general = config.group(GENERAL_GROUP);
......@@ -463,4 +491,48 @@ QHash<Profile::Property,QVariant> ProfileCommandParser::parse(const QString& inp
return changes;
}
void ProfileGroup::updateValues()
{
const PropertyInfo* properties = Profile::DefaultPropertyNames;
while (properties->name != 0)
{
// the profile group does not store a value for some properties
// (eg. name, path) if even they are equal between profiles -
//
// the exception is when the group has only one profile in which
// case it behaves like a standard Profile
if (_profiles.count() > 1 &&
!canInheritProperty(properties->property))
{
properties++;
continue;
}
QVariant value;
for (int i=0;i<_profiles.count();i++)
{
QVariant profileValue = _profiles[i]->property<QVariant>(properties->property);
if (value.isNull())
value = profileValue;
else if (value != profileValue)
{
value = QVariant();
break;
}
}
Profile::setProperty(properties->property,value);
properties++;
}
}
void ProfileGroup::setProperty(Property property, const QVariant& value)
{
if (_profiles.count() > 1 && !canInheritProperty(property))
return;
Profile::setProperty(property,value);
foreach(Profile::Ptr profile,_profiles)
profile->setProperty(property,value);
}
This diff is collapsed.
......@@ -78,7 +78,8 @@ SessionManager::SessionManager()
SLOT(sessionTerminated(QObject*)) );
//load fallback profile
addProfile( Profile::Ptr(new FallbackProfile) );
_fallbackProfile = Profile::Ptr(new FallbackProfile);
addProfile(_fallbackProfile);
//locate and load default profile
KSharedConfigPtr appConfig = KGlobal::config();
......@@ -103,6 +104,10 @@ SessionManager::SessionManager()
}
Profile::Ptr SessionManager::loadProfile(const QString& shortPath)
{
// the fallback profile has a 'special' path name, "FALLBACK/"
if (shortPath == _fallbackProfile->property<QString>(Profile::Path))
return _fallbackProfile;
QString path = shortPath;
// add a suggested suffix and relative prefix if missing
......@@ -177,11 +182,16 @@ Profile::Ptr SessionManager::loadProfile(const QString& shortPath)
return newProfile;
}
}
QList<QString> SessionManager::availableProfilePaths() const
QStringList SessionManager::availableProfilePaths() const
{
KDE4ProfileReader reader;
KDE3ProfileReader kde3Reader;
KDE4ProfileReader kde4Reader;
return reader.findProfiles();
QStringList profiles;
profiles += kde3Reader.findProfiles();
profiles += kde4Reader.findProfiles();
return profiles;
}
void SessionManager::loadAllProfiles()
......@@ -189,12 +199,7 @@ void SessionManager::loadAllProfiles()
if ( _loadedAllProfiles )
return;
KDE3ProfileReader kde3Reader;
KDE4ProfileReader kde4Reader;
QStringList profiles;
profiles += kde3Reader.findProfiles();
profiles += kde4Reader.findProfiles();
QStringList profiles = availableProfilePaths();
QListIterator<QString> iter(profiles);
while (iter.hasNext())
......@@ -302,6 +307,8 @@ Profile::Ptr SessionManager::defaultProfile() const
{
return _defaultProfile;
}
Profile::Ptr SessionManager::fallbackProfile() const
{ return _fallbackProfile; }
QString SessionManager::saveProfile(Profile::Ptr info)
{
......@@ -329,6 +336,20 @@ void SessionManager::changeProfile(Profile::Ptr info ,
info->setProperty(property,propertyMap[property]);
}
// when changing a group, iterate through the profiles
// in the group and call changeProfile() on each of them
//
// this is so that each profile in the group, the profile is
// applied, a change notification is emitted and the profile
// is saved to disk
ProfileGroup::Ptr group = info->asGroup();
if (group)
{
foreach(Profile::Ptr profile, group->profiles())
changeProfile(profile,propertyMap,persistant);
return;
}
// apply the changes to existing sessions
applyProfile(info,true);
......@@ -468,7 +489,9 @@ bool SessionManager::deleteProfile(Profile::Ptr type)
}
}
// remove from favorites, profile list, shortcut list etc.
setFavorite(type,false);
setShortcut(type,QKeySequence());
_types.remove(type);
// mark the profile as hidden so that it does not show up in the
......@@ -571,6 +594,9 @@ void SessionManager::setShortcut(Profile::Ptr info ,
QKeySequence existingShortcut = shortcut(info);
_shortcuts.remove(existingShortcut);
if (keySequence.isEmpty())
return;
ShortcutData data;
data.profileKey = info;
data.profilePath = info->path();
......@@ -653,6 +679,11 @@ Profile::Ptr SessionManager::findByShortcut(const QKeySequence& shortcut)
if ( !_shortcuts[shortcut].profileKey )
{
Profile::Ptr key = loadProfile(_shortcuts[shortcut].profilePath);
if (!key)
{
_shortcuts.remove(shortcut);
return Profile::Ptr();
}
_shortcuts[shortcut].profileKey = key;
}
......
......@@ -56,7 +56,7 @@ class Session;
* how to display them. The favorite status of a profile can be altered using
* setFavorite() and retrieved using isFavorite()
*/
class SessionManager : public QObject
class KDE_EXPORT SessionManager : public QObject
{
Q_OBJECT
......@@ -95,7 +95,7 @@ public:
* Searches for available profiles on-disk and returns a list
* of paths of profiles which can be loaded.
*/
QList<QString> availableProfilePaths() const;
QStringList availableProfilePaths() const;
/**
......@@ -134,6 +134,12 @@ public:
* if createSession() is called with an empty configPath argument.
*/
Profile::Ptr defaultProfile() const;
/**
* Returns a Profile object with hard-coded settings which is always available.
* This can be used as a parent for new profiles which provides suitable default settings
* for all properties.
*/
Profile::Ptr fallbackProfile() const;
/**
* Creates a new session using the settings specified by the specified
......@@ -323,7 +329,8 @@ private:
QList<Session*> _sessions; // list of running sessions
Profile::Ptr _defaultProfile;
Profile::Ptr _fallbackProfile;
QSet<Profile::Ptr> _favorites; // list of favorite profiles
bool _loadedAllProfiles; // set to true after loadAllProfiles has been called
......
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
include_directories( ${KDE4_KPTY_INCLUDES} ${KDE4_KPARTS_INCLUDES} ${QT_QTTEST_INCLUDES})
set(KONSOLE_TEST_LIBS ${QT_QTTEST_LIBRARY} kdeinit_konsole)
kde4_add_executable(PartTest TEST PartTest.cpp)
target_link_libraries(PartTest ${KDE4_KPARTS_LIBS} ${KDE4_KPTY_LIBS} ${QT_QTTEST_LIBRARY} kdeinit_konsole)
target_link_libraries(PartTest ${KDE4_KPARTS_LIBS} ${KDE4_KPTY_LIBS} ${KONSOLE_TEST_LIBS})
kde4_add_unit_test(ProfileTest ProfileTest.cpp)
target_link_libraries(ProfileTest ${KONSOLE_TEST_LIBS})
kde4_add_unit_test(SessionManagerTest SessionManagerTest.cpp)
target_link_libraries(SessionManagerTest ${KONSOLE_TEST_LIBS})
/*
Copyright 2008 by Robert Knight <robertknight@gmail.com>
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 2 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
// Own
#include "ProfileTest.h"
// KDE
#include <qtest_kde.h>
// Konsole
#include "../Profile.h"
using namespace Konsole;
void ProfileTest::testProfile()
{
// create a new profile
Profile* parent = new Profile;
parent->setProperty(Profile::Name, "Parent");
parent->setProperty(Profile::Path, "FakePath");
parent->setProperty(Profile::AntiAliasFonts,false);
parent->setProperty(Profile::StartInCurrentSessionDir,false);
// create a child profile
Profile* child = new Profile(Profile::Ptr(parent));
child->setProperty(Profile::StartInCurrentSessionDir,true);
// check which properties are set
QVERIFY(parent->isPropertySet(Profile::Name));
QVERIFY(parent->isPropertySet(Profile::Path));
QVERIFY(parent->isPropertySet(Profile::AntiAliasFonts));
QVERIFY(!parent->isPropertySet(Profile::Icon));
QVERIFY(!parent->isPropertySet(Profile::Command));
QVERIFY(!parent->isPropertySet(Profile::Arguments));
QVERIFY(child->isPropertySet(Profile::StartInCurrentSessionDir));
QVERIFY(!child->isPropertySet(Profile::Name));
QVERIFY(!child->isPropertySet(Profile::AntiAliasFonts));
QVERIFY(!child->isPropertySet(Profile::ColorScheme));
// read non-inheritable properties
QCOMPARE(parent->property<QString>(Profile::Name),QString("Parent"));
QCOMPARE(child->property<QVariant>(Profile::Name),QVariant());
QCOMPARE(parent->property<QString>(Profile::Path),QString("FakePath"));
QCOMPARE(child->property<QVariant>(Profile::Path),QVariant());
// read inheritable properties
QVERIFY(parent->property<bool>(Profile::AntiAliasFonts) == false);
QVERIFY(child->property<bool>(Profile::AntiAliasFonts) == false);
QVERIFY(parent->property<bool>(Profile::StartInCurrentSessionDir) == false);
QVERIFY(child->property<bool>(Profile::StartInCurrentSessionDir) == true);
delete child;
}
void ProfileTest::testClone()
{
// create source profile and parent
Profile::Ptr parent(new Profile);
parent->setProperty(Profile::Command,"ps");
parent->setProperty(Profile::ColorScheme,"BlackOnWhite");
Profile::Ptr source(new Profile(parent));
source->setProperty(Profile::AntiAliasFonts,false);
source->setProperty(Profile::HistorySize,4567);
source->setProperty(Profile::Name,"SourceProfile");
source->setProperty(Profile::Path,"SourcePath");
// create target to clone source and parent
Profile::Ptr targetParent(new Profile);
// same value as source parent
targetParent->setProperty(Profile::Command,"ps");
// different value from source parent
targetParent->setProperty(Profile::ColorScheme,"BlackOnGrey");
Profile::Ptr target(new Profile(parent));
// clone source profile, setting only properties that differ
// between the source and target
target->clone(source,true);
// check that properties from source have been cloned into target
QCOMPARE(source->property<bool>(Profile::AntiAliasFonts),
target->property<bool>(Profile::AntiAliasFonts));
QCOMPARE(source->property<int>(Profile::HistorySize),
target->property<int>(Profile::HistorySize));
// check that Name and Path properties are handled specially and not cloned
QVERIFY(source->property<QString>(Profile::Name) !=
target->property<QString>(Profile::Name));
QVERIFY(source->property<QString>(Profile::Path) !=
target->property<QString>(Profile::Path));
// check that Command property is not set in target because the values
// are the same
QVERIFY(!target->isPropertySet(Profile::Command));
// check that ColorScheme property is cloned because the inherited values
// from the source parent and target parent differ
QCOMPARE(source->property<QString>(Profile::ColorScheme),
target->property<QString>(Profile::ColorScheme));
}
void ProfileTest::testProfileGroup()
{
// create three new profiles
Profile::Ptr profile[3];
for (int i=0;i<3;i++)
{
profile[i] = new Profile;
QVERIFY(!profile[i]->asGroup());
}
// set properties with different values
profile[0]->setProperty(Profile::UseCustomCursorColor,true);
profile[1]->setProperty(Profile::UseCustomCursorColor,false);
// set properties with same values
for (int i=0;i<3;i++)
profile[i]->setProperty(Profile::HistorySize,1234);
// create a group profile
ProfileGroup::Ptr group = ProfileGroup::Ptr(new ProfileGroup);
QVERIFY(group->asGroup());
for (int i=0;i<3;i++)
{
group->addProfile(profile[i]);
QVERIFY(group->profiles().contains(profile[i]));
}
group->updateValues();
// read and check properties from the group
QCOMPARE(group->property<int>(Profile::HistorySize),1234);
QCOMPARE(group->property<QVariant>(Profile::UseCustomCursorColor),QVariant());
// set and test shareable properties in the group
group->setProperty(Profile::Command,"ssh");
group->setProperty(Profile::AntiAliasFonts,false);
QCOMPARE(profile[0]->property<QString>(Profile::Command),QString("ssh"));
QVERIFY(profile[1]->property<bool>(Profile::AntiAliasFonts) == false);
// set and test non-sharable properties in the group
// (should have no effect)
group->setProperty(Profile::Name,"NewName");
group->setProperty(Profile::Path,"NewPath");
QVERIFY(profile[1]->property<QString>(Profile::Name) != "NewName");
QVERIFY(profile[2]->property<QString>(Profile::Path) != "NewPath");
// remove a profile from the group
group->removeProfile(profile[0]);
QVERIFY(!group->profiles().contains(profile[0]));
group->updateValues();
// check that profile is no longer affected by group
group->setProperty(Profile::Command,"fish");
QVERIFY(profile[0]->property<QString>(Profile::Command)