File indexing completed on 2024-04-28 15:40:13
0001 // SPDX-FileCopyrightText: 2003-2018 Jesper K Pedersen <blackie@kde.org> 0002 // SPDX-FileCopyrightText: 2022-2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0003 // 0004 // SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 #include "WelcomeDialog.h" 0007 0008 #include "FeatureDialog.h" 0009 #include "Window.h" 0010 0011 #include <KConfigGroup> 0012 #include <KLocalizedString> 0013 #include <KMessageBox> 0014 #include <KSharedConfig> 0015 #include <KShell> 0016 #include <QDialogButtonBox> 0017 #include <QFileDialog> 0018 #include <QHBoxLayout> 0019 #include <QLabel> 0020 #include <QLayout> 0021 #include <QLineEdit> 0022 #include <QPushButton> 0023 #include <QStandardPaths> 0024 #include <QVBoxLayout> 0025 #include <kwidgetsaddons_version.h> 0026 0027 using namespace MainWindow; 0028 0029 WelcomeDialog::WelcomeDialog(QWidget *parent) 0030 : QDialog(parent) 0031 0032 { 0033 QVBoxLayout *lay1 = new QVBoxLayout(this); 0034 QHBoxLayout *lay2 = new QHBoxLayout; 0035 lay1->addLayout(lay2); 0036 0037 QLabel *image = new QLabel(this); 0038 image->setMinimumSize(QSize(273, 204)); 0039 image->setMaximumSize(QSize(273, 204)); 0040 image->setPixmap(QStandardPaths::locate(QStandardPaths::DataLocation, QString::fromLatin1("pics/splash.png"))); 0041 lay2->addWidget(image); 0042 0043 QLabel *textLabel2 = new QLabel(this); 0044 lay2->addWidget(textLabel2); 0045 textLabel2->setText(i18n("<h1>Welcome to KPhotoAlbum</h1>" 0046 "<p>KPhotoAlbum is a powerful free tool to archive, tag and manage your photos and " 0047 "videos. It will not modify or change your precious files, it only indexes them " 0048 "and lets you easily find and manage your photos and videos.</p>" 0049 "<p>Start by showing KPhotoAlbum where your photos are by pressing on Create My Own " 0050 "Database. Select this button also if you have an existing KPhotoAlbum database " 0051 "that you want to start using again.</p>" 0052 "<p>If you feel safer first trying out KPhotoAlbum with prebuilt set of images, " 0053 "press the Load Demo button.</p>")); 0054 textLabel2->setWordWrap(true); 0055 0056 QHBoxLayout *lay3 = new QHBoxLayout; 0057 lay1->addLayout(lay3); 0058 lay3->addStretch(1); 0059 0060 QPushButton *createSetup = new QPushButton(i18n("Create My Own Database..."), this); 0061 lay3->addWidget(createSetup); 0062 0063 QPushButton *loadDemo = new QPushButton(i18n("Load Demo")); 0064 lay3->addWidget(loadDemo); 0065 0066 QPushButton *checkFeatures = new QPushButton(i18n("Check My Feature Set")); 0067 lay3->addWidget(checkFeatures); 0068 0069 connect(loadDemo, &QPushButton::clicked, this, &WelcomeDialog::slotLoadDemo); 0070 connect(createSetup, &QPushButton::clicked, this, &WelcomeDialog::createSetup); 0071 connect(checkFeatures, &QPushButton::clicked, this, &WelcomeDialog::checkFeatures); 0072 } 0073 0074 void WelcomeDialog::slotLoadDemo() 0075 { 0076 // rerun KPA with "--demo" 0077 MainWindow::Window::theMainWindow()->runDemo(); 0078 // cancel the dialog (and exit this instance of KPA) 0079 reject(); 0080 } 0081 0082 void WelcomeDialog::createSetup() 0083 { 0084 FileDialog dialog(this); 0085 m_configFile = dialog.getFileName(); 0086 if (!m_configFile.isNull()) 0087 accept(); 0088 } 0089 0090 QString WelcomeDialog::configFileName() const 0091 { 0092 return m_configFile; 0093 } 0094 0095 FileDialog::FileDialog(QWidget *parent) 0096 : QDialog(parent) 0097 { 0098 QVBoxLayout *mainLayout = new QVBoxLayout(this); 0099 0100 QLabel *label = new QLabel(i18n("<h1>KPhotoAlbum database creation</h1>" 0101 "<p>You need to show where the photos and videos are for KPhotoAlbum to " 0102 "find them. They all need to be contained by a single folder, for example " 0103 "/home/user/Images. In this folder you can have as many subfolders as you " 0104 "want, KPhotoAlbum will find them all for you.</p>" 0105 "<p>Feel safe, KPhotoAlbum will not modify or edit any of your images, so you can " 0106 "simply point KPhotoAlbum to the folder where you already have all your " 0107 "images.</p>" 0108 "<p>If you have an existing KPhotoAlbum database and image folder somewhere, " 0109 "point KPhotoAlbum to that folder to start using it again.</p>"), 0110 this); 0111 label->setWordWrap(true); 0112 mainLayout->addWidget(label); 0113 0114 QHBoxLayout *lay2 = new QHBoxLayout; 0115 label = new QLabel(i18n("Image/Video root folder: "), this); 0116 lay2->addWidget(label); 0117 0118 m_lineEdit = new QLineEdit(this); 0119 m_lineEdit->setText(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); 0120 lay2->addWidget(m_lineEdit); 0121 0122 QPushButton *button = new QPushButton(QString::fromLatin1("..."), this); 0123 button->setMaximumWidth(30); 0124 lay2->addWidget(button); 0125 connect(button, &QPushButton::clicked, this, &FileDialog::slotBrowseForDirecory); 0126 0127 mainLayout->addLayout(lay2); 0128 0129 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0130 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0131 okButton->setDefault(true); 0132 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0133 connect(buttonBox, &QDialogButtonBox::accepted, this, &FileDialog::accept); 0134 connect(buttonBox, &QDialogButtonBox::rejected, this, &FileDialog::reject); 0135 mainLayout->addWidget(buttonBox); 0136 } 0137 0138 void FileDialog::slotBrowseForDirecory() 0139 { 0140 QString dir = QFileDialog::getExistingDirectory(this, QString(), m_lineEdit->text()); 0141 if (!dir.isNull()) 0142 m_lineEdit->setText(dir); 0143 } 0144 0145 QString FileDialog::getFileName() 0146 { 0147 bool ok = false; 0148 QString dir; 0149 while (!ok) { 0150 if (exec() == Rejected) 0151 return QString(); 0152 0153 dir = KShell::tildeExpand(m_lineEdit->text()); 0154 if (!QFileInfo::exists(dir)) { 0155 const QString question = i18n("Folder does not exist, create it?"); 0156 const QString title = i18nc("@title", "Create folder?"); 0157 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) 0158 const auto answer = KMessageBox::questionTwoActions(this, 0159 question, 0160 title, 0161 KGuiItem(i18nc("@action:button", "Create")), 0162 KStandardGuiItem::cancel()); 0163 if (answer == KMessageBox::ButtonCode::PrimaryAction) { 0164 #else 0165 const auto answer = KMessageBox::questionYesNo(this, question, title); 0166 if (answer == KMessageBox::Yes) { 0167 #endif 0168 bool ok2 = QDir().mkdir(dir); 0169 if (!ok2) { 0170 KMessageBox::error(this, i18n("Could not create folder %1", dir)); 0171 } else 0172 ok = true; 0173 } 0174 } else if (!QFileInfo(dir).isDir()) { 0175 KMessageBox::error(this, i18n("%1 exists, but is not a folder", dir)); 0176 } else 0177 ok = true; 0178 } 0179 0180 QString file = dir + QString::fromLatin1("/index.xml"); 0181 KConfigGroup group = KSharedConfig::openConfig()->group(QString::fromUtf8("General")); 0182 group.writeEntry(QString::fromLatin1("imageDBFile"), file); 0183 group.sync(); 0184 0185 return file; 0186 } 0187 0188 void MainWindow::WelcomeDialog::checkFeatures() 0189 { 0190 if (!FeatureDialog::hasAllFeaturesAvailable()) { 0191 const QString msg = i18n("<p>KPhotoAlbum does not seem to be built with support for all its features. The following is a list " 0192 "indicating what you may be missing:<ul>%1</ul></p>" 0193 "<p>For details on how to solve this problem, please choose <b>Help</b>|<b>KPhotoAlbum Feature Status</b> " 0194 "from the menus.</p>", 0195 FeatureDialog::featureString()); 0196 KMessageBox::information(this, msg, i18n("Feature Check")); 0197 } else { 0198 KMessageBox::information(this, i18n("Congratulations: all dynamic features have been enabled."), 0199 i18n("Feature Check")); 0200 } 0201 } 0202 0203 // vi:expandtab:tabstop=4 shiftwidth=4: 0204 0205 #include "moc_WelcomeDialog.cpp"