Commit 09e0265f authored by Karel Slaný's avatar Karel Slaný

Moved copied SpinBox code into a separate unit.

parent 2152dbbd
......@@ -49,6 +49,7 @@ TRANSLATIONS += res/locale/datovka_en.ts \
lupdate_only {
SOURCES += qml/*.qml \
qml/components/*.qml \
qml/pages/*.qml
}
......
/*
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
import QtQuick.Controls 2.0
SpinBox {
/* Must be a non-decreasing list ending with infinity. */
property var items: [1, qsTr("max")]
property int dfltIdx: 0
from: 0
to: items.length - 1 /* Last is infinite. */
//stepSize: 1
textFromValue: function(value) {
return items[value];
}
valueFromText: function(text) {
for (var i = 0; i < items.length; ++i) {
if (items[i].toLowerCase().indexOf(text.toLowerCase()) === 0) {
return i
}
}
return sb.value
}
function val() {
if (value < to) { /* Last is infinite. */
return items[value]
} else {
return 0 /* Infinity is treated as zero. */
}
}
function setVal(v) {
if (v <= 0) { /* infinite */
value = to
} else if (v < items[0]) { /* less than minimal */
value = from
} else if (v > items[to - 1]) { /* more than maximal */
value = to
} else {
for (var i = 0; i < (items.length - 1); ++i) {
if (v == items[i]) {
value = i
return
} else if (v < items[i]) {
value = i - 1
return
}
}
value = from
}
}
}
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -24,6 +24,7 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import cz.nic.mobileDatovka 1.0
Component {
id: pinPage
......@@ -330,61 +331,15 @@ Component {
text: qsTr("Lock after seconds of inactivity")
horizontalAlignment: Text.AlignHCenter
}
SpinBox {
SpinBoxZeroMax {
/* Holds value in seconds. */
id: lockIntervalSpinBox
anchors.horizontalCenter: parent.horizontalCenter
/* Must be a non-decreasing list ending with infinity. */
property var items: [15, 30, 60, 90, 120, 150, 180, qsTr("don't lock")]
property int dfltIdx: 0
from: 0
to: items.length - 1 /* Last is infinite. */
//stepSize: 1
textFromValue: function(value) {
return items[value];
}
valueFromText: function(text) {
for (var i = 0; i < items.length; ++i) {
if (items[i].toLowerCase().indexOf(text.toLowerCase()) === 0) {
return i
}
}
return sb.value
}
function val() {
if (value < to) { /* Last is infinite. */
return items[value]
} else {
return 0 /* Infinity is treated as zero. */
}
}
function setVal(v) {
if (v <= 0) { /* infinite */
value = to
} else if (v < items[0]) { /* less than minimal */
value = from
} else if (v > items[to - 1]) { /* more than maximal */
value = to
} else {
for (var i = 0; i < (items.length - 1); ++i) {
if (v == items[i]) {
value = i
return
} else if (v < items[i]) {
value = i - 1
return
}
}
value = from
}
}
items: [15, 30, 60, 90, 120, 150, 180, qsTr("don't lock")]
dfltIdx: 0
onValueChanged: {
/* Enable accept button. Always visible? */
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -24,6 +24,7 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import cz.nic.mobileDatovka 1.0
Component {
id: settingsDialog
......@@ -105,59 +106,13 @@ Component {
width: myWidht
text: qsTr("Number of days to keep messages")
}
SpinBox {
SpinBoxZeroMax {
/* Holds value in days. */
id: messageLifeSpinBox
/* Must be a non-decreasing list ending with infinity. */
property var items: [90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, qsTr("don't delete")]
property int dfltIdx: 0
from: 0
to: items.length - 1 /* Last is infinite. */
//stepSize: 1
textFromValue: function(value) {
return items[value];
}
valueFromText: function(text) {
for (var i = 0; i < items.length; ++i) {
if (items[i].toLowerCase().indexOf(text.toLowerCase()) === 0) {
return i
}
}
return sb.value
}
function val() {
if (value < to) { /* Last is infinite. */
return items[value]
} else {
return 0 /* Infinity is treated as zero. */
}
}
function setVal(v) {
if (v <= 0) { /* infinite */
value = to
} else if (v < items[0]) { /* less than minimal */
value = from
} else if (v > items[to - 1]) { /* more than maximal */
value = to
} else {
for (var i = 0; i < (items.length - 1); ++i) {
if (v == items[i]) {
value = i
return
} else if (v < items[i]) {
value = i - 1
return
}
}
value = from
}
}
items: [90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, qsTr("don't delete")]
dfltIdx: 0
}
Text {
color: datovkaPalette.mid
......@@ -178,59 +133,13 @@ Component {
width: myWidht
text: qsTr("Number of days to keep attachments")
}
SpinBox {
SpinBoxZeroMax {
/* Holds value in days. */
id: attachLifeSpinBox
/* Must be a non-decreasing list ending with infinity. */
property var items: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, qsTr("like messages")]
property int dfltIdx: 1
from: 0
to: items.length - 1 /* Last is infinite. */
//stepSize: 1
textFromValue: function(value) {
return items[value];
}
valueFromText: function(text) {
for (var i = 0; i < items.length; ++i) {
if (items[i].toLowerCase().indexOf(text.toLowerCase()) === 0) {
return i
}
}
return sb.value
}
function val() {
if (value < to) { /* Last is infinite. */
return items[value]
} else {
return 0 /* Infinity is treated as zero. */
}
}
function setVal(v) {
if (v <= 0) { /* infinite */
value = to
} else if (v < items[0]) { /* less than minimal */
value = from
} else if (v > items[to - 1]) { /* more than maximal */
value = to
} else {
for (var i = 0; i < (items.length - 1); ++i) {
if (v == items[i]) {
value = i
return
} else if (v < items[i]) {
value = i - 1
return
}
}
value = from
}
}
items: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, qsTr("like messages")]
dfltIdx: 1
}
Text {
color: datovkaPalette.mid
......
......@@ -110,5 +110,6 @@
<file>../qml/pages/MessageDetailMenuPage.qml</file>
<file>../qml/pages/MessageMenuPage.qml</file>
<file>../qml/pages/MessagesMenuPage.qml</file>
<file>../qml/components/SpinBoxZeroMax.qml</file>
</qresource>
</RCC>
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -47,11 +47,21 @@
/* namespace for QML registered objects */
const char *uri = "cz.nic.mobileDatovka";
/* For registering of pages */
static const struct {
const char *type;
int major, minor;
} qmldir_pages [] = {
/*!
* @brief Used when registering types.
*/
struct QmlTypeEntry {
const char *typeName;
int major;
int minor;
};
#define QML_PAGE_LOC "qrc:/qml/pages"
/*!
* @brief NULL-terminated list of pages.
*/
static
const struct QmlTypeEntry qmlPages[] = {
{ "AccountsPage", 1, 0 },
{ "MessagesPage", 1, 0 },
{ "MessageMenuPage", 1, 0 },
......@@ -67,11 +77,46 @@ static const struct {
{ "SettingsGeneralPage", 1, 0 },
{ "SettingsSyncPage", 1, 0 },
{ "SettingsStoragePage", 1, 0 },
{ NULL, 0, 0 }
};
int main(int argc, char *argv[])
#define QML_COMPONENT_LOC "qrc:/qml/components"
/*!
* @brief NULL-terminated list of components.
*/
static
const struct QmlTypeEntry qmlComponents[] = {
{ "SpinBoxZeroMax", 1, 0 },
{ NULL, 0, 0 }
};
/*!
* @brief Registers QML types.
*
* @param[in] uri Namespace for QML objects.
* @param[in] location Location of the QML description file.
* @Param[in] entries List of entries describing the types.
*/
static
void registerQmlTypes(const char *uri, const char *location,
const struct QmlTypeEntry *entries)
{
if ((uri == NULL) || (location == NULL)) {
Q_ASSERT(0);
return;
}
const struct QmlTypeEntry *entry = entries;
while ((entry != NULL) && (entry->typeName != NULL)) {
qmlRegisterType(
QUrl(QString("%1/%2.qml").arg(location).arg(entry->typeName)),
uri, entry->major, entry->minor, entry->typeName);
++entry;
}
}
int main(int argc, char *argv[])
{
/* Perform check that configuration file can be accessed. */
const QString settingsFileName(Settings::settingsPath());
if (settingsFileName.isEmpty()) {
......@@ -153,13 +198,9 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
QQmlContext *ctx = engine.rootContext();
/* load and register application pages to QML */
for (int i = 0; i < int(sizeof(qmldir_pages)/sizeof(qmldir_pages[0])); i++) {
qmlRegisterType(QUrl(
QString("qrc:/qml/pages/%1.qml").arg(qmldir_pages[i].type)),
uri, qmldir_pages[i].major, qmldir_pages[i].minor,
qmldir_pages[i].type);
}
/* Register application pages to QML */
registerQmlTypes(uri, QML_PAGE_LOC, qmlPages);
registerQmlTypes(uri, QML_COMPONENT_LOC, qmlComponents);
/* Register types into QML. */
Messages::declareQML();
......
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