~ubuntu-branches/ubuntu/precise/mp3diags/precise

« back to all changes in this revision

Viewing changes to src/MainFormDlgImpl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-09-05 10:48:57 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090905104857-48aob98yoibqarh0
Tags: 0.99.05.033-0ubuntu1
New upstream release (FFe granted LP: #423812).

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    //p->m_pContentM->append(convStr(s));
80
80
    //p->m_pCommonData->m_qstrContent += convStr(s);
81
81
    //p->m_pCommonData->m_qstrContent += "\n";
82
 
    if (0 != p)
 
82
    if (0 != p && 0 != p->m_pCommonData)
83
83
    {
84
 
        p->m_pCommonData->trace(s);
 
84
        p->m_pCommonData->trace(s); //ttt0 if p->m_pCommonData==0 or p==0 use logToGlobalFile()
85
85
    }
86
86
}
87
87
 
95
95
    int s_nStepFile;
96
96
    int s_nCrtStepSize;
97
97
    int s_nPage;
 
98
 
 
99
#ifndef WIN32
 
100
#else
 
101
    HANDLE s_hStepFile (INVALID_HANDLE_VALUE);
 
102
#endif
98
103
}
99
104
 
100
105
 
101
106
 
102
 
void traceToFile(const string& s)
 
107
void traceToFile(const string& s, int nLevelChange)
103
108
{
104
109
    if (!s_bEnableTraceToFile) { return; }
105
110
 
106
111
    static QMutex mutex;
107
112
    QMutexLocker lck (&mutex);
108
113
 
 
114
    static int s_nLevel (0);
 
115
    s_nLevel += nLevelChange;
 
116
    string s1 (s_nLevel, ' ');
 
117
    s1 += s;
 
118
 
109
119
    QTime t (QTime::currentTime());
110
120
    char a [15];
111
 
    sprintf(a, "%02d:%02d:%02d.%03d ", t.hour(), t.minute(), t.second(), t.msec());
 
121
    sprintf(a, "%02d:%02d:%02d.%03d", t.hour(), t.minute(), t.second(), t.msec());
112
122
 
113
123
    ofstream_utf8 out (s_strTraceFile.c_str(), ios_base::app);
114
 
    out << a << s << endl;
115
 
}
116
 
 
117
 
 
118
 
void traceLastStep(const string& s)
 
124
    out << a << s1 << endl;
 
125
}
 
126
 
 
127
 
 
128
 
 
129
#ifndef WIN32
 
130
#else
 
131
void CB_LIB_CALL displayOsErrorIfExists(const char* szTitle)
 
132
{
 
133
    unsigned int nErr (GetLastError());
 
134
    if (0 == nErr) return;
 
135
 
 
136
    LPVOID lpMsgBuf;
 
137
 
 
138
    FormatMessageA(
 
139
        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
 
140
        NULL,
 
141
        nErr,
 
142
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
 
143
        (LPSTR) &lpMsgBuf,
 
144
        0,
 
145
        NULL
 
146
    );
 
147
 
 
148
    string strRes ((LPSTR)lpMsgBuf);
 
149
 
 
150
    // Free the buffer.
 
151
    LocalFree(lpMsgBuf);
 
152
    unsigned int nSize ((unsigned int)strRes.size());
 
153
    if (nSize - 2 == strRes.rfind("\r\n"))
 
154
    {
 
155
        strRes.resize(nSize - 2);
 
156
    }
 
157
 
 
158
    QMessageBox::critical(0, szTitle, convStr(strRes));
 
159
}
 
160
 
 
161
 
 
162
#endif
 
163
 
 
164
 
 
165
 
 
166
 
 
167
void traceLastStep(const string& s, int nLevelChange)
119
168
{
120
169
    if (!s_bEnableTraceToFile) { return; }
121
170
 
122
171
    static QMutex mutex;
123
172
    QMutexLocker lck (&mutex);
124
173
 
125
 
    QTime t (QTime::currentTime());
 
174
    static int s_nLevel (0);
 
175
    s_nLevel += nLevelChange;
 
176
    string s1 (s_nLevel, ' ');
 
177
    //string s1; char b [20]; sprintf(b, "%d", s_nLevel); s1 = b;
 
178
    s1 += s;
 
179
 
126
180
    char a [15];
127
181
    a[0] = 0;
128
 
    //sprintf(a, "%02d:%02d:%02d.%03d ", t.hour(), t.minute(), t.second(), t.msec());
 
182
    //QTime t (QTime::currentTime()); sprintf(a, "%02d:%02d:%02d.%03d ", t.hour(), t.minute(), t.second(), t.msec());
129
183
 
 
184
#ifndef WIN32
130
185
    ofstream_utf8 out (s_vstrStepFile[s_nStepFile].c_str(), ios_base::app);
131
 
    out << a << s << endl;
132
 
 
 
186
    out << a << s1 << endl;
 
187
#else
 
188
    /*FILE* f (fopen(s_vstrStepFile[s_nStepFile].c_str(), "a+"));
 
189
    fwrite(a, strlen(a), 1, f);
 
190
    fwrite(s.c_str(), s.size(), 1, f);
 
191
    fwrite("\n", 1, 1, f);
 
192
    fclose(f);*/
 
193
 
 
194
/*
 
195
    //HANDLE h (CreateFileA(toNativeSeparators(s_vstrStepFile[s_nStepFile]).c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_ALWAYS,
 
196
    HANDLE h (CreateFileA(s_vstrStepFile[s_nStepFile].c_str(), GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_ALWAYS,
 
197
    //HANDLE h (CreateFileA("C:\\Mp3DiagsWindows\\debug\\aaa.txt", GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_ALWAYS,
 
198
    //HANDLE h (CreateFileA("C:\\Mp3DiagsWindows\\debug\\aaa.txt", GENERIC_WRITE, 0, 0, OPEN_ALWAYS,
 
199
                          FILE_ATTRIBUTE_TEMPORARY,
 
200
                          //FILE_ATTRIBUTE_NORMAL,
 
201
                          0));
 
202
    if (INVALID_HANDLE_VALUE == h)
 
203
    {
 
204
        displayOsErrorIfExists();
 
205
    }
 
206
 
 
207
    SetFilePointer(h, 0, 0, FILE_END);
 
208
    DWORD dwWrt;
 
209
    WriteFile(h, a, strlen(a), &dwWrt, 0);
 
210
    WriteFile(h, s.c_str(), s.size(), &dwWrt, 0);
 
211
    WriteFile(h, "\n", 1, &dwWrt, 0);
 
212
    //const char* qq ("abcdefg");
 
213
    //QMessageBox::critical(0, "abc", "before wrt");
 
214
    //WriteFile(h, qq, 4, 0, 0);
 
215
    //QMessageBox::critical(0, "123", "after wrt");
 
216
    CloseHandle(h);
 
217
*/
 
218
 
 
219
/*
133
220
    s_nCrtStepSize += s.size() + 1;
 
221
    if (s_nCrtStepSize > 5000000)
 
222
    {
 
223
        s_nCrtStepSize = 0;
 
224
        s_nStepFile = 1 - s_nStepFile;
 
225
        try
 
226
        {
 
227
            deleteFile(s_vstrStepFile[s_nStepFile]);
 
228
        }
 
229
        catch (...)
 
230
        { //ttt0
 
231
        }
 
232
        //ofstream_utf8 out (s_vstrStepFile[s_nStepFile].c_str(), ios_base::app);
 
233
        //out << "page " << s_nPage++ << endl;
 
234
    }
 
235
*/
 
236
 
 
237
    //HANDLE h (CreateFileA("C:\\Mp3DiagsWindows\\debug\\aaa.txt", GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_ALWAYS,
 
238
    //HANDLE h (CreateFileA("C:\\Mp3DiagsWindows\\debug\\aaa.txt", GENERIC_WRITE, 0, 0, OPEN_ALWAYS,
 
239
    /*static HANDLE h (CreateFileA(s_vstrStepFile[s_nStepFile].c_str(),
 
240
                                 GENERIC_WRITE,
 
241
                                 FILE_SHARE_WRITE | FILE_SHARE_READ,
 
242
                                 0,
 
243
                                 //OPEN_ALWAYS,
 
244
                                 CREATE_ALWAYS,
 
245
                                 FILE_ATTRIBUTE_TEMPORARY,
 
246
                                 //FILE_ATTRIBUTE_NORMAL,
 
247
                                 0));*/
 
248
 
 
249
    DWORD dwWrt;
 
250
    WriteFile(s_hStepFile, a, strlen(a), &dwWrt, 0);
 
251
    WriteFile(s_hStepFile, s1.c_str(), s1.size(), &dwWrt, 0);
 
252
    WriteFile(s_hStepFile, "\r\n", 2, &dwWrt, 0);
 
253
#endif
 
254
 
 
255
    s_nCrtStepSize += s1.size() +
 
256
#ifndef WIN32
 
257
                      1;
 
258
#else
 
259
                      2;
 
260
#endif
 
261
 
134
262
    if (s_nCrtStepSize > 50000)
135
263
    {
136
264
        s_nCrtStepSize = 0;
142
270
        catch (...)
143
271
        { //ttt0
144
272
        }
145
 
        ofstream_utf8 out (s_vstrStepFile[s_nStepFile].c_str(), ios_base::app);
146
 
        out << "page " << s_nPage++ << endl;
 
273
#ifndef WIN32
 
274
#else
 
275
        CloseHandle(s_hStepFile);
 
276
#endif
 
277
        {
 
278
            ofstream_utf8 out (s_vstrStepFile[s_nStepFile].c_str(), ios_base::app);
 
279
            out << "page " << ++s_nPage << endl;
 
280
        }
 
281
 
 
282
#ifndef WIN32
 
283
#else
 
284
        s_hStepFile = CreateFileA(s_vstrStepFile[s_nStepFile].c_str(),
 
285
                         GENERIC_WRITE,
 
286
                         FILE_SHARE_WRITE | FILE_SHARE_READ,
 
287
                         0,
 
288
                         OPEN_ALWAYS,
 
289
                         //CREATE_ALWAYS,
 
290
                         FILE_ATTRIBUTE_TEMPORARY,
 
291
                         //FILE_ATTRIBUTE_NORMAL,
 
292
                         0);
 
293
        if (INVALID_HANDLE_VALUE == s_hStepFile) { displayOsErrorIfExists("Error in traceLastStep()"); }
 
294
        SetFilePointer(s_hStepFile, 0, 0, FILE_END);
 
295
#endif
147
296
    }
148
297
}
 
298
//ttt0 implement abstract "NativeFile"
149
299
 
150
300
 
151
301
void setupTraceToFile(bool bEnable)
156
306
 
157
307
    try
158
308
    {
 
309
#ifndef WIN32
 
310
#else
 
311
        CloseHandle(s_hStepFile);
 
312
        s_hStepFile = INVALID_HANDLE_VALUE;
 
313
#endif
159
314
        deleteFile(s_strTraceFile);
160
315
        deleteFile(s_vstrStepFile[0]);
161
316
        deleteFile(s_vstrStepFile[1]);
166
321
 
167
322
    if (s_bEnableTraceToFile)
168
323
    {
169
 
        traceToFile(convStr(getSystemInfo()));
 
324
#ifndef WIN32
 
325
#else
 
326
        s_hStepFile = CreateFileA(s_vstrStepFile[s_nStepFile].c_str(),
 
327
                         GENERIC_WRITE,
 
328
                         FILE_SHARE_WRITE | FILE_SHARE_READ,
 
329
                         0,
 
330
                         OPEN_ALWAYS,
 
331
                         //CREATE_ALWAYS,
 
332
                         FILE_ATTRIBUTE_TEMPORARY,
 
333
                         //FILE_ATTRIBUTE_NORMAL,
 
334
                         0);
 
335
        if (INVALID_HANDLE_VALUE == s_hStepFile) { displayOsErrorIfExists("Error in setupTraceToFile()"); }
 
336
#endif
 
337
        traceToFile(convStr(getSystemInfo()), 0);
 
338
        traceLastStep(convStr(getSystemInfo()), 0);
170
339
    }
171
340
}
172
341
 
