aboutsummaryrefslogtreecommitdiff
path: root/src/yuzu/nup_dialogs.h
blob: b9258c216b97bf801f03169a9e562d273397327b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <filesystem>

#include <QByteArray>
#include <QDialog>
#include <QElapsedTimer>
#include <QPixmap>
#include <QWidget>

#include "common/common_types.h"
#include "core/file_sys/nup_writer.h"

class QCheckBox;
class QLabel;
class QLineEdit;
class QProgressBar;
class QPushButton;
class QRadioButton;

// Square preview that accepts an image dropped on it or chosen with a click.
class IconDropZone : public QWidget {
    Q_OBJECT
public:
    explicit IconDropZone(int size, QWidget* parent = nullptr);

    void SetIcon(const QPixmap& icon);

signals:
    void FileDropped(const QString& path);
    void Clicked();

protected:
    void paintEvent(QPaintEvent* event) override;
    void dragEnterEvent(QDragEnterEvent* event) override;
    void dragLeaveEvent(QDragLeaveEvent* event) override;
    void dropEvent(QDropEvent* event) override;
    void mouseReleaseEvent(QMouseEvent* event) override;
    void enterEvent(QEnterEvent* event) override;
    void leaveEvent(QEvent* event) override;

private:
    QPixmap icon;
    bool dragging = false;
    bool hovered = false;
};

// Asks for the metadata a NUP is written with and for the conversion options.
class NupMetadataDialog : public QDialog {
    Q_OBJECT
public:
    NupMetadataDialog(const std::filesystem::path& source, const std::filesystem::path& archive,
                      u64 needed_bytes, u64 available_bytes, QWidget* parent = nullptr);
    ~NupMetadataDialog() override;

    // Empty fields keep what the dump supplies.
    FileSys::Nup::Metadata Metadata() const;
    bool DeleteSources() const;
    // What the summary shows: the name entered and the icon that will be stored.
    QString DisplayName() const;
    QPixmap CurrentIcon() const;

private:
    void ChooseIcon();
    void SetIconFromFile(const QString& path);
    void ResetIcon();
    void UpdateIconPreview();
    void UpdateVersionEnabled();

    FileSys::Nup::Metadata detected;
    QByteArray custom_icon;
    QPixmap current_icon;

    IconDropZone* icon_preview;
    QLabel* icon_hint;
    QPushButton* reset_icon;
    QLineEdit* name_edit;
    QRadioButton* version_auto;
    QRadioButton* version_manual;
    QLineEdit* version_edit;
    QCheckBox* low_storage;
};

// Shown while a conversion runs. The bar spans the dialog; the labels show what is being
// converted, how much is done and a rough time remaining.
class NupProgressDialog : public QDialog {
    Q_OBJECT
public:
    NupProgressDialog(const QString& title, const QPixmap& icon, QWidget* parent = nullptr);

    void SetProgress(const FileSys::Nup::PackProgress& progress);
    void SetCancelling();
    // Closes the dialog without treating it as a cancel request.
    void Finish();

signals:
    void CancelRequested();

protected:
    void closeEvent(QCloseEvent* event) override;
    void reject() override;

private:
    QLabel* status;
    QLabel* details;
    QProgressBar* bar;
    QPushButton* cancel;
    QElapsedTimer timer;
    bool cancelling = false;
    bool finished = false;
};