summaryrefslogtreecommitdiff
path: root/src/modinfodialogtab.cpp
blob: 5874522049c620fc0513ca1858808dcb8b9c86a2 (plain)
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
115
116
117
118
119
120
121
122
123
#include "modinfodialogtab.h"
#include "ui_modinfodialog.h"
#include "texteditor.h"
#include "directoryentry.h"

ModInfoDialogTab::ModInfoDialogTab(
  OrganizerCore& oc, PluginContainer& plugin,
  QWidget* parent, Ui::ModInfoDialog* ui)
    : ui(ui), m_core(oc), m_plugin(plugin), m_parent(parent), m_origin(nullptr)
{
}

void ModInfoDialogTab::update()
{
  // no-op
}

bool ModInfoDialogTab::feedFile(const QString&, const QString&)
{
  // no-op
  return false;
}

bool ModInfoDialogTab::canClose()
{
  return true;
}

void ModInfoDialogTab::saveState(Settings&)
{
  // no-op
}

void ModInfoDialogTab::restoreState(const Settings& s)
{
  // no-op
}

bool ModInfoDialogTab::deleteRequested()
{
  // no-op
  return false;
}

void ModInfoDialogTab::setMod(ModInfo::Ptr mod, MOShared::FilesOrigin* origin)
{
  m_mod = mod;
  m_origin = origin;
}

ModInfo::Ptr ModInfoDialogTab::mod() const
{
  return m_mod;
}

MOShared::FilesOrigin* ModInfoDialogTab::origin() const
{
  return m_origin;
}

OrganizerCore& ModInfoDialogTab::core()
{
  return m_core;
}

PluginContainer& ModInfoDialogTab::plugin()
{
  return m_plugin;
}

QWidget* ModInfoDialogTab::parentWidget()
{
  return m_parent;
}

void ModInfoDialogTab::emitOriginModified()
{
  if (m_origin) {
    emit originModified(m_origin->getID());
  }
}

void ModInfoDialogTab::emitModOpen(QString name)
{
  emit modOpen(name);
}


NotesTab::NotesTab(
  OrganizerCore& oc, PluginContainer& plugin,
  QWidget* parent, Ui::ModInfoDialog* ui)
   : ModInfoDialogTab(oc, plugin, parent, ui)
{
  connect(ui->commentsEdit, &QLineEdit::editingFinished, [&]{ onComments(); });
  connect(ui->notesEdit, &HTMLEditor::editingFinished, [&]{ onNotes(); });
}

void NotesTab::clear()
{
  ui->commentsEdit->clear();
  ui->notesEdit->clear();
}

void NotesTab::update()
{
  ui->commentsEdit->setText(mod()->comments());
  ui->notesEdit->setText(mod()->notes());
}

void NotesTab::onComments()
{
  mod()->setComments(ui->commentsEdit->text());
}

void NotesTab::onNotes()
{
  // Avoid saving html stub if notes field is empty.
  if (ui->notesEdit->toPlainText().isEmpty()) {
    mod()->setNotes({});
  } else {
    mod()->setNotes(ui->notesEdit->toHtml());
  }
}