File indexing completed on 2025-01-19 03:57:58
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 "collectionpage.h" 0016 0017 // Qt includes 0018 0019 #include <QApplication> 0020 #include <QStyle> 0021 #include <QLabel> 0022 #include <QDir> 0023 #include <QStandardPaths> 0024 #include <QFileInfo> 0025 #include <QVBoxLayout> 0026 #include <QTemporaryFile> 0027 #include <QMessageBox> 0028 0029 // KDE includes 0030 0031 #include <ksharedconfig.h> 0032 #include <kconfiggroup.h> 0033 #include <klocalizedstring.h> 0034 0035 // Local includes 0036 0037 #include "dlayoutbox.h" 0038 #include "dfileselector.h" 0039 #include "digikam_debug.h" 0040 #include "digikam_version.h" 0041 0042 namespace Digikam 0043 { 0044 0045 class Q_DECL_HIDDEN CollectionPage::Private 0046 { 0047 public: 0048 0049 explicit Private() 0050 : rootAlbumPathRequester(nullptr) 0051 { 0052 } 0053 0054 QString rootAlbum; 0055 0056 DFileSelector* rootAlbumPathRequester; 0057 }; 0058 0059 CollectionPage::CollectionPage(QWizard* const dlg) 0060 : DWizardPage(dlg, i18n("<b>Configure where you keep your images</b>")), 0061 d(new Private) 0062 { 0063 QWidget* const widget = new QWidget(this); 0064 QVBoxLayout* const vlayout = new QVBoxLayout(widget); 0065 0066 QString picturesPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); 0067 0068 qCDebug(DIGIKAM_GENERAL_LOG) << picturesPath; 0069 0070 if (picturesPath.isEmpty()) 0071 { 0072 picturesPath = QDir::homePath() + i18nc("This is a path name so you should " 0073 "include the slash in the translation", "/Pictures"); 0074 } 0075 0076 QLabel* const textLabel1 = new QLabel(widget); 0077 textLabel1->setWordWrap(true); 0078 0079 QString message = i18n("<p>Please enter a location where you keep your images.</p> " 0080 "<p>You can choose any local folder, even one that already contains images." 0081 "<br/> " 0082 "More folders can be added later under the <i>Settings</i> menu. " 0083 "</p> "); 0084 0085 #ifndef Q_OS_WIN 0086 0087 message.append(i18n("<p><i>Note:</i> removable media (such as USB drives or DVDs) and remote file systems " 0088 "(such as NFS, or Samba mounted with cifs/smbfs) are supported.</p>")); 0089 0090 #endif 0091 0092 textLabel1->setText(message); 0093 0094 d->rootAlbumPathRequester = new DFileSelector(widget); 0095 d->rootAlbumPathRequester->setFileDlgMode(QFileDialog::Directory); 0096 d->rootAlbumPathRequester->setFileDlgOptions(QFileDialog::ShowDirsOnly); 0097 d->rootAlbumPathRequester->setFileDlgPath(picturesPath); 0098 0099 vlayout->addWidget(textLabel1); 0100 vlayout->addWidget(d->rootAlbumPathRequester); 0101 vlayout->setContentsMargins(QMargins()); 0102 vlayout->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0103 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0104 0105 setPageWidget(widget); 0106 setLeftBottomPix(QIcon::fromTheme(QLatin1String("folder-pictures"))); 0107 } 0108 0109 CollectionPage::~CollectionPage() 0110 { 0111 delete d; 0112 } 0113 0114 QString CollectionPage::firstAlbumPath() const 0115 { 0116 return d->rootAlbum; 0117 } 0118 0119 void CollectionPage::saveSettings() 0120 { 0121 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0122 KConfigGroup group = config->group(QLatin1String("General Settings")); 0123 group.writeEntry("Version", digikam_version); 0124 0125 config->sync(); 0126 } 0127 0128 bool CollectionPage::checkSettings() 0129 { 0130 QString rootAlbumFolder; 0131 0132 if (!checkRootAlbum(rootAlbumFolder)) 0133 { 0134 return false; 0135 } 0136 0137 d->rootAlbum = rootAlbumFolder; 0138 0139 return true; 0140 } 0141 0142 bool CollectionPage::checkRootAlbum(QString& rootAlbumFolder) 0143 { 0144 rootAlbumFolder = d->rootAlbumPathRequester->fileDlgPath(); 0145 qCDebug(DIGIKAM_GENERAL_LOG) << "Root album is : " << rootAlbumFolder; 0146 0147 if (rootAlbumFolder.isEmpty()) 0148 { 0149 QMessageBox::information(this, qApp->applicationName(), 0150 i18n("You must select a folder for digiKam to " 0151 "use as the root album. All of your images will go there.")); 0152 return false; 0153 } 0154 0155 #ifndef Q_OS_WIN 0156 0157 if (!QDir::isAbsolutePath(rootAlbumFolder)) 0158 { 0159 rootAlbumFolder.prepend(QDir::homePath()); 0160 } 0161 0162 #endif 0163 0164 /* 0165 if (QUrl::fromLocalFile(rootAlbumFolder).equals(QUrl::fromLocalFile(QDir::homePath()), QUrl::CompareWithoutFragment)) 0166 { 0167 QMessageBox::information(this, qApp->applicationName(), 0168 i18n("digiKam will not use your home folder as the " 0169 "root album. Please select another location.")); 0170 return false; 0171 } 0172 */ 0173 0174 QDir targetPath(rootAlbumFolder); 0175 0176 if (!targetPath.exists()) 0177 { 0178 int rc = QMessageBox::question(this, i18nc("@title:window", "Create Root Album Folder?"), 0179 i18n("<p>The folder to use as the root album path does not exist:</p>" 0180 "<p><b>%1</b></p>" 0181 "Would you like digiKam to create it for you?", 0182 QDir::toNativeSeparators(rootAlbumFolder))); 0183 0184 if (rc == QMessageBox::No) 0185 { 0186 return false; 0187 } 0188 0189 if (!targetPath.mkpath(rootAlbumFolder)) 0190 { 0191 QMessageBox::information(this, i18nc("@title:window", "Create Root Album Folder Failed"), 0192 i18n("<p>digiKam could not create the folder to use as the root album.\n" 0193 "Please select a different location.</p>" 0194 "<p><b>%1</b></p>", QDir::toNativeSeparators(rootAlbumFolder))); 0195 return false; 0196 } 0197 } 0198 0199 QFileInfo path(rootAlbumFolder); 0200 0201 #ifdef Q_OS_WIN 0202 0203 // Work around bug #189168 0204 0205 QTemporaryFile temp; 0206 temp.setFileTemplate(path.filePath() + QLatin1String("/XXXXXX")); 0207 0208 if (!temp.open()) 0209 0210 #else 0211 0212 if (!path.isWritable()) 0213 0214 #endif 0215 { 0216 QMessageBox::information(this, qApp->applicationName(), 0217 i18n("You do not seem to have write access for the folder " 0218 "selected to be the root album.\n" 0219 "Warning: Without write access, items cannot be edited.")); 0220 } 0221 0222 return true; 0223 } 0224 0225 } // namespace Digikam 0226 0227 #include "moc_collectionpage.cpp"