QTfrontend/ui/page/pageplayrecord.cpp
author unc0rr
Sun, 27 May 2012 23:42:43 +0400
changeset 7130 fcab1fd02bc6
parent 7000 d22633829ac8
child 7382 b158940f83e2
permissions -rw-r--r--
- Allow switching colors with mouse wheel - Use indices instead of color values - Introduce a model for colors - Some small fixes, .pro can be used to build again - Yay, tested it to work via network (and fixed a bug!) (TODO: pass colors to engine by index)
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
6952
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6700
diff changeset
     3
 * Copyright (c) 2004-2012 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
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
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
    BtnPlayDemo = new QPushButton(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    44
    BtnPlayDemo->setFont(*font14);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    45
    BtnPlayDemo->setText(QPushButton::tr("Play demo"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    46
    pageLayout->addWidget(BtnPlayDemo, 3, 2);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    47
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    48
    BtnRenameRecord = new QPushButton(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    49
    BtnRenameRecord->setText(QPushButton::tr("Rename"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    50
    pageLayout->addWidget(BtnRenameRecord, 0, 2);
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
    51
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    52
    BtnRemoveRecord = new QPushButton(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    53
    BtnRemoveRecord->setText(QPushButton::tr("Delete"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    54
    pageLayout->addWidget(BtnRemoveRecord, 1, 2);
720
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
    55
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    56
    DemosList = new QListWidget(this);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    57
    DemosList->setGeometry(QRect(170, 10, 311, 311));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    58
    pageLayout->addWidget(DemosList, 0, 1, 3, 1);
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
    59
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
    60
    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
    61
}
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
    62
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
    63
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
    64
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    65
    connect(BtnRenameRecord, SIGNAL(clicked()), this, SLOT(renameRecord()));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    66
    connect(BtnRemoveRecord, SIGNAL(clicked()), this, SLOT(removeRecord()));
7000
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
    67
    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
    68
}
6009
14f6fc9869f2 code cleanup/etc
sheepluva
parents: 5865
diff changeset
    69
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
    70
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
    71
{
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
    72
    initPage();
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    73
}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    74
581
909141b17f68 Better 'Load' page
unc0rr
parents: 580
diff changeset
    75
void PagePlayDemo::FillFromDir(RecordType rectype)
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
    76
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    77
    QDir dir;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    78
    QString extension;
581
909141b17f68 Better 'Load' page
unc0rr
parents: 580
diff changeset
    79
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    80
    recType = rectype;
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
    81
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    82
    dir.cd(cfgdir->absolutePath());
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    83
    if (rectype == RT_Demo)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    84
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    85
        dir.cd("Demos");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    86
        extension = "hwd";
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    87
        BtnPlayDemo->setText(QPushButton::tr("Play demo"));
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
    88
    }
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
    89
    else
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    90
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    91
        dir.cd("Saves");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    92
        extension = "hws";
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    93
        BtnPlayDemo->setText(QPushButton::tr("Load"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    94
    }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    95
    dir.setFilter(QDir::Files);
580
d3ebf84e9fad Working 'Load' page
unc0rr
parents: 579
diff changeset
    96
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
    97
    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
    98
    sl.replaceInStrings(QRegExp(QString("^(.*)\\.%2\\.%1$").arg(extension, *cProtoVer)), "\\1");
580
d3ebf84e9fad Working 'Load' page
unc0rr
parents: 579
diff changeset
    99
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   100
    DemosList->clear();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   101
    DemosList->addItems(sl);
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   102
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   103
    for (int i = 0; i < DemosList->count(); ++i)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   104
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   105
        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
   106
        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
   107
    }
579
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   108
}
94db15de0392 - Some changes to make build process clear
unc0rr
parents:
diff changeset
   109
7000
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   110
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   111
void PagePlayDemo::refresh()
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   112
{
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 7000
diff changeset
   113
    if (this->isVisible())
7000
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   114
        FillFromDir(recType);
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   115
}
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   116
d22633829ac8 allow F5 magic to refresh demos/saves list too
sheepluva
parents: 6952
diff changeset
   117
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   118
void PagePlayDemo::renameRecord()
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   119
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   120
    QListWidgetItem * curritem = DemosList->currentItem();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   121
    if (!curritem)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   122
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   123
        QMessageBox::critical(this,
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   124
                              tr("Error"),
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   125
                              tr("Please select record from the list"),
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   126
                              tr("OK"));
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   127
        return ;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   128
    }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   129
    QFile rfile(curritem->data(Qt::UserRole).toString());
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   130
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   131
    QFileInfo finfo(rfile);
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   132
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   133
    bool ok;
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   134
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   135
    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
   136
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   137
    if(ok && newname.size())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   138
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   139
        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
   140
                              .arg(finfo.absolutePath())
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   141
                              .arg(newname)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   142
                              .arg(*cProtoVer)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   143
                              .arg(finfo.suffix());
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   144
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   145
        ok = rfile.rename(newfullname);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   146
        if(!ok)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   147
            QMessageBox::critical(this, tr("Error"), tr("Cannot rename to") + newfullname);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   148
        else
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   149
            FillFromDir(recType);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   150
    }
627
92e136c3eb46 Button for renaming demo and save files
unc0rr
parents: 603
diff changeset
   151
}
720
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   152
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   153
void PagePlayDemo::removeRecord()
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   154
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   155
    QListWidgetItem * curritem = DemosList->currentItem();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   156
    if (!curritem)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   157
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   158
        QMessageBox::critical(this,
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   159
                              tr("Error"),
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   160
                              tr("Please select record from the list"),
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6060
diff changeset
   161
                              tr("OK"));
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   162
        return ;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   163
    }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   164
    QFile rfile(curritem->data(Qt::UserRole).toString());
720
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   165
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   166
    bool ok;
720
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   167
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   168
    ok = rfile.remove();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   169
    if(!ok)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   170
        QMessageBox::critical(this, tr("Error"), tr("Cannot delete file"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   171
    else
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2742
diff changeset
   172
        FillFromDir(recType);
720
97a9d67d5c3e - Add 'Delete' button to demos and saves pages
unc0rr
parents: 628
diff changeset
   173
}
5865
35387d27f73a Save demo when loaded from save game finishes
unc0rr
parents: 5205
diff changeset
   174
35387d27f73a Save demo when loaded from save game finishes
unc0rr
parents: 5205
diff changeset
   175
bool PagePlayDemo::isSave()
35387d27f73a Save demo when loaded from save game finishes
unc0rr
parents: 5205
diff changeset
   176
{
35387d27f73a Save demo when loaded from save game finishes
unc0rr
parents: 5205
diff changeset
   177
    return recType == RT_Save;
35387d27f73a Save demo when loaded from save game finishes
unc0rr
parents: 5205
diff changeset
   178
}