File indexing completed on 2024-04-28 04:21:19

0001 /* SPDX-FileCopyrightText: 2003-2020 The KPhotoAlbum Development Team
0002 
0003    SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 #include "GeneralPage.h"
0006 
0007 #include <DB/Category.h>
0008 #include <DB/CategoryCollection.h>
0009 #include <DB/ImageDB.h>
0010 #include <MainWindow/Window.h>
0011 #include <kpabase/SettingsData.h>
0012 
0013 #include <KComboBox>
0014 #include <KLocalizedString>
0015 #include <QCheckBox>
0016 #include <QGroupBox>
0017 #include <QLabel>
0018 #include <QSpinBox>
0019 #include <QTextEdit>
0020 #include <QVBoxLayout>
0021 #include <QWidget>
0022 
0023 Settings::GeneralPage::GeneralPage(QWidget *parent)
0024     : QWidget(parent)
0025 {
0026     QVBoxLayout *lay1 = new QVBoxLayout(this);
0027 
0028     QGroupBox *box = new QGroupBox(i18n("Loading New Images"), this);
0029     lay1->addWidget(box);
0030 
0031     QGridLayout *lay = new QGridLayout(box);
0032     lay->setSpacing(6);
0033     int row = 0;
0034 
0035     // Thrust time stamps
0036     QLabel *timeStampLabel = new QLabel(i18n("Trust image dates:"), box);
0037     m_trustTimeStamps = new KComboBox(box);
0038     m_trustTimeStamps->addItems(QStringList() << i18nc("As in 'always trust image dates'", "Always")
0039                                               << i18nc("As in 'ask whether to trust image dates'", "Ask")
0040                                               << i18nc("As in 'never trust image dates'", "Never"));
0041     timeStampLabel->setBuddy(m_trustTimeStamps);
0042     lay->addWidget(timeStampLabel, row, 0);
0043     lay->addWidget(m_trustTimeStamps, row, 1, 1, 3);
0044 
0045     // Do Exif rotate
0046     row++;
0047     m_useEXIFRotate = new QCheckBox(i18n("Use Exif orientation information"), box);
0048     lay->addWidget(m_useEXIFRotate, row, 0, 1, 4);
0049 
0050     // Use Exif description
0051     row++;
0052     m_useEXIFComments = new QCheckBox(i18n("Use Exif description"), box);
0053     lay->addWidget(m_useEXIFComments, row, 0, 1, 4);
0054     connect(m_useEXIFComments, &QCheckBox::stateChanged, this, &GeneralPage::useEXIFCommentsChanged);
0055 
0056     m_stripEXIFComments = new QCheckBox(i18n("Strip out camera generated default descriptions"), box);
0057     connect(m_stripEXIFComments, &QCheckBox::stateChanged, this, &GeneralPage::stripEXIFCommentsChanged);
0058     lay->addWidget(m_stripEXIFComments, row, 1, 1, 4);
0059 
0060     row++;
0061     m_commentsToStrip = new QTextEdit();
0062     m_commentsToStrip->setMaximumHeight(60);
0063     m_commentsToStrip->setEnabled(false);
0064     lay->addWidget(m_commentsToStrip, row, 1, 1, 4);
0065 
0066     // Use embedded thumbnail
0067     row++;
0068     m_useRawThumbnail = new QCheckBox(i18n("Use the embedded thumbnail in RAW file or halfsized RAW"), box);
0069     lay->addWidget(m_useRawThumbnail, row, 0);
0070 
0071     row++;
0072     QLabel *label = new QLabel(i18n("Required size for the thumbnail:"), box);
0073     m_useRawThumbnailWidth = new QSpinBox(box);
0074     m_useRawThumbnailWidth->setRange(100, 5000);
0075     m_useRawThumbnailWidth->setSingleStep(64);
0076     lay->addWidget(label, row, 0);
0077     lay->addWidget(m_useRawThumbnailWidth, row, 1);
0078 
0079     label = new QLabel(QString::fromLatin1("x"), box);
0080     m_useRawThumbnailHeight = new QSpinBox(box);
0081     m_useRawThumbnailHeight->setRange(100, 5000);
0082     m_useRawThumbnailHeight->setSingleStep(64);
0083     lay->addWidget(label, row, 2);
0084     lay->addWidget(m_useRawThumbnailHeight, row, 3);
0085 
0086     box = new QGroupBox(i18n("Histogram"), this);
0087     lay1->addWidget(box);
0088 
0089     lay = new QGridLayout(box);
0090     lay->setSpacing(6);
0091     row = 0;
0092 
0093     m_showHistogram = new QCheckBox(i18n("Show histogram"), box);
0094     lay->addWidget(m_showHistogram, row, 0);
0095     row++;
0096     connect(m_showHistogram, &QCheckBox::stateChanged, this, &GeneralPage::showHistogramChanged);
0097 
0098     m_histogramUseLinearScale = new QCheckBox(i18n("Use linear scale for histogram"));
0099     lay->addWidget(m_histogramUseLinearScale, row, 0);
0100     row++;
0101 
0102     label = new QLabel(i18n("Size of histogram columns in date bar:"), box);
0103     m_barWidth = new QSpinBox;
0104     m_barWidth->setRange(1, 100);
0105     m_barWidth->setSingleStep(1);
0106     lay->addWidget(label, row, 0);
0107     lay->addWidget(m_barWidth, row, 1);
0108 
0109     label = new QLabel(QString::fromLatin1("x"), box);
0110     m_barHeight = new QSpinBox;
0111     m_barHeight->setRange(15, 100);
0112     lay->addWidget(label, row, 2);
0113     lay->addWidget(m_barHeight, row, 3);
0114 
0115     box = new QGroupBox(i18n("Miscellaneous"), this);
0116     lay1->addWidget(box);
0117 
0118     lay = new QGridLayout(box);
0119     lay->setSpacing(6);
0120     row = 0;
0121 
0122     // Show splash screen
0123     m_showSplashScreen = new QCheckBox(i18n("Show splash screen"), box);
0124     lay->addWidget(m_showSplashScreen, row, 0);
0125 
0126 #ifdef KPA_ENABLE_REMOTECONTROL
0127     m_listenForAndroidDevicesOnStartup = new QCheckBox(i18n("Listen for Android devices on startup"));
0128     lay->addWidget(m_listenForAndroidDevicesOnStartup);
0129 #endif
0130 
0131     lay1->addStretch(1);
0132 
0133     // Whats This
0134     QString txt;
0135 
0136     txt = i18n("<p>KPhotoAlbum will try to read the image date from Exif information in the image. "
0137                "If that fails it will try to get the date from the file's time stamp.</p>"
0138                "<p>However, this information will be wrong if the image was scanned in (you want the date the image "
0139                "was taken, not the date of the scan).</p>"
0140                "<p>If you only scan images, in contrast to sometimes using "
0141                "a digital camera, you should reply <b>no</b>. If you never scan images, you should reply <b>yes</b>, "
0142                "otherwise reply <b>ask</b>. This will allow you to decide whether the images are from "
0143                "the scanner or the camera, from session to session.</p>");
0144     timeStampLabel->setWhatsThis(txt);
0145     m_trustTimeStamps->setWhatsThis(txt);
0146 
0147     txt = i18n("<p>JPEG images may contain information about rotation. "
0148                "If you have a reason for not using this information to get a default rotation of "
0149                "your images, uncheck this check box.</p>"
0150                "<p>Note: Your digital camera may not write this information into the images at all.</p>");
0151     m_useEXIFRotate->setWhatsThis(txt);
0152 
0153     txt = i18n("<p>JPEG images may contain a description. "
0154                "Check this checkbox to specify if you want to use this as a "
0155                "default description for your images.</p>");
0156     m_useEXIFComments->setWhatsThis(txt);
0157 
0158     txt = i18n("Show the KPhotoAlbum splash screen on start up");
0159     m_showSplashScreen->setWhatsThis(txt);
0160 
0161 #ifdef KPA_ENABLE_REMOTECONTROL
0162     txt = i18n("<p>KPhotoAlbum is capable of showing your images on android devices. KPhotoAlbum will automatically pair with the app from "
0163                "android. This, however, requires that KPhotoAlbum on your desktop is listening for multicast messages. "
0164                "Checking this checkbox will make KPhotoAlbum do so automatically on start up. "
0165                "Alternatively, you can click the connection icon in the status bar to start listening.");
0166     m_listenForAndroidDevicesOnStartup->setWhatsThis(txt);
0167 #endif
0168 
0169     txt = i18n("<p>Some cameras automatically store generic comments in each image. "
0170                "These comments can be ignored automatically.</p>"
0171                "<p>Enter the comments that you want to ignore in the input field, one per line. "
0172                "Be sure to add the exact comment, including all whitespace.</p>");
0173     m_stripEXIFComments->setWhatsThis(txt);
0174     m_commentsToStrip->setWhatsThis(txt);
0175 }
0176 
0177 void Settings::GeneralPage::loadSettings(Settings::SettingsData *opt)
0178 {
0179     m_trustTimeStamps->setCurrentIndex(opt->tTimeStamps());
0180     m_useEXIFRotate->setChecked(opt->useEXIFRotate());
0181     m_useEXIFComments->setChecked(opt->useEXIFComments());
0182 
0183     m_stripEXIFComments->setChecked(opt->stripEXIFComments());
0184     m_stripEXIFComments->setEnabled(opt->useEXIFComments());
0185 
0186     QStringList commentsToStrip = opt->EXIFCommentsToStrip();
0187     QString commentsToStripStr;
0188     for (int i = 0; i < commentsToStrip.size(); ++i) {
0189         if (commentsToStripStr.size() > 0) {
0190             commentsToStripStr += QString::fromLatin1("\n");
0191         }
0192         commentsToStripStr += commentsToStrip.at(i);
0193     }
0194     m_commentsToStrip->setPlainText(commentsToStripStr);
0195     m_commentsToStrip->setEnabled(opt->stripEXIFComments());
0196 
0197     m_useRawThumbnail->setChecked(opt->useRawThumbnail());
0198     setUseRawThumbnailSize(QSize(opt->useRawThumbnailSize().width(), opt->useRawThumbnailSize().height()));
0199     m_barWidth->setValue(opt->histogramSize().width());
0200     m_barHeight->setValue(opt->histogramSize().height());
0201     m_showHistogram->setChecked(opt->showHistogram());
0202     m_histogramUseLinearScale->setChecked(opt->histogramUseLinearScale());
0203     m_showSplashScreen->setChecked(opt->showSplashScreen());
0204 #ifdef KPA_ENABLE_REMOTECONTROL
0205     m_listenForAndroidDevicesOnStartup->setChecked(opt->listenForAndroidDevicesOnStartup());
0206 #endif
0207 }
0208 
0209 void Settings::GeneralPage::saveSettings(Settings::SettingsData *opt)
0210 {
0211     opt->setTTimeStamps((TimeStampTrust)m_trustTimeStamps->currentIndex());
0212     opt->setUseEXIFRotate(m_useEXIFRotate->isChecked());
0213     opt->setUseEXIFComments(m_useEXIFComments->isChecked());
0214 
0215     opt->setStripEXIFComments(m_stripEXIFComments->isChecked());
0216 
0217     QStringList commentsToStrip = m_commentsToStrip->toPlainText().split(QString::fromLatin1("\n"));
0218     // Put the processable list to opt
0219     opt->setEXIFCommentsToStrip(commentsToStrip);
0220 
0221     QString commentsToStripString;
0222     for (QString comment : commentsToStrip) {
0223         // separate comments with "-,-" and escape existing commas by doubling
0224         if (!comment.isEmpty())
0225             commentsToStripString += comment.replace(QString::fromLatin1(","), QString::fromLatin1(",,")) + QString::fromLatin1("-,-");
0226     }
0227     // Put the storable list to opt
0228     opt->setCommentsToStrip(commentsToStripString);
0229 
0230     opt->setUseRawThumbnail(m_useRawThumbnail->isChecked());
0231     opt->setUseRawThumbnailSize(QSize(useRawThumbnailSize()));
0232     opt->setShowHistogram(m_showHistogram->isChecked());
0233     opt->setHistogramUseLinearScale(m_histogramUseLinearScale->isChecked());
0234     opt->setShowSplashScreen(m_showSplashScreen->isChecked());
0235 #ifdef KPA_ENABLE_REMOTECONTROL
0236     opt->setListenForAndroidDevicesOnStartup(m_listenForAndroidDevicesOnStartup->isChecked());
0237 #endif
0238 
0239     opt->setHistogramSize(QSize(m_barWidth->value(), m_barHeight->value()));
0240 }
0241 
0242 void Settings::GeneralPage::setUseRawThumbnailSize(const QSize &size)
0243 {
0244     m_useRawThumbnailWidth->setValue(size.width());
0245     m_useRawThumbnailHeight->setValue(size.height());
0246 }
0247 
0248 QSize Settings::GeneralPage::useRawThumbnailSize()
0249 {
0250     return QSize(m_useRawThumbnailWidth->value(), m_useRawThumbnailHeight->value());
0251 }
0252 
0253 void Settings::GeneralPage::showHistogramChanged(int state) const
0254 {
0255     const bool checked = state == Qt::Checked;
0256     m_histogramUseLinearScale->setChecked(checked);
0257     m_barHeight->setEnabled(checked);
0258     m_barWidth->setEnabled(checked);
0259     MainWindow::Window::theMainWindow()->setHistogramVisibilty(checked);
0260 }
0261 
0262 void Settings::GeneralPage::useEXIFCommentsChanged(int state)
0263 {
0264     m_stripEXIFComments->setEnabled(state);
0265     m_commentsToStrip->setEnabled(state && m_stripEXIFComments->isChecked());
0266 }
0267 
0268 void Settings::GeneralPage::stripEXIFCommentsChanged(int state)
0269 {
0270     m_commentsToStrip->setEnabled(state);
0271 }
0272 
0273 // vi:expandtab:tabstop=4 shiftwidth=4:
0274 
0275 #include "moc_GeneralPage.cpp"