tageditor/gui/tageditorwidget.h

230 lines
7.1 KiB
C
Raw Permalink Normal View History

#ifndef TAGEDITORWIDGET_H
#define TAGEDITORWIDGET_H
#include "./previousvaluehandling.h"
#include "./webviewdefs.h"
2018-03-06 02:04:35 +01:00
#include <tagparser/diagnostics.h>
2018-03-07 01:18:01 +01:00
#include <tagparser/mediafileinfo.h>
#include <QByteArray>
#include <QFuture>
2018-03-07 01:18:01 +01:00
#include <QWidget>
#include <functional>
QT_FORWARD_DECLARE_CLASS(QFileSystemWatcher)
QT_FORWARD_DECLARE_CLASS(QMenu)
QT_FORWARD_DECLARE_CLASS(QTreeView)
QT_FORWARD_DECLARE_CLASS(QFile)
QT_FORWARD_DECLARE_CLASS(QTemporaryFile)
2019-07-07 12:00:16 +02:00
#define TAGEDITOR_ENUM_CLASS enum class
2018-03-06 23:10:13 +01:00
namespace TagParser {
2019-07-07 12:00:16 +02:00
TAGEDITOR_ENUM_CLASS TagType : unsigned int;
}
2019-07-07 12:00:16 +02:00
#undef TAGEDITOR_ENUM_CLASS
namespace QtGui {
namespace Ui {
class TagEditorWidget;
}
class TagEdit;
class FileInfoModel;
2018-03-07 01:18:01 +01:00
class TagEditorWidget : public QWidget {
Q_OBJECT
Q_PROPERTY(QString currentPath READ currentPath NOTIFY currentPathChanged)
Q_PROPERTY(QString currentDir READ currentDir)
2016-09-25 23:59:04 +02:00
Q_PROPERTY(bool tagEditShown READ isTagEditShown)
Q_PROPERTY(QByteArray fileInfoHtml READ fileInfoHtml)
Q_PROPERTY(bool fileNameVisible READ isFileNameVisible WRITE setFileNameVisible)
Q_PROPERTY(bool buttonsVisible READ areButtonsVisible WRITE setButtonVisible)
Q_PROPERTY(bool fileOperationOngoing READ isFileOperationOngoing)
2018-03-07 01:18:01 +01:00
public:
explicit TagEditorWidget(QWidget *parent = nullptr);
2019-06-01 12:45:12 +02:00
~TagEditorWidget() override;
public:
bool isFileOperationOngoing() const;
const QString &currentPath() const;
const QString &currentDir() const;
2018-03-06 23:10:13 +01:00
TagParser::MediaFileInfo &fileInfo();
const TagParser::Diagnostics &diagnostics() const;
2016-03-03 22:21:15 +01:00
bool isTagEditShown() const;
const QByteArray &fileInfoHtml() const;
const QByteArray &generateFileInfoHtml();
bool isFileNameVisible() const;
void setFileNameVisible(bool visible);
bool areButtonsVisible() const;
void setButtonVisible(bool visible);
2018-03-07 01:18:01 +01:00
void foreachTagEdit(const std::function<void(TagEdit *)> &function);
2016-03-03 22:21:15 +01:00
TagEdit *activeTagEdit();
2020-03-08 14:04:29 +01:00
public Q_SLOTS:
// operations with the currently opened file: load, save, delete, close
bool startParsing(const QString &path, bool forceRefresh = false);
bool startSaving();
void saveAndShowNextFile();
bool reparseFile();
bool applyEntriesAndSaveChangings();
bool deleteAllTagsAndSave();
void closeFile();
void renameFile();
void saveFileInfo();
void openFileInfoInBrowser();
// misc
void applySettingsFromDialog();
void addParsingNotificationLine(const QString &line);
2020-03-09 18:46:08 +01:00
Q_SIGNALS:
/// \brief Emitted when loading the next file has been triggered.
void nextFileSelected();
/// \brief Emitted to show a status message.
void statusMessage(const QString &message, int timeout = 0);
2016-12-01 22:23:01 +01:00
/// \brief Emitted when the file status (opened/closed) has changed.
void fileStatusChanged(bool opened, bool hasTag);
/// \brief Emitted when the current path has changed; always emitted a saving.
void currentPathChanged(const QString &newPath);
2016-12-01 22:23:01 +01:00
/// \brief Emitted when all tag values have been parsed and loaded into tag edits.
/// \remarks In particular, this is emitted *before* any additional data is inserted (like title from file name).
void tagValuesLoaded();
/// \brief Emitted when a file has been shown (file is parsed and all widgets have been updated accordingly).
/// \remarks In particular, this is emitted *after* additional data (like title from file name) might have been inserted.
void fileShown();
protected:
2019-06-01 12:45:12 +02:00
bool event(QEvent *event) override;
2020-03-08 14:04:29 +01:00
private Q_SLOTS:
// editor
void fileChangedOnDisk(const QString &path);
void showFile(char result, const QString &ioError);
void handleReturnPressed();
void handleKeepPreviousValuesActionTriggered(QAction *action);
2018-03-06 23:10:13 +01:00
void addTag(const std::function<TagParser::Tag *(TagParser::MediaFileInfo &)> &createTag);
void removeTag(TagParser::Tag *tag);
void changeTarget(TagParser::Tag *tag);
// saving
void showSavingResult(QString ioError, bool processingError, bool canceled);
// info (web) view
void initInfoView();
void updateInfoView();
void showInfoTreeViewContextMenu(const QPoint &position);
#ifndef TAGEDITOR_NO_WEBVIEW
void showInfoWebViewContextMenu(const QPoint &position);
#endif
bool handleFileInfoUnavailable();
bool writeFileInfoToFile(QFile &file);
private:
void updateDocumentTitleEdits();
void updateTagEditsAndAttachmentEdits(bool updateUi = true, PreviousValueHandling previousValueHandling = PreviousValueHandling::Auto);
void updateTagSelectionComboBox();
void updateFileStatusStatus();
void updateTagManagementMenu();
2018-03-14 19:35:52 +01:00
void updateKeepPreviousValuesButton();
void insertTitleFromFilename();
bool confirmCreationOfId3TagForUnsupportedFile();
// UI
std::unique_ptr<Ui::TagEditorWidget> m_ui;
QMenu *m_keepPreviousValuesMenu;
QMenu *m_tagOptionsMenu;
QMenu *m_addTagMenu;
QMenu *m_removeTagMenu;
QMenu *m_changeTargetMenu;
#ifndef TAGEDITOR_NO_WEBVIEW
TAGEDITOR_WEB_VIEW *m_infoWebView;
#endif
FileInfoModel *m_infoModel;
QTreeView *m_infoTreeView;
std::unique_ptr<QTemporaryFile> m_temporaryInfoFile;
// tag, file, directory management
QString m_currentPath;
QFileSystemWatcher *m_fileWatcher;
bool m_fileChangedOnDisk;
2018-03-06 23:10:13 +01:00
TagParser::MediaFileInfo m_fileInfo;
std::vector<TagParser::Tag *> m_tags;
QByteArray m_fileInfoHtml;
2016-12-01 22:23:01 +01:00
QString m_fileName;
QString m_currentDir;
QString m_lastDir;
2016-05-01 20:07:04 +02:00
QString m_saveFilePath;
// status
2018-03-06 23:10:13 +01:00
TagParser::Diagnostics m_diag;
TagParser::Diagnostics m_diagReparsing;
QFuture<void> m_ongoingFileOperation;
bool m_nextFileAfterSaving;
bool m_makingResultsAvailable;
bool m_abortClicked;
};
/*!
* \brief Returns the mutex which is internally used for thread-synchronization.
*/
inline bool TagEditorWidget::isFileOperationOngoing() const
{
return m_ongoingFileOperation.isRunning();
}
/*!
2016-12-01 22:23:01 +01:00
* \brief Returns the path of the currently opened file including filename.
*/
inline const QString &TagEditorWidget::currentPath() const
{
return m_currentPath;
}
/*!
2016-12-01 22:23:01 +01:00
* \brief Returns the path of the currently opened file excluding filename.
* \remarks This is the actual directory of the opened file which may differ from the directory selected in the tree view of the main window.
*/
inline const QString &TagEditorWidget::currentDir() const
{
return m_currentDir;
}
/*!
* \brief Return file info.
*/
2018-03-06 23:10:13 +01:00
inline TagParser::MediaFileInfo &TagEditorWidget::fileInfo()
{
return m_fileInfo;
}
/*!
2018-03-06 02:04:35 +01:00
* \brief Returns the diagnostic messages.
*/
2018-03-06 23:10:13 +01:00
inline const TagParser::Diagnostics &TagEditorWidget::diagnostics() const
{
2018-03-06 02:04:35 +01:00
return m_diag;
}
/*!
* \brief Returns the HTML source of the info website.
* \remarks Returns an empty string if no file info has been generated yet. See generateFileInfoHtml() for a method which will ensure
* the file info has been generated.
*/
inline const QByteArray &TagEditorWidget::fileInfoHtml() const
{
return m_fileInfoHtml;
}
2016-03-03 22:21:15 +01:00
/*!
* \brief Returns whether currently a tag edit is shown.
*/
inline bool TagEditorWidget::isTagEditShown() const
{
return !m_tags.empty();
}
2018-03-07 01:18:01 +01:00
} // namespace QtGui
#endif // TAGEDITORWIDGET_H