+ } else {
+ return false;
+ }
+}
+
+void InputLine::on_returnPressed() {
+ addToHistory(text());
+ emit sendText(text());
+ resetLine();
+}
+
+void InputLine::on_textChanged(QString newText) {
+ QStringList lineSeparators;
+ lineSeparators << QString("\r\n")
+ << QString('\n')
+ << QString('\r');
+
+ QString lineSep;
+ foreach(QString separator, lineSeparators) {
+ if(newText.contains(separator)) {
+ lineSep = separator;
+ break;
+ }
+ }
+
+ if(lineSep.isEmpty())
+ return;
+
+ QStringList lines = newText.split(lineSep);
+ clear();
+
+ if(lines.count() >= 4) {
+ QString msg = tr("Do you really want to paste %1 lines?").arg(lines.count());
+ msg += "<p>";
+ for(int i = 0; i < 3; i++) {
+ msg += lines[i].left(40);
+ if(lines[i].count() > 40)
+ msg += "...";
+ msg += "<br />";
+ }
+ msg += "...</p>";
+ QMessageBox question(QMessageBox::NoIcon, tr("Paste Protection"), msg, QMessageBox::Yes|QMessageBox::No);
+ question.setDefaultButton(QMessageBox::No);
+ question.setWindowFlags(question.windowFlags() | Qt::Sheet);
+ if(question.exec() == QMessageBox::No)
+ return;
+ }
+
+ foreach(QString line, lines) {
+ clear();
+ insert(line);
+ emit returnPressed();