Skip to content

Commit e15f941

Browse files
Preset management
1 parent 6cc9a09 commit e15f941

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1884
-301
lines changed

App.cpp

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "DeviceSelectorObserver.hpp"
1414
#include "OutputOptionsState.hpp"
1515
#include "PreferencesView.hpp"
16+
#include "PresetPanel.hpp"
1617
#include "PreviewPanel.hpp"
1718
#include "ScanOptionsPanel.hpp"
1819
#include "Writers/FileWriter.hpp"
@@ -113,7 +114,7 @@ GtkWidget *ZooScan::App::CreateContent()
113114
auto deviceSelected = !GetSelectorDeviceName().empty();
114115

115116
auto *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
116-
gtk_widget_set_margin_bottom(paned, 15);
117+
gtk_widget_set_margin_bottom(paned, 0);
117118
gtk_widget_set_margin_top(paned, 0);
118119
gtk_widget_set_margin_start(paned, 10);
119120
gtk_widget_set_margin_end(paned, 10);
@@ -128,31 +129,53 @@ GtkWidget *ZooScan::App::CreateContent()
128129
gtk_orientable_set_orientation(GTK_ORIENTABLE(clamp), GTK_ORIENTATION_HORIZONTAL);
129130
gtk_paned_set_start_child(GTK_PANED(paned), clamp);
130131

131-
m_SettingsBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
132+
m_SettingsBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
132133
gtk_widget_set_margin_bottom(m_SettingsBox, 0);
133134
gtk_widget_set_margin_top(m_SettingsBox, 0);
134135
gtk_widget_set_margin_start(m_SettingsBox, 0);
135136
gtk_widget_set_margin_end(m_SettingsBox, 10);
136137
adw_clamp_set_child(ADW_CLAMP(clamp), m_SettingsBox);
137138

139+
auto buttonBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
140+
gtk_widget_set_margin_bottom(buttonBox, 20);
141+
gtk_widget_set_margin_top(buttonBox, 20);
142+
gtk_widget_set_margin_start(buttonBox, 0);
143+
gtk_widget_set_margin_end(buttonBox, 0);
144+
gtk_box_append(GTK_BOX(m_SettingsBox), buttonBox);
145+
138146
m_PreviewButton = gtk_button_new_with_label(_("Preview"));
139147
ConnectGtkSignal(this, &App::OnPreviewClicked, m_PreviewButton, "clicked");
140148
gtk_widget_set_sensitive(m_PreviewButton, deviceSelected);
141-
gtk_box_append(GTK_BOX(m_SettingsBox), m_PreviewButton);
149+
gtk_box_append(GTK_BOX(buttonBox), m_PreviewButton);
142150

143151
m_ScanButton = gtk_button_new_with_label(_("Scan"));
144152
ConnectGtkSignal(this, &App::OnScanClicked, m_ScanButton, "clicked");
145153
gtk_widget_set_sensitive(m_ScanButton, deviceSelected);
146-
gtk_box_append(GTK_BOX(m_SettingsBox), m_ScanButton);
154+
gtk_box_append(GTK_BOX(buttonBox), m_ScanButton);
147155

148156
m_CancelButton = gtk_button_new_with_label(_("Cancel Scan"));
149157
ConnectGtkSignal(this, &App::OnCancelClicked, m_CancelButton, "clicked");
150158
gtk_widget_set_sensitive(m_CancelButton, false);
151-
gtk_box_append(GTK_BOX(m_SettingsBox), m_CancelButton);
159+
gtk_box_append(GTK_BOX(buttonBox), m_CancelButton);
160+
161+
auto bottomAlignedSection = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
162+
gtk_widget_set_hexpand(bottomAlignedSection, true);
163+
gtk_widget_set_vexpand(bottomAlignedSection, true);
164+
gtk_widget_set_valign(bottomAlignedSection, GTK_ALIGN_END);
165+
gtk_box_append(GTK_BOX(m_SettingsBox), bottomAlignedSection);
166+
167+
m_PresetPanel = ZooLib::View::Create<PresetPanel>(&m_Dispatcher, this);
168+
auto presetsBox = m_PresetPanel->GetRootWidget();
169+
gtk_widget_set_margin_bottom(presetsBox, 0);
170+
gtk_widget_set_margin_top(presetsBox, 0);
171+
gtk_widget_set_margin_start(presetsBox, 0);
172+
gtk_widget_set_margin_end(presetsBox, 0);
173+
gtk_box_append(GTK_BOX(bottomAlignedSection), presetsBox);
174+
gtk_widget_set_hexpand(presetsBox, true);
152175

