Notification baner added

This commit is contained in:
mkiol 2014-02-13 23:22:55 +01:00
parent 214600f894
commit 28ea995374
13 changed files with 130 additions and 82 deletions

View file

@ -41,7 +41,8 @@ OTHER_FILES += \
qml/icon.png \
qml/SettingsPage.qml \
qml/AdvancedSettingsPage.qml \
qml/EmptyPage.qml
qml/scripts.js \
qml/Notification.qml
HEADERS += \
src/utils.h \

View file

@ -47,7 +47,7 @@ DockedPanel {
dock: Dock.Bottom
Rectangle {
/*Rectangle {
id: shadow
anchors.fill: parent
color: Theme.rgba(Theme.highlightBackgroundColor, 0.4)
@ -59,7 +59,7 @@ DockedPanel {
offset: 0.5
direction: OpacityRamp.BottomToTop
sourceItem: shadow
}
}*/
Rectangle {
id: background

View file

@ -81,6 +81,7 @@ PullDownMenu {
target: fetcher
onReady: update()
}
}
}

55
qml/Notification.qml Normal file
View file

@ -0,0 +1,55 @@
/*
Copyright (C) 2014 Michal Kosciesza <michal@mkiol.net>
This file is part of Kaktus.
Kaktus 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.
Kaktus 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 Kaktus. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import Sailfish.Silica 1.0
Rectangle {
id: root
width: parent.width
height: 50
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
color: Theme.highlightBackgroundColor
opacity: timer.running ? 1.0 : 0.0
Behavior on opacity { FadeAnimation {} }
function show(text) {
label.text = text;
timer.restart();
}
Label {
id: label
font.pixelSize: Theme.fontSizeSmall
font.family: Theme.fontFamily
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left; anchors.leftMargin: Theme.paddingMedium
opacity: 0.8
color: "black"
}
Timer {
id: timer
interval: 2000
}
}

View file

@ -40,48 +40,12 @@ Dialog {
acceptText : qsTr("Sign In")
}
Rectangle {
id: infoLabel
anchors {
left: parent.left; leftMargin: Theme.paddingLarge
right: parent.right; rightMargin: Theme.paddingLarge
}
height: childrenRect.height + 2*Theme.paddingLarge
color: Theme.rgba(Theme.highlightBackgroundColor, 0.2)
radius: 5
Label {
anchors.centerIn: parent;
wrapMode: Text.Wrap
textFormat: Text.PlainText
font.pixelSize: Theme.fontSizeSmall
Component.onCompleted: {
switch (code) {
case 402:
text = qsTr("Username & password do not match!");
break;
default:
text = qsTr("Enter Netvibes username & password");
}
}
}
}
Label {
text: " "
}
/*Label {
text: qsTr("Username")
}*/
TextField {
id: user
anchors.left: parent.left; anchors.right: parent.right
inputMethodHints: Qt.ImhEmailCharactersOnly| Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
placeholderText: "Enter username here!"
placeholderText: qsTr("Enter username here!")
label: qsTr("Username")
Component.onCompleted: {
@ -89,19 +53,22 @@ Dialog {
}
}
/*Label {
text: qsTr("Password")
}*/
TextField {
id: password
anchors.left: parent.left; anchors.right: parent.right
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText | Qt.ImhSensitiveData
echoMode: TextInput.Password
placeholderText: "Enter password here!"
placeholderText: qsTr("Enter password here!")
label: qsTr("Password")
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
EnterKey.onClicked: {
Qt.inputMethod.hide();
root.accept();
}
}
}
onAccepted: {

View file

@ -79,6 +79,17 @@ Page {
}
PullDownMenu {
MenuItem {
text: qsTr("Copy URL")
onClicked: {
if (offLineMode)
utils.copyToClipboard(offlineUrl);
else
utils.copyToClipboard(onlineUrl);
}
}
MenuItem {
text: qsTr("Open in browser")

View file

@ -27,19 +27,15 @@ ApplicationWindow {
onOffLineModeChanged: {
settings.setOfflineMode(offLineMode);
if (offLineMode)
notification.show(qsTr("Switched to Offline mode!"));
else
notification.show(qsTr("Switched to Online mode!"));
}
Component.onCompleted: {
offLineMode = settings.getOfflineMode();
/*if (settings.getSignedIn()) {
// User signed in, getting stored data
db.init();
} else {
// User not signed in, showing empty page
pageStack.push(Qt.resolvedUrl("EmptyPage.qml"));
}*/
db.init();
}
@ -49,6 +45,13 @@ ApplicationWindow {
onSettingsChanged: {
offLineMode = settings.getOfflineMode();
}
onError: {
console.log("Settings error!");
console.log("code=" + code);
notification.show(qsTr("An unknown error occurred! :-("));
Qt.quit();
}
}
Connections {
@ -62,8 +65,6 @@ ApplicationWindow {
onEmpty: {
console.log("DB is empty!");
// No stred data, showing empty page
// pageStack.push(Qt.resolvedUrl("EmptyPage.qml"));
utils.setTabModel(settings.getNetvibesDefaultDashboard());
pageStack.clear()
pageStack.push(Qt.resolvedUrl("TabPage.qml"));
@ -72,7 +73,6 @@ ApplicationWindow {
onNotEmpty: {
console.log("DB is not empty!");
// Found stored data, showing tabs
utils.setTabModel(settings.getNetvibesDefaultDashboard());
pageStack.clear()
pageStack.push(Qt.resolvedUrl("TabPage.qml"));
@ -126,7 +126,7 @@ ApplicationWindow {
onReady: {
console.log("Fetcher ready!");
notification.show(qsTr("Sync done!"));
utils.setTabModel(settings.getNetvibesDefaultDashboard());
pageStack.clear()
pageStack.push(Qt.resolvedUrl("TabPage.qml"));
@ -148,22 +148,26 @@ ApplicationWindow {
}
if (code >= 400 && code < 500) {
if (code == 402)
notification.show(qsTr("User & Password do not match!"));
// Sign in
pageStack.push(Qt.resolvedUrl("SignInDialog.qml"),{"code": code});
} else {
// Unknown error
pageStack.push(Qt.resolvedUrl("ErrorPage.qml"),{"message": "Fether error, code: " + code});
notification.show(qsTr("An unknown error occurred! :-("));
}
}
onErrorCheckingCredentials: {
console.log("Fetcher checking error");
console.log("code=" + code);
notification.show(qsTr("User & Password do not match!"));
busy.hide();
}
onCredentialsValid: {
console.log("Fetcher credentials valid");
notification.show(qsTr("Successfully Signed In!"));
busy.hide();
}
@ -213,6 +217,10 @@ ApplicationWindow {
}
}
Notification {
id: notification
}
Image {
anchors {
right: parent.right

View file

@ -25,6 +25,7 @@
#include <QtDebug>
#include <QGuiApplication>
#include <QScopedPointer>
#include <QQmlEngine>
#include <sailfishapp.h>
#include "databasemanager.h"
@ -49,6 +50,8 @@ int main(int argc, char *argv[])
view->rootContext()->setContextProperty("PAGE", PAGE);
app->setOrganizationName("mkiol");
app->setApplicationDisplayName(APP_NAME);
app->setApplicationVersion(VERSION);
DatabaseManager db;
DownloadManager dm(&db);
@ -57,7 +60,7 @@ int main(int argc, char *argv[])
Utils utils(&db, view.data());
QObject::connect(&fetcher, SIGNAL(ready()), &utils, SLOT(updateModels()));
//QObject::connect(view->engine(), SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
QObject::connect(view->engine(), SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
view->rootContext()->setContextProperty("db", &db);
view->rootContext()->setContextProperty("fetcher", &fetcher);

View file

@ -135,21 +135,19 @@ int Settings::getDmCacheRetencyFeedLimit()
return settings.value("dm_limit", 20).toInt();
}
void Settings::setSettingsDir(const QString &value)
/*void Settings::setSettingsDir(const QString &value)
{
settings.setValue("settingsdir", value);
}
}*/
QString Settings::getSettingsDir()
{
QString value = QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation))
.filePath(QCoreApplication::applicationName());
value = settings.value("settingsdir", value).toString();
QString value = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)).path();
if (!QDir(value).exists()) {
if (!QDir::root().mkpath(value)) {
qWarning() << "Unable to create settings dir!";
/// @todo handle 'Unable to create settings dir'
emit error(501);
}
}
@ -186,21 +184,20 @@ int Settings::getDmMaxSize()
return settings.value("maxsize", 1000000).toInt();
}
void Settings::setDmCacheDir(const QString &value)
/*void Settings::setDmCacheDir(const QString &value)
{
settings.setValue("cachedir", value);
}
}*/
QString Settings::getDmCacheDir()
{
QString value = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))
.filePath("cached_files");
value = settings.value("cachedir", value).toString();
if (!QDir(value).exists()) {
if (!QDir::root().mkpath(value)) {
qWarning() << "Unable to create cache dir!";
/// @todo handle 'Unable to create cache dir'
emit error(502);
}
}

View file

@ -35,7 +35,7 @@ public:
static Settings* instance();
// General
Q_INVOKABLE void setSettingsDir(const QString &value);
//Q_INVOKABLE void setSettingsDir(const QString &value);
Q_INVOKABLE QString getSettingsDir();
Q_INVOKABLE void setAutoDownloadOnUpdate(bool value);
Q_INVOKABLE bool getAutoDownloadOnUpdate();
@ -65,7 +65,7 @@ public:
Q_INVOKABLE int getDmTimeOut();
Q_INVOKABLE void setDmMaxSize(int value);
Q_INVOKABLE int getDmMaxSize();
Q_INVOKABLE void setDmCacheDir(const QString &value);
//Q_INVOKABLE void setDmCacheDir(const QString &value);
Q_INVOKABLE QString getDmCacheDir();
Q_INVOKABLE void setDmUserAgent(const QString &value);
Q_INVOKABLE QString getDmUserAgent();
@ -80,6 +80,11 @@ public:
signals:
void settingsChanged();
/*
501 - Unable create settings dir
502 - Unable create cache dir
*/
void error(int);
private:
QSettings settings;

View file

@ -25,19 +25,18 @@ Utils::Utils(DatabaseManager* db, QQuickView* view, QObject *parent) :
_db = db;
_view = view;
_dashboardModel = NULL;
//offLine = false;
}
/*bool Utils::isOffline()
void Utils::copyToClipboard(const QString &text)
{
return offLine;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QClipboard *clipboard = QGuiApplication::clipboard();
#else
QClipboard *clipboard = QApplication::clipboard();
#endif
clipboard->setText(text);
}
void Utils::setMode(bool isOffline)
{
offLine = isOffline;
}*/
void Utils::setTabModel(const QString &dashboardId)
{
TabModel* tabModel;

View file

@ -28,6 +28,8 @@
#include <QString>
#include <QDebug>
#include <QStringList>
#include <QGuiApplication>
#include <QClipboard>
#include "tabmodel.h"
#include "dashboardmodel.h"
@ -45,9 +47,8 @@ public:
Q_INVOKABLE void setFeedModel(const QString &tabId);
Q_INVOKABLE void setTabModel(const QString &dashboardId);
Q_INVOKABLE void setDashboardModel();
//Q_INVOKABLE bool isOffline();
//Q_INVOKABLE void setMode(bool isOffline);
Q_INVOKABLE QList<QString> dashboards();
Q_INVOKABLE void copyToClipboard(const QString &text);
/*Q_INVOKABLE void setAsRead(const QString &entryId);
Q_INVOKABLE void unsetAsRead(const QString &entryId);