18 #include <QFileDialog>
19 #include <QPushButton>
45 if (pterrain->identifier_load == ch) {
57 ui.show_preview->setText(
_(
"Show preview"));
58 ui.load_pix->setProperty(
"themed_border",
true);
59 ui.load_pix->setFixedSize(0, 0);
60 ui.load_save_text->setText(QLatin1String(
""));
61 ui.load_save_text->setTextFormat(Qt::RichText);
62 ui.load_save_text->setWordWrap(
true);
64 ui.saves_load->setRowCount(0);
66 sav <<
_(
"Choose Saved Game to Load") <<
_(
"Date");
67 ui.saves_load->setColumnCount(sav.count());
68 ui.saves_load->setHorizontalHeaderLabels(sav);
69 ui.saves_load->horizontalHeader()->setSectionResizeMode(
70 0, QHeaderView::Stretch);
72 connect(
ui.saves_load->selectionModel(),
73 &QItemSelectionModel::selectionChanged,
this,
75 connect(
ui.show_preview, &QCheckBox::stateChanged,
this,
79 ui.buttons->addButton(
_(
"Browse..."), QDialogButtonBox::ActionRole);
80 browse->setIcon(QIcon::fromTheme(QStringLiteral(
"document-open-folder")));
83 connect(
ui.buttons->button(QDialogButtonBox::Cancel),
86 auto load =
ui.buttons->button(QDialogButtonBox::Ok);
87 load->setText(
_(
"Load"));
88 connect(load, &QAbstractButton::clicked,
this,
102 ui.saves_load->clearContents();
103 ui.saves_load->setRowCount(0);
108 for (
const auto &info : files) {
109 auto item =
new QTableWidgetItem();
110 item->setData(Qt::UserRole, info.absoluteFilePath());
111 ui.saves_load->insertRow(row);
112 item->setText(info.fileName());
113 ui.saves_load->setItem(row, 0,
item);
114 item =
new QTableWidgetItem();
115 item->setData(Qt::DisplayRole, QDateTime(info.lastModified()));
116 ui.saves_load->setItem(row, 1,
item);
120 ui.saves_load->sortByColumn(1, Qt::DescendingOrder);
122 if (!files.isEmpty()) {
123 ui.saves_load->setCurrentCell(0, 0);
138 str = QString(
_(
"Save Files"))
139 + QStringLiteral(
" (*.sav *.sav.bz2 *.sav.gz *.sav.xz *.sav.zst)");
140 current_file = QFileDialog::getOpenFileName(
this,
_(
"Open Save File"),
141 QDir::homePath(), str);
153 ui.show_preview->checkState() != Qt::Unchecked;
154 auto selection =
ui.saves_load->selectionModel()->selection();
155 ui.saves_load->selectionModel()->clearSelection();
156 ui.saves_load->selectionModel()->select(
158 QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
162 const QItemSelection &deselected)
165 QModelIndexList indexes = selected.indexes();
171 const char *terr_name;
176 if (indexes.isEmpty()) {
180 index = indexes.at(0);
181 qvar = index.data(Qt::UserRole);
183 if (
ui.show_preview->checkState() == Qt::Unchecked) {
184 ui.load_pix->setPixmap(*(
new QPixmap));
185 ui.load_save_text->setText(QLatin1String(
""));
190 auto sf = std::unique_ptr<section_file, decltype(&secfile_destroy)>(
199 QString pl_str =
nullptr;
206 final_str = QStringLiteral(
"<b>") +
_(
"Turn") +
":</b> "
207 + QString::number(integer).toHtmlEscaped() +
"<br>";
214 final_str = final_str +
"<b>" +
_(
"Players") +
":</b>" +
" "
215 + QString::number(integer).toHtmlEscaped() +
"<br>";
217 num_players = integer;
219 for (
int i = 0; i < num_players; i++) {
220 pl_str = QStringLiteral(
"player") + QString::number(i);
221 pl_bytes = pl_str.toLocal8Bit();
225 sf.get(),
true,
"player%d.unassigned_user", i))) {
232 if (pl_str ==
nullptr) {
233 ui.load_save_text->setText(final_str);
238 pl_bytes = pl_str.toLocal8Bit();
242 "player%d.nation", curr_player);
244 final_str = final_str +
"<b>" +
_(
"Nation") +
":</b> "
245 + QString(sname).toHtmlEscaped() +
"<br>";
250 final_str = final_str +
"<b>" +
_(
"Cities") +
":</b> "
251 + QString::number(integer).toHtmlEscaped() +
"<br>";
256 final_str = final_str +
"<b>" +
_(
"Units") +
":</b> "
257 + QString::number(integer).toHtmlEscaped() +
"<br>";
262 final_str = final_str +
"<b>" +
_(
"Gold") +
":</b> "
263 + QString::number(integer).toHtmlEscaped() +
"<br>";
268 sf.get(),
nullptr,
"player%d.map_t%04d", curr_player,
nat_y);
269 if (line ==
nullptr) {
272 nat_x = qstrlen(line);
273 str_pixmap = str_pixmap + line;
282 QStringLiteral(
"savefile"),
true));
285 sf.get(),
nullptr,
"savefile.terrident%d.name", ii))
288 if (pterr !=
nullptr) {
290 sf.get(),
nullptr,
"savefile.terrident%d.identifier", ii);
298 QImage
img(
nat_x,
nat_y, QImage::Format_ARGB32_Premultiplied);
300 for (
int a = 0; a <
nat_x; a++) {
301 for (
int b = 0; b <
nat_y; b++) {
308 col.setRgb(rgb->
r, rgb->
g, rgb->
b);
309 img.setPixel(a,
b, col.rgb());
313 if (
img.width() > 1) {
314 ui.load_pix->setPixmap(QPixmap::fromImage(
img).scaledToHeight(200));
316 ui.load_pix->setPixmap(*(
new QPixmap));
318 ui.load_pix->setFixedSize(
ui.load_pix->pixmap().width(),
319 ui.load_pix->pixmap().height());
321 QStringLiteral(
"research"),
true));
324 sf.get(),
nullptr,
"research.r%d.now_name", curr_player);
326 final_str = final_str +
"<b>" +
_(
"Researching") +
":</b> "
327 + QString(sname).toHtmlEscaped();
331 ui.load_save_text->setText(final_str);
333 ui.load_save_text->show();
335 ui.buttons->button(QDialogButtonBox::Ok)->setEnabled(
true);
338 ui.load_save_text->hide();
340 ui.buttons->button(QDialogButtonBox::Ok)->setEnabled(
false);
void slot_disconnect()
Disconnect from server and return to MAIN PAGE.
void start_from_file(const QString &file)
start from save file
void start_from_save()
Starts game from chosen save - chosen_file (save or scenario)
void slot_selection_changed(const QItemSelection &, const QItemSelection &)
void state_preview()
State of preview has been changed.
void browse_saves()
Browse saves directory.
void update_load_page()
Updates saves to load and updates in tableview = saves_load.
page_load(QWidget *, fc_client *)
class fc_client * king()
Return fc_client instance.
#define fc_assert_ret(condition)
client_options * gui_options
static struct terrain * char2terrain(char ch)
Helper function for drawing map of savegames.
void secfile_destroy(struct section_file *secfile)
Free a section file.
struct section_file * secfile_load_section(const QString &filename, const QString §ion, bool allow_duplicates)
Create a section file from a file, read only one particular section.
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
Lookup a boolean value in the secfile.
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
Lookup a string value in the secfile.
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
Lookup a integer value in the secfile.
const QStringList & get_save_dirs()
Returns a list of save directory paths, in the order in which they should be searched.
QFileInfoList find_files_in_path(const QStringList &path, const QString &pattern, bool nodups)
Search for file names matching the pattern in the provided list of directories.
struct terrain * terrain_by_rule_name(const char *name)
Return the terrain type matching the name, or T_UNKNOWN if none matches.
#define terrain_type_iterate(_p)
#define TERRAIN_UNKNOWN_IDENTIFIER
#define terrain_type_iterate_end