+ // restore
+ inputLine()->setHistory(historyMap[currentBufferId].history);
+ inputLine()->setTempHistory(historyMap[currentBufferId].tempHistory);
+ inputLine()->setIdx(historyMap[currentBufferId].idx);
+ inputLine()->setHtml(historyMap[currentBufferId].inputLine);
+ inputLine()->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
+
+ // FIXME this really should be in MultiLineEdit (and the const int on top removed)
+ QTextBlockFormat format = inputLine()->textCursor().blockFormat();
+ format.setLeftMargin(leftMargin); // we want a little space between the frame and the contents
+ inputLine()->textCursor().setBlockFormat(format);
+ }
+
+ NetworkId networkId = current.data(NetworkModel::NetworkIdRole).value<NetworkId>();
+ if (networkId == _networkId)
+ return;
+
+ setNetwork(networkId);
+ updateNickSelector();
+ updateEnabledState();
+}
+
+void InputWidget::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
+{
+ QItemSelectionRange changedArea(topLeft, bottomRight);
+ if (changedArea.contains(selectionModel()->currentIndex())) {
+ updateEnabledState();
+
+ bool encrypted = false;
+
+ auto* chan = qobject_cast<IrcChannel*>(
+ Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcChannelRole).value<QObject*>());
+ if (chan)
+ encrypted = chan->encrypted();
+
+ auto* user = qobject_cast<IrcUser*>(
+ Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcUserRole).value<QObject*>());
+ if (user)
+ encrypted = user->encrypted();
+
+ if (encrypted)
+ ui.encryptionIconLabel->show();
+ else
+ ui.encryptionIconLabel->hide();
+ }
+}
+
+void InputWidget::rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end)
+{
+ NetworkId networkId;
+ QModelIndex child;
+ for (int row = start; row <= end; row++) {
+ child = model()->index(row, 0, parent);
+ if (NetworkModel::NetworkItemType != child.data(NetworkModel::ItemTypeRole).toInt())
+ continue;
+ networkId = child.data(NetworkModel::NetworkIdRole).value<NetworkId>();
+ if (networkId == _networkId) {
+ setNetwork(0);
+ updateNickSelector();
+ return;
+ }
+ }
+}
+
+void InputWidget::updateEnabledState()
+{
+// FIXME: Find a visualization for this that does not disable the widget!
+// Disabling kills global action shortcuts, plus users sometimes need/want to enter text
+// even in inactive channels.
+#if 0
+ QModelIndex currentIndex = selectionModel()->currentIndex();
+
+ const Network *net = Client::networkModel()->networkByIndex(currentIndex);
+ bool enabled = false;
+ if (net) {
+ // disable inputline if it's a channelbuffer we parted from or...
+ enabled = (currentIndex.data(NetworkModel::ItemActiveRole).value<bool>() || (currentIndex.data(NetworkModel::BufferTypeRole).toInt() != BufferInfo::ChannelBuffer));
+ // ... if we're not connected to the network at all
+ enabled &= net->isConnected();
+ }
+
+ ui.inputEdit->setEnabled(enabled);
+#endif
+}
+
+const Network* InputWidget::currentNetwork() const
+{
+ return Client::network(_networkId);
+}
+
+BufferInfo InputWidget::currentBufferInfo() const
+{
+ return selectionModel()->currentIndex().data(NetworkModel::BufferInfoRole).value<BufferInfo>();
+}
+
+void InputWidget::applyFormatActiveColor()
+{
+ if (!ui.textcolorButton->defaultAction()) {
+ return;
+ }
+ colorChosen(ui.textcolorButton->defaultAction());
+}
+
+void InputWidget::applyFormatActiveColorFill()
+{
+ if (!ui.highlightcolorButton->defaultAction()) {
+ return;
+ }
+ colorHighlightChosen(ui.highlightcolorButton->defaultAction());
+}
+
+void InputWidget::toggleFormatBold()
+{
+ setFormatBold(!ui.boldButton->isChecked());
+}
+
+void InputWidget::toggleFormatItalic()
+{
+ setFormatItalic(!ui.italicButton->isChecked());
+}
+
+void InputWidget::toggleFormatUnderline()
+{
+ setFormatUnderline(!ui.underlineButton->isChecked());
+}
+
+void InputWidget::clearFormat()
+{
+ // Clear all formatting for selection (not global)
+ setFormatClear(false);
+}
+
+void InputWidget::setNetwork(NetworkId networkId)
+{
+ if (_networkId == networkId)
+ return;
+
+ const Network* previousNet = Client::network(_networkId);
+ if (previousNet) {
+ disconnect(previousNet, nullptr, this, nullptr);
+ if (previousNet->me())
+ disconnect(previousNet->me(), nullptr, this, nullptr);
+ }
+
+ _networkId = networkId;
+
+ const Network* network = Client::network(networkId);
+ if (network) {
+ connect(network, &Network::identitySet, this, &InputWidget::setIdentity);
+ connectMyIrcUser();
+ setIdentity(network->identity());
+ }
+ else {
+ setIdentity(0);
+ _networkId = 0;
+ }
+}
+
+void InputWidget::connectMyIrcUser()
+{
+ const Network* network = currentNetwork();
+ if (network->me()) {
+ connect(network->me(), &IrcUser::nickSet, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::userModesSet, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::userModesAdded, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::userModesRemoved, this, &InputWidget::updateNickSelector);
+ connect(network->me(), &IrcUser::awaySet, this, &InputWidget::updateNickSelector);
+ disconnect(network, &Network::myNickSet, this, &InputWidget::connectMyIrcUser);
+ updateNickSelector();
+ }
+ else {
+ connect(network, &Network::myNickSet, this, &InputWidget::connectMyIrcUser);
+ }
+}
+
+void InputWidget::setIdentity(IdentityId identityId)
+{
+ if (_identityId == identityId)
+ return;
+
+ const Identity* previousIdentity = Client::identity(_identityId);
+ if (previousIdentity)
+ disconnect(previousIdentity, nullptr, this, nullptr);