diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${ECM_MODULE_PATH}) find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Qml Quick Widgets Test Sql Positioning) -find_package(KF5 5.5 REQUIRED COMPONENTS I18n Declarative Config DBusAddons KIO GuiAddons CoreAddons) +find_package(KF5 5.5 REQUIRED COMPONENTS I18n Declarative Config DBusAddons KIO GuiAddons CoreAddons Notifications) find_package(Exiv2 0.21 REQUIRED) include(FeatureSummary) diff --git a/qmlUiKirigami/ImageViewer.qml b/qmlUiKirigami/ImageViewer.qml --- a/qmlUiKirigami/ImageViewer.qml +++ b/qmlUiKirigami/ImageViewer.qml @@ -39,6 +39,33 @@ leftPadding: 0 rightPadding: 0 + + KQA.MimeDatabase { + id: mimeDB + } + + actions { + main: Kirigami.Action { + iconName: "document-share" + tooltip: i18n("Share Image") + onTriggered: { + shareDialog.sheetOpen = true + shareDialog.inputData = { + "urls": [ listView.currentItem.currentImageSource.toString() ], + "mimeType": mimeDB.mimeTypeForUrl( listView.currentItem.currentImageSource).name + } + } + } + left: Kirigami.Action { + iconName: "view-close" + tooltip: i18n("Close Image") + onTriggered: root.state = "closed" + } + right: Kirigami.Action { + iconName: "editimage" + tooltip: i18n("Edit Image") + } + } states: [ State { @@ -74,6 +101,10 @@ target: root visible: false } + PropertyChanges { + target: shareDialog + sheetOpen: false + } }, State { name: "fullscreen" @@ -165,10 +196,12 @@ listView.positionViewAtIndex(currentIndex, ListView.Beginning) footerList.opacity = 1.0 timer.restart() + shareDialog.sheetOpen = false } delegate: Flickable { id: flick + property alias currentImageSource: image.source width: imageWidth height: imageHeight contentWidth: imageWidth @@ -355,10 +388,25 @@ } } } + + ShareDialog { + id: shareDialog + inputData: { urls: [] } + sheetOpen: false + onFinished: { + if (error==0 && output.url !== "") { + console.assert(output.url !== undefined); + var resultUrl = output.url; + console.log("Received", resultUrl) + //Qt.openUrlExternally(resultUrl) + notificationManager.showNotification( true, resultUrl); + } else { + notificationManager.showNotification( false); + } + } + } - //FIXME: placeholder, will have to use the state machine - Controls.Button { - text: i18n("Back") - onClicked: root.state = "closed" + Koko.NotificationManager { + id: notificationManager } } diff --git a/qmlUiKirigami/Main.qml b/qmlUiKirigami/Main.qml --- a/qmlUiKirigami/Main.qml +++ b/qmlUiKirigami/Main.qml @@ -192,7 +192,7 @@ id: imageViewer //go on top of the overlay drawer //HACK on the parent and z to go on top of the handle as well - z: 2000002 + z: 1999999 parent: root.overlay.parent width: overlay.width height: overlay.height diff --git a/qmlUiKirigami/ShareDialog.qml b/qmlUiKirigami/ShareDialog.qml new file mode 100644 --- /dev/null +++ b/qmlUiKirigami/ShareDialog.qml @@ -0,0 +1,64 @@ +/* + * Copyright 2017 by Atul Sharma + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.1 as Controls +import org.kde.purpose 1.0 as Purpose +import org.kde.kirigami 2.1 as Kirigami + +Kirigami.OverlaySheet +{ + id: window + property alias inputData: view.inputData + property bool running: false + signal finished(var output, int error, string message) + + Controls.BusyIndicator { + visible: window.running + anchors.fill: parent + } + + contentItem: ColumnLayout { + height: Kirigami.Units.gridUnit * 16 + + Kirigami.Heading { + text: window.inputData.mimeType ? i18n("Shares for '%1'", window.inputData.mimeType) : "" + } + Purpose.AlternativesView { + id: view + Layout.fillWidth: true + Layout.fillHeight: true + pluginType: "Export" + + delegate: Kirigami.BasicListItem { + label: model.display + icon: "arrow-right" + onClicked: view.createJob (model.index) + Keys.onReturnPressed: view.createJob (model.index) + Keys.onEnterPressed: view.createJob (model.index) + } + + onRunningChanged: window.running = running + onFinished: { + window.finished(output, error, message) + } + } + } +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,6 +63,7 @@ allimagesmodel.cpp fileinfo.cpp imagelistmodel.cpp + notificationmanager.cpp types.cpp roles.cpp ) @@ -75,6 +76,7 @@ KF5::KIOFileWidgets KF5::KIOWidgets KF5::GuiAddons + KF5::Notifications kokocommon ) @@ -129,3 +131,4 @@ install (FILES ${CMAKE_CURRENT_BINARY_DIR}/admin1Codes.txt DESTINATION ${DATA_INSTALL_DIR}/koko) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/admin2Codes.txt DESTINATION ${DATA_INSTALL_DIR}/koko) install (FILES countries.csv DESTINATION ${DATA_INSTALL_DIR}/koko) +install (FILES koko.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR}) diff --git a/src/koko.notifyrc b/src/koko.notifyrc new file mode 100644 --- /dev/null +++ b/src/koko.notifyrc @@ -0,0 +1,13 @@ +[Global] +IconName=koko +Name=Koko + +[Event/sharingSuccess] +Name=Sharing success +Comment=Image Shared Successfully +Action=Popup + +[Event/sharingFailed] +Name=Sharing failed +Comment=Image Sharing failed +Action=Popup diff --git a/src/notificationmanager.h b/src/notificationmanager.h new file mode 100644 --- /dev/null +++ b/src/notificationmanager.h @@ -0,0 +1,44 @@ +/* + * Copyright 2017 by Atul Sharma + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef NOTIFICATION_MANAGER_H +#define NOTIFICATION_MANAGER_H + +#include +#include + +class NotificationManager: public QObject +{ + Q_OBJECT +public: + explicit NotificationManager(QObject *parent = 0); + ~NotificationManager(); + + /** + * @argument valid: to check whether the returned url after sharing is valid or not + * @argument url: the valid url returned after sharing the image + */ + Q_INVOKABLE void showNotification(bool valid, QVariant url = QVariant()); + +private: + KNotification *m_sharingSuccess; + KNotification *m_sharingFailed; + +}; +#endif diff --git a/src/notificationmanager.cpp b/src/notificationmanager.cpp new file mode 100644 --- /dev/null +++ b/src/notificationmanager.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2017 by Atul Sharma + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "notificationmanager.h" + +NotificationManager::NotificationManager(QObject* parent) +{ + Q_UNUSED(parent) + m_sharingSuccess = new KNotification( "sharingSuccess", KNotification::Persistent); + + m_sharingFailed = new KNotification( "sharingFailed", KNotification::CloseOnTimeout); + m_sharingFailed->setText("Sharing failed"); +} + +NotificationManager::~NotificationManager() +{ + delete m_sharingFailed; + delete m_sharingSuccess; +} + +void NotificationManager::showNotification(bool valid, QVariant url) +{ + if (valid) { + m_sharingSuccess->setText("Shared url for image is " + url.toString()); + m_sharingSuccess->sendEvent(); + } else { + m_sharingFailed->sendEvent(); + } +} + +#include "moc_notificationmanager.cpp" diff --git a/src/qmlplugins.cpp b/src/qmlplugins.cpp --- a/src/qmlplugins.cpp +++ b/src/qmlplugins.cpp @@ -29,6 +29,7 @@ #include "allimagesmodel.h" #include "fileinfo.h" #include "imagelistmodel.h" +#include "notificationmanager.h" #include "types.h" #include "roles.h" @@ -49,6 +50,7 @@ qmlRegisterType (uri, 0, 1, "SortModel"); qmlRegisterType (uri, 0, 1, "FileInfo"); qmlRegisterType (uri, 0, 1, "ImageListModel"); + qmlRegisterType (uri, 0, 1, "NotificationManager"); qmlRegisterUncreatableType(uri, 0, 1, "Types", "Cannot instantiate the Types class"); qmlRegisterUncreatableType(uri, 0, 1, "Roles", "Cannot instantiate the Roles class"); }