Bug 213370 - Channel Settings dialog fails to refresh topic information upon subsequent openings
Summary: Channel Settings dialog fails to refresh topic information upon subsequent op...
Status: RESOLVED FIXED
Alias: None
Product: konversation
Classification: Applications
Component: general (show other bugs)
Version: 1.2
Platform: Gentoo Packages Unspecified
: NOR normal
Target Milestone: ---
Assignee: Konversation Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-06 05:09 UTC by Luke-Jr
Modified: 2010-07-01 16:19 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luke-Jr 2009-11-06 05:09:01 UTC
Version:           1.2 (using KDE 4.3.2)
Installed from:    Gentoo Packages

[22:02:03] <luke-jr> Channel Settings dialog doesn't reset its copy of the topic when someone else changes it, so if I go in there to change modes, it accidentally resets the topic too..
Comment 1 Eike Hein 2009-11-07 02:51:34 UTC
Ok, here's some background on this:

1. Whenever the client receives channel topic data (i.e. on channel join or when someone changes the channel topic), the topic history list in the dialog is updated. The same code is apparently also run whenever the dialog is constructed.

2. When someone changes the channel topic and a new item is added to the list, the selection changes to that new item. The upper text widget in the dialog always shows the topic currently selected in the list, and thus changes accordingly.

3. When the text in the lower text widget in the dialog is changed, a bool m_editingTopic is set to true.

4. During #1, the lower text widget in the dialog is set to the first item in the topic history list only if the history is not empty (duh) and m_editingTopic is not true.

5. m_editingTopic is set to false only when the dialog is cancelled.


IOW, the reason for this problem is that code was written to avoid topic changes interfering with the user editing the topic himself in the lower text widget, but there are two problems:

- The protection is overzealous: It appears that #4 alone causes #3, not just user-originated changes to the widget's contents. This means that when someone changes the topic while the dialog is open, the topic in the lower text widget will not be updated, even when the user hasn't actually touched the widget (the list and upper text widgets update correctly, however).

- m_editingTopic isn't reset to false when the dialog is closed with "Ok". So when the user 1. edits the topic in the dialog (or some mode), 2. then OK's it, 3. then someone else changes the topic and 4. the user subsequently reopens the dialog, the lower text widget will still show the contents from when it was opened and OK'd previously.

The bottom line here is probably that the behavior should be changed so that the two text widgets update in sync with the selection in the list unless the user has actually modified the contents of the lower text widget, and that closing the dialog in any way (i.e. both OK and Cancel, where Cancel includes closing the window) should make it forget that the user has modified the lower text widget.
Comment 2 Eike Hein 2009-11-07 03:29:34 UTC
SVN commit 1045997 by hein:

* Making and then comitting unrelated changes in the Channel Settings
  dialog could cause unintentionally setting the channel's topic to an
  older version if someone else had changed the topic since the first
  time the dialog was opened or while the dialog was open, due to a bug
  in the code that avoids such external topic changes interfering with
  concurrent local editing of the topic. This has been fixed.
* The contents of the topic edit field in the Channel Settings dialog
  will now reflect the selected item in the topic history list until
  the user starts editing.

(Ended up abusing QTextEdit::undoAvailable() to get something akin to
QLineEdit::textEdited() for QTextEdit, and QTextEdit::clear() to flush
the undo history at dialog close to kick the selection->textedit sync
back into gear for the next dialog open.)

BUG:213370


 M  +9 -0      ChangeLog  
 M  +11 -8     src/irc/channeloptionsdialog.cpp  
 M  +1 -1      src/irc/channeloptionsdialog.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1045997
Comment 3 Eike Hein 2010-07-01 16:19:47 UTC
commit 59311d2101064ab86611d72d94844dbb25f74e96
Author: Eike Hein <hein@kde.org>
Date:   Sat Nov 7 02:29:31 2009 +0000

    * Making and then comitting unrelated changes in the Channel Settings
      dialog could cause unintentionally setting the channel's topic to an
      older version if someone else had changed the topic since the first
      time the dialog was opened or while the dialog was open, due to a bug
      in the code that avoids such external topic changes interfering with
      concurrent local editing of the topic. This has been fixed.
    * The contents of the topic edit field in the Channel Settings dialog
      will now reflect the selected item in the topic history list until
      the user starts editing.
    
    (Ended up abusing QTextEdit::undoAvailable() to get something akin to
    QLineEdit::textEdited() for QTextEdit, and QTextEdit::clear() to flush
    the undo history at dialog close to kick the selection->textedit sync
    back into gear for the next dialog open.)
    
    BUG:213370
    
    svn path=/trunk/extragear/network/konversation/; revision=1045997

