]> Some of my projects - localmylist.git/commitdiff
Add Hosts tab.
authorAPTX <marek321@gmail.com>
Sun, 30 Aug 2015 15:12:33 +0000 (17:12 +0200)
committerAPTX <marek321@gmail.com>
Sun, 30 Aug 2015 15:13:14 +0000 (17:13 +0200)
Removing hosts is currently disabled. Editing the current
host is not handled in any special way. This means that
changes aren't immediately visible and local config will
need changes if the current host name changes.

localmylist-management/localmylist-management.pro
localmylist-management/registertabs.cpp
localmylist-management/tabs/hosttab.cpp [new file with mode: 0644]
localmylist-management/tabs/hosttab.h [new file with mode: 0644]
localmylist-management/tabs/hosttab.ui [new file with mode: 0644]

index 2a378e4d7f5b912e51613ec25de2a92a142ed458..0016ebaaa53be470ce0bc59ddff6ebfb52cb82d4 100644 (file)
@@ -30,6 +30,7 @@ SOURCES += main.cpp\
        tabs/clientlogtab.cpp \
        tabs/dynamicmodeltab.cpp \
        tabs/pathmappingtab.cpp \
+       tabs/hosttab.cpp \
        fonts.cpp \
        aniaddsyntaxhighlighter.cpp \
        settingsdialog.cpp \
@@ -57,6 +58,7 @@ HEADERS += mainwindow.h \
        tabs/clientlogtab.h \
        tabs/dynamicmodeltab.h \
        tabs/pathmappingtab.h \
+       tabs/hosttab.h \
        fonts.h \
        aniaddsyntaxhighlighter.h \
        settingsdialog.h \
@@ -76,7 +78,8 @@ FORMS += mainwindow.ui \
        tabs/databaselogtab.ui \
        tabs/clientlogtab.ui \
        tabs/dynamicmodeltab.ui \
-       tabs/pathmappingtab.ui
+       tabs/pathmappingtab.ui \
+       tabs/hosttab.ui
 
 include(../localmylist.pri)
 include(qtsingleapplication/qtsingleapplication.pri)
index 944be3d420b790ea0a102f4f5f33036cf84910e6..f360c792c84b2c3b5b17cde7eccc2091bdf4eb21 100644 (file)
@@ -8,6 +8,7 @@
 #include "tabs/clientlogtab.h"
 #include "tabs/dynamicmodeltab.h"
 #include "tabs/pathmappingtab.h"
+#include "tabs/hosttab.h"
 
 void registerTabs()
 {
@@ -20,4 +21,5 @@ void registerTabs()
        TabWidget::registerTab<ClientLogTab>();
        TabWidget::registerTab<DynamicModelTab>();
        TabWidget::registerTab<PathMappingTab>();
+       TabWidget::registerTab<HostTab>();
 }
diff --git a/localmylist-management/tabs/hosttab.cpp b/localmylist-management/tabs/hosttab.cpp
new file mode 100644 (file)
index 0000000..1cff0df
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * 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();
+}
diff --git a/localmylist-management/tabs/hosttab.h b/localmylist-management/tabs/hosttab.h
new file mode 100644 (file)
index 0000000..a9350ed
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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
diff --git a/localmylist-management/tabs/hosttab.ui b/localmylist-management/tabs/hosttab.ui
new file mode 100644 (file)
index 0000000..15be515
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>HostTab</class>
+ <widget class="QWidget" name="HostTab">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <property name="leftMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QTableView" name="hostView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>