diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 523ad743..6d84337e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,416 +1,415 @@ include_directories(${elisa_BINARY_DIR}) set(elisaLib_SOURCES mediaplaylist.cpp musicalbum.cpp musicaudiotrack.cpp musicartist.cpp musicaudiogenre.cpp progressindicator.cpp databaseinterface.cpp musiclistenersmanager.cpp managemediaplayercontrol.cpp manageheaderbar.cpp manageaudioplayer.cpp trackslistener.cpp elisaapplication.cpp notificationitem.cpp topnotificationmanager.cpp elisautils.cpp datatype.cpp trackdatahelper.cpp - modeldatacache.cpp abstractfile/abstractfilelistener.cpp abstractfile/abstractfilelisting.cpp filescanner.cpp file/filelistener.cpp file/localfilelisting.cpp models/albummodel.cpp models/allalbumsmodel.cpp models/allartistsmodel.cpp models/alltracksmodel.cpp models/allgenresmodel.cpp models/abstractmediaproxymodel.cpp models/allalbumsproxymodel.cpp models/allartistsproxymodel.cpp models/alltracksproxymodel.cpp models/singleartistproxymodel.cpp models/singlealbumproxymodel.cpp models/genericdatamodel.cpp ) if (LIBVLC_FOUND) set(elisaLib_SOURCES ${elisaLib_SOURCES} audiowrapper_libvlc.cpp ) else() set(elisaLib_SOURCES ${elisaLib_SOURCES} audiowrapper_qtmultimedia.cpp ) endif() if (KF5KIO_FOUND) set(elisaLib_SOURCES ${elisaLib_SOURCES} models/filebrowsermodel.cpp models/filebrowserproxymodel.cpp ) endif() if (KF5Baloo_FOUND) if (Qt5DBus_FOUND) set(elisaLib_SOURCES ${elisaLib_SOURCES} baloo/localbaloofilelisting.cpp baloo/baloolistener.cpp ) qt5_add_dbus_interface(elisaLib_SOURCES ${BALOO_DBUS_INTERFACES_DIR}/org.kde.baloo.main.xml baloo/main) qt5_add_dbus_interface(elisaLib_SOURCES ${BALOO_DBUS_INTERFACES_DIR}/org.kde.baloo.fileindexer.xml baloo/fileindexer) qt5_add_dbus_interface(elisaLib_SOURCES ${BALOO_DBUS_INTERFACES_DIR}/org.kde.baloo.scheduler.xml baloo/scheduler) qt5_add_dbus_adaptor(elisaLib_SOURCES ${BALOO_DBUS_INTERFACES_DIR}/org.kde.BalooWatcherApplication.xml baloo/localbaloofilelisting.h LocalBalooFileListing) endif() endif() if (Qt5DBus_FOUND) set(elisaLib_SOURCES ${elisaLib_SOURCES} mpris2/mpris2.cpp mpris2/mediaplayer2.cpp mpris2/mediaplayer2player.cpp ) endif() if (UPNPQT_FOUND) set(elisaLib_SOURCES ${elisaLib_SOURCES} upnp/upnpcontrolcontentdirectory.cpp upnp/upnpcontentdirectorymodel.cpp upnp/upnpcontrolconnectionmanager.cpp upnp/upnpcontrolmediaserver.cpp upnp/didlparser.cpp upnp/upnplistener.cpp upnp/upnpdiscoverallmusic.cpp ) endif() if (KF5Baloo_FOUND) if (Qt5DBus_FOUND) qt5_add_dbus_interface(elisaLib_SOURCES ${BALOO_DBUS_INTERFACES_DIR}/org.kde.baloo.fileindexer.xml baloo/fileindexer) qt5_add_dbus_interface(elisaLib_SOURCES ${BALOO_DBUS_INTERFACES_DIR}/org.kde.baloo.scheduler.xml baloo/scheduler) set(elisaLib_SOURCES ${elisaLib_SOURCES} ../src/baloo/baloolistener.cpp ../src/baloo/localbaloofilelisting.cpp ) endif() endif() kconfig_add_kcfg_files(elisaLib_SOURCES ../src/elisa_settings.kcfgc ) set(elisaLib_SOURCES ${elisaLib_SOURCES} ../src/elisa_core.kcfg ) add_library(elisaLib ${elisaLib_SOURCES}) target_link_libraries(elisaLib LINK_PUBLIC Qt5::Multimedia LINK_PRIVATE Qt5::Core Qt5::Sql Qt5::Widgets Qt5::Concurrent Qt5::Qml KF5::I18n KF5::CoreAddons KF5::ConfigCore KF5::ConfigGui) if (KF5FileMetaData_FOUND) target_link_libraries(elisaLib LINK_PRIVATE KF5::FileMetaData ) endif() if (KF5KIO_FOUND) target_link_libraries(elisaLib LINK_PUBLIC KF5::KIOCore KF5::KIOFileWidgets KF5::KIOWidgets ) endif() if (KF5XmlGui_FOUND) target_link_libraries(elisaLib LINK_PUBLIC KF5::XmlGui ) endif() if (KF5ConfigWidgets_FOUND) target_link_libraries(elisaLib LINK_PUBLIC KF5::ConfigWidgets ) endif() if (KF5KCMUtils_FOUND) target_link_libraries(elisaLib LINK_PUBLIC KF5::KCMUtils ) endif() if (KF5Baloo_FOUND) if (Qt5DBus_FOUND) target_link_libraries(elisaLib LINK_PUBLIC KF5::Baloo ) endif() endif() if (Qt5DBus_FOUND) target_link_libraries(elisaLib LINK_PUBLIC Qt5::DBus ) if (KF5DBusAddons_FOUND) target_link_libraries(elisaLib LINK_PUBLIC KF5::DBusAddons ) endif() endif() if (LIBVLC_FOUND) target_include_directories(elisaLib PRIVATE ${LIBVLC_INCLUDE_DIR} ) target_link_libraries(elisaLib LINK_PRIVATE ${LIBVLC_LIBRARY} ) endif() generate_export_header(elisaLib BASE_NAME ElisaLib EXPORT_FILE_NAME elisaLib_export.h) set_target_properties(elisaLib PROPERTIES VERSION 0.1 SOVERSION 0 EXPORT_NAME ElisaLib ) if (NOT APPLE AND NOT WIN32) install(TARGETS elisaLib LIBRARY DESTINATION ${KDE_INSTALL_FULL_LIBDIR}/elisa RUNTIME DESTINATION ${KDE_INSTALL_FULL_LIBDIR}/elisa BUNDLE DESTINATION ${KDE_INSTALL_FULL_LIBDIR}/elisa ) else() install(TARGETS elisaLib ${INSTALL_TARGETS_DEFAULT_ARGS}) endif() set(elisaqmlplugin_SOURCES elisaqmlplugin.cpp datatype.cpp elisautils.cpp embeddedcoverageimageprovider.cpp ) add_library(elisaqmlplugin SHARED ${elisaqmlplugin_SOURCES}) target_link_libraries(elisaqmlplugin LINK_PRIVATE Qt5::Quick Qt5::Widgets KF5::ConfigCore KF5::ConfigGui elisaLib ) if (KF5FileMetaData_FOUND) target_link_libraries(elisaqmlplugin LINK_PRIVATE KF5::FileMetaData ) endif() set_target_properties(elisaqmlplugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/org/kde/elisa ) if (NOT APPLE AND NOT WIN32) set_target_properties(elisaqmlplugin PROPERTIES INSTALL_RPATH "${KDE_INSTALL_FULL_LIBDIR}/elisa;${CMAKE_INSTALL_RPATH}" ) endif() install(TARGETS elisaqmlplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/elisa/) install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/elisa) add_custom_target(copy) add_custom_target(copy2) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/org/kde/elisa) add_custom_command(TARGET copy PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qmldir ${CMAKE_BINARY_DIR}/bin/org/kde/elisa/) add_custom_command(TARGET copy2 PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugins.qmltypes ${CMAKE_BINARY_DIR}/bin/org/kde/elisa/) add_dependencies(elisaqmlplugin copy copy2) if (Qt5Quick_FOUND AND Qt5Widgets_FOUND) set(elisa_SOURCES main.cpp windows/WindowsTheme.qml windows/PlatformIntegration.qml android/ElisaMainWindow.qml android/AndroidTheme.qml android/PlatformIntegration.qml qml/ElisaMainWindow.qml qml/ApplicationMenu.qml qml/BaseTheme.qml qml/Theme.qml qml/PlatformIntegration.qml qml/LabelWithToolTip.qml qml/RatingStar.qml qml/PlayListEntry.qml qml/MediaBrowser.qml qml/DraggableItem.qml qml/PassiveNotification.qml qml/TopNotification.qml qml/TopNotificationItem.qml qml/TrackImportNotification.qml qml/HeaderBar.qml qml/NavigationActionBar.qml qml/MediaPlayerControl.qml qml/ContextView.qml qml/ContentView.qml qml/ViewSelector.qml qml/ViewManager.qml qml/MediaPlayListView.qml qml/MediaTrackDelegate.qml qml/MediaAlbumTrackDelegate.qml qml/MediaTrackMetadataView.qml qml/GridBrowserView.qml qml/GridBrowserDelegate.qml qml/ListBrowserView.qml qml/FileBrowserDelegate.qml qml/FileBrowserView.qml qml/ScrollHelper.qml qml/FlatButtonWithToolTip.qml ) qt5_add_resources(elisa_SOURCES resources.qrc) set_property(SOURCE qrc_resources.cpp PROPERTY SKIP_AUTOMOC ON) set(elisa_ICONS_PNG ../icons/128-apps-elisa.png ../icons/64-apps-elisa.png ../icons/48-apps-elisa.png ../icons/32-apps-elisa.png ../icons/22-apps-elisa.png ../icons/16-apps-elisa.png ) # add icons to application sources, to have them bundled ecm_add_app_icon(elisa_SOURCES ICONS ${elisa_ICONS_PNG}) add_executable(elisa ${elisa_SOURCES}) target_include_directories(elisa PRIVATE ${KDSoap_INCLUDE_DIRS}) target_link_libraries(elisa LINK_PRIVATE elisaLib Qt5::Widgets Qt5::QuickControls2 Qt5::Svg KF5::I18n KF5::CoreAddons KF5::ConfigCore KF5::ConfigGui ) if (ANDROID) target_link_libraries(elisa LINK_PRIVATE Qt5::AndroidExtras ) endif() if (KF5Crash_FOUND) target_link_libraries(elisa LINK_PRIVATE KF5::Crash ) endif() if (KF5Declarative_FOUND) target_link_libraries(elisa LINK_PRIVATE KF5::Declarative ) endif() if (NOT APPLE AND NOT WIN32) set_target_properties(elisa PROPERTIES INSTALL_RPATH "${KDE_INSTALL_FULL_LIBDIR}/elisa;${CMAKE_INSTALL_RPATH}" ) endif() install(TARGETS elisa ${INSTALL_TARGETS_DEFAULT_ARGS}) endif() if (KF5ConfigWidgets_FOUND AND KF5Declarative_FOUND) add_subdirectory(localFileConfiguration) endif() set(elisaImport_SOURCES elisaimport.cpp elisaimportapplication.cpp ) kconfig_add_kcfg_files(elisaImport_SOURCES ../src/elisa_settings.kcfgc ) set(elisaImport_SOURCES ${elisaImport_SOURCES} ../src/elisa_core.kcfg ) add_executable(elisaImport ${elisaImport_SOURCES}) target_link_libraries(elisaImport LINK_PRIVATE KF5::ConfigCore KF5::ConfigGui elisaLib ) if (KF5FileMetaData_FOUND) target_link_libraries(elisaImport LINK_PRIVATE KF5::FileMetaData ) endif() set(QML_IMPORT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "qml import path" FORCE) diff --git a/src/modeldatacache.cpp b/src/modeldatacache.cpp deleted file mode 100644 index 98c6e814..00000000 --- a/src/modeldatacache.cpp +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright 2018 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 "modeldatacache.h" - -#include "databaseinterface.h" - -#include -#include -#include -#include -#include - -#include - -class ModelDataCachePrivate -{ -public: - - QList> mPartialData; - - QHash> mFullData; - - QHash mRows; - - DatabaseInterface *mDatabase = nullptr; - - QAtomicInt mDataCount; - - QAtomicInt mDataChangedLowerBound; - - QAtomicInt mDataChangedUpperBound; - - DataUtils::DataType mDataType = DataUtils::DataType::UnknownType; - - QAtomicInt mHasFullData = false; - - bool mIsConnected = false; - -}; - -ModelDataCache::ModelDataCache(QObject *parent) - : QObject(parent), d(std::make_unique()) -{ - d->mFullData.reserve(CACHE_SIZE); -} - -ModelDataCache::ModelDataCache::~ModelDataCache() = default; - -DataUtils::DataType ModelDataCache::dataType() const -{ - return d->mDataType; -} - -int ModelDataCache::dataCount() const -{ - int result = d->mDataCount; - - return result; -} - -QVariant ModelDataCache::data(int row, ElisaUtils::ColumnsRoles role) const -{ - auto result = QVariant{}; - - bool databaseIdIsOk = false; - auto databaseId = d->mPartialData[row][DatabaseInterface::DatabaseId].toULongLong(&databaseIdIsOk); - if (!databaseIdIsOk || databaseId == 0) { - return result; - } - - d->mRows[databaseId] = row; - - switch (role) - { - case ElisaUtils::TitleRole: - result = d->mPartialData[row][DatabaseInterface::DisplayRole]; - break; - case ElisaUtils::SecondaryTextRole: - result = d->mPartialData[row][DatabaseInterface::SecondaryRole]; - break; - case ElisaUtils::DatabaseIdRole: - result = d->mPartialData[row][DatabaseInterface::DatabaseId]; - break; - case ElisaUtils::IsPartialDataRole: - result = !d->mHasFullData; - break; - default: - if (d->mHasFullData) { - result = d->mFullData[databaseId][role]; - } else { - const auto currentRow = d->mRows[databaseId]; - if (d->mDataChangedLowerBound > currentRow) { - d->mDataChangedLowerBound = currentRow; - } - if (d->mDataChangedUpperBound < currentRow) { - d->mDataChangedUpperBound = currentRow; - } - } - break; - }; - - return result; -} - -DatabaseInterface *ModelDataCache::database() const -{ - return d->mDatabase; -} - -void ModelDataCache::neededData() -{ - qDebug() << "ModelDataCache::neededData"; - - if (d->mHasFullData) { - return; - } - - switch (d->mDataType) - { - case DataUtils::DataType::AllAlbums: - { - auto allData = d->mDatabase->allAlbums(); - for (const auto &data : allData) { - auto &fullData = d->mFullData[data.databaseId()]; - const auto &albumArt = data.albumArtURI(); - - if (albumArt.isValid()) { - fullData[ElisaUtils::ImageUrlRole] = albumArt; - fullData[ElisaUtils::ShadowForImageRole] = true; - } else { - fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/media-optical-audio")); - fullData[ElisaUtils::ShadowForImageRole] = false; - } - - fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); - fullData[ElisaUtils::ArtistRole] = data.artist(); - fullData[ElisaUtils::AllArtistsRole] = data.allArtists(); - fullData[ElisaUtils::HighestTrackRating] = data.highestTrackRating(); - } - - d->mHasFullData = true; - Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); - - break; - } - case DataUtils::DataType::AllArtists: - { - auto allData = d->mDatabase->allArtists(); - for (const auto &data : allData) { - auto &fullData = d->mFullData[data.databaseId()]; - - fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); - fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/view-media-artist")); - fullData[ElisaUtils::ShadowForImageRole] = false; - fullData[ElisaUtils::GenreRole] = data.genres(); - } - - d->mHasFullData = true; - Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); - - break; - } - case DataUtils::DataType::AllComposers: - { - auto allData = d->mDatabase->allComposers(); - for (const auto &data : allData) { - auto &fullData = d->mFullData[data.databaseId()]; - - fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); - fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/view-media-artist")); - fullData[ElisaUtils::ShadowForImageRole] = false; - } - - d->mHasFullData = true; - Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); - - break; - } - case DataUtils::DataType::AllLyricists: - { - auto allData = d->mDatabase->allLyricists(); - for (const auto &data : allData) { - auto &fullData = d->mFullData[data.databaseId()]; - - fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); - fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/view-media-artist")); - fullData[ElisaUtils::ShadowForImageRole] = false; - } - - d->mHasFullData = true; - Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); - - break; - } - case DataUtils::DataType::AllGenres: - { - auto allData = d->mDatabase->allGenres(); - for (const auto &data : allData) { - auto &fullData = d->mFullData[data.databaseId()]; - - fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); - fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/view-media-genre")); - fullData[ElisaUtils::ShadowForImageRole] = false; - } - - d->mHasFullData = true; - Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); - - break; - } - case DataUtils::DataType::AllTracks: - { - auto allData = d->mDatabase->allTracks(); - for (const auto &data : allData) { - auto &fullData = d->mFullData[data.databaseId()]; - const auto &albumArt = data.albumCover(); - - if (albumArt.isValid()) { - fullData[ElisaUtils::ImageUrlRole] = albumArt; - fullData[ElisaUtils::ShadowForImageRole] = true; - } else { - fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/media-optical-audio")); - fullData[ElisaUtils::ShadowForImageRole] = false; - } - - fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); - fullData[ElisaUtils::ArtistRole] = data.artist(); - fullData[ElisaUtils::RatingRole] = data.rating(); - } - - d->mHasFullData = true; - Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); - - break; - } - case DataUtils::DataType::UnknownType: - break; - } -} - -void ModelDataCache::setDataType(DataUtils::DataType dataType) -{ - if (d->mDataType == dataType) { - return; - } - - d->mDataType = dataType; - Q_EMIT dataTypeChanged(d->mDataType); - - if (!d->mDatabase) { - return; - } - - connectDatabase(); - fetchPartialData(); -} - -void ModelDataCache::setDatabase(DatabaseInterface *database) -{ - if (d->mDatabase == database) { - return; - } - - d->mDatabase = database; - Q_EMIT databaseChanged(d->mDatabase); - - if (d->mDataType == DataUtils::DataType::UnknownType) { - return; - } - - connectDatabase(); - fetchPartialData(); -} - -void ModelDataCache::databaseContentChanged() -{ - fetchPartialData(); -} - -void ModelDataCache::fetchPartialData() -{ - if (!d->mDatabase) { - return; - } - - d->mPartialData = d->mDatabase->allData(d->mDataType); - - d->mDataCount = d->mPartialData.count(); - - d->mDataChangedLowerBound = d->mDataCount; - d->mDataChangedUpperBound = 0; - - d->mHasFullData = false; - - QMetaObject::invokeMethod(const_cast(this), "neededData", - Qt::QueuedConnection); - - Q_EMIT dataChanged(-1, -1); -} - -void ModelDataCache::connectDatabase() -{ - if (d->mDataType == DataUtils::DataType::UnknownType) { - return; - } - - if (!d->mDatabase) { - return; - } - - if (d->mIsConnected) { - disconnect(d->mDatabase, nullptr, this, nullptr); - d->mIsConnected = false; - } - - switch(d->mDataType) - { - case DataUtils::DataType::AllAlbums: - connect(d->mDatabase, &DatabaseInterface::albumsAdded, - this, &ModelDataCache::databaseContentChanged, - Qt::QueuedConnection); - break; - case DataUtils::DataType::AllArtists: - connect(d->mDatabase, &DatabaseInterface::artistsAdded, - this, &ModelDataCache::databaseContentChanged, - Qt::QueuedConnection); - break; - case DataUtils::DataType::AllTracks: - connect(d->mDatabase, &DatabaseInterface::tracksAdded, - this, &ModelDataCache::databaseContentChanged, - Qt::QueuedConnection); - break; - case DataUtils::DataType::AllGenres: - connect(d->mDatabase, &DatabaseInterface::genresAdded, - this, &ModelDataCache::databaseContentChanged, - Qt::QueuedConnection); - break; - case DataUtils::DataType::AllComposers: - connect(d->mDatabase, &DatabaseInterface::composersAdded, - this, &ModelDataCache::databaseContentChanged, - Qt::QueuedConnection); - break; - case DataUtils::DataType::AllLyricists: - connect(d->mDatabase, &DatabaseInterface::lyricistsAdded, - this, &ModelDataCache::databaseContentChanged, - Qt::QueuedConnection); - break; - case DataUtils::DataType::UnknownType: - break; - } - - d->mIsConnected = true; -} - - -#include "moc_modeldatacache.cpp" diff --git a/src/modeldatacache.h b/src/modeldatacache.h deleted file mode 100644 index 8e3030d4..00000000 --- a/src/modeldatacache.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2018 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 MODELDATACACHE_H -#define MODELDATACACHE_H - -#include "elisaLib_export.h" - -#include "datatype.h" -#include "elisautils.h" - -#include - -#include - -class ModelDataCachePrivate; -class DatabaseInterface; -class MusicAlbum; - -class ELISALIB_EXPORT ModelDataCache : public QObject -{ - - Q_OBJECT - - Q_PROPERTY(DataUtils::DataType dataType READ dataType WRITE setDataType NOTIFY dataTypeChanged) - - Q_PROPERTY(DatabaseInterface* database READ database WRITE setDatabase NOTIFY databaseChanged) - -public: - - static const int CACHE_SIZE = 3000; - - enum CallMode { - CannotBlock, - CanBlock, - }; - - explicit ModelDataCache(QObject *parent = nullptr); - - ~ModelDataCache(); - - DataUtils::DataType dataType() const; - - int dataCount() const; - - QVariant data(int row, ElisaUtils::ColumnsRoles role) const; - - DatabaseInterface* database() const; - -Q_SIGNALS: - - void dataTypeChanged(DataUtils::DataType dataType); - - void receiveData(int row); - - void databaseChanged(DatabaseInterface* database); - - void dataChanged(int lowerBound, int upperBound); - -public Q_SLOTS: - - void neededData(); - - void setDataType(DataUtils::DataType dataType); - - void setDatabase(DatabaseInterface* database); - -private Q_SLOTS: - - void databaseContentChanged(); - -private: - - void fetchPartialData(); - - void connectDatabase(); - - std::unique_ptr d; - -}; - -#endif // MODELDATACACHE_H diff --git a/src/models/genericdatamodel.cpp b/src/models/genericdatamodel.cpp index eebd24ac..531dc5cd 100644 --- a/src/models/genericdatamodel.cpp +++ b/src/models/genericdatamodel.cpp @@ -1,209 +1,178 @@ /* * Copyright 2018 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 "genericdatamodel.h" #include "databaseinterface.h" -#include "modeldatacache.h" #include #include #include class GenericDataModelPrivate { public: QHash mDataPositionCache; - ModelDataCache *mModelCache = nullptr; - DataUtils::DataType mDataType = DataUtils::DataType::UnknownType; bool mIsBusy = true; }; GenericDataModel::GenericDataModel(QObject *parent) : QAbstractListModel(parent), d(std::make_unique()) { } GenericDataModel::~GenericDataModel() = default; int GenericDataModel::rowCount(const QModelIndex &parent) const { auto rowCount = 0; if (parent.isValid()) { return rowCount; } - rowCount = d->mModelCache->dataCount(); - return rowCount; } QHash GenericDataModel::roleNames() const { auto roles = QAbstractItemModel::roleNames(); roles[static_cast(ElisaUtils::ColumnsRoles::SecondaryTextRole)] = "secondaryText"; roles[static_cast(ElisaUtils::ColumnsRoles::ImageUrlRole)] = "imageUrl"; roles[static_cast(ElisaUtils::ColumnsRoles::ShadowForImageRole)] = "shadowForImage"; roles[static_cast(ElisaUtils::ColumnsRoles::ChildModelRole)] = "childModel"; roles[static_cast(ElisaUtils::ColumnsRoles::IsPartialDataRole)] = "isPartial"; roles[static_cast(ElisaUtils::ColumnsRoles::ContainerDataRole)] = "containerData"; roles[static_cast(ElisaUtils::ColumnsRoles::DatabaseIdRole)] = "databaseId"; return roles; } QVariant GenericDataModel::data(const QModelIndex &index, int role) const { auto result = QVariant(); - const auto albumCount = d->mModelCache->dataCount(); + const auto albumCount = 0; if (!index.isValid()) { return result; } if (index.column() != 0) { return result; } if (index.row() < 0) { return result; } if (index.parent().isValid()) { return result; } if (index.row() < 0 || index.row() >= albumCount) { return result; } if (role != Qt::DisplayRole && (role < ElisaUtils::SecondaryTextRole || role > ElisaUtils::IsPartialDataRole)) { return result; } switch(role) { case Qt::DisplayRole: - result = d->mModelCache->data(index.row(), ElisaUtils::TitleRole); break; default: - result = d->mModelCache->data(index.row(), static_cast(role)); break; }; return result; } QModelIndex GenericDataModel::parent(const QModelIndex &child) const { Q_UNUSED(child) return {}; } int GenericDataModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent) return 1; } DataUtils::DataType GenericDataModel::dataType() const { return d->mDataType; } -ModelDataCache *GenericDataModel::modelCache() const -{ - return d->mModelCache; -} - bool GenericDataModel::isBusy() const { return d->mIsBusy; } void GenericDataModel::setDataType(DataUtils::DataType dataType) { if (d->mDataType == dataType) { return; } resetModelType(); d->mDataType = dataType; Q_EMIT dataTypeChanged(d->mDataType); } -void GenericDataModel::setModelCache(ModelDataCache *modelCache) -{ - if (d->mModelCache == modelCache) { - return; - } - - d->mModelCache = modelCache; - Q_EMIT modelCacheChanged(d->mModelCache); - - connect(this, &GenericDataModel::neededData, - d->mModelCache, &ModelDataCache::neededData); - connect(d->mModelCache, &ModelDataCache::receiveData, - this, &GenericDataModel::receiveData); - connect(this, &GenericDataModel::dataTypeChanged, - d->mModelCache, &ModelDataCache::setDataType); - connect(d->mModelCache, &ModelDataCache::dataChanged, - this, &GenericDataModel::modelDataChanged); -} - void GenericDataModel::modelDataChanged(int lowerBound, int upperBound) { if (lowerBound == -1 && upperBound == -1) { beginResetModel(); endResetModel(); d->mIsBusy = false; Q_EMIT isBusyChanged(d->mIsBusy); } Q_EMIT dataChanged(index(lowerBound), index(upperBound), {}); } void GenericDataModel::resetModelType() { beginResetModel(); d->mDataPositionCache.clear(); d->mIsBusy = true; Q_EMIT isBusyChanged(d->mIsBusy); endResetModel(); } void GenericDataModel::receiveData(int row) { Q_EMIT dataChanged(index(row), index(row), {}); } #include "moc_genericdatamodel.cpp" diff --git a/src/models/genericdatamodel.h b/src/models/genericdatamodel.h index 862c3989..72e932f1 100644 --- a/src/models/genericdatamodel.h +++ b/src/models/genericdatamodel.h @@ -1,95 +1,86 @@ /* * Copyright 2018 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 GENERICDATAMODEL_H #define GENERICDATAMODEL_H #include "elisaLib_export.h" #include "datatype.h" #include #include class GenericDataModelPrivate; -class ModelDataCache; class ELISALIB_EXPORT GenericDataModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(DataUtils::DataType dataType READ dataType WRITE setDataType NOTIFY dataTypeChanged) - Q_PROPERTY(ModelDataCache* modelCache READ modelCache WRITE setModelCache NOTIFY modelCacheChanged) - Q_PROPERTY(bool isBusy READ isBusy NOTIFY isBusyChanged) public: explicit GenericDataModel(QObject *parent = nullptr); ~GenericDataModel() override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QHash roleNames() const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QModelIndex parent(const QModelIndex &child) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; DataUtils::DataType dataType() const; - ModelDataCache *modelCache() const; - bool isBusy() const; Q_SIGNALS: void neededData(int row); void dataTypeChanged(DataUtils::DataType dataType); - void modelCacheChanged(ModelDataCache* modelCache); - void isBusyChanged(bool isBusy); public Q_SLOTS: void receiveData(int row); void setDataType(DataUtils::DataType dataType); - void setModelCache(ModelDataCache* modelCache); - void modelDataChanged(int lowerBound, int upperBound); private: void resetModelType(); std::unique_ptr d; }; #endif // GENERICDATAMODEL_H