+void InputWidget::setMaxLines(const QVariant &v)
+{
+ ui.inputEdit->setMaxHeight(v.toInt());
+}
+
+
+void InputWidget::setScrollBarsEnabled(const QVariant &v)
+{
+ ui.inputEdit->setScrollBarsEnabled(v.toBool());
+}
+
+
+void InputWidget::setLineWrapEnabled(const QVariant &v)
+{
+ ui.inputEdit->setLineWrapEnabled(v.toBool());
+}
+
+
+void InputWidget::setMultiLineEnabled(const QVariant &v)
+{
+ ui.inputEdit->setMode(v.toBool() ? MultiLineEdit::MultiLine : MultiLineEdit::SingleLine);
+}
+
+
+bool InputWidget::eventFilter(QObject *watched, QEvent *event)
+{
+ if (event->type() != QEvent::KeyPress)
+ return false;
+
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+
+ // keys from BufferView should be sent to (and focus) the input line
+ BufferView *view = qobject_cast<BufferView *>(watched);
+ if (view) {
+ if (keyEvent->text().length() == 1 && !(keyEvent->modifiers() & (Qt::ControlModifier ^ Qt::AltModifier))) { // normal key press
+ QChar c = keyEvent->text().at(0);
+ if (c.isLetterOrNumber() || c.isSpace() || c.isPunct() || c.isSymbol()) {
+ setFocus();
+ QCoreApplication::sendEvent(inputLine(), keyEvent);
+ return true;
+ }
+ }
+ return false;
+ }
+ else if (watched == ui.inputEdit) {
+ if (keyEvent->matches(QKeySequence::Find)) {
+ QAction *act = GraphicalUi::actionCollection()->action("ToggleSearchBar");
+ if (act) {
+ act->toggle();
+ return true;
+ }
+ }
+ return false;
+ }
+ return false;
+}
+
+
+void InputWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
+{
+ BufferId currentBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
+ BufferId previousBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();
+
+ if (_perChatHistory) {
+ //backup
+ historyMap[previousBufferId].history = inputLine()->history();
+ historyMap[previousBufferId].tempHistory = inputLine()->tempHistory();
+ historyMap[previousBufferId].idx = inputLine()->idx();
+ historyMap[previousBufferId].inputLine = inputLine()->html();
+
+ //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;
+
+ IrcChannel *chan = qobject_cast<IrcChannel *>(Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcChannelRole).value<QObject *>());
+ if (chan)
+ encrypted = chan->encrypted();
+
+ IrcUser *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::setNetwork(NetworkId networkId)
+{
+ if (_networkId == networkId)
+ return;
+
+ const Network *previousNet = Client::network(_networkId);
+ if (previousNet) {
+ disconnect(previousNet, 0, this, 0);
+ if (previousNet->me())
+ disconnect(previousNet->me(), 0, this, 0);
+ }
+
+ _networkId = networkId;
+
+ const Network *network = Client::network(networkId);
+ if (network) {
+ connect(network, SIGNAL(identitySet(IdentityId)), this, SLOT(setIdentity(IdentityId)));
+ connectMyIrcUser();
+ setIdentity(network->identity());
+ }
+ else {
+ setIdentity(0);
+ _networkId = 0;
+ }
+}
+
+
+void InputWidget::connectMyIrcUser()
+{
+ const Network *network = currentNetwork();
+ if (network->me()) {
+ connect(network->me(), SIGNAL(nickSet(const QString &)), this, SLOT(updateNickSelector()));
+ connect(network->me(), SIGNAL(userModesSet(QString)), this, SLOT(updateNickSelector()));
+ connect(network->me(), SIGNAL(userModesAdded(QString)), this, SLOT(updateNickSelector()));
+ connect(network->me(), SIGNAL(userModesRemoved(QString)), this, SLOT(updateNickSelector()));
+ connect(network->me(), SIGNAL(awaySet(bool)), this, SLOT(updateNickSelector()));
+ disconnect(network, SIGNAL(myNickSet(const QString &)), this, SLOT(connectMyIrcUser()));
+ updateNickSelector();
+ }
+ else {
+ connect(network, SIGNAL(myNickSet(const QString &)), this, SLOT(connectMyIrcUser()));
+ }
+}
+
+
+void InputWidget::setIdentity(IdentityId identityId)
+{
+ if (_identityId == identityId)
+ return;
+
+ const Identity *previousIdentity = Client::identity(_identityId);
+ if (previousIdentity)
+ disconnect(previousIdentity, 0, this, 0);