Subversion Repositories svn1

Rev

Rev 176 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
103 - 1
#include "qmconfwinners.h"
174 - 2
#include "qmconfig.h"
103 - 3
#include "ui_qmconfwinners.h"
181 - 4
#include "mainwindow.h"
103 - 5
 
104 - 6
#include    "consts.h"
7
#include    "structs.h"
8
#include    "proto.h"
9
 
10
#include "QTableWidgetItem"
11
 
103 - 12
QmConfWinners::QmConfWinners(QWidget *parent) :
13
    QWidget(parent),
14
    ui(new Ui::QmConfWinners)
15
{
16
    ui->setupUi(this);
104 - 17
 
18
    ui->tableWidget->setRowCount(MAX_FAME);
181 - 19
    dirty = true;
20
    populating = false;
21
 
22
    connect(ui->pushButtonSave, SIGNAL(clicked()), this, SLOT(save()) );
23
    connect(ui->pushButtonRestore, SIGNAL(clicked()), this, SLOT(cancel()) );
24
    connect(ui->tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(changed()));
25
 
104 - 26
    populate();
103 - 27
}
28
 
29
QmConfWinners::~QmConfWinners()
30
{
31
    delete ui;
32
}
33
 
104 - 34
void QmConfWinners::populate(void)
35
{
181 - 36
    populating = true;
104 - 37
    for ( int ii = 0; ii < MAX_FAME; ii++)
38
    {
39
        ui->tableWidget->setItem(ii, 0, new QTableWidgetItem(config.hall_fame[ii] ));
40
    }
181 - 41
    populating = false;
42
    updateChanged(false);
104 - 43
}
44
 
45
void QmConfWinners::save(void)
46
{
47
    /*
48
    **    Copy original data
49
    */
176 - 50
     QmConfig newcfg(config);
104 - 51
 
52
    /*
53
    **  Extract the data from the Widgets
54
    */
55
    for ( int ii = 0; ii < MAX_FAME; ii++)
56
    {
57
        QTableWidgetItem *item = ui->tableWidget->item ( ii, 0 );
58
        if ( item )
59
        {
60
            strncpy(newcfg.hall_fame[ii], qPrintable(item->text()), sizeof(newcfg.hall_fame[ii])-1);
61
        }
62
    }
63
 
64
    newcfg.num_fame = 0;
65
    for( int i = 0; i < MAX_FAME; i++ )
66
        if( newcfg.hall_fame[i][0] )
67
            newcfg.num_fame++;
68
 
181 - 69
    // Sanity Check
70
    try
104 - 71
    {
181 - 72
        MainWindow::showMessage( "Saving Config");
73
        for( int i = newcfg.num_fame; i < MAX_FAME; i++ )
74
            if( newcfg.hall_fame[i][0] )
75
            {
76
                throw ( "Configuration error: Missing Fame name. Gaps not allowed" );
77
            }
78
 
104 - 79
        config = newcfg;
176 - 80
        config.write_config();
181 - 81
        updateChanged(false);
104 - 82
    }
181 - 83
    catch ( const char * str)
84
    {
85
        MainWindow::showMessage(str);
86
    }
87
 
104 - 88
}
89
 
90
void QmConfWinners::cancel(void)
91
{
92
    populate();
93
}
181 - 94
 
95
void QmConfWinners::changed(void)
96
{
97
    if ( populating )
98
        return;
99
    updateChanged(true);
100
}
101
 
102
void QmConfWinners::updateChanged(bool newDirty)
103
{
104
    if (newDirty != dirty)
105
    {
106
        dirty = newDirty;
107
        if (dirty)
108
        {
109
            ui->Changed->setVisible(true);
110
            ui->pushButtonSave->setEnabled(true);
111
        }
112
        else
113
        {
114
            ui->Changed->setVisible(false);
115
            ui->pushButtonSave->setEnabled(false);
116
        }
117
    }
118
}
119
 
103 - 120
void QmConfWinners::changeEvent(QEvent *e)
121
{
122
    QWidget::changeEvent(e);
123
    switch (e->type()) {
124
    case QEvent::LanguageChange:
125
        ui->retranslateUi(this);
126
        break;
127
    default:
128
        break;
129
    }
130
}