[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [konsole] src: Prevent the opening of two or more "edit profile dialogs" per session.
From:       Francesco Cecconi <francesco.cecconi () gmail ! com>
Date:       2013-03-14 16:47:07
Message-ID: 20130314164707.A4CF9A604F () git ! kde ! org
[Download RAW message or body]

Git commit c45d07698fc68522e94c082e638156a9ef94a438 by Francesco Cecconi.
Committed on 14/03/2013 at 17:40.
Pushed by cecconi into branch 'master'.

Prevent the opening of two or more "edit profile dialogs" per session.

Fixing the wrong behaviour to open two or more "edit dialog" for
one session/tab with the same profile, and the crash with two or
more "edit dialog", one for different session(tabs) with the same profile.

BUG: 311270
REVIEW: 107640
FIXED-IN: 4.11

M  +1    -2    src/EditProfileDialog.h
M  +22   -1    src/ManageProfilesDialog.cpp
M  +26   -3    src/SessionController.cpp
M  +4    -0    src/SessionController.h
M  +5    -0    src/TerminalDisplay.cpp
M  +1    -1    src/TerminalDisplay.h

http://commits.kde.org/konsole/c45d07698fc68522e94c082e638156a9ef94a438

diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h
index 30d72e5..33b3930 100644
--- a/src/EditProfileDialog.h
+++ b/src/EditProfileDialog.h
@@ -84,6 +84,7 @@ public:
      * and make it easy for them to change it.
      */
     void selectProfileName();
+    const Profile::Ptr lookupProfile() const;
 
 public slots:
     // reimplemented
@@ -231,8 +232,6 @@ private:
     };
     void setupCheckBoxes(BooleanOption* options , const Profile::Ptr profile);
 
-    const Profile::Ptr lookupProfile() const;
-
     Ui::EditProfileDialog* _ui;
     Profile::Ptr _tempProfile;
     Profile::Ptr _profile;
diff --git a/src/ManageProfilesDialog.cpp b/src/ManageProfilesDialog.cpp
index 3b270dc..7701b3f 100644
--- a/src/ManageProfilesDialog.cpp
+++ b/src/ManageProfilesDialog.cpp
@@ -32,6 +32,10 @@
 // Konsole
 #include "EditProfileDialog.h"
 #include "ProfileManager.h"
+#include "Session.h"
+#include "TerminalDisplay.h"
+#include "SessionManager.h"
+#include "SessionController.h"
 #include "ui_ManageProfilesDialog.h"
 
 using namespace Konsole;