153176
m_PreviewPanel = ZooLib::View::Create<PreviewPanel>(&m_Dispatcher, this);
154177
auto previewBox = m_PreviewPanel->GetRootWidget();
155-
gtk_widget_set_margin_bottom(previewBox, 0);
178+
gtk_widget_set_margin_bottom(previewBox, 10);
156179
gtk_widget_set_margin_top(previewBox, 0);
157180
gtk_widget_set_margin_start(previewBox, 10);
158181
gtk_widget_set_margin_end(previewBox, 0);
@@ -268,7 +291,7 @@ void ZooScan::App::Update(const std::vector<uint64_t> &lastSeenVersions)
268291
}
269292

270293
gtk_box_remove(GTK_BOX(m_SettingsBox), m_ScanOptionsPanel->GetRootWidget());
271-
// m_DeviceOptionsPanel is automatically deleted when its root widget is destroyed.
294+
// m_ScanOptionsPanel is automatically deleted when its root widget is destroyed.
272295
m_ScanOptionsPanel = nullptr;
273296
m_Dispatcher.UnregisterHandler<SetScanAreaCommand>();
274297
}
@@ -315,18 +338,26 @@ void ZooScan::App::Update(const std::vector<uint64_t> &lastSeenVersions)
315338
}
316339
}
317340

318-
const ZooScan::DeviceOptionsState *ZooScan::App::GetDeviceOptions() const
341+
ZooScan::DeviceOptionsState *ZooScan::App::GetDeviceOptions() const
319342
{
320343
if (m_ScanOptionsPanel == nullptr)
321344
return nullptr;
322345

323346
return m_ScanOptionsPanel->GetDeviceOptionsState();
324347
}
325348

326-
void ZooScan::App::RestoreScanOptions() const
349+
ZooScan::OutputOptionsState *ZooScan::App::GetOutputOptions()
350+
{
351+
if (m_ScanOptionsPanel == nullptr)
352+
return nullptr;
353+
354+
return m_ScanOptionsPanel->GetOutputOptionsState();
355+
}
356+
357+
void ZooScan::App::RestoreScanOptions()
327358
{
328359
auto device = GetDevice();
329-
const auto options = GetDeviceOptions();
360+
auto options = GetDeviceOptions();
330361
if (device == nullptr || options == nullptr)
331362
{
332363
return;

App.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace ZooScan
1414
{
15+
class PresetPanel;
1516
class FileWriter;
1617
class DeviceOptionsObserver;
1718
class ScanOptionsPanel;
@@ -33,6 +34,7 @@ namespace ZooScan
3334

3435
ScanOptionsPanel *m_ScanOptionsPanel{};
3536
PreviewPanel *m_PreviewPanel{};
37+
PresetPanel *m_PresetPanel{};
3638

3739
GtkWidget *m_SettingsBox{};
3840

@@ -74,7 +76,7 @@ namespace ZooScan
7476
{
7577
return nullptr;
7678
}
77-
return m_DeviceSelectorState->GetDeviceByName(m_AppState->GetOptionPanelDeviceName());
79+
return m_DeviceSelectorState->GetDeviceByName(m_AppState->GetCurrentDeviceName());
7880
}
7981

8082
[[nodiscard]] int GetScanHeight() const;
@@ -83,7 +85,7 @@ namespace ZooScan
8385

8486
void OnPreviewClicked(GtkWidget *widget);
8587
void UpdatePreview();
86-
void RestoreScanOptions() const;
88+
void RestoreScanOptions();
8789
void StopPreview();
8890

8991
bool CheckFileOutputOptions(const OutputOptionsState *scanOptions);
@@ -114,9 +116,9 @@ namespace ZooScan
114116
return m_AppState;
115117
}
116118

117-
[[nodiscard]] AppState *GetAppState()
119+
[[nodiscard]] const DeviceSelectorState *GetDeviceSelectorState() const
118120
{
119-
return m_AppState;
121+
return m_DeviceSelectorState;
120122
}
121123

122124
void Update(const std::vector<uint64_t> &lastSeenVersions);
@@ -131,6 +133,7 @@ namespace ZooScan
131133
return m_DeviceSelectorState->GetDeviceByName(deviceName);
132134
}
133135

134-
[[nodiscard]] const DeviceOptionsState *GetDeviceOptions() const;
136+
[[nodiscard]] DeviceOptionsState *GetDeviceOptions() const;
137+
[[nodiscard]] OutputOptionsState *GetOutputOptions();
135138
};
136139
}

AppState.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace ZooScan
1616
private:
1717
const bool m_DevMode;
1818

19-
std::string m_OptionPanelDeviceName{};
19+
std::string m_CurrentDeviceName{};
2020
AppMode m_AppMode{};
2121

2222
bool m_IsScanning{};
@@ -29,13 +29,11 @@ namespace ZooScan
2929
{
3030
}
3131

32-
~AppState() override
33-
{
34-
}
32+
~AppState() override = default;
3533

