-void InputWidget::on_inputEdit_textEntered(const QString &text) const {
- Client::userInput(currentBufferInfo(), text);
- actionTextBold->setChecked(false);
- actionTextUnderline->setChecked(false);
- actionTextItalic->setChecked(false);
- inputLine()->setFontWeight(QFont::Normal);
- inputLine()->setFontUnderline(false);
- inputLine()->setFontItalic(false);
+
+void InputWidget::setIdentity(IdentityId identityId)
+{
+ if (_identityId == identityId)
+ return;
+
+ const Identity *previousIdentity = Client::identity(_identityId);
+ if (previousIdentity)
+ disconnect(previousIdentity, 0, this, 0);
+
+ _identityId = identityId;
+
+ const Identity *identity = Client::identity(identityId);
+ if (identity) {
+ connect(identity, SIGNAL(nicksSet(QStringList)), this, SLOT(updateNickSelector()));
+ }
+ else {
+ _identityId = 0;
+ }
+ updateNickSelector();
+}
+
+
+void InputWidget::updateNickSelector() const
+{
+ ui.ownNick->clear();
+
+ const Network *net = currentNetwork();
+ if (!net)
+ return;
+
+ const Identity *identity = Client::identity(net->identity());
+ if (!identity) {
+ qWarning() << "InputWidget::updateNickSelector(): can't find Identity for Network" << net->networkId() << "IdentityId:" << net->identity();
+ return;
+ }
+
+ int nickIdx;
+ QStringList nicks = identity->nicks();
+ if ((nickIdx = nicks.indexOf(net->myNick())) == -1) {
+ nicks.prepend(net->myNick());
+ nickIdx = 0;
+ }
+
+ if (nicks.isEmpty())
+ return;
+
+ IrcUser *me = net->me();
+ if (me) {
+ nicks[nickIdx] = net->myNick();
+ if (!me->userModes().isEmpty())
+ nicks[nickIdx] += QString(" (+%1)").arg(me->userModes());
+ }
+
+ ui.ownNick->addItems(nicks);
+
+ if (me && me->isAway())
+ ui.ownNick->setItemData(nickIdx, icon::get({"im-user-away", "user-away"}), Qt::DecorationRole);
+
+ ui.ownNick->setCurrentIndex(nickIdx);
+}
+
+
+void InputWidget::changeNick(const QString &newNick) const
+{
+ const Network *net = currentNetwork();
+ if (!net || net->isMyNick(newNick))
+ return;
+
+ // we reset the nick selecter as we have no confirmation yet, that this will succeed.
+ // if the action succeeds it will be properly updated anyways.
+ updateNickSelector();
+ Client::userInput(BufferInfo::fakeStatusBuffer(net->networkId()), QString("/NICK %1").arg(newNick));