+Widget::Widget(QString const & source, QWidget * parent)
+ : QWidget(parent)
+ , mSource(source)
+ , mAutoScroll(true)
+{
+ QVBoxLayout * w = new QVBoxLayout;
+ setLayout(w);
+
+ mModel = new Model(this);
+ connect(mModel, SIGNAL(messageAdded(QModelIndex)), this, SLOT(messageAdded(QModelIndex)));
+
+ wList = new QListView;
+ wList->setModel(mModel);
+ wList->setUniformItemSizes(true);
+ connect(wList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
+ w->addWidget(wList);
+
+ wList->setContextMenuPolicy(Qt::ActionsContextMenu);
+
+ QAction * a = new QAction(tr("&Copy", VER_MODULE_NAME_STR), this);
+ a->setStatusTip(tr("Copies the selected message to the clipboard for pasting into other applications", VER_MODULE_NAME_STR));
+ connect(a, SIGNAL(triggered()), this, SLOT(copyToClipboard()));
+ wList->addAction(a);
+
+ a = new QAction(tr("&Save to ...", VER_MODULE_NAME_STR), this);
+ a->setStatusTip(tr("Saves all the messages to a file", VER_MODULE_NAME_STR));
+ connect(a, SIGNAL(triggered()), this, SLOT(saveToFile()));
+ wList->addAction(a);
+
+ wDetails = new QLabel;
+ wDetails->setWordWrap(true);
+ w->addWidget(wDetails);
+}
+
+void Widget::messageAdded(QModelIndex const & index)
+{
+ if (mAutoScroll)
+ wList->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
+}
+
+void Widget::currentChanged(QModelIndex const & current, QModelIndex const & previous)
+{
+ Q_UNUSED(previous);
+
+ if (!current.isValid() || current.row() < 0 || current.row() > mModel->rowCount()) {
+ wDetails->clear();
+ return;
+ }
+
+ mAutoScroll = current.row() == (mModel->rowCount() - 1);
+
+ wDetails->setText(mModel->details(current));
+}
+
+void Widget::copyToClipboard()
+{
+ QModelIndex idx = wList->selectionModel()->currentIndex();
+ if (idx.isValid())
+ mModel->copyToClipboard(idx);
+}
+
+void Widget::saveToFile()
+{
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Save to file", VER_MODULE_NAME_STR),
+ Common::iApp::instance()->dataRootDir() + QString("%1_%2.txt").arg(mSource).arg(QDate::currentDate().toString("yyyyMMdd")),
+ tr("Text files (*.txt);;All files (*)", VER_MODULE_NAME_STR));
+ if (fileName.isEmpty())
+ return;
+
+ if (!mModel->saveToFile(fileName))
+ QMessageBox::critical(this, tr("Error", VER_MODULE_NAME_STR), mModel->errorString());
+}
+
+
+//-------------------------------------------------------------------
+
+Window::Window(QWidget * parent, Qt::WindowFlags flags)