36-
[[nodiscard]] const std::string &GetOptionPanelDeviceName() const
34+
[[nodiscard]] const std::string &GetCurrentDeviceName() const
3735
{
38-
return m_OptionPanelDeviceName;
36+
return m_CurrentDeviceName;
3937
}
4038

4139
[[nodiscard]] AppMode GetAppMode() const
@@ -66,9 +64,13 @@ namespace ZooScan
6664
{
6765
}
6866

69-
void UpdateOptionPanelDeviceName(const std::string &deviceName) const
67+
void LoadFromJson(const nlohmann::json &json) override
68+
{
69+
}
70+
71+
void SetCurrentDevice(const std::string &deviceName) const
7072
{
71-
m_StateComponent->m_OptionPanelDeviceName = deviceName;
73+
m_StateComponent->m_CurrentDeviceName = deviceName;
7274
}
7375

7476
void SetAppMode(AppMode scanMode) const

CMakeLists.txt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,35 @@ set(SOURCE_FILES
5959
DeviceOptionsState.cpp
6060
DeviceSelectorState.cpp
6161
OptionRewriter.cpp
62+
PresetCreateDialog.cpp
63+
PresetPanel.cpp
64+
PresetPanelState.cpp
6265
PreviewPanel.cpp
6366
ScanOptionsPanel.cpp
6467

6568
Writers/FileWriter.cpp
6669
Writers/JpegWriter.cpp
6770
Writers/PngWriter.cpp
6871
Writers/TiffWriter.cpp
72+
PresetRenameDialog.cpp
73+
PresetViewDialog.cpp
6974
)
7075

