fixed uninitialized qint32
[quassel.git] / src / qtui / inputwidget.cpp
index 900fef5..f05311a 100644 (file)
@@ -110,6 +110,9 @@ InputWidget::InputWidget(QWidget *parent)
   s.notify("ShowStyleButtons", this, SLOT(setShowStyleButtons(QVariant)));
   setShowStyleButtons(s.value("ShowStyleButtons", true));
 
+  s.notify("EnablePerChatHistory", this, SLOT(setEnablePerChatHistory(QVariant)));
+  setEnablePerChatHistory(s.value("EnablePerChatHistory", true));
+
   s.notify("MaxNumLines", this, SLOT(setMaxLines(QVariant)));
   setMaxLines(s.value("MaxNumLines", 5));
 
@@ -159,6 +162,10 @@ void InputWidget::setShowStyleButtons(const QVariant &v) {
   ui.showStyleButton->setVisible(v.toBool());
 }
 
+void InputWidget::setEnablePerChatHistory(const QVariant &v) {
+  _perChatHistory = v.toBool();
+}
+
 void InputWidget::setMaxLines(const QVariant &v) {
   ui.inputEdit->setMaxHeight(v.toInt());
 }
@@ -203,7 +210,24 @@ bool InputWidget::eventFilter(QObject *watched, QEvent *event) {
 }
 
 void InputWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
-  Q_UNUSED(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);
+  }
+
   NetworkId networkId = current.data(NetworkModel::NetworkIdRole).value<NetworkId>();
   if(networkId == _networkId)
     return;
@@ -381,7 +405,8 @@ void InputWidget::on_inputEdit_textEntered(const QString &text) {
 
 #ifdef HAVE_KDE
   // Set highlighter back to active in case it was deactivated by too many errors.
-  ui.inputEdit->highlighter()->setActive(true);
+  if(ui.inputEdit->highlighter())
+    ui.inputEdit->highlighter()->setActive(true);
 #endif
 }