eric6/Cooperation/ChatWidget.py

Mon, 15 Apr 2019 19:53:29 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 15 Apr 2019 19:53:29 +0200
branch
setup.py
changeset 6949
a5255f1ba3f0
parent 6942
2602857055c5
child 7229
53054eb5b15a
permissions
-rw-r--r--

setup.py: continued implementing support for setup.py.

149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the chat dialog.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2436
diff changeset
11
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
12 from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal, QDateTime, QPoint, QFileInfo
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
13 from PyQt5.QtGui import QColor
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
14 from PyQt5.QtWidgets import QWidget, QListWidgetItem, QMenu, QApplication
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
16 from E5Gui.E5Application import e5App
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
17 from E5Gui import E5MessageBox, E5FileDialog
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
18
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
19 from Globals import recentNameHosts
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
20
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 from .CooperationClient import CooperationClient
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 from .Ui_ChatWidget import Ui_ChatWidget
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 import Preferences
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
26 import Utilities
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 import UI.PixmapCache
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
29
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 class ChatWidget(QWidget, Ui_ChatWidget):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Class implementing the chat dialog.
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
33
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
34 @signal connected(connected) emitted to signal a change of the connected
501
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 165
diff changeset
35 state (bool)
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
36 @signal editorCommand(hashStr, filename, message) emitted when an editor
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
37 command has been received (string, string, string)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
38 @signal shareEditor(share) emitted to signal a share is requested (bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
39 @signal startEdit() emitted to start a shared edit session
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
40 @signal sendEdit() emitted to send a shared edit session
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
41 @signal cancelEdit() emitted to cancel a shared edit session
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
43 connected = pyqtSignal(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
44 editorCommand = pyqtSignal(str, str, str)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
45
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
46 shareEditor = pyqtSignal(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
47 startEdit = pyqtSignal()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
48 sendEdit = pyqtSignal()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
49 cancelEdit = pyqtSignal()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
50
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
51 def __init__(self, ui, port=-1, parent=None):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 Constructor
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
55 @param ui reference to the user interface object (UserInterface)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @param port port to be used for the cooperation server (integer)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @param parent reference to the parent widget (QWidget)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2436
diff changeset
59 super(ChatWidget, self).__init__(parent)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.setupUi(self)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
62 self.shareButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
63 UI.PixmapCache.getIcon("sharedEditDisconnected.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
64 self.startEditButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
65 UI.PixmapCache.getIcon("sharedEditStart.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
66 self.sendEditButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
67 UI.PixmapCache.getIcon("sharedEditSend.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
68 self.cancelEditButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
69 UI.PixmapCache.getIcon("sharedEditCancel.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
70
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
71 self.__ui = ui
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
72 self.__client = CooperationClient(self)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__myNickName = self.__client.nickName()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
75 self.__initChatMenu()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
76 self.__initUsersMenu()
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
77
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.messageEdit.returnPressed.connect(self.__handleMessage)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.sendButton.clicked.connect(self.__handleMessage)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.__client.newMessage.connect(self.appendMessage)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.__client.newParticipant.connect(self.__newParticipant)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.__client.participantLeft.connect(self.__participantLeft)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.__client.connectionError.connect(self.__showErrorMessage)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.__client.cannotConnect.connect(self.__initialConnectionRefused)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
85 self.__client.editorCommand.connect(self.__editorCommandMessage)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
87 self.serverButton.setText(self.tr("Start Server"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 self.serverLed.setColor(QColor(Qt.red))
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 if port == -1:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 port = Preferences.getCooperation("ServerPort")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.serverPortSpin.setValue(port)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.__setConnected(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 if Preferences.getCooperation("AutoStartServer"):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self.on_serverButton_clicked()
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
98
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
99 self.recent = []
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
100 self.__loadHostsHistory()
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
101
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
102 def __loadHostsHistory(self):
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
103 """
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
104 Private method to load the recently connected hosts.
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
105 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
106 self.__recent = []
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
107 Preferences.Prefs.rsettings.sync()
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
108 rh = Preferences.Prefs.rsettings.value(recentNameHosts)
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
109 if rh is not None:
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
110 self.__recent = rh[:20]
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
111 self.hostEdit.clear()
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
112 self.hostEdit.addItems(self.__recent)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
113 self.hostEdit.clearEditText()
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
114
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
115 def __saveHostsHistory(self):
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
116 """
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
117 Private method to save the list of recently connected hosts.
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
118 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
119 Preferences.Prefs.rsettings.setValue(recentNameHosts, self.__recent)
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
120 Preferences.Prefs.rsettings.sync()
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
121
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
122 def __setHostsHistory(self, host):
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
123 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
124 Private method to remember the given host as the most recent entry.
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
125
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
126 @param host host entry to remember (string)
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
127 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
128 if host in self.__recent:
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
129 self.__recent.remove(host)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
130 self.__recent.insert(0, host)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
131 self.__saveHostsHistory()
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
132 self.hostEdit.clear()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
133 self.hostEdit.addItems(self.__recent)
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
134
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
135 def __clearHostsHistory(self):
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
136 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
137 Private slot to clear the hosts history.
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
138 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
139 self.__recent = []
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
140 self.__saveHostsHistory()
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
141 self.hostEdit.clear()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
142 self.hostEdit.addItems(self.__recent)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 def __handleMessage(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 Private slot handling the Return key pressed in the message edit.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 text = self.messageEdit.text()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 if text == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 if text.startswith("/"):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 self.__showErrorMessage(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
154 self.tr("! Unknown command: {0}\n")
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
155 .format(text.split()[0]))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 else:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 self.__client.sendMessage(text)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self.appendMessage(self.__myNickName, text)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.messageEdit.clear()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 def __newParticipant(self, nick):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 Private slot handling a new participant joining.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 @param nick nick name of the new participant (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 if nick == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 color = self.chatEdit.textColor()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 self.chatEdit.setTextColor(Qt.gray)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
174 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
175 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
176 self.chatEdit.append(self.tr("* {0} has joined.\n").format(nick))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 self.chatEdit.setTextColor(color)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 QListWidgetItem(
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 UI.PixmapCache.getIcon(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
181 "chatUser{0}.png".format(1 + self.usersList.count() % 6)),
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 nick, self.usersList)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 if not self.__connected:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 self.__setConnected(True)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
186
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
187 if not self.isVisible():
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
188 self.__ui.showNotification(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
189 UI.PixmapCache.getPixmap("cooperation48.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
190 self.tr("New User"), self.tr("{0} has joined.")
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
191 .format(nick))
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
192
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 def __participantLeft(self, nick):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 Private slot handling a participant leaving the session.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 @param nick nick name of the participant (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 if nick == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 items = self.usersList.findItems(nick, Qt.MatchExactly)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 for item in items:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 self.usersList.takeItem(self.usersList.row(item))
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 del item
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 color = self.chatEdit.textColor()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 self.chatEdit.setTextColor(Qt.gray)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
210 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
211 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
212 self.chatEdit.append(self.tr("* {0} has left.\n").format(nick))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 self.chatEdit.setTextColor(color)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 if not self.__client.hasConnections():
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 self.__setConnected(False)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
217
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
218 if not self.isVisible():
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
219 self.__ui.showNotification(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
220 UI.PixmapCache.getPixmap("cooperation48.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
221 self.tr("User Left"), self.tr("{0} has left.")
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
222 .format(nick))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 def appendMessage(self, from_, message):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 Public slot to append a message to the display.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 @param from_ originator of the message (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 @param message message to be appended (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 if from_ == "" or message == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 self.chatEdit.append(
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
235 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 " <" + from_ + ">:")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 self.chatEdit.append(message + "\n")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 bar = self.chatEdit.verticalScrollBar()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 bar.setValue(bar.maximum())
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
240
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
241 if not self.isVisible():
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
242 self.__ui.showNotification(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
243 UI.PixmapCache.getPixmap("cooperation48.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
244 self.tr("Message from <{0}>").format(from_), message)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 @pyqtSlot(str)
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
247 def on_hostEdit_editTextChanged(self, host):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 Private slot handling the entry of a host to connect to.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 @param host host to connect to (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 if not self.__connected:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 self.connectButton.setEnabled(host != "")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
256 def __getConnectionParameters(self):
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
257 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
258 Private method to determine the connection parameters.
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
259
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
260 @return tuple with hostname and port (string, integer)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
261 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
262 hostEntry = self.hostEdit.currentText()
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
263 if "@" in hostEntry:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
264 host, port = hostEntry.split("@")
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
265 try:
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
266 port = int(port)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
267 except ValueError:
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
268 port = Preferences.getCooperation("ServerPort")
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
269 self.hostEdit.setEditText("{0}@{1}".format(host, port))
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
270 else:
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
271 host = hostEntry
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
272 port = Preferences.getCooperation("ServerPort")
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
273 self.hostEdit.setEditText("{0}@{1}".format(host, port))
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
274 return host, port
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
275
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 @pyqtSlot()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 def on_connectButton_clicked(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 Private slot initiating the connection.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 if not self.__connected:
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
282 host, port = self.__getConnectionParameters()
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
283 self.__setHostsHistory(self.hostEdit.currentText())
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
284 if not self.__client.isListening():
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 self.on_serverButton_clicked()
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
286 if self.__client.isListening():
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
287 self.__client.connectToHost(host, port)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 self.__setConnected(True)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 else:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 self.__client.disconnectConnections()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 self.__setConnected(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 @pyqtSlot()
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
294 def on_clearHostsButton_clicked(self):
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
295 """
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
296 Private slot to clear the hosts list.
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
297 """
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
298 self.__clearHostsHistory()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
299
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
300 @pyqtSlot()
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 def on_serverButton_clicked(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 Private slot to start the server.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 """
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
305 if self.__client.isListening():
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
306 self.__client.close()
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
307 self.serverButton.setText(self.tr("Start Server"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 self.serverPortSpin.setEnabled(True)
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
309 if (self.serverPortSpin.value() !=
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
310 Preferences.getCooperation("ServerPort")):
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
311 self.serverPortSpin.setValue(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
312 Preferences.getCooperation("ServerPort"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 self.serverLed.setColor(QColor(Qt.red))
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 else:
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
315 res, port = self.__client.startListening(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
316 self.serverPortSpin.value())
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 if res:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
318 self.serverButton.setText(self.tr("Stop Server"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 self.serverPortSpin.setValue(port)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 self.serverPortSpin.setEnabled(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 self.serverLed.setColor(QColor(Qt.green))
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 else:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 self.__showErrorMessage(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
324 self.tr("! Server Error: {0}\n").format(
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
325 self.__client.errorString())
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 )
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 def __setConnected(self, connected):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 Private slot to set the connected state.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 @param connected new connected state (boolean)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 if connected:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
335 self.connectButton.setText(self.tr("Disconnect"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 self.connectButton.setEnabled(True)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 self.connectionLed.setColor(QColor(Qt.green))
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
339 self.connectButton.setText(self.tr("Connect"))
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
340 self.connectButton.setEnabled(self.hostEdit.currentText() != "")
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 self.connectionLed.setColor(QColor(Qt.red))
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
342 self.on_cancelEditButton_clicked()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
343 self.shareButton.setChecked(False)
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
344 self.on_shareButton_clicked(False)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
345 self.__connected = connected
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
346 self.hostEdit.setEnabled(not connected)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
347 self.serverButton.setEnabled(not connected)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
348 self.sharingGroup.setEnabled(connected)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
349
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
350 if connected:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
351 vm = e5App().getObject("ViewManager")
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
352 aw = vm.activeWindow()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
353 if aw:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
354 self.checkEditorActions(aw)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 def __showErrorMessage(self, message):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 Private slot to show an error message.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 @param message error message to show (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 color = self.chatEdit.textColor()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 self.chatEdit.setTextColor(Qt.red)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
365 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
366 ":")
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
367 self.chatEdit.append(message + "\n")
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 self.chatEdit.setTextColor(color)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 def __initialConnectionRefused(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 Private slot to handle the refusal of the initial connection.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 self.__setConnected(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 def preferencesChanged(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 Public slot to handle a change of preferences.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 """
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
380 if not self.__client.isListening():
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
381 self.serverPortSpin.setValue(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
382 Preferences.getCooperation("ServerPort"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 if Preferences.getCooperation("AutoStartServer"):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 self.on_serverButton_clicked()
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
385
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
386 def getClient(self):
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
387 """
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
388 Public method to get a reference to the cooperation client.
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2436
diff changeset
389
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2436
diff changeset
390 @return reference to the cooperation client (CooperationClient)
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
391 """
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
392 return self.__client
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
393
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
394 def __editorCommandMessage(self, hashStr, fileName, message):
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
395 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
396 Private slot to handle editor command messages from the client.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
397
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
398 @param hashStr hash of the project (string)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
399 @param fileName project relative file name of the editor (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
400 @param message command message (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
401 """
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
402 self.editorCommand.emit(hashStr, fileName, message)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
403
2400
c1726b754f96 Started with delaying the import upon the time it is needed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
404 from QScintilla.Editor import Editor
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
405 if message.startswith(Editor.StartEditToken + Editor.Separator) or \
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
406 message.startswith(Editor.EndEditToken + Editor.Separator):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
407 vm = e5App().getObject("ViewManager")
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
408 aw = vm.activeWindow()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
409 if aw:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
410 self.checkEditorActions(aw)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
411
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
412 @pyqtSlot(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
413 def on_shareButton_clicked(self, checked):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
414 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
415 Private slot to share the current editor.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
416
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
417 @param checked flag indicating the button state (boolean)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
418 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
419 if checked:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
420 self.shareButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
421 UI.PixmapCache.getIcon("sharedEditConnected.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
422 else:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
423 self.shareButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
424 UI.PixmapCache.getIcon("sharedEditDisconnected.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
425 self.startEditButton.setEnabled(checked)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
426
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
427 self.shareEditor.emit(checked)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
428
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
429 @pyqtSlot(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
430 def on_startEditButton_clicked(self, checked):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
431 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
432 Private slot to start a shared edit session.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
433
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
434 @param checked flag indicating the button state (boolean)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
435 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
436 if checked:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
437 self.sendEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
438 self.cancelEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
439 self.shareButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
440 self.startEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
441
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
442 self.startEdit.emit()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
443
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
444 @pyqtSlot()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
445 def on_sendEditButton_clicked(self):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
446 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
447 Private slot to end a shared edit session and send the changes.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
448 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
449 self.sendEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
450 self.cancelEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
451 self.shareButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
452 self.startEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
453 self.startEditButton.setChecked(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
454
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
455 self.sendEdit.emit()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
456
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
457 @pyqtSlot()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
458 def on_cancelEditButton_clicked(self):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
459 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
460 Private slot to cancel a shared edit session.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
461 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
462 self.sendEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
463 self.cancelEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
464 self.shareButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
465 self.startEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
466 self.startEditButton.setChecked(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
467
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
468 self.cancelEdit.emit()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
469
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
470 def checkEditorActions(self, editor):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
471 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
472 Public slot to set action according to an editor's state.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
473
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
474 @param editor reference to the editor (Editor)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
475 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
476 shareable, sharing, editing, remoteEditing = editor.getSharingStatus()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
477
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
478 self.shareButton.setChecked(sharing)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
479 if sharing:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
480 self.shareButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
481 UI.PixmapCache.getIcon("sharedEditConnected.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
482 else:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
483 self.shareButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
484 UI.PixmapCache.getIcon("sharedEditDisconnected.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
485 self.startEditButton.setChecked(editing)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
486
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
487 self.shareButton.setEnabled(shareable and not editing)
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
488 self.startEditButton.setEnabled(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
489 sharing and not editing and not remoteEditing)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
490 self.sendEditButton.setEnabled(editing)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
491 self.cancelEditButton.setEnabled(editing)
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
492
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
493 def __initChatMenu(self):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
494 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
495 Private slot to initialize the chat edit context menu.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
496 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
497 self.__chatMenu = QMenu(self)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
498 self.__copyChatAct = \
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
499 self.__chatMenu.addAction(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
500 UI.PixmapCache.getIcon("editCopy.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
501 self.tr("Copy"), self.__copyChat)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
502 self.__chatMenu.addSeparator()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
503 self.__cutAllChatAct = \
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
504 self.__chatMenu.addAction(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
505 UI.PixmapCache.getIcon("editCut.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
506 self.tr("Cut all"), self.__cutAllChat)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
507 self.__copyAllChatAct = \
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
508 self.__chatMenu.addAction(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
509 UI.PixmapCache.getIcon("editCopy.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
510 self.tr("Copy all"), self.__copyAllChat)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
511 self.__chatMenu.addSeparator()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
512 self.__clearChatAct = \
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
513 self.__chatMenu.addAction(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
514 UI.PixmapCache.getIcon("editDelete.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
515 self.tr("Clear"), self.__clearChat)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
516 self.__chatMenu.addSeparator()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
517 self.__saveChatAct = \
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
518 self.__chatMenu.addAction(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
519 UI.PixmapCache.getIcon("fileSave.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
520 self.tr("Save"), self.__saveChat)
2250
810e9c7b61e3 Fixed a little issue in the initialisation of the Cooperation Chat window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2223
diff changeset
521
810e9c7b61e3 Fixed a little issue in the initialisation of the Cooperation Chat window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2223
diff changeset
522 self.on_chatEdit_copyAvailable(False)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
523
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
524 @pyqtSlot(bool)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
525 def on_chatEdit_copyAvailable(self, yes):
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
526 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
527 Private slot to react to text selection/deselection of the chat edit.
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
528
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
529 @param yes flag signaling the availability of selected text (boolean)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
530 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
531 self.__copyChatAct.setEnabled(yes)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
532
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
533 @pyqtSlot(QPoint)
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
534 def on_chatEdit_customContextMenuRequested(self, pos):
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
535 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
536 Private slot to show the context menu for the chat.
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
537
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
538 @param pos the position of the mouse pointer (QPoint)
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
539 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
540 enable = self.chatEdit.toPlainText() != ""
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
541 self.__saveChatAct.setEnabled(enable)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
542 self.__copyAllChatAct.setEnabled(enable)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
543 self.__cutAllChatAct.setEnabled(enable)
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
544 self.__chatMenu.popup(self.chatEdit.mapToGlobal(pos))
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
545
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
546 def __clearChat(self):
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
547 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
548 Private slot to clear the contents of the chat display.
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
549 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
550 self.chatEdit.clear()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
551
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
552 def __saveChat(self):
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
553 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
554 Private slot to save the contents of the chat display.
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
555 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
556 txt = self.chatEdit.toPlainText()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
557 if txt:
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
558 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
559 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
560 self.tr("Save Chat"),
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
561 "",
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
562 self.tr("Text Files (*.txt);;All Files (*)"),
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
563 None,
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
564 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
565 if fname:
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
566 ext = QFileInfo(fname).suffix()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
567 if not ext:
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
568 ex = selectedFilter.split("(*")[1].split(")")[0]
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
569 if ex:
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
570 fname += ex
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
571 if QFileInfo(fname).exists():
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
572 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
573 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
574 self.tr("Save Chat"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
575 self.tr("<p>The file <b>{0}</b> already exists."
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
576 " Overwrite it?</p>").format(fname),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
577 icon=E5MessageBox.Warning)
546
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
578 if not res:
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
579 return
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
580 fname = Utilities.toNativeSeparators(fname)
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
581
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
582 try:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
583 f = open(fname, "w", encoding="utf-8")
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
584 f.write(txt)
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
585 f.close()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
586 except IOError as err:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
587 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
588 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
589 self.tr("Error saving Chat"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
590 self.tr("""<p>The chat contents could not be"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
591 """ written to <b>{0}</b></p>"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
592 """<p>Reason: {1}</p>""") .format(
3032
927a2f8b3669 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3021
diff changeset
593 fname, str(err)))
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
594
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
595 def __copyChat(self):
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
596 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
597 Private slot to copy the contents of the chat display to the clipboard.
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
598 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
599 self.chatEdit.copy()
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
600
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
601 def __copyAllChat(self):
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
602 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
603 Private slot to copy the contents of the chat display to the clipboard.
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
604 """
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
605 txt = self.chatEdit.toPlainText()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
606 if txt:
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
607 cb = QApplication.clipboard()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
608 cb.setText(txt)
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
609
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
610 def __cutAllChat(self):
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
611 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
612 Private slot to cut the contents of the chat display to the clipboard.
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
613 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
614 txt = self.chatEdit.toPlainText()
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
615 if txt:
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
616 cb = QApplication.clipboard()
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
617 cb.setText(txt)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
618 self.chatEdit.clear()
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
619
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
620 def __initUsersMenu(self):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
621 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
622 Private slot to initialize the users list context menu.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
623 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
624 self.__usersMenu = QMenu(self)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
625 self.__kickUserAct = \
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
626 self.__usersMenu.addAction(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
627 UI.PixmapCache.getIcon("chatKickUser.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
628 self.tr("Kick User"), self.__kickUser)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
629 self.__banUserAct = \
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
630 self.__usersMenu.addAction(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
631 UI.PixmapCache.getIcon("chatBanUser.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
632 self.tr("Ban User"), self.__banUser)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
633 self.__banKickUserAct = \
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
634 self.__usersMenu.addAction(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
635 UI.PixmapCache.getIcon("chatBanKickUser.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
636 self.tr("Ban and Kick User"), self.__banKickUser)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
637
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
638 @pyqtSlot(QPoint)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
639 def on_usersList_customContextMenuRequested(self, pos):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
640 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
641 Private slot to show the context menu for the users list.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
642
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
643 @param pos the position of the mouse pointer (QPoint)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
644 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
645 itm = self.usersList.itemAt(pos)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
646 self.__kickUserAct.setEnabled(itm is not None)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
647 self.__banUserAct.setEnabled(itm is not None)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
648 self.__banKickUserAct.setEnabled(itm is not None)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
649 self.__usersMenu.popup(self.usersList.mapToGlobal(pos))
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
650
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
651 def __kickUser(self):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
652 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
653 Private slot to disconnect a user.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
654 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
655 itm = self.usersList.currentItem()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
656 self.__client.kickUser(itm.text())
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
657
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
658 color = self.chatEdit.textColor()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
659 self.chatEdit.setTextColor(Qt.darkYellow)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
660 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
661 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
662 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
663 self.chatEdit.append(self.tr("* {0} has been kicked.\n").format(
2285
a6fc5bda1de9 Corrected a few issues in the Cooperation function introduced during the IPv6 extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2250
diff changeset
664 itm.text().split("@")[0]))
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
665 self.chatEdit.setTextColor(color)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
666
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
667 def __banUser(self):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
668 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
669 Private slot to ban a user.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
670 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
671 itm = self.usersList.currentItem()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
672 self.__client.banUser(itm.text())
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
673
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
674 color = self.chatEdit.textColor()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
675 self.chatEdit.setTextColor(Qt.darkYellow)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
676 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
677 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
678 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
679 self.chatEdit.append(self.tr("* {0} has been banned.\n").format(
2285
a6fc5bda1de9 Corrected a few issues in the Cooperation function introduced during the IPv6 extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2250
diff changeset
680 itm.text().split("@")[0]))
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
681 self.chatEdit.setTextColor(color)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
682
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
683 def __banKickUser(self):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
684 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
685 Private slot to ban and kick a user.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
686 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
687 itm = self.usersList.currentItem()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
688 self.__client.banKickUser(itm.text())
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
689
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
690 color = self.chatEdit.textColor()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
691 self.chatEdit.setTextColor(Qt.darkYellow)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
692 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
693 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
694 ":")
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
695 self.chatEdit.append(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
696 self.tr("* {0} has been banned and kicked.\n")
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
697 .format(itm.text().split("@")[0]))
880
52ed20236a1c Added the option to not use the native file dialog to prevent crashes on Linux.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
698 self.chatEdit.setTextColor(color)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
699
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
700 def shutdown(self):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
701 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
702 Public method to shut down the cooperation system.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
703 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
704 self.__client.disconnectConnections()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
705 self.__setConnected(False)

eric ide

mercurial