diff --git a/autotests/localfilelistingtest.cpp b/autotests/localfilelistingtest.cpp --- a/autotests/localfilelistingtest.cpp +++ b/autotests/localfilelistingtest.cpp @@ -61,7 +61,6 @@ qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); - qRegisterMetaType("NotificationItem"); } void initialTestWithNoTrack() @@ -432,17 +431,13 @@ QSignalSpy modifiedTracksListSpy(&myListing, &LocalFileListing::modifyTracksList); QSignalSpy indexingStartedSpy(&myListing, &LocalFileListing::indexingStarted); QSignalSpy indexingFinishedSpy(&myListing, &LocalFileListing::indexingFinished); - QSignalSpy newNotificationSpy(&myListing, &LocalFileListing::newNotification); - QSignalSpy closeNotificationSpy(&myListing, &LocalFileListing::closeNotification); QSignalSpy askRestoredTracksSpy(&myListing, &LocalFileListing::askRestoredTracks); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(indexingStartedSpy.count(), 0); QCOMPARE(indexingFinishedSpy.count(), 0); - QCOMPARE(newNotificationSpy.count(), 0); - QCOMPARE(closeNotificationSpy.count(), 0); QCOMPARE(askRestoredTracksSpy.count(), 0); myListing.setAllRootPaths({QStringLiteral("/does/not/exists")}); @@ -452,8 +447,6 @@ QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(indexingStartedSpy.count(), 0); QCOMPARE(indexingFinishedSpy.count(), 0); - QCOMPARE(newNotificationSpy.count(), 0); - QCOMPARE(closeNotificationSpy.count(), 0); QCOMPARE(askRestoredTracksSpy.count(), 0); myListing.init(); @@ -463,8 +456,6 @@ QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(indexingStartedSpy.count(), 0); QCOMPARE(indexingFinishedSpy.count(), 0); - QCOMPARE(newNotificationSpy.count(), 0); - QCOMPARE(closeNotificationSpy.count(), 0); QCOMPARE(askRestoredTracksSpy.count(), 1); myListing.restoredTracks({{QUrl::fromLocalFile(QStringLiteral("/removed/files1")), QDateTime::fromMSecsSinceEpoch(1)}, @@ -475,8 +466,6 @@ QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(indexingStartedSpy.count(), 1); QCOMPARE(indexingFinishedSpy.count(), 0); - QCOMPARE(newNotificationSpy.count(), 0); - QCOMPARE(closeNotificationSpy.count(), 0); QCOMPARE(askRestoredTracksSpy.count(), 1); auto removedTracksSignal = removedTracksListSpy.at(0); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,8 +12,6 @@ trackslistener.cpp elisaapplication.cpp modeldataloader.cpp - notificationitem.cpp - topnotificationmanager.cpp elisautils.cpp abstractfile/abstractfilelistener.cpp abstractfile/abstractfilelisting.cpp @@ -358,8 +356,6 @@ qml/RatingStar.qml qml/DraggableItem.qml - qml/TopNotification.qml - qml/TopNotificationItem.qml qml/TrackImportNotification.qml qml/HeaderBar.qml diff --git a/src/abstractfile/abstractfilelistener.h b/src/abstractfile/abstractfilelistener.h --- a/src/abstractfile/abstractfilelistener.h +++ b/src/abstractfile/abstractfilelistener.h @@ -18,8 +18,6 @@ #ifndef ABSTRACTFILELISTENER_H #define ABSTRACTFILELISTENER_H -#include "notificationitem.h" - #include #include #include @@ -63,10 +61,6 @@ void clearDatabase(); - void newNotification(NotificationItem notification); - - void closeNotification(QString notificationId); - public Q_SLOTS: void setDatabaseInterface(DatabaseInterface* databaseInterface); @@ -81,8 +75,6 @@ void setFileListing(AbstractFileListing *fileIndexer); - NotificationItem& currentNotification(); - private: std::unique_ptr d; diff --git a/src/abstractfile/abstractfilelistener.cpp b/src/abstractfile/abstractfilelistener.cpp --- a/src/abstractfile/abstractfilelistener.cpp +++ b/src/abstractfile/abstractfilelistener.cpp @@ -19,7 +19,6 @@ #include "abstractfilelisting.h" #include "databaseinterface.h" -#include "notificationitem.h" #include @@ -100,10 +99,6 @@ this, &AbstractFileListener::indexingStarted); connect(fileIndexer, &AbstractFileListing::indexingFinished, this, &AbstractFileListener::indexingFinished); - connect(fileIndexer, &AbstractFileListing::newNotification, - this, &AbstractFileListener::newNotification); - connect(fileIndexer, &AbstractFileListing::closeNotification, - this, &AbstractFileListener::closeNotification); } AbstractFileListing *AbstractFileListener::fileListing() const diff --git a/src/abstractfile/abstractfilelisting.h b/src/abstractfile/abstractfilelisting.h --- a/src/abstractfile/abstractfilelisting.h +++ b/src/abstractfile/abstractfilelisting.h @@ -20,8 +20,6 @@ #include "elisaLib_export.h" -#include "notificationitem.h" - #include #include #include @@ -33,7 +31,6 @@ class AbstractFileListingPrivate; class MusicAudioTrack; -class NotificationItem; class FileScanner; class QFileInfo; class QMimeDatabase; @@ -65,10 +62,6 @@ void indexingFinished(); - void newNotification(NotificationItem notification); - - void closeNotification(QString notificationId); - void askRestoredTracks(); void errorWatchingFileSystemChanges(); diff --git a/src/abstractfile/abstractfilelisting.cpp b/src/abstractfile/abstractfilelisting.cpp --- a/src/abstractfile/abstractfilelisting.cpp +++ b/src/abstractfile/abstractfilelisting.cpp @@ -22,7 +22,6 @@ #include "abstractfile/indexercommon.h" #include "musicaudiotrack.h" -#include "notificationitem.h" #include "filescanner.h" #include @@ -64,8 +63,6 @@ int mImportedTracksCount = 0; - int mNotificationUpdateInterval = 1; - int mNewFilesEmitInterval = 1; bool mHandleNewFiles = true; @@ -231,9 +228,6 @@ newFiles.push_back(newTrack); ++d->mImportedTracksCount; - if (d->mImportedTracksCount % d->mNotificationUpdateInterval == 0) { - d->mNotificationUpdateInterval = std::min(50, 1 + d->mNotificationUpdateInterval * 2); - } if (newFiles.size() > d->mNewFilesEmitInterval && d->mStopRequest == 0) { d->mNewFilesEmitInterval = std::min(50, 1 + d->mNewFilesEmitInterval * d->mNewFilesEmitInterval); diff --git a/src/android/androidmusiclistener.h b/src/android/androidmusiclistener.h --- a/src/android/androidmusiclistener.h +++ b/src/android/androidmusiclistener.h @@ -20,8 +20,6 @@ #ifndef ANDROIDMUSICLISTENER_H #define ANDROIDMUSICLISTENER_H -#include "notificationitem.h" - #include #include #include @@ -78,10 +76,6 @@ void clearDatabase(const QString &listenerName); - void newNotification(NotificationItem notification); - - void closeNotification(QString notificationId); - void tracksList(const QList &tracks, const QHash &covers, const QString &musicSource); void removedTracksList(const QList &removedTracks); diff --git a/src/baloo/localbaloofilelisting.cpp b/src/baloo/localbaloofilelisting.cpp --- a/src/baloo/localbaloofilelisting.cpp +++ b/src/baloo/localbaloofilelisting.cpp @@ -20,7 +20,6 @@ #include "baloo/baloocommon.h" #include "musicaudiotrack.h" -#include "notificationitem.h" #include "elisa_settings.h" #include "elisautils.h" @@ -117,7 +116,6 @@ LocalBalooFileListing::~LocalBalooFileListing() { - Q_EMIT closeNotification(QStringLiteral("balooInvalidConfiguration")); } void LocalBalooFileListing::applicationAboutToQuit() diff --git a/src/elisaimport.cpp b/src/elisaimport.cpp --- a/src/elisaimport.cpp +++ b/src/elisaimport.cpp @@ -37,7 +37,6 @@ qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType>(); - qRegisterMetaType("NotificationItem"); qRegisterMetaType>("QMap"); QCommandLineParser parser; diff --git a/src/elisaqmlplugin.cpp b/src/elisaqmlplugin.cpp --- a/src/elisaqmlplugin.cpp +++ b/src/elisaqmlplugin.cpp @@ -63,8 +63,6 @@ #endif #include "audiowrapper.h" -#include "notificationitem.h" -#include "topnotificationmanager.h" #if defined Qt5DBus_FOUND && Qt5DBus_FOUND #include "mpris2/mpris2.h" @@ -133,7 +131,6 @@ #endif qmlRegisterType(uri, 1, 0, "AudioWrapper"); - qmlRegisterType(uri, 1, 0, "TopNotificationManager"); qmlRegisterUncreatableType(uri, 1, 0, "DatabaseInterface", QStringLiteral("Only created in c++")); #if defined Qt5DBus_FOUND && Qt5DBus_FOUND @@ -160,7 +157,6 @@ qRegisterMetaType("TracksListener::ListTrackDataType"); qRegisterMetaType>(); qRegisterMetaType(); - qRegisterMetaType("NotificationItem"); qRegisterMetaType>("QMap"); qRegisterMetaType("ElisaUtils::PlayListEnqueueMode"); qRegisterMetaType("ElisaUtils::PlayListEnqueueTriggerPlay"); diff --git a/src/musiclistenersmanager.h b/src/musiclistenersmanager.h --- a/src/musiclistenersmanager.h +++ b/src/musiclistenersmanager.h @@ -20,7 +20,6 @@ #include "elisaLib_export.h" -#include "notificationitem.h" #include "databaseinterface.h" #include @@ -30,7 +29,6 @@ class MusicListenersManagerPrivate; class MediaPlayList; -class NotificationItem; class ElisaApplication; class ModelDataLoader; @@ -110,10 +108,6 @@ void importedTracksCountChanged(); - void newNotification(NotificationItem notification); - - void closeNotification(QString notificationId); - void elisaApplicationChanged(); void removeTracksInError(QList tracks); diff --git a/src/musiclistenersmanager.cpp b/src/musiclistenersmanager.cpp --- a/src/musiclistenersmanager.cpp +++ b/src/musiclistenersmanager.cpp @@ -39,7 +39,6 @@ #include "file/filelistener.h" #include "file/localfilelisting.h" #include "trackslistener.h" -#include "notificationitem.h" #include "elisaapplication.h" #include "elisa_settings.h" #include "modeldataloader.h" @@ -336,22 +335,14 @@ this, &MusicListenersManager::monitorEndingListeners); connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::clearDatabase, &d->mDatabaseInterface, &DatabaseInterface::removeAllTracksFromSource); - connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::newNotification, - this, &MusicListenersManager::newNotification); - connect(d->mAndroidMusicListener.get(), &AndroidMusicListener::closeNotification, - this, &MusicListenersManager::closeNotification); } #endif } void MusicListenersManager::increaseImportedTracksCount(const DatabaseInterface::ListTrackDataType &allTracks) { d->mImportedTracksCount += allTracks.size(); - //if (d->mImportedTracksCount >= 4) { - Q_EMIT closeNotification(QStringLiteral("notEnoughTracks")); - //} - Q_EMIT importedTracksCountChanged(); } @@ -370,24 +361,6 @@ void MusicListenersManager::monitorEndingListeners() { - /*if (d->mImportedTracksCount < 4 && d->mElisaApplication) { - NotificationItem notEnoughTracks; - - notEnoughTracks.setNotificationId(QStringLiteral("notEnoughTracks")); - - notEnoughTracks.setTargetObject(this); - - notEnoughTracks.setMessage(i18nc("No track found message", "No track have been found")); - - auto configureAction = d->mElisaApplication->action(QStringLiteral("options_configure")); - - notEnoughTracks.setMainButtonText(configureAction->text()); - notEnoughTracks.setMainButtonIconName(configureAction->icon().name()); - notEnoughTracks.setMainButtonMethodName(QStringLiteral("showConfiguration")); - - Q_EMIT newNotification(notEnoughTracks); - }*/ - d->mIndexerBusy = false; Q_EMIT indexerBusyChanged(); } @@ -449,10 +422,6 @@ this, &MusicListenersManager::monitorStartingListeners); connect(&d->mFileListener, &FileListener::indexingFinished, this, &MusicListenersManager::monitorEndingListeners); - connect(&d->mFileListener, &FileListener::newNotification, - this, &MusicListenersManager::newNotification); - connect(&d->mFileListener, &FileListener::closeNotification, - this, &MusicListenersManager::closeNotification); QMetaObject::invokeMethod(d->mFileListener.fileListing(), "init", Qt::QueuedConnection); @@ -475,10 +444,6 @@ this, &MusicListenersManager::monitorEndingListeners); connect(&d->mBalooListener, &BalooListener::clearDatabase, &d->mDatabaseInterface, &DatabaseInterface::clearData); - connect(&d->mBalooListener, &BalooListener::newNotification, - this, &MusicListenersManager::newNotification); - connect(&d->mBalooListener, &BalooListener::closeNotification, - this, &MusicListenersManager::closeNotification); QMetaObject::invokeMethod(d->mBalooListener.fileListing(), "init", Qt::QueuedConnection); diff --git a/src/notificationitem.h b/src/notificationitem.h deleted file mode 100644 --- a/src/notificationitem.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2017 Matthieu Gallien - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef NOTIFICATIONITEM_H -#define NOTIFICATIONITEM_H - -#include "elisaLib_export.h" - -#include - -#include - -class NotificationItemPrivate; -class QObject; - -class ELISALIB_EXPORT NotificationItem -{ - -public: - - NotificationItem(); - - NotificationItem(const NotificationItem &other); - - NotificationItem(NotificationItem &&other); - - NotificationItem& operator=(const NotificationItem &other); - - NotificationItem& operator=(NotificationItem &&other); - - ~NotificationItem(); - - const QString& notificationId() const; - - const QString& message() const; - - const QString& mainButtonText() const; - - const QString& mainButtonIconName() const; - - const QString& secondaryButtonText() const; - - const QString& secondaryButtonIconName() const; - - void setNotificationId(QString notificationId); - - void setMessage(QString message); - - void setMainButtonText(QString mainButtonText); - - void setMainButtonIconName(QString mainButtonIconName); - - void setSecondaryButtonText(QString secondaryButtonText); - - void setSecondaryButtonIconName(QString secondaryButtonIconName); - - void setTargetObject(QObject *target); - - void setMainButtonMethodName(QString methodName); - - void setSecondaryButtonMethodName(QString methodName); - - void triggerMainButton() const; - - void triggerSecondaryButton() const; - -private: - - std::unique_ptr d; - -}; - -#endif // NOTIFICATIONITEM_H diff --git a/src/notificationitem.cpp b/src/notificationitem.cpp deleted file mode 100644 --- a/src/notificationitem.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright 2017 Matthieu Gallien - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include "notificationitem.h" - -#include - -class NotificationItemPrivate { -public: - - QString mNotificationId; - - QString mMessage; - - QString mMainButtonText; - - QString mMainButtonIconName; - - QString mSecondaryButtonText; - - QString mSecondaryButtonIconName; - - QObject *mTarget = nullptr; - - QString mMainButtonMethodName; - - QString mSecondaryButtonMethodName; - -}; - -NotificationItem::NotificationItem() : d(std::make_unique()) -{ -} - -NotificationItem::NotificationItem(const NotificationItem &other) : d(std::make_unique(*other.d)) -{ -} - -NotificationItem::NotificationItem(NotificationItem &&other) -{ - other.d.swap(d); -} - -NotificationItem& NotificationItem::operator=(const NotificationItem &other) -{ - if (&other != this) { - *d = *(other.d); - } - - return *this; -} - -NotificationItem::~NotificationItem() -= default; - -const QString& NotificationItem::notificationId() const -{ - return d->mNotificationId; -} - -const QString& NotificationItem::message() const -{ - return d->mMessage; -} - -const QString& NotificationItem::mainButtonText() const -{ - return d->mMainButtonText; -} - -const QString& NotificationItem::secondaryButtonText() const -{ - return d->mSecondaryButtonText; -} - -const QString& NotificationItem::secondaryButtonIconName() const -{ - return d->mSecondaryButtonIconName; -} - -void NotificationItem::setNotificationId(QString notificationId) -{ - if (d->mNotificationId == notificationId) { - return; - } - - d->mNotificationId = std::move(notificationId); -} - -const QString& NotificationItem::mainButtonIconName() const -{ - return d->mMainButtonIconName; -} - -void NotificationItem::setMessage(QString message) -{ - if (d->mMessage == message) { - return; - } - - d->mMessage = std::move(message); -} - -void NotificationItem::setMainButtonText(QString mainButtonText) -{ - if (d->mMainButtonText == mainButtonText) { - return; - } - - d->mMainButtonText = std::move(mainButtonText); -} - -void NotificationItem::setSecondaryButtonText(QString secondaryButtonText) -{ - if (d->mSecondaryButtonText == secondaryButtonText) { - return; - } - - d->mSecondaryButtonText = std::move(secondaryButtonText); -} - -void NotificationItem::setSecondaryButtonIconName(QString secondaryButtonIconName) -{ - if (d->mSecondaryButtonIconName == secondaryButtonIconName) { - return; - } - - d->mSecondaryButtonIconName = std::move(secondaryButtonIconName); -} - -void NotificationItem::setTargetObject(QObject *target) -{ - d->mTarget = target; -} - -void NotificationItem::setMainButtonMethodName(QString methodName) -{ - d->mMainButtonMethodName = std::move(methodName); -} - -void NotificationItem::setSecondaryButtonMethodName(QString methodName) -{ - d->mSecondaryButtonMethodName = std::move(methodName); -} - -void NotificationItem::triggerMainButton() const -{ - if (!d->mTarget) { - return; - } - - QMetaObject::invokeMethod(d->mTarget, d->mMainButtonMethodName.toLatin1().data(), Qt::QueuedConnection); -} - -void NotificationItem::triggerSecondaryButton() const -{ - if (!d->mTarget) { - return; - } - - QMetaObject::invokeMethod(d->mTarget, d->mSecondaryButtonMethodName.toLatin1().data(), Qt::QueuedConnection); -} - -void NotificationItem::setMainButtonIconName(QString mainButtonIconName) -{ - if (d->mMainButtonIconName == mainButtonIconName) { - return; - } - - d->mMainButtonIconName = std::move(mainButtonIconName); -} diff --git a/src/qml/ContentView.qml b/src/qml/ContentView.qml --- a/src/qml/ContentView.qml +++ b/src/qml/ContentView.qml @@ -178,16 +178,6 @@ spacing: 0 - TopNotification { - id: invalidBalooConfiguration - - Layout.fillWidth: true - - musicManager: elisa.musicManager - - focus: true - } - Item { Layout.fillHeight: true Layout.fillWidth: true diff --git a/src/qml/TopNotification.qml b/src/qml/TopNotification.qml deleted file mode 100644 --- a/src/qml/TopNotification.qml +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright 2017 Matthieu Gallien - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -import QtQuick 2.7 -import QtQuick.Layouts 1.2 -import QtQuick.Controls 2.2 -import QtQml.Models 2.2 -import org.kde.elisa 1.0 - -FocusScope { - id: topItem - - property var musicManager - property bool isViewExpanded: false - - property int rowHeight: elisaTheme.delegateHeight * 2 - - visible: Layout.preferredHeight > 0 - - Rectangle { - anchors.fill: parent - - color: myPalette.mid - } - - Component { - id: highlightBar - - Rectangle { - width: notificationColumn.width - height: rowHeight - color: (topItem.state === 'expanded' ? myPalette.highlight : myPalette.mid) - - Behavior on color { - ColorAnimation { - duration: 300 - } - } - } - } - - Rectangle { - id: notificationCounter - - anchors { - top: parent.top - left: parent.left - margins: elisaTheme.layoutVerticalMargin - } - - width: elisaTheme.delegateToolButtonSize - height: elisaTheme.delegateToolButtonSize - - radius: width / 2 - - color: myPalette.window - - opacity: 0.0 - visible: opacity > 0 - - z: 3 - - ToolButton { - anchors.centerIn: parent - text: manager.countNotifications - - onClicked: topItem.isViewExpanded = !topItem.isViewExpanded - Accessible.onPressAction: onClicked - } - } - - ScrollView { - id: expandedView - - ScrollBar.vertical.policy: ScrollBar.AlwaysOff - - anchors { - top: parent.top - right: parent.right - left: notificationCounter.right - bottom: parent.bottom - } - - opacity: 0 - visible: opacity > 0 - - focus: true - - z: 2 - - ListView { - id: notificationColumn - - focus: true - - populate: Transition { - NumberAnimation { properties: "opacity"; from: 0; to: 1.0; duration: 300 } - } - - add: Transition { - NumberAnimation { properties: "opacity"; from: 0; to: 1.0; duration: 300 } - } - - displaced: Transition { - NumberAnimation { properties: "x,y"; duration: 300 } - } - - highlight: highlightBar - - model: DelegateModel { - model: manager - - delegate: TopNotificationItem { - id: currentDelegate - - focus: true - - width: ListView.view.width - height: rowHeight - - onEntered: notificationColumn.currentIndex = index - - onClose: manager.closeNotification(index) - - onMainButtonClicked: manager.triggerMainButton(index) - - onSecondaryButtonClicked: manager.triggerSecondaryButton(index) - - itemMessage: message - itemMainButtonText: mainButtonText - itemMainButtonIconName: mainButtonIconName - itemSecondaryButtonText: secondaryButtonText - itemSecondaryButtonIconName: secondaryButtonIconName - - ListView.onRemove: SequentialAnimation { - PropertyAction { target: currentDelegate; property: "ListView.delayRemove"; value: true } - ParallelAnimation { - NumberAnimation { target: currentDelegate; properties: "height"; from: elisaTheme.delegateHeight * 2; to: 0; duration: 300 } - NumberAnimation { target: currentDelegate; properties: "opacity"; from: 1.0; to: 0; duration: 300 } - } - PropertyAction { target: currentDelegate; property: "ListView.delayRemove"; value: false } - } - } - } - - function gotoBeginning() { - anim.from = notificationColumn.contentY; - anim.to = 0; - anim.running = true; - } - - NumberAnimation { id: anim; target: notificationColumn; property: "contentY"; duration: 300 } - } - } - - TopNotificationManager { - id: manager - } - - Connections { - target: elisa.musicManager - - onNewNotification: - manager.addNotification(notification) - - onCloseNotification: - manager.closeNotificationById(notificationId) - } - - states: [ - State { - name: "empty" - when: manager.countNotifications === 0 - - PropertyChanges { - target: topItem - Layout.preferredHeight: 0 - } - PropertyChanges { - target: notificationCounter - opacity: 0.0 - } - PropertyChanges { - target: notificationCounter - width: 0 - } - PropertyChanges { - target: notificationColumn - interactive: false - } - PropertyChanges { - target: expandedView - opacity: 0.0 - ScrollBar.vertical.policy: ScrollBar.AlwaysOff - } - StateChangeScript { - script: notificationColumn.gotoBeginning() - } - }, - State { - name: "oneNotification" - when: manager.countNotifications === 1 - - PropertyChanges { - target: topItem - Layout.preferredHeight: elisaTheme.delegateHeight * 2 - } - PropertyChanges { - target: notificationCounter - opacity: 0.0 - } - PropertyChanges { - target: notificationCounter - width: 0 - } - PropertyChanges { - target: notificationColumn - interactive: false - } - PropertyChanges { - target: expandedView - opacity: 1.0 - ScrollBar.vertical.policy: ScrollBar.AlwaysOff - } - StateChangeScript { - script: notificationColumn.gotoBeginning() - } - }, - State { - name: "multipleNotifications" - when: manager.countNotifications > 1 && !isViewExpanded - - PropertyChanges { - target: topItem - Layout.preferredHeight: elisaTheme.delegateHeight * 2 - } - PropertyChanges { - target: notificationCounter - opacity: 1.0 - } - PropertyChanges { - target: notificationCounter - width: elisaTheme.delegateToolButtonSize - } - PropertyChanges { - target: notificationColumn - interactive: false - } - PropertyChanges { - target: expandedView - opacity: 1.0 - ScrollBar.vertical.policy: ScrollBar.AsNeeded - } - StateChangeScript { - script: notificationColumn.gotoBeginning() - } - }, - State { - name: "expanded" - when: manager.countNotifications > 1 && isViewExpanded - - PropertyChanges { - target: topItem - Layout.preferredHeight: elisaTheme.delegateHeight * 4 - } - PropertyChanges { - target: notificationCounter - opacity: 1.0 - } - PropertyChanges { - target: notificationCounter - width: elisaTheme.delegateToolButtonSize - } - PropertyChanges { - target: notificationColumn - interactive: true - } - PropertyChanges { - target: expandedView - opacity: 1.0 - ScrollBar.vertical.policy: ScrollBar.AsNeeded - } - } - ] - - transitions: [ - Transition { - SequentialAnimation { - PropertyAction { - target: expandedView - property: "ScrollBar.vertical.policy" - value: ScrollBar.AlwaysOff - } - ParallelAnimation { - NumberAnimation { - target: topItem - - duration: 300 - - property: "Layout.preferredHeight" - } - NumberAnimation { - target: notificationCounter - - duration: 300 - - property: "opacity" - } - NumberAnimation { - target: notificationCounter - - duration: 300 - - property: "width" - } - NumberAnimation { - target: expandedView - - duration: 300 - - property: "opacity" - } - } - } - } - ] -} diff --git a/src/qml/TopNotificationItem.qml b/src/qml/TopNotificationItem.qml deleted file mode 100644 --- a/src/qml/TopNotificationItem.qml +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2017 Matthieu Gallien - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -import QtQuick 2.7 -import QtQuick.Layouts 1.2 -import QtQuick.Controls 2.3 -import org.kde.elisa 1.0 - -FocusScope { - id: topItem - - signal close() - signal mainButtonClicked() - signal secondaryButtonClicked() - signal entered() - - property alias itemMessage: notificationText.text - property alias itemMainButtonText: mainButton.text - property alias itemMainButtonIconName: mainButton.icon.name - property alias itemSecondaryButtonText: secondaryButton.text - property alias itemSecondaryButtonIconName: secondaryButton.icon.name - property var parentList - - MouseArea { - anchors.fill: parent - - hoverEnabled: true - acceptedButtons: Qt.NoButton - - onEntered: topItem.entered() - } - - RowLayout { - id: content - anchors.fill: parent - - Label { - id: notificationText - font.pointSize: Math.round(elisaTheme.defaultFontPoinPoint * 1.5) - - Layout.leftMargin: elisaTheme.layoutHorizontalMargin - Layout.alignment: Qt.AlignHCenter - - visible: topItem.height > height - opacity: (topItem.height - height) / height - } - - Button { - id: mainButton - - Layout.leftMargin: elisaTheme.layoutHorizontalMargin - Layout.alignment: Qt.AlignHCenter - Layout.maximumHeight: elisaTheme.delegateHeight - - visible: text !== "" && topItem.height > height - opacity: (topItem.height - height) / height - - onClicked: { - mainButton.enabled = false - enableAgainMainButtonTimer.start() - mainButtonClicked() - } - Accessible.onPressAction: onClicked - - Timer { - id: enableAgainMainButtonTimer - interval: 500 - onTriggered: mainButton.enabled = true - } - } - - Button { - id: secondaryButton - - Layout.leftMargin: elisaTheme.layoutHorizontalMargin - Layout.alignment: Qt.AlignHCenter - Layout.maximumHeight: elisaTheme.delegateHeight - - visible: text !== "" && topItem.height > height - opacity: (topItem.height - height) / height - - onClicked: { - secondaryButton.enabled = false - enableAgainSecondaryButtonTimer.start() - secondaryButtonClicked() - } - Accessible.onPressAction: onClicked - - Timer { - id: enableAgainSecondaryButtonTimer - interval: 500 - onTriggered: secondaryButton.enabled = true - } - } - - Item { - Layout.fillWidth: true - } - } - - FlatButtonWithToolTip { - anchors.top: parent.top - anchors.right: parent.right - icon.name: 'dialog-close' - - visible: topItem.height > height - opacity: (topItem.height - height) / height - - onClicked: close() - Accessible.onPressAction: onClicked - } -} diff --git a/src/resources.qrc b/src/resources.qrc --- a/src/resources.qrc +++ b/src/resources.qrc @@ -14,9 +14,7 @@ qml/Theme.qml qml/PlatformIntegration.qml qml/LabelWithToolTip.qml - qml/TopNotification.qml qml/TrackImportNotification.qml - qml/TopNotificationItem.qml qml/MediaTrackMetadataView.qml qml/GridBrowserView.qml qml/GridBrowserDelegate.qml diff --git a/src/topnotificationmanager.h b/src/topnotificationmanager.h deleted file mode 100644 --- a/src/topnotificationmanager.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2017 Matthieu Gallien - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef TOPNOTIFICATIONMANAGER_H -#define TOPNOTIFICATIONMANAGER_H - -#include "elisaLib_export.h" - -#include "notificationitem.h" - -#include -#include - -#include - -class TopNotificationManagerPrivate; - -class ELISALIB_EXPORT TopNotificationManager : public QAbstractListModel -{ - - Q_OBJECT - - Q_PROPERTY(int countNotifications - READ countNotifications - NOTIFY countNotificationsChanged) - - Q_PROPERTY(QString notificationMessage - READ notificationMessage - NOTIFY notificationMessageChanged) - - Q_PROPERTY(QString notificationMainButtonText - READ notificationMainButtonText - NOTIFY notificationMainButtonTextChanged) - - Q_PROPERTY(QString notificationMainButtonIconName - READ notificationMainButtonIconName - NOTIFY notificationMainButtonIconNameChanged) - - Q_PROPERTY(QString notificationSecondaryButtonText - READ notificationSecondaryButtonText - NOTIFY notificationSecondaryButtonTextChanged) - - Q_PROPERTY(QString notificationSecondaryButtonIconName - READ notificationSecondaryButtonIconName - NOTIFY notificationSecondaryButtonIconNameChanged) - -public: - - enum ColumnsRoles { - MessageRole = Qt::UserRole + 1, - MainButtonTextRole, - MainButtonIconNameRole, - SecondaryButtonTextRole, - SecondaryButtonIconNameRole, - }; - - Q_ENUM(ColumnsRoles) - - explicit TopNotificationManager(QObject *parent = nullptr); - - ~TopNotificationManager(); - - int countNotifications() const; - - QModelIndex parent(const QModelIndex &index) const override; - - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - - QHash roleNames() const override; - - QString notificationMessage() const; - - QString notificationMainButtonText() const; - - QString notificationMainButtonIconName() const; - - QString notificationSecondaryButtonText() const; - - QString notificationSecondaryButtonIconName() const; - -Q_SIGNALS: - - void countNotificationsChanged(); - - void notificationMessageChanged(); - - void notificationMainButtonTextChanged(); - - void notificationMainButtonIconNameChanged(); - - void notificationSecondaryButtonTextChanged(); - - void notificationSecondaryButtonIconNameChanged(); - -public Q_SLOTS: - - void addNotification(NotificationItem notification); - - void closeNotification(int index); - - void closeNotificationById(const QString ¬ificationId); - - void triggerMainButton(int index) const; - - void triggerSecondaryButton(int index) const; - -private: - - std::unique_ptr d; - -}; - - - -#endif // TOPNOTIFICATIONMANAGER_H diff --git a/src/topnotificationmanager.cpp b/src/topnotificationmanager.cpp deleted file mode 100644 --- a/src/topnotificationmanager.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2017 Matthieu Gallien - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include "topnotificationmanager.h" -#include "notificationitem.h" - -class TopNotificationManagerPrivate -{ -public: - - QList mNotifications; - -}; - -TopNotificationManager::TopNotificationManager(QObject *parent) : QAbstractListModel(parent), d(std::make_unique()) -{ -} - -TopNotificationManager::~TopNotificationManager() -=default; - -int TopNotificationManager::countNotifications() const -{ - return d->mNotifications.count(); -} - -QModelIndex TopNotificationManager::parent(const QModelIndex &index) const -{ - Q_UNUSED(index); - - return {}; -} - -void TopNotificationManager::addNotification(NotificationItem notification) -{ - beginInsertRows({}, d->mNotifications.count(), d->mNotifications.count()); - d->mNotifications.push_back(notification); - endInsertRows(); - - Q_EMIT countNotificationsChanged(); - Q_EMIT notificationMessageChanged(); - Q_EMIT notificationMainButtonTextChanged(); - Q_EMIT notificationMainButtonIconNameChanged(); - Q_EMIT notificationSecondaryButtonTextChanged(); - Q_EMIT notificationSecondaryButtonIconNameChanged(); -} - -void TopNotificationManager::closeNotification(int index) -{ - if (index < 0 || index >= d->mNotifications.count()) { - return; - } - - beginRemoveRows({}, index, index); - d->mNotifications.removeAt(index); - endRemoveRows(); - - Q_EMIT countNotificationsChanged(); - Q_EMIT notificationMessageChanged(); - Q_EMIT notificationMainButtonTextChanged(); - Q_EMIT notificationMainButtonIconNameChanged(); - Q_EMIT notificationSecondaryButtonTextChanged(); - Q_EMIT notificationSecondaryButtonIconNameChanged(); -} - -void TopNotificationManager::closeNotificationById(const QString ¬ificationId) -{ - for (int i = 0; i < d->mNotifications.size(); ) { - if (d->mNotifications.at(i).notificationId() == notificationId) { - closeNotification(i); - } else { - ++i; - } - } -} - -void TopNotificationManager::triggerMainButton(int index) const -{ - if (index < 0 || index >= d->mNotifications.count()) { - return; - } - - d->mNotifications.at(index).triggerMainButton(); -} - -void TopNotificationManager::triggerSecondaryButton(int index) const -{ - if (index < 0 || index >= d->mNotifications.count()) { - return; - } - - d->mNotifications.at(index).triggerSecondaryButton(); -} - -int TopNotificationManager::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) { - return 0; - } - - return d->mNotifications.count(); -} - -QVariant TopNotificationManager::data(const QModelIndex &index, int role) const -{ - auto result = QVariant(); - - if (!index.isValid()) { - return result; - } - - if (index.column() != 0) { - return result; - } - - if (index.row() < 0 || index.row() >= d->mNotifications.count()) { - return result; - } - - if (role < ColumnsRoles::MessageRole || role > ColumnsRoles::SecondaryButtonIconNameRole) { - return result; - } - - auto realRole = static_cast(role); - - switch(realRole) - { - case ColumnsRoles::MessageRole: - result = d->mNotifications.at(index.row()).message(); - break; - case ColumnsRoles::MainButtonTextRole: - result = d->mNotifications.at(index.row()).mainButtonText(); - break; - case ColumnsRoles::MainButtonIconNameRole: - result = d->mNotifications.at(index.row()).mainButtonIconName(); - break; - case ColumnsRoles::SecondaryButtonTextRole: - result = d->mNotifications.at(index.row()).secondaryButtonText(); - break; - case ColumnsRoles::SecondaryButtonIconNameRole: - result = d->mNotifications.at(index.row()).secondaryButtonIconName(); - break; - } - - return result; -} - -QHash TopNotificationManager::roleNames() const -{ - QHash roles; - - roles[static_cast(ColumnsRoles::MessageRole)] = "message"; - roles[static_cast(ColumnsRoles::MainButtonTextRole)] = "mainButtonText"; - roles[static_cast(ColumnsRoles::MainButtonIconNameRole)] = "mainButtonIconName"; - roles[static_cast(ColumnsRoles::SecondaryButtonTextRole)] = "secondaryButtonText"; - roles[static_cast(ColumnsRoles::SecondaryButtonIconNameRole)] = "secondaryButtonIconName"; - - return roles; -} - -QString TopNotificationManager::notificationMessage() const -{ - return data(index(0, 0, {}), TopNotificationManager::MessageRole).toString(); -} - -QString TopNotificationManager::notificationMainButtonText() const -{ - return data(index(0, 0, {}), TopNotificationManager::MainButtonTextRole).toString(); -} - -QString TopNotificationManager::notificationMainButtonIconName() const -{ - return data(index(0, 0, {}), TopNotificationManager::MainButtonIconNameRole).toString(); -} - -QString TopNotificationManager::notificationSecondaryButtonText() const -{ - return data(index(0, 0, {}), TopNotificationManager::SecondaryButtonTextRole).toString(); -} - -QString TopNotificationManager::notificationSecondaryButtonIconName() const -{ - return data(index(0, 0, {}), TopNotificationManager::SecondaryButtonIconNameRole).toString(); -} - - -//#include "moc_topnotificationmanager.cpp"