Skip to content

Commit 74acd42

Browse files
committed
App: modify initial error
1 parent 7ceaedd commit 74acd42

4 files changed

Lines changed: 127 additions & 91 deletions

File tree

App/Client/main.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,7 @@ int main(int argc, char *argv[])
170170
app.processEvents();
171171
// For time-consuming operations
172172
nRet = w->Initial();
173-
if(nRet) {
174-
qCritical(log) << "Initialize error";
175-
QMessageBox::critical(nullptr, QObject::tr("Error"),
176-
QObject::tr("Initialize error"));
177-
}
178-
else
173+
if(!nRet)
179174
nRet = app.exec();
180175
} catch (std::exception &e) {
181176
qCritical(log) << "exception:" << e.what();

App/Client/mainwindow.cpp

Lines changed: 85 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -401,70 +401,109 @@ MainWindow::~MainWindow()
401401
//! For time-consuming operations
402402
int MainWindow::Initial()
403403
{
404-
int nRet = 0;
405404
qDebug(log) << Q_FUNC_INFO;
406405

407-
QMessageBox box(QMessageBox::Information, tr("Load"), tr("Load ......"));
408-
box.showNormal();
409-
qApp->processEvents();
410-
setEnabled(false);
411-
412-
QString szMsg;
413-
szMsg = tr("Load plugins ......");
414-
box.setText(szMsg);
415-
slotInformation(szMsg);
416-
qApp->processEvents();
417-
nRet = m_Manager.Initial();
418-
if(nRet) return nRet;
419-
m_Manager.EnumPlugins(this);
420-
421-
if(m_Manager.GetGlobalParameters())
422-
m_Parameter.m_Database = m_Manager.GetGlobalParameters()->m_Database;
406+
int nRet = 0;
407+
QString szErr;
423408

424-
if(m_pRecent) {
425-
szMsg = tr("Load list recent dock ......");
426-
box.setText(szMsg);
427-
slotInformation(szMsg);
409+
setEnabled(false);
410+
do {
411+
QMessageBox initMsgBox(QMessageBox::Information, tr("Load"), tr("Load ......"));
412+
initMsgBox.showNormal();
428413
qApp->processEvents();
429-
nRet = m_pRecent->Init();
430-
if(nRet) return nRet;
431-
}
432414

433-
if(m_pRecentMenu) {
434-
szMsg = tr("Load recent menu ......");
435-
box.setText(szMsg);
415+
QString szMsg;
416+
szMsg = tr("Load plugins ......");
417+
initMsgBox.setText(szMsg);
436418
slotInformation(szMsg);
437419
qApp->processEvents();
420+
nRet = m_Manager.Initial();
421+
if(nRet) {
422+
szErr = tr("Initial manage error");
423+
break;
424+
}
425+
m_Manager.EnumPlugins(this);
426+
427+
if(m_Manager.GetGlobalParameters())
428+
m_Parameter.m_Database = m_Manager.GetGlobalParameters()->m_Database;
429+
438430
if(m_pRecent) {
439-
auto recents = m_pRecent->GetRecents(m_Parameter.GetRecentMenuMaxCount());
440-
//qDebug(log) << "recents totaol:" << recents.size() << m_Parameter.GetRecentMenuMaxCount();
441-
for(auto it = recents.rbegin(); it != recents.rend(); it++) {
442-
m_pRecentMenu->addRecentFile(it->GetFile(), it->szName, it->icon);
431+
szMsg = tr("Load list recent dock ......");
432+
initMsgBox.setText(szMsg);
433+
slotInformation(szMsg);
434+
qApp->processEvents();
435+
nRet = m_pRecent->Init();
436+
if(nRet) {
437+
szErr = tr("Initial recent dock error");
438+
break;
443439
}
444440
}
445-
}
446441

447-
if(m_pFavoriteView) {
448-
szMsg = tr("Load favorite ......");
449-
box.setText(szMsg);
442+
if(m_pRecentMenu) {
443+
szMsg = tr("Load recent menu ......");
444+
initMsgBox.setText(szMsg);
445+
slotInformation(szMsg);
446+
qApp->processEvents();
447+
if(m_pRecent) {
448+
auto recents = m_pRecent->GetRecents(m_Parameter.GetRecentMenuMaxCount());
449+
//qDebug(log) << "recents totaol:" << recents.size() << m_Parameter.GetRecentMenuMaxCount();
450+
for(auto it = recents.rbegin(); it != recents.rend(); it++) {
451+
m_pRecentMenu->addRecentFile(it->GetFile(), it->szName, it->icon);
452+
}
453+
}
454+
}
455+
456+
if(m_pFavoriteView) {
457+
szMsg = tr("Load favorite ......");
458+
initMsgBox.setText(szMsg);
459+
slotInformation(szMsg);
460+
qApp->processEvents();
461+
nRet = m_pFavoriteView->Initial();
462+
if(nRet) {
463+
szErr = tr("Initial favorite error");
464+
break;
465+
}
466+
}
467+
468+
slotEnableSystemTrayIcon();
469+
470+
setEnabled(true);
471+
472+
szMsg = tr("Load laster operate ......");
473+
initMsgBox.setText(szMsg);
450474
slotInformation(szMsg);
451475
qApp->processEvents();
452-
nRet = m_pFavoriteView->Initial();
453-
if(nRet) return nRet;
454-
}
476+
nRet = LoadOperateLasterClose();
477+
if(nRet) {
478+
szErr = tr("Initial load laster close operate error");
479+
break;
480+
}
455481

456-
slotEnableSystemTrayIcon();
482+
slotInformation(tr("Ready"));
483+
484+
return nRet;
485+
} while(false);
457486

458487
setEnabled(true);
459488

460-
szMsg = tr("Load laster operate ......");
461-
box.setText(szMsg);
462-
slotInformation(szMsg);
463-
qApp->processEvents();
464-
nRet = LoadOperateLasterClose();
465-
if(nRet) return nRet;
489+
QMessageBox errMsgBox;
490+
errMsgBox.setWindowTitle(QObject::tr("Error"));
491+
errMsgBox.setText(QObject::tr("Initial error:") + szErr);
492+
errMsgBox.setIcon(QMessageBox::Critical);
493+
494+
auto logMenu = RabbitCommon::CTools::GetLogMenu();
495+
QPushButton *pbLog = new QPushButton(logMenu->title());
496+
pbLog->setMenu(logMenu);
497+
498+
QPushButton *pbettings = new QPushButton(ui->actionSettings->text());
499+
QMenu* pSettings = new QMenu(pbettings);
500+
pSettings->addAction(ui->actionSettings);
501+
pbettings->setMenu(pSettings);
502+
errMsgBox.addButton(pbettings, QMessageBox::ActionRole);
503+
errMsgBox.addButton(pbLog, QMessageBox::ActionRole);
504+
errMsgBox.addButton(QMessageBox::Cancel);
466505

467-
slotInformation(tr("Ready"));
506+
errMsgBox.exec();
468507

469508
return nRet;
470509
}

Src/Database/Database.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ bool CDatabase::OpenMySqlDatabase(const CParameterDatabase *pPara,
165165
if (!m_database.open()) {
166166
qCritical(log) << "Failed to open mysql database:"
167167
<< m_database.lastError().text()
168+
<< "Host:" << net.GetHost() << "Port:" << net.GetPort()
169+
<< "User:" << user.GetUser()
168170
<< "connect name:" << m_database.connectionName()
169171
<< "database name:" << m_database.databaseName();
170172
return false;

Src/Database/ParameterDatabaseUI.ui

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,14 @@
77
<x>0</x>
88
<y>0</y>
99
<width>550</width>
10-
<height>148</height>
10+
<height>300</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout">
1717
<item row="4" column="0">
18-
<spacer name="verticalSpacer">
19-
<property name="orientation">
20-
<enum>Qt::Orientation::Vertical</enum>
21-
</property>
22-
<property name="sizeHint" stdset="0">
23-
<size>
24-
<width>20</width>
25-
<height>40</height>
26-
</size>
27-
</property>
28-
</spacer>
29-
</item>
30-
<item row="2" column="0">
31-
<widget class="CParameterNetUI" name="wNet" native="true"/>
32-
</item>
33-
<item row="0" column="0">
34-
<layout class="QHBoxLayout" name="horizontalLayout">
35-
<item>
36-
<widget class="QLabel" name="label">
37-
<property name="text">
38-
<string>Type:</string>
39-
</property>
40-
</widget>
41-
</item>
42-
<item>
43-
<widget class="QComboBox" name="cbType">
44-
<property name="sizePolicy">
45-
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
46-
<horstretch>0</horstretch>
47-
<verstretch>0</verstretch>
48-
</sizepolicy>
49-
</property>
50-
</widget>
51-
</item>
52-
</layout>
53-
</item>
54-
<item row="3" column="0">
5518
<layout class="QHBoxLayout" name="horizontalLayout_3">
5619
<item>
5720
<widget class="QLabel" name="label_3">
@@ -65,7 +28,10 @@
6528
</item>
6629
</layout>
6730
</item>
68-
<item row="1" column="0">
31+
<item row="3" column="0">
32+
<widget class="CParameterNetUI" name="wNet" native="true"/>
33+
</item>
34+
<item row="2" column="0">
6935
<layout class="QHBoxLayout" name="horizontalLayout_2">
7036
<item>
7137
<widget class="QLabel" name="label_2">
@@ -86,7 +52,41 @@
8652
</item>
8753
</layout>
8854
</item>
55+
<item row="1" column="0">
56+
<layout class="QHBoxLayout" name="horizontalLayout">
57+
<item>
58+
<widget class="QLabel" name="label">
59+
<property name="text">
60+
<string>Type:</string>
61+
</property>
62+
</widget>
63+
</item>
64+
<item>
65+
<widget class="QComboBox" name="cbType">
66+
<property name="sizePolicy">
67+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
68+
<horstretch>0</horstretch>
69+
<verstretch>0</verstretch>
70+
</sizepolicy>
71+
</property>
72+
</widget>
73+
</item>
74+
</layout>
75+
</item>
8976
<item row="5" column="0">
77+
<spacer name="verticalSpacer">
78+
<property name="orientation">
79+
<enum>Qt::Orientation::Vertical</enum>
80+
</property>
81+
<property name="sizeHint" stdset="0">
82+
<size>
83+
<width>20</width>
84+
<height>40</height>
85+
</size>
86+
</property>
87+
</spacer>
88+
</item>
89+
<item row="0" column="0">
9090
<widget class="QLabel" name="label_4">
9191
<property name="text">
9292
<string>The setting will take effect only after restarting the program.</string>

0 commit comments

Comments
 (0)