7176
set(GETTEXT_SOURCE_FILES
7277
${SOURCE_FILES}
7378

79+
Commands/ApplyPresetCommand.hpp
7480
Commands/ChangeOptionCommand.hpp
81+
Commands/CreatePresetCommand.hpp
82+
Commands/DeletePresetCommand.hpp
7583
Commands/DeviceSelectorCommands.hpp
7684
Commands/DevMode/SetDumpSaneOptions.hpp
85+
Commands/RenamePresetCommand.hpp
7786
Commands/SelectDeviceCommand.hpp
7887
Commands/SetCreateMissingDirectoriesCommand.hpp
7988
Commands/SetFileExistsActionCommand.hpp
8089
Commands/SetJpegQuality.hpp
90+
Commands/SetPresetExpanded.hpp
8191
Commands/SetOutputDestinationCommand.hpp
8292
Commands/SetOutputDirectoryCommand.hpp
8393
Commands/SetOutputFileNameCommand.hpp
@@ -106,16 +116,20 @@ set(GETTEXT_SOURCE_FILES
106116
ZooLib/CommandDispatcher.hpp
107117
ZooLib/ErrorDialog.hpp
108118
ZooLib/Gettext.hpp
119+
ZooLib/GtkUtils.hpp
109120
ZooLib/Observer.hpp
110121
ZooLib/ObserverManager.hpp
111122
ZooLib/SignalSupport.hpp
112123
ZooLib/State.hpp
113124
ZooLib/StateComponent.hpp
125+
ZooLib/StringUtils.hpp
114126
ZooLib/View.hpp
115127

116128
App.hpp
117129
AppState.hpp
130+
CurrentDeviceObserver.hpp
118131
DeviceOptionsObserver.hpp
132+
DeviceOptionsState.hpp
119133
DeviceOptionValueBase.hpp
120134
DeviceOptionValue.hpp
121135
DeviceSelector.hpp
@@ -125,6 +139,9 @@ set(GETTEXT_SOURCE_FILES
125139
OutputOptionsState.hpp
126140
Point.hpp
127141
PreferencesView.hpp
142+
PresetPanel.hpp
143+
PresetPanelDialogs.hpp
144+
PresetPanelState.hpp
128145
PreviewPanel.hpp
129146
PreviewState.hpp
130147
Rect.hpp
@@ -136,6 +153,21 @@ set(GETTEXT_SOURCE_FILES
136153

137154
if (GETTEXT_XGETTEXT_EXECUTABLE)
138155

156+
# Check that the GETTEXT_SOURCE_FILES are up to date with the files in the project.
157+
file(GLOB_RECURSE GETTEXT_SOURCE_FILES_FROM_GLOB RELATIVE ${CMAKE_SOURCE_DIR} *.cpp *.hpp)
158+
file(GLOB_RECURSE GETTEXT_EXCLUDED_SOURCE_FILES_FROM_GLOB RELATIVE ${CMAKE_SOURCE_DIR} Tests/* ZooLib/json/* cmake-*/*)
159+
list(REMOVE_ITEM GETTEXT_SOURCE_FILES_FROM_GLOB ${GETTEXT_EXCLUDED_SOURCE_FILES_FROM_GLOB})
160+
161+
list(APPEND GETTEXT_SOURCE_FILES_DIFF ${GETTEXT_SOURCE_FILES_FROM_GLOB})
162+
list(REMOVE_ITEM GETTEXT_SOURCE_FILES_DIFF ${GETTEXT_SOURCE_FILES})
163+
list(LENGTH GETTEXT_SOURCE_FILES_DIFF GETTEXT_SOURCE_FILES_DIFF_LENGTH)
164+
if (GETTEXT_SOURCE_FILES_DIFF_LENGTH GREATER 0)
165+
message(STATUS "These files are missing from the GETTEXT_SOURCE_FILES:")
166+
foreach (item IN LISTS GETTEXT_SOURCE_FILES_DIFF)
167+
message(STATUS " ${item}")
168+
endforeach()
169+
endif()
170+
139171
# Extract strings from JSON files: title, description and string_list. Make a list of them and remove empty strings.
140172
set(JQ_FILTER '[.options[].title,.options[].description,.options[].string_list[]] | map(select((. | length) > 0))')
141173

@@ -199,7 +231,6 @@ if (GETTEXT_MSGMERGE_EXECUTABLE)
199231
message(TRACE " PO_FILES: ${PO_FILES}")
200232

201233
foreach(PO_FILE IN ITEMS ${PO_FILES})
202-
message(STATUS " Adding msgmerge for: ${PO_FILE}")
203234
add_custom_command(
204235
TARGET pot-merge
205236
PRE_BUILD
@@ -227,7 +258,6 @@ if (GETTEXT_MSGFMT_EXECUTABLE)
227258

228259
foreach(PO_LANG IN ITEMS ${PO_LANGS})
229260
if(IS_DIRECTORY ${PO_LANG})
230-
message(STATUS " Adding msgfmt for: ${PO_LANG}")
231261
add_custom_command(
232262
TARGET po-compile
233263
PRE_BUILD

Commands/ApplyPresetCommand.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#pragma once
2+
#include <string>
3+
4+
5+
#include "DeviceOptionsState.hpp"
6+
7+
#include "OutputOptionsState.hpp"
8+
#include "PresetPanelState.hpp"
9+
#include "ZooLib/Command.hpp"
10+
11+
namespace ZooScan
12+
{
13+
class ApplyPresetCommand : public ZooLib::Command
14+
{
15+
const nlohmann::json *m_Preset;
16+
17+
public:
18+
explicit ApplyPresetCommand(const nlohmann::json *preset)
19+
: m_Preset(preset)
20+
{
21+
}
22+
23+
static void
24+
Execute(const ApplyPresetCommand &command, DeviceOptionsState *deviceOptions, OutputOptionsState *outputOptions)
25+
{
26+
if (command.m_Preset == nullptr)
27+
{
28+
return;
29+
}
30+
31+
if (command.m_Preset->contains(PresetPanelState::s_PresetSectionScannerSettings))
32+
{
33+
auto scannerSettings = command.m_Preset->at(PresetPanelState::s_PresetSectionScannerSettings);
34+
auto deviceOptionsUpdater = DeviceOptionsState::Updater(deviceOptions);
35+
deviceOptionsUpdater.ApplySettings(scannerSettings);
36+
}
37+
if (command.m_Preset->contains(PresetPanelState::s_PresetSectionScanArea))
38+
{
39+
auto scanAreaSettings = command.m_Preset->at(PresetPanelState::s_PresetSectionScanArea);
40+
auto deviceOptionsUpdater = DeviceOptionsState::Updater(deviceOptions);
41+
deviceOptionsUpdater.ApplyScanArea(scanAreaSettings);
42+
}
43+
if (command.m_Preset->contains(PresetPanelState::s_PresetSectionOutputSettings))
44+
{
45+
auto outputSettings = command.m_Preset->at(PresetPanelState::s_PresetSectionOutputSettings);
46+
auto outputOptionsUpdater = OutputOptionsState::Updater(outputOptions);
47+
// outputOptionsUpdater.ApplySettings(outputSettings);
48+
}
49+
}
50+
};
51+
}

Commands/CreatePresetCommand.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
#include "PresetPanelState.hpp"
3+
#include "ZooLib/Command.hpp"
4+
#include "ZooLib/json/single_include/nlohmann/json.hpp"
5+
6+
namespace ZooScan
7+
{
8+
9+
class CreatePresetCommand : public ZooLib::Command
10+
{
11+
nlohmann::json m_Preset{};
12+
13+
public:
14+
explicit CreatePresetCommand(const nlohmann::json &j)
15+
: m_Preset(j)
16+
{
17+
}
18+
19+
static void Execute(const CreatePresetCommand &command, PresetPanelState *state)
20+
{
21+
auto updater = PresetPanelState::Updater(state);
22+
updater.AddPreset(command.m_Preset);
23+
}
24+
};
25+
26+
}

0 commit comments

Comments
 (0)