diff --git a/ChangeLog b/ChangeLog
index c25aee4..166c1f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -30,6 +30,15 @@ Changes since 1.2:
   the "Downloads paths" configured in System Settings or the equivalent
   in other desktop environments (under the hood, this is a shared XDG
   setting).
+* Making and then comitting unrelated changes in the Channel Settings
+  dialog could cause unintentionally setting the channel's topic to an
+  older version if someone else had changed the topic since the first
+  time the dialog was opened or while the dialog was open, due to a bug
+  in the code that avoids such external topic changes interfering with
+  concurrent local editing of the topic. This has been fixed.
+* The contents of the topic edit field in the Channel Settings dialog
+  will now reflect the selected item in the topic history list until
+  the user starts editing.
 
 
 Changes from 1.2-rc1 to 1.2:
diff --git a/src/irc/channeloptionsdialog.cpp b/src/irc/channeloptionsdialog.cpp
index 68b19f2..4fc7a26 100644
--- a/src/irc/channeloptionsdialog.cpp
+++ b/src/irc/channeloptionsdialog.cpp
@@ -54,7 +54,8 @@ namespace Konversation
         connect(m_ui.topicHistoryView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
                 this, SLOT(topicHistoryItemClicked(const QItemSelection&)));
         connect(m_ui.toggleAdvancedModes, SIGNAL(clicked()), this, SLOT(toggleAdvancedModes()));
-        connect(m_ui.topicEdit, SIGNAL(textChanged()), this, SLOT(topicBeingEdited()));
+        connect(m_ui.topicEdit, SIGNAL(undoAvailable(bool)), this, SLOT(topicBeingEdited(bool)));
+        connect(this, SIGNAL(finished()), m_ui.topicEdit, SLOT(clear()));
 
         connect(m_channel, SIGNAL(topicHistoryChanged()), this, SLOT(refreshTopicHistory()));
 
@@ -159,9 +160,9 @@ namespace Konversation
         }
     }
 
-    void ChannelOptionsDialog::topicBeingEdited()
+    void ChannelOptionsDialog::topicBeingEdited(bool edited)
     {
-        m_editingTopic = true;
+        m_editingTopic = edited;
     }
 
     QString ChannelOptionsDialog::topic()
@@ -190,22 +191,25 @@ namespace Konversation
         // update topic preview
         QItemSelection selection(m_topicModel->index(0, 0, QModelIndex()), m_topicModel->index(0, 1, QModelIndex()));
         m_ui.topicHistoryView->selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect);
-        // don't destroy the user's edit box if they started editing
-        if(!m_editingTopic && !history.isEmpty())
-            m_ui.topicEdit->setText(history.first().section(' ', 2));
     }
 
     void ChannelOptionsDialog::topicHistoryItemClicked(const QItemSelection& selection)
     {
-        if(!selection.isEmpty())
+        if (!selection.isEmpty())
         {
             // update topic preview
             m_ui.topicPreview->setText(m_topicModel->data(selection.indexes().first(), Qt::UserRole).toString());
+
+            if (!m_editingTopic)
+                m_ui.topicEdit->setText(m_topicModel->data(selection.indexes().first(), Qt::UserRole).toString());
         }
         else
         {
             // clear topic preview
             m_ui.topicPreview->clear();
+
+            if (!m_editingTopic)
+                m_ui.topicEdit->clear();
         }
     }
 
@@ -480,7 +484,6 @@ namespace Konversation
             QApplication::sendEvent(m_ui.banList->renameLineEdit(), &e);
         }
 
-        m_editingTopic = false;
         hide();
     }
 
diff --git a/src/irc/channeloptionsdialog.h b/src/irc/channeloptionsdialog.h
index d41debb..1dc5a57 100644
--- a/src/irc/channeloptionsdialog.h
+++ b/src/irc/channeloptionsdialog.h
@@ -64,7 +64,7 @@ namespace Konversation
 
         protected slots:
             void topicHistoryItemClicked(const QItemSelection& selection);
-            void topicBeingEdited();
+            void topicBeingEdited(bool edited);
 
             void cancelClicked();
             void okClicked();