mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
More readable startup code.
This commit is contained in:
parent
9f6c0abf23
commit
e99c776878
3 changed files with 27 additions and 29 deletions
|
@ -314,7 +314,7 @@ bool lcApplication::LoadPartsLibrary(const QList<QPair<QString, bool>>& LibraryP
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool& ShowWindow)
|
lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths)
|
||||||
{
|
{
|
||||||
bool OnlyUseLibraryPaths = false;
|
bool OnlyUseLibraryPaths = false;
|
||||||
bool SaveImage = false;
|
bool SaveImage = false;
|
||||||
|
@ -696,8 +696,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
|
||||||
#endif
|
#endif
|
||||||
printf("Compiled " __DATE__ "\n");
|
printf("Compiled " __DATE__ "\n");
|
||||||
|
|
||||||
ShowWindow = false;
|
return lcStartupMode::Success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else if (Param == QLatin1String("-?") || Param == QLatin1String("--help"))
|
else if (Param == QLatin1String("-?") || Param == QLatin1String("--help"))
|
||||||
{
|
{
|
||||||
|
@ -736,8 +735,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
|
||||||
printf(" -?, --help: Display this help message and exit.\n");
|
printf(" -?, --help: Display this help message and exit.\n");
|
||||||
printf(" \n");
|
printf(" \n");
|
||||||
|
|
||||||
ShowWindow = false;
|
return lcStartupMode::Success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -747,9 +745,14 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ParseOK)
|
if (!ParseOK)
|
||||||
|
return lcStartupMode::Error;
|
||||||
|
|
||||||
|
const bool SaveAndExit = (SaveImage || SaveWavefront || Save3DS || SaveCOLLADA || SaveHTML);
|
||||||
|
|
||||||
|
if (SaveAndExit && ProjectName.isEmpty())
|
||||||
{
|
{
|
||||||
ShowWindow = false;
|
printf("No file name specified.\n");
|
||||||
return false;
|
return lcStartupMode::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AASamples > 1)
|
if (AASamples > 1)
|
||||||
|
@ -770,20 +773,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
|
||||||
lcLoadDefaultKeyboardShortcuts();
|
lcLoadDefaultKeyboardShortcuts();
|
||||||
lcLoadDefaultMouseShortcuts();
|
lcLoadDefaultMouseShortcuts();
|
||||||
|
|
||||||
if (SaveImage || SaveWavefront || Save3DS || SaveCOLLADA || SaveHTML)
|
if (!LoadPartsLibrary(LibraryPaths, OnlyUseLibraryPaths, !SaveAndExit))
|
||||||
{
|
|
||||||
ShowWindow = false;
|
|
||||||
|
|
||||||
if (ProjectName.isEmpty())
|
|
||||||
{
|
|
||||||
printf("No file name specified.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ShowWindow = true;
|
|
||||||
|
|
||||||
if (!LoadPartsLibrary(LibraryPaths, OnlyUseLibraryPaths, ShowWindow))
|
|
||||||
{
|
{
|
||||||
QString Message;
|
QString Message;
|
||||||
|
|
||||||
|
@ -792,7 +782,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
|
||||||
else
|
else
|
||||||
Message = tr("LeoCAD could not load Parts Library.\n\nPlease visit https://www.leocad.org for information on how to download and install a library.");
|
Message = tr("LeoCAD could not load Parts Library.\n\nPlease visit https://www.leocad.org for information on how to download and install a library.");
|
||||||
|
|
||||||
if (ShowWindow)
|
if (!SaveAndExit)
|
||||||
QMessageBox::information(gMainWindow, tr("LeoCAD"), Message);
|
QMessageBox::information(gMainWindow, tr("LeoCAD"), Message);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "%s", Message.toLatin1().constData());
|
fprintf(stderr, "%s", Message.toLatin1().constData());
|
||||||
|
@ -803,7 +793,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
|
||||||
Project* NewProject = new Project();
|
Project* NewProject = new Project();
|
||||||
SetProject(NewProject);
|
SetProject(NewProject);
|
||||||
|
|
||||||
if (ShowWindow && ProjectName.isEmpty() && lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT))
|
if (!SaveAndExit && ProjectName.isEmpty() && lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT))
|
||||||
ProjectName = lcGetProfileString(LC_PROFILE_RECENT_FILE1);
|
ProjectName = lcGetProfileString(LC_PROFILE_RECENT_FILE1);
|
||||||
|
|
||||||
if (!ProjectName.isEmpty() && gMainWindow->OpenProject(ProjectName))
|
if (!ProjectName.isEmpty() && gMainWindow->OpenProject(ProjectName))
|
||||||
|
@ -1016,7 +1006,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShowWindow)
|
if (!SaveAndExit)
|
||||||
{
|
{
|
||||||
gMainWindow->SetColorIndex(lcGetColorIndex(7));
|
gMainWindow->SetColorIndex(lcGetColorIndex(7));
|
||||||
gMainWindow->GetPartSelectionWidget()->SetDefaultPart();
|
gMainWindow->GetPartSelectionWidget()->SetDefaultPart();
|
||||||
|
@ -1024,7 +1014,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
|
||||||
gMainWindow->show();
|
gMainWindow->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return SaveAndExit ? lcStartupMode::Success : lcStartupMode::ShowWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcApplication::Shutdown()
|
void lcApplication::Shutdown()
|
||||||
|
|
|
@ -70,6 +70,13 @@ public:
|
||||||
int mDrawPreviewAxis;
|
int mDrawPreviewAxis;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class lcStartupMode
|
||||||
|
{
|
||||||
|
ShowWindow,
|
||||||
|
Success,
|
||||||
|
Error
|
||||||
|
};
|
||||||
|
|
||||||
class lcApplication : public QApplication
|
class lcApplication : public QApplication
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -79,7 +86,7 @@ public:
|
||||||
~lcApplication();
|
~lcApplication();
|
||||||
|
|
||||||
void SetProject(Project* Project);
|
void SetProject(Project* Project);
|
||||||
bool Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool& ShowWindow);
|
lcStartupMode Initialize(QList<QPair<QString, bool>>& LibraryPaths);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
void ShowPreferencesDialog();
|
void ShowPreferencesDialog();
|
||||||
void SaveTabLayout() const;
|
void SaveTabLayout() const;
|
||||||
|
|
|
@ -181,13 +181,14 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
setlocale(LC_NUMERIC, "C");
|
setlocale(LC_NUMERIC, "C");
|
||||||
|
|
||||||
bool ShowWindow;
|
lcStartupMode StartupMode = Application.Initialize(LibraryPaths);
|
||||||
if (!Application.Initialize(LibraryPaths, ShowWindow))
|
|
||||||
|
if (StartupMode == lcStartupMode::Error)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
int ExecReturn = 0;
|
int ExecReturn = 0;
|
||||||
|
|
||||||
if (ShowWindow)
|
if (StartupMode == lcStartupMode::ShowWindow)
|
||||||
{
|
{
|
||||||
#if !LC_DISABLE_UPDATE_CHECK
|
#if !LC_DISABLE_UPDATE_CHECK
|
||||||
lcDoInitialUpdateCheck();
|
lcDoInitialUpdateCheck();
|
||||||
|
|
Loading…
Add table
Reference in a new issue