From: APTX Date: Sun, 30 Aug 2015 15:12:33 +0000 (+0200) Subject: Add Hosts tab. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=3f960b641ef5effcfa5da32c091e02dc12ec3739;p=localmylist.git Add Hosts tab. 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. --- diff --git a/localmylist-management/localmylist-management.pro b/localmylist-management/localmylist-management.pro index 2a378e4..0016eba 100644 --- a/localmylist-management/localmylist-management.pro +++ b/localmylist-management/localmylist-management.pro @@ -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) diff --git a/localmylist-management/registertabs.cpp b/localmylist-management/registertabs.cpp index 944be3d..f360c79 100644 --- a/localmylist-management/registertabs.cpp +++ b/localmylist-management/registertabs.cpp @@ -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(); TabWidget::registerTab(); TabWidget::registerTab(); + TabWidget::registerTab(); } diff --git a/localmylist-management/tabs/hosttab.cpp b/localmylist-management/tabs/hosttab.cpp new file mode 100644 index 0000000..1cff0df --- /dev/null +++ b/localmylist-management/tabs/hosttab.cpp @@ -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 +#include +#include + +#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 index 0000000..a9350ed --- /dev/null +++ b/localmylist-management/tabs/hosttab.h @@ -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 +{ + 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 index 0000000..15be515 --- /dev/null +++ b/localmylist-management/tabs/hosttab.ui @@ -0,0 +1,33 @@ + + + HostTab + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + + + + + + +