QTfrontend/ui/page/pageplayrecord.cpp
author sheepluva
Mon, 05 Aug 2019 00:20:45 +0200
changeset 15295 f382ec6dba11
parent 14836 b9437746bffb
permissions -rw-r--r--
In hindsight my emscripten-ifdef (70d416a8f63f) is nonsense. As fpcrtl_glShaderSource() would not be defined and lead to compiling issues. So either it's 3 ifdefs (in pas2cRedo, pas2cSystem and misc.c), in order to toggle between fpcrtl_ and the native function, or alternatively have no ifdef for it at all. I'm going with none at all, which means emscripten will compile with the original (const) function prototype, being wrapped by the fpcrtl_ function, same as non-emscripten builds.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 720
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     4
 *
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     8
 *
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    13
 *
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    17
 */
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    18
7000
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
    19
#include "pageplayrecord.h"
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
    20
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    21
#include <QFont>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    22
#include <QGridLayout>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    23
#include <QPushButton>
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    24
#include <QListWidget>
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
    25
#include <QListWidgetItem>
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
    26
#include <QFileInfo>
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
    27
#include <QMessageBox>
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
    28
#include <QInputDialog>
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    29
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    30
#include "hwconsts.h"
7000
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
    31
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
    32
#include "DataManager.h"
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    33
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    34
QLayout * PagePlayDemo::bodyLayoutDefinition()
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    35
{
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    36
    QGridLayout * pageLayout = new QGridLayout();
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
    37
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    38
    pageLayout->setColumnStretch(0, 1);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    39
    pageLayout->setColumnStretch(1, 2);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    40
    pageLayout->setColumnStretch(2, 1);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    41
    pageLayout->setRowStretch(2, 100);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    42
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    43
    BtnRenameRecord = new QPushButton(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    44
    BtnRenameRecord->setText(QPushButton::tr("Rename"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    45
    pageLayout->addWidget(BtnRenameRecord, 0, 2);
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
    46
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    47
    BtnRemoveRecord = new QPushButton(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    48
    BtnRemoveRecord->setText(QPushButton::tr("Delete"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    49
    pageLayout->addWidget(BtnRemoveRecord, 1, 2);
720
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
    50
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    51
    DemosList = new QListWidget(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    52
    DemosList->setGeometry(QRect(170, 10, 311, 311));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    53
    pageLayout->addWidget(DemosList, 0, 1, 3, 1);
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
    54
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    55
    return pageLayout;
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    56
}
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    57
11819
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    58
QLayout * PagePlayDemo::footerLayoutDefinition()
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    59
{
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    60
    QHBoxLayout * bottomLayout = new QHBoxLayout();
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    61
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    62
    BtnPlayDemo = addButton(tr("Play demo"), bottomLayout, 0, false, Qt::AlignBottom);
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    63
    const QIcon& lp = QIcon(":/res/Start.png");
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    64
    QSize sz = lp.actualSize(QSize(65535, 65535));
12236
a0ed4caa6d35 Apply minimal padding to all text buttons in frontend
Wuzzy <almikes@aol.com>
parents: 11819
diff changeset
    65
    BtnPlayDemo->setStyleSheet("padding: 5px 10px");
11819
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    66
    BtnPlayDemo->setIcon(lp);
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    67
    BtnPlayDemo->setFixedHeight(50);
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    68
    BtnPlayDemo->setIconSize(sz);
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    69
    BtnPlayDemo->setFlat(true);
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    70
    BtnPlayDemo->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    71
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    72
    return bottomLayout;
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    73
}
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    74
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    75
void PagePlayDemo::connectSignals()
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    76
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    77
    connect(BtnRenameRecord, SIGNAL(clicked()), this, SLOT(renameRecord()));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    78
    connect(BtnRemoveRecord, SIGNAL(clicked()), this, SLOT(removeRecord()));
7000
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
    79
    connect(&DataManager::instance(), SIGNAL(updated()), this, SLOT(refresh()));
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    80
}
6009
14f6fc9869f2 code cleanup/etc
sheepluva
parents: 5865
diff changeset
    81
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    82
PagePlayDemo::PagePlayDemo(QWidget* parent) : AbstractPage(parent)
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    83
{
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    84
    initPage();
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    85
}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    86
581
909141b17f68 Better 'Load' page
unc0rr
parents: 580
diff changeset
    87
void PagePlayDemo::FillFromDir(RecordType rectype)
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    88
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    89
    QDir dir;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    90
    QString extension;
581
909141b17f68 Better 'Load' page
unc0rr
parents: 580
diff changeset
    91
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    92
    recType = rectype;
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
    93
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    94
    dir.cd(cfgdir->absolutePath());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    95
    if (rectype == RT_Demo)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    96
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    97
        dir.cd("Demos");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    98
        extension = "hwd";
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    99
        BtnPlayDemo->setText(QPushButton::tr("Play demo"));
11819
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   100
        BtnPlayDemo->setWhatsThis(tr("Play the selected demo"));
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   101
    }
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   102
    else
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   103
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   104
        dir.cd("Saves");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   105
        extension = "hws";
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   106
        BtnPlayDemo->setText(QPushButton::tr("Load"));
11819
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   107
        BtnPlayDemo->setWhatsThis(tr("Load the selected game"));
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   108
    }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   109
    dir.setFilter(QDir::Files);
580
d3ebf84e9fad Working 'Load' page
unc0rr
parents: 579
diff changeset
   110
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   111
    QStringList sl = dir.entryList(QStringList(QString("*.%2.%1").arg(extension, *cProtoVer)));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   112
    sl.replaceInStrings(QRegExp(QString("^(.*)\\.%2\\.%1$").arg(extension, *cProtoVer)), "\\1");
580
d3ebf84e9fad Working 'Load' page
unc0rr
parents: 579
diff changeset
   113
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   114
    DemosList->clear();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   115
    DemosList->addItems(sl);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   116
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   117
    for (int i = 0; i < DemosList->count(); ++i)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   118
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   119
        DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%3.%2").arg(sl[i], extension, *cProtoVer)));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   120
        DemosList->item(i)->setIcon(recType == RT_Demo ? QIcon(":/res/file_demo.png") : QIcon(":/res/file_save.png"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   121
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   122
}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   123
7000
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   124
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   125
void PagePlayDemo::refresh()
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   126
{
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 7000
diff changeset
   127
    if (this->isVisible())
7000
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   128
        FillFromDir(recType);
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   129
}
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   130
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   131
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   132
void PagePlayDemo::renameRecord()
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   133
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   134
    QListWidgetItem * curritem = DemosList->currentItem();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   135
    if (!curritem)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   136
    {
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   137
        QMessageBox recordMsg(this);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   138
        recordMsg.setIcon(QMessageBox::Warning);
12473
faed28f815c7 Simplify error messages in record play page and fix poor grammar.
Wuzzy <almikes@aol.com>
parents: 12471
diff changeset
   139
        recordMsg.setWindowTitle(QMessageBox::tr("Error"));
faed28f815c7 Simplify error messages in record play page and fix poor grammar.
Wuzzy <almikes@aol.com>
parents: 12471
diff changeset
   140
        recordMsg.setText(QMessageBox::tr("Please select a file from the list."));
14836
b9437746bffb Frontend: Force plain text mode for many message windows
Wuzzy <Wuzzy2@mail.ru>
parents: 12473
diff changeset
   141
        recordMsg.setTextFormat(Qt::PlainText);
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   142
        recordMsg.setWindowModality(Qt::WindowModal);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   143
        recordMsg.exec();
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   144
        return ;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   145
    }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   146
    QFile rfile(curritem->data(Qt::UserRole).toString());
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   147
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   148
    QFileInfo finfo(rfile);
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   149
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   150
    bool ok;
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   151
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   152
    QString newname = QInputDialog::getText(this, tr("Rename dialog"), tr("Enter new file name:"), QLineEdit::Normal, finfo.completeBaseName().replace("." + *cProtoVer, ""), &ok);
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   153
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   154
    if(ok && newname.size())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   155
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   156
        QString newfullname = QString("%1/%2.%3.%4")
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   157
                              .arg(finfo.absolutePath())
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   158
                              .arg(newname)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   159
                              .arg(*cProtoVer)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   160
                              .arg(finfo.suffix());
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   161
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   162
        ok = rfile.rename(newfullname);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   163
        if(!ok)
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   164
        {
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   165
            QMessageBox renameMsg(this);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   166
            renameMsg.setIcon(QMessageBox::Warning);
12473
faed28f815c7 Simplify error messages in record play page and fix poor grammar.
Wuzzy <almikes@aol.com>
parents: 12471
diff changeset
   167
            renameMsg.setWindowTitle(QMessageBox::tr("Error"));
faed28f815c7 Simplify error messages in record play page and fix poor grammar.
Wuzzy <almikes@aol.com>
parents: 12471
diff changeset
   168
            renameMsg.setText(QMessageBox::tr("Cannot rename file to %1.").arg(newfullname));
14836
b9437746bffb Frontend: Force plain text mode for many message windows
Wuzzy <Wuzzy2@mail.ru>
parents: 12473
diff changeset
   169
            renameMsg.setTextFormat(Qt::PlainText);
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   170
            renameMsg.setWindowModality(Qt::WindowModal);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   171
            renameMsg.exec();
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   172
        }
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   173
        else
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   174
            FillFromDir(recType);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   175
    }
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   176
}
720
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   177
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   178
void PagePlayDemo::removeRecord()
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   179
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   180
    QListWidgetItem * curritem = DemosList->currentItem();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   181
    if (!curritem)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   182
    {
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   183
        QMessageBox recordMsg(this);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   184
        recordMsg.setIcon(QMessageBox::Warning);
12473
faed28f815c7 Simplify error messages in record play page and fix poor grammar.
Wuzzy <almikes@aol.com>
parents: 12471
diff changeset
   185
        recordMsg.setWindowTitle(QMessageBox::tr("Error"));
faed28f815c7 Simplify error messages in record play page and fix poor grammar.
Wuzzy <almikes@aol.com>
parents: 12471
diff changeset
   186
        recordMsg.setText(QMessageBox::tr("Please select a file from the list."));
14836
b9437746bffb Frontend: Force plain text mode for many message windows
Wuzzy <Wuzzy2@mail.ru>
parents: 12473
diff changeset
   187
        recordMsg.setTextFormat(Qt::PlainText);
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   188
        recordMsg.setWindowModality(Qt::WindowModal);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   189
        recordMsg.exec();
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   190
        return ;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   191
    }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   192
    QFile rfile(curritem->data(Qt::UserRole).toString());
720
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   193
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   194
    bool ok;
720
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   195
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   196
    ok = rfile.remove();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   197
    if(!ok)
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   198
    {
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   199
        QMessageBox removeMsg(this);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   200
        removeMsg.setIcon(QMessageBox::Warning);
12473
faed28f815c7 Simplify error messages in record play page and fix poor grammar.
Wuzzy <almikes@aol.com>
parents: 12471
diff changeset
   201
        removeMsg.setWindowTitle(QMessageBox::tr("Error"));
faed28f815c7 Simplify error messages in record play page and fix poor grammar.
Wuzzy <almikes@aol.com>
parents: 12471
diff changeset
   202
        removeMsg.setText(QMessageBox::tr("Cannot delete file %1.").arg(rfile.fileName()));
14836
b9437746bffb Frontend: Force plain text mode for many message windows
Wuzzy <Wuzzy2@mail.ru>
parents: 12473
diff changeset
   203
        removeMsg.setTextFormat(Qt::PlainText);
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   204
        removeMsg.setWindowModality(Qt::WindowModal);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   205
        removeMsg.exec();
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7382
diff changeset
   206
    }
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   207
    else
7382
b158940f83e2 When removing a record, set selection on the next item in the list
unc0rr
parents: 7130
diff changeset
   208
    {
b158940f83e2 When removing a record, set selection on the next item in the list
unc0rr
parents: 7130
diff changeset
   209
        int i = DemosList->row(curritem);
b158940f83e2 When removing a record, set selection on the next item in the list
unc0rr
parents: 7130
diff changeset
   210
        delete curritem;
b158940f83e2 When removing a record, set selection on the next item in the list
unc0rr
parents: 7130
diff changeset
   211
        DemosList->setCurrentRow(i < DemosList->count() ? i : DemosList->count() - 1);
b158940f83e2 When removing a record, set selection on the next item in the list
unc0rr
parents: 7130
diff changeset
   212
    }
720
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   213
}
5865
35387d27f73a Save demo when loaded from save game finishes
unc0rr
parents: 5205
diff changeset
   214
35387d27f73a Save demo when loaded from save game finishes
unc0rr
parents: 5205
diff changeset
   215
bool PagePlayDemo::isSave()
35387d27f73a Save demo when loaded from save game finishes
unc0rr
parents: 5205
diff changeset
   216
{
35387d27f73a Save demo when loaded from save game finishes
unc0rr
parents: 5205
diff changeset
   217
    return recType == RT_Save;
35387d27f73a Save demo when loaded from save game finishes
unc0rr
parents: 5205
diff changeset
   218
}