File indexing completed on 2025-01-05 03:53:06

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2021-07-24
0007  * Description : MJPEG Stream configuration dialog
0008  *
0009  * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2021      by Quoc Hưng Tran <quochungtran1999 at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "mjpegstreamdlg_p.h"
0017 
0018 namespace DigikamGenericMjpegStreamPlugin
0019 {
0020 
0021 MjpegStreamDlg::MjpegStreamDlg(QObject* const /*parent*/,
0022                                DInfoInterface* const iface)
0023     : DPluginDialog(nullptr, MjpegServerMngr::instance()->configGroupName()),
0024       d            (new Private)
0025 {
0026     setWindowTitle(i18nc("@title:window", "Share Files With MJPEG Stream Server"));
0027     setModal(false);
0028     d->spacing               = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0029                                     QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0030     d->tabView               = new QTabWidget(this);
0031 
0032     // NOTE: We overwrite the default albums chooser object name for load save check items state between sessions.
0033     // The goal is not mix these settings with other export tools.
0034 
0035     d->settings.iface        = iface;
0036     d->settings.iface->setObjectName(QLatin1String("SetupMjpegStreamIface"));
0037 
0038     // ---
0039 
0040     QWidget* const itemsSel  = setupItemsView();
0041     setupServerView();
0042     setupStreamView();
0043     setupTransitionView();
0044     setupEffectView();
0045     setupOSDView();
0046 
0047     // ---
0048 
0049     m_buttons->addButton(QDialogButtonBox::Cancel);
0050     m_buttons->addButton(QDialogButtonBox::Ok);
0051     m_buttons->button(QDialogButtonBox::Ok)->setDefault(true);
0052 
0053     QVBoxLayout* const vlay = new QVBoxLayout(this);
0054     vlay->addWidget(itemsSel);
0055     vlay->addWidget(d->tabView);
0056     vlay->addWidget(m_buttons);
0057     vlay->setStretchFactor(itemsSel,   10);
0058     vlay->setStretchFactor(d->tabView, 1);
0059     vlay->setSpacing(d->spacing);
0060     setLayout(vlay);
0061 
0062     // ---
0063 
0064     connect(m_buttons->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
0065             this, &MjpegStreamDlg::reject);
0066 
0067     connect(m_buttons->button(QDialogButtonBox::Ok), &QPushButton::clicked,
0068             this, &MjpegStreamDlg::accept);
0069 
0070     // ---
0071 
0072     readSettings();
0073 }
0074 
0075 MjpegStreamDlg::~MjpegStreamDlg()
0076 {
0077     delete d;
0078 }
0079 
0080 void MjpegStreamDlg::accept()
0081 {
0082     if (d->dirty)
0083     {
0084         bool empty = false;
0085 
0086         if (d->albumSupport)
0087         {
0088             empty = d->settings.iface->albumChooserItems().isEmpty();
0089         }
0090         else
0091         {
0092             empty = d->listView->imageUrls().isEmpty();
0093         }
0094 
0095         if (!empty)
0096         {
0097             int rc = QMessageBox::question(this, i18nc("@title:window", "MJPEG Server Contents"),
0098                                            i18nc("@info", "The items list to share has changed. "
0099                                                  "Do you want to start now the MJPEG server with this contents?"));
0100             if (rc == QMessageBox::Yes)
0101             {
0102                 startMjpegServer();
0103             }
0104         }
0105     }
0106 
0107     saveSettings();
0108     QDialog::accept();
0109 }
0110 
0111 void MjpegStreamDlg::slotOpenPreview()
0112 {
0113     QDesktopServices::openUrl(QUrl(QString::fromLatin1("http://localhost:%1")       // krazy:exclude=insecurenet
0114                                    .arg(d->settings.port)));
0115 }
0116 
0117 } // namespace DigikamGenericMjpegStreamPlugin
0118 
0119 #include "moc_mjpegstreamdlg.cpp"