Commit 61975b9c authored by Andrea Scarpino's avatar Andrea Scarpino

Implement poller (fixes #2)

Also:
- Do not enable PingAll/Clear buttons when there're no hosts
- Update Italian translation
parent b1da2ad1
......@@ -2,6 +2,8 @@ TARGET = harbour-hostisdown
CONFIG += sailfishapp
QT += sql
SOURCES += \
src/main.cpp \
src/pingaction.cpp \
......@@ -9,25 +11,25 @@ SOURCES += \
src/hostssqlmodel.cpp \
src/hostsmanager.cpp
HEADERS += \
src/pingaction.h \
src/dbmanager.h \
src/hostssqlmodel.h \
src/hostsmanager.h
OTHER_FILES += \
qml/cover/CoverPage.qml \
translations/*.ts \
qml/pages/HostDelegate.qml \
qml/pages/MainPage.qml \
qml/pages/Settings.qml \
qml/HostIsDown.qml \
harbour-hostisdown.desktop \
translations/*.ts \
rpm/harbour-hostisdown.changes \
rpm/harbour-hostisdown.spec \
rpm/harbour-hostisdown.yaml \
qml/pages/HostDelegate.qml
rpm/harbour-hostisdown.yaml
CONFIG += sailfishapp_i18n
TRANSLATIONS += translations/harbour-hostisdown-it.ts \
translations/harbour-hostisdown-sv.ts
HEADERS += \
src/pingaction.h \
src/dbmanager.h \
src/hostssqlmodel.h \
src/hostsmanager.h
QT += sql
/*
The MIT License (MIT)
Copyright (c) 2014-2015 Andrea Scarpino <me@andreascarpino.it>
Copyright (c) 2014-2016 Andrea Scarpino <me@andreascarpino.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -63,20 +63,35 @@ Page {
PullDownMenu {
MenuItem {
text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("Settings.qml"))
}
MenuItem {
id: pingAll
text: qsTr("Ping all")
enabled: hosts.count > 0
onClicked: {
target.text = "";
errorMsg.text = "";
manager.pingAll()
manager.pingAll();
}
}
MenuItem {
id: clearHistory
text: qsTr("Clear history")
enabled: hosts.count > 0
onClicked: {
manager.clearHistory()
errorMsg.text = "";
enabled = false;
pingAll.enabled = false;
manager.clearHistory();
}
}
}
......@@ -142,6 +157,7 @@ Page {
}
Repeater {
id: hosts
model: recentHosts
delegate: HostDelegate {}
}
......@@ -155,6 +171,9 @@ Page {
busy.visible = true;
busy.running = true;
button.enabled = false;
clearHistory.enabled = true;
pingAll.enabled = true;
manager.ping(target.text, useIpv6.checked);
}
}
/*
The MIT License (MIT)
Copyright (c) 2016 Andrea Scarpino <me@andreascarpino.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
allowedOrientations: Orientation.All
Column {
width: parent.width
PageHeader {
title: qsTr("Settings")
}
TextSwitch {
id: poller
width: parent.width
text: qsTr("Enable poller")
description: qsTr("Pings every N minutes all hosts in the history")
onCheckedChanged: pollerMinutes.enabled = checked;
}
TextField {
id: pollerMinutes
width: parent.width - Theme.horizontalPageMargin
label: qsTr("Poller interval in minutes")
inputMethodHints: Qt.ImhDigitsOnly
validator: RegExpValidator { regExp: /^[0-9]+$/ }
text: "60"
enabled: poller.checked
}
}
Component.onCompleted: {
var m = manager.getPoller();
if (m > 0) {
poller.checked = true;
pollerMinutes.text = m;
}
}
onStatusChanged: {
if (status === PageStatus.Deactivating) {
if (poller.checked && pollerMinutes.text > 0) {
manager.setPoller(pollerMinutes.text);
} else {
manager.setPoller(0);
}
}
}
}
* Thu Jun 02 2016 Andrea Scarpino <me@andreascarpino.it> 0.6-1
- Implemented a poller to ping all hosts from history
- Add Sweding and Italian translations
- Minor fixes
* Fri Jul 03 2015 Andrea Scarpino <me@andreascarpino.it> 0.5.1-1
- Landscape support
......
......@@ -13,7 +13,7 @@ Name: harbour-hostisdown
%{!?qtc_make:%define qtc_make make}
%{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Check if the desired host is up or not
Version: 0.5.1
Version: 0.6
Release: 1
Group: Qt/Qt
License: MIT
......
Name: harbour-hostisdown
Summary: Check if the desired host is up or not
Version: 0.5.1
Version: 0.6
Release: 1
# The contents of the Group field should be one of the groups listed here:
# http://gitorious.org/meego-developer-tools/spectacle/blobs/master/data/GROUPS
......@@ -33,7 +33,7 @@ PkgConfigBR:
# Runtime dependencies which are not automatically detected
Requires:
- sailfishsilica-qt5 >= 0.10.9
- sailfishsilica-qt5 >= 0.10.9
# All installed files
Files:
......
/*
The MIT License (MIT)
Copyright (c) 2015 Andrea Scarpino <me@andreascarpino.it>
Copyright (c) 2015-2016 Andrea Scarpino <me@andreascarpino.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -24,21 +24,35 @@
#include "hostsmanager.h"
#include <QCoreApplication>
#include <QDebug>
#include <QEventLoop>
#include <QSettings>
#include <QSqlRecord>
#include <QTimer>
#include "pingaction.h"
HostsManager::HostsManager(QObject *parent) :
QObject(parent),
m_db(new DBManager(this)), m_model(new HostsSqlModel(this))
QObject(parent)
, m_db(new DBManager(this))
, m_model(new HostsSqlModel(this))
, m_timer(0)
{
m_settings = new QSettings(QCoreApplication::organizationDomain(), QCoreApplication::applicationName(), this);
setPoller(m_settings->value("Poller", 0).toUInt());
if (m_timer) {
connect(m_timer, &QTimer::timeout, this, &HostsManager::pingAll);
}
}
HostsManager::~HostsManager()
{
delete m_model;
delete m_db;
delete m_settings;
delete m_timer;
}
void HostsManager::clearHistory()
......@@ -85,6 +99,33 @@ void HostsManager::pingLast()
ping(last.value("host").toString(), last.value("ipv6").toBool());
}
void HostsManager::setPoller(const quint16 minutes)
{
m_poller = minutes;
m_settings->setValue("Poller", minutes);
if (minutes > 0) {
if (!m_timer) {
m_timer = new QTimer();
} else {
m_timer->stop();
}
qDebug() << "Starting a new timer every" << minutes << "minutes";
m_timer->start(minutes * 60 * 1000);
} else {
if (m_timer) {
qDebug() << "Stopping the timer";
m_timer->stop();
}
}
}
quint16 HostsManager::getPoller() const
{
return m_poller;
}
HostsSqlModel *HostsManager::recentHosts()
{
m_model = new HostsSqlModel(this);
......
......@@ -29,6 +29,9 @@
#include "dbmanager.h"
class QSettings;
class QTimer;
class HostsManager : public QObject
{
Q_OBJECT
......@@ -41,6 +44,8 @@ public:
Q_INVOKABLE void ping(const QString &host, const bool ipv6);
Q_INVOKABLE void pingAll();
Q_INVOKABLE void pingLast();
Q_INVOKABLE quint16 getPoller() const;
Q_INVOKABLE void setPoller(const quint16 minutes);
HostsSqlModel* recentHosts();
Q_SIGNALS:
......@@ -51,6 +56,9 @@ private:
DBManager *m_db;
HostsSqlModel* m_model;
QSettings* m_settings;
QTimer* m_timer;
quint16 m_poller;
};
......
......@@ -71,38 +71,66 @@
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="66"/>
<source>Settings</source>
<translation>Impostazioni</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="73"/>
<source>Ping all</source>
<translation>Manda ping a tutti</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="76"/>
<location filename="../qml/pages/MainPage.qml" line="86"/>
<source>Clear history</source>
<translation>Cancella cronologia</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="89"/>
<location filename="../qml/pages/MainPage.qml" line="104"/>
<source>Ping any host!</source>
<translation>Manda un ping!</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="97"/>
<location filename="../qml/pages/MainPage.qml" line="112"/>
<source>An IP address or hostname</source>
<translation>Un indirizzo IP o hostname</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="117"/>
<location filename="../qml/pages/MainPage.qml" line="132"/>
<source>Use IPv6</source>
<translation type="unfinished"></translation>
<translation>Usa IPv6</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="133"/>
<location filename="../qml/pages/MainPage.qml" line="148"/>
<source>Ping it</source>
<translation>Manda un ping</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="141"/>
<location filename="../qml/pages/MainPage.qml" line="156"/>
<source>History</source>
<translation>Cronologia</translation>
</message>
</context>
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="36"/>
<source>Settings</source>
<translation>Impostazioni</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="42"/>
<source>Enable poller</source>
<translation>Abilita monitor</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="43"/>
<source>Pings every N minutes all hosts in the history</source>
<translation>Effettua un ping ogni N minuti su ogni host nella cronologia</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="51"/>
<source>Poller interval in minutes</source>
<translation>Intervallo del monitor in minuti</translation>
</message>
</context>
</TS>
......@@ -71,38 +71,66 @@
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="66"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="73"/>
<source>Ping all</source>
<translation>Pinga alla</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="76"/>
<location filename="../qml/pages/MainPage.qml" line="86"/>
<source>Clear history</source>
<translation>Rensa historiken</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="89"/>
<location filename="../qml/pages/MainPage.qml" line="104"/>
<source>Ping any host!</source>
<translation>Pinga en värddator!</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="97"/>
<location filename="../qml/pages/MainPage.qml" line="112"/>
<source>An IP address or hostname</source>
<translation>En IP-adress eller ett värdnamn</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="117"/>
<location filename="../qml/pages/MainPage.qml" line="132"/>
<source>Use IPv6</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="133"/>
<location filename="../qml/pages/MainPage.qml" line="148"/>
<source>Ping it</source>
<translation>Pinga den</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="141"/>
<location filename="../qml/pages/MainPage.qml" line="156"/>
<source>History</source>
<translation>Historik</translation>
</message>
</context>
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="36"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="42"/>
<source>Enable poller</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="43"/>
<source>Pings every N minutes all hosts in the history</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="51"/>
<source>Poller interval in minutes</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
......@@ -71,38 +71,66 @@
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="66"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="73"/>
<source>Ping all</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="76"/>
<location filename="../qml/pages/MainPage.qml" line="86"/>
<source>Clear history</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="89"/>
<location filename="../qml/pages/MainPage.qml" line="104"/>
<source>Ping any host!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="97"/>
<location filename="../qml/pages/MainPage.qml" line="112"/>
<source>An IP address or hostname</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="117"/>
<location filename="../qml/pages/MainPage.qml" line="132"/>
<source>Use IPv6</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="133"/>
<location filename="../qml/pages/MainPage.qml" line="148"/>
<source>Ping it</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="141"/>
<location filename="../qml/pages/MainPage.qml" line="156"/>
<source>History</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="36"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="42"/>
<source>Enable poller</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="43"/>
<source>Pings every N minutes all hosts in the history</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="51"/>
<source>Poller interval in minutes</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment