~ubuntu-branches/ubuntu/saucy/goldencheetah/saucy

« back to all changes in this revision

Viewing changes to src/SaveDialogs.cpp

  • Committer: Package Import Robot
  • Author(s): KURASHIKI Satoru
  • Date: 2013-08-18 07:02:45 UTC
  • mfrom: (4.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130818070245-zgdvb47e1k3mtgil
Tags: 3.0-3
debian/control: remove needless dependency. (Closes: #719571)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
#include "MainWindow.h"
19
19
#include "GcRideFile.h"
 
20
#include "JsonRideFile.h"
20
21
#include "RideItem.h"
21
22
#include "RideFile.h"
22
23
#include "RideFileCommand.h"
31
32
{
32
33
    bool setting;
33
34
 
34
 
    boost::shared_ptr<QSettings> settings = GetApplicationSettings();
35
 
    QVariant warnsetting = settings->value(GC_WARNCONVERT);
 
35
    QVariant warnsetting = appsettings->value(NULL, GC_WARNCONVERT);
36
36
    if (warnsetting.isNull()) setting = true;
37
37
    else setting = warnsetting.toBool();
38
38
    return setting;
41
41
void
42
42
setWarnOnConvert(bool setting)
43
43
{
44
 
    boost::shared_ptr<QSettings> settings = GetApplicationSettings();
45
 
    settings->setValue(GC_WARNCONVERT, setting);
 
44
    appsettings->setValue(GC_WARNCONVERT, setting);
46
45
}
47
46
 
48
47
static bool
49
48
warnExit()
50
49
{
51
 
    bool setting;
52
 
 
53
 
    boost::shared_ptr<QSettings> settings = GetApplicationSettings();
54
 
    QVariant warnsetting = settings->value(GC_WARNEXIT);
55
 
    if (warnsetting.isNull()) setting = true;
56
 
    else setting = warnsetting.toBool();
57
 
    return setting;
 
50
    return appsettings->value(NULL, GC_WARNEXIT, true).toBool();
58
51
}
59
52
 
60
53
void
61
54
setWarnExit(bool setting)
62
55
{
63
 
    boost::shared_ptr<QSettings> settings = GetApplicationSettings();
64
 
    settings->setValue(GC_WARNEXIT, setting);
 
56
    appsettings->setValue(GC_WARNEXIT, setting);
65
57
}
66
58
 
67
59
//----------------------------------------------------------------------
129
121
    bool    convert;
130
122
 
131
123
    // Do we need to convert the file type?
132
 
    if (currentType != "GC") convert = true;
 
124
    if (currentType != "JSON") convert = true;
133
125
    else convert = false;
134
126
 
135
127
    // Has the date/time changed?
143
135
                               .arg ( ridedatetime.time().minute(), 2, 10, zero )
144
136
                               .arg ( ridedatetime.time().second(), 2, 10, zero );
145
137
 
 
138
    // if there is a notes file we need to rename it (cpi we will ignore)
 
139
    QFile notesFile(currentFI.path() + QDir::separator() + currentFI.baseName() + ".notes");
 
140
    if (notesFile.exists()) notesFile.remove();
 
141
 
146
142
    // When datetime changes we need to update
147
143
    // the filename & rename/delete old file
148
144
    // we also need to preserve the notes file
149
145
    if (currentFI.baseName() != targetnosuffix) {
150
146
 
151
 
        // if there is a notes file we need to rename it (cpi we will ignore)
152
 
        QFile notesFile(currentFI.path() + QDir::separator() + currentFI.baseName() + ".notes");
153
 
 
154
 
        if (notesFile.exists())
155
 
            notesFile.rename(notesFile.fileName(),
156
 
                             rideItem->path + QDir::separator() + targetnosuffix + ".notes");
157
 
 
158
 
        // we also need to update the path to the notes filename
159
 
        ride->notesFileName = targetnosuffix + ".notes";
160
 
 
161
147
        // rename as backup current if converting, or just delete it if its already .gc
162
 
        // delete old .bak file if it is there
 
148
        // unlink previous .bak if it is already there
163
149
        if (convert) {
164
 
            QFile::remove(currentFile.fileName() + ".bak");
 
150
            QFile::remove(currentFile.fileName()+".bak"); // ignore errors if not there
165
151
            currentFile.rename(currentFile.fileName(), currentFile.fileName() + ".bak");
166
152
        } else currentFile.remove();
167
153
        convert = false; // we just did it already!
168
154
 
169
155
        // set the new filename & Start time everywhere
170
 
        currentFile.setFileName(rideItem->path + QDir::separator() + targetnosuffix + ".gc");
 
156
        currentFile.setFileName(rideItem->path + QDir::separator() + targetnosuffix + ".json");
171
157
        rideItem->setFileName(QFileInfo(currentFile).path(), QFileInfo(currentFile).fileName());
172
158
    }
173
159
 
174
160
    // set target filename
175
161
    if (convert) {
176
162
        // rename the source
177
 
        savedFile.setFileName(currentFI.path() + QDir::separator() + currentFI.baseName() + ".gc");
 
163
        savedFile.setFileName(currentFI.path() + QDir::separator() + currentFI.baseName() + ".json");
178
164
    } else {
179
165
        savedFile.setFileName(currentFile.fileName());
180
166
    }
187
173
    rideItem->ride()->setTag("Change History", log);
188
174
 
189
175
    // save in GC format
190
 
    GcFileReader reader;
191
 
    reader.writeRideFile(rideItem->ride(), savedFile);
 
176
    JsonFileReader reader;
 
177
    reader.writeRideFile(this, rideItem->ride(), savedFile);
192
178
 
193
179
    // rename the file and update the rideItem list to reflect the change
194
180
    if (convert) {
195
181
 
196
 
        // rename on disk and delete old .bak if it is there
197
 
        QFile::remove(currentFile.fileName() + ".bak");
 
182
        // rename on disk
 
183
        QFile::remove(currentFile.fileName()+".bak"); // ignore errors if not there
198
184
        currentFile.rename(currentFile.fileName(), currentFile.fileName() + ".bak");
199
185
 
200
186
        // rename in memory
201
187
        rideItem->setFileName(QFileInfo(savedFile).path(), QFileInfo(savedFile).fileName());
202
188
    }
203
189
 
 
190
 
204
191
    // mark clean as we have now saved the data
205
192
    rideItem->ride()->emitSaved();
206
193
}
333
320
{
334
321
    // whizz through the list and save one by one using
335
322
    // singleSave to ensure warnings are given if neccessary
 
323
    // use mainWindow->ismultisave to prevent refreshing stats
 
324
    // for each file
 
325
    mainWindow->ismultisave = true;
336
326
    for (int i=0; i<dirtyList.count(); i++) {
337
327
        QCheckBox *c = (QCheckBox *)dirtyFiles->cellWidget(i,0);
338
328
        if (c->isChecked()) {
 
329
            if (i==dirtyList.count()-1) {
 
330
                mainWindow->ismultisave = false;
 
331
            }
339
332
            mainWindow->saveRideSingleDialog(dirtyList.at(i));
340
333
        }
341
334
    }
 
335
 
 
336
    mainWindow->ismultisave = false;
342
337
    accept();
343
338
}
344
339