Change the logic of the IRC widget to only show the "Edit Topic" button, if the user is allowed to do so. 5_3_x

Sat, 02 Mar 2013 19:06:18 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 02 Mar 2013 19:06:18 +0100
branch
5_3_x
changeset 2448
9bf183ba828d
parent 2443
df6c0224305f
child 2449
b5b9d235e2cd

Change the logic of the IRC widget to only show the "Edit Topic" button, if the user is allowed to do so.
(grafted from e3fadb2b85c7df5949a316b3b21cbfea2bbcaa50)

Network/IRC/IrcChannelWidget.py file | annotate | diff | comparison | revisions
--- a/Network/IRC/IrcChannelWidget.py	Sat Mar 02 15:45:29 2013 +0100
+++ b/Network/IRC/IrcChannelWidget.py	Sat Mar 02 19:06:18 2013 +0100
@@ -161,6 +161,16 @@
             privilege |= IrcUserItem.Away
         self.__privilege = privilege
         self.__setIcon()
+    
+    def canChangeTopic(self):
+        """
+        Public method to check, if the user is allowed to change the topic.
+        
+        @return flag indicating that the topic can be changed (boolean)
+        """
+        return(bool(self.__privilege & IrcUserItem.Operator) or \
+               bool(self.__privilege & IrcUserItem.Admin) or \
+               bool(self.__privilege & IrcUserItem.Owner))
 
 
 class IrcChannelWidget(QWidget, Ui_IrcChannelWidget):
@@ -197,6 +207,7 @@
         self.__ircWidget = parent
         
         self.editTopicButton.setIcon(UI.PixmapCache.getIcon("ircEditTopic.png"))
+        self.editTopicButton.hide()
         
         height = self.usersList.height() + self.messages.height()
         self.splitter.setSizes([height * 0.3, height * 0.7])
@@ -617,10 +628,12 @@
                     itm = IrcUserItem(userName, self.usersList)
                 for privilege in userPrivileges:
                     itm.changePrivilege(privilege)
+            
+            self.__setEditTopicButton()
             return True
         
         return False
-    
+
     def __userAway(self, match):
         """
         Private method to handle a topic change of the channel.
@@ -888,6 +901,7 @@
             itm = self.__findUser(match.group(4))
             if itm:
                 itm.changePrivilege(match.group(3))
+                self.__setEditTopicButton()
             self.__addManagementMessage(IrcChannelWidget.MessageIndicator,
                 self.trUtf8("{0} sets mode for {1}: {2}.").format(
                     match.group(1), match.group(4), match.group(3)))
@@ -1659,6 +1673,14 @@
         
         return False
     
+    def __setEditTopicButton(self):
+        """
+        Private method to set the visibility of the Edit Topic button.
+        """
+        itm = self.__findUser(self.__userName)
+        if itm:
+            self.editTopicButton.setVisible(itm.canChangeTopic())
+    
     @pyqtSlot()
     def on_editTopicButton_clicked(self):
         """

eric ide

mercurial