File indexing completed on 2025-03-09 03:52:09
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2003-01-31 0007 * Description : a presentation tool. 0008 * 0009 * SPDX-FileCopyrightText: 2006-2009 by Valerio Fuoglio <valerio dot fuoglio at gmail dot com> 0010 * SPDX-FileCopyrightText: 2009 by Andi Clemens <andi dot clemens at googlemail dot com> 0011 * SPDX-FileCopyrightText: 2003-2005 by Renchi Raju <renchi dot raju at gmail dot com> 0012 * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0013 * 0014 * SPDX-License-Identifier: GPL-2.0-or-later 0015 * 0016 * ============================================================ */ 0017 0018 #include "presentationmngr.h" 0019 0020 // C++ includes 0021 0022 #include <cstdlib> 0023 0024 // Qt includes 0025 0026 #include <QTime> 0027 #include <QPair> 0028 #include <QStringList> 0029 #include <QAction> 0030 #include <QWindow> 0031 #include <QApplication> 0032 #include <QMessageBox> 0033 #include <QRandomGenerator> 0034 0035 // KDE includes 0036 0037 #include <klocalizedstring.h> 0038 #include <ksharedconfig.h> 0039 #include <kconfiggroup.h> 0040 0041 // Local includes 0042 0043 #include "digikam_config.h" 0044 #include "digikam_debug.h" 0045 #include "presentationwidget.h" 0046 #include "presentationcontainer.h" 0047 0048 #ifdef HAVE_OPENGL 0049 # include "presentationgl.h" 0050 # include "presentationkb.h" 0051 #endif 0052 0053 namespace DigikamGenericPresentationPlugin 0054 { 0055 0056 PresentationMngr::PresentationMngr(QObject* const parent, DInfoInterface* const iface) 0057 : QObject (parent), 0058 m_plugin(nullptr), 0059 m_dialog(nullptr) 0060 { 0061 m_sharedData = new PresentationContainer(); 0062 m_sharedData->iface = iface; 0063 } 0064 0065 PresentationMngr::~PresentationMngr() 0066 { 0067 delete m_dialog; 0068 delete m_sharedData; 0069 } 0070 0071 void PresentationMngr::setPlugin(DPlugin* const plugin) 0072 { 0073 m_plugin = plugin; 0074 } 0075 0076 void PresentationMngr::addFiles(const QList<QUrl>& urls) 0077 { 0078 m_sharedData->urlList = urls; 0079 } 0080 0081 void PresentationMngr::showConfigDialog() 0082 { 0083 m_dialog = new PresentationDlg(QApplication::activeWindow(), m_sharedData); 0084 0085 connect(m_dialog, SIGNAL(buttonStartClicked()), 0086 this, SLOT(slotSlideShow())); 0087 0088 m_dialog->setPlugin(m_plugin); 0089 m_dialog->show(); 0090 } 0091 0092 void PresentationMngr::slotSlideShow() 0093 { 0094 KSharedConfigPtr config = KSharedConfig::openConfig(); 0095 KConfigGroup grp = config->group(QLatin1String("Presentation Settings")); 0096 bool opengl = grp.readEntry("OpenGL", false); 0097 bool shuffle = grp.readEntry("Shuffle", false); 0098 bool wantKB = grp.readEntry("Effect Name (OpenGL)") == QLatin1String("Ken Burns"); 0099 0100 if (m_sharedData->urlList.isEmpty()) 0101 { 0102 QMessageBox::information(QApplication::activeWindow(), QString(), i18n("There are no images to show.")); 0103 return; 0104 } 0105 0106 if (shuffle) 0107 { 0108 QList<QUrl>::iterator it = m_sharedData->urlList.begin(); 0109 QList<QUrl>::iterator it1; 0110 0111 for (uint i = 0 ; i < (uint) m_sharedData->urlList.size() ; ++i) 0112 { 0113 int inc = QRandomGenerator::global()->bounded(m_sharedData->urlList.count()); 0114 0115 it1 = m_sharedData->urlList.begin(); 0116 it1 += inc; 0117 0118 std::swap(*(it++), *(it1)); 0119 } 0120 } 0121 0122 if (!opengl) 0123 { 0124 PresentationWidget* const slide = new PresentationWidget(m_sharedData); 0125 slide->show(); 0126 } 0127 else 0128 { 0129 0130 #ifdef HAVE_OPENGL 0131 0132 bool supportsOpenGL = true; 0133 0134 if (wantKB) 0135 { 0136 PresentationKB* const slide = new PresentationKB(m_sharedData); 0137 slide->show(); 0138 0139 if (!slide->checkOpenGL()) 0140 { 0141 supportsOpenGL = false; 0142 slide->close(); 0143 } 0144 0145 } 0146 else 0147 { 0148 PresentationGL* const slide = new PresentationGL(m_sharedData); 0149 slide->show(); 0150 0151 if (!slide->checkOpenGL()) 0152 { 0153 supportsOpenGL = false; 0154 slide->close(); 0155 } 0156 } 0157 0158 if (!supportsOpenGL) 0159 { 0160 QMessageBox::critical(QApplication::activeWindow(), QString(), 0161 i18n("OpenGL support is not available on your system.")); 0162 } 0163 0164 #else 0165 0166 Q_UNUSED(wantKB); 0167 0168 #endif 0169 0170 } 0171 } 0172 0173 } // namespace DigikamGenericPresentationPlugin 0174 0175 #include "moc_presentationmngr.cpp"