@@ -344,10 +348,27 @@ void ManageProfilesDialog::createProfile()
 }
 void ManageProfilesDialog::editSelected()
 {
+    QList<Profile::Ptr> profiles(selectedProfiles());
+
+    foreach (Session* session, SessionManager::instance()->sessions()) {
+         foreach (TerminalDisplay* terminal, session->views()) {
+             // Searching for opened profiles
+             if (terminal->sessionController()->profileDialogPointer() != NULL) {
+                 foreach (const Profile::Ptr & profile, profiles) {
+                     if (profile->name() == \
terminal->sessionController()->profileDialogPointer()->lookupProfile()->name() +      \
&& terminal->sessionController()->profileDialogPointer()->isVisible()) { +            \
// close opened edit dialog +                         \
terminal->sessionController()->profileDialogPointer()->close(); +                     \
} +                 }
+             }
+         }
+    }
+
     EditProfileDialog dialog(this);
     // the dialog will delete the profile group when it is destroyed
     ProfileGroup* group = new ProfileGroup;
-    foreach(const Profile::Ptr & profile, selectedProfiles()) {
+    foreach (const Profile::Ptr & profile, profiles) {
         group->addProfile(profile);
     }
     group->updateValues();
diff --git a/src/SessionController.cpp b/src/SessionController.cpp
index 25eb1ef..88fc50c 100644
--- a/src/SessionController.cpp
+++ b/src/SessionController.cpp
@@ -218,6 +218,10 @@ SessionController::~SessionController()
         _view->setScreenWindow(0);
 
     _allControllers.remove(this);
+
+    if (!_editProfileDialog.isNull()) {
+        delete _editProfileDialog.data();
+    }
 }
 void SessionController::trackOutput(QKeyEvent* event)
 {
@@ -783,12 +787,31 @@ void SessionController::changeCodec(QTextCodec* codec)
     _session->setCodec(codec);
 }
 
+EditProfileDialog* SessionController::profileDialogPointer()
+{
+    return _editProfileDialog.data();
+}
+
 void SessionController::editCurrentProfile()
 {
-    EditProfileDialog* dialog = new EditProfileDialog(QApplication::activeWindow());
+    // Searching for Edit profile dialog opened with the same profile
+    foreach (SessionController* session, _allControllers.values()) {
+        if (session->profileDialogPointer()
+                && session->profileDialogPointer()->isVisible()
+                && session->profileDialogPointer()->lookupProfile() == \
SessionManager::instance()->sessionProfile(_session)) { +            \
session->profileDialogPointer()->close(); +        }
+    }
+
+    // NOTE bug311270: For to prevent the crash, the profile must be reset.
+    if (!_editProfileDialog.isNull()) {
+        // exists but not visible
+        delete _editProfileDialog.data();
+    }
 
-    dialog->setProfile(SessionManager::instance()->sessionProfile(_session));
-    dialog->show();
+    _editProfileDialog = new EditProfileDialog(QApplication::activeWindow());
+    _editProfileDialog.data()->setProfile(SessionManager::instance()->sessionProfile(_session));
 +    _editProfileDialog.data()->show();
 }
 
 void SessionController::renameSession()
diff --git a/src/SessionController.h b/src/SessionController.h
index 97020fa..036e053 100644
--- a/src/SessionController.h
+++ b/src/SessionController.h
@@ -62,6 +62,7 @@ class IncrementalSearchBar;
 class ProfileList;
 class UrlFilter;
 class RegExpFilter;
+class EditProfileDialog;
 
 // SaveHistoryTask
 class TerminalCharacterDecoder;
@@ -144,6 +145,8 @@ public:
      */
     void setShowMenuAction(QAction* action);
 
+    EditProfileDialog* profileDialogPointer();
+
     // reimplemented
     virtual KUrl url() const;
     virtual QString currentDir() const;
@@ -340,6 +343,7 @@ private:
     QStringList _bookmarkValidProgramsToClear;
 
     bool _isSearchBarEnabled;
+    QWeakPointer<EditProfileDialog> _editProfileDialog;
 
     QString _searchText;
 };
diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp
index 8016c1e..285a249 100644
--- a/src/TerminalDisplay.cpp
+++ b/src/TerminalDisplay.cpp
@@ -3105,6 +3105,11 @@ void TerminalDisplay::setSessionController(SessionController* \
controller)  _sessionController = controller;
 }
 
+SessionController* TerminalDisplay::sessionController()
+{
+    return _sessionController;
+}
+
 AutoScrollHandler::AutoScrollHandler(QWidget* parent)
     : QObject(parent)
     , _timerId(0)
diff --git a/src/TerminalDisplay.h b/src/TerminalDisplay.h
index 46058be..1800945 100644
--- a/src/TerminalDisplay.h
+++ b/src/TerminalDisplay.h
@@ -51,7 +51,6 @@ namespace Konsole
 class FilterChain;
 class TerminalImageFilterChain;
 class SessionController;
-
 /**
  * A widget which displays output from a terminal emulation and sends input \
                keypresses and mouse activity
  * to the terminal.
@@ -217,6 +216,7 @@ public:
     uint lineSpacing() const;
 
     void setSessionController(SessionController* controller);
+    SessionController* sessionController();
 
     /**
      * Sets the shape of the keyboard cursor.  This is the cursor drawn


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic