Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
*.so.*
*.dll
*.dylib
Build
checks.json
.vscode
build

# Qt-es
object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
/.qmake.cache
/.qmake.stash
src/*.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
Expand Down
43 changes: 0 additions & 43 deletions CMakeLists.txt

This file was deleted.

70 changes: 70 additions & 0 deletions src/Media/Album.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,74 @@ const std::vector<std::string> &Album::getBandMembers() const {
return band_members_;
}
const std::vector<std::string> &Album::getSongs() const { return songs_; }
bool Album::operator==(const Media &other) const {
const Album *other_album = dynamic_cast<const Album *>(&other);
if (other_album) {
return Media::operator==(*other_album) && band_ == other_album->band_ &&
band_members_ == other_album->band_members_ &&
songs_ == other_album->songs_;
}
return false;
}

std::vector<std::shared_ptr<Media>> Album::filter(const std::vector<std::shared_ptr<Album>>& input) const {
std::vector<std::shared_ptr<Media>> result;

// Riutilizzo filtro base di Media
std::vector<std::shared_ptr<Media>> baseInput(input.begin(), input.end());
std::vector<std::shared_ptr<Media>> filteredBase = Media::filter(baseInput);

// Filtro specifico per Album
for (const auto& mediaPtr : filteredBase) {
auto albumPtr = std::dynamic_pointer_cast<Album>(mediaPtr);
if (!albumPtr) continue;

bool match = true;

// Band
if (!band_.empty() && !stringContainsIgnoreCase(albumPtr->getBand(), band_))
match = false;

// Band members (ogni membro richiesto deve matchare almeno uno esistente)
if (!band_members_.empty()) {
for (const auto& memberFilter : band_members_) {
bool found = false;
for (const auto& m : albumPtr->getBandMembers()) {
if (stringContainsIgnoreCase(m, memberFilter)) {
found = true;
break;
}
}
if (!found) {
match = false;
break;
}
}
}

// Songs (ogni canzone richiesta deve matchare almeno una esistente)
if (!songs_.empty()) {
for (const auto& songFilter : songs_) {
bool found = false;
for (const auto& s : albumPtr->getSongs()) {
if (stringContainsIgnoreCase(s, songFilter)) {
found = true;
break;
}
}
if (!found) {
match = false;
break;
}
}
}

if (match)
result.push_back(albumPtr);
}

return result;
}


} // namespace media
8 changes: 6 additions & 2 deletions src/Media/Album.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ class Album : public Media {
Album(const std::string &title, int release, const std::string &language,
bool favourite, const std::vector<std::string> &genres,
const std::string &img_path, const std::string &notes,
const std::string &band, const std::vector<std::string> &band_members,
const std::vector<std::string> &songs);
const std::string &band = "", const std::vector<std::string> &band_members = {},
const std::vector<std::string> &songs = {});
const std::string &getBand() const;
const std::vector<std::string> &getBandMembers() const;
const std::vector<std::string> &getSongs() const;
bool operator==(const Media &other) const override;

std::vector<std::shared_ptr<Media>> filter(const std::vector<std::shared_ptr<Album>>& input) const;

};
} // namespace media
#endif
38 changes: 36 additions & 2 deletions src/Media/AudioBook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ AudioBook::AudioBook(const std::string& title, int publicationYear, const std::s
narrator_(narrator), streamingService_(streamingService) {}


void AudioBook::accept(IConstMediaVisitor& v) const {
v.visit(*this);
bool AudioBook::operator==(const Media& other) const {
const AudioBook* otherAudioBook = dynamic_cast<const AudioBook*>(&other);
if (otherAudioBook) {
return Novel::operator==(*otherAudioBook) && narrator_ == otherAudioBook->narrator_ &&
streamingService_ == otherAudioBook->streamingService_;
}
return false;
}

std::string AudioBook::getNarrator() const {
Expand All @@ -32,4 +37,33 @@ void AudioBook::setStreamingService(const std::string& service) {
streamingService_ = service;
}

std::vector<std::shared_ptr<Media>> AudioBook::filter(const std::vector<std::shared_ptr<AudioBook>>& input) const {
std::vector<std::shared_ptr<Media>> result;

// Riutilizza filtro base di Novel (che include filtro di Media)
std::vector<std::shared_ptr<Novel>> novels(input.begin(), input.end());
std::vector<std::shared_ptr<Media>> filteredNovels = Novel::filter(novels);

// Filtro specifico AudioBook
for (const auto& novelPtr : filteredNovels) {
auto audiobookPtr = std::dynamic_pointer_cast<AudioBook>(novelPtr);
if (!audiobookPtr) continue;

bool match = true;

// File size
if (narrator_ != "" && audiobookPtr->getNarrator()!= narrator_)
match = false;

// DRM
if (streamingService_ != "" && audiobookPtr->getStreamingService() != streamingService_)
match = false;

if (match)
result.push_back(audiobookPtr);
}

return result;
}

}
13 changes: 8 additions & 5 deletions src/Media/AudioBook.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef AudioBook_H
#define AudioBook_H
#ifndef MEDIA_AUDIOBOOK_H
#define MEDIA_AUDIOBOOK_H

#include "Novel.h"

Expand All @@ -11,21 +11,24 @@ class AudioBook : public Novel {
std::string streamingService_;

public:
//durata è in minuti e usa il campo dati pagine di Novel
AudioBook(const std::string& title, int publicationYear, const std::string& language,
bool favorite, const std::vector<std::string>& genres, const std::string& imagePath, const std::string& notes,
const std::string& author, const std::string& publisher,
unsigned int duration, const std::string& series, const std::string& isbn,
const std::string& narrator, const std::string& streamingService);
const std::string& narrator = "", const std::string& streamingService = "");

void accept(IConstMediaVisitor& v) const override;
bool operator==(const Media& other) const override;

std::string getNarrator() const;
std::string getStreamingService() const;

void setNarrator(const std::string& narrator);
void setStreamingService(const std::string& service);

std::vector<std::shared_ptr<Media>> filter(const std::vector<std::shared_ptr<AudioBook>>& input) const;
};

}

#endif // AudioBook_H
#endif // MEDIA_AUDIOBOOK_H
41 changes: 38 additions & 3 deletions src/Media/Ebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ Ebook::Ebook(const std::string& title, int publicationYear, const std::string& l
author, publisher, pages, series, isbn),
fileSizeBytes_(fileSizeBytes), drm_(drm) {}

void Ebook::accept(IConstMediaVisitor& v) const {
v.visit(*this);
}
bool Ebook::operator==(const Media& other) const {
const Ebook* otherEbook = dynamic_cast<const Ebook*>(&other);
if (otherEbook) {
return Novel::operator==(*otherEbook) && fileSizeBytes_ == otherEbook->fileSizeBytes_ &&
drm_ == otherEbook->drm_;
}
return false;
}

unsigned int Ebook::getFileSizeBytes() const {
return fileSizeBytes_;
Expand All @@ -31,4 +36,34 @@ void Ebook::setDrm(bool drm) {
drm_ = drm;
}

std::vector<std::shared_ptr<Media>> Ebook::filter(const std::vector<std::shared_ptr<Ebook>>& input) const {
std::vector<std::shared_ptr<Media>> result;

// Riutilizza filtro base di Novel (che include filtro di Media)
std::vector<std::shared_ptr<Novel>> novels(input.begin(), input.end());
std::vector<std::shared_ptr<Media>> filteredNovels = Novel::filter(novels);

// Filtro specifico Ebook
for (const auto& novelPtr : filteredNovels) {
auto ebookPtr = std::dynamic_pointer_cast<Ebook>(novelPtr);
if (!ebookPtr) continue;

bool match = true;

// File size
if (fileSizeBytes_ > 0 && ebookPtr->getFileSizeBytes() != fileSizeBytes_)
match = false;

// DRM
if (drm_ && ebookPtr->hasDrm() != drm_)
match = false;

if (match)
result.push_back(ebookPtr);
}

return result;
}


}
13 changes: 8 additions & 5 deletions src/Media/Ebook.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef EBOOK_H
#define EBOOK_H
#ifndef MEDIA_EBOOK_H
#define MEDIA_EBOOK_H

#include "Novel.h"

Expand All @@ -15,17 +15,20 @@ class Ebook : public Novel {
bool favorite, const std::vector<std::string>& genres, const std::string& imagePath, const std::string& notes,
const std::string& author, const std::string& publisher,
unsigned int pages, const std::string& series, const std::string& isbn,
unsigned int fileSizeBytes, bool drm);
unsigned int fileSizeBytes = 0, bool drm = false);

void accept(IConstMediaVisitor& v) const override;
bool operator==(const Media& other) const override;

unsigned int getFileSizeBytes() const;
bool hasDrm() const;

void setFileSizeBytes(unsigned int size);
void setDrm(bool drm);

std::vector<std::shared_ptr<Media>> filter(const std::vector<std::shared_ptr<Ebook>>& input) const;

};

}

#endif // EBOOK_H
#endif // MEDIA_EBOOK_H
7 changes: 2 additions & 5 deletions src/Media/IMedia.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#ifndef IMedia_H
#define IMedia_H
#ifndef MEDIA_IMedia_H
#define MEDIA_IMedia_H

#include "IConstMediaVisitor.h"


namespace media {


class IMedia {
virtual void accept(IConstMediaVisitor &) const = 0;
virtual bool open() = 0;
};

}


#endif
Loading
Loading