173
 
 
174
 
 
 
342
//ttt0 add checkbox to uninst on wnd to remove data and settings; //ttt0 uninst should remove log file as well
 
343
//ttt0 msvc 2008 fails to compile "cout << strRes << endl;" see if printing strings is GCC extension
175
344
//static QString s_strAssertTitle ("Assertion failure");
176
345
//static QString s_strCrashWarnTitle ("Crash detected");
177
346
static QString s_qstrErrorMsg;
228
397
    /*QString s ("<p/>Please report this issue on the <a href=\"http://sourceforge.net/apps/mantisbt/mp3diags/\">MP3 Diags Issue Tracker</a> (<a href=\"http://sourceforge.net/apps/mantisbt/mp3diags/\">http://sourceforge.net/apps/mantisbt/mp3diags/</a>). Make sure to include the data below, as well as any other detail that seems relevant (what might have caused the failure, steps to reproduce it, ...)<p/><p/><hr/><p/>");*/
229
398
 
230
399
//qDebug("%s", s.toUtf8().data());
231
 
    pContent->setHtml(Qt::escape(s_qstrErrorMsg) /*+ s + Qt::escape(s_qstrErrorMsg)*/ + "<p/><p/>Please restart the application for instructions about how to report this issue");
 
400
    pContent->setHtml(Qt::escape(s_qstrErrorMsg) /*+ s + Qt::escape(s_qstrErrorMsg)*/ + "<p style=\"margin-bottom:1px; margin-top:12px; \">Please restart the application for instructions about how to report this issue</p>");
232
401
    pLayout->addWidget(pContent);
233
402
 
234
403
    QHBoxLayout btnLayout;
260
429
 
261
430
    pContent->setOpenExternalLinks(true);
262
431
 
263
 
    pContent->setHtml(qstrText + "<p/>" + qstrVer);
 
432
    pContent->setHtml(qstrText + "<hr/><p style=\"margin-bottom:1px; margin-top:8px; \">" + qstrVer + "</p>"); //ttt0 perhaps use CSS
264
433
    pLayout->addWidget(pContent);
265
434
 
266
435
    QHBoxLayout btnLayout;
285
454
 
286
455
    s_qstrErrorMsg = QString("Assertion failure in file %1, line %2: %3. The program will exit.").arg(szFile).arg(nLine).arg(szCond);
287
456
    setupTraceToFile(true);
288
 
    traceToFile(convStr(s_qstrErrorMsg));
 
457
    traceToFile(convStr(s_qstrErrorMsg), 0);
289
458
    qDebug("Assertion failure in file %s, line %d: %s", szFile, nLine, szCond);
290
459
 
291
460
    MainFormDlgImpl* p (getGlobalDlg());
319
488
    }
320
489
}
321
490
 
 
491
void logAssert(const char* szFile, int nLine, const char* szCond, const std::string& strAddtlInfo)
 
492
{
 
493
    string s (string(szCond) + "; additional info: " + strAddtlInfo);
 
494
    logAssert(szFile, nLine, s.c_str());
 
495
}
 
496
 
 
497
 
322
498
void MainFormDlgImpl::onShowAssert()
323
499
{
324
500
    /*QMessageBox dlg (QMessageBox::Critical, s_strAssertTitle, s_strErrorMsg, QMessageBox::Close, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
415
591
}
416
592
 
417
593
 
418
 
/*
419
 
    if (!pCommonData->m_bWarnedAboutSel)
420
 
    {
421
 
        
422
 
    }
423
 
        p->m_bWarnedAboutBackup = m_pSettings->value("main/warnedAboutBackup", false).toBool();
424
 
*/
425
594
 
426
595
 
427
596
//=====================================================================================================================
637
806
 
638
807
 
639
808
 
640
 
MainFormDlgImpl::MainFormDlgImpl(const string& strSession, bool bUniqueSession) : QDialog(0, getMainWndFlags()), m_settings(strSession), m_nLastKey(0)/*, m_settings("Ciobi", "Mp3Diags_v01")*/ /*, m_nPrevTabIndex(-1), m_bTagEdtWasEntered(false)*/, m_strSession(strSession), m_bShowMaximized(false), m_nScanWidth(0)
 
809
MainFormDlgImpl::MainFormDlgImpl(const string& strSession, bool bUniqueSession) : QDialog(0, getMainWndFlags()), m_settings(strSession), m_nLastKey(0)/*, m_settings("Ciobi", "Mp3Diags_v01")*/ /*, m_nPrevTabIndex(-1), m_bTagEdtWasEntered(false)*/, m_pCommonData(0), m_strSession(strSession), m_bShowMaximized(false), m_nScanWidth(0)
641
810
{
642
811
//int x (2); CB_ASSERT(x > 4);
643
812
//CB_ASSERT("345" == "ab");
681
850
            {
682
851
                if (fileExists(s_strTraceFile))
683
852
                {
684
 
                    showErrorDlg2(this, "Restarting after crash", "MP3 Diags is restarting after a crash. Information in the files \"" + Qt::escape(toNativeSeparators(convStr(s_strTraceFile))) + "\", \"" + Qt::escape(toNativeSeparators(convStr(s_vstrStepFile[0]))) + "\", and \"" + Qt::escape(toNativeSeparators(convStr(s_vstrStepFile[1]))) + "\" may help identify the cause of the crash, so please make them available to the developer by mailing them to <a href=\"mailto:ciobi@inbox.com?subject=000 MP3 Diags crash/\">ciobi@inbox.com</a>, by reporting an issue to the project's <a href=\"http://sourceforge.net/apps/mantisbt/mp3diags/\">MP3 Diags Issue Tracker</a> (<a href=\"http://sourceforge.net/apps/mantisbt/mp3diags/\">http://sourceforge.net/apps/mantisbt/mp3diags/</a>) and attaching the files to the report, or by some other means (like putting them on a web server.)<p/><p/>These are plain text files, which you can review before sending, if you have privacy concerns.<p/><p/>After getting the files, the developer will probably want to contact you for more details, so please check back on the status of your report.<p/><p/>So please send these files, as well as any other detail that seems relevant (what might have caused the failure, steps to reproduce it, ...)<p/><p/><hr/><p/>", "OK");
 
853
                    showErrorDlg2(this, "Restarting after crash", "<p style=\"margin-bottom:8px; margin-top:1px; \">MP3 Diags is restarting after a crash. Information in the files \"" + Qt::escape(toNativeSeparators(convStr(s_strTraceFile))) + "\", \"" + Qt::escape(toNativeSeparators(convStr(s_vstrStepFile[0]))) + "\", and \"" + Qt::escape(toNativeSeparators(convStr(s_vstrStepFile[1]))) + "\" may help identify the cause of the crash, so please make them available to the developer by mailing them to <a href=\"mailto:ciobi@inbox.com?subject=000 MP3 Diags crash/\">ciobi@inbox.com</a>, by reporting an issue to the project's <a href=\"http://sourceforge.net/apps/mantisbt/mp3diags/\">Issue Tracker</a> (<a href=\"http://sourceforge.net/apps/mantisbt/mp3diags/\">http://sourceforge.net/apps/mantisbt/mp3diags/</a>) and attaching the files to the report, or by some other means (like putting them on a web server.)</p><p style=\"margin-bottom:8px; margin-top:1px; \">These are plain text files, which you can review before sending, if you have privacy concerns.</p><p style=\"margin-bottom:8px; margin-top:1px; \">After getting the files, the developer will probably want to contact you for more details, so please check back on the status of your report.</p><p style=\"margin-bottom:8px; margin-top:1px; \">So please send these files, as well as any other detail that seems relevant (what might have caused the failure, steps to reproduce it, ...)</p>", "Remove these files and continue");
685
854
                    //ttt0 perhaps loop until the file is deleted
686
855
                }
687
856
                else
688
857
                {
689
 
                    showErrorDlg2(this, "Restarting after crash", "MP3 Diags is restarting after a crash. There was supposed to be some information about what led to the crash in the file \"" + Qt::escape(toNativeSeparators(convStr(s_strTraceFile))) + "\", but that file cannot be found. Please report this issue to the project's <a href=\"http://sourceforge.net/apps/mantisbt/mp3diags/\">MP3 Diags Issue Tracker</a> (<a href=\"http://sourceforge.net/apps/mantisbt/mp3diags/\">http://sourceforge.net/apps/mantisbt/mp3diags/</a>)<p/><p/>The developer will probably want to contact you for more details, so please check back on the status of your report.<p/>Make sure to include the data below, as well as any other detail that seems relevant (what might have caused the failure, steps to reproduce it, ...)<p/><p/><hr/><p/>", "OK");
 
858
                    showErrorDlg2(this, "Restarting after crash", "<p style=\"margin-bottom:8px; margin-top:1px; \">MP3 Diags is restarting after a crash. There was supposed to be some information about what led to the crash in the file \"" + Qt::escape(toNativeSeparators(convStr(s_strTraceFile))) + "\", but that file cannot be found. Please report this issue to the project's <a href=\"http://sourceforge.net/apps/mantisbt/mp3diags/\">Issue Tracker</a> (<a href=\"http://sourceforge.net/apps/mantisbt/mp3diags/\">http://sourceforge.net/apps/mantisbt/mp3diags/</a>)</p><p style=\"margin-bottom:8px; margin-top:1px; \">The developer will probably want to contact you for more details, so please check back on the status of your report.</p><p style=\"margin-bottom:8px; margin-top:1px; \">Make sure to include the data below, as well as any other detail that seems relevant (what might have caused the failure, steps to reproduce it, ...)</p>", "OK");
690
859
                }
691
860
            }
692
861
 
1325
1494
        }
1326
1495
    }
1327
1496
 
1328
 
    m_pCrtDirE->setText(toNativeSeparators(convStr(m_pCommonData->getViewHandlers()[nCrtFile]->getDir())));
 
1497
    QString qs (toNativeSeparators(convStr(m_pCommonData->getViewHandlers()[nCrtFile]->getDir())));
 
1498
#ifndef WIN32
 
1499
#else
 
1500
    if (2 == qs.size() && ':' == qs[1])
 
1501
    {
 
1502
        qs += "\\"; //ttt0 test
 
1503
    }
 
1504
#endif
 
1505
    m_pCrtDirE->setText(qs);
1329
1506
 
1330
1507
    pLayout->addStretch(0);
1331
1508
}
2052
2229
void MainFormDlgImpl::on_m_pPrevB_clicked()
2053
2230
{
2054
2231
//CB_ASSERT("345" == "ab");
 
2232
//traceLastStep("tsterr", 0); char* p (0); *p = 11;
 
2233
 
2055
2234
    m_pCommonData->previous();
2056
2235
    //updateWidgets();
2057
2236
    m_pFilesG->setFocus();