This commit is contained in:
2026-02-07 08:28:56 +03:00
parent eff857a55e
commit 451ddd9ae0
30 changed files with 3993 additions and 1233 deletions
+101
View File
@@ -0,0 +1,101 @@
#include "MediaFileManager.h"
#include <QDebug>
MediaFileManager::MediaFileManager()
{
// Конструктор может быть использован для инициализации
}
bool MediaFileManager::addFile(const QString& name, const QString& filePath)
{
// Проверка на пустые значения
if (name.isEmpty() || filePath.isEmpty()) {
qWarning() << "Имя файла или путь не могут быть пустыми";
return false;
}
// Проверка на уникальность имени
if (contains(name)) {
qWarning() << "Файл с именем" << name << "уже существует";
return false;
}
// Добавление нового файла
mediaFiles.append(MediaFile(name, filePath));
qDebug() << "Файл" << name << "добавлен с путем:" << filePath;
return true;
}
bool MediaFileManager::removeFile(const QString& name)
{
int index = findFileIndex(name);
if (index == -1) {
qWarning() << "Файл с именем" << name << "не найден";
return false;
}
mediaFiles.remove(index);
qDebug() << "Файл" << name << "удален";
return true;
}
bool MediaFileManager::updateFile(const QString& oldName, const QString& newName, const QString& newFilePath)
{
int index = findFileIndex(oldName);
if (index == -1) {
qWarning() << "Файл с именем" << oldName << "не найден";
return false;
}
// Проверяем, не используется ли новое имя другим файлом
if (oldName != newName && contains(newName)) {
qWarning() << "Файл с именем" << newName << "уже существует";
return false;
}
// Обновляем информацию о файле
mediaFiles[index].name = newName;
mediaFiles[index].filePath = newFilePath;
qDebug() << "Файл обновлен:" << oldName << "->" << newName << "путь:" << newFilePath;
return true;
}
QString MediaFileManager::getFilePathByName(const QString& name) const
{
int index = findFileIndex(name);
if (index == -1) {
qWarning() << "Файл с именем" << name << "не найден";
return QString();
}
return mediaFiles[index].filePath;
}
int MediaFileManager::getFileCount() const
{
return mediaFiles.size();
}
QVector<MediaFile> MediaFileManager::getAllFiles() const
{
return mediaFiles;
}
bool MediaFileManager::contains(const QString& name) const
{
return findFileIndex(name) != -1;
}
int MediaFileManager::findFileIndex(const QString& name) const
{
for (int i = 0; i < mediaFiles.size(); ++i) {
if (mediaFiles[i].name == name) {
return i;
}
}
return -1;
}