-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPSEngine.hpp
More file actions
149 lines (116 loc) · 5.34 KB
/
MPSEngine.hpp
File metadata and controls
149 lines (116 loc) · 5.34 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* This file is part of MemphisNow.
*
* MemphisNow is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MemphisNow is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MemphisNow. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MPSENGINE_HPP
#define MPSENGINE_HPP
#include "MPSToken.hpp"
#include "MPSEngineObserver.hpp"
#include "MPSTransformsContainer.hpp"
#include <string>
#include <map>
#include <QVector>
#include <QString>
struct MPSFilesMapStruct {
MPSToken* root;
std::wstring rename_to;
explicit MPSFilesMapStruct (MPSToken* token = 0, const std::wstring& rename = L"")
: root (token), rename_to (rename) {}
};
typedef std::map<size_t, MPSFilesMapStruct> MPSFilesToRenameMap;
class MPSEngine : public MPSTransformsContainer
{
public:
MPSEngine();
~MPSEngine();
void set_default_separators (const std::wstring& separators);
std::wstring default_separators () const { return m_default_separators; }
void set_always_lowcase_extension (bool lowcase) { m_always_lowcase_extension = lowcase; }
bool is_always_lowcase_extension () const { return m_always_lowcase_extension; }
/*
* Tries to find the file_name in the internal map based on its hash value
* If it's found, it will select the stored root token
* If not, it will add an entry into the internal map and select the new root token
* Passing an empty string forces a deselect
*/
void select_master_token (const std::wstring& file_name);
const MPSToken* master_token () const { return m_master_token; }
std::wstring current_rename_to () const { return m_rename_to; }
// subtoken methods
void select_subtoken (MPSToken* token, bool updateOutput = true);
const MPSToken* selected_subtoken () const { return m_selected_subtoken; }
void update_selected_subtoken (
const std::wstring& text,
const std::wstring& separators,
bool discard,
bool force_update = false
);
// shift selected subtoken
void shift_selected_subtoken (EMPSDirection direction);
// upcase or lowcase first or all
void change_case (bool upcase, bool only_first, bool recursive);
// insert text to left or right
void insert_text (const std::wstring& text_to_insert, EMPSDirection direction);
// files map access
bool has_rename_to (const std::wstring& file_name, std::wstring& rename_to); // check if have rename to entry in map
bool is_files_map_empty () const { return m_files_map.empty(); }
bool has_files_to_rename () const;
void clear_files_map ();
// remove strings
void add_string_to_remove(const QString& rem_str) { m_strings_to_remove.push_back(rem_str); }
const QString& get_string_to_remove_at (int idx) const { return m_strings_to_remove.at(idx); }
int count_strings_to_remove() const { return m_strings_to_remove.count(); }
void clear_strings_to_remove () { m_strings_to_remove.clear(); }
std::wstring remove_strings_from_text (const std::wstring& text);
// renames one file
bool rename_one ( const std::wstring& folder,
const std::wstring& src_file,
const std::wstring& dst_file,
bool update_map_entry = false) const;
// renames all files from the map
void rename_all (const std::wstring& path) const;
// observer utils
void add_observer (MPSEngineObserver* obs) { m_observers.push_back(obs); }
void clear_observers () { m_observers.clear(); }
// from MPSEngineBase
virtual void update (MPSToken* token);
virtual bool is_token_current_root (const MPSToken* token) const;
private: // methods
// (re)constructs the rename to name for the current root token
std::wstring reconstruct_output (MPSToken* token);
// in the engine base this method is public, making it private here is intended
void change_case (MPSToken* token, bool upcase, bool only_first, bool recursive);
void update_token (MPSToken*& token,
const std::wstring& text,
const std::wstring& separators,
bool discard,
bool force_update);
private:
// the renaming list
MPSFilesToRenameMap m_files_map;
// the next members are stored for convenience, they will always be filled in from the new / selected root token
MPSToken* m_master_token; // points to current root token from files map
std::wstring m_rename_to;
// strings to remove
QVector<QString> m_strings_to_remove;
// currently selected subtoken in the current root token
MPSToken* m_selected_subtoken;
// engine settings
std::wstring m_default_separators;
bool m_always_lowcase_extension;
// state observers
std::vector<MPSEngineObserver*> m_observers;
};
#endif // MPSENGINE_HPP