diff --git a/src/Application.cpp b/src/Application.cpp index 43517bece..d76e91c67 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -81,10 +81,10 @@ MainWindow* Application::newMainWindow() MainWindow* window = new MainWindow(); window->setSessionList( new ProfileList(true,window) ); - connect( window , SIGNAL(newSessionRequest(const QString&,const QString&,ViewManager*)), - this , SLOT(createSession(const QString&,const QString&,ViewManager*))); - connect( window , SIGNAL(newWindowRequest(const QString&,const QString&)), - this , SLOT(createWindow(const QString&,const QString&)) ); + connect( window , SIGNAL(newSessionRequest(Profile::Ptr,const QString&,ViewManager*)), + this , SLOT(createSession(Profile::Ptr,const QString&,ViewManager*))); + connect( window , SIGNAL(newWindowRequest(Profile::Ptr,const QString&)), + this , SLOT(createWindow(Profile::Ptr,const QString&)) ); connect( window->viewManager() , SIGNAL(viewDetached(Session*)) , this , SLOT(detachView(Session*)) ); return window; @@ -162,8 +162,8 @@ void Application::processProfileSelectArgs(KCmdLineArgs* args,MainWindow* window { if ( args->isSet("profile") ) { - QString key = SessionManager::instance()->loadProfile(args->getOption("profile")); - window->setDefaultProfile(key); + Profile::Ptr profile = SessionManager::instance()->loadProfile(args->getOption("profile")); + window->setDefaultProfile(profile); } } @@ -178,10 +178,8 @@ bool Application::processHelpArgs(KCmdLineArgs* args) } void Application::processProfileChangeArgs(KCmdLineArgs* args,MainWindow* window) { - SessionManager* const manager = SessionManager::instance(); - - Profile* defaultProfile = manager->profile(window->defaultProfile()); - Profile* const newProfile = new Profile(defaultProfile); + Profile::Ptr defaultProfile = window->defaultProfile(); + Profile::Ptr newProfile = Profile::Ptr(new Profile(defaultProfile)); newProfile->setHidden(true); // run a custom command @@ -215,13 +213,9 @@ void Application::processProfileChangeArgs(KCmdLineArgs* args,MainWindow* window } } - if (newProfile->isEmpty()) + if (!newProfile->isEmpty()) { - delete newProfile; - } - else - { - window->setDefaultProfile(SessionManager::instance()->addProfile(newProfile)); + window->setDefaultProfile(newProfile); } } @@ -272,17 +266,17 @@ void Application::detachView(Session* session) window->show(); } -void Application::createWindow(const QString& key , const QString& directory) +void Application::createWindow(Profile::Ptr profile , const QString& directory) { MainWindow* window = newMainWindow(); - window->setDefaultProfile(key); - createSession(key,directory,window->viewManager()); + window->setDefaultProfile(profile); + createSession(profile,directory,window->viewManager()); window->show(); } -Session* Application::createSession(const QString& key , const QString& directory , ViewManager* view) +Session* Application::createSession(Profile::Ptr profile, const QString& directory , ViewManager* view) { - Session* session = SessionManager::instance()->createSession(key); + Session* session = SessionManager::instance()->createSession(profile); if (!directory.isEmpty() && session->initialWorkingDirectory().isEmpty()) session->setInitialWorkingDirectory(directory); diff --git a/src/Application.h b/src/Application.h index b21ed9d99..6151b1907 100644 --- a/src/Application.h +++ b/src/Application.h @@ -23,6 +23,9 @@ // KDE #include +// Konsole +#include "Profile.h" + class KCmdLineArgs; namespace Konsole @@ -72,8 +75,8 @@ public: static Application* self(); private slots: - Session* createSession(const QString& key, const QString& directory , ViewManager* view); - void createWindow(const QString& key , const QString& directory); + Session* createSession(Profile::Ptr profile, const QString& directory , ViewManager* view); + void createWindow(Profile::Ptr profile , const QString& directory); void detachView(Session* session); void toggleBackgroundInstance(); diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp index ba96e55e2..a2712a15e 100644 --- a/src/EditProfileDialog.cpp +++ b/src/EditProfileDialog.cpp @@ -50,7 +50,6 @@ #include "ui_EditProfileDialog.h" #include "KeyBindingEditor.h" #include "KeyboardTranslator.h" -#include "Profile.h" #include "SessionManager.h" #include "ShellCommand.h" #include "TabTitleFormatAction.h" @@ -91,11 +90,11 @@ EditProfileDialog::EditProfileDialog(QWidget* parent) SLOT(preparePage(int)) ); _tempProfile = new Profile; + _tempProfile->setHidden(true); } EditProfileDialog::~EditProfileDialog() { delete _ui; - delete _tempProfile; } void EditProfileDialog::save() { @@ -128,16 +127,14 @@ void EditProfileDialog::updateCaption(const QString& profileName) { setCaption( i18n("Edit Profile \"%1\"",profileName) ); } -void EditProfileDialog::setProfile(const QString& key) +void EditProfileDialog::setProfile(Profile::Ptr profile) { - _profileKey = key; + _profileKey = profile; - const Profile* info = SessionManager::instance()->profile(key); - - Q_ASSERT( info ); + Q_ASSERT( profile ); // update caption - updateCaption(info->name()); + updateCaption(profile->name()); // mark each page of the dialog as out of date // and force an update of the currently visible page @@ -148,17 +145,16 @@ void EditProfileDialog::setProfile(const QString& key) if ( _tempProfile ) { - delete _tempProfile; _tempProfile = new Profile; } } -const Profile* EditProfileDialog::lookupProfile() const +const Profile::Ptr EditProfileDialog::lookupProfile() const { - return SessionManager::instance()->profile(_profileKey); + return _profileKey; } void EditProfileDialog::preparePage(int page) { - const Profile* info = lookupProfile(); + const Profile::Ptr info = lookupProfile(); Q_ASSERT( _pageNeedsUpdate.count() > page ); Q_ASSERT( info ); @@ -194,7 +190,7 @@ void EditProfileDialog::selectProfileName() _ui->profileNameEdit->selectAll(); _ui->profileNameEdit->setFocus(); } -void EditProfileDialog::setupGeneralPage(const Profile* info) +void EditProfileDialog::setupGeneralPage(const Profile::Ptr info) { // basic profile options @@ -238,7 +234,7 @@ void EditProfileDialog::setupGeneralPage(const Profile* info) } void EditProfileDialog::showEnvironmentEditor() { - const Profile* info = lookupProfile(); + const Profile::Ptr info = lookupProfile(); KDialog* dialog = new KDialog(this); QTextEdit* edit = new QTextEdit(dialog); @@ -257,7 +253,7 @@ void EditProfileDialog::showEnvironmentEditor() dialog->deleteLater(); } -void EditProfileDialog::setupTabsPage(const Profile* info) +void EditProfileDialog::setupTabsPage(const Profile::Ptr info) { // tab title format _ui->tabTitleEdit->setClearButtonShown(true); @@ -372,7 +368,7 @@ void EditProfileDialog::selectInitialDir() if ( !url.isEmpty() ) _ui->initialDirEdit->setText(url.path()); } -void EditProfileDialog::setupAppearancePage(const Profile* info) +void EditProfileDialog::setupAppearancePage(const Profile::Ptr info) { ColorSchemeViewDelegate* delegate = new ColorSchemeViewDelegate(this); _ui->colorSchemeList->setItemDelegate(delegate); @@ -609,7 +605,7 @@ void EditProfileDialog::preview(int property , const QVariant& value) _delayedPreviewProperties.remove(property); - const Profile* original = lookupProfile(); + const Profile::Ptr original = lookupProfile(); if (!_previewedProperties.contains(property)) _previewedProperties.insert(property , original->property((Profile::Property)property) ); @@ -729,7 +725,7 @@ void EditProfileDialog::updateTransparencyWarning() _ui->transparencyWarningIcon->setPixmap( KIcon("dialog-warning").pixmap(QSize(48,48)) ); } } -void EditProfileDialog::setupKeyboardPage(const Profile* /* info */) +void EditProfileDialog::setupKeyboardPage(const Profile::Ptr /* info */) { // setup translator list updateKeyBindingsList(true); @@ -829,7 +825,7 @@ void EditProfileDialog::editKeyBinding() { showKeyBindingEditor(false); } -void EditProfileDialog::setupCombo( ComboOption* options , const Profile* profile ) +void EditProfileDialog::setupCombo( ComboOption* options , const Profile::Ptr profile ) { while ( options->button != 0 ) { @@ -854,7 +850,7 @@ void EditProfileDialog::setupRadio( RadioOption* possible , int actual ) } } -void EditProfileDialog::setupScrollingPage(const Profile* profile) +void EditProfileDialog::setupScrollingPage(const Profile::Ptr profile) { // setup scrollbar radio int scrollBarPosition = profile->property(Profile::ScrollBarPosition); @@ -912,7 +908,7 @@ void EditProfileDialog::showScrollBarRight() { _tempProfile->setProperty(Profile::ScrollBarPosition , Profile::ScrollBarRight ); } -void EditProfileDialog::setupAdvancedPage(const Profile* profile) +void EditProfileDialog::setupAdvancedPage(const Profile::Ptr profile) { ComboOption options[] = { { _ui->enableBlinkingTextButton , Profile::BlinkingTextEnabled , SLOT(toggleBlinkingText(bool)) }, diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h index 0990ed5a4..5af7f6a62 100644 --- a/src/EditProfileDialog.h +++ b/src/EditProfileDialog.h @@ -30,6 +30,9 @@ // KDE #include +// Local +#include "Profile.h" + class QAbstractButton; class QItemSelectionModel; class QTextCodec; @@ -76,7 +79,7 @@ public: * * @param key The key for the session type provided by the SessionManager instance */ - void setProfile(const QString& key); + void setProfile(Profile::Ptr profile); /** * Selects the text in the profile name edit area. @@ -168,12 +171,12 @@ private slots: private: // initialize various pages of the dialog - void setupGeneralPage(const Profile* info); - void setupTabsPage(const Profile* info); - void setupAppearancePage(const Profile* info); - void setupKeyboardPage(const Profile* info); - void setupScrollingPage(const Profile* info); - void setupAdvancedPage(const Profile* info); + void setupGeneralPage(const Profile::Ptr info); + void setupTabsPage(const Profile::Ptr info); + void setupAppearancePage(const Profile::Ptr info); + void setupKeyboardPage(const Profile::Ptr info); + void setupScrollingPage(const Profile::Ptr info); + void setupAdvancedPage(const Profile::Ptr info); void updateColorSchemeList(bool selectCurrentScheme = false); void updateColorSchemeButtons(); @@ -207,13 +210,13 @@ private: int property; const char* slot; }; - void setupCombo(ComboOption* options , const Profile* profile); + void setupCombo(ComboOption* options , const Profile::Ptr profile); - const Profile* lookupProfile() const; + const Profile::Ptr lookupProfile() const; Ui::EditProfileDialog* _ui; - Profile* _tempProfile; - QString _profileKey; + Profile::Ptr _tempProfile; + Profile::Ptr _profileKey; // 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 diff --git a/src/Emulation.cpp b/src/Emulation.cpp index 07ffacf4f..2aadce9ab 100644 --- a/src/Emulation.cpp +++ b/src/Emulation.cpp @@ -163,9 +163,11 @@ const HistoryType& Emulation::history() void Emulation::setCodec(const QTextCodec * qtc) { - Q_ASSERT( qtc ); + if (qtc) + _codec = qtc; + else + setCodec(LocaleCodec); - _codec = qtc; delete _decoder; _decoder = _codec->makeDecoder(); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index e604b53fc..2282bd2bb 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -115,11 +115,11 @@ void MainWindow::correctShortcuts() helpAction->setShortcut( QKeySequence() ); } -void MainWindow::setDefaultProfile(const QString& key) +void MainWindow::setDefaultProfile(Profile::Ptr profile) { - _defaultProfile = key; + _defaultProfile = profile; } -QString MainWindow::defaultProfile() const +Profile::Ptr MainWindow::defaultProfile() const { return _defaultProfile; } @@ -268,8 +268,8 @@ void MainWindow::setSessionList(ProfileList* list) { sessionListChanged(list->actions()); - connect( list , SIGNAL(profileSelected(const QString&)) , this , - SLOT(newFromProfile(const QString&)) ); + connect( list , SIGNAL(profileSelected(Profile::Ptr)) , this , + SLOT(newFromProfile(Profile::Ptr)) ); connect( list , SIGNAL(actionsChanged(const QList&)) , this , SLOT(sessionListChanged(const QList&)) ); @@ -348,9 +348,9 @@ void MainWindow::showShortcutsDialog() KShortcutsEditor::LetterShortcutsDisallowed, this ); } -void MainWindow::newFromProfile(const QString& key) +void MainWindow::newFromProfile(Profile::Ptr profile) { - emit newSessionRequest(key, activeSessionDir(), _viewManager); + emit newSessionRequest(profile, activeSessionDir(), _viewManager); } void MainWindow::showManageProfilesDialog() { @@ -360,9 +360,9 @@ void MainWindow::showManageProfilesDialog() void MainWindow::showRemoteConnectionDialog() { - RemoteConnectionDialog dialog(this); - if ( dialog.exec() == QDialog::Accepted ) - emit newSessionRequest(dialog.sessionKey(),QString(),_viewManager); +// RemoteConnectionDialog dialog(this); +// if ( dialog.exec() == QDialog::Accepted ) +// emit newSessionRequest(dialog.sessionKey(),QString(),_viewManager); } void MainWindow::setupWidgets() diff --git a/src/MainWindow.h b/src/MainWindow.h index 94dd2f2f4..bfcf4d9aa 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -27,6 +27,9 @@ #include #include +// Local +#include "Profile.h" + class KToggleAction; namespace Konsole @@ -36,7 +39,6 @@ class IncrementalSearchBar; class ViewManager; class ViewProperties; class SessionController; -class Profile; class ProfileList; class BookmarkHandler; @@ -82,30 +84,30 @@ class MainWindow : public KXmlGuiWindow BookmarkHandler* bookmarkHandler() const; /** - * Sets the default profile key for this window. - * This is the default value for the key argument + * Sets the default profile for this window. + * This is the default value for the profile argument * when the newSessionRequest() and newWindow() signals * are emitted. */ - void setDefaultProfile(const QString& key); + void setDefaultProfile(Profile::Ptr profile); /** - * Returns the default profile key for this window. + * Returns the default profile for this window. * See setDefaultProfile() */ - QString defaultProfile() const; + Profile::Ptr defaultProfile() const; signals: /** * Emitted by the main window to request the creation of a new session. * - * @param key The key for the profile to use to create the new session. + * @param profile The profile to use to create the new session. * @param directory Initial working directory for the new session or empty * if the default working directory associated with the profile should be used. * @param view The view manager owned by this main window */ - void newSessionRequest(const QString& key , + void newSessionRequest(Profile::Ptr profile, const QString& directory, ViewManager* view); @@ -113,13 +115,13 @@ class MainWindow : public KXmlGuiWindow * Emitted by the main window to request the creation of a * new session in a new window. * - * @param key The key for the profile to use to create the + * @param profile The profile to use to create the * first session in the new window. * @param directory Initial working directory for the new window or empty * if the default working directory associated with the profile should * be used. */ - void newWindowRequest(const QString& key, + void newWindowRequest(Profile::Ptr profile, const QString& directory); /** @@ -137,7 +139,7 @@ class MainWindow : public KXmlGuiWindow void showManageProfilesDialog(); void showRemoteConnectionDialog(); void showShortcutsDialog(); - void newFromProfile(const QString&); + void newFromProfile(Profile::Ptr profile); void activeViewChanged(SessionController* controller); void activeViewTitleChanged(ViewProperties*); @@ -166,7 +168,7 @@ class MainWindow : public KXmlGuiWindow QPointer _pluggedController; - QString _defaultProfile; + Profile::Ptr _defaultProfile; bool _menuBarVisibilitySet; }; diff --git a/src/ManageProfilesDialog.cpp b/src/ManageProfilesDialog.cpp index df07526ad..8e451988b 100644 --- a/src/ManageProfilesDialog.cpp +++ b/src/ManageProfilesDialog.cpp @@ -54,15 +54,15 @@ ManageProfilesDialog::ManageProfilesDialog(QWidget* parent) // update table and listen for changes to the session types updateTableModel(); - connect( SessionManager::instance() , SIGNAL(profileAdded(const QString&)) , this, + connect( SessionManager::instance() , SIGNAL(profileAdded(Profile::Ptr)) , this, SLOT(updateTableModel()) ); - connect( SessionManager::instance() , SIGNAL(profileRemoved(const QString&)) , this, + connect( SessionManager::instance() , SIGNAL(profileRemoved(Profile::Ptr)) , this, SLOT(updateTableModel()) ); - connect( SessionManager::instance() , SIGNAL(profileChanged(const QString&)) , this, + connect( SessionManager::instance() , SIGNAL(profileChanged(Profile::Ptr)) , this, SLOT(updateTableModel()) ); connect( SessionManager::instance() , - SIGNAL(favoriteStatusChanged(const QString&,bool)) , this , - SLOT(updateFavoriteStatus(const QString&,bool)) ); + SIGNAL(favoriteStatusChanged(Profile::Ptr,bool)) , this , + SLOT(updateFavoriteStatus(Profile::Ptr,bool)) ); // resize the session table to the full width of the table _ui->sessionTable->horizontalHeader()->setHighlightSections(false); @@ -110,7 +110,7 @@ void ManageProfilesDialog::itemDataChanged(QStandardItem* item) kDebug() << "New key sequence: " << item->text(); - SessionManager::instance()->setShortcut(item->data(ShortcutRole).value(), + SessionManager::instance()->setShortcut(item->data(ShortcutRole).value(), sequence); } } @@ -126,12 +126,10 @@ void ManageProfilesDialog::updateTableModel() _sessionModel->setHorizontalHeaderLabels( QStringList() << i18n("Name") << i18n("Show in Menu") << i18n("Shortcut") ); - QListIterator keyIter( SessionManager::instance()->loadedProfiles() ); - while ( keyIter.hasNext() ) + QListIterator profileIter( SessionManager::instance()->loadedProfiles() ); + while ( profileIter.hasNext() ) { - const QString& key = keyIter.next(); - - Profile* info = SessionManager::instance()->profile(key); + Profile::Ptr info = profileIter.next(); if ( info->isHidden() ) continue; @@ -141,9 +139,10 @@ void ManageProfilesDialog::updateTableModel() if ( !info->icon().isEmpty() ) item->setIcon( KIcon(info->icon()) ); - item->setData(key,ProfileKeyRole); + + item->setData(QVariant::fromValue(info),ProfileKeyRole); - const bool isFavorite = SessionManager::instance()->findFavorites().contains(key); + const bool isFavorite = SessionManager::instance()->findFavorites().contains(info); // favorite column QStandardItem* favoriteItem = new QStandardItem(); @@ -152,14 +151,14 @@ void ManageProfilesDialog::updateTableModel() else favoriteItem->setData(KIcon(),Qt::DecorationRole); - favoriteItem->setData(key,ProfileKeyRole); + favoriteItem->setData(QVariant::fromValue(info),ProfileKeyRole); // shortcut column QStandardItem* shortcutItem = new QStandardItem(); - QString shortcut = SessionManager::instance()->shortcut(key). + QString shortcut = SessionManager::instance()->shortcut(info). toString(); shortcutItem->setText(shortcut); - shortcutItem->setData(key,ShortcutRole); + shortcutItem->setData(QVariant::fromValue(info),ShortcutRole); itemList << item << favoriteItem << shortcutItem; @@ -191,14 +190,14 @@ void ManageProfilesDialog::updateTableModel() } void ManageProfilesDialog::updateDefaultItem() { - const QString& defaultKey = SessionManager::instance()->defaultProfileKey(); + Profile::Ptr defaultProfile = SessionManager::instance()->defaultProfile(); for ( int i = 0 ; i < _sessionModel->rowCount() ; i++ ) { QStandardItem* item = _sessionModel->item(i); QFont font = item->font(); - bool isDefault = ( defaultKey == item->data().value() ); + bool isDefault = ( defaultProfile == item->data().value() ); if ( isDefault && !font.bold() ) { @@ -216,7 +215,7 @@ void ManageProfilesDialog::tableSelectionChanged(const QItemSelection& selection { bool enable = !selection.indexes().isEmpty(); const SessionManager* manager = SessionManager::instance(); - const bool isNotDefault = enable && selectedKey() != manager->defaultProfileKey(); + const bool isNotDefault = enable && selectedKey() != manager->defaultProfile(); _ui->editSessionButton->setEnabled(enable); // do not allow the default session type to be removed @@ -229,8 +228,8 @@ void ManageProfilesDialog::deleteSelected() // one or more other profiles since deleting a profile will change the settings // of the profiles which inherit from it. - Q_ASSERT( !selectedKey().isEmpty() ); - Q_ASSERT( selectedKey() != SessionManager::instance()->defaultProfileKey() ); + Q_ASSERT( selectedKey() ); + Q_ASSERT( selectedKey() != SessionManager::instance()->defaultProfile() ); SessionManager::instance()->deleteProfile(selectedKey()); } @@ -250,75 +249,70 @@ void ManageProfilesDialog::newType() // setup a temporary profile, inheriting from the selected profile // or the default if no profile is selected - Profile* parentProfile = 0; + Profile::Ptr parentProfile; - QString selectedProfileKey = selectedKey(); - if ( selectedProfileKey.isEmpty() ) + Profile::Ptr selectedProfile = selectedKey(); + if ( !selectedProfile ) parentProfile = SessionManager::instance()->defaultProfile(); else - parentProfile = SessionManager::instance()->profile(selectedProfileKey); + parentProfile = selectedProfile; Q_ASSERT( parentProfile ); - Profile* newProfile = new Profile(parentProfile); + Profile::Ptr newProfile = Profile::Ptr(new Profile(parentProfile)); newProfile->setProperty(Profile::Name,i18n("New Profile")); - const QString& key = SessionManager::instance()->addProfile(newProfile); - kDebug() << "Key for new profile" << key; - - dialog.setProfile(key); + dialog.setProfile(newProfile); dialog.selectProfileName(); - // if the user doesn't accept the dialog, remove the temporary profile - // if they do accept the dialog, it will become a permanent profile - if ( dialog.exec() != QDialog::Accepted ) - SessionManager::instance()->deleteProfile(key); - else + if ( dialog.exec() == QDialog::Accepted ) { - SessionManager::instance()->setFavorite(key,true); + SessionManager::instance()->addProfile(newProfile); + SessionManager::instance()->setFavorite(newProfile,true); } } void ManageProfilesDialog::editSelected() { - Q_ASSERT( !selectedKey().isEmpty() ); + Q_ASSERT( selectedKey() ); EditProfileDialog dialog(this); dialog.setProfile(selectedKey()); dialog.exec(); } -QString ManageProfilesDialog::selectedKey() const +Profile::Ptr ManageProfilesDialog::selectedKey() const { QItemSelectionModel* selection = _ui->sessionTable->selectionModel(); if ( !selection || selection->selectedRows().count() != 1 ) - return QString(); + return Profile::Ptr(); // TODO There has to be an easier way of getting the data // associated with the currently selected item return selection-> - selectedIndexes().first().data( Qt::UserRole + 1 ).value(); + selectedIndexes().first().data( Qt::UserRole + 1 ).value(); } -void ManageProfilesDialog::updateFavoriteStatus(const QString& key , bool favorite) +void ManageProfilesDialog::updateFavoriteStatus(Profile::Ptr profile, bool favorite) { Q_ASSERT( _sessionModel ); - const QModelIndex topIndex = _sessionModel->index(0,FavoriteStatusColumn); - - QModelIndexList list = _sessionModel->match( topIndex , ProfileKeyRole, - key ); - - foreach( QModelIndex index , list ) - { - const KIcon icon = favorite ? KIcon("favorites") : KIcon(); - _sessionModel->setData(index,icon,Qt::DecorationRole); - } + int rowCount = _sessionModel->rowCount(); + for (int i=0;i < rowCount;i++) + { + QModelIndex index = _sessionModel->index(i,FavoriteStatusColumn); + if (index.data(ProfileKeyRole).value() == + profile ) + { + const KIcon icon = favorite ? KIcon("favorites") : KIcon(); + _sessionModel->setData(index,icon,Qt::DecorationRole); + } + } } void ManageProfilesDialog::setShortcutEditorVisible(bool visible) { _ui->sessionTable->setColumnHidden(ShortcutColumn,!visible); } ProfileItemDelegate::ProfileItemDelegate(QObject* parent) - : QItemDelegate(parent) + : QStyledItemDelegate(parent) { } // Is there a simpler way of centering the decoration than re-implementing @@ -327,22 +321,22 @@ void ProfileItemDelegate::drawDecoration(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect,const QPixmap& pixmap) const { - QStyleOptionViewItem centeredOption(option); - centeredOption.decorationAlignment = Qt::AlignCenter; - QItemDelegate::drawDecoration(painter, - centeredOption, - QStyle::alignedRect(Qt::LeftToRight,Qt::AlignCenter,rect.size(),option.rect), - pixmap); + //QStyleOptionViewItem centeredOption(option); + //centeredOption.decorationAlignment = Qt::AlignCenter; + //QStyledItemDelegate::drawDecoration(painter, + // centeredOption, + // QStyle::alignedRect(Qt::LeftToRight,Qt::AlignCenter,rect.size(),option.rect), + // pixmap); } bool ProfileItemDelegate::editorEvent(QEvent* event,QAbstractItemModel*, const QStyleOptionViewItem&,const QModelIndex& index) { if ( event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress ) { - const QString& key = index.data(ManageProfilesDialog::ProfileKeyRole).value(); - const bool isFavorite = !SessionManager::instance()->findFavorites().contains(key); + Profile::Ptr profile = index.data(ManageProfilesDialog::ProfileKeyRole).value(); + const bool isFavorite = !SessionManager::instance()->findFavorites().contains(profile); - SessionManager::instance()->setFavorite(key, + SessionManager::instance()->setFavorite(profile, isFavorite); } diff --git a/src/ManageProfilesDialog.h b/src/ManageProfilesDialog.h index c5429e74d..b4347d80c 100644 --- a/src/ManageProfilesDialog.h +++ b/src/ManageProfilesDialog.h @@ -21,11 +21,14 @@ #define MANAGEPROFILESDIALOG_H // Qt -#include +#include // KDE #include +// Konsole +#include "Profile.h" + class QItemSelection; class QShowEvent; class QStandardItem; @@ -85,10 +88,10 @@ private slots: // session manager void updateTableModel(); - void updateFavoriteStatus(const QString& key , bool favorite); + void updateFavoriteStatus(Profile::Ptr profile, bool favorite); private: - QString selectedKey() const; // return the key associated with the currently selected + Profile::Ptr selectedKey() const; // return the profile associated with the currently selected // item in the profile table void updateDefaultItem(); // updates the font of the items to match @@ -102,7 +105,7 @@ private: static const int ShortcutRole = Qt::UserRole + 1; }; -class ProfileItemDelegate : public QItemDelegate +class ProfileItemDelegate : public QStyledItemDelegate { public: ProfileItemDelegate(QObject* parent = 0); diff --git a/src/ManageProfilesDialog.ui b/src/ManageProfilesDialog.ui index 735341b1f..71ee6cf0d 100644 --- a/src/ManageProfilesDialog.ui +++ b/src/ManageProfilesDialog.ui @@ -89,9 +89,6 @@ - - QFrame::Plain - true diff --git a/src/Part.cpp b/src/Part.cpp index 62bc6f23c..7c5d74527 100644 --- a/src/Part.cpp +++ b/src/Part.cpp @@ -101,7 +101,7 @@ Part::Part(QWidget* parentWidget , QObject* parent) action->setShortcutContext(Qt::WidgetWithChildrenShortcut); // create basic session - createSession(QString()); + createSession(); } Part::~Part() { @@ -155,7 +155,7 @@ void Part::terminalExited() } void Part::newTab() { - createSession( QString() ); + createSession(); showShellInDir( QString() ); } Session* Part::activeSession() const @@ -204,9 +204,9 @@ void Part::sendInput( const QString& text ) activeSession()->emulation()->sendText(text); } -Session* Part::createSession(const QString& key) +Session* Part::createSession(const Profile::Ptr profile) { - Session* session = SessionManager::instance()->createSession(key); + Session* session = SessionManager::instance()->createSession(profile); _viewManager->createView(session); return session; @@ -254,7 +254,7 @@ void Part::showEditCurrentProfileDialog(QWidget* parent) EditProfileDialog* dialog = new EditProfileDialog(parent); dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->setProfile( activeSession()->profileKey() ); + dialog->setProfile( SessionManager::instance()->sessionProfile(activeSession()) ); dialog->show(); } void Part::changeSessionSettings(const QString& text) diff --git a/src/Part.h b/src/Part.h index 935b81edb..111219a26 100644 --- a/src/Part.h +++ b/src/Part.h @@ -25,6 +25,9 @@ #include #include +// Konsole +#include "Profile.h" + class QAction; class QStringList; @@ -106,9 +109,9 @@ protected: virtual bool openFile(); private slots: - // creates a new session using the specified key. + // creates a new session using the specified profile. // call the run() method on the returned Session instance to begin the session - Session* createSession(const QString& key); + Session* createSession(const Profile::Ptr profile = Profile::Ptr()); void activeViewChanged(SessionController* controller); void activeViewTitleChanged(ViewProperties* properties); void showManageProfilesDialog(); diff --git a/src/Profile.cpp b/src/Profile.cpp index 2d9f03fff..f85595d16 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -134,7 +134,7 @@ void Profile::fillTableWithDefaultNames() } FallbackProfile::FallbackProfile() - : Profile(0) + : Profile() { // Fallback settings setProperty(Name,i18n("Shell")); @@ -176,17 +176,21 @@ FallbackProfile::FallbackProfile() setHidden(true); } -Profile::Profile(Profile* parent) +Profile::Profile(Profile::Ptr parent) : _parent(parent) ,_hidden(false) { } - +Profile::~Profile() +{ + if (!name().isEmpty() && !isHidden()) + kDebug() << "Destroying profile " << name(); +} bool Profile::isHidden() const { return _hidden; } void Profile::setHidden(bool hidden) { _hidden = hidden; } -void Profile::setParent(Profile* parent) { _parent = parent; } -const Profile* Profile::parent() const { return _parent; } +void Profile::setParent(Profile::Ptr parent) { _parent = parent; } +const Profile::Ptr Profile::parent() const { return _parent; } bool Profile::isEmpty() const { @@ -244,7 +248,7 @@ void Profile::registerProperty(const PropertyInfo& info) _infoByProperty.insert(info.property,info); } -QString KDE4ProfileWriter::getPath(const Profile* info) +QString KDE4ProfileWriter::getPath(const Profile::Ptr info) { QString newPath; @@ -264,7 +268,7 @@ QString KDE4ProfileWriter::getPath(const Profile* info) return newPath; } void KDE4ProfileWriter::writeProperties(KConfig& config, - const Profile* profile, + const Profile::Ptr profile, const Profile::PropertyInfo* properties) { const char* groupName = 0; @@ -288,7 +292,7 @@ void KDE4ProfileWriter::writeProperties(KConfig& config, properties++; } } -bool KDE4ProfileWriter::writeProfile(const QString& path , const Profile* profile) +bool KDE4ProfileWriter::writeProfile(const QString& path , const Profile::Ptr profile) { KConfig config(path,KConfig::NoGlobals); @@ -296,7 +300,7 @@ bool KDE4ProfileWriter::writeProfile(const QString& path , const Profile* profil // Parent profile if set, when loading the profile in future, the parent // must be loaded as well if it exists. - if ( profile->parent() != 0 ) + if ( profile->parent() ) general.writeEntry("Parent",profile->parent()->path()); if ( profile->isPropertySet(Profile::Command) @@ -315,7 +319,7 @@ QStringList KDE4ProfileReader::findProfiles() return KGlobal::dirs()->findAllResources("data","konsole/*.profile", KStandardDirs::NoDuplicates); } -void KDE4ProfileReader::readProperties(const KConfig& config, Profile* profile, +void KDE4ProfileReader::readProperties(const KConfig& config, Profile::Ptr profile, const Profile::PropertyInfo* properties) { const char* groupName = 0; @@ -343,7 +347,7 @@ void KDE4ProfileReader::readProperties(const KConfig& config, Profile* profile, } } -bool KDE4ProfileReader::readProfile(const QString& path , Profile* profile , QString& parentProfile) +bool KDE4ProfileReader::readProfile(const QString& path , Profile::Ptr profile , QString& parentProfile) { KConfig config(path,KConfig::NoGlobals); @@ -369,7 +373,7 @@ QStringList KDE3ProfileReader::findProfiles() return KGlobal::dirs()->findAllResources("data", "konsole/*.desktop", KStandardDirs::NoDuplicates); } -bool KDE3ProfileReader::readProfile(const QString& path , Profile* profile , QString& parentProfile) +bool KDE3ProfileReader::readProfile(const QString& path , Profile::Ptr profile , QString& parentProfile) { if (!QFile::exists(path)) return false; diff --git a/src/Profile.h b/src/Profile.h index 1db2c13e8..1e08ef427 100644 --- a/src/Profile.h +++ b/src/Profile.h @@ -31,6 +31,9 @@ #include +// KDE +#include + class KConfig; class KConfigGroup; @@ -59,14 +62,15 @@ namespace Konsole * pointer to the parent profile using QPointer. Try to find * a more light-weight solution to this. */ -class Profile : public QObject +class Profile : public QSharedData { -Q_OBJECT friend class KDE4ProfileReader; friend class KDE4ProfileWriter; public: + typedef KSharedPtr Ptr; + /** * This enum describes the available properties * which a Profile may consist of. @@ -254,18 +258,18 @@ public: /** * Constructs a new profile */ - Profile(Profile* parent = 0); - virtual ~Profile() {} + explicit Profile(Ptr parent = Ptr()); + virtual ~Profile(); /** * Changes the parent profile. When calling the property() method, * if the specified property has not been set for this profile, * the parent's value for the property will be returned instead. */ - void setParent(Profile* parent); + void setParent(Ptr parent); /** Returns the parent profile. */ - const Profile* parent() const; + const Ptr parent() const; /** * Returns the current value of the specified @p property, cast to type T. @@ -382,7 +386,7 @@ private: static void fillTableWithDefaultNames(); QHash _propertyValues; - QPointer _parent; + Ptr _parent; bool _hidden; @@ -445,23 +449,23 @@ public: * @param profile Pointer to the Profile the settings will be read into * @param parentProfile Receives the name of the parent profile specified in */ - virtual bool readProfile(const QString& path , Profile* profile , QString& parentProfile) = 0; + virtual bool readProfile(const QString& path , Profile::Ptr profile , QString& parentProfile) = 0; }; /** Reads a KDE 3 profile .desktop file. */ class KDE3ProfileReader : public ProfileReader { public: virtual QStringList findProfiles(); - virtual bool readProfile(const QString& path , Profile* profile, QString& parentProfile); + virtual bool readProfile(const QString& path , Profile::Ptr profile, QString& parentProfile); }; /** Reads a KDE 4 .profile file. */ class KDE4ProfileReader : public ProfileReader { public: virtual QStringList findProfiles(); - virtual bool readProfile(const QString& path , Profile* profile, QString& parentProfile); + virtual bool readProfile(const QString& path , Profile::Ptr profile, QString& parentProfile); private: - void readProperties(const KConfig& config, Profile* profile, + void readProperties(const KConfig& config, Profile::Ptr profile, const Profile::PropertyInfo* properties); }; /** Interface for all classes which can write profile settings to a file. */ @@ -474,22 +478,22 @@ public: * @p profile to. The path-name should be accepted by * the corresponding ProfileReader class. */ - virtual QString getPath(const Profile* profile) = 0; + virtual QString getPath(const Profile::Ptr profile) = 0; /** * Writes the properties and values from @p profile to the file specified by * @p path. This profile should be readable by the corresponding ProfileReader class. */ - virtual bool writeProfile(const QString& path , const Profile* profile) = 0; + virtual bool writeProfile(const QString& path , const Profile::Ptr profile) = 0; }; /** Writes a KDE 4 .profile file. */ class KDE4ProfileWriter : public ProfileWriter { public: - virtual QString getPath(const Profile* profile); - virtual bool writeProfile(const QString& path , const Profile* profile); + virtual QString getPath(const Profile::Ptr profile); + virtual bool writeProfile(const QString& path , const Profile::Ptr profile); private: - void writeProperties(KConfig& config, const Profile* profile, + void writeProperties(KConfig& config, const Profile::Ptr profile, const Profile::PropertyInfo* properties); }; @@ -523,5 +527,6 @@ public: }; } +Q_DECLARE_METATYPE(Konsole::Profile::Ptr) #endif // PROFILE_H diff --git a/src/ProfileList.cpp b/src/ProfileList.cpp index 83a0addb8..0db50334d 100644 --- a/src/ProfileList.cpp +++ b/src/ProfileList.cpp @@ -48,27 +48,25 @@ ProfileList::ProfileList(bool addShortcuts , QObject* parent) _emptyListAction = new QAction(i18n("No profiles available"),_group); _emptyListAction->setEnabled(false); - - QList list = manager->findFavorites().toList(); - qSort(list); - QListIterator iter(list); + // TODO Sort list in alphabetical order + QList list = manager->findFavorites().toList(); + QListIterator iter(list); while (iter.hasNext()) { - const QString& key = iter.next(); - favoriteChanged(key,true); + favoriteChanged(iter.next(),true); } connect( _group , SIGNAL(triggered(QAction*)) , this , SLOT(triggered(QAction*)) ); // listen for future changes to the session list - connect( manager , SIGNAL(favoriteStatusChanged(const QString&,bool)) , this , - SLOT(favoriteChanged(const QString&,bool)) ); - connect( manager , SIGNAL(shortcutChanged(QString,QKeySequence)) , this , - SLOT(shortcutChanged(QString,QKeySequence)) ); - connect( manager , SIGNAL(profileChanged(const QString&)) , this , - SLOT(profileChanged(const QString&)) ); + connect( manager , SIGNAL(favoriteStatusChanged(Profile::Ptr,bool)) , this , + SLOT(favoriteChanged(Profile::Ptr,bool)) ); + connect( manager , SIGNAL(shortcutChanged(Profile::Ptr,QKeySequence)) , this , + SLOT(shortcutChanged(Profile::Ptr,QKeySequence)) ); + connect( manager , SIGNAL(profileChanged(Profile::Ptr)) , this , + SLOT(profileChanged(Profile::Ptr)) ); } void ProfileList::updateEmptyAction() { @@ -82,26 +80,26 @@ void ProfileList::updateEmptyAction() if ( showEmptyAction != _emptyListAction->isVisible() ) _emptyListAction->setVisible(showEmptyAction); } -QAction* ProfileList::actionForKey(const QString& key) const +QAction* ProfileList::actionForKey(Profile::Ptr key) const { QListIterator iter(_group->actions()); while ( iter.hasNext() ) { QAction* next = iter.next(); - if ( next->data() == key ) + if ( next->data().value() == key ) return next; } return 0; // not found } -void ProfileList::profileChanged(const QString& key) +void ProfileList::profileChanged(Profile::Ptr key) { QAction* action = actionForKey(key); if ( action ) - updateAction(action,SessionManager::instance()->profile(key)); + updateAction(action,key); } -void ProfileList::updateAction(QAction* action , Profile* info) +void ProfileList::updateAction(QAction* action , Profile::Ptr info) { Q_ASSERT(action); Q_ASSERT(info); @@ -109,32 +107,30 @@ void ProfileList::updateAction(QAction* action , Profile* info) action->setText(info->name()); action->setIcon(KIcon(info->icon())); } -void ProfileList::shortcutChanged(const QString& key,const QKeySequence& sequence) +void ProfileList::shortcutChanged(Profile::Ptr info,const QKeySequence& sequence) { if ( !_addShortcuts ) return; - QAction* action = actionForKey(key); + QAction* action = actionForKey(info); if ( action ) { action->setShortcut(sequence); } } -void ProfileList::favoriteChanged(const QString& key,bool isFavorite) +void ProfileList::favoriteChanged(Profile::Ptr info,bool isFavorite) { SessionManager* manager = SessionManager::instance(); if ( isFavorite ) { - Profile* info = manager->profile(key); - QAction* action = new QAction(_group); - action->setData( key ); + action->setData( QVariant::fromValue(info) ); if ( _addShortcuts ) { - action->setShortcut(manager->shortcut(key)); + action->setShortcut(manager->shortcut(info)); } updateAction(action,info); @@ -143,7 +139,7 @@ void ProfileList::favoriteChanged(const QString& key,bool isFavorite) } else { - QAction* action = actionForKey(key); + QAction* action = actionForKey(info); if ( action ) { @@ -157,10 +153,7 @@ void ProfileList::favoriteChanged(const QString& key,bool isFavorite) void ProfileList::triggered(QAction* action) { - // assert that session key is still valid - Q_ASSERT( SessionManager::instance()->profile( action->data().toString() ) ); - - emit profileSelected( action->data().toString() ); + emit profileSelected( action->data().value() ); } QList ProfileList::actions() diff --git a/src/ProfileList.h b/src/ProfileList.h index a393b678b..9e9f30353 100644 --- a/src/ProfileList.h +++ b/src/ProfileList.h @@ -23,6 +23,8 @@ #include #include +#include "Profile.h" + class QAction; class QActionGroup; class QKeySequence; @@ -71,7 +73,7 @@ signals: * * @param key The profile key associated with the selected action. */ - void profileSelected(const QString& key); + void profileSelected(Profile::Ptr profile); /** * Emitted when the list of actions changes. */ @@ -79,13 +81,13 @@ signals: private slots: void triggered(QAction* action); - void favoriteChanged(const QString& key , bool isFavorite); - void profileChanged(const QString& key); - void shortcutChanged(const QString& key, const QKeySequence& sequence); + void favoriteChanged(Profile::Ptr profile, bool isFavorite); + void profileChanged(Profile::Ptr profile); + void shortcutChanged(Profile::Ptr profile, const QKeySequence& sequence); private: - QAction* actionForKey(const QString& key) const; - void updateAction(QAction* action , Profile* profile); + QAction* actionForKey(Profile::Ptr profile) const; + void updateAction(QAction* action , Profile::Ptr profile); void updateEmptyAction(); QActionGroup* _group; diff --git a/src/Session.cpp b/src/Session.cpp index 8ceb499af..203b12193 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -624,13 +624,6 @@ Session::~Session() delete _zmodemProc; } -void Session::setProfileKey(const QString& key) -{ - _profileKey = key; - emit profileChanged(key); -} -QString Session::profileKey() const { return _profileKey; } - void Session::done(int exitStatus) { if (!_autoClose) diff --git a/src/Session.h b/src/Session.h index d512c76d2..9bf1a21d1 100644 --- a/src/Session.h +++ b/src/Session.h @@ -85,20 +85,6 @@ public: */ bool isRunning() const; - /** - * Sets the profile associated with this session. - * - * @param profileKey A key which can be used to obtain the current - * profile settings from the SessionManager - */ - void setProfileKey(const QString& profileKey); - /** - * Returns the profile key associated with this session. - * This can be passed to the SessionManager to obtain the current - * profile settings. - */ - QString profileKey() const; - /** * Adds a new view for this session. * @@ -421,9 +407,6 @@ signals: /** Emitted when the session's title has changed. */ void titleChanged(); - /** Emitted when the session's profile has changed. */ - void profileChanged(const QString& profile); - /** * Emitted when the activity state of this session changes. * diff --git a/src/SessionController.cpp b/src/SessionController.cpp index 488d559f8..a8ba73998 100644 --- a/src/SessionController.cpp +++ b/src/SessionController.cpp @@ -52,6 +52,7 @@ #include "ProcessInfo.h" #include "ProfileList.h" #include "TerminalDisplay.h" +#include "SessionManager.h" // for SaveHistoryTask #include @@ -584,17 +585,17 @@ void SessionController::setupActions() //action->setText( "Get Foreground Process" ); //connect( action , SIGNAL(triggered()) , this , SLOT(debugProcess()) ); } -void SessionController::changeProfile(const QString& key) +void SessionController::changeProfile(Profile::Ptr profile) { - _session->setProfileKey(key); + SessionManager::instance()->setSessionProfile(_session,profile); } void SessionController::prepareChangeProfileMenu() { if ( _changeProfileMenu->isEmpty() ) { _profileList = new ProfileList(false,this); - connect( _profileList , SIGNAL(profileSelected(const QString&)) , - this , SLOT(changeProfile(const QString&)) ); + connect( _profileList , SIGNAL(profileSelected(Profile::Ptr)) , + this , SLOT(changeProfile(Profile::Ptr)) ); } _changeProfileMenu->clear(); @@ -651,7 +652,7 @@ void SessionController::editCurrentProfile() { EditProfileDialog* dialog = new EditProfileDialog( QApplication::activeWindow() ); - dialog->setProfile(_session->profileKey()); + dialog->setProfile(SessionManager::instance()->sessionProfile(_session)); dialog->show(); } void SessionController::renameSession() diff --git a/src/SessionController.h b/src/SessionController.h index fad71e9f0..48263ea48 100644 --- a/src/SessionController.h +++ b/src/SessionController.h @@ -36,6 +36,7 @@ // Konsole #include "HistorySizeDialog.h" #include "ViewProperties.h" +#include "Profile.h" namespace KIO { @@ -182,7 +183,7 @@ private slots: void decreaseTextSize(); void renameSession(); void saveSession(); - void changeProfile(const QString& key); + void changeProfile(Profile::Ptr profile); // other void prepareChangeProfileMenu(); diff --git a/src/SessionManager.cpp b/src/SessionManager.cpp index 35d25c7b0..507aa623c 100644 --- a/src/SessionManager.cpp +++ b/src/SessionManager.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -77,7 +76,7 @@ SessionManager::SessionManager() SLOT(sessionTerminated(QObject*)) ); //load fallback profile - addProfile( new FallbackProfile ); + addProfile( Profile::Ptr(new FallbackProfile) ); //locate and load default profile KSharedConfigPtr appConfig = KGlobal::config(); @@ -87,20 +86,20 @@ SessionManager::SessionManager() QString path = KGlobal::dirs()->findResource("data","konsole/"+defaultSessionFilename); if (!path.isEmpty()) { - const QString& key = loadProfile(path); - if ( !key.isEmpty() ) - _defaultProfile = key; + Profile::Ptr profile = loadProfile(path); + if ( profile ) + _defaultProfile = profile; } Q_ASSERT( _types.count() > 0 ); - Q_ASSERT( !_defaultProfile.isEmpty() ); + Q_ASSERT( _defaultProfile ); // get shortcuts and paths of profiles associated with // them - this doesn't load the shortcuts themselves, // that is done on-demand. loadShortcuts(); } -QString SessionManager::loadProfile(const QString& shortPath) +Profile::Ptr SessionManager::loadProfile(const QString& shortPath) { QString path = shortPath; @@ -115,25 +114,29 @@ QString SessionManager::loadProfile(const QString& shortPath) if ( !fileInfo.isAbsolute() ) path = KStandardDirs::locate("data",path); + // check that we have not already loaded this profile + QSetIterator iter(_types); + while ( iter.hasNext() ) + { + Profile::Ptr profile = iter.next(); + if ( profile->path() == path ) + return profile; + } + // guard to prevent problems if a profile specifies itself as its parent // or if there is recursion in the "inheritance" chain // (eg. two profiles, A and B, specifying each other as their parents) static QStack recursionGuard; + PopStackOnExit popGuardOnExit(recursionGuard); + if (recursionGuard.contains(path)) - return QString(); + { + kWarning() << "Ignoring attempt to load profile recursively from" << path; + return Profile::Ptr(); + } else recursionGuard.push(path); - - // check that we have not already loaded this profile - QHashIterator iter(_types); - while ( iter.hasNext() ) - { - iter.next(); - if ( iter.value()->path() == path ) - return iter.key(); - } - // load the profile ProfileReader* reader = 0; if ( path.endsWith(".desktop") ) @@ -143,32 +146,34 @@ QString SessionManager::loadProfile(const QString& shortPath) if (!reader) { - recursionGuard.pop(); - return QString(); + kWarning() << "Could not create loader to read profile from" << path; + return Profile::Ptr(); } - Profile* newProfile = new Profile(defaultProfile()); + Profile::Ptr newProfile = Profile::Ptr(new Profile(defaultProfile())); newProfile->setProperty(Profile::Path,path); - QString parentProfile; - bool result = reader->readProfile(path,newProfile,parentProfile); + QString parentProfilePath; + bool result = reader->readProfile(path,newProfile,parentProfilePath); - if ( !parentProfile.isEmpty() ) + if ( !parentProfilePath.isEmpty() ) { - QString parentKey = loadProfile(parentProfile); - newProfile->setParent(profile(parentKey)); + Profile::Ptr parentProfile = loadProfile(parentProfilePath); + newProfile->setParent(parentProfile); } delete reader; - recursionGuard.pop(); if (!result) { - delete newProfile; - return QString(); + kWarning() << "Could not load profile from " << path; + return Profile::Ptr(); } else - return addProfile(newProfile); + { + addProfile(newProfile); + return newProfile; + } } QList SessionManager::availableProfilePaths() const { @@ -212,12 +217,6 @@ SessionManager::~SessionManager() session->close(); delete session; } - - // free profiles - QListIterator infoIter(_types.values()); - - while (infoIter.hasNext()) - delete infoIter.next(); } const QList SessionManager::sessions() @@ -227,7 +226,7 @@ const QList SessionManager::sessions() void SessionManager::updateSession(Session* session) { - Profile* info = profile(session->profileKey()); + Profile::Ptr info = _sessionProfiles[session]; Q_ASSERT( info ); @@ -238,27 +237,22 @@ void SessionManager::updateSession(Session* session) emit sessionUpdated(session); } -Session* SessionManager::createSession(const QString& key ) +Session* SessionManager::createSession(Profile::Ptr info) { Session* session = 0; - const Profile* info = 0; - - if ( key.isEmpty() ) - info = defaultProfile(); - else - info = _types[key]; + if (!info) + info = defaultProfile(); + + if (!_types.contains(info)) + addProfile(info); //configuration information found, create a new session based on this session = new Session(); - session->setProfileKey(key); applyProfile(session,info,false); - connect( session , SIGNAL(profileChanged(const QString&)) , this , - SLOT(sessionProfileChanged()) ); - - connect( session , SIGNAL(profileChangeCommandReceived(const QString&)) , this , - SLOT(sessionProfileCommandReceived(const QString&)) ); + connect( session , SIGNAL(profileChangeCommandReceived(QString)) , this , + SLOT(sessionProfileCommandReceived(QString)) ); //ask for notification when session dies _sessionMapper->setMapping(session,session); @@ -267,6 +261,7 @@ Session* SessionManager::createSession(const QString& key ) //add session to active list _sessions << session; + _sessionProfiles.insert(session,info); Q_ASSERT( session ); @@ -283,33 +278,17 @@ void SessionManager::sessionTerminated(QObject* sessionObject) session->deleteLater(); } -QList SessionManager::loadedProfiles() const +QList SessionManager::loadedProfiles() const { - return _types.keys(); + return _types.toList(); } -Profile* SessionManager::profile(const QString& key) const -{ - if ( key.isEmpty() ) - return defaultProfile(); - - if ( _types.contains(key) ) - return _types[key]; - else - return 0; -} - -Profile* SessionManager::defaultProfile() const -{ - return _types[_defaultProfile]; -} - -QString SessionManager::defaultProfileKey() const +Profile::Ptr SessionManager::defaultProfile() const { return _defaultProfile; } -QString SessionManager::saveProfile(Profile* info) +QString SessionManager::saveProfile(Profile::Ptr info) { ProfileWriter* writer = new KDE4ProfileWriter; @@ -322,16 +301,10 @@ QString SessionManager::saveProfile(Profile* info) return newPath; } -void SessionManager::changeProfile(const QString& key , +void SessionManager::changeProfile(Profile::Ptr info , QHash propertyMap, bool persistant) { - Profile* info = profile(key); - - if (!info || key.isEmpty()) - { - kWarning() << "Profile for key" << key << "not found."; - return; - } + Q_ASSERT(info); // insert the changes into the existing Profile instance QListIterator iter(propertyMap.keys()); @@ -342,10 +315,10 @@ void SessionManager::changeProfile(const QString& key , } // apply the changes to existing sessions - applyProfile(key,true); + applyProfile(info,true); // notify the world about the change - emit profileChanged(key); + emit profileChanged(info); // save changes to disk, unless the profile is hidden, in which case // it has no file on disk @@ -354,23 +327,30 @@ void SessionManager::changeProfile(const QString& key , info->setProperty(Profile::Path,saveProfile(info)); } } -void SessionManager::applyProfile(const QString& key , bool modifiedPropertiesOnly) +void SessionManager::applyProfile(Profile::Ptr info , bool modifiedPropertiesOnly) { - Profile* info = profile(key); - QListIterator iter(_sessions); while ( iter.hasNext() ) { Session* next = iter.next(); - if ( next->profileKey() == key ) + if ( _sessionProfiles[next] == info ) applyProfile(next,info,modifiedPropertiesOnly); } } -void SessionManager::applyProfile(Session* session, const Profile* info , bool modifiedPropertiesOnly) +Profile::Ptr SessionManager::sessionProfile(Session* session) const { - QString key = _types.key((Profile*)info); - if ( session->profileKey() != key ) - session->setProfileKey(key); + return _sessionProfiles[session]; +} +void SessionManager::setSessionProfile(Session* session, Profile::Ptr profile) +{ + _sessionProfiles[session] = profile; + updateSession(session); +} +void SessionManager::applyProfile(Session* session, const Profile::Ptr info , bool modifiedPropertiesOnly) +{ + Q_ASSERT(info); + + _sessionProfiles[session] = info; ShouldApplyProperty apply(info,modifiedPropertiesOnly); @@ -438,36 +418,18 @@ void SessionManager::applyProfile(Session* session, const Profile* info , bool m } } -QString SessionManager::addProfile(Profile* type) +void SessionManager::addProfile(Profile::Ptr type) { - QString key; - - // choose a key for the Profile - for ( int counter = 0;;counter++ ) - { - //if ( !_types.contains(type->path() + QString::number(counter)) ) - - if ( !_types.contains(type->name() + QString::number(counter)) ) - { - key = type->name() + QString::number(counter); - break; - } - } - if ( _types.isEmpty() ) - _defaultProfile = key; + _defaultProfile = type; - _types.insert(key,type); + _types.insert(type); - emit profileAdded(key); - - return key; + emit profileAdded(type); } -bool SessionManager::deleteProfile(const QString& key) +bool SessionManager::deleteProfile(Profile::Ptr type) { - Profile* type = profile(key); - bool wasDefault = ( type == defaultProfile() ); if ( type ) @@ -484,29 +446,30 @@ bool SessionManager::deleteProfile(const QString& key) } } - setFavorite(key,false); - _types.remove(key); - delete type; + setFavorite(type,false); + _types.remove(type); + + // mark the profile as hidden so that it does not show up in the + // Manage Profiles dialog and is not saved to disk + type->setHidden(true); } // if we just deleted the default session type, - // replace it with the first type in the list + // replace it with a random type from the list if ( wasDefault ) { - setDefaultProfile( _types.keys().first() ); + setDefaultProfile( _types.toList().first() ); } - emit profileRemoved(key); + emit profileRemoved(type); return true; } -void SessionManager::setDefaultProfile(const QString& key) +void SessionManager::setDefaultProfile(Profile::Ptr info) { - Q_ASSERT ( _types.contains(key) ); + Q_ASSERT ( _types.contains(info) ); - _defaultProfile = key; - - Profile* info = profile(key); + _defaultProfile = info; QString path = info->path(); @@ -515,34 +478,32 @@ void SessionManager::setDefaultProfile(const QString& key) QFileInfo fileInfo(path); - //kDebug() << "setting default session type to " << fileInfo.fileName(); - KSharedConfigPtr config = KGlobal::config(); KConfigGroup group = config->group("Desktop Entry"); group.writeEntry("DefaultProfile",fileInfo.fileName()); } -QSet SessionManager::findFavorites() +QSet SessionManager::findFavorites() { if (_favorites.isEmpty()) loadFavorites(); return _favorites; } -void SessionManager::setFavorite(const QString& key , bool favorite) +void SessionManager::setFavorite(Profile::Ptr info , bool favorite) { - Q_ASSERT( _types.contains(key) ); + if (!_types.contains(info)) + addProfile(info); - if ( favorite && !_favorites.contains(key) ) + if ( favorite && !_favorites.contains(info) ) { - _favorites.insert(key); - emit favoriteStatusChanged(key,favorite); + _favorites.insert(info); + emit favoriteStatusChanged(info,favorite); } - else if ( !favorite && _favorites.contains(key) ) + else if ( !favorite && _favorites.contains(info) ) { - _favorites.remove(key); - emit favoriteStatusChanged(key,favorite); + _favorites.remove(info); + emit favoriteStatusChanged(info,favorite); } - } void SessionManager::loadShortcuts() { @@ -582,20 +543,20 @@ void SessionManager::saveShortcuts() iter.value().profilePath); } } -void SessionManager::setShortcut(const QString& profileKey , +void SessionManager::setShortcut(const Profile::Ptr info , const QKeySequence& keySequence ) { - QKeySequence existingShortcut = shortcut(profileKey); + QKeySequence existingShortcut = shortcut(info); _shortcuts.remove(existingShortcut); ShortcutData data; - data.profileKey = profileKey; - data.profilePath = profile(profileKey)->path(); + data.profileKey = info; + data.profilePath = info->path(); // TODO - This won't work if the profile doesn't // have a path yet _shortcuts.insert(keySequence,data); - emit shortcutChanged(profileKey,keySequence); + emit shortcutChanged(info,keySequence); } void SessionManager::loadFavorites() { @@ -617,14 +578,14 @@ void SessionManager::loadFavorites() } // look for favorites amongst those already loaded - QHashIterator iter(_types); + QSetIterator iter(_types); while ( iter.hasNext() ) { - iter.next(); - const QString& path = iter.value()->path(); + Profile::Ptr profile = iter.next(); + const QString& path = profile->path(); if ( favoriteSet.contains( path ) ) { - _favorites.insert( iter.key() ); + _favorites.insert( profile ); favoriteSet.remove(path); } } @@ -632,9 +593,9 @@ void SessionManager::loadFavorites() QSetIterator unloadedFavoriteIter(favoriteSet); while ( unloadedFavoriteIter.hasNext() ) { - const QString& key = loadProfile(unloadedFavoriteIter.next()); - if (!key.isEmpty()) - _favorites.insert(key); + Profile::Ptr profile = loadProfile(unloadedFavoriteIter.next()); + if (profile) + _favorites.insert(profile); } } void SessionManager::saveFavorites() @@ -643,14 +604,14 @@ void SessionManager::saveFavorites() KConfigGroup favoriteGroup = appConfig->group("Favorite Profiles"); QStringList paths; - QSetIterator keyIter(_favorites); + QSetIterator keyIter(_favorites); while ( keyIter.hasNext() ) { - const QString& key = keyIter.next(); + Profile::Ptr profile = keyIter.next(); - Q_ASSERT( _types.contains(key) && profile(key) != 0 ); + Q_ASSERT( _types.contains(profile) && profile ); - paths << profile(key)->path(); + paths << profile->path(); } favoriteGroup.writeEntry("Favorites",paths); @@ -661,27 +622,19 @@ QList SessionManager::shortcuts() return _shortcuts.keys(); } -QString SessionManager::findByShortcut(const QKeySequence& shortcut) +Profile::Ptr SessionManager::findByShortcut(const QKeySequence& shortcut) { Q_ASSERT( _shortcuts.contains(shortcut) ); - if ( _shortcuts[shortcut].profileKey.isEmpty() ) + if ( !_shortcuts[shortcut].profileKey ) { - QString key = loadProfile(_shortcuts[shortcut].profilePath); + Profile::Ptr key = loadProfile(_shortcuts[shortcut].profilePath); _shortcuts[shortcut].profileKey = key; } return _shortcuts[shortcut].profileKey; } -void SessionManager::sessionProfileChanged() -{ - Session* session = qobject_cast(sender()); - Q_ASSERT( session ); - - updateSession(session); -} - void SessionManager::sessionProfileCommandReceived(const QString& text) { // FIXME: This is inefficient, it creates a new profile instance for @@ -694,7 +647,7 @@ void SessionManager::sessionProfileCommandReceived(const QString& text) ProfileCommandParser parser; QHash changes = parser.parse(text); - Profile* newProfile = new Profile( profile(session->profileKey()) ); + Profile::Ptr newProfile = Profile::Ptr(new Profile(_sessionProfiles[session])); QHashIterator iter(changes); while ( iter.hasNext() ) @@ -703,18 +656,16 @@ void SessionManager::sessionProfileCommandReceived(const QString& text) newProfile->setProperty(iter.key(),iter.value()); } - session->setProfileKey( addProfile(newProfile) ); + _sessionProfiles[session] = newProfile; } -QKeySequence SessionManager::shortcut(const QString& profileKey) const +QKeySequence SessionManager::shortcut(Profile::Ptr info) const { - Profile* info = profile(profileKey); - QMapIterator iter(_shortcuts); while (iter.hasNext()) { iter.next(); - if ( iter.value().profileKey == profileKey + if ( iter.value().profileKey == info || iter.value().profilePath == info->path() ) return iter.key(); } diff --git a/src/SessionManager.h b/src/SessionManager.h index 89f4f08bf..ca2295e57 100644 --- a/src/SessionManager.h +++ b/src/SessionManager.h @@ -33,6 +33,7 @@ #include #include #include +#include // Konsole #include "Profile.h" @@ -67,7 +68,7 @@ public: virtual ~SessionManager(); /** - * Returns a list of keys for profiles which have been loaded. + * Returns a list of profiles which have been loaded. * Initially only the profile currently set as the default is loaded. * * Favorite profiles are loaded automatically when findFavorites() is called. @@ -76,7 +77,7 @@ public: * involves opening, reading and parsing all profiles from disk, and * should only be done when necessary. */ - QList loadedProfiles() const; + QList loadedProfiles() const; /** * Searches for available profiles on-disk and returns a list @@ -84,23 +85,7 @@ public: */ QList availableProfilePaths() const; - /** - * Returns the session information object for the profile with the specified - * key or 0 if no profile with the specified key exists. - * - * If @p key is empty, a pointer to the default profile is returned. - */ - Profile* profile(const QString& key) const; - - /** - * Registers a new type of session and returns the key - * which can be passed to createSession() to create new instances of the session. - * - * The favorite status of the session ( as returned by isFavorite() ) is set - * to false by default. - */ - QString addProfile(Profile* type); - + /** * Loads a profile from the specified path and registers * it with the SessionManager. @@ -111,51 +96,50 @@ public: * "konsole/My Profile.profile" , "My Profile.profile" and * "My Profile" will be accepted) * - * @return The profile key which can be used to create new sessions - * from this profile using createSession() + * @return Pointer to a profile which can be passed to createSession() + * to create a new session using this profile. */ - QString loadProfile(const QString& path); + Profile::Ptr loadProfile(const QString& path); /** - * Updates the profile associated with the specified @p key with - * the changes specified in @p propertyMap. + * Updates a @p profile with the changes specified in @p propertyMap. * - * All sessions using the profile will be updated to reflect the new settings. + * All sessions currently using the profile will be updated to reflect the new settings. * * After the profile is updated, the profileChanged() signal will be emitted. * - * @param key The profile's key + * @param profile The profile to change * @param propertyMap A map between profile properties and values describing the changes * @param persistant If true, the changes are saved to the profile's configuration file, * set this to false if you want to preview possible changes to a profile but do not * wish to make them permanent. */ - void changeProfile(const QString& key , QHash propertyMap, + void changeProfile(Profile::Ptr profile , QHash propertyMap, bool persistant = true); /** * Returns a Profile object describing the default type of session, which is used * if createSession() is called with an empty configPath argument. */ - Profile* defaultProfile() const; - - /** - * Returns the key for the default profile. - */ - QString defaultProfileKey() const; + Profile::Ptr defaultProfile() const; /** * Creates a new session using the settings specified by the specified - * profile key. + * profile. * * The new session has no views associated with it. A new TerminalDisplay view * must be created in order to display the output from the terminal session and * send keyboard or mouse input to it. * - * @param type Specifies the type of session to create. Passing an empty - * string will create a session using the default configuration. + * @param profile A profile containing the settings for the new session. If @p profile + * is null the defaul profile (see defaultProfile()) will be used. */ - Session* createSession(const QString& key = QString()); + Session* createSession(Profile::Ptr profile = Profile::Ptr()); + + /** Returns the profile associated with a session. */ + Profile::Ptr sessionProfile(Session* session) const; + /** Sets the profile associated with a session. */ + void setSessionProfile(Session* session, Profile::Ptr profile); /** * Updates a session's properties to match its current profile. @@ -168,24 +152,25 @@ public: const QList sessions(); /** - * Deletes the profile with the specified key. - * The configuration file associated with the profile is - * deleted if possible. - * + * Deletes the configuration file used to store a profile. + * The profile will continue to exist while sessions are still using it. The profile + * will be marked as hidden (see Profile::setHidden() ) so that it does not show + * up in profile lists and future changes to the profile are not stored to disk. + * * Returns true if the profile was successfully deleted or false otherwise. */ - bool deleteProfile(const QString& key); + bool deleteProfile(Profile::Ptr profile); /** - * Sets the profile with the specified key - * as the default type. + * Sets the @p profile as the default profile for new sessions created + * with createSession() */ - void setDefaultProfile(const QString& key); + void setDefaultProfile(Profile::Ptr profile); /** - * Returns the set of keys for the user's favorite profiles. + * Returns the set of the user's favorite profiles. */ - QSet findFavorites(); + QSet findFavorites(); /** * Returns the list of shortcut key sequences which @@ -194,30 +179,35 @@ public: * * When one of the shortcuts is activated, * use findByShortcut() to load the profile associated - * with the shortcut and obtain its key. + * with the shortcut. */ QList shortcuts(); /** * Finds and loads the profile associated with - * the specified @p shortcut key sequence and returns - * its string key. + * the specified @p shortcut key sequence and returns a pointer to it. */ - QString findByShortcut(const QKeySequence& shortcut); + Profile::Ptr findByShortcut(const QKeySequence& shortcut); /** * Associates a shortcut with a particular profile. */ - void setShortcut(const QString& key , const QKeySequence& shortcut); + void setShortcut(Profile::Ptr profile , const QKeySequence& shortcut); /** Returns the shortcut associated with a particular profile. */ - QKeySequence shortcut(const QString& profileKey) const; + QKeySequence shortcut(Profile::Ptr profile) const; + + /** + * Registers a new type of session. + * The favorite status of the session ( as returned by isFavorite() ) is set to false by default. + */ + void addProfile(Profile::Ptr type); /** * Specifies whether a profile should be included in the user's * list of favorite sessions. */ - void setFavorite(const QString& key , bool favorite); + void setFavorite(Profile::Ptr profile , bool favorite); /** * Loads all available profiles. This involves reading each @@ -237,11 +227,11 @@ public: signals: /** Emitted when a profile is added to the manager. */ - void profileAdded(const QString& key); + void profileAdded(Profile::Ptr ptr); /** Emitted when a profile is removed from the manager. */ - void profileRemoved(const QString& key); + void profileRemoved(Profile::Ptr ptr); /** Emitted when a profile's properties are modified. */ - void profileChanged(const QString& key); + void profileChanged(Profile::Ptr ptr); /** * Emitted when a session's settings are updated to match @@ -252,18 +242,18 @@ signals: /** * Emitted when the favorite status of a profile changes. * - * @param key The key for the profile + * @param profile The profile to change * @param favorite Specifies whether the session is a favorite or not */ - void favoriteStatusChanged(const QString& key , bool favorite); + void favoriteStatusChanged(Profile::Ptr profile , bool favorite); /** * Emitted when the shortcut for a profile is changed. * - * @param key The key for the profile + * @param profile The profile whoose status was changed * @param newShortcut The new shortcut key sequence for the profile */ - void shortcutChanged(const QString& key , const QKeySequence& newShortcut); + void shortcutChanged(Profile::Ptr profile , const QKeySequence& newShortcut); protected Q_SLOTS: @@ -275,10 +265,11 @@ protected Q_SLOTS: void sessionTerminated( QObject* session ); private slots: - void sessionProfileChanged(); void sessionProfileCommandReceived(const QString& text); private: + + // loads the mappings between shortcut key sequences and // profile paths void loadShortcuts(); @@ -294,33 +285,34 @@ private: // returns the path to which the profile was saved, which will // be the same as the path property of profile if valid or a newly generated path // otherwise - QString saveProfile(Profile* profile); + QString saveProfile(Profile::Ptr profile); - // applies updates to the profile associated with @p key + // applies updates to a profile // to all sessions currently using that profile // if modifiedPropertiesOnly is true, only properties which // are set in the profile @p key are updated - void applyProfile(const QString& key , bool modifiedPropertiesOnly); + void applyProfile(Profile::Ptr ptr , bool modifiedPropertiesOnly); // apples updates to the profile @p info to the session @p session // if modifiedPropertiesOnly is true, only properties which // are set in @p info are update ( ie. properties for which info->isPropertySet() // returns true ) - void applyProfile(Session* session , const Profile* info , bool modifiedPropertiesOnly); + void applyProfile(Session* session , const Profile::Ptr info , bool modifiedPropertiesOnly); + + QSet _types; + QHash _sessionProfiles; - QHash _types; // profile key -> Profile instance - struct ShortcutData { - QString profileKey; + Profile::Ptr profileKey; QString profilePath; }; QMap _shortcuts; // shortcut keys -> profile path QList _sessions; // list of running sessions - QString _defaultProfile; // profile key of default profile + Profile::Ptr _defaultProfile; - QSet _favorites; // list of profile keys for favorite profiles + QSet _favorites; // list of favorite profiles bool _loadedAllProfiles; // set to true after loadAllProfiles has been called @@ -330,7 +322,7 @@ private: class ShouldApplyProperty { public: - ShouldApplyProperty(const Profile* profile , bool modifiedOnly) : + ShouldApplyProperty(const Profile::Ptr profile , bool modifiedOnly) : _profile(profile) , _modifiedPropertiesOnly(modifiedOnly) {} bool shouldApply(Profile::Property property) const @@ -338,9 +330,31 @@ public: return !_modifiedPropertiesOnly || _profile->isPropertySet(property); } private: - const Profile* _profile; + const Profile::Ptr _profile; bool _modifiedPropertiesOnly; }; +/** + * PopStackOnExit is a utility to remove all values from a stack which are added during + * the lifetime of a PopStackOnExit instance. + * + * When a PopStackOnExit instance is destroyed, elements are removed from the stack + * until the stack count is reduced the value when the PopStackOnExit instance was created. + */ +template +class PopStackOnExit +{ +public: + PopStackOnExit(QStack& stack) : _stack(stack) , _count(stack.count()) {} + ~PopStackOnExit() + { + while (_stack.count() > _count) + _stack.pop(); + } +private: + QStack& _stack; + int _count; +}; + } #endif //SESSIONMANAGER_H diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 5120845ec..d87038446 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -78,8 +78,8 @@ ViewManager::ViewManager(QObject* parent , KActionCollection* collection) SLOT(containerViewsChanged(QObject*)) ); // listen for profile changes - connect( SessionManager::instance() , SIGNAL(profileChanged(const QString&)) , this, - SLOT(profileChanged(const QString&)) ); + connect( SessionManager::instance() , SIGNAL(profileChanged(Profile::Ptr)) , this, + SLOT(profileChanged(Profile::Ptr)) ); connect( SessionManager::instance() , SIGNAL(sessionUpdated(Session*)) , this, SLOT(updateViewsForSession(Session*)) ); } @@ -381,7 +381,7 @@ void ViewManager::splitView(Qt::Orientation orientation) { Session* session = _sessionMap[(TerminalDisplay*)existingViewIter.next()]; TerminalDisplay* display = createTerminalDisplay(session); - applyProfile(display,session->profileKey()); + applyProfile(display,SessionManager::instance()->sessionProfile(session)); ViewProperties* properties = createController(session,display); _sessionMap[display] = session; @@ -389,7 +389,7 @@ void ViewManager::splitView(Qt::Orientation orientation) // create a container using settings from the first // session in the previous container if ( !container ) - container = createContainer(session->profileKey()); + container = createContainer(SessionManager::instance()->sessionProfile(session)); container->addView(display,properties); session->addView( display ); @@ -496,7 +496,7 @@ void ViewManager::createView(Session* session) // create the default container if (_viewSplitter->containers().count() == 0) { - _viewSplitter->addContainer( createContainer(session->profileKey()) , + _viewSplitter->addContainer( createContainer(SessionManager::instance()->sessionProfile(session)) , Qt::Vertical ); emit splitViewToggle(false); } @@ -515,7 +515,7 @@ void ViewManager::createView(Session* session) { ViewContainer* container = containerIter.next(); TerminalDisplay* display = createTerminalDisplay(session); - applyProfile(display,session->profileKey()); + applyProfile(display,SessionManager::instance()->sessionProfile(session)); // set initial size display->setSize(80,40); @@ -527,7 +527,8 @@ void ViewManager::createView(Session* session) session->addView(display); // tell the session whether it has a light or dark background - session->setDarkBackground( colorSchemeForProfile(session->profileKey())->hasDarkBackground() ); + const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); + session->setDarkBackground( colorSchemeForProfile(profile)->hasDarkBackground() ); if ( container == activeContainer ) { @@ -539,10 +540,8 @@ void ViewManager::createView(Session* session) updateDetachViewState(); } -ViewContainer* ViewManager::createContainer(const QString& profileKey) +ViewContainer* ViewManager::createContainer(const Profile::Ptr info) { - const Profile* info = SessionManager::instance()->profile(profileKey); - Q_ASSERT( info ); const int tabPosition = info->property(Profile::TabBarPosition); @@ -655,10 +654,8 @@ TerminalDisplay* ViewManager::createTerminalDisplay(Session* session) return display; } -const ColorScheme* ViewManager::colorSchemeForProfile(const QString& profileKey) const +const ColorScheme* ViewManager::colorSchemeForProfile(const Profile::Ptr info) const { - Profile* info = SessionManager::instance()->profile(profileKey); - const ColorScheme* colorScheme = ColorSchemeManager::instance()-> findColorScheme(info->colorScheme()); if ( !colorScheme ) @@ -668,13 +665,11 @@ const ColorScheme* ViewManager::colorSchemeForProfile(const QString& profileKey) return colorScheme; } -void ViewManager::applyProfile(TerminalDisplay* view , const QString& profileKey) +void ViewManager::applyProfile(TerminalDisplay* view , const Profile::Ptr info ) { - Profile* info = SessionManager::instance()->profile(profileKey); - Q_ASSERT( info ); - const ColorScheme* colorScheme = colorSchemeForProfile(profileKey); + const ColorScheme* colorScheme = colorSchemeForProfile(info); // menu bar visibility emit setMenuBarVisibleRequest( info->property(Profile::ShowMenuBar) ); @@ -751,11 +746,11 @@ void ViewManager::updateViewsForSession(Session* session) QListIterator iter(_sessionMap.keys(session)); while ( iter.hasNext() ) { - applyProfile(iter.next(),session->profileKey()); + applyProfile(iter.next(),SessionManager::instance()->sessionProfile(session)); } } -void ViewManager::profileChanged(const QString& key) +void ViewManager::profileChanged(Profile::Ptr profile) { QHashIterator iter(_sessionMap); @@ -764,9 +759,11 @@ void ViewManager::profileChanged(const QString& key) iter.next(); // if session uses this profile, update the display - if ( iter.key() != 0 && iter.value() != 0 && iter.value()->profileKey() == key ) + if ( iter.key() != 0 && + iter.value() != 0 && + SessionManager::instance()->sessionProfile(iter.value()) == profile ) { - applyProfile(iter.key(),key); + applyProfile(iter.key(),profile); } } } diff --git a/src/ViewManager.h b/src/ViewManager.h index 2777d5fe7..12c87caea 100644 --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -25,6 +25,9 @@ #include #include +// Konsole +#include "Profile.h" + class QSignalMapper; class KActionCollection; @@ -84,7 +87,7 @@ public: * Applies the view-specific settings associated with specified @p profile * to the terminal display @p view. */ - void applyProfile(TerminalDisplay* view , const QString& profile); + void applyProfile(TerminalDisplay* view , const Profile::Ptr profile); /** * Return the main widget for the view manager which @@ -226,7 +229,7 @@ private slots: void containerViewsChanged(QObject* container); // called when a profile changes - void profileChanged(const QString& key); + void profileChanged(Profile::Ptr profile); void updateViewsForSession(Session* session); @@ -242,7 +245,7 @@ private slots: void controllerChanged(SessionController* controller); private: - const ColorScheme* colorSchemeForProfile(const QString& key) const; + const ColorScheme* colorSchemeForProfile(const Profile::Ptr profile) const; void setupActions(); void focusActiveView(); @@ -255,9 +258,9 @@ private: void splitView(Qt::Orientation orientation); // creates a new container which can hold terminal displays - // 'key' specifies the profile to use to get initial + // 'profile' specifies the profile to use to get initial // settings (eg. navigation position) for the container - ViewContainer* createContainer(const QString& profileKey); + ViewContainer* createContainer(const Profile::Ptr profile); // removes a container and emits appropriate signals void removeContainer(ViewContainer* container);