File indexing completed on 2025-01-05 03:58:23

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-28-04
0007  * Description : first run assistant dialog
0008  *
0009  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "firstrundlg.h"
0016 
0017 // Qt includes
0018 
0019 #include <QPushButton>
0020 
0021 // Local includes
0022 
0023 #include "digikam_globals.h"
0024 #include "dxmlguiwindow.h"
0025 #include "welcomepage.h"
0026 #include "collectionpage.h"
0027 #include "databasepage.h"
0028 #include "rawpage.h"
0029 #include "metadatapage.h"
0030 #include "previewpage.h"
0031 #include "openfilepage.h"
0032 #include "tooltipspage.h"
0033 #include "startscanpage.h"
0034 
0035 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0036 #   include "migratefromdigikam4page.h"
0037 #endif
0038 
0039 namespace Digikam
0040 {
0041 
0042 class Q_DECL_HIDDEN FirstRunDlg::Private
0043 {
0044 public:
0045 
0046     explicit Private()
0047       : welcomePage(nullptr),
0048 
0049 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0050 
0051         migrateFromDigikam4Page(nullptr),
0052 
0053 #endif
0054 
0055         collectionPage(nullptr),
0056         databasePage(nullptr),
0057         rawPage(nullptr),
0058         metadataPage(nullptr),
0059         previewPage(nullptr),
0060         openFilePage(nullptr),
0061         tooltipsPage(nullptr),
0062         startScanPage(nullptr)
0063     {
0064     }
0065 
0066     WelcomePage*             welcomePage;
0067 
0068 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0069 
0070     MigrateFromDigikam4Page* migrateFromDigikam4Page;
0071 
0072 #endif
0073 
0074     CollectionPage*          collectionPage;
0075     DatabasePage*            databasePage;
0076     RawPage*                 rawPage;
0077     MetadataPage*            metadataPage;
0078     PreviewPage*             previewPage;
0079     OpenFilePage*            openFilePage;
0080     TooltipsPage*            tooltipsPage;
0081     StartScanPage*           startScanPage;
0082 };
0083 
0084 FirstRunDlg::FirstRunDlg(QWidget* const parent)
0085     : QWizard(parent),
0086       d(new Private)
0087 {
0088     setWizardStyle(QWizard::ClassicStyle);
0089     setButtonLayout(QList<QWizard::WizardButton>() << QWizard::HelpButton
0090                                                    << QWizard::BackButton
0091                                                    << QWizard::CancelButton
0092                                                    << QWizard::NextButton
0093                                                    << QWizard::FinishButton);
0094 
0095     d->welcomePage    = new WelcomePage(this);    // First assistant page
0096 
0097 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0098 
0099     if (MigrateFromDigikam4Page::checkForMigration())
0100     {
0101         d->migrateFromDigikam4Page = new MigrateFromDigikam4Page(this);
0102     }
0103 
0104 #endif
0105 
0106     d->collectionPage = new CollectionPage(this);
0107     d->databasePage   = new DatabasePage(this);
0108     d->rawPage        = new RawPage(this);
0109     d->metadataPage   = new MetadataPage(this);
0110     d->previewPage    = new PreviewPage(this);
0111     d->openFilePage   = new OpenFilePage(this);
0112     d->tooltipsPage   = new TooltipsPage(this);
0113 
0114     // NOTE: Added here new assistant pages...
0115 
0116     d->startScanPage  = new StartScanPage(this);  // Last assistant page
0117 
0118     resize(600, 600);
0119 
0120     connect(button(QWizard::FinishButton), SIGNAL(clicked()),
0121             this, SLOT(slotFinishPressed()));
0122 
0123     connect(this, SIGNAL(helpRequested()),
0124             this, SLOT(slotHelp()));
0125 }
0126 
0127 FirstRunDlg::~FirstRunDlg()
0128 {
0129     delete d;
0130 }
0131 
0132 void FirstRunDlg::slotHelp()
0133 {
0134     openOnlineDocumentation(QLatin1String("getting_started"), QLatin1String("quick_start"));
0135 }
0136 
0137 QString FirstRunDlg::firstAlbumPath() const
0138 {
0139     return d->collectionPage->firstAlbumPath();
0140 }
0141 
0142 DbEngineParameters FirstRunDlg::getDbEngineParameters() const
0143 {
0144     return d->databasePage->getDbEngineParameters();
0145 }
0146 
0147 bool FirstRunDlg::validateCurrentPage()
0148 {
0149     if (currentPage() == d->collectionPage)
0150     {
0151         if (!d->collectionPage->checkSettings())
0152         {
0153             return false;
0154         }
0155         else
0156         {
0157             d->databasePage->setDatabasePath(firstAlbumPath());
0158         }
0159     }
0160 
0161     if (currentPage() == d->databasePage)
0162     {
0163         if (!d->databasePage->checkSettings())
0164         {
0165             return false;
0166         }
0167     }
0168 
0169     return true;
0170 }
0171 
0172 void FirstRunDlg::slotFinishPressed()
0173 {
0174 
0175 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0176 
0177     if (d->migrateFromDigikam4Page && d->migrateFromDigikam4Page->isMigrationChecked())
0178     {
0179        // The user choose to do a migration from digikam4
0180 
0181        d->migrateFromDigikam4Page->doMigration();
0182     }
0183     else
0184 
0185 #endif
0186 
0187     {
0188        // Save settings to rc files.
0189 
0190        d->collectionPage->saveSettings();
0191        d->databasePage->saveSettings();
0192        d->rawPage->saveSettings();
0193        d->metadataPage->saveSettings();
0194        d->previewPage->saveSettings();
0195        d->openFilePage->saveSettings();
0196        d->tooltipsPage->saveSettings();
0197     }
0198 }
0199 
0200 } // namespace Digikam
0201 
0202 #include "moc_firstrundlg.cpp"