From eb0dc47696de8b82e8974fba159531010d65e83d Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Tue, 28 Mar 2023 08:55:46 +0200 Subject: [PATCH] initial --- .gitignore | 95 ++++++++++++++++++++++++++++------------ cmainwindow.cpp | 109 ++++++++++++++++++++++++++++++++++++++++++++++ cmainwindow.h | 40 +++++++++++++++++ cmainwindow.ui | 45 +++++++++++++++++++ cmediainfo.cpp | 83 +++++++++++++++++++++++++++++++++++ cmediainfo.h | 42 ++++++++++++++++++ fileInventory.pro | 51 ++++++++++++++++++++++ main.cpp | 11 +++++ 8 files changed, 449 insertions(+), 27 deletions(-) create mode 100644 cmainwindow.cpp create mode 100644 cmainwindow.h create mode 100644 cmainwindow.ui create mode 100644 cmediainfo.cpp create mode 100644 cmediainfo.h create mode 100644 fileInventory.pro create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore index 259148f..fab7372 100644 --- a/.gitignore +++ b/.gitignore @@ -1,32 +1,73 @@ -# Prerequisites -*.d +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- -# Compiled Object files -*.slo -*.lo +*~ +*.autosave +*.a +*.core +*.moc *.o *.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries +*.orig +*.rej *.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl *.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/cmainwindow.cpp b/cmainwindow.cpp new file mode 100644 index 0000000..af9126f --- /dev/null +++ b/cmainwindow.cpp @@ -0,0 +1,109 @@ +#include "cmainwindow.h" +#include "ui_cmainwindow.h" + +#include "cmediainfo.h" + +#include +#include + +#include +#include + +#include + + +cMainWindow::cMainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::cMainWindow), + m_scanImages(true), + m_scanVideos(true) +{ + ui->setupUi(this); +} + +cMainWindow::~cMainWindow() +{ + delete ui; +} + +void cMainWindow::addFile(const QString& fileName) +{ + QMimeType mimeType = m_mimeDB.mimeTypeForFile(fileName); + + if((mimeType.name().startsWith("image") && m_scanImages) || (mimeType.name().startsWith("video") && m_scanVideos)) + { + ui->statusbar->showMessage(fileName); + qApp->processEvents(); + m_mediaInfoList.add(fileName); + } +} + +void cMainWindow::on_pushButton_clicked() +{ +// m_scanImages = true; + + scan("E:\\Babs\\Photos 2013 bis jetzt", "c:\\Temp\\CSV\\Babs.csv"); + scan("C:\\Users\\birkeh\\OneDrive\\__MEDIA__", "c:\\Temp\\CSV\\OneDrive.csv"); + + ui->statusbar->showMessage("done.", 5000); + qApp->processEvents(); +} + +void cMainWindow::scan(const QString& dir, const QString& fileName) +{ + m_mediaInfoList.clear(); + scanDir(dir); + writeFile(fileName); +} + +void cMainWindow::scanDir(const QString& dir) +{ + QDir d(dir); + QStringList files = d.entryList(QDir::Files); + + for(int x = 0;x < files.count();x++) + addFile(dir + "\\" + files[x]); + + QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden); + + for(int x = 0;x < dirs.count();x++) + scanDir(dir + "\\" + dirs[x]); +} + +void cMainWindow::writeFile(const QString& fileName) +{ + ui->statusbar->showMessage("writing..."); + qApp->processEvents(); + + QStringList keys = m_mediaInfoList.keys(); + + QFile file(fileName); + if(file.open(QIODevice::WriteOnly | QIODevice::Text)) + { + QTextStream out(&file); + + for(int x = 0;x < keys.count();x++) + { + if(x) + out << ";"; + + out << "\"" << keys[x] << "\""; + } + out << "\n"; + + for(int x = 0;x < m_mediaInfoList.count();x++) + { + cMediaInfo* lpMediaInfo = m_mediaInfoList[x]; + + for(int y = 0;y < keys.count();y++) + { + if(y) + out << ";"; + + out << "\"" << lpMediaInfo->value(keys[y]) << "\""; + } + out << "\n"; + } + file.close(); + } +} diff --git a/cmainwindow.h b/cmainwindow.h new file mode 100644 index 0000000..77a4e0e --- /dev/null +++ b/cmainwindow.h @@ -0,0 +1,40 @@ +#ifndef CMAINWINDOW_H +#define CMAINWINDOW_H + + +#include "cmediainfo.h" + +#include +#include + + +QT_BEGIN_NAMESPACE +namespace Ui { class cMainWindow; } +QT_END_NAMESPACE + + +class cMainWindow : public QMainWindow +{ + Q_OBJECT + +public: + cMainWindow(QWidget *parent = nullptr); + ~cMainWindow(); + +private: + Ui::cMainWindow* ui; + cMediaInfoList m_mediaInfoList; + QMimeDatabase m_mimeDB; + bool m_scanImages; + bool m_scanVideos; + + void scan(const QString& dir, const QString& fileName); + + void addFile(const QString& fileName); + void scanDir(const QString& dir); + void writeFile(const QString& fileName); + +private slots: + void on_pushButton_clicked(); +}; +#endif // CMAINWINDOW_H diff --git a/cmainwindow.ui b/cmainwindow.ui new file mode 100644 index 0000000..05d57ad --- /dev/null +++ b/cmainwindow.ui @@ -0,0 +1,45 @@ + + + cMainWindow + + + + 0 + 0 + 800 + 600 + + + + cMainWindow + + + + + + 40 + 30 + 75 + 23 + + + + start + + + + + + + 0 + 0 + 800 + 21 + + + + + + + + diff --git a/cmediainfo.cpp b/cmediainfo.cpp new file mode 100644 index 0000000..2b71711 --- /dev/null +++ b/cmediainfo.cpp @@ -0,0 +1,83 @@ +#include "cmediainfo.h" +#include "MediaInfoDLL.h" + +#include + + +using namespace MediaInfoDLL; + + +cMediaInfo::cMediaInfo() +{ + +} + +bool cMediaInfo::fromFile(const QString& fileName) +{ + MediaInfo info; + + if(!info.Open(fileName.toStdWString().c_str())) + return(false); + + QString informString = QString::fromStdWString(info.Inform()); + QStringList list = informString.split("\r\n"); + + info.Close(); + + QString category; + + for(int x = 0;x < list.count();x++) + { + if(list[x].isEmpty()) + continue; + + if(list[x].length() < 41) + { + category = list[x]; + if(category == "General") + category = "_General"; + continue; + } + + if(category == "_General" || category.startsWith("video", Qt::CaseInsensitive) || category.startsWith("audio", Qt::CaseInsensitive)) + { + QString key = list[x].left(41).trimmed(); + QString value = list[x].mid(42).trimmed(); + + m_values.insert(category + "|" + key, value); + } + } + return(true); +} + +QStringList cMediaInfo::keys() +{ + return(m_values.keys()); +} + +QString cMediaInfo::value(const QString& key) +{ + return(m_values.value(key)); +} + +cMediaInfoList::cMediaInfoList() +{ +} + + +cMediaInfo* cMediaInfoList::add(const QString& fileName) +{ + cMediaInfo* lpNew = new cMediaInfo; + append(lpNew); + lpNew->fromFile(fileName); + m_keyList.append(lpNew->keys()); + m_keyList.removeDuplicates(); + + return(lpNew); +} + +QStringList cMediaInfoList::keys() +{ + m_keyList.sort(Qt::CaseInsensitive); + return(m_keyList); +} diff --git a/cmediainfo.h b/cmediainfo.h new file mode 100644 index 0000000..bd06f2d --- /dev/null +++ b/cmediainfo.h @@ -0,0 +1,42 @@ +#ifndef CMEDIAINFO_H +#define CMEDIAINFO_H + +#include +#include +#include +#include + +#include + + +class cMediaInfo +{ +public: + cMediaInfo(); + + bool fromFile(const QString& fileName); + QStringList keys(); + + QString value(const QString& key); + +private: + QMap m_values; +}; + +Q_DECLARE_METATYPE(cMediaInfo*) + +class cMediaInfoList : public QList +{ +public: + cMediaInfoList(); + + cMediaInfo* add(const QString& fileName); + QStringList keys(); + +private: + QStringList m_keyList; + bool m_pictures; + bool m_videos; +}; + +#endif // CMEDIAINFO_H diff --git a/fileInventory.pro b/fileInventory.pro new file mode 100644 index 0000000..f4962e7 --- /dev/null +++ b/fileInventory.pro @@ -0,0 +1,51 @@ +QT += core gui sql multimedia + +win32-msvc* { + contains(QT_ARCH, i386) { + message("msvc 32-bit") + } else { + message("msvc 64-bit") + } +} + +win32-g++ { + message("mingw") + INCLUDEPATH += C:\dev\3rdParty\libmediainfo\Developers\Source\MediaInfoDLL + LIBS += -LC:\dev\3rdParty\libmediainfo -lMediaInfo +} + +unix { + message("*nix") +} + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + cmediainfo.cpp \ + main.cpp \ + cmainwindow.cpp + +HEADERS += \ + cmainwindow.h \ + cmediainfo.h + +FORMS += \ + cmainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..025da0a --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "cmainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + cMainWindow w; + w.show(); + return a.exec(); +}