--- /dev/null
+/*
+ * Copyright (c) 20015 APTX
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "hosttab.h"
+#include "ui_hosttab.h"
+
+#include <QSqlTableModel>
+#include <QSqlError>
+#include <QMessageBox>
+
+#include "mylist.h"
+
+HostTab::HostTab(QWidget *parent) :
+ AbstractTabBase(parent),
+ ui(new Ui::HostTab)
+{
+ ui->setupUi(this);
+ m_label = tr("Hosts");
+}
+
+HostTab::~HostTab()
+{
+ delete ui;
+}
+
+QString HostTab::staticId()
+{
+ return "host";
+}
+
+QString HostTab::name()
+{
+ return tr("Hosts");
+}
+
+void HostTab::init()
+{
+ model = new QSqlTableModel(this,
+ LocalMyList::instance()->database()->connection());
+ model->setTable("host");
+ model->setEditStrategy(QSqlTableModel::OnManualSubmit);
+
+ model->setHeaderData(0, Qt::Horizontal, "ID");
+ model->setHeaderData(1, Qt::Horizontal, "Name");
+ model->setHeaderData(2, Qt::Horizontal, "Is UDP Host");
+
+ ui->hostView->setModel(model);
+ ui->hostView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ ui->hostView->hideColumn(0);
+
+ reload();
+}
+
+AbstractTab::TabActions HostTab::availableActions() const
+{
+ return Reload | SelectAll | ClearSelection | SaveChanges | DiscardChanges
+ | AddEntry;
+}
+
+void HostTab::reload()
+{
+ model->select();
+}
+
+void HostTab::addEntry()
+{
+ model->insertRecord(-1, QSqlRecord());
+}
+
+void HostTab::saveChanges()
+{
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+ if(!model->isDirty())
+ return;
+#endif
+
+ if (model->submitAll())
+ return;
+
+ QMessageBox::critical(this, tr("Error while saving changes"),
+ model->lastError().text());
+}
+
+void HostTab::discardChanges()
+{
+ model->revertAll();
+}
--- /dev/null
+/*
+ * Copyright (c) 20015 APTX
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef HOSTTAB_H
+#define HOSTTAB_H
+
+#include "abstracttab.h"
+
+class QSqlTableModel;
+
+namespace Ui {
+class HostTab;
+}
+
+class HostTab : public AbstractTabBase<HostTab>
+{
+ Q_OBJECT
+
+public:
+ explicit HostTab(QWidget *parent = 0);
+ ~HostTab();
+
+ static QString staticId();
+ static QString name();
+
+ void init() override;
+
+ TabActions availableActions() const override;
+ void reload() override;
+ void addEntry() override;
+ void saveChanges() override;
+ void discardChanges() override;
+
+private:
+ Ui::HostTab *ui;
+ QSqlTableModel *model;
+};
+
+#endif // HOSTTAB_H