41
41
CommandLineClient::~CommandLineClient() = default;
43
void CommandLineClient::run_list_sections(bool remote)
43
void CommandLineClient::run_list_sections(bool remote, QString const & storage)
45
QMap<QString, QVariantMap> choices_values;
45
keeper::Items choices_values;
48
choices_values = keeper_client_->getBackupChoices();
49
choices_values = keeper_client_->getBackupChoices(error);
50
check_for_choices_error(error);
49
51
list_backup_sections(choices_values);
53
choices_values = keeper_client_->getRestoreChoices();
55
choices_values = keeper_client_->getRestoreChoices(storage, error);
56
check_for_choices_error(error);
54
57
list_restore_sections(choices_values);
58
void CommandLineClient::run_backup(QStringList & sections)
61
void CommandLineClient::run_list_storage_accounts()
63
list_storage_accounts(keeper_client_->getStorageAccounts());
66
void CommandLineClient::run_backup(QStringList & sections, QString const & storage)
60
68
auto unhandled_sections = sections;
61
auto choices_values = keeper_client_->getBackupChoices();
70
auto choices_values = keeper_client_->getBackupChoices(error);
71
check_for_choices_error(error);
63
for(auto iter = choices_values.begin(); iter != choices_values.end() && unhandled_sections.size(); ++iter)
74
auto uuids_choices = choices_values.get_uuids();
75
for(auto iter = uuids_choices.begin(); iter != uuids_choices.end() && unhandled_sections.size(); ++iter)
65
const auto& values = iter.value();
66
auto iter_values = values.find("type");
67
if (iter_values != values.end())
77
const auto& values = choices_values[(*iter)];
79
if (values.is_valid() && values.get_type() == keeper::Item::FOLDER_VALUE)
69
if (iter_values.value() == "folder")
82
auto display_name = values.get_display_name();
83
auto index = unhandled_sections.indexOf(display_name);
71
auto iter_display_name = values.find("display-name");
72
if (iter_display_name != values.end())
74
auto index = unhandled_sections.indexOf((*iter_display_name).toString());
77
// we have to backup this section
79
unhandled_sections.removeAt(index);
80
view_->add_task((*iter_display_name).toString(), "waiting", 0.0);
86
// we have to backup this section
88
unhandled_sections.removeAt(index);
89
view_->add_task(display_name, "waiting", 0.0);
100
107
keeper_client_->enableBackup(uuid, true);
102
keeper_client_->startBackup();
109
keeper_client_->startBackup(storage);
103
110
view_->start_printing_tasks();
106
void CommandLineClient::run_restore(QStringList & sections)
113
void CommandLineClient::run_restore(QStringList & sections, QString const & storage)
108
115
auto unhandled_sections = sections;
109
auto choices_values = keeper_client_->getRestoreChoices();
118
auto choices_values = keeper_client_->getRestoreChoices(storage, error);
119
check_for_choices_error(error);
110
120
QStringList uuids;
111
for(auto iter = choices_values.begin(); iter != choices_values.end(); ++iter)
122
auto uuids_choices = choices_values.get_uuids();
123
for(auto iter = uuids_choices.begin(); iter != uuids_choices.end(); ++iter)
113
const auto& values = iter.value();
125
const auto& values = choices_values[(*iter)];
115
QVariant choice_value;
116
auto has_type = find_choice_value(values, "type", choice_value);
117
if (has_type && choice_value == "folder")
127
if (values.is_valid() && values.get_type() == keeper::Item::FOLDER_VALUE)
119
QVariant display_name;
120
auto has_display_name = find_choice_value(values, "display-name", display_name);
121
if (!has_display_name)
125
auto has_dir_name = find_choice_value(values, "dir-name", dir_name);
129
auto section_name = QStringLiteral("%1:%2").arg(display_name.toString()).arg(dir_name.toString());
129
auto display_name = values.get_display_name();
130
auto dir_name = values.get_dir_name();
132
auto section_name = QStringLiteral("%1:%2").arg(display_name).arg(dir_name);
130
133
auto index = unhandled_sections.indexOf(section_name);
133
136
// we have to restore this section
135
138
unhandled_sections.removeAt(index);
136
view_->add_task(display_name.toString(), "waiting", 0.0);
139
view_->add_task(display_name, "waiting", 0.0);
153
156
keeper_client_->enableRestore(uuid, true);
155
keeper_client_->startRestore();
158
keeper_client_->startRestore(storage);
156
159
view_->start_printing_tasks();
159
void CommandLineClient::list_backup_sections(QMap<QString, QVariantMap> const & choices_values)
162
void CommandLineClient::run_cancel() const
164
keeper_client_->cancel();
167
void CommandLineClient::list_backup_sections(keeper::Items const & choices_values)
161
169
QStringList sections;
162
170
for(auto iter = choices_values.begin(); iter != choices_values.end(); ++iter)
164
const auto& values = iter.value();
166
QVariant choice_value;
167
auto has_type = find_choice_value(values, "type", choice_value);
168
if (has_type && choice_value == "folder")
170
auto has_display_name = find_choice_value(values, "display-name", choice_value);
171
if (has_display_name)
172
if ((*iter).is_valid() && (*iter).get_type() == keeper::Item::FOLDER_VALUE)
174
sections << (*iter).get_display_name();
177
view_->print_sections(sections);
180
void CommandLineClient::list_restore_sections(keeper::Items const & choices_values)
182
QMap<QString, QList<keeper::Item>> values_per_dir;
184
for(auto iter = choices_values.begin(); iter != choices_values.end(); ++iter)
186
if ((*iter).is_valid() && (*iter).get_type() == keeper::Item::FOLDER_VALUE)
188
auto dir_name = (*iter).get_dir_name();
189
if (!dir_name.isEmpty())
173
sections << choice_value.toString();
191
values_per_dir[dir_name].push_back((*iter));
177
view_->print_sections(sections);
180
void CommandLineClient::list_restore_sections(QMap<QString, QVariantMap> const & choices_values)
182
QMap<QString, QList<QVariantMap>> values_per_dir;
184
for(auto iter = choices_values.begin(); iter != choices_values.end(); ++iter)
186
const auto& values = iter.value();
188
QVariant choice_value;
189
auto has_type = find_choice_value(values, "type", choice_value);
190
if (has_type && choice_value == "folder")
192
auto has_dir_name = find_choice_value(values, "dir-name", choice_value);
195
values_per_dir[choice_value.toString()].push_back(values);
199
196
QStringList sections;
200
197
for(auto iter = values_per_dir.begin(); iter != values_per_dir.end(); ++iter)
202
199
for(auto iter_items = (*iter).begin(); iter_items != (*iter).end(); ++iter_items)
204
201
const auto& values = (*iter_items);
206
QVariant choice_value;
207
auto has_type = find_choice_value(values, "type", choice_value);
208
if (has_type && choice_value == "folder")
210
auto has_display_name = find_choice_value(values, "display-name", choice_value);
211
if (has_display_name)
213
sections << QStringLiteral("%1:%2").arg(choice_value.toString()).arg(iter.key());
202
sections << QStringLiteral("%1:%2").arg(values.get_display_name()).arg(iter.key());
219
206
view_->print_sections(sections);
209
void CommandLineClient::list_storage_accounts(QStringList const & accounts)
211
view_->print_sections(accounts);
222
214
void CommandLineClient::on_progress_changed()
224
216
view_->progress_changed(keeper_client_->progress());