File indexing completed on 2025-01-05 03:57:55

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2004-11-22
0007  * Description : stand alone digiKam image editor
0008  *
0009  * SPDX-FileCopyrightText: 2004-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0011  * SPDX-FileCopyrightText: 2009-2011 by Andi Clemens <andi dot clemens at gmail dot com>
0012  * SPDX-FileCopyrightText: 2004-2005 by Renchi Raju <renchi dot raju at gmail dot com>
0013  * SPDX-FileCopyrightText: 2005-2006 by Tom Albers <tomalbers at kde dot nl>
0014  * SPDX-FileCopyrightText: 2008      by Arnd Baecker <arnd dot baecker at web dot de>
0015  * SPDX-FileCopyrightText: 2013-2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0016  *
0017  * SPDX-License-Identifier: GPL-2.0-or-later
0018  *
0019  * ============================================================ */
0020 
0021 #include "showfoto_p.h"
0022 
0023 namespace ShowFoto
0024 {
0025 
0026 Showfoto::Showfoto(const QList<QUrl>& urlList, QWidget* const)
0027     : Digikam::EditorWindow(QLatin1String("Showfoto")),
0028       d                    (new Private)
0029 {
0030     setXMLFile(QLatin1String("showfotoui5.rc"));
0031 
0032     m_nonDestructive = false;
0033 
0034     // Show splash-screen at start up.
0035 
0036     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0037     KConfigGroup group        = config->group(configGroupName());
0038     KConfigGroup sgroup       = config->group(QLatin1String("ImageViewer Settings"));
0039     QString iconTheme         = sgroup.readEntry(QLatin1String("Icon Theme"), QString());
0040 
0041     if (!iconTheme.isEmpty())
0042     {
0043         QIcon::setThemeName(iconTheme);
0044     }
0045 
0046     if (group.readEntry(QLatin1String("ShowSplash"), true) && !qApp->isSessionRestored())
0047     {
0048         d->splash = new Digikam::DSplashScreen();
0049         d->splash->show();
0050     }
0051 
0052     // Setup loading cache and thumbnails interface.
0053 
0054     Digikam::LoadingCacheInterface::initialize();
0055     Digikam::MetaEngineSettings::instance();
0056     Digikam::LocalizeSettings::instance();
0057     Digikam::NetworkManager::instance();
0058 
0059 #ifdef HAVE_GEOLOCATION
0060 
0061     connect(Digikam::GeolocationSettings::instance(), &Digikam::GeolocationSettings::signalSetupGeolocation,
0062             this, [=](int tab)
0063         {
0064             ShowfotoSetup::execGeolocation(this, tab);
0065         }
0066     );
0067 
0068 #endif
0069 
0070     connect(LocalizeSettings::instance(), &LocalizeSettings::signalOpenLocalizeSetup,
0071             this, [=]()
0072         {
0073             ShowfotoSetup::execLocalize(this);
0074         }
0075     );
0076 
0077     ExifToolThread* const exifToolThread = new ExifToolThread(this);
0078     exifToolThread->start();
0079 
0080     d->thumbLoadThread = new Digikam::ThumbnailLoadThread();
0081     d->thumbLoadThread->setThumbnailSize(Digikam::ThumbnailSize::Huge);
0082     d->thumbLoadThread->setSendSurrogatePixmap(true);
0083 
0084     // Check ICC profiles repository availability
0085 
0086     if (d->splash)
0087     {
0088         d->splash->setMessage(i18n("Checking ICC repository..."));
0089     }
0090 
0091     d->validIccPath = Digikam::SetupICC::iccRepositoryIsValid();
0092 
0093     // Populate Themes
0094 
0095     if (d->splash)
0096     {
0097         d->splash->setMessage(i18n("Loading themes..."));
0098     }
0099 
0100     Digikam::ThemeManager::instance();
0101 
0102     // Load plugins
0103 
0104     if (d->splash)
0105     {
0106         d->splash->setMessage(i18n("Load Plugins..."));
0107     }
0108 
0109     DPluginLoader* const dpl = Digikam::DPluginLoader::instance();
0110     dpl->init();
0111 
0112     // -- Build the GUI -----------------------------------
0113 
0114     this->setupUserArea();
0115     this->setupActions();
0116     setupStatusBar();
0117     createGUI(xmlFile());
0118     registerPluginsActions();
0119     d->folderView->registerPluginActions(dpl->pluginsActions(DPluginAction::GenericView, this));
0120     d->stackView->registerPluginActions(dpl->pluginsActions(DPluginAction::GenericView, this));
0121 
0122     cleanupActions();
0123 
0124     // Create tool selection view
0125 
0126     setupSelectToolsAction();
0127 
0128     // Create context menu.
0129 
0130     setupContextMenu();
0131 
0132     // Make signals/slots connections
0133 
0134     this->setupConnections();
0135 
0136     // Disable all actions
0137 
0138     this->toggleActions(false);
0139 
0140     // -- Read settings --------------------------------
0141 
0142     this->readSettings();
0143     applySettings();
0144     setAutoSaveSettings(configGroupName(), true);
0145 
0146     d->leftSideBar->loadState();
0147     d->folderView->loadState();
0148     d->stackView->loadState();
0149     d->rightSideBar->loadState();
0150 
0151     //--------------------------------------------------
0152 
0153     d->thumbBarDock->reInitialize();
0154 
0155     // -- Load current items ---------------------------
0156 
0157     slotDroppedUrls(urlList, false, QUrl());
0158 }
0159 
0160 Showfoto::~Showfoto()
0161 {
0162     delete m_canvas;
0163     m_canvas = nullptr;
0164 
0165     Digikam::ThumbnailLoadThread::cleanUp();
0166     Digikam::LoadingCacheInterface::cleanUp();
0167     Digikam::DPluginLoader::instance()->cleanUp();
0168 
0169     delete d->model;
0170     delete d->filterModel;
0171     delete d->thumbBar;
0172     delete d->rightSideBar;
0173     delete d->thumbLoadThread;
0174     delete d;
0175 }
0176 
0177 bool Showfoto::queryClose()
0178 {
0179     // wait if a save operation is currently running
0180 
0181     if (!waitForSavingToComplete())
0182     {
0183         return false;
0184     }
0185 
0186     if (!d->thumbBar->currentInfo().isNull() && !promptUserSave(d->thumbBar->currentUrl()))
0187     {
0188         return false;
0189     }
0190 
0191     saveSettings();
0192 
0193     return true;
0194 }
0195 
0196 void Showfoto::show()
0197 {
0198     // Remove Splashscreen.
0199 
0200     if (d->splash)
0201     {
0202         d->splash->finish(this);
0203     }
0204 
0205     // Display application window.
0206 
0207     QMainWindow::show();
0208 
0209     // Report errors from ICC repository path.
0210 
0211     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0212 
0213     if (!d->validIccPath)
0214     {
0215         QString message = i18n("<p>The ICC profile path seems to be invalid.</p>"
0216                                "<p>If you want to set it now, select \"Yes\", otherwise "
0217                                "select \"No\". In this case, \"Color Management\" feature "
0218                                "will be disabled until you solve this issue</p>");
0219 
0220         if (QMessageBox::warning(this, qApp->applicationName(), message,
0221                                  QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
0222         {
0223             if (!setup(true))
0224             {
0225                 KConfigGroup group = config->group(QLatin1String("Color Management"));
0226                 group.writeEntry(QLatin1String("EnableCM"), false);
0227                 config->sync();
0228             }
0229         }
0230         else
0231         {
0232             KConfigGroup group = config->group(QLatin1String("Color Management"));
0233             group.writeEntry(QLatin1String("EnableCM"), false);
0234             config->sync();
0235         }
0236     }
0237 
0238     if (d->splash)
0239     {
0240         delete d->splash;
0241         d->splash = nullptr;
0242     }
0243 }
0244 
0245 Digikam::Sidebar* Showfoto::rightSideBar() const
0246 {
0247     return (dynamic_cast<Digikam::Sidebar*>(d->rightSideBar));
0248 }
0249 
0250 void Showfoto::slotChanged()
0251 {
0252     QString mpixels;
0253     QSize dims(m_canvas->imageWidth(), m_canvas->imageHeight());
0254     mpixels = QLocale().toString(dims.width()*dims.height()/1000000.0, 'f', 1);
0255     QString str = (!dims.isValid()) ? i18nc("unknown image dimensions", "Unknown")
0256                                     : i18nc("%1 width, %2 height, %3 mpixels", "%1x%2 (%3Mpx)",
0257                                             dims.width(),dims.height(),mpixels);
0258     m_resLabel->setAdjustedText(str);
0259 
0260     if (!d->thumbBar->currentInfo().isNull())
0261     {
0262         if (d->thumbBar->currentUrl().isValid())
0263         {
0264             QRect sel                = m_canvas->getSelectedArea();
0265             Digikam::DImg* const img = m_canvas->interface()->getImg();
0266             d->rightSideBar->itemChanged(d->thumbBar->currentUrl(), sel, img);
0267         }
0268     }
0269 }
0270 
0271 void Showfoto::slotUpdateItemInfo()
0272 {
0273     d->itemsNb = d->thumbBar->showfotoItemInfos().size();
0274     int index  = d->thumbBar->thumbnailIndexForUrl(d->thumbBar->currentUrl());
0275     QString text;
0276 
0277     if (d->itemsNb > 0)
0278     {
0279         text = i18nc("<Image file name> (<Image number> of <Images in album>)",
0280                      "%1 (%2 of %3)", d->thumbBar->currentInfo().name,
0281                      index, d->itemsNb);
0282 
0283         setCaption(QDir::toNativeSeparators(d->thumbBar->currentUrl()
0284                                             .adjusted(QUrl::RemoveFilename).toLocalFile()));
0285     }
0286     else
0287     {
0288         text = QLatin1String("");
0289         setCaption(QLatin1String(""));
0290     }
0291 
0292     m_nameLabel->setText(text);
0293     toggleNavigation(index);
0294 }
0295 
0296 DInfoInterface* Showfoto::infoIface(DPluginAction* const)
0297 {
0298     ShowfotoInfoIface* const iface = new ShowfotoInfoIface(this, d->thumbBar->urls());
0299 
0300     qCDebug(DIGIKAM_GENERAL_LOG) << "Showfoto::infoIface: nb of file" << d->thumbBar->urls().size();
0301 
0302     connect(iface, SIGNAL(signalItemChanged(QUrl)),
0303             this, SLOT(slotChanged()));
0304 
0305     connect(iface, SIGNAL(signalImportedImage(QUrl)),
0306             this, SLOT(slotImportedImagefromScanner(QUrl)));
0307 
0308     connect(iface, SIGNAL(signalRemoveImageFromAlbum(QUrl)),
0309             this, SLOT(slotRemoveImageFromAlbum(QUrl)));
0310 
0311     return iface;
0312 }
0313 
0314 void Showfoto::slotOnlineVersionCheck()
0315 {
0316     ShowfotoSetup::onlineVersionCheck();
0317 }
0318 
0319 } // namespace ShowFoto
0320 
0321 #include "moc_showfoto